RFC: remove REQ_OP_WRITE_SAME
Subsystems (8)
Now that we are using REQ_OP_WRITE_ZEROES for all zeroing needs in the kernel there is very little use left for REQ_OP_WRITE_SAME. We only have two callers left, and both just export optional protocol features to remote systems: DRBD and the target code.
Do we have any major users of those? If not removing it will clean up a few warts in the block layer.
git://git.infradead.org/users/hch/block.git delete-write-same
Gitweb:
http://git.infradead.org/users/hch/block.git/shortlog/refs/heads/delete-write-same
PATCH 1/8 drbd: drop REQ_OP_WRITE_SAME support
Linux only used it for zeroing, for which we have better methods now.
--- drivers/block/drbd/drbd_main.c | 28 ++---------------- drivers/block/drbd/drbd_nl.c | 60 -------------------------------------- drivers/block/drbd/drbd_receiver.c | 38 +++--------------------- drivers/block/drbd/drbd_req.c | 1 - drivers/block/drbd/drbd_worker.c | 4 --- 5 files changed, 7 insertions(+), 124 deletions(-)
drivers/block/drbd/drbd_main.c +3 -25
@@ -931,7 +931,7 @@ void assign_p_sizes_qlim(struct drbd_device *device, struct p_sizes *p, struct r p->qlim->io_min =cpu_to_be32 (queue_io_min (q)); p->qlim->io_opt =cpu_to_be32 (queue_io_opt (q)); p->qlim->discard_enabled =blk_queue_discard (q); - p->qlim->write_same_capable = !!q->limits.max_write_same_sectors; + p->qlim->write_same_capable =0 ; }else { q = device->rq_queue; p->qlim->physical_block_size =cpu_to_be32 (queue_physical_block_size (q));
@@ -1610,9 +1610,6 @@ static int _drbd_send_bio(struct drbd_peer_device *peer_device, struct bio *bio) ? 0 : MSG_MORE);if (err)return err; -/* REQ_OP_WRITE_SAME has only one segment */ -if (bio_op (bio) ==REQ_OP_WRITE_SAME ) -break ; }return 0 ; }
@@ -1631,9 +1628,6 @@ static int _drbd_send_zc_bio(struct drbd_peer_device *peer_device, struct bio *b bio_iter_last(bvec, iter) ? 0 : MSG_MORE);if (err)return err; -/* REQ_OP_WRITE_SAME has only one segment */ -if (bio_op (bio) ==REQ_OP_WRITE_SAME ) -break ; }return 0 ; }
@@ -1665,7 +1659,6 @@ static u32 bio_flags_to_wire(struct drbd_connection *connection,return (bio->bi_opf &REQ_SYNC ?DP_RW_SYNC :0 ) | (bio->bi_opf &REQ_FUA ?DP_FUA :0 ) | (bio->bi_opf &REQ_PREFLUSH ?DP_FLUSH :0 ) | - (bio_op (bio) ==REQ_OP_WRITE_SAME ?DP_WSAME :0 ) | (bio_op (bio) ==REQ_OP_DISCARD ?DP_DISCARD :0 ) | (bio_op (bio) ==REQ_OP_WRITE_ZEROES ?DP_DISCARD :0 ); else
@@ -1680,7 +1673,6 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *struct drbd_device *device = peer_device->device;struct drbd_socket *sock;struct p_data *p; -struct p_wsame *wsame =NULL ;void *digest_out;unsigned int dp_flags =0 ;int digest_size;
@@ -1717,27 +1709,13 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request * err =__send_command (peer_device->connection, device->vnr, sock,P_TRIM ,sizeof (*t),NULL ,0 ); goto out; } -if (dp_flags &DP_WSAME ) { -/* this will only work if DRBD_FF_WSAME is set AND the -* handshake agreed that all nodes and backend devices are -* WRITE_SAME capable and agree on logical_block_size */ - wsame = (struct p_wsame *)p; - digest_out = wsame +1 ; - wsame->size =cpu_to_be32 (req->i.size); - }else - digest_out = p +1 ; + digest_out = p +1 ;/* our digest is still only over the payload. * TRIM does not carry any payload. */ if (digest_size)drbd_csum_bio (peer_device->connection->integrity_tfm, req->master_bio, digest_out); -if (wsame) { - err = -__send_command (peer_device->connection, device->vnr, sock,P_WSAME , -sizeof (*wsame) + digest_size,NULL , -bio_iovec (req->master_bio).bv_len); - }else - err = + err =__send_command (peer_device->connection, device->vnr, sock,P_DATA ,sizeof (*p) + digest_size,NULL , req->i.size);if (!err) {
drivers/block/drbd/drbd_nl.c +0 -60
72 lines not on this page · raw message
drivers/block/drbd/drbd_receiver.c +4 -34
@@ -1459,18 +1459,6 @@ static void drbd_issue_peer_discard(struct drbd_device *device, struct drbd_peerdrbd_endio_write_sec_final (peer_req); } -static void drbd_issue_peer_wsame (struct drbd_device *device, -struct drbd_peer_request *peer_req) -{ -struct block_device *bdev = device->ldev->backing_bdev; -sector_t s = peer_req->i.sector; -sector_t nr = peer_req->i.size >>9 ; -if (blkdev_issue_write_same (bdev, s, nr,GFP_NOIO , peer_req->pages)) - peer_req->flags |=EE_WAS_ERROR ; -drbd_endio_write_sec_final (peer_req); -} - -/** * drbd_submit_peer_request() * @device: DRBD device.
@@ -1508,7 +1496,7 @@ int drbd_submit_peer_request(struct drbd_device *device,* Correctness first, performance later. Next step is to code an * asynchronous variant of the same. */ -if (peer_req->flags & (EE_IS_TRIM |EE_WRITE_SAME )) { +if (peer_req->flags &EE_IS_TRIM ) {/* wait for all pending IO completions, before we start * zeroing things out. */ conn_wait_active_ee_empty (peer_req->peer_device->connection);
@@ -1527,8 +1515,6 @@ int drbd_submit_peer_request(struct drbd_device *device,if (peer_req->flags &EE_IS_TRIM )drbd_issue_peer_discard (device, peer_req); -else /* EE_WRITE_SAME */ -drbd_issue_peer_wsame (device, peer_req);return 0 ; }
@@ -1723,7 +1709,6 @@ read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector,void *dig_vv = peer_device->connection->int_dig_vv;unsigned long *data;struct p_trim *trim = (pi->cmd ==P_TRIM ) ? pi->data :NULL ; -struct p_trim *wsame = (pi->cmd ==P_WSAME ) ? pi->data :NULL ; digest_size =0 ;if (!trim && peer_device->connection->peer_integrity_tfm) {
@@ -1738,29 +1723,17 @@ read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector, data_size -= digest_size; } -/* assume request_size == data_size, but special case trim and wsame. */ +/* assume request_size == data_size, but special case trim. */ ds = data_size;if (trim) {if (!expect (data_size ==0 ))return NULL ; ds =be32_to_cpu (trim->size); - }else if (wsame) { -if (data_size !=queue_logical_block_size (device->rq_queue)) { -drbd_err (peer_device,"data size (%u) != drbd logical block size (%u)\n" , - data_size,queue_logical_block_size (device->rq_queue)); -return NULL ; - } -if (data_size !=bdev_logical_block_size (device->ldev->backing_bdev)) { -drbd_err (peer_device,"data size (%u) != backend logical block size (%u)\n" , - data_size,bdev_logical_block_size (device->ldev->backing_bdev)); -return NULL ; - } - ds =be32_to_cpu (wsame->size); }if (!expect (IS_ALIGNED (ds,512 )))return NULL ; -if (trim || wsame) { +if (trim) {if (!expect (ds <= (DRBD_MAX_BBIO_SECTORS <<9 )))return NULL ; }else if (!expect (ds <=DRBD_MAX_BIO_SIZE ))
@@ -1788,8 +1761,6 @@ read_in_block(struct drbd_peer_device *peer_device, u64 id, sector_t sector, peer_req->flags |=EE_IS_TRIM ;return peer_req; } -if (wsame) - peer_req->flags |=EE_WRITE_SAME ;/* receive payload size bytes into page chain */ ds = data_size;
@@ -2545,7 +2516,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info ** we wait for all pending requests, respectively wait for * active_ee to become empty in drbd_submit_peer_request(); * better not add ourselves here. */ -if ((peer_req->flags & (EE_IS_TRIM |EE_WRITE_SAME )) ==0 ) +if ((peer_req->flags &EE_IS_TRIM ) ==0 )list_add_tail (&peer_req->w.list, &device->active_ee);spin_unlock_irq (&device->resource->req_lock);
@@ -4869,7 +4840,6 @@ static struct data_cmd drbd_cmd_handler[] = { [P_PROTOCOL_UPDATE] = { 1, sizeof(struct p_protocol), receive_protocol }, [P_TRIM] = { 0, sizeof(struct p_trim), receive_Data }, [P_RS_DEALLOCATED] = { 0, sizeof(struct p_block_desc), receive_rs_deallocated }, - [P_WSAME] = { 1, sizeof(struct p_wsame), receive_Data }, };static void drbdd (struct drbd_connection *connection)
drivers/block/drbd/drbd_req.c +0 -1
@@ -58,7 +58,6 @@ static struct drbd_request *drbd_req_new(struct drbd_device *device, struct biodrbd_req_make_private_bio (req, bio_src); req->rq_state = (bio_data_dir (bio_src) ==WRITE ?RQ_WRITE :0 ) - | (bio_op (bio_src) ==REQ_OP_WRITE_SAME ?RQ_WSAME :0 ) | (bio_op (bio_src) ==REQ_OP_WRITE_ZEROES ?RQ_UNMAP :0 ) | (bio_op (bio_src) ==REQ_OP_DISCARD ?RQ_UNMAP :0 ); req->device = device;
drivers/block/drbd/drbd_worker.c +0 -4
@@ -330,10 +330,6 @@ void drbd_csum_bio(struct crypto_ahash *tfm, struct bio *bio, void *digest)sg_set_page (&sg, bvec.bv_page, bvec.bv_len, bvec.bv_offset);ahash_request_set_crypt (req, &sg,NULL , sg.length);crypto_ahash_update (req); -/* REQ_OP_WRITE_SAME has only one segment, -* checksum the payload only once. */ -if (bio_op (bio) ==REQ_OP_WRITE_SAME ) -break ; }ahash_request_set_crypt (req,NULL , digest,0 );crypto_ahash_final (req);
Signature · 1 line
2.11.0
PATCH 2/8 target: remove iblock WRITE_SAME passthrough support
In reply to Christoph HellwigUse the pscsi driver to support arbitrary command passthrough instead.
--- drivers/target/target_core_iblock.c | 34 ---------------------------------- 1 file changed, 34 deletions(-)
drivers/target/target_core_iblock.c +0 -34
@@ -415,39 +415,8 @@ iblock_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb) }static sense_reason_t -iblock_execute_write_same_direct (struct block_device *bdev,struct se_cmd *cmd) -{ -struct se_device *dev = cmd->se_dev; -struct scatterlist *sg = &cmd->t_data_sg[0 ]; -struct page *page =NULL ; -int ret; - -if (sg->offset) { - page =alloc_page (GFP_KERNEL ); -if (!page) -return TCM_OUT_OF_RESOURCES ; -sg_copy_to_buffer (sg, cmd->t_data_nents,page_address (page), - dev->dev_attrib.block_size); - } - - ret =blkdev_issue_write_same (bdev, -target_to_linux_sector (dev, cmd->t_task_lba), -target_to_linux_sector (dev, -sbc_get_write_same_sectors (cmd)), -GFP_KERNEL , page ? page :sg_page (sg)); -if (page) -__free_page (page); -if (ret) -return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ; - -target_complete_cmd (cmd,GOOD ); -return 0 ; -} - -static sense_reason_t iblock_execute_write_same (struct se_cmd *cmd) { -struct block_device *bdev =IBLOCK_DEV (cmd->se_dev)->ibd_bd;struct iblock_req *ibr;struct scatterlist *sg;struct bio *bio;
@@ -472,9 +441,6 @@ iblock_execute_write_same(struct se_cmd *cmd)return TCM_INVALID_CDB_FIELD ; } -if (bdev_write_same (bdev)) -return iblock_execute_write_same_direct (bdev, cmd); - ibr =kzalloc (sizeof (struct iblock_req ),GFP_KERNEL );if (!ibr) goto fail;
Signature · 1 line
2.11.0
Re: [PATCH 2/8] target: remove iblock WRITE_SAME passthrough support
Quoted 3 lines · Christoph Hellwig
Use the pscsi driver to support arbitrary command passthrough instead.
The people who are actively using iblock_execute_write_same_direct() are doing so in the context of ESX VAAI BlockZero, together with EXTENDED_COPY and COMPARE_AND_WRITE primitives. Just using PSCSI is not an option for them.
In practice though I've not seen any users of IBLOCK WRITE_SAME for anything other than VAAI BlockZero, so just using blkdev_issue_zeroout() when available, and falling back to iblock_execute_write_same() if the WRITE_SAME buffer contains anything other than zeros should be OK.
How about something like the following below..?
This would bring parity to how blkdev_issue_write_same() works atm wrt to synchronous bio completions. However, most folks with a raw make_request or blk-mq backend driver that supports multiple GB/sec of zero bandwidth end up changing IBLOCK to support asynchronous REQ_WRITE_SAME completions anyways.
I'd be happy to add support for that using __blkdev_issue_zeroout() once the basic conversion is in place.
From ff74012eaff38f9fa0d74aca60507b9964f484ce Mon Sep 17 00:00:00 2001
From: Nicholas Bellinger <[email protected]>
Date: Tue, 11 Apr 2017 22:21:47 -0700
Subject: [PATCH] target/iblock: Convert WRITE_SAME to blkdev_issue_zeroout
--- drivers/target/target_core_iblock.c | 44 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-)
drivers/target/target_core_iblock.c +27 -17
@@ -86,6 +86,7 @@ static int iblock_configure_device(struct se_device *dev)struct block_device *bd =NULL ;struct blk_integrity *bi;fmode_t mode; +unsigned int max_write_zeroes_sectors;int ret = -ENOMEM ;if (!(ib_dev->ibd_flags &IBDF_HAS_UDEV_PATH )) {
@@ -129,7 +130,11 @@ static int iblock_configure_device(struct se_device *dev)* Enable write same emulation for IBLOCK and use 0xFFFF as * the smaller WRITE_SAME(10) only has a two-byte block count. */ - dev->dev_attrib.max_write_same_len =0xFFFF ; + max_write_zeroes_sectors =bdev_write_zeroes_sectors (bd); +if (max_write_zeroes_sectors) + dev->dev_attrib.max_write_same_len = max_write_zeroes_sectors; +else + dev->dev_attrib.max_write_same_len =0xFFFF ;if (blk_queue_nonrot (q)) dev->dev_attrib.is_nonrot =1 ;
@@ -415,28 +420,31 @@ static void iblock_end_io_flush(struct bio *bio) }static sense_reason_t -iblock_execute_write_same_direct (struct block_device *bdev,struct se_cmd *cmd) +iblock_execute_zero_out (struct block_device *bdev,struct se_cmd *cmd) {struct se_device *dev = cmd->se_dev;struct scatterlist *sg = &cmd->t_data_sg[0 ]; -struct page *page =NULL ; -int ret; +unsigned char *buf, zero =0x00 , *p = &zero; +int rc, ret; -if (sg->offset) { - page =alloc_page (GFP_KERNEL ); -if (!page) -return TCM_OUT_OF_RESOURCES ; -sg_copy_to_buffer (sg, cmd->t_data_nents,page_address (page), - dev->dev_attrib.block_size); - } + buf =kmap (sg_page (sg)) + sg->offset; +if (!buf) +return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ; +/* +* Fall back to block_execute_write_same() slow-path if +* incoming WRITE_SAME payload does not contain zeros. +*/ + rc =memcmp (buf, p, cmd->data_length); +kunmap (sg_page (sg)); + +if (rc) +return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ; - ret =blkdev_issue_write_same (bdev, + ret =blkdev_issue_zeroout (bdev,target_to_linux_sector (dev, cmd->t_task_lba),target_to_linux_sector (dev,sbc_get_write_same_sectors (cmd)), -GFP_KERNEL , page ? page :sg_page (sg)); -if (page) -__free_page (page); +GFP_KERNEL , false);if (ret)return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ;
@@ -472,8 +480,10 @@ static void iblock_end_io_flush(struct bio *bio)return TCM_INVALID_CDB_FIELD ; } -if (bdev_write_same (bdev)) -return iblock_execute_write_same_direct (bdev, cmd); +if (bdev_write_zeroes_sectors (bdev)) { +if (!iblock_execute_zero_out (bdev, cmd)) +return 0 ; + } ibr =kzalloc (sizeof (struct iblock_req ),GFP_KERNEL );if (!ibr)
Re: [PATCH 2/8] target: remove iblock WRITE_SAME passthrough support
Hi Nic,
this patch looks fine, and I'll include it for the next post. I'll move some of the explanation in this mail into the patch, though.
Re: [PATCH 2/8] target: remove iblock WRITE_SAME passthrough support
In reply to Nicholas A. BellingerHey HCH & Jens,
Is this already queued up for v4.13 to address the missing LBPRZ feature bit..?
If not, I'll happy to take it via target-pending along with the following to re-enable it via max_write_zeroes_sectors.
drivers/target/target_core_device.c +1 -1
@@ -851,7 +851,7 @@ bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib, attrib->unmap_granularity = q->limits.discard_granularity / block_size; attrib->unmap_granularity_alignment = q->limits.discard_alignment / block_size; - attrib->unmap_zeroes_data =0 ; + attrib->unmap_zeroes_data = (q->limits.max_write_zeroes_sectors);return true; }EXPORT_SYMBOL (target_configure_unmap_from_queue);
Any objections..?
Quoted 120 lines · Nicholas A. Bellinger
Quoted 3 lines · Christoph Hellwig
Use the pscsi driver to support arbitrary command passthrough instead.
The people who are actively using
iblock_execute_write_same_direct()are doing so in the context of ESX VAAI BlockZero, together withEXTENDED_COPYandCOMPARE_AND_WRITEprimitives. Just using PSCSI is not an option for them.In practice though I've not seen any users of IBLOCK
WRITE_SAMEfor anything other than VAAI BlockZero, so just usingblkdev_issue_zeroout()when available, and falling back toiblock_execute_write_same()if theWRITE_SAMEbuffer contains anything other than zeros should be OK.How about something like the following below..?
This would bring parity to how
blkdev_issue_write_same()works atm wrt to synchronous bio completions. However, most folks with a rawmake_requestor blk-mq backend driver that supports multiple GB/sec of zero bandwidth end up changing IBLOCK to support asynchronousREQ_WRITE_SAMEcompletions anyways.I'd be happy to add support for that using
__blkdev_issue_zeroout()once the basic conversion is in place.From
ff74012eaff38f9fa0d74aca60507b9964f484ceMon Sep 17 00:00:00 2001
From: Nicholas Bellinger <[email protected]>
Date: Tue, 11 Apr 2017 22:21:47 -0700
Subject: [PATCH] target/iblock: ConvertWRITE_SAMEtoblkdev_issue_zerooutSigned-off-by Nicholas Bellinger <[email protected]>--- drivers/target/target_core_iblock.c | 44 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-)drivers/target/target_core_iblock.c +27
-17@@ -86,6 +86,7 @@ static int iblock_configure_device(struct se_device *dev)struct block_device *bd =NULL ;struct blk_integrity *bi;fmode_t mode; +unsigned int max_write_zeroes_sectors;int ret = -ENOMEM ;if (!(ib_dev->ibd_flags &IBDF_HAS_UDEV_PATH )) {@@ -129,7 +130,11 @@ static int iblock_configure_device(struct se_device *dev)* Enable write same emulation for IBLOCK and use 0xFFFF as * the smaller WRITE_SAME(10) only has a two-byte block count. */ - dev->dev_attrib.max_write_same_len =0xFFFF ; + max_write_zeroes_sectors =bdev_write_zeroes_sectors (bd); +if (max_write_zeroes_sectors) + dev->dev_attrib.max_write_same_len = max_write_zeroes_sectors; +else + dev->dev_attrib.max_write_same_len =0xFFFF ;if (blk_queue_nonrot (q)) dev->dev_attrib.is_nonrot =1 ;@@ -415,28 +420,31 @@ static void iblock_end_io_flush(struct bio *bio) }static sense_reason_t -iblock_execute_write_same_direct (struct block_device *bdev,struct se_cmd *cmd) +iblock_execute_zero_out (struct block_device *bdev,struct se_cmd *cmd) {struct se_device *dev = cmd->se_dev;struct scatterlist *sg = &cmd->t_data_sg[0 ]; -struct page *page =NULL ; -int ret; +unsigned char *buf, zero =0x00 , *p = &zero; +int rc, ret; -if (sg->offset) { - page =alloc_page (GFP_KERNEL ); -if (!page) -return TCM_OUT_OF_RESOURCES ; -sg_copy_to_buffer (sg, cmd->t_data_nents,page_address (page), - dev->dev_attrib.block_size); - } + buf =kmap (sg_page (sg)) + sg->offset; +if (!buf) +return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ; +/* +* Fall back to block_execute_write_same() slow-path if +* incoming WRITE_SAME payload does not contain zeros. +*/ + rc =memcmp (buf, p, cmd->data_length); +kunmap (sg_page (sg)); + +if (rc) +return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ; - ret =blkdev_issue_write_same (bdev, + ret =blkdev_issue_zeroout (bdev,target_to_linux_sector (dev, cmd->t_task_lba),target_to_linux_sector (dev,sbc_get_write_same_sectors (cmd)), -GFP_KERNEL , page ? page :sg_page (sg)); -if (page) -__free_page (page); +GFP_KERNEL , false);if (ret)return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ;@@ -472,8 +480,10 @@ static void iblock_end_io_flush(struct bio *bio)return TCM_INVALID_CDB_FIELD ; } -if (bdev_write_same (bdev)) -return iblock_execute_write_same_direct (bdev, cmd); +if (bdev_write_zeroes_sectors (bdev)) { +if (!iblock_execute_zero_out (bdev, cmd)) +return 0 ; + } ibr =kzalloc (sizeof (struct iblock_req ),GFP_KERNEL );if (!ibr)
Re: [PATCH 2/8] target: remove iblock WRITE_SAME passthrough support
Quoted 7 lines · Nicholas A. Bellinger
Hey HCH & Jens,
Is this already queued up for v4.13 to address the missing LBPRZ feature bit..?
If not, I'll happy to take it via target-pending along with the following to re-enable it via
max_write_zeroes_sectors.
It's not queued up. Feel free to take it through the target tree.
Re: [PATCH 2/8] target: remove iblock WRITE_SAME passthrough support
In reply to Nicholas A. BellingerQuoted 81 lines · Nicholas A. Bellinger
Quoted 3 lines · Christoph Hellwig
Use the pscsi driver to support arbitrary command passthrough instead.
The people who are actively using
iblock_execute_write_same_direct()are doing so in the context of ESX VAAI BlockZero, together withEXTENDED_COPYandCOMPARE_AND_WRITEprimitives. Just using PSCSI is not an option for them.In practice though I've not seen any users of IBLOCK
WRITE_SAMEfor anything other than VAAI BlockZero, so just usingblkdev_issue_zeroout()when available, and falling back toiblock_execute_write_same()if theWRITE_SAMEbuffer contains anything other than zeros should be OK.How about something like the following below..?
This would bring parity to how
blkdev_issue_write_same()works atm wrt to synchronous bio completions. However, most folks with a rawmake_requestor blk-mq backend driver that supports multiple GB/sec of zero bandwidth end up changing IBLOCK to support asynchronousREQ_WRITE_SAMEcompletions anyways.I'd be happy to add support for that using
__blkdev_issue_zeroout()once the basic conversion is in place.From
ff74012eaff38f9fa0d74aca60507b9964f484ceMon Sep 17 00:00:00 2001
From: Nicholas Bellinger <[email protected]>
Date: Tue, 11 Apr 2017 22:21:47 -0700
Subject: [PATCH] target/iblock: ConvertWRITE_SAMEtoblkdev_issue_zerooutSigned-off-by Nicholas Bellinger <[email protected]>--- drivers/target/target_core_iblock.c | 44 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-)drivers/target/target_core_iblock.c +9
-11@@ -86,6 +86,7 @@ static int iblock_configure_device(struct se_device *dev)struct block_device *bd =NULL ;struct blk_integrity *bi;fmode_t mode; +unsigned int max_write_zeroes_sectors;int ret = -ENOMEM ;if (!(ib_dev->ibd_flags &IBDF_HAS_UDEV_PATH )) {@@ -129,7 +130,11 @@ static int iblock_configure_device(struct se_device *dev)* Enable write same emulation for IBLOCK and use 0xFFFF as * the smaller WRITE_SAME(10) only has a two-byte block count. */ - dev->dev_attrib.max_write_same_len =0xFFFF ; + max_write_zeroes_sectors =bdev_write_zeroes_sectors (bd); +if (max_write_zeroes_sectors) + dev->dev_attrib.max_write_same_len = max_write_zeroes_sectors; +else + dev->dev_attrib.max_write_same_len =0xFFFF ;if (blk_queue_nonrot (q)) dev->dev_attrib.is_nonrot =1 ;@@ -415,28 +420,31 @@ static void iblock_end_io_flush(struct bio *bio) }static sense_reason_t -iblock_execute_write_same_direct (struct block_device *bdev,struct se_cmd *cmd) +iblock_execute_zero_out (struct block_device *bdev,struct se_cmd *cmd) {struct se_device *dev = cmd->se_dev;struct scatterlist *sg = &cmd->t_data_sg[0 ]; -struct page *page =NULL ; -int ret; +unsigned char *buf, zero =0x00 , *p = &zero; +int rc, ret; -if (sg->offset) { - page =alloc_page (GFP_KERNEL ); -if (!page) -return TCM_OUT_OF_RESOURCES ; -sg_copy_to_buffer (sg, cmd->t_data_nents,page_address (page), - dev->dev_attrib.block_size); - }
drivers/target/target_core_iblock.c static void iblock_end_io_flush(struct bio *bio) · line 439
Quoted 10 lines
drivers/target/target_core_iblock.c +10
-0+ buf =kmap (sg_page (sg)) + sg->offset; +if (!buf) +return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ; +/* +* Fall back to block_execute_write_same() slow-path if +* incoming WRITE_SAME payload does not contain zeros. +*/ + rc =memcmp (buf, p, cmd->data_length); +kunmap (sg_page (sg)); +
I recently pulled in this patch and I am getting:
[ 716.756756] ------------[ cut here ]------------
[ 716.756757] kernel BUG at /build/linux-hwe-edge-F6_Smd/linux-hwe-edge-4.13.0/lib/string.c:985!
[ 716.756762] Oops: Exception in kernel mode, sig: 5 [#1]
[ 716.756764] SMP NR_CPUS=2048
[ 716.756765] NUMA
[ 716.756767] pSeries
[ 716.756769] Modules linked in: hvcs(OE) hvcserver dm_snapshot dm_bufio ip6table_raw xt_CT xt_mac xt_tcpudp xt_comment xt_physdev xt_set ip_set_hash_net ip_set rpadlpar_io rpaphp iptable_raw target_core_pscsi(OE) target_core_file(OE) target_core_iblock(OE) iscsi_target_mod(OE) dccp_diag dccp tcp_diag udp_diag inet_diag unix_diag af_packet_diag netlink_diag vport_vxlan vxlan ip6_udp_tunnel udp_tunnel openvswitch nf_nat_ipv6 target_core_user(OE) uio binfmt_misc ibmvmc(OE) pseries_rng vmx_crypto crct10dif_vpmsum xt_conntrack nf_nat_ftp nf_conntrack_ftp nf_conntrack_netlink nfnetlink nf_conntrack_netbios_ns nf_conntrack_broadcast nf_conntrack_ipv6 nf_defrag_ipv6 nbd ipt_REJECT nf_reject_ipv4 ipt_MASQUERADE nf_nat_masquerade_ipv4 iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat
nf_conntrack
[ 716.756825] iptable_mangle iptable_filter ip_tables ip6table_filter ip6_tables ebtables x_tables br_netfilter bridge stp llc ib_iser rdma_cm iw_cm ib_cm ib_core iscsi_tcp libiscsi_tcp libiscsi scsi_transport_iscsi autofs4 btrfs raid10 raid456 async_raid6_recov async_memcpy async_pq async_xor async_tx xor raid6_pq raid1 raid0 multipath linear mlx4_en dm_round_robin ses enclosure scsi_transport_sas ibmvscsis(OE) target_core_mod(OE) ibmveth(OE) mlx5_core mlx4_core bnx2x mdio libcrc32c crc32c_vpmsum mlxfw ipr devlink tg3 scsi_dh_emc scsi_dh_rdac scsi_dh_alua dm_multipath
[ 716.756872] CPU: 1 PID: 3685 Comm: kworker/1:2 Tainted: G OE 4.13.0-16-generic #19~16.04.3-Ubuntu
[ 716.756880] Workqueue: ibmvscsis30000008 ibmvscsis_scheduler [ibmvscsis]
[ 716.756883] task: c0000001ee076a00 task.stack: c0000001b536c000
[ 716.756885] NIP: c000000000c26620 LR: c000000000c2661c CTR: 0000000000655170
[ 716.756888] REGS: c0000001b536f590 TRAP: 0700 Tainted: G OE (4.13.0-16-generic)
[ 716.756891] MSR: 800000000282b033 <SF,VEC,VSX,EE,FP,ME,IR,DR,RI,LE>
[ 716.756896] CR: 28482222 XER: 20000003
[ 716.756899] CFAR: c000000000179740 SOFTE: 1
GPR00: c000000000c2661c c0000001b536f810 c0000000015c2b00 0000000000000022
GPR04: c0000001f704ade8 c0000001f7062068 0000000000000003 ffffffffffffffff
GPR08: 0000000000000007 c0000000010d1a74 00000001f5f80000 0000000000000066
GPR12: 0000000000002200 c00000000fac0a80 c000000000129158 c0000001f2b5bb00
GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
GPR20: 0000000000000000 0000000000000000 0000000000000000 fffffffffffffef7
GPR24: 0000000000000000 f0000000007a82c0 00000000000003f0 0000000000648010
GPR28: c00000004394fbd0 c0000001f36c2780 c0000001ddb0e700 c0000001e391a000
[ 716.756932] NIP [c000000000c26620] fortify_panic+0x28/0x38
[ 716.756935] LR [c000000000c2661c] fortify_panic+0x24/0x38
[ 716.756937] Call Trace:
[ 716.756939] [c0000001b536f810] [c000000000c2661c] fortify_panic+0x24/0x38 (unreliable)
[ 716.756944] [c0000001b536f870] [d000000013c30bf8] iblock_execute_write_same+0x3b8/0x3c0 [target_core_iblock]
[ 716.756955] [c0000001b536f920] [d00000000b6537b4] __target_execute_cmd+0x54/0x150 [target_core_mod]
[ 716.756960] [c0000001b536f950] [d00000000b822c90] ibmvscsis_write_pending+0x70/0xc0 [ibmvscsis]
[ 716.756969] [c0000001b536f9c0] [d00000000b654f28] transport_generic_new_cmd+0x318/0x370 [target_core_mod]
[ 716.756979] [c0000001b536fa40] [d00000000b654fe4] transport_handle_cdb_direct+0x64/0xd0 [target_core_mod]
[ 716.756988] [c0000001b536fab0] [d00000000b6551f8] target_submit_cmd_map_sgls+0x1a8/0x320 [target_core_mod]
[ 716.756998] [c0000001b536fb40] [d00000000b6553b8] target_submit_cmd+0x48/0x60 [target_core_mod]
[ 716.757002] [c0000001b536fbe0] [d00000000b824bb0] ibmvscsis_scheduler+0x370/0x600 [ibmvscsis]
[ 716.757007] [c0000001b536fca0] [c0000000001200fc] process_one_work+0x1ec/0x580
[ 716.757010] [c0000001b536fd30] [c000000000120528] worker_thread+0x98/0x5d0
[ 716.757013] [c0000001b536fdc0] [c0000000001292bc] kthread+0x16c/0x1b0
[ 716.757017] [c0000001b536fe30] [c00000000000b4e8] ret_from_kernel_thread+0x5c/0x74
[ 716.757020] Instruction dump:
[ 716.757022] 7c0803a6 4e800020 3c4c009a 3842c508 7c0802a6 f8010010 f821ffa1 7c641b78
[ 716.757027] 3c62ff98 3863e8b8 4b5530dd 60000000 <0fe00000> 00000000 00000000 00000000
[ 716.757033] ---[ end trace 1f1264fedf09f0b7 ]---It looks like memcmp is throwing the fortify panic due to size of ptrs being incorrectly determined at compile time.
-Bryant
PATCH 3/8 sd: remove write same support
In reply to Christoph HellwigThere are no more end-users of REQ_OP_WRITE_SAME left, so we can start deleting it.
--- drivers/scsi/sd.c | 70 --------------------------------------------------- drivers/scsi/sd_zbc.c | 1 - 2 files changed, 71 deletions(-)
drivers/scsi/sd.c +0 -70
@@ -878,77 +878,10 @@ static void sd_config_write_same(struct scsi_disk *sdkp) sdkp->zeroing_mode =SD_ZERO_WRITE ; out: -blk_queue_max_write_same_sectors (q, sdkp->max_ws_blocks * - (logical_block_size >>9 ));blk_queue_max_write_zeroes_sectors (q, sdkp->max_ws_blocks * (logical_block_size >>9 )); } -/** -* sd_setup_write_same_cmnd - write the same data to multiple blocks -* @cmd: command to prepare -* -* Will issue either WRITE SAME(10) or WRITE SAME(16) depending on -* preference indicated by target device. -**/ -static int sd_setup_write_same_cmnd (struct scsi_cmnd *cmd) -{ -struct request *rq = cmd->request; -struct scsi_device *sdp = cmd->device; -struct scsi_disk *sdkp =scsi_disk (rq->rq_disk); -struct bio *bio = rq->bio; -sector_t sector =blk_rq_pos (rq); -unsigned int nr_sectors =blk_rq_sectors (rq); -unsigned int nr_bytes =blk_rq_bytes (rq); -int ret; - -if (sdkp->device->no_write_same) -return BLKPREP_INVALID ; - -BUG_ON (bio_offset (bio) ||bio_iovec (bio).bv_len != sdp->sector_size); - -if (sd_is_zoned (sdkp)) { - ret =sd_zbc_setup_write_cmnd (cmd); -if (ret !=BLKPREP_OK ) -return ret; - } - - sector >>=ilog2 (sdp->sector_size) -9 ; - nr_sectors >>=ilog2 (sdp->sector_size) -9 ; - - rq->timeout =SD_WRITE_SAME_TIMEOUT ; - -if (sdkp->ws16 || sector >0xffffffff || nr_sectors >0xffff ) { - cmd->cmd_len =16 ; - cmd->cmnd[0 ] =WRITE_SAME_16 ; -put_unaligned_be64 (sector, &cmd->cmnd[2 ]); -put_unaligned_be32 (nr_sectors, &cmd->cmnd[10 ]); - }else { - cmd->cmd_len =10 ; - cmd->cmnd[0 ] =WRITE_SAME ; -put_unaligned_be32 (sector, &cmd->cmnd[2 ]); -put_unaligned_be16 (nr_sectors, &cmd->cmnd[7 ]); - } - - cmd->transfersize = sdp->sector_size; - cmd->allowed =SD_MAX_RETRIES ; - -/* -* For WRITE SAME the data transferred via the DATA OUT buffer is -* different from the amount of data actually written to the target. -* -* We set up __data_len to the amount of data transferred via the -* DATA OUT buffer so that blk_rq_map_sg sets up the proper S/G list -* to transfer a single sector of data first, but then reset it to -* the amount of data to be written right after so that the I/O path -* knows how much to actually write. -*/ - rq->__data_len = sdp->sector_size; - ret =scsi_init_io (cmd); - rq->__data_len = nr_bytes; -return ret; -} -static int sd_setup_flush_cmnd (struct scsi_cmnd *cmd) {struct request *rq = cmd->request;
@@ -1232,8 +1165,6 @@ static int sd_init_command(struct scsi_cmnd *cmd) }case REQ_OP_WRITE_ZEROES :return sd_setup_write_zeroes_cmnd (cmd); -case REQ_OP_WRITE_SAME : -return sd_setup_write_same_cmnd (cmd);case REQ_OP_FLUSH :return sd_setup_flush_cmnd (cmd);case REQ_OP_READ :
@@ -1872,7 +1803,6 @@ static int sd_done(struct scsi_cmnd *SCpnt)switch (req_op (req)) {case REQ_OP_DISCARD :case REQ_OP_WRITE_ZEROES : -case REQ_OP_WRITE_SAME :case REQ_OP_ZONE_RESET :if (!result) { good_bytes =blk_rq_bytes (req);
drivers/scsi/sd_zbc.c +0 -1
@@ -330,7 +330,6 @@ void sd_zbc_complete(struct scsi_cmnd *cmd,switch (req_op (rq)) {case REQ_OP_WRITE :case REQ_OP_WRITE_ZEROES : -case REQ_OP_WRITE_SAME :case REQ_OP_ZONE_RESET :/* Unlock the zone */
Signature · 1 line
2.11.0
PATCH 4/8 md: drop WRITE_SAME support
In reply to Christoph Hellwig--- drivers/md/linear.c | 1 - drivers/md/md.h | 7 ------- drivers/md/multipath.c | 1 - drivers/md/raid0.c | 2 -- drivers/md/raid1.c | 4 +--- drivers/md/raid10.c | 1 - drivers/md/raid5.c | 1 - 7 files changed, 1 insertion(+), 16 deletions(-)
drivers/md/linear.c +0 -1
@@ -292,7 +292,6 @@ static void linear_make_request(struct mddev *mddev, struct bio *bio)trace_block_bio_remap (bdev_get_queue (split->bi_bdev), split,disk_devt (mddev->gendisk), bio_sector); -mddev_check_writesame (mddev, split);mddev_check_write_zeroes (mddev, split);generic_make_request (split); }
drivers/md/md.h +0 -7
@@ -703,13 +703,6 @@ static inline void mddev_clear_unsupported_flags(struct mddev *mddev, mddev->flags &= ~unsupported_flags; } -static inline void mddev_check_writesame (struct mddev *mddev,struct bio *bio) -{ -if (bio_op (bio) ==REQ_OP_WRITE_SAME && - !bdev_get_queue (bio->bi_bdev)->limits.max_write_same_sectors) - mddev->queue->limits.max_write_same_sectors =0 ; -} -static inline void mddev_check_write_zeroes (struct mddev *mddev,struct bio *bio) { if (bio_op(bio) == REQ_OP_WRITE_ZEROES &&
drivers/md/multipath.c +0 -1
@@ -138,7 +138,6 @@ static void multipath_make_request(struct mddev *mddev, struct bio * bio) mp_bh->bio.bi_opf |=REQ_FAILFAST_TRANSPORT ; mp_bh->bio.bi_end_io = multipath_end_request; mp_bh->bio.bi_private = mp_bh; -mddev_check_writesame (mddev, &mp_bh->bio);mddev_check_write_zeroes (mddev, &mp_bh->bio);generic_make_request (&mp_bh->bio);return ;
drivers/md/raid0.c +0 -2
@@ -382,7 +382,6 @@ static int raid0_run(struct mddev *mddev)bool discard_supported = false;blk_queue_max_hw_sectors (mddev->queue, mddev->chunk_sectors); -blk_queue_max_write_same_sectors (mddev->queue, mddev->chunk_sectors);blk_queue_max_write_zeroes_sectors (mddev->queue, mddev->chunk_sectors);blk_queue_max_discard_sectors (mddev->queue, mddev->chunk_sectors);
@@ -504,7 +503,6 @@ static void raid0_make_request(struct mddev *mddev, struct bio *bio)trace_block_bio_remap (bdev_get_queue (split->bi_bdev), split,disk_devt (mddev->gendisk), bio_sector); -mddev_check_writesame (mddev, split);mddev_check_write_zeroes (mddev, split);generic_make_request (split); }
drivers/md/raid1.c +1 -3
@@ -3177,10 +3177,8 @@ static int raid1_run(struct mddev *mddev)if (IS_ERR (conf))return PTR_ERR (conf); -if (mddev->queue) { -blk_queue_max_write_same_sectors (mddev->queue,0 ); +if (mddev->queue)blk_queue_max_write_zeroes_sectors (mddev->queue,0 ); - }rdev_for_each (rdev, mddev) {if (!mddev->gendisk)
drivers/md/raid10.c +0 -1
@@ -3748,7 +3748,6 @@ static int raid10_run(struct mddev *mddev)if (mddev->queue) {blk_queue_max_discard_sectors (mddev->queue, mddev->chunk_sectors); -blk_queue_max_write_same_sectors (mddev->queue,0 );blk_queue_max_write_zeroes_sectors (mddev->queue,0 );blk_queue_io_min (mddev->queue, chunk_size);if (conf->geo.raid_disks % conf->geo.near_copies)
drivers/md/raid5.c +0 -1
@@ -7262,7 +7262,6 @@ static int raid5_run(struct mddev *mddev)blk_queue_max_discard_sectors (mddev->queue,0xfffe *STRIPE_SECTORS ); -blk_queue_max_write_same_sectors (mddev->queue,0 );blk_queue_max_write_zeroes_sectors (mddev->queue,0 );rdev_for_each (rdev, mddev) {
Signature · 1 line
2.11.0
PATCH 5/8 dm: remove write same support
In reply to Christoph Hellwig--- drivers/md/dm-core.h | 1 - drivers/md/dm-io.c | 21 +-------------------- drivers/md/dm-linear.c | 1 - drivers/md/dm-mpath.c | 1 - drivers/md/dm-rq.c | 3 --- drivers/md/dm-stripe.c | 4 +--- drivers/md/dm-table.c | 29 ----------------------------- drivers/md/dm.c | 23 ----------------------- include/linux/device-mapper.h | 6 ------ 9 files changed, 2 insertions(+), 87 deletions(-)
drivers/md/dm-core.h +0 -1
@@ -131,7 +131,6 @@ struct mapped_device {void dm_init_md_queue (struct mapped_device *md);void dm_init_normal_md_queue (struct mapped_device *md);int md_in_flight (struct mapped_device *md); -void disable_write_same (struct mapped_device *md);void disable_write_zeroes (struct mapped_device *md);static inline struct completion *dm_get_completion_from_kobject (struct kobject *kobj)
drivers/md/dm-io.c +1 -20
@@ -303,7 +303,6 @@ static void do_region(int op, int op_flags, unsigned region,unsigned num_bvecs;sector_t remaining = where->count;struct request_queue *q =bdev_get_queue (where->bdev); -unsigned short logical_block_size =queue_logical_block_size (q);sector_t num_sectors;unsigned int uninitialized_var (special_cmd_max_sectors );
@@ -314,10 +313,7 @@ static void do_region(int op, int op_flags, unsigned region, special_cmd_max_sectors = q->limits.max_discard_sectors; else if (op == REQ_OP_WRITE_ZEROES) special_cmd_max_sectors = q->limits.max_write_zeroes_sectors; - else if (op == REQ_OP_WRITE_SAME) - special_cmd_max_sectors = q->limits.max_write_same_sectors; -if ((op ==REQ_OP_DISCARD || op ==REQ_OP_WRITE_ZEROES || - op ==REQ_OP_WRITE_SAME ) && +if ((op ==REQ_OP_DISCARD || op ==REQ_OP_WRITE_ZEROES ) && special_cmd_max_sectors ==0 ) {dec_count (io, region, -EOPNOTSUPP );return ;
@@ -336,9 +332,6 @@ static void do_region(int op, int op_flags, unsigned region,case REQ_OP_WRITE_ZEROES : num_bvecs =0 ;break ; -case REQ_OP_WRITE_SAME : - num_bvecs =1 ; -break ;default : num_bvecs =min_t (int,BIO_MAX_PAGES ,dm_sector_div_up (remaining, (PAGE_SIZE >>SECTOR_SHIFT )));
@@ -355,18 +348,6 @@ static void do_region(int op, int op_flags, unsigned region, num_sectors =min_t (sector_t, special_cmd_max_sectors, remaining); bio->bi_iter.bi_size = num_sectors <<SECTOR_SHIFT ; remaining -= num_sectors; - }else if (op ==REQ_OP_WRITE_SAME ) { -/* -* WRITE SAME only uses a single page. -*/ - dp->get_page (dp, &page, &len, &offset); -bio_add_page (bio, page, logical_block_size, offset); - num_sectors =min_t (sector_t, special_cmd_max_sectors, remaining); - bio->bi_iter.bi_size = num_sectors <<SECTOR_SHIFT ; - - offset =0 ; - remaining -= num_sectors; - dp->next_page (dp); }else while (remaining) {/* * Try and add as many pages as possible.
drivers/md/dm-linear.c +0 -1
@@ -58,7 +58,6 @@ static int linear_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->num_flush_bios =1 ; ti->num_discard_bios =1 ; - ti->num_write_same_bios =1 ; ti->num_write_zeroes_bios =1 ; ti->private = lc;return 0 ;
drivers/md/dm-mpath.c +0 -1
@@ -1102,7 +1102,6 @@ static int multipath_ctr(struct dm_target *ti, unsigned argc, char **argv) ti->num_flush_bios =1 ; ti->num_discard_bios =1 ; - ti->num_write_same_bios =1 ; ti->num_write_zeroes_bios =1 ;if (m->queue_mode ==DM_TYPE_BIO_BASED ) ti->per_io_data_size =multipath_per_bio_data_size ();
drivers/md/dm-rq.c +0 -3
@@ -299,9 +299,6 @@ static void dm_done(struct request *clone, int error, bool mapped) }if (unlikely (r == -EREMOTEIO )) { -if (req_op (clone) ==REQ_OP_WRITE_SAME && - !clone->q->limits.max_write_same_sectors) -disable_write_same (tio->md);if (req_op (clone) ==REQ_OP_WRITE_ZEROES && !clone->q->limits.max_write_zeroes_sectors)disable_write_zeroes (tio->md);
drivers/md/dm-stripe.c +1 -3
@@ -168,7 +168,6 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->num_flush_bios = stripes; ti->num_discard_bios = stripes; - ti->num_write_same_bios = stripes; ti->num_write_zeroes_bios = stripes; sc->chunk_size = chunk_size;
@@ -294,8 +293,7 @@ static int stripe_map(struct dm_target *ti, struct bio *bio)return DM_MAPIO_REMAPPED ; }if (unlikely (bio_op (bio) ==REQ_OP_DISCARD ) || -unlikely (bio_op (bio) ==REQ_OP_WRITE_ZEROES ) || -unlikely (bio_op (bio) ==REQ_OP_WRITE_SAME )) { +unlikely (bio_op (bio) ==REQ_OP_WRITE_ZEROES )) { target_bio_nr =dm_bio_get_target_bio_nr (bio);BUG_ON (target_bio_nr >= sc->stripes);return stripe_map_range (sc, bio, target_bio_nr);
drivers/md/dm-table.c +0 -29
@@ -1490,33 +1490,6 @@ static bool dm_table_all_devices_attribute(struct dm_table *t,return true; } -static int device_not_write_same_capable (struct dm_target *ti,struct dm_dev *dev, -sector_t start,sector_t len,void *data) -{ -struct request_queue *q =bdev_get_queue (dev->bdev); - -return q && !q->limits.max_write_same_sectors; -} - -static bool dm_table_supports_write_same (struct dm_table *t) -{ -struct dm_target *ti; -unsigned i =0 ; - -while (i <dm_table_get_num_targets (t)) { - ti =dm_table_get_target (t, i++); - -if (!ti->num_write_same_bios) -return false; - -if (!ti->type->iterate_devices || - ti->type->iterate_devices (ti, device_not_write_same_capable,NULL )) -return false; - } - -return true; -} -static int device_not_write_zeroes_capable (struct dm_target *ti,struct dm_dev *dev,sector_t start,sector_t len,void *data) {
@@ -1610,8 +1583,6 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,else queue_flag_clear_unlocked (QUEUE_FLAG_NONROT , q); -if (!dm_table_supports_write_same (t)) - q->limits.max_write_same_sectors =0 ;if (!dm_table_supports_write_zeroes (t)) q->limits.max_write_zeroes_sectors =0 ;
drivers/md/dm.c +0 -23
@@ -816,14 +816,6 @@ static void dec_pending(struct dm_io *io, int error) } } -void disable_write_same (struct mapped_device *md) -{ -struct queue_limits *limits =dm_get_queue_limits (md); - -/* device doesn't really support WRITE SAME, disable it */ - limits->max_write_same_sectors =0 ; -} -void disable_write_zeroes (struct mapped_device *md) {struct queue_limits *limits =dm_get_queue_limits (md);
@@ -859,9 +851,6 @@ static void clone_endio(struct bio *bio) }if (unlikely (r == -EREMOTEIO )) { -if (bio_op (bio) ==REQ_OP_WRITE_SAME && - !bdev_get_queue (bio->bi_bdev)->limits.max_write_same_sectors) -disable_write_same (md);if (bio_op (bio) ==REQ_OP_WRITE_ZEROES && !bdev_get_queue (bio->bi_bdev)->limits.max_write_zeroes_sectors)disable_write_zeroes (md);
@@ -1209,11 +1198,6 @@ static unsigned get_num_discard_bios(struct dm_target *ti)return ti->num_discard_bios; } -static unsigned get_num_write_same_bios (struct dm_target *ti) -{ -return ti->num_write_same_bios; -} -static unsigned get_num_write_zeroes_bios (struct dm_target *ti) {return ti->num_write_zeroes_bios;
@@ -1268,11 +1252,6 @@ static int __send_discard(struct clone_info *ci) is_split_required_for_discard); } -static int __send_write_same (struct clone_info *ci) -{ -return __send_changing_extent_only (ci, get_num_write_same_bios,NULL ); -} -static int __send_write_zeroes (struct clone_info *ci) {return __send_changing_extent_only (ci, get_num_write_zeroes_bios,NULL );
@@ -1290,8 +1269,6 @@ static int __split_and_process_non_flush(struct clone_info *ci)if (unlikely (bio_op (bio) ==REQ_OP_DISCARD ))return __send_discard (ci); -else if (unlikely (bio_op (bio) ==REQ_OP_WRITE_SAME )) -return __send_write_same (ci);else if (unlikely (bio_op (bio) ==REQ_OP_WRITE_ZEROES ))return __send_write_zeroes (ci);
include/linux/device-mapper.h +0 -6
@@ -249,12 +249,6 @@ struct dm_target {unsigned num_discard_bios;/* -* The number of WRITE SAME bios that will be submitted to the target. -* The bio number can be accessed with dm_bio_get_target_bio_nr. -*/ -unsigned num_write_same_bios; - -/* * The number of WRITE ZEROES bios that will be submitted to the target. * The bio number can be accessed with dm_bio_get_target_bio_nr. */
Signature · 1 line
2.11.0
PATCH 6/8 block: remove REQ_OP_WRITE_SAME support
In reply to Christoph Hellwig--- block/bio.c | 3 -- block/blk-core.c | 11 +----- block/blk-lib.c | 90 --------------------------------------------- block/blk-merge.c | 32 ---------------- block/blk-settings.c | 16 -------- block/blk-sysfs.c | 12 ------ include/linux/bio.h | 3 -- include/linux/blk_types.h | 4 +- include/linux/blkdev.h | 26 ------------- include/trace/events/f2fs.h | 1 - kernel/trace/blktrace.c | 1 - 11 files changed, 2 insertions(+), 197 deletions(-)
block/bio.c +0 -3
@@ -684,9 +684,6 @@ static struct bio *__bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask,case REQ_OP_SECURE_ERASE :case REQ_OP_WRITE_ZEROES :break ; -case REQ_OP_WRITE_SAME : - bio->bi_io_vec[bio->bi_vcnt++] = bio_src->bi_io_vec[0 ]; -break ;default :__bio_for_each_segment (bv, bio_src, iter, iter_src) bio->bi_io_vec[bio->bi_vcnt++] = bv;
block/blk-core.c +1 -10
@@ -1929,10 +1929,6 @@ generic_make_request_checks(struct bio *bio)if (!blk_queue_secure_erase (q)) goto not_supported;break ; -case REQ_OP_WRITE_SAME : -if (!bdev_write_same (bio->bi_bdev)) - goto not_supported; -break ;case REQ_OP_ZONE_REPORT :case REQ_OP_ZONE_RESET :if (!bdev_is_zoned (bio->bi_bdev))
@@ -2100,12 +2096,7 @@ blk_qc_t submit_bio(struct bio *bio)* go through the normal accounting stuff before submission. */ if (bio_has_data (bio)) { -unsigned int count; - -if (unlikely (bio_op (bio) ==REQ_OP_WRITE_SAME )) - count =bdev_logical_block_size (bio->bi_bdev) >>9 ; -else - count =bio_sectors (bio); +unsigned int count =bio_sectors (bio);if (op_is_write (bio_op (bio))) {count_vm_events (PGPGOUT , count);
block/blk-lib.c +0 -90
96 lines not on this page · raw message
block/blk-merge.c +0 -32
@@ -68,22 +68,6 @@ static struct bio *blk_bio_write_zeroes_split(struct request_queue *q,return bio_split (bio, q->limits.max_write_zeroes_sectors,GFP_NOIO , bs); } -static struct bio *blk_bio_write_same_split (struct request_queue *q, -struct bio *bio, -struct bio_set *bs, -unsigned *nsegs) -{ - *nsegs =1 ; - -if (!q->limits.max_write_same_sectors) -return NULL ; - -if (bio_sectors (bio) <= q->limits.max_write_same_sectors) -return NULL ; - -return bio_split (bio, q->limits.max_write_same_sectors,GFP_NOIO , bs); -} -static inline unsigned get_max_io_size (struct request_queue *q,struct bio *bio) {
@@ -216,9 +200,6 @@ void blk_queue_split(struct request_queue *q, struct bio **bio,case REQ_OP_WRITE_ZEROES : split =blk_bio_write_zeroes_split (q, *bio, bs, &nsegs);break ; -case REQ_OP_WRITE_SAME : - split =blk_bio_write_same_split (q, *bio, bs, &nsegs); -break ;default : split =blk_bio_segment_split (q, *bio, q->bio_split, &nsegs);break ;
@@ -259,8 +240,6 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,case REQ_OP_SECURE_ERASE :case REQ_OP_WRITE_ZEROES :return 0 ; -case REQ_OP_WRITE_SAME : -return 1 ; } fbio = bio;
@@ -454,8 +433,6 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,if (rq->rq_flags &RQF_SPECIAL_PAYLOAD ) nsegs =__blk_bvec_map_sg (q, rq->special_vec, sglist, &sg); -else if (rq->bio &&bio_op (rq->bio) ==REQ_OP_WRITE_SAME ) - nsegs =__blk_bvec_map_sg (q,bio_iovec (rq->bio), sglist, &sg);else if (rq->bio) nsegs =__blk_bios_map_sg (q, rq->bio, sglist, &sg);
@@ -688,10 +665,6 @@ static struct request *attempt_merge(struct request_queue *q, || req_no_special_merge(next))return NULL ; -if (req_op (req) ==REQ_OP_WRITE_SAME && - !blk_write_same_mergeable (req->bio, next->bio)) -return NULL ; -/* * If we are allowed to merge, then append bio list * from next to rq and release next. merge_requests_fn
@@ -806,11 +779,6 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)if (blk_integrity_merge_bio (rq->q, rq, bio) == false)return false; -/* must be using the same buffer */ -if (req_op (rq) ==REQ_OP_WRITE_SAME && - !blk_write_same_mergeable (rq->bio, bio)) -return false; -return true; }
block/blk-settings.c +0 -16
@@ -96,7 +96,6 @@ void blk_set_default_limits(struct queue_limits *lim) lim->max_sectors = lim->max_hw_sectors =BLK_SAFE_MAX_SECTORS ; lim->max_dev_sectors =0 ; lim->chunk_sectors =0 ; - lim->max_write_same_sectors =0 ; lim->max_write_zeroes_sectors =0 ; lim->max_discard_sectors =0 ; lim->max_hw_discard_sectors =0 ;
@@ -132,7 +131,6 @@ void blk_set_stacking_limits(struct queue_limits *lim) lim->max_segment_size =UINT_MAX ; lim->max_sectors =UINT_MAX ; lim->max_dev_sectors =UINT_MAX ; - lim->max_write_same_sectors =UINT_MAX ; lim->max_write_zeroes_sectors =UINT_MAX ; }EXPORT_SYMBOL (blk_set_stacking_limits);
@@ -291,18 +289,6 @@ void blk_queue_max_discard_sectors(struct request_queue *q,EXPORT_SYMBOL (blk_queue_max_discard_sectors);/** -* blk_queue_max_write_same_sectors - set max sectors for a single write same -* @q: the request queue for the device -* @max_write_same_sectors: maximum number of sectors to write per command -**/ -void blk_queue_max_write_same_sectors (struct request_queue *q, -unsigned int max_write_same_sectors) -{ - q->limits.max_write_same_sectors = max_write_same_sectors; -} -EXPORT_SYMBOL (blk_queue_max_write_same_sectors); - -/** * blk_queue_max_write_zeroes_sectors - set max sectors for a single * write zeroes * @q: the request queue for the device
@@ -557,8 +543,6 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, t->max_sectors =min_not_zero (t->max_sectors, b->max_sectors); t->max_hw_sectors =min_not_zero (t->max_hw_sectors, b->max_hw_sectors); t->max_dev_sectors =min_not_zero (t->max_dev_sectors, b->max_dev_sectors); - t->max_write_same_sectors =min (t->max_write_same_sectors, - b->max_write_same_sectors); t->max_write_zeroes_sectors =min (t->max_write_zeroes_sectors, b->max_write_zeroes_sectors); t->bounce_pfn =min_not_zero (t->bounce_pfn, b->bounce_pfn);
block/blk-sysfs.c +0 -12
@@ -211,12 +211,6 @@ static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *pagreturn queue_var_show (0 , page); } -static ssize_t queue_write_same_max_show (struct request_queue *q,char *page) -{ -return sprintf (page,"%llu\n" , - (unsigned long long )q->limits.max_write_same_sectors <<9 ); -} -static ssize_t queue_write_zeroes_max_show (struct request_queue *q,char *page) { return sprintf(page, "%llu\n",
@@ -603,11 +597,6 @@ static struct queue_sysfs_entry queue_discard_zeroes_data_entry = { .show = queue_discard_zeroes_data_show, }; -static struct queue_sysfs_entry queue_write_same_max_entry = { - .attr = {.name ="write_same_max_bytes" , .mode =S_IRUGO }, - .show = queue_write_same_max_show, -}; -static struct queue_sysfs_entry queue_write_zeroes_max_entry = { .attr = {.name ="write_zeroes_max_bytes" , .mode =S_IRUGO }, .show = queue_write_zeroes_max_show,
@@ -705,7 +694,6 @@ static struct attribute *default_attrs[] = { &queue_discard_max_entry.attr, &queue_discard_max_hw_entry.attr, &queue_discard_zeroes_data_entry.attr, - &queue_write_same_max_entry.attr, &queue_write_zeroes_max_entry.attr, &queue_nonrot_entry.attr, &queue_zoned_entry.attr,
include/linux/bio.h +0 -3
@@ -87,7 +87,6 @@ static inline bool bio_no_advance_iter(struct bio *bio) {return bio_op (bio) ==REQ_OP_DISCARD ||bio_op (bio) ==REQ_OP_SECURE_ERASE || -bio_op (bio) ==REQ_OP_WRITE_SAME ||bio_op (bio) ==REQ_OP_WRITE_ZEROES ; }
@@ -199,8 +198,6 @@ static inline unsigned __bio_segments(struct bio *bio, struct bvec_iter *bvec)case REQ_OP_SECURE_ERASE :case REQ_OP_WRITE_ZEROES :return 0 ; -case REQ_OP_WRITE_SAME : -return 1 ;default :break ; }
include/linux/blk_types.h +1 -3
@@ -171,10 +171,8 @@ enum req_opf {REQ_OP_SECURE_ERASE =5 ,/* seset a zone write pointer */ REQ_OP_ZONE_RESET =6 , -/* write the same sector many times */ -REQ_OP_WRITE_SAME =7 ,/* write the zero filled sector many times */ -REQ_OP_WRITE_ZEROES =9 , +REQ_OP_WRITE_ZEROES =7 ,/* SCSI passthrough using struct scsi_request */ REQ_OP_SCSI_IN = 32,
include/linux/blkdev.h +0 -26
@@ -326,7 +326,6 @@ struct queue_limits {unsigned int io_opt;unsigned int max_discard_sectors;unsigned int max_hw_discard_sectors; -unsigned int max_write_same_sectors;unsigned int max_write_zeroes_sectors;unsigned int discard_granularity;unsigned int discard_alignment;
@@ -806,14 +805,6 @@ static inline bool rq_mergeable(struct request *rq)return true; } -static inline bool blk_write_same_mergeable (struct bio *a,struct bio *b) -{ -if (bio_data (a) ==bio_data (b)) -return true; - -return false; -} -static inline unsigned int blk_queue_depth (struct request_queue *q) {if (q->queue_depth)
@@ -1035,9 +1026,6 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,if (unlikely (op ==REQ_OP_DISCARD || op ==REQ_OP_SECURE_ERASE ))return min (q->limits.max_discard_sectors,UINT_MAX >>9 ); -if (unlikely (op ==REQ_OP_WRITE_SAME )) -return q->limits.max_write_same_sectors; -if (unlikely (op ==REQ_OP_WRITE_ZEROES ))return q->limits.max_write_zeroes_sectors;
@@ -1157,8 +1145,6 @@ extern void blk_queue_max_discard_segments(struct request_queue *,extern void blk_queue_max_segment_size (struct request_queue *,unsigned int );extern void blk_queue_max_discard_sectors (struct request_queue *q,unsigned int max_discard_sectors); -extern void blk_queue_max_write_same_sectors (struct request_queue *q, -unsigned int max_write_same_sectors);extern void blk_queue_max_write_zeroes_sectors (struct request_queue *q,unsigned int max_write_same_sectors);extern void blk_queue_logical_block_size (struct request_queue *,unsigned short );
@@ -1336,8 +1322,6 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt, }extern int blkdev_issue_flush (struct block_device *,gfp_t ,sector_t *); -extern int blkdev_issue_write_same (struct block_device *bdev,sector_t sector, -sector_t nr_sects,gfp_t gfp_mask,struct page *page);#define BLKDEV_DISCARD_SECURE (1 << 0)/* issue a secure erase */
@@ -1539,16 +1523,6 @@ static inline int bdev_discard_alignment(struct block_device *bdev)return q->limits.discard_alignment; } -static inline unsigned int bdev_write_same (struct block_device *bdev) -{ -struct request_queue *q =bdev_get_queue (bdev); - -if (q) -return q->limits.max_write_same_sectors; - -return 0 ; -} -static inline unsigned int bdev_write_zeroes_sectors (struct block_device *bdev) {struct request_queue *q =bdev_get_queue (bdev);
include/trace/events/f2fs.h +0 -1
@@ -71,7 +71,6 @@ TRACE_DEFINE_ENUM(CP_DISCARD); { REQ_OP_ZONE_REPORT, "ZONE_REPORT" }, \ { REQ_OP_SECURE_ERASE, "SECURE_ERASE" }, \ { REQ_OP_ZONE_RESET, "ZONE_RESET" }, \ - { REQ_OP_WRITE_SAME, "WRITE_SAME" }, \ { REQ_OP_WRITE_ZEROES, "WRITE_ZEROES" })#define show_bio_op_flags (flags) \
kernel/trace/blktrace.c +0 -1
@@ -1750,7 +1750,6 @@ void blk_fill_rwbs(char *rwbs, unsigned int op, int bytes)switch (op &REQ_OP_MASK ) {case REQ_OP_WRITE : -case REQ_OP_WRITE_SAME : rwbs[i++] ='W' ;break ;case REQ_OP_DISCARD :
Signature · 1 line
2.11.0
PATCH 7/8 block: remove bio_no_advance_iter
In reply to Christoph HellwigNow that we don't have to support the odd Write Same special case we can simply increment the iter if the bio has data, else just manipulate bi_size directly.
--- include/linux/bio.h | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-)
include/linux/bio.h +3 -10
@@ -83,13 +83,6 @@ static inline bool bio_has_data(struct bio *bio)return false; } -static inline bool bio_no_advance_iter (struct bio *bio) -{ -return bio_op (bio) ==REQ_OP_DISCARD || -bio_op (bio) ==REQ_OP_SECURE_ERASE || -bio_op (bio) ==REQ_OP_WRITE_ZEROES ; -} -static inline bool bio_mergeable (struct bio *bio) {if (bio->bi_opf &REQ_NOMERGE_FLAGS )
@@ -165,10 +158,10 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter, { iter->bi_sector += bytes >>9 ; -if (bio_no_advance_iter (bio)) - iter->bi_size -= bytes; -else +if (bio_has_data (bio))bvec_iter_advance (bio->bi_io_vec, iter, bytes); +else + iter->bi_size -= bytes; }#define __bio_for_each_segment (bvl, bio, iter, start) \
Signature · 1 line
2.11.0
PATCH 8/8 block: use bio_has_data to check if a bio has bvecs
In reply to Christoph HellwigNow that Write Same is gone and discard bios never have a payload we can simply use bio_has_data as an indicator that the bio has bvecs that need to be handled.
--- block/bio.c | 8 +------- block/blk-merge.c | 9 +-------- include/linux/bio.h | 21 +++++---------------- 3 files changed, 7 insertions(+), 31 deletions(-)
block/bio.c +1 -7
@@ -679,15 +679,9 @@ static struct bio *__bio_clone_bioset(struct bio *bio_src, gfp_t gfp_mask, bio->bi_iter.bi_sector = bio_src->bi_iter.bi_sector; bio->bi_iter.bi_size = bio_src->bi_iter.bi_size; -switch (bio_op (bio)) { -case REQ_OP_DISCARD : -case REQ_OP_SECURE_ERASE : -case REQ_OP_WRITE_ZEROES : -break ; -default : +if (bio_has_data (bio)) {__bio_for_each_segment (bv, bio_src, iter, iter_src) bio->bi_io_vec[bio->bi_vcnt++] = bv; -break ; }if (bio_integrity (bio_src)) {
block/blk-merge.c +1 -8
@@ -232,16 +232,9 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,struct bio *fbio, *bbio;struct bvec_iter iter; -if (!bio) +if (!bio || !bio_has_data (bio))return 0 ; -switch (bio_op (bio)) { -case REQ_OP_DISCARD : -case REQ_OP_SECURE_ERASE : -case REQ_OP_WRITE_ZEROES : -return 0 ; - } - fbio = bio; cluster =blk_queue_cluster (q); seg_size =0 ;
include/linux/bio.h +5 -16
@@ -178,26 +178,15 @@ static inline void bio_advance_iter(struct bio *bio, struct bvec_iter *iter,static inline unsigned __bio_segments (struct bio *bio,struct bvec_iter *bvec) {unsigned segs =0 ; -struct bio_vec bv; -struct bvec_iter iter; -/* -* We special case discard/write same/write zeroes, because they -* interpret bi_size differently: -*/ +if (bio_has_data (bio)) { +struct bio_vec bv; +struct bvec_iter iter; -switch (bio_op (bio)) { -case REQ_OP_DISCARD : -case REQ_OP_SECURE_ERASE : -case REQ_OP_WRITE_ZEROES : -return 0 ; -default : -break ; +__bio_for_each_segment (bv, bio, iter, *bvec) + segs++; } -__bio_for_each_segment (bv, bio, iter, *bvec) - segs++; -return segs; }
Signature · 1 line
2.11.0
Quoted 7 lines · Christoph Hellwig
Now that we are using
REQ_OP_WRITE_ZEROESfor all zeroing needs in the kernel there is very little use left forREQ_OP_WRITE_SAME. We only have two callers left, and both just export optional protocol features to remote systems: DRBD and the target code.Do we have any major users of those? If not removing it will clean up a few warts in the block layer.
I added the iblock write same support because for RBD/ceph we were going to pass it from rbd down to the OSD. We are using tcmu right now, so we no longer need iblock support.