linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20
@ 2022-06-28 20:02 Mike Christie
  2022-06-28 20:02 ` [PATCH v2 1/5] scsi: target: Remove incorrect zero blocks WRITE_SAME check Mike Christie
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Mike Christie @ 2022-06-28 20:02 UTC (permalink / raw)
  To: hch, martin.petersen, james.bottomley, linux-scsi, target-devel

The following patches were made over Linus's tree and:

[PATCH 1/1] scsi: target: Fix WRITE_SAME No Data Buffer crash

They perform cleanup to target_core_file's WRITE_SAME handling and allow
users to configure UNMAP/WRITE_SAME after we have done the initial device
addition/configuration.

v2
- Fix coding style issues.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/5] scsi: target: Remove incorrect zero blocks WRITE_SAME check
  2022-06-28 20:02 [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Mike Christie
@ 2022-06-28 20:02 ` Mike Christie
  2022-06-28 20:02 ` [PATCH v2 2/5] scsi: target: Add callout to configure unmap settings Mike Christie
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Mike Christie @ 2022-06-28 20:02 UTC (permalink / raw)
  To: hch, martin.petersen, james.bottomley, linux-scsi, target-devel
  Cc: Mike Christie, Christoph Hellwig

We use WSNZ=1 so if we get a WRITE_SAME with zero logical blocks we are
supposed to fail it. We do this check and failure in target_core_sbc.c
before calling into the backend, so we can remove the incorrect check in
target_core_file.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/target/target_core_file.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index 6c8d8b051bfd..e8440e5dd804 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -438,10 +438,6 @@ fd_execute_write_same(struct se_cmd *cmd)
 	unsigned int len = 0, i;
 	ssize_t ret;
 
-	if (!nolb) {
-		target_complete_cmd(cmd, SAM_STAT_GOOD);
-		return 0;
-	}
 	if (cmd->prot_op) {
 		pr_err("WRITE_SAME: Protection information with FILEIO"
 		       " backends not supported\n");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/5] scsi: target: Add callout to configure unmap settings
  2022-06-28 20:02 [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Mike Christie
  2022-06-28 20:02 ` [PATCH v2 1/5] scsi: target: Remove incorrect zero blocks WRITE_SAME check Mike Christie
@ 2022-06-28 20:02 ` Mike Christie
  2022-06-28 20:02 ` [PATCH v2 3/5] scsi: target: Add iblock configure_unmap callout Mike Christie
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Mike Christie @ 2022-06-28 20:02 UTC (permalink / raw)
  To: hch, martin.petersen, james.bottomley, linux-scsi, target-devel
  Cc: Mike Christie, Christoph Hellwig

This patch adds a callout to configure a backend's unmap settings. This
will be used in this patchset to allow userspace to setup unmap after
the initial device setup similar to how we can setup the other attrs
post device configuration.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/target/target_core_device.c  | 6 ++++++
 include/target/target_core_backend.h | 1 +
 2 files changed, 7 insertions(+)

diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index 25f33eb25337..086ac9c9343c 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -960,6 +960,12 @@ int target_configure_device(struct se_device *dev)
 	ret = dev->transport->configure_device(dev);
 	if (ret)
 		goto out_free_index;
+
+	if (dev->transport->configure_unmap &&
+	    dev->transport->configure_unmap(dev)) {
+		pr_debug("Discard support available, but disabled by default.\n");
+	}
+
 	/*
 	 * XXX: there is not much point to have two different values here..
 	 */
diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h
index 773963a1e0b5..a3c193df25b3 100644
--- a/include/target/target_core_backend.h
+++ b/include/target/target_core_backend.h
@@ -37,6 +37,7 @@ struct target_backend_ops {
 	struct se_dev_plug *(*plug_device)(struct se_device *se_dev);
 	void (*unplug_device)(struct se_dev_plug *se_plug);
 
+	bool (*configure_unmap)(struct se_device *se_dev);
 	ssize_t (*set_configfs_dev_params)(struct se_device *,
 					   const char *, ssize_t);
 	ssize_t (*show_configfs_dev_params)(struct se_device *, char *);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/5] scsi: target: Add iblock configure_unmap callout
  2022-06-28 20:02 [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Mike Christie
  2022-06-28 20:02 ` [PATCH v2 1/5] scsi: target: Remove incorrect zero blocks WRITE_SAME check Mike Christie
  2022-06-28 20:02 ` [PATCH v2 2/5] scsi: target: Add callout to configure unmap settings Mike Christie
@ 2022-06-28 20:02 ` Mike Christie
  2022-06-28 20:02 ` [PATCH v2 4/5] scsi: target: Add file " Mike Christie
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Mike Christie @ 2022-06-28 20:02 UTC (permalink / raw)
  To: hch, martin.petersen, james.bottomley, linux-scsi, target-devel
  Cc: Mike Christie, Christoph Hellwig

Move iblock's unmap setup code to a configure_unmap callout.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/target/target_core_iblock.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 1ed9381751e6..7bef97097b78 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -76,6 +76,14 @@ static struct se_device *iblock_alloc_device(struct se_hba *hba, const char *nam
 	return NULL;
 }
 
+static bool iblock_configure_unmap(struct se_device *dev)
+{
+	struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
+
+	return target_configure_unmap_from_queue(&dev->dev_attrib,
+						 ib_dev->ibd_bd);
+}
+
 static int iblock_configure_device(struct se_device *dev)
 {
 	struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
@@ -119,10 +127,6 @@ static int iblock_configure_device(struct se_device *dev)
 	dev->dev_attrib.hw_max_sectors = queue_max_hw_sectors(q);
 	dev->dev_attrib.hw_queue_depth = q->nr_requests;
 
-	if (target_configure_unmap_from_queue(&dev->dev_attrib, bd))
-		pr_debug("IBLOCK: BLOCK Discard support available,"
-			 " disabled by default\n");
-
 	/*
 	 * Enable write same emulation for IBLOCK and use 0xFFFF as
 	 * the smaller WRITE_SAME(10) only has a two-byte block count.
@@ -903,6 +907,7 @@ static const struct target_backend_ops iblock_ops = {
 	.configure_device	= iblock_configure_device,
 	.destroy_device		= iblock_destroy_device,
 	.free_device		= iblock_free_device,
+	.configure_unmap	= iblock_configure_unmap,
 	.plug_device		= iblock_plug_device,
 	.unplug_device		= iblock_unplug_device,
 	.parse_cdb		= iblock_parse_cdb,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/5] scsi: target: Add file configure_unmap callout
  2022-06-28 20:02 [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Mike Christie
                   ` (2 preceding siblings ...)
  2022-06-28 20:02 ` [PATCH v2 3/5] scsi: target: Add iblock configure_unmap callout Mike Christie
@ 2022-06-28 20:02 ` Mike Christie
  2022-06-28 20:02 ` [PATCH v2 5/5] scsi: target: Detect unmap support post configuration Mike Christie
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Mike Christie @ 2022-06-28 20:02 UTC (permalink / raw)
  To: hch, martin.petersen, james.bottomley, linux-scsi, target-devel
  Cc: Mike Christie, Christoph Hellwig

Move file's unmap setup code to a configure_unmap callout.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/target/target_core_file.c | 33 ++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index e8440e5dd804..28aa643be5d5 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -86,6 +86,24 @@ static struct se_device *fd_alloc_device(struct se_hba *hba, const char *name)
 	return &fd_dev->dev;
 }
 
+static bool fd_configure_unmap(struct se_device *dev)
+{
+	struct file *file = FD_DEV(dev)->fd_file;
+	struct inode *inode = file->f_mapping->host;
+
+	if (S_ISBLK(inode->i_mode))
+		return target_configure_unmap_from_queue(&dev->dev_attrib,
+							 I_BDEV(inode));
+
+	/* Limit UNMAP emulation to 8k Number of LBAs (NoLB) */
+	dev->dev_attrib.max_unmap_lba_count = 0x2000;
+	/* Currently hardcoded to 1 in Linux/SCSI code. */
+	dev->dev_attrib.max_unmap_block_desc_count = 1;
+	dev->dev_attrib.unmap_granularity = 1;
+	dev->dev_attrib.unmap_granularity_alignment = 0;
+	return true;
+}
+
 static int fd_configure_device(struct se_device *dev)
 {
 	struct fd_dev *fd_dev = FD_DEV(dev);
@@ -149,10 +167,6 @@ static int fd_configure_device(struct se_device *dev)
 			" block_device blocks: %llu logical_block_size: %d\n",
 			dev_size, div_u64(dev_size, fd_dev->fd_block_size),
 			fd_dev->fd_block_size);
-
-		if (target_configure_unmap_from_queue(&dev->dev_attrib, bdev))
-			pr_debug("IFILE: BLOCK Discard support available,"
-				 " disabled by default\n");
 		/*
 		 * Enable write same emulation for IBLOCK and use 0xFFFF as
 		 * the smaller WRITE_SAME(10) only has a two-byte block count.
@@ -170,16 +184,6 @@ static int fd_configure_device(struct se_device *dev)
 		}
 
 		fd_dev->fd_block_size = FD_BLOCKSIZE;
-		/*
-		 * Limit UNMAP emulation to 8k Number of LBAs (NoLB)
-		 */
-		dev->dev_attrib.max_unmap_lba_count = 0x2000;
-		/*
-		 * Currently hardcoded to 1 in Linux/SCSI code..
-		 */
-		dev->dev_attrib.max_unmap_block_desc_count = 1;
-		dev->dev_attrib.unmap_granularity = 1;
-		dev->dev_attrib.unmap_granularity_alignment = 0;
 
 		/*
 		 * Limit WRITE_SAME w/ UNMAP=0 emulation to 8k Number of LBAs (NoLB)
@@ -923,6 +927,7 @@ static const struct target_backend_ops fileio_ops = {
 	.configure_device	= fd_configure_device,
 	.destroy_device		= fd_destroy_device,
 	.free_device		= fd_free_device,
+	.configure_unmap	= fd_configure_unmap,
 	.parse_cdb		= fd_parse_cdb,
 	.set_configfs_dev_params = fd_set_configfs_dev_params,
 	.show_configfs_dev_params = fd_show_configfs_dev_params,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 5/5] scsi: target: Detect unmap support post configuration
  2022-06-28 20:02 [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Mike Christie
                   ` (3 preceding siblings ...)
  2022-06-28 20:02 ` [PATCH v2 4/5] scsi: target: Add file " Mike Christie
@ 2022-06-28 20:02 ` Mike Christie
  2022-07-07 20:54 ` [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Martin K. Petersen
  2022-07-14  4:22 ` Martin K. Petersen
  6 siblings, 0 replies; 8+ messages in thread
From: Mike Christie @ 2022-06-28 20:02 UTC (permalink / raw)
  To: hch, martin.petersen, james.bottomley, linux-scsi, target-devel
  Cc: Mike Christie, Christoph Hellwig

On our backend we can do something similar to LIO where we can enable and
disable unmap support on the fly. In the scsi/block layer we can detect
this by just doing a rescan. However, LIO cannot detect this change
because we only check during the initial configuration. This patch
allows unmap detection to also happen when the user tries to turn it on.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/target/target_core_configfs.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index bbcbbfa72b07..f28d3c6dab98 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -732,6 +732,7 @@ static ssize_t emulate_tpu_store(struct config_item *item,
 		const char *page, size_t count)
 {
 	struct se_dev_attrib *da = to_attrib(item);
+	struct se_device *dev = da->da_dev;
 	bool flag;
 	int ret;
 
@@ -744,8 +745,11 @@ static ssize_t emulate_tpu_store(struct config_item *item,
 	 * Discard supported is detected iblock_create_virtdevice().
 	 */
 	if (flag && !da->max_unmap_block_desc_count) {
-		pr_err("Generic Block Discard not supported\n");
-		return -ENOSYS;
+		if (!dev->transport->configure_unmap ||
+		    !dev->transport->configure_unmap(dev)) {
+			pr_err("Generic Block Discard not supported\n");
+			return -ENOSYS;
+		}
 	}
 
 	da->emulate_tpu = flag;
@@ -758,6 +762,7 @@ static ssize_t emulate_tpws_store(struct config_item *item,
 		const char *page, size_t count)
 {
 	struct se_dev_attrib *da = to_attrib(item);
+	struct se_device *dev = da->da_dev;
 	bool flag;
 	int ret;
 
@@ -770,8 +775,11 @@ static ssize_t emulate_tpws_store(struct config_item *item,
 	 * Discard supported is detected iblock_create_virtdevice().
 	 */
 	if (flag && !da->max_unmap_block_desc_count) {
-		pr_err("Generic Block Discard not supported\n");
-		return -ENOSYS;
+		if (!dev->transport->configure_unmap ||
+		    !dev->transport->configure_unmap(dev)) {
+			pr_err("Generic Block Discard not supported\n");
+			return -ENOSYS;
+		}
 	}
 
 	da->emulate_tpws = flag;
@@ -964,6 +972,7 @@ static ssize_t unmap_zeroes_data_store(struct config_item *item,
 		const char *page, size_t count)
 {
 	struct se_dev_attrib *da = to_attrib(item);
+	struct se_device *dev = da->da_dev;
 	bool flag;
 	int ret;
 
@@ -982,10 +991,12 @@ static ssize_t unmap_zeroes_data_store(struct config_item *item,
 	 * Discard supported is detected iblock_configure_device().
 	 */
 	if (flag && !da->max_unmap_block_desc_count) {
-		pr_err("dev[%p]: Thin Provisioning LBPRZ will not be set"
-		       " because max_unmap_block_desc_count is zero\n",
-		       da->da_dev);
-		return -ENOSYS;
+		if (!dev->transport->configure_unmap ||
+		    !dev->transport->configure_unmap(dev)) {
+			pr_err("dev[%p]: Thin Provisioning LBPRZ will not be set because max_unmap_block_desc_count is zero\n",
+			       da->da_dev);
+			return -ENOSYS;
+		}
 	}
 	da->unmap_zeroes_data = flag;
 	pr_debug("dev[%p]: SE Device Thin Provisioning LBPRZ bit: %d\n",
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20
  2022-06-28 20:02 [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Mike Christie
                   ` (4 preceding siblings ...)
  2022-06-28 20:02 ` [PATCH v2 5/5] scsi: target: Detect unmap support post configuration Mike Christie
@ 2022-07-07 20:54 ` Martin K. Petersen
  2022-07-14  4:22 ` Martin K. Petersen
  6 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2022-07-07 20:54 UTC (permalink / raw)
  To: Mike Christie
  Cc: hch, martin.petersen, james.bottomley, linux-scsi, target-devel


Mike,

> They perform cleanup to target_core_file's WRITE_SAME handling and allow
> users to configure UNMAP/WRITE_SAME after we have done the initial device
> addition/configuration.

Applied to 5.20/scsi-staging, thanks!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20
  2022-06-28 20:02 [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Mike Christie
                   ` (5 preceding siblings ...)
  2022-07-07 20:54 ` [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Martin K. Petersen
@ 2022-07-14  4:22 ` Martin K. Petersen
  6 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2022-07-14  4:22 UTC (permalink / raw)
  To: target-devel, hch, Mike Christie, james.bottomley, linux-scsi
  Cc: Martin K . Petersen

On Tue, 28 Jun 2022 15:02:25 -0500, Mike Christie wrote:

> The following patches were made over Linus's tree and:
> 
> [PATCH 1/1] scsi: target: Fix WRITE_SAME No Data Buffer crash
> 
> They perform cleanup to target_core_file's WRITE_SAME handling and allow
> users to configure UNMAP/WRITE_SAME after we have done the initial device
> addition/configuration.
> 
> [...]

Applied to 5.20/scsi-queue, thanks!

[1/5] scsi: target: Remove incorrect zero blocks WRITE_SAME check
      https://git.kernel.org/mkp/scsi/c/036d8903f03b
[2/5] scsi: target: Add callout to configure unmap settings
      https://git.kernel.org/mkp/scsi/c/6b206a5a8c29
[3/5] scsi: target: Add iblock configure_unmap callout
      https://git.kernel.org/mkp/scsi/c/d7c382c51d03
[4/5] scsi: target: Add file configure_unmap callout
      https://git.kernel.org/mkp/scsi/c/33efaaf6e24b
[5/5] scsi: target: Detect unmap support post configuration
      https://git.kernel.org/mkp/scsi/c/34bd1dcacf0d

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-07-14  4:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-28 20:02 [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Mike Christie
2022-06-28 20:02 ` [PATCH v2 1/5] scsi: target: Remove incorrect zero blocks WRITE_SAME check Mike Christie
2022-06-28 20:02 ` [PATCH v2 2/5] scsi: target: Add callout to configure unmap settings Mike Christie
2022-06-28 20:02 ` [PATCH v2 3/5] scsi: target: Add iblock configure_unmap callout Mike Christie
2022-06-28 20:02 ` [PATCH v2 4/5] scsi: target: Add file " Mike Christie
2022-06-28 20:02 ` [PATCH v2 5/5] scsi: target: Detect unmap support post configuration Mike Christie
2022-07-07 20:54 ` [PATCH v2 0/5] target: UNMAP/WRITE_SAME features/cleanups for 5.20 Martin K. Petersen
2022-07-14  4:22 ` Martin K. Petersen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).