target: UNMAP/WRITE_SAME features/cleanups for 5.20
Subsystems (2)
cover target: UNMAP/WRITE_SAME features/cleanups for 5.20
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.
PATCH 1/5 scsi: target: Remove incorrect zero blocks WRITE_SAME check
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.
--- drivers/target/target_core_file.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/target/target_core_file.c +0 -4
@@ -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" );
Signature · 1 line
2.25.1
Re: [PATCH 1/5] scsi: target: Remove incorrect zero blocks WRITE_SAME check
Quoted 4 lines · Mike Christie
We use WSNZ=1 so if we get a
WRITE_SAMEwith zero logical blocks we are supposed to fail it. We do this check and failure intarget_core_sbc.cbefore calling into the backend, so we can remove the incorrect check intarget_core_file.
Looks good:
PATCH 2/5 scsi: target: Add callout to configure unmap settings
In reply to Mike ChristieThis 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.
--- drivers/target/target_core_device.c | 6 ++++++ include/target/target_core_backend.h | 1 + 2 files changed, 7 insertions(+)
drivers/target/target_core_device.c +6 -0
@@ -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.. */
include/target/target_core_backend.h +1 -0
@@ -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 *);
Signature · 1 line
2.25.1
Re: [PATCH 2/5] scsi: target: Add callout to configure unmap settings
Quoted 6 lines · Mike Christie
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 <[email protected]>
Looks good:
PATCH 3/5 scsi: target: Add iblock configure_unmap callout
In reply to Mike ChristieMove iblock's unmap setup code to a configure_unmap callout.
--- drivers/target/target_core_iblock.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/target/target_core_iblock.c +9 -4
@@ -76,6 +76,14 @@ static struct se_device *iblock_alloc_device(struct se_hba *hba, const char *namreturn 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,
Signature · 1 line
2.25.1
Re: [PATCH 3/5] scsi: target: Add iblock configure_unmap callout
Looks good:
PATCH 4/5 scsi: target: Add file configure_unmap callout
In reply to Mike ChristieMove file's unmap setup code to a configure_unmap callout.
--- drivers/target/target_core_file.c | 38 +++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-)
drivers/target/target_core_file.c +24 -14
@@ -86,6 +86,29 @@ 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)); + }else { +/* +* 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 +172,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 +189,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 +932,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,
Signature · 1 line
2.25.1
Re: [PATCH 4/5] scsi: target: Add file configure_unmap callout
drivers/target/target_core_file.c static struct se_device *fd_alloc_device(struct se_hba *hba, const char *name) · line 97
Quoted 9 lines · Mike Christie
drivers/target/target_core_file.c +9
-0+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)); + }else {
No need for the else here.
Otherwise this looks good:
PATCH 5/5 scsi: target: Detect unmap support post configuration
In reply to Mike ChristieOn 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.
--- drivers/target/target_core_configfs.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/target/target_core_configfs.c +19 -8
@@ -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",
Signature · 1 line
2.25.1
Re: [PATCH 5/5] scsi: target: Detect unmap support post configuration
Looks good: