Skip to content

Commit 773cbaf

Browse files
author
Nicholas Bellinger
committed
target: Add/check max_write_same_len device attribute + update block limits VPD
This patch adds a new max_write_same_len device attribute for use with WRITE_SAME w/ UNMAP=0 backend emulation. This can be useful for lowering the default backend value (IBLOCK uses 0xFFFF). Also, update block limits VPD emulation code in spc_emulate_evpd_b0() to report MAXIMUM WRITE SAME LENGTH, and enforce max_write_same_len during sbc_parse() -> sbc_setup_write_same() CDB sanity checking for all emulated WRITE_SAME w/ UNMAP=0 cases. (Robert: Move max_write_same_len check in sbc_setup_write_same() to check both WRITE_SAME w/ UNMAP=1 and w/ UNMAP=0 cases) Cc: Christoph Hellwig <hch@lst.de> Cc: Martin K. Petersen <martin.petersen@oracle.com> Cc: Robert Elliott <Elliott@hp.com> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
1 parent cd063be commit 773cbaf

6 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎drivers/target/target_core_configfs.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ SE_DEV_ATTR(unmap_granularity, S_IRUGO | S_IWUSR);
676676
DEF_DEV_ATTRIB(unmap_granularity_alignment);
677677
SE_DEV_ATTR(unmap_granularity_alignment, S_IRUGO | S_IWUSR);
678678

679+
DEF_DEV_ATTRIB(max_write_same_len);
680+
SE_DEV_ATTR(max_write_same_len, S_IRUGO | S_IWUSR);
681+
679682
CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group);
680683

681684
static struct configfs_attribute *target_core_dev_attrib_attrs[] = {
@@ -701,6 +704,7 @@ static struct configfs_attribute *target_core_dev_attrib_attrs[] = {
701704
&target_core_dev_attrib_max_unmap_block_desc_count.attr,
702705
&target_core_dev_attrib_unmap_granularity.attr,
703706
&target_core_dev_attrib_unmap_granularity_alignment.attr,
707+
&target_core_dev_attrib_max_write_same_len.attr,
704708
NULL,
705709
};
706710

‎drivers/target/target_core_device.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,16 @@ int se_dev_set_unmap_granularity_alignment(
706706
return 0;
707707
}
708708

709+
int se_dev_set_max_write_same_len(
710+
struct se_device *dev,
711+
u32 max_write_same_len)
712+
{
713+
dev->dev_attrib.max_write_same_len = max_write_same_len;
714+
pr_debug("dev[%p]: Set max_write_same_len: %u\n",
715+
dev, dev->dev_attrib.max_write_same_len);
716+
return 0;
717+
}
718+
709719
int se_dev_set_emulate_dpo(struct se_device *dev, int flag)
710720
{
711721
if (flag != 0 && flag != 1) {
@@ -1393,6 +1403,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
13931403
dev->dev_attrib.unmap_granularity = DA_UNMAP_GRANULARITY_DEFAULT;
13941404
dev->dev_attrib.unmap_granularity_alignment =
13951405
DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT;
1406+
dev->dev_attrib.max_write_same_len = DA_MAX_WRITE_SAME_LEN;
13961407
dev->dev_attrib.fabric_max_sectors = DA_FABRIC_MAX_SECTORS;
13971408
dev->dev_attrib.optimal_sectors = DA_FABRIC_MAX_SECTORS;
13981409

‎drivers/target/target_core_internal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ int se_dev_set_max_unmap_lba_count(struct se_device *, u32);
2424
int se_dev_set_max_unmap_block_desc_count(struct se_device *, u32);
2525
int se_dev_set_unmap_granularity(struct se_device *, u32);
2626
int se_dev_set_unmap_granularity_alignment(struct se_device *, u32);
27+
int se_dev_set_max_write_same_len(struct se_device *, u32);
2728
int se_dev_set_emulate_dpo(struct se_device *, int);
2829
int se_dev_set_emulate_fua_write(struct se_device *, int);
2930
int se_dev_set_emulate_fua_read(struct se_device *, int);

‎drivers/target/target_core_sbc.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,19 @@ static inline unsigned long long transport_lba_64_ext(unsigned char *cdb)
238238
static sense_reason_t
239239
sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *ops)
240240
{
241+
unsigned int sectors = spc_get_write_same_sectors(cmd);
242+
241243
if ((flags[0] & 0x04) || (flags[0] & 0x02)) {
242244
pr_err("WRITE_SAME PBDATA and LBDATA"
243245
" bits not supported for Block Discard"
244246
" Emulation\n");
245247
return TCM_UNSUPPORTED_SCSI_OPCODE;
246248
}
249+
if (sectors > cmd->se_dev->dev_attrib.max_write_same_len) {
250+
pr_warn("WRITE_SAME sectors: %u exceeds max_write_same_len: %u\n",
251+
sectors, cmd->se_dev->dev_attrib.max_write_same_len);
252+
return TCM_INVALID_CDB_FIELD;
253+
}
247254
/*
248255
* Special case for WRITE_SAME w/ UNMAP=1 that ends up getting
249256
* translated into block discard requests within backend code.

‎drivers/target/target_core_spc.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
465465
* Exit now if we don't support TP.
466466
*/
467467
if (!have_tp)
468-
return 0;
468+
goto max_write_same;
469469

470470
/*
471471
* Set MAXIMUM UNMAP LBA COUNT
@@ -491,6 +491,12 @@ spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
491491
if (dev->dev_attrib.unmap_granularity_alignment != 0)
492492
buf[32] |= 0x80; /* Set the UGAVALID bit */
493493

494+
/*
495+
* MAXIMUM WRITE SAME LENGTH
496+
*/
497+
max_write_same:
498+
put_unaligned_be64(dev->dev_attrib.max_write_same_len, &buf[36]);
499+
494500
return 0;
495501
}
496502

‎include/target/target_core_base.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
#define DA_UNMAP_GRANULARITY_DEFAULT 0
7272
/* Default unmap_granularity_alignment */
7373
#define DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT 0
74+
/* Default max_write_same_len, disabled by default */
75+
#define DA_MAX_WRITE_SAME_LEN 0
7476
/* Default max transfer length */
7577
#define DA_FABRIC_MAX_SECTORS 8192
7678
/* Emulation for Direct Page Out */
@@ -609,6 +611,7 @@ struct se_dev_attrib {
609611
u32 max_unmap_block_desc_count;
610612
u32 unmap_granularity;
611613
u32 unmap_granularity_alignment;
614+
u32 max_write_same_len;
612615
struct se_device *da_dev;
613616
struct config_group da_group;
614617
};

0 commit comments

Comments
 (0)