Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

scsi: target: core: Add emulation for REPORT IDENTIFYING INFORMATION

Add emulation for REPORT IDENTIFYING INFORMATION command using the
configfs file 'pd_text_id_info' in target core module. The configfs file
is created in /sys/kernel/config/target/core/<backend type>/
<backing_store_name>/wwn/.

An emulation function, spc_emulate_report_id_info(), is defined to
return the identification string based on the contents of
'pd_text_id_info'.

The details of the REPORT IDENTIFYING INFORMATION command is defined in
section 6.32 of SPC4.

[mkp: checkpatch tweaks]

Signed-off-by: Gulam Mohamed <gulam.mohamed@oracle.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
Link: https://patch.msgid.link/20251201110716.227588-1-gulam.mohamed@oracle.com
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Gulam Mohamed and committed by
Martin K. Petersen
7011e8aa 8f0b4cce

+140
+50
drivers/target/target_core_configfs.c
··· 1741 1741 return len; 1742 1742 } 1743 1743 1744 + static ssize_t target_wwn_pd_text_id_info_show(struct config_item *item, 1745 + char *page) 1746 + { 1747 + return sysfs_emit(page, "%s\n", &to_t10_wwn(item)->pd_text_id_info[0]); 1748 + } 1749 + 1750 + static ssize_t target_wwn_pd_text_id_info_store(struct config_item *item, 1751 + const char *page, size_t count) 1752 + { 1753 + struct t10_wwn *t10_wwn = to_t10_wwn(item); 1754 + struct se_device *dev = t10_wwn->t10_dev; 1755 + 1756 + /* +2 to allow for a trailing (stripped) '\n' and null-terminator */ 1757 + unsigned char buf[PD_TEXT_ID_INFO_LEN + 2]; 1758 + char *stripped; 1759 + 1760 + /* 1761 + * Check to see if any active exports exist. If they do exist, fail 1762 + * here as changing this information on the fly (underneath the 1763 + * initiator side OS dependent multipath code) could cause negative 1764 + * effects. 1765 + */ 1766 + if (dev->export_count) { 1767 + pr_err("Unable to set the peripheral device text id info while active %d exports exist\n", 1768 + dev->export_count); 1769 + return -EINVAL; 1770 + } 1771 + 1772 + if (strscpy(buf, page, sizeof(buf)) < 0) 1773 + return -EOVERFLOW; 1774 + 1775 + /* Strip any newline added from userspace. */ 1776 + stripped = strstrip(buf); 1777 + if (strlen(stripped) >= PD_TEXT_ID_INFO_LEN) { 1778 + pr_err("Emulated peripheral device text id info exceeds PD_TEXT_ID_INFO_LEN: " __stringify(PD_TEXT_ID_INFO_LEN "\n")); 1779 + return -EOVERFLOW; 1780 + } 1781 + 1782 + BUILD_BUG_ON(sizeof(dev->t10_wwn.pd_text_id_info) != PD_TEXT_ID_INFO_LEN); 1783 + strscpy(dev->t10_wwn.pd_text_id_info, stripped, 1784 + sizeof(dev->t10_wwn.pd_text_id_info)); 1785 + 1786 + pr_debug("Target_Core_ConfigFS: Set emulated peripheral dev text id info:" 1787 + " %s\n", dev->t10_wwn.pd_text_id_info); 1788 + 1789 + return count; 1790 + } 1791 + 1744 1792 /* 1745 1793 * Generic wrapper for dumping VPD identifiers by association. 1746 1794 */ ··· 1845 1797 CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_logical_unit); 1846 1798 CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_target_port); 1847 1799 CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_scsi_target_device); 1800 + CONFIGFS_ATTR(target_wwn_, pd_text_id_info); 1848 1801 1849 1802 static struct configfs_attribute *target_core_dev_wwn_attrs[] = { 1850 1803 &target_wwn_attr_vendor_id, ··· 1857 1808 &target_wwn_attr_vpd_assoc_logical_unit, 1858 1809 &target_wwn_attr_vpd_assoc_target_port, 1859 1810 &target_wwn_attr_vpd_assoc_scsi_target_device, 1811 + &target_wwn_attr_pd_text_id_info, 1860 1812 NULL, 1861 1813 }; 1862 1814
+86
drivers/target/target_core_spc.c
··· 25 25 #include "target_core_ua.h" 26 26 #include "target_core_xcopy.h" 27 27 28 + #define PD_TEXT_ID_INFO_HDR_LEN 4 29 + 28 30 static void spc_fill_alua_data(struct se_lun *lun, unsigned char *buf) 29 31 { 30 32 struct t10_alua_tg_pt_gp *tg_pt_gp; ··· 2001 1999 .enabled = spc_rsoc_enabled, 2002 2000 }; 2003 2001 2002 + static struct target_opcode_descriptor tcm_opcode_report_identifying_information = { 2003 + .support = SCSI_SUPPORT_FULL, 2004 + .serv_action_valid = 1, 2005 + .opcode = MAINTENANCE_IN, 2006 + .service_action = MI_REPORT_IDENTIFYING_INFORMATION, 2007 + .cdb_size = 12, 2008 + .usage_bits = {MAINTENANCE_IN, MI_REPORT_IDENTIFYING_INFORMATION, 2009 + 0x00, 0x00, 2010 + 0x00, 0x00, 0xff, 0xff, 2011 + 0xff, 0xff, 0xff, SCSI_CONTROL_MASK}, 2012 + }; 2013 + 2004 2014 static bool tcm_is_set_tpg_enabled(const struct target_opcode_descriptor *descr, 2005 2015 struct se_cmd *cmd) 2006 2016 { ··· 2100 2086 &tcm_opcode_report_target_pgs, 2101 2087 &tcm_opcode_report_supp_opcodes, 2102 2088 &tcm_opcode_set_tpg, 2089 + &tcm_opcode_report_identifying_information, 2103 2090 }; 2104 2091 2105 2092 static int ··· 2318 2303 return ret; 2319 2304 } 2320 2305 2306 + static sense_reason_t 2307 + spc_fill_pd_text_id_info(struct se_cmd *cmd, u8 *cdb) 2308 + { 2309 + struct se_device *dev = cmd->se_dev; 2310 + unsigned char *buf; 2311 + unsigned char *rbuf; 2312 + u32 buf_len; 2313 + u16 data_len; 2314 + 2315 + buf_len = get_unaligned_be32(&cdb[6]); 2316 + if (buf_len < PD_TEXT_ID_INFO_HDR_LEN) 2317 + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 2318 + 2319 + data_len = strlen(dev->t10_wwn.pd_text_id_info); 2320 + if (data_len > 0) 2321 + /* trailing null */ 2322 + data_len += 1; 2323 + 2324 + data_len = data_len + PD_TEXT_ID_INFO_HDR_LEN; 2325 + 2326 + if (data_len < buf_len) 2327 + buf_len = data_len; 2328 + 2329 + buf = kzalloc(buf_len, GFP_KERNEL); 2330 + if (!buf) { 2331 + pr_err("Unable to allocate response buffer for IDENTITY INFO\n"); 2332 + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 2333 + } 2334 + 2335 + scnprintf(&buf[PD_TEXT_ID_INFO_HDR_LEN], buf_len - PD_TEXT_ID_INFO_HDR_LEN, "%s", 2336 + dev->t10_wwn.pd_text_id_info); 2337 + 2338 + put_unaligned_be16(data_len, &buf[2]); 2339 + 2340 + rbuf = transport_kmap_data_sg(cmd); 2341 + if (!rbuf) { 2342 + pr_err("transport_kmap_data_sg() failed in %s\n", __func__); 2343 + kfree(buf); 2344 + return TCM_OUT_OF_RESOURCES; 2345 + } 2346 + 2347 + memcpy(rbuf, buf, buf_len); 2348 + transport_kunmap_data_sg(cmd); 2349 + kfree(buf); 2350 + 2351 + target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, buf_len); 2352 + return TCM_NO_SENSE; 2353 + } 2354 + 2355 + static sense_reason_t 2356 + spc_emulate_report_id_info(struct se_cmd *cmd) 2357 + { 2358 + u8 *cdb = cmd->t_task_cdb; 2359 + sense_reason_t rc; 2360 + 2361 + switch ((cdb[10] >> 1)) { 2362 + case 2: 2363 + rc = spc_fill_pd_text_id_info(cmd, cdb); 2364 + break; 2365 + default: 2366 + return TCM_UNSUPPORTED_SCSI_OPCODE; 2367 + } 2368 + 2369 + return rc; 2370 + } 2371 + 2321 2372 sense_reason_t 2322 2373 spc_parse_cdb(struct se_cmd *cmd, unsigned int *size) 2323 2374 { ··· 2523 2442 MI_REPORT_SUPPORTED_OPERATION_CODES) 2524 2443 cmd->execute_cmd = 2525 2444 spc_emulate_report_supp_op_codes; 2445 + if ((cdb[1] & 0x1f) == 2446 + MI_REPORT_IDENTIFYING_INFORMATION) { 2447 + cmd->execute_cmd = 2448 + spc_emulate_report_id_info; 2449 + } 2526 2450 *size = get_unaligned_be32(&cdb[6]); 2527 2451 } else { 2528 2452 /*
+4
include/target/target_core_base.h
··· 108 108 #define SE_MODE_PAGE_BUF 512 109 109 #define SE_SENSE_BUF 96 110 110 111 + /* Peripheral Device Text Identification Information */ 112 + #define PD_TEXT_ID_INFO_LEN 256 113 + 111 114 enum target_submit_type { 112 115 /* Use the fabric driver's default submission type */ 113 116 TARGET_FABRIC_DEFAULT_SUBMIT, ··· 351 348 struct se_device *t10_dev; 352 349 struct config_group t10_wwn_group; 353 350 struct list_head t10_vpd_list; 351 + char pd_text_id_info[PD_TEXT_ID_INFO_LEN]; 354 352 }; 355 353 356 354 struct t10_pr_registration {