aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDouglas Gilbert <dgilbert@interlog.com>2016-05-06 00:40:28 -0400
committerMartin K. Petersen <martin.petersen@oracle.com>2016-05-10 21:25:34 -0400
commit09ba24c18c7e0c215c39b3d92332b64132dae170 (patch)
treea573558ac5fc30204da60b5f8119d3f091092041
parent760f3b0342df19c2cfe53fffcc5ff5e2311447a6 (diff)
scsi_debug: uuid for lu name
Permit changing of a LU name from a (fake) IEEE registered NAA (5) to a locally assigned UUID. Using a UUID (RFC 4122) for a SCSI designation descriptor (e.g. a LU name) was added in spc5r08.pdf (a draft INCITS standard) on 25 January 2016. Add parameter uuid_ctl to use a separate UUID for each LU (storage device) name. Additional option for all LU names to have the same UUID (since their storage is shared). Previous action of using NAA identifier for LU name remains the default. Signed-off-by: Douglas Gilbert <dgilbert@interlog.com> Reviewed-by: Hannes Reinecke <hare@suse.com> Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r--drivers/scsi/scsi_debug.c61
1 files changed, 51 insertions, 10 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index afbbfaa20a34..efb454906fc7 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -41,6 +41,7 @@
41#include <linux/interrupt.h> 41#include <linux/interrupt.h>
42#include <linux/atomic.h> 42#include <linux/atomic.h>
43#include <linux/hrtimer.h> 43#include <linux/hrtimer.h>
44#include <linux/uuid.h>
44 45
45#include <net/checksum.h> 46#include <net/checksum.h>
46 47
@@ -137,6 +138,7 @@ static const char *sdebug_version_date = "20160430";
137#define DEF_STRICT 0 138#define DEF_STRICT 0
138#define DEF_STATISTICS false 139#define DEF_STATISTICS false
139#define DEF_SUBMIT_QUEUES 1 140#define DEF_SUBMIT_QUEUES 1
141#define DEF_UUID_CTL 0
140#define JDELAY_OVERRIDDEN -9999 142#define JDELAY_OVERRIDDEN -9999
141 143
142#define SDEBUG_LUN_0_VAL 0 144#define SDEBUG_LUN_0_VAL 0
@@ -241,6 +243,7 @@ struct sdebug_dev_info {
241 unsigned int channel; 243 unsigned int channel;
242 unsigned int target; 244 unsigned int target;
243 u64 lun; 245 u64 lun;
246 uuid_be lu_name;
244 struct sdebug_host_info *sdbg_host; 247 struct sdebug_host_info *sdbg_host;
245 unsigned long uas_bm[1]; 248 unsigned long uas_bm[1];
246 atomic_t num_in_q; 249 atomic_t num_in_q;
@@ -600,6 +603,7 @@ static unsigned int sdebug_unmap_granularity = DEF_UNMAP_GRANULARITY;
600static unsigned int sdebug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS; 603static unsigned int sdebug_unmap_max_blocks = DEF_UNMAP_MAX_BLOCKS;
601static unsigned int sdebug_unmap_max_desc = DEF_UNMAP_MAX_DESC; 604static unsigned int sdebug_unmap_max_desc = DEF_UNMAP_MAX_DESC;
602static unsigned int sdebug_write_same_length = DEF_WRITESAME_LENGTH; 605static unsigned int sdebug_write_same_length = DEF_WRITESAME_LENGTH;
606static int sdebug_uuid_ctl = DEF_UUID_CTL;
603static bool sdebug_removable = DEF_REMOVABLE; 607static bool sdebug_removable = DEF_REMOVABLE;
604static bool sdebug_clustering; 608static bool sdebug_clustering;
605static bool sdebug_host_lock = DEF_HOST_LOCK; 609static bool sdebug_host_lock = DEF_HOST_LOCK;
@@ -928,8 +932,8 @@ static const u64 naa5_comp_c = 0x5111111000000000ULL;
928/* Device identification VPD page. Returns number of bytes placed in arr */ 932/* Device identification VPD page. Returns number of bytes placed in arr */
929static int inquiry_vpd_83(unsigned char *arr, int port_group_id, 933static int inquiry_vpd_83(unsigned char *arr, int port_group_id,
930 int target_dev_id, int dev_id_num, 934 int target_dev_id, int dev_id_num,
931 const char *dev_id_str, 935 const char *dev_id_str, int dev_id_str_len,
932 int dev_id_str_len) 936 const uuid_be *lu_name)
933{ 937{
934 int num, port_a; 938 int num, port_a;
935 char b[32]; 939 char b[32];
@@ -946,13 +950,25 @@ static int inquiry_vpd_83(unsigned char *arr, int port_group_id,
946 arr[3] = num; 950 arr[3] = num;
947 num += 4; 951 num += 4;
948 if (dev_id_num >= 0) { 952 if (dev_id_num >= 0) {
949 /* NAA-5, Logical unit identifier (binary) */ 953 if (sdebug_uuid_ctl) {
950 arr[num++] = 0x1; /* binary (not necessarily sas) */ 954 /* Locally assigned UUID */
951 arr[num++] = 0x3; /* PIV=0, lu, naa */ 955 arr[num++] = 0x1; /* binary (not necessarily sas) */
952 arr[num++] = 0x0; 956 arr[num++] = 0xa; /* PIV=0, lu, naa */
953 arr[num++] = 0x8; 957 arr[num++] = 0x0;
954 put_unaligned_be64(naa5_comp_b + dev_id_num, arr + num); 958 arr[num++] = 0x12;
955 num += 8; 959 arr[num++] = 0x10; /* uuid type=1, locally assigned */
960 arr[num++] = 0x0;
961 memcpy(arr + num, lu_name, 16);
962 num += 16;
963 } else {
964 /* NAA-5, Logical unit identifier (binary) */
965 arr[num++] = 0x1; /* binary (not necessarily sas) */
966 arr[num++] = 0x3; /* PIV=0, lu, naa */
967 arr[num++] = 0x0;
968 arr[num++] = 0x8;
969 put_unaligned_be64(naa5_comp_b + dev_id_num, arr + num);
970 num += 8;
971 }
956 /* Target relative port number */ 972 /* Target relative port number */
957 arr[num++] = 0x61; /* proto=sas, binary */ 973 arr[num++] = 0x61; /* proto=sas, binary */
958 arr[num++] = 0x94; /* PIV=1, target port, rel port */ 974 arr[num++] = 0x94; /* PIV=1, target port, rel port */
@@ -1293,7 +1309,8 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1293 arr[1] = cmd[2]; /*sanity */ 1309 arr[1] = cmd[2]; /*sanity */
1294 arr[3] = inquiry_vpd_83(&arr[4], port_group_id, 1310 arr[3] = inquiry_vpd_83(&arr[4], port_group_id,
1295 target_dev_id, lu_id_num, 1311 target_dev_id, lu_id_num,
1296 lu_id_str, len); 1312 lu_id_str, len,
1313 &devip->lu_name);
1297 } else if (0x84 == cmd[2]) { /* Software interface ident. */ 1314 } else if (0x84 == cmd[2]) { /* Software interface ident. */
1298 arr[1] = cmd[2]; /*sanity */ 1315 arr[1] = cmd[2]; /*sanity */
1299 arr[3] = inquiry_vpd_84(&arr[4]); 1316 arr[3] = inquiry_vpd_84(&arr[4]);
@@ -3503,6 +3520,9 @@ static void sdebug_q_cmd_wq_complete(struct work_struct *work)
3503 sdebug_q_cmd_complete(sd_dp); 3520 sdebug_q_cmd_complete(sd_dp);
3504} 3521}
3505 3522
3523static bool got_shared_uuid;
3524static uuid_be shared_uuid;
3525
3506static struct sdebug_dev_info *sdebug_device_create( 3526static struct sdebug_dev_info *sdebug_device_create(
3507 struct sdebug_host_info *sdbg_host, gfp_t flags) 3527 struct sdebug_host_info *sdbg_host, gfp_t flags)
3508{ 3528{
@@ -3510,6 +3530,17 @@ static struct sdebug_dev_info *sdebug_device_create(
3510 3530
3511 devip = kzalloc(sizeof(*devip), flags); 3531 devip = kzalloc(sizeof(*devip), flags);
3512 if (devip) { 3532 if (devip) {
3533 if (sdebug_uuid_ctl == 1)
3534 uuid_be_gen(&devip->lu_name);
3535 else if (sdebug_uuid_ctl == 2) {
3536 if (got_shared_uuid)
3537 devip->lu_name = shared_uuid;
3538 else {
3539 uuid_be_gen(&shared_uuid);
3540 got_shared_uuid = true;
3541 devip->lu_name = shared_uuid;
3542 }
3543 }
3513 devip->sdbg_host = sdbg_host; 3544 devip->sdbg_host = sdbg_host;
3514 list_add_tail(&devip->dev_list, &sdbg_host->dev_info_list); 3545 list_add_tail(&devip->dev_list, &sdbg_host->dev_info_list);
3515 } 3546 }
@@ -4101,6 +4132,7 @@ module_param_named(unmap_granularity, sdebug_unmap_granularity, int, S_IRUGO);
4101module_param_named(unmap_max_blocks, sdebug_unmap_max_blocks, int, S_IRUGO); 4132module_param_named(unmap_max_blocks, sdebug_unmap_max_blocks, int, S_IRUGO);
4102module_param_named(unmap_max_desc, sdebug_unmap_max_desc, int, S_IRUGO); 4133module_param_named(unmap_max_desc, sdebug_unmap_max_desc, int, S_IRUGO);
4103module_param_named(virtual_gb, sdebug_virtual_gb, int, S_IRUGO | S_IWUSR); 4134module_param_named(virtual_gb, sdebug_virtual_gb, int, S_IRUGO | S_IWUSR);
4135module_param_named(uuid_ctl, sdebug_uuid_ctl, int, S_IRUGO);
4104module_param_named(vpd_use_hostno, sdebug_vpd_use_hostno, int, 4136module_param_named(vpd_use_hostno, sdebug_vpd_use_hostno, int,
4105 S_IRUGO | S_IWUSR); 4137 S_IRUGO | S_IWUSR);
4106module_param_named(write_same_length, sdebug_write_same_length, int, 4138module_param_named(write_same_length, sdebug_write_same_length, int,
@@ -4150,6 +4182,8 @@ MODULE_PARM_DESC(unmap_alignment, "lowest aligned thin provisioning lba (def=0)"
4150MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)"); 4182MODULE_PARM_DESC(unmap_granularity, "thin provisioning granularity in blocks (def=1)");
4151MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)"); 4183MODULE_PARM_DESC(unmap_max_blocks, "max # of blocks can be unmapped in one cmd (def=0xffffffff)");
4152MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)"); 4184MODULE_PARM_DESC(unmap_max_desc, "max # of ranges that can be unmapped in one cmd (def=256)");
4185MODULE_PARM_DESC(uuid_ctl,
4186 "1->use uuid for lu name, 0->don't, 2->all use same (def=0)");
4153MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)"); 4187MODULE_PARM_DESC(virtual_gb, "virtual gigabyte (GiB) size (def=0 -> use dev_size_mb)");
4154MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)"); 4188MODULE_PARM_DESC(vpd_use_hostno, "0 -> dev ids ignore hostno (def=1 -> unique dev ids)");
4155MODULE_PARM_DESC(write_same_length, "Maximum blocks per WRITE SAME cmd (def=0xffff)"); 4189MODULE_PARM_DESC(write_same_length, "Maximum blocks per WRITE SAME cmd (def=0xffff)");
@@ -4787,6 +4821,12 @@ static ssize_t strict_store(struct device_driver *ddp, const char *buf,
4787} 4821}
4788static DRIVER_ATTR_RW(strict); 4822static DRIVER_ATTR_RW(strict);
4789 4823
4824static ssize_t uuid_ctl_show(struct device_driver *ddp, char *buf)
4825{
4826 return scnprintf(buf, PAGE_SIZE, "%d\n", !!sdebug_uuid_ctl);
4827}
4828static DRIVER_ATTR_RO(uuid_ctl);
4829
4790 4830
4791/* Note: The following array creates attribute files in the 4831/* Note: The following array creates attribute files in the
4792 /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these 4832 /sys/bus/pseudo/drivers/scsi_debug directory. The advantage of these
@@ -4825,6 +4865,7 @@ static struct attribute *sdebug_drv_attrs[] = {
4825 &driver_attr_host_lock.attr, 4865 &driver_attr_host_lock.attr,
4826 &driver_attr_ndelay.attr, 4866 &driver_attr_ndelay.attr,
4827 &driver_attr_strict.attr, 4867 &driver_attr_strict.attr,
4868 &driver_attr_uuid_ctl.attr,
4828 NULL, 4869 NULL,
4829}; 4870};
4830ATTRIBUTE_GROUPS(sdebug_drv); 4871ATTRIBUTE_GROUPS(sdebug_drv);