From: Kyle Fortin Date: Tue, 13 Mar 2018 17:57:50 +0000 (-0400) Subject: target: add inquiry_product module param to override LIO default X-Git-Tag: v4.1.12-124.31.3~908 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fb90110fa99f209d16a7c1bd21db92e562990e61;p=users%2Fjedix%2Flinux-maple.git target: add inquiry_product module param to override LIO default Orabug: 27679431 OL6 iscsi target used IET which presented VIRTUAL-DISK for inquiry product. OL7 uses the LIO iscsi target instead, which presented LIO iblock name. Exadata targets upgrading from OL6 to OL7 need to present the same product ID to existing iscsi initiator multipath mappings. Add target_core_mod parameter inquiry_product for target inquiry vendor string override. It defaults to LIO iblock name. The user will also need to do one of the following in targetcli: set global export_backstore_name_as_model=false or for each backstore: /backstores// set attribute emulate_model_alias=0 (cherry picked from commit faf91b95fd22dbf0a1a7fd5b18ab71a929385927) Signed-off-by: Kyle Fortin Reviewed-by: Martin K. Petersen --- diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 44382647668c..193d95d35dbb 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -63,6 +63,12 @@ module_param_string(inquiry_vendor, g_inquiry_vendor, sizeof(g_inquiry_vendor), S_IRUGO|S_IWUSR); MODULE_PARM_DESC(inquiry_vendor, "inquiry vendor string override"); +/* SCSI inquiry product string is 16 chars space padded + NULL. */ +char g_inquiry_product[17] = ""; +module_param_string(inquiry_product, g_inquiry_product, + sizeof(g_inquiry_product), S_IRUGO|S_IWUSR); +MODULE_PARM_DESC(inquiry_product, "inquiry product string override"); + sense_reason_t transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun) { @@ -757,8 +763,15 @@ int se_dev_set_emulate_model_alias(struct se_device *dev, int flag) if (flag) { dev_set_t10_wwn_model_alias(dev); } else { - strncpy(&dev->t10_wwn.model[0], - dev->transport->inquiry_prod, 16); + /* + * If module_parm inquiry_product was set, use that. + */ + if (g_inquiry_product[0] != '\0') + strncpy(&dev->t10_wwn.model[0], + g_inquiry_product, 16); + else + strncpy(&dev->t10_wwn.model[0], + dev->transport->inquiry_prod, 16); } dev->dev_attrib.emulate_model_alias = flag; @@ -1614,8 +1627,15 @@ int target_configure_device(struct se_device *dev) */ if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) { strncpy(&dev->t10_wwn.vendor[0], g_inquiry_vendor, 8); - strncpy(&dev->t10_wwn.model[0], - dev->transport->inquiry_prod, 16); + /* + * If module_parm inquiry_product was set, use that. + */ + if (g_inquiry_product[0] != '\0') + strncpy(&dev->t10_wwn.model[0], + g_inquiry_product, 16); + else + strncpy(&dev->t10_wwn.model[0], + dev->transport->inquiry_prod, 16); strncpy(&dev->t10_wwn.revision[0], dev->transport->inquiry_rev, 4); } diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h index 9e19d9099df5..9d273e68e5a2 100644 --- a/drivers/target/target_core_internal.h +++ b/drivers/target/target_core_internal.h @@ -21,6 +21,7 @@ extern struct t10_alua_lu_gp *default_lu_gp; extern struct mutex g_device_mutex; extern struct list_head g_device_list; extern char g_inquiry_vendor[]; +extern char g_inquiry_product[]; struct se_dev_entry *core_get_se_deve_from_rtpi(struct se_node_acl *, u16); int core_free_device_list_for_node(struct se_node_acl *, diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c index d75bdd9dbe2a..87f6084951ec 100644 --- a/drivers/target/target_core_spc.c +++ b/drivers/target/target_core_spc.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -117,9 +118,9 @@ spc_emulate_inquiry_std(struct se_cmd *cmd, unsigned char *buf) memcpy(&buf[8], g_inquiry_vendor, 8); memset(&buf[16], 0x20, 16); memcpy(&buf[16], dev->t10_wwn.model, - min_t(size_t, strlen(dev->t10_wwn.model), 16)); + min_t(size_t, strnlen(dev->t10_wwn.model, 16), 16)); memcpy(&buf[32], dev->t10_wwn.revision, - min_t(size_t, strlen(dev->t10_wwn.revision), 4)); + min_t(size_t, strnlen(dev->t10_wwn.revision, 4), 4)); buf[4] = 31; /* Set additional length to 31 */ return 0; @@ -134,7 +135,8 @@ spc_emulate_evpd_80(struct se_cmd *cmd, unsigned char *buf) u16 len; if (dev->dev_flags & DF_EMULATED_VPD_UNIT_SERIAL) { - len = sprintf(&buf[4], "%s", dev->t10_wwn.unit_serial); + len = snprintf(&buf[4], INQUIRY_VPD_SERIAL_LEN, "%s", + dev->t10_wwn.unit_serial); len++; /* Extra Byte for NULL Terminator */ buf[3] = len; } @@ -187,7 +189,7 @@ spc_emulate_evpd_83(struct se_cmd *cmd, unsigned char *buf) struct t10_alua_tg_pt_gp *tg_pt_gp; struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; unsigned char *prod = &dev->t10_wwn.model[0]; - u32 prod_len; + u32 prod_len, model_len; u32 unit_serial_len, off = 0; u16 len = 0, id_len; @@ -246,15 +248,22 @@ check_t10_vend_desc: id_len = 8; /* For Vendor field */ prod_len = 4; /* For VPD Header */ prod_len += 8; /* For Vendor field */ - prod_len += strlen(prod); + model_len = strnlen(prod, 16); + prod_len += model_len; prod_len++; /* For : */ if (dev->dev_flags & DF_EMULATED_VPD_UNIT_SERIAL) { - unit_serial_len = strlen(&dev->t10_wwn.unit_serial[0]); - unit_serial_len++; /* For NULL Terminator */ - - id_len += sprintf(&buf[off+12], "%s:%s", prod, - &dev->t10_wwn.unit_serial[0]); + unit_serial_len = strnlen(&dev->t10_wwn.unit_serial[0], + INQUIRY_VPD_SERIAL_LEN); + if (model_len && unit_serial_len) { + id_len += snprintf(&buf[off+12], + model_len, "%s", prod); + id_len += snprintf(&buf[off+12+model_len], + unit_serial_len + 1, ":%s", + &dev->t10_wwn.unit_serial[0]); + /* Extra Byte for NULL Terminator */ + id_len++; + } } buf[off] = 0x2; /* ASCII */ buf[off+1] = 0x1; /* T10 Vendor ID */