Commit fadf3dff authored by Santosh Pradhan's avatar Santosh Pradhan Committed by Jens Axboe

block/rnbd: add support for REQ_OP_WRITE_ZEROES

Remove REQ_OP_WRITE_SAME in favour of REQ_OP_WRITE_ZEROES.
Signed-off-by: default avatarSantosh Pradhan <santosh.pradhan@ionos.com>
Reviewed-by: default avatarMd Haris Iqbal <haris.iqbal@ionos.com>
Signed-off-by: default avatarGrzegorz Prajsner <grzegorz.prajsner@ionos.com>
Signed-off-by: default avatarMd Haris Iqbal <haris.iqbal@ionos.com>
Link: https://lore.kernel.org/r/20231124213422.113449-2-haris.iqbal@ionos.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 2cc14f52
...@@ -1006,10 +1006,10 @@ static int rnbd_client_xfer_request(struct rnbd_clt_dev *dev, ...@@ -1006,10 +1006,10 @@ static int rnbd_client_xfer_request(struct rnbd_clt_dev *dev,
msg.prio = cpu_to_le16(req_get_ioprio(rq)); msg.prio = cpu_to_le16(req_get_ioprio(rq));
/* /*
* We only support discards with single segment for now. * We only support discards/WRITE_ZEROES with single segment for now.
* See queue limits. * See queue limits.
*/ */
if (req_op(rq) != REQ_OP_DISCARD) if ((req_op(rq) != REQ_OP_DISCARD) && (req_op(rq) != REQ_OP_WRITE_ZEROES))
sg_cnt = blk_rq_map_sg(dev->queue, rq, iu->sgt.sgl); sg_cnt = blk_rq_map_sg(dev->queue, rq, iu->sgt.sgl);
if (sg_cnt == 0) if (sg_cnt == 0)
...@@ -1362,6 +1362,8 @@ static void setup_request_queue(struct rnbd_clt_dev *dev, ...@@ -1362,6 +1362,8 @@ static void setup_request_queue(struct rnbd_clt_dev *dev,
blk_queue_write_cache(dev->queue, blk_queue_write_cache(dev->queue,
!!(rsp->cache_policy & RNBD_WRITEBACK), !!(rsp->cache_policy & RNBD_WRITEBACK),
!!(rsp->cache_policy & RNBD_FUA)); !!(rsp->cache_policy & RNBD_FUA));
blk_queue_max_write_zeroes_sectors(dev->queue,
le32_to_cpu(rsp->max_write_zeroes_sectors));
} }
static int rnbd_clt_setup_gen_disk(struct rnbd_clt_dev *dev, 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, ...@@ -1626,10 +1628,11 @@ struct rnbd_clt_dev *rnbd_clt_map_device(const char *sessname,
} }
rnbd_clt_info(dev, rnbd_clt_info(dev,
"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", "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",
dev->gd->disk_name, le64_to_cpu(rsp->nsectors), dev->gd->disk_name, le64_to_cpu(rsp->nsectors),
le16_to_cpu(rsp->logical_block_size), le16_to_cpu(rsp->logical_block_size),
le16_to_cpu(rsp->physical_block_size), le16_to_cpu(rsp->physical_block_size),
le32_to_cpu(rsp->max_write_zeroes_sectors),
le32_to_cpu(rsp->max_discard_sectors), le32_to_cpu(rsp->max_discard_sectors),
le32_to_cpu(rsp->discard_granularity), le32_to_cpu(rsp->discard_granularity),
le32_to_cpu(rsp->discard_alignment), le32_to_cpu(rsp->discard_alignment),
......
...@@ -128,7 +128,7 @@ enum rnbd_cache_policy { ...@@ -128,7 +128,7 @@ enum rnbd_cache_policy {
* @device_id: device_id on server side to identify the device * @device_id: device_id on server side to identify the device
* @nsectors: number of sectors in the usual 512b unit * @nsectors: number of sectors in the usual 512b unit
* @max_hw_sectors: max hardware sectors in the usual 512b unit * @max_hw_sectors: max hardware sectors in the usual 512b unit
* @max_write_same_sectors: max sectors for WRITE SAME in the 512b unit * @max_write_zeroes_sectors: max sectors for WRITE ZEROES in the 512b unit
* @max_discard_sectors: max. sectors that can be discarded at once in 512b * @max_discard_sectors: max. sectors that can be discarded at once in 512b
* unit. * unit.
* @discard_granularity: size of the internal discard allocation unit in bytes * @discard_granularity: size of the internal discard allocation unit in bytes
...@@ -145,7 +145,7 @@ struct rnbd_msg_open_rsp { ...@@ -145,7 +145,7 @@ struct rnbd_msg_open_rsp {
__le32 device_id; __le32 device_id;
__le64 nsectors; __le64 nsectors;
__le32 max_hw_sectors; __le32 max_hw_sectors;
__le32 max_write_same_sectors; __le32 max_write_zeroes_sectors;
__le32 max_discard_sectors; __le32 max_discard_sectors;
__le32 discard_granularity; __le32 discard_granularity;
__le32 discard_alignment; __le32 discard_alignment;
...@@ -186,7 +186,7 @@ struct rnbd_msg_io { ...@@ -186,7 +186,7 @@ struct rnbd_msg_io {
* @RNBD_OP_FLUSH: flush the volatile write cache * @RNBD_OP_FLUSH: flush the volatile write cache
* @RNBD_OP_DISCARD: discard sectors * @RNBD_OP_DISCARD: discard sectors
* @RNBD_OP_SECURE_ERASE: securely erase sectors * @RNBD_OP_SECURE_ERASE: securely erase sectors
* @RNBD_OP_WRITE_SAME: write the same sectors many times * @RNBD_OP_WRITE_ZEROES: write zeroes sectors
* @RNBD_F_SYNC: request is sync (sync write or read) * @RNBD_F_SYNC: request is sync (sync write or read)
* @RNBD_F_FUA: forced unit access * @RNBD_F_FUA: forced unit access
...@@ -199,7 +199,7 @@ enum rnbd_io_flags { ...@@ -199,7 +199,7 @@ enum rnbd_io_flags {
RNBD_OP_FLUSH = 2, RNBD_OP_FLUSH = 2,
RNBD_OP_DISCARD = 3, RNBD_OP_DISCARD = 3,
RNBD_OP_SECURE_ERASE = 4, RNBD_OP_SECURE_ERASE = 4,
RNBD_OP_WRITE_SAME = 5, RNBD_OP_WRITE_ZEROES = 5,
/* Flags */ /* Flags */
RNBD_F_SYNC = 1<<(RNBD_OP_BITS + 0), RNBD_F_SYNC = 1<<(RNBD_OP_BITS + 0),
...@@ -236,6 +236,9 @@ static inline blk_opf_t rnbd_to_bio_flags(u32 rnbd_opf) ...@@ -236,6 +236,9 @@ static inline blk_opf_t rnbd_to_bio_flags(u32 rnbd_opf)
case RNBD_OP_SECURE_ERASE: case RNBD_OP_SECURE_ERASE:
bio_opf = REQ_OP_SECURE_ERASE; bio_opf = REQ_OP_SECURE_ERASE;
break; break;
case RNBD_OP_WRITE_ZEROES:
bio_opf = REQ_OP_WRITE_ZEROES;
break;
default: default:
WARN(1, "Unknown RNBD type: %d (flags %d)\n", WARN(1, "Unknown RNBD type: %d (flags %d)\n",
rnbd_op(rnbd_opf), rnbd_opf); rnbd_op(rnbd_opf), rnbd_opf);
...@@ -268,6 +271,9 @@ static inline u32 rq_to_rnbd_flags(struct request *rq) ...@@ -268,6 +271,9 @@ static inline u32 rq_to_rnbd_flags(struct request *rq)
case REQ_OP_SECURE_ERASE: case REQ_OP_SECURE_ERASE:
rnbd_opf = RNBD_OP_SECURE_ERASE; rnbd_opf = RNBD_OP_SECURE_ERASE;
break; break;
case REQ_OP_WRITE_ZEROES:
rnbd_opf = RNBD_OP_WRITE_ZEROES;
break;
case REQ_OP_FLUSH: case REQ_OP_FLUSH:
rnbd_opf = RNBD_OP_FLUSH; rnbd_opf = RNBD_OP_FLUSH;
break; break;
......
...@@ -544,7 +544,8 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp, ...@@ -544,7 +544,8 @@ static void rnbd_srv_fill_msg_open_rsp(struct rnbd_msg_open_rsp *rsp,
rsp->max_segments = cpu_to_le16(bdev_max_segments(bdev)); rsp->max_segments = cpu_to_le16(bdev_max_segments(bdev));
rsp->max_hw_sectors = rsp->max_hw_sectors =
cpu_to_le32(queue_max_hw_sectors(bdev_get_queue(bdev))); cpu_to_le32(queue_max_hw_sectors(bdev_get_queue(bdev)));
rsp->max_write_same_sectors = 0; rsp->max_write_zeroes_sectors =
cpu_to_le32(bdev_write_zeroes_sectors(bdev));
rsp->max_discard_sectors = cpu_to_le32(bdev_max_discard_sectors(bdev)); rsp->max_discard_sectors = cpu_to_le32(bdev_max_discard_sectors(bdev));
rsp->discard_granularity = cpu_to_le32(bdev_discard_granularity(bdev)); rsp->discard_granularity = cpu_to_le32(bdev_discard_granularity(bdev));
rsp->discard_alignment = cpu_to_le32(bdev_discard_alignment(bdev)); rsp->discard_alignment = cpu_to_le32(bdev_discard_alignment(bdev));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment