Skip to content

Commit fadf3df

Browse files
Santosh Pradhanaxboe
authored andcommitted
block/rnbd: add support for REQ_OP_WRITE_ZEROES
Remove REQ_OP_WRITE_SAME in favour of REQ_OP_WRITE_ZEROES. Signed-off-by: Santosh Pradhan <santosh.pradhan@ionos.com> Reviewed-by: Md Haris Iqbal <haris.iqbal@ionos.com> Signed-off-by: Grzegorz Prajsner <grzegorz.prajsner@ionos.com> Signed-off-by: Md Haris Iqbal <haris.iqbal@ionos.com> Link: https://lore.kernel.org/r/20231124213422.113449-2-haris.iqbal@ionos.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2cc14f5 commit fadf3df

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

drivers/block/rnbd/rnbd-clt.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,10 +1006,10 @@ static int rnbd_client_xfer_request(struct rnbd_clt_dev *dev,
10061006
msg.prio = cpu_to_le16(req_get_ioprio(rq));
10071007

10081008
/*
1009-
* We only support discards with single segment for now.
1009+
* We only support discards/WRITE_ZEROES with single segment for now.
10101010
* See queue limits.
10111011
*/
1012-
if (req_op(rq) != REQ_OP_DISCARD)
1012+
if ((req_op(rq) != REQ_OP_DISCARD) && (req_op(rq) != REQ_OP_WRITE_ZEROES))
10131013
sg_cnt = blk_rq_map_sg(dev->queue, rq, iu->sgt.sgl);
10141014

10151015
if (sg_cnt == 0)
@@ -1362,6 +1362,8 @@ static void setup_request_queue(struct rnbd_clt_dev *dev,
13621362
blk_queue_write_cache(dev->queue,
13631363
!!(rsp->cache_policy & RNBD_WRITEBACK),
13641364
!!(rsp->cache_policy & RNBD_FUA));
1365+
blk_queue_max_write_zeroes_sectors(dev->queue,
1366+
le32_to_cpu(rsp->max_write_zeroes_sectors));
13651367
}
13661368

13671369
static int rnbd_clt_setup_gen_disk(struct rnbd_clt_dev *dev,
@@ -1626,10 +1628,11 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname,
16261628
}
16271629

16281630
rnbd_clt_info(dev,
1629-
"map_device: Device mapped as %s (nsectors: %llu, logical_block_size: %d, physical_block_size: %d, max_discard_sectors: %d, discard_granularity: %d, discard_alignment: %d, secure_discard: %d, max_segments: %d, max_hw_sectors: %d, wc: %d, fua: %d)\n",
1631+
"map_device: Device mapped as %s (nsectors: %llu, logical_block_size: %d, physical_block_size: %d, max_write_zeroes_sectors: %d, max_discard_sectors: %d, discard_granularity: %d, discard_alignment: %d, secure_discard: %d, max_segments: %d, max_hw_sectors: %d, wc: %d, fua: %d)\n",
16301632
dev->gd->disk_name, le64_to_cpu(rsp->nsectors),
16311633
le16_to_cpu(rsp->logical_block_size),
16321634
le16_to_cpu(rsp->physical_block_size),
1635+
le32_to_cpu(rsp->max_write_zeroes_sectors),
16331636
le32_to_cpu(rsp->max_discard_sectors),
16341637
le32_to_cpu(rsp->discard_granularity),
16351638
le32_to_cpu(rsp->discard_alignment),

drivers/block/rnbd/rnbd-proto.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ enum rnbd_cache_policy {
128128
* @device_id: device_id on server side to identify the device
129129
* @nsectors: number of sectors in the usual 512b unit
130130
* @max_hw_sectors: max hardware sectors in the usual 512b unit
131-
* @max_write_same_sectors: max sectors for WRITE SAME in the 512b unit
131+
* @max_write_zeroes_sectors: max sectors for WRITE ZEROES in the 512b unit
132132
* @max_discard_sectors: max. sectors that can be discarded at once in 512b
133133
* unit.
134134
* @discard_granularity: size of the internal discard allocation unit in bytes
@@ -145,7 +145,7 @@ struct rnbd_msg_open_rsp {
145145
__le32 device_id;
146146
__le64 nsectors;
147147
__le32 max_hw_sectors;
148-
__le32 max_write_same_sectors;
148+
__le32 max_write_zeroes_sectors;
149149
__le32 max_discard_sectors;
150150
__le32 discard_granularity;
151151
__le32 discard_alignment;
@@ -186,7 +186,7 @@ struct rnbd_msg_io {
186186
* @RNBD_OP_FLUSH: flush the volatile write cache
187187
* @RNBD_OP_DISCARD: discard sectors
188188
* @RNBD_OP_SECURE_ERASE: securely erase sectors
189-
* @RNBD_OP_WRITE_SAME: write the same sectors many times
189+
* @RNBD_OP_WRITE_ZEROES: write zeroes sectors
190190
191191
* @RNBD_F_SYNC: request is sync (sync write or read)
192192
* @RNBD_F_FUA: forced unit access
@@ -199,7 +199,7 @@ enum rnbd_io_flags {
199199
RNBD_OP_FLUSH = 2,
200200
RNBD_OP_DISCARD = 3,
201201
RNBD_OP_SECURE_ERASE = 4,
202-
RNBD_OP_WRITE_SAME = 5,
202+
RNBD_OP_WRITE_ZEROES = 5,
203203

204204
/* Flags */
205205
RNBD_F_SYNC = 1<<(RNBD_OP_BITS + 0),
@@ -236,6 +236,9 @@ static inline blk_opf_t rnbd_to_bio_flags(u32 rnbd_opf)
236236
case RNBD_OP_SECURE_ERASE:
237237
bio_opf = REQ_OP_SECURE_ERASE;
238238
break;
239+
case RNBD_OP_WRITE_ZEROES:
240+
bio_opf = REQ_OP_WRITE_ZEROES;
241+
break;
239242
default:
240243
WARN(1, "Unknown RNBD type: %d (flags %d)\n",
241244
rnbd_op(rnbd_opf), rnbd_opf);
@@ -268,6 +271,9 @@ static inline u32 rq_to_rnbd_flags(struct request *rq)
268271
case REQ_OP_SECURE_ERASE:
269272
rnbd_opf = RNBD_OP_SECURE_ERASE;
270273
break;
274+
case REQ_OP_WRITE_ZEROES:
275+
rnbd_opf = RNBD_OP_WRITE_ZEROES;
276+
break;
271277
case REQ_OP_FLUSH:
272278
rnbd_opf = RNBD_OP_FLUSH;
273279
break;

drivers/block/rnbd/rnbd-srv.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
544544
rsp->max_segments = cpu_to_le16(bdev_max_segments(bdev));
545545
rsp->max_hw_sectors =
546546
cpu_to_le32(queue_max_hw_sectors(bdev_get_queue(bdev)));
547-
rsp->max_write_same_sectors = 0;
547+
rsp->max_write_zeroes_sectors =
548+
cpu_to_le32(bdev_write_zeroes_sectors(bdev));
548549
rsp->max_discard_sectors = cpu_to_le32(bdev_max_discard_sectors(bdev));
549550
rsp->discard_granularity = cpu_to_le32(bdev_discard_granularity(bdev));
550551
rsp->discard_alignment = cpu_to_le32(bdev_discard_alignment(bdev));

0 commit comments

Comments
 (0)