All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] target: Introduce dummy devices
@ 2021-03-18  9:42 Konstantin Shelekhin
  2021-03-18  9:42 ` [PATCH 1/2] target: Add the DUMMY flag to rd_mcp Konstantin Shelekhin
  2021-03-18  9:42 ` [PATCH 2/2] target: Make the virtual LUN 0 device dummy Konstantin Shelekhin
  0 siblings, 2 replies; 5+ messages in thread
From: Konstantin Shelekhin @ 2021-03-18  9:42 UTC (permalink / raw)
  To: Martin Petersen, Mike Christie, target-devel
  Cc: linux, linux-scsi, Konstantin Shelekhin

This patch series (inspired by SCST) adds support for the dummy devices
via the new DUMMY flag of rd_mcp. The rationale behind the change is to
give a user the ability to create conifgurable devices for LUN 0 with
custom WWN values (like vendor, product or revision) as some tools like
QConvergeGUI use LUN 0 to identify the whole storage.

The advantage over simply creating a NULLIO rd_mcp device is that the
DUMMY device will not be seen as a block device, hence less confusion
for the system administrator.

Konstantin Shelekhin (2):
  target: Add the DUMMY flag to rd_mcp
  target: Make the virtual LUN 0 device dummy

 drivers/target/target_core_device.c |  2 +-
 drivers/target/target_core_rd.c     | 27 +++++++++++++++++++++++----
 drivers/target/target_core_rd.h     |  1 +
 drivers/target/target_core_spc.c    |  6 +-----
 4 files changed, 26 insertions(+), 10 deletions(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] target: Add the DUMMY flag to rd_mcp
  2021-03-18  9:42 [PATCH 0/2] target: Introduce dummy devices Konstantin Shelekhin
@ 2021-03-18  9:42 ` Konstantin Shelekhin
  2021-03-22 17:06   ` Mike Christie
  2021-03-18  9:42 ` [PATCH 2/2] target: Make the virtual LUN 0 device dummy Konstantin Shelekhin
  1 sibling, 1 reply; 5+ messages in thread
From: Konstantin Shelekhin @ 2021-03-18  9:42 UTC (permalink / raw)
  To: Martin Petersen, Mike Christie, target-devel
  Cc: linux, linux-scsi, Konstantin Shelekhin, Roman Bolshakov

This commit adds the DUMMY flag to the rd_mcp backend that forces a
logical unit to report itself as not connected device of an unknown
type. Essentially this allows users to create devices identical to the
device for the virtual LUN 0, making it possible to explicitly create a
LUN 0 device and configure it's WWNs (e.g. vendor or product name).

Signed-off-by: Konstantin Shelekhin <k.shelekhin@yadro.com>
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
 drivers/target/target_core_rd.c | 27 +++++++++++++++++++++++----
 drivers/target/target_core_rd.h |  1 +
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
index bf936bbeccfe..cdc5c3bc4b07 100644
--- a/drivers/target/target_core_rd.c
+++ b/drivers/target/target_core_rd.c
@@ -530,12 +530,13 @@ rd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
 }
 
 enum {
-	Opt_rd_pages, Opt_rd_nullio, Opt_err
+	Opt_rd_pages, Opt_rd_nullio, Opt_rd_dummy, Opt_err
 };
 
 static match_table_t tokens = {
 	{Opt_rd_pages, "rd_pages=%d"},
 	{Opt_rd_nullio, "rd_nullio=%d"},
+	{Opt_rd_dummy, "rd_dummy=%d"},
 	{Opt_err, NULL}
 };
 
@@ -574,6 +575,14 @@ static ssize_t rd_set_configfs_dev_params(struct se_device *dev,
 			pr_debug("RAMDISK: Setting NULLIO flag: %d\n", arg);
 			rd_dev->rd_flags |= RDF_NULLIO;
 			break;
+		case Opt_rd_dummy:
+			match_int(args, &arg);
+			if (arg != 1)
+				break;
+
+			pr_debug("RAMDISK: Setting DUMMY flag: %d\n", arg);
+			rd_dev->rd_flags |= RDF_DUMMY;
+			break;
 		default:
 			break;
 		}
@@ -590,12 +599,22 @@ static ssize_t rd_show_configfs_dev_params(struct se_device *dev, char *b)
 	ssize_t bl = sprintf(b, "TCM RamDisk ID: %u  RamDisk Makeup: rd_mcp\n",
 			rd_dev->rd_dev_id);
 	bl += sprintf(b + bl, "        PAGES/PAGE_SIZE: %u*%lu"
-			"  SG_table_count: %u  nullio: %d\n", rd_dev->rd_page_count,
+			"  SG_table_count: %u  nullio: %d dummy: %d\n",
+			rd_dev->rd_page_count,
 			PAGE_SIZE, rd_dev->sg_table_count,
-			!!(rd_dev->rd_flags & RDF_NULLIO));
+			!!(rd_dev->rd_flags & RDF_NULLIO),
+			!!(rd_dev->rd_flags & RDF_DUMMY));
 	return bl;
 }
 
+static u32 rd_get_device_type(struct se_device *dev)
+{
+	if (RD_DEV(dev)->rd_flags & RDF_DUMMY)
+		return 0x3f; /* Unknown device type, not connected */
+	else
+		return TYPE_DISK;
+}
+
 static sector_t rd_get_blocks(struct se_device *dev)
 {
 	struct rd_dev *rd_dev = RD_DEV(dev);
@@ -647,7 +666,7 @@ static const struct target_backend_ops rd_mcp_ops = {
 	.parse_cdb		= rd_parse_cdb,
 	.set_configfs_dev_params = rd_set_configfs_dev_params,
 	.show_configfs_dev_params = rd_show_configfs_dev_params,
-	.get_device_type	= sbc_get_device_type,
+	.get_device_type	= rd_get_device_type,
 	.get_blocks		= rd_get_blocks,
 	.init_prot		= rd_init_prot,
 	.free_prot		= rd_free_prot,
diff --git a/drivers/target/target_core_rd.h b/drivers/target/target_core_rd.h
index 8b88f9b14c3f..9ffda5c4b584 100644
--- a/drivers/target/target_core_rd.h
+++ b/drivers/target/target_core_rd.h
@@ -28,6 +28,7 @@ struct rd_dev_sg_table {
 
 #define RDF_HAS_PAGE_COUNT	0x01
 #define RDF_NULLIO		0x02
+#define RDF_DUMMY		0x04
 
 struct rd_dev {
 	struct se_device dev;
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] target: Make the virtual LUN 0 device dummy
  2021-03-18  9:42 [PATCH 0/2] target: Introduce dummy devices Konstantin Shelekhin
  2021-03-18  9:42 ` [PATCH 1/2] target: Add the DUMMY flag to rd_mcp Konstantin Shelekhin
@ 2021-03-18  9:42 ` Konstantin Shelekhin
  1 sibling, 0 replies; 5+ messages in thread
From: Konstantin Shelekhin @ 2021-03-18  9:42 UTC (permalink / raw)
  To: Martin Petersen, Mike Christie, target-devel
  Cc: linux, linux-scsi, Konstantin Shelekhin, Roman Bolshakov

Create the device for the virtual LUN 0 using the DUMMY flag. This
change makes it possible to remove some special-casing in the
INQUIRY code.

Signed-off-by: Konstantin Shelekhin <k.shelekhin@yadro.com>
Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
 drivers/target/target_core_device.c | 2 +-
 drivers/target/target_core_spc.c    | 6 +-----
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index 7787c527aad3..2d50da7840fc 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -1029,7 +1029,7 @@ int core_dev_setup_virtual_lun0(void)
 {
 	struct se_hba *hba;
 	struct se_device *dev;
-	char buf[] = "rd_pages=8,rd_nullio=1";
+	char buf[] = "rd_pages=8,rd_nullio=1,rd_dummy=1";
 	int ret;
 
 	hba = core_alloc_hba("rd_mcp", 0, HBA_FLAGS_INTERNAL_USE);
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index ca5579ebc81d..70a661801cb9 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -701,7 +701,6 @@ static sense_reason_t
 spc_emulate_inquiry(struct se_cmd *cmd)
 {
 	struct se_device *dev = cmd->se_dev;
-	struct se_portal_group *tpg = cmd->se_lun->lun_tpg;
 	unsigned char *rbuf;
 	unsigned char *cdb = cmd->t_task_cdb;
 	unsigned char *buf;
@@ -715,10 +714,7 @@ spc_emulate_inquiry(struct se_cmd *cmd)
 		return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
 	}
 
-	if (dev == rcu_access_pointer(tpg->tpg_virt_lun0->lun_se_dev))
-		buf[0] = 0x3f; /* Not connected */
-	else
-		buf[0] = dev->transport->get_device_type(dev);
+	buf[0] = dev->transport->get_device_type(dev);
 
 	if (!(cdb[1] & 0x1)) {
 		if (cdb[2]) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] target: Add the DUMMY flag to rd_mcp
  2021-03-18  9:42 ` [PATCH 1/2] target: Add the DUMMY flag to rd_mcp Konstantin Shelekhin
@ 2021-03-22 17:06   ` Mike Christie
  2021-03-22 18:57     ` Konstantin Shelekhin
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Christie @ 2021-03-22 17:06 UTC (permalink / raw)
  To: Konstantin Shelekhin, Martin Petersen, target-devel
  Cc: linux, linux-scsi, Roman Bolshakov

On 3/18/21 4:42 AM, Konstantin Shelekhin wrote:
> This commit adds the DUMMY flag to the rd_mcp backend that forces a
> logical unit to report itself as not connected device of an unknown
> type. Essentially this allows users to create devices identical to the
> device for the virtual LUN 0, making it possible to explicitly create a
> LUN 0 device and configure it's WWNs (e.g. vendor or product name).
> 
> Signed-off-by: Konstantin Shelekhin <k.shelekhin@yadro.com>
> Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com>
> ---
>  drivers/target/target_core_rd.c | 27 +++++++++++++++++++++++----
>  drivers/target/target_core_rd.h |  1 +
>  2 files changed, 24 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/target/target_core_rd.c b/drivers/target/target_core_rd.c
> index bf936bbeccfe..cdc5c3bc4b07 100644
> --- a/drivers/target/target_core_rd.c
> +++ b/drivers/target/target_core_rd.c
> @@ -530,12 +530,13 @@ rd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
>  }
>  
>  enum {
> -	Opt_rd_pages, Opt_rd_nullio, Opt_err
> +	Opt_rd_pages, Opt_rd_nullio, Opt_rd_dummy, Opt_err
>  };
>  
>  static match_table_t tokens = {
>  	{Opt_rd_pages, "rd_pages=%d"},
>  	{Opt_rd_nullio, "rd_nullio=%d"},
> +	{Opt_rd_dummy, "rd_dummy=%d"},
>  	{Opt_err, NULL}
>  };
>  
> @@ -574,6 +575,14 @@ static ssize_t rd_set_configfs_dev_params(struct se_device *dev,
>  			pr_debug("RAMDISK: Setting NULLIO flag: %d\n", arg);
>  			rd_dev->rd_flags |= RDF_NULLIO;
>  			break;
> +		case Opt_rd_dummy:
> +			match_int(args, &arg);
> +			if (arg != 1)
> +				break;
> +
> +			pr_debug("RAMDISK: Setting DUMMY flag: %d\n", arg);
> +			rd_dev->rd_flags |= RDF_DUMMY;
> +			break;
>  		default:
>  			break;
>  		}
> @@ -590,12 +599,22 @@ static ssize_t rd_show_configfs_dev_params(struct se_device *dev, char *b)
>  	ssize_t bl = sprintf(b, "TCM RamDisk ID: %u  RamDisk Makeup: rd_mcp\n",
>  			rd_dev->rd_dev_id);
>  	bl += sprintf(b + bl, "        PAGES/PAGE_SIZE: %u*%lu"
> -			"  SG_table_count: %u  nullio: %d\n", rd_dev->rd_page_count,
> +			"  SG_table_count: %u  nullio: %d dummy: %d\n",
> +			rd_dev->rd_page_count,
>  			PAGE_SIZE, rd_dev->sg_table_count,
> -			!!(rd_dev->rd_flags & RDF_NULLIO));
> +			!!(rd_dev->rd_flags & RDF_NULLIO),
> +			!!(rd_dev->rd_flags & RDF_DUMMY));
>  	return bl;
>  }
>  
> +static u32 rd_get_device_type(struct se_device *dev)
> +{
> +	if (RD_DEV(dev)->rd_flags & RDF_DUMMY)
> +		return 0x3f; /* Unknown device type, not connected */
> +	else
> +		return TYPE_DISK;

Maybe have this call sbc_get_device_type here so it matches the other drivers
and how this driver calls into lio core for other operations/fields like
parse_cdb or the attrs.


> +}
> +
>  static sector_t rd_get_blocks(struct se_device *dev)
>  {
>  	struct rd_dev *rd_dev = RD_DEV(dev);
> @@ -647,7 +666,7 @@ static const struct target_backend_ops rd_mcp_ops = {
>  	.parse_cdb		= rd_parse_cdb,
>  	.set_configfs_dev_params = rd_set_configfs_dev_params,
>  	.show_configfs_dev_params = rd_show_configfs_dev_params,
> -	.get_device_type	= sbc_get_device_type,
> +	.get_device_type	= rd_get_device_type,
>  	.get_blocks		= rd_get_blocks,
>  	.init_prot		= rd_init_prot,
>  	.free_prot		= rd_free_prot,
> diff --git a/drivers/target/target_core_rd.h b/drivers/target/target_core_rd.h
> index 8b88f9b14c3f..9ffda5c4b584 100644
> --- a/drivers/target/target_core_rd.h
> +++ b/drivers/target/target_core_rd.h
> @@ -28,6 +28,7 @@ struct rd_dev_sg_table {
>  
>  #define RDF_HAS_PAGE_COUNT	0x01
>  #define RDF_NULLIO		0x02
> +#define RDF_DUMMY		0x04
>  
>  struct rd_dev {
>  	struct se_device dev;
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] target: Add the DUMMY flag to rd_mcp
  2021-03-22 17:06   ` Mike Christie
@ 2021-03-22 18:57     ` Konstantin Shelekhin
  0 siblings, 0 replies; 5+ messages in thread
From: Konstantin Shelekhin @ 2021-03-22 18:57 UTC (permalink / raw)
  To: Mike Christie
  Cc: Martin Petersen, target-devel, linux, linux-scsi, Roman Bolshakov

On Mon, Mar 22, 2021 at 12:06:36PM -0500, Mike Christie wrote:
> > +static u32 rd_get_device_type(struct se_device *dev)
> > +{
> > +	if (RD_DEV(dev)->rd_flags & RDF_DUMMY)
> > +		return 0x3f; /* Unknown device type, not connected */
> > +	else
> > +		return TYPE_DISK;
> 
> Maybe have this call sbc_get_device_type here so it matches the other drivers
> and how this driver calls into lio core for other operations/fields like
> parse_cdb or the attrs.

Yeah, good point, I'll fix and send the next round. Are you okay with
the whole idea though?

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-03-22 18:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-18  9:42 [PATCH 0/2] target: Introduce dummy devices Konstantin Shelekhin
2021-03-18  9:42 ` [PATCH 1/2] target: Add the DUMMY flag to rd_mcp Konstantin Shelekhin
2021-03-22 17:06   ` Mike Christie
2021-03-22 18:57     ` Konstantin Shelekhin
2021-03-18  9:42 ` [PATCH 2/2] target: Make the virtual LUN 0 device dummy Konstantin Shelekhin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.