target: Add device attribute to expose config_item_name for INQUIRY model
authorTregaron Bayly <tregaron@baylys.org>
Thu, 31 Jan 2013 22:30:24 +0000 (15:30 -0700)
committerNicholas Bellinger <nab@linux-iscsi.org>
Wed, 13 Feb 2013 19:27:58 +0000 (11:27 -0800)
This patch changes LIO to use the configfs backend device name as the
model if you echo '1' to an individual device's emulate_model_alias attribute.
This is a valid operation only on devices with an export count of 0.

Signed-off-by: Tregaron Bayly <tbayly@bluehost.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_configfs.c
drivers/target/target_core_device.c
drivers/target/target_core_internal.h
include/target/target_core_base.h

index 4efb61b8d00195b7d2f6018f0578f4e02273cda1..43b7ac6c5b1c80e5132bb793d4a447abf11f443c 100644 (file)
@@ -609,6 +609,9 @@ static struct target_core_dev_attrib_attribute                              \
        __CONFIGFS_EATTR_RO(_name,                                      \
        target_core_dev_show_attr_##_name);
 
+DEF_DEV_ATTRIB(emulate_model_alias);
+SE_DEV_ATTR(emulate_model_alias, S_IRUGO | S_IWUSR);
+
 DEF_DEV_ATTRIB(emulate_dpo);
 SE_DEV_ATTR(emulate_dpo, S_IRUGO | S_IWUSR);
 
@@ -681,6 +684,7 @@ SE_DEV_ATTR(max_write_same_len, S_IRUGO | S_IWUSR);
 CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group);
 
 static struct configfs_attribute *target_core_dev_attrib_attrs[] = {
+       &target_core_dev_attrib_emulate_model_alias.attr,
        &target_core_dev_attrib_emulate_dpo.attr,
        &target_core_dev_attrib_emulate_fua_write.attr,
        &target_core_dev_attrib_emulate_fua_read.attr,
index d10cbed234722f0dc74fdf009055e67897b28e01..6fb82f1abe5c8049d0924a3567f27edfe8dec4fb 100644 (file)
@@ -713,6 +713,44 @@ int se_dev_set_max_write_same_len(
        return 0;
 }
 
+static void dev_set_t10_wwn_model_alias(struct se_device *dev)
+{
+       const char *configname;
+
+       configname = config_item_name(&dev->dev_group.cg_item);
+       if (strlen(configname) >= 16) {
+               pr_warn("dev[%p]: Backstore name '%s' is too long for "
+                       "INQUIRY_MODEL, truncating to 16 bytes\n", dev,
+                       configname);
+       }
+       snprintf(&dev->t10_wwn.model[0], 16, "%s", configname);
+}
+
+int se_dev_set_emulate_model_alias(struct se_device *dev, int flag)
+{
+       if (dev->export_count) {
+               pr_err("dev[%p]: Unable to change model alias"
+                       " while export_count is %d\n",
+                       dev, dev->export_count);
+                       return -EINVAL;
+       }
+
+       if (flag != 0 && flag != 1) {
+               pr_err("Illegal value %d\n", flag);
+               return -EINVAL;
+       }
+
+       if (flag) {
+               dev_set_t10_wwn_model_alias(dev);
+       } else {
+               strncpy(&dev->t10_wwn.model[0],
+                       dev->transport->inquiry_prod, 16);
+       }
+       dev->dev_attrib.emulate_model_alias = flag;
+
+       return 0;
+}
+
 int se_dev_set_emulate_dpo(struct se_device *dev, int flag)
 {
        if (flag != 0 && flag != 1) {
@@ -1396,6 +1434,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
        dev->t10_alua.t10_dev = dev;
 
        dev->dev_attrib.da_dev = dev;
+       dev->dev_attrib.emulate_model_alias = DA_EMULATE_MODEL_ALIAS;
        dev->dev_attrib.emulate_dpo = DA_EMULATE_DPO;
        dev->dev_attrib.emulate_fua_write = DA_EMULATE_FUA_WRITE;
        dev->dev_attrib.emulate_fua_read = DA_EMULATE_FUA_READ;
index 93e9c1f580b01def8787d46f75c7e558ce7b3d97..fdc51f8301a1383b87fd5dcec61d23ac3061bab4 100644 (file)
@@ -25,6 +25,7 @@ int   se_dev_set_max_unmap_block_desc_count(struct se_device *, u32);
 int    se_dev_set_unmap_granularity(struct se_device *, u32);
 int    se_dev_set_unmap_granularity_alignment(struct se_device *, u32);
 int    se_dev_set_max_write_same_len(struct se_device *, u32);
+int    se_dev_set_emulate_model_alias(struct se_device *, int);
 int    se_dev_set_emulate_dpo(struct se_device *, int);
 int    se_dev_set_emulate_fua_write(struct se_device *, int);
 int    se_dev_set_emulate_fua_read(struct se_device *, int);
index 199b0ad1a55ebd35268befd6c884b41da88bff5b..df14dce59191df42e1270918cb143ebaf02dddc9 100644 (file)
@@ -75,6 +75,8 @@
 #define DA_MAX_WRITE_SAME_LEN                  0
 /* Default max transfer length */
 #define DA_FABRIC_MAX_SECTORS                  8192
+/* Use a model alias based on the configfs backend device name */
+#define DA_EMULATE_MODEL_ALIAS                 0
 /* Emulation for Direct Page Out */
 #define DA_EMULATE_DPO                         0
 /* Emulation for Forced Unit Access WRITEs */
@@ -591,6 +593,7 @@ struct se_dev_entry {
 };
 
 struct se_dev_attrib {
+       int             emulate_model_alias;
        int             emulate_dpo;
        int             emulate_fua_write;
        int             emulate_fua_read;