Skip to contentSkip to conversation

LIO: Add emulate_removable attribute

RFC PATCH New Phillip Susi 1 participant 2 messages Feb 8, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 LIO: Add emulate_removable attribute

The following patch adds an additional attribute to the LIO confgfs allowing you to cause the disk to report that it is removable.

It currently works but to get the sd driver to register the change in the removable bit in the IDENTIFY data, you have to tap the delete sysfs knob to unbind it and then trigger the host to rescan. Is there a way to trigger this when the attribute is changed?

I noticed that the attributes show up in configfs under the fileio backing store rather than the disk lun, which seems like the wrong place. Why is this?

Also targetcli does not seem to know about these attributes. Shouldn't it? Or did I just miss it?

#1 lore raw

PATCH 1/1 LIO: Add emulate_removable attribute

Add another attribute that can be tuned via sysfs to have the emulated scsi disk report that it is removable.

---
 drivers/target/target_core_configfs.c | 4 ++++
 drivers/target/target_core_spc.c      | 2 ++
 include/target/target_core_base.h     | 1 +
 3 files changed, 7 insertions(+)
drivers/target/target_core_configfs.c +4 -0
index f04352285155..2cecc0c1cc26 100644
@@ -546,6 +546,7 @@ DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity);
 DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity_alignment);
 DEF_CONFIGFS_ATTRIB_SHOW(unmap_zeroes_data);
 DEF_CONFIGFS_ATTRIB_SHOW(max_write_same_len);
+DEF_CONFIGFS_ATTRIB_SHOW(emulate_removable);
 
 #define DEF_CONFIGFS_ATTRIB_STORE_U32(_name)				\
 static ssize_t _name##_store(struct config_item *item, const char *page,\
@@ -589,6 +590,7 @@ DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_3pc);
 DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_pr);
 DEF_CONFIGFS_ATTRIB_STORE_BOOL(enforce_pr_isids);
 DEF_CONFIGFS_ATTRIB_STORE_BOOL(is_nonrot);
+DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_removable);
 
 #define DEF_CONFIGFS_ATTRIB_STORE_STUB(_name)				\
 static ssize_t _name##_store(struct config_item *item, const char *page,\
@@ -1178,6 +1180,7 @@ CONFIGFS_ATTR(, emulate_tpws);
 CONFIGFS_ATTR(, emulate_caw);
 CONFIGFS_ATTR(, emulate_3pc);
 CONFIGFS_ATTR(, emulate_pr);
+CONFIGFS_ATTR(, emulate_removable);
 CONFIGFS_ATTR(, pi_prot_type);
 CONFIGFS_ATTR_RO(, hw_pi_prot_type);
 CONFIGFS_ATTR(, pi_prot_format);
@@ -1241,6 +1244,7 @@ struct configfs_attribute *sbc_attrib_attrs[] = {
 	&attr_max_write_same_len,
 	&attr_alua_support,
 	&attr_pgr_support,
+	&attr_emulate_removable,
 	NULL,
 };
 EXPORT_SYMBOL(sbc_attrib_attrs);
drivers/target/target_core_spc.c +2 -0
index ca5579ebc81d..5af67a1e10f9 100644
@@ -54,6 +54,8 @@ spc_emulate_inquiry_std(struct se_cmd *cmd, unsigned char *buf)
 	struct se_device *dev = cmd->se_dev;
 	struct se_session *sess = cmd->se_sess;
 
+	if (dev->dev_attrib.emulate_removable)
+		buf[1] = 0x80;
 	/* Set RMB (removable media) for tape devices */
 	if (dev->transport->get_device_type(dev) == TYPE_TAPE)
 		buf[1] = 0x80;
include/target/target_core_base.h +1 -0
index 63dd12124139..ae2396c1485a 100644
@@ -692,6 +692,7 @@ struct se_dev_attrib {
 	bool		is_nonrot;
 	bool		emulate_rest_reord;
 	bool		unmap_zeroes_data;
+	bool		emulate_removable;
 	u32		hw_block_size;
 	u32		block_size;
 	u32		hw_max_sectors;
Signature · 1 line
2.30.0