Skip to contentSkip to conversation

target: perform t10_wwn ID initialisation in target_alloc_device()

PATCH Superseded David Disseldorp 3 participants 5 messages Nov 30, 2018 – Dec 4, 2018 SCSI target

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 5/5 target: perform t10_wwn ID initialisation in target_alloc_device()

Initialise the t10_wwn vendor, model and revision defaults when a device is allocated instead of when it's enabled. This ensures that custom vendor or model strings set prior to enablement are not later overwritten with default values.

---
 drivers/target/target_core_device.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
drivers/target/target_core_device.c +17 -17
index 5512871f50e4..6318d59a1564 100644
@@ -810,6 +810,23 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
 	mutex_init(&xcopy_lun->lun_tg_pt_md_mutex);
 	xcopy_lun->lun_tpg = &xcopy_pt_tpg;
 
+	/*
+	 * Preload the initial INQUIRY const values if we are doing
+	 * anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI
+	 * passthrough because this is being provided by the backend LLD.
+	 */
+	BUILD_BUG_ON(sizeof(dev->t10_wwn.vendor) != INQUIRY_VENDOR_LEN + 1);
+	BUILD_BUG_ON(sizeof(dev->t10_wwn.model) != INQUIRY_MODEL_LEN + 1);
+	BUILD_BUG_ON(sizeof(dev->t10_wwn.revision) != INQUIRY_REVISION_LEN + 1);
+	if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) {
+		strlcpy(dev->t10_wwn.vendor, "LIO-ORG",
+			sizeof(dev->t10_wwn.vendor));
+		strlcpy(dev->t10_wwn.model, dev->transport->inquiry_prod,
+			sizeof(dev->t10_wwn.model));
+		strlcpy(dev->t10_wwn.revision, dev->transport->inquiry_rev,
+			sizeof(dev->t10_wwn.revision));
+	}
+
 	return dev;
 }
 
@@ -984,23 +1001,6 @@ int target_configure_device(struct se_device *dev)
 	 */
 	INIT_WORK(&dev->qf_work_queue, target_qf_do_work);
 
-	/*
-	 * Preload the initial INQUIRY const values if we are doing
-	 * anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI
-	 * passthrough because this is being provided by the backend LLD.
-	 */
-	BUILD_BUG_ON(sizeof(dev->t10_wwn.vendor) != INQUIRY_VENDOR_LEN + 1);
-	BUILD_BUG_ON(sizeof(dev->t10_wwn.model) != INQUIRY_MODEL_LEN + 1);
-	BUILD_BUG_ON(sizeof(dev->t10_wwn.revision) != INQUIRY_REVISION_LEN + 1);
-	if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) {
-		strlcpy(dev->t10_wwn.vendor, "LIO-ORG",
-			sizeof(dev->t10_wwn.vendor));
-		strlcpy(dev->t10_wwn.model, dev->transport->inquiry_prod,
-			sizeof(dev->t10_wwn.model));
-		strlcpy(dev->t10_wwn.revision, dev->transport->inquiry_rev,
-			sizeof(dev->t10_wwn.revision));
-	}
-
 	scsi_dump_inquiry(dev);
 
 	spin_lock(&hba->device_lock);
Signature · 1 line
2.13.7
#1 lore raw
Quoted 10 lines · David Disseldorp

Initialise the t10_wwn vendor, model and revision defaults when a device is allocated instead of when it's enabled. This ensures that custom vendor or model strings set prior to enablement are not later overwritten with default values.

---
  drivers/target/target_core_device.c | 34 +++++++++++++++++-----------------
  1 file changed, 17 insertions(+), 17 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/target/target_core_device.c

Quoted 17 lines

index 5512871f50e4..6318d59a1564 100644

drivers/target/target_core_device.c +10 -0
@@ -810,6 +810,23 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
  	mutex_init(&xcopy_lun->lun_tg_pt_md_mutex);
  	xcopy_lun->lun_tpg = &xcopy_pt_tpg;
 
+	/*
+	 * Preload the initial INQUIRY const values if we are doing
+	 * anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI
+	 * passthrough because this is being provided by the backend LLD.
+	 */
+	BUILD_BUG_ON(sizeof(dev->t10_wwn.vendor) != INQUIRY_VENDOR_LEN + 1);
+	BUILD_BUG_ON(sizeof(dev->t10_wwn.model) != INQUIRY_MODEL_LEN + 1);
+	BUILD_BUG_ON(sizeof(dev->t10_wwn.revision) != INQUIRY_REVISION_LEN + 1);
+	if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) {
+		strlcpy(dev->t10_wwn.vendor, "LIO-ORG",

drivers/target/target_core_device.c struct se_device *target_alloc_device(struct se_hba *hba, const char *name) · line 832

Quoted 10 lines
drivers/target/target_core_device.c +7 -0
+			sizeof(dev->t10_wwn.vendor));
+		strlcpy(dev->t10_wwn.model, dev->transport->inquiry_prod,
+			sizeof(dev->t10_wwn.model));
+		strlcpy(dev->t10_wwn.revision, dev->transport->inquiry_rev,
+			sizeof(dev->t10_wwn.revision));
+	}
+
  	return dev;
  }
 

This is odd. I'd rather have it consistent across backends, ie either move the initialisation into the backends, or provide a means to check if the inquiry data has already been pre-filled.
But this check really is awkward.

Cheers,

Hannes

#2 lore raw
In reply to David Disseldorp

Hi Hannes,

Thanks for the feedback...

Quoted 1 line · Hannes Reinecke

On 12/1/18 12:34 AM, David Disseldorp wrote:

...

Quoted 20 lines
Quoted 20 lines
drivers/target/target_core_device.c +16 -0
@@ -810,6 +810,23 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
  	mutex_init(&xcopy_lun->lun_tg_pt_md_mutex);
  	xcopy_lun->lun_tpg = &xcopy_pt_tpg;
 
+	/*
+	 * Preload the initial INQUIRY const values if we are doing
+	 * anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI
+	 * passthrough because this is being provided by the backend LLD.
+	 */
+	BUILD_BUG_ON(sizeof(dev->t10_wwn.vendor) != INQUIRY_VENDOR_LEN + 1);
+	BUILD_BUG_ON(sizeof(dev->t10_wwn.model) != INQUIRY_MODEL_LEN + 1);
+	BUILD_BUG_ON(sizeof(dev->t10_wwn.revision) != INQUIRY_REVISION_LEN + 1);
+	if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) {
+		strlcpy(dev->t10_wwn.vendor, "LIO-ORG",
+			sizeof(dev->t10_wwn.vendor));
+		strlcpy(dev->t10_wwn.model, dev->transport->inquiry_prod,
+			sizeof(dev->t10_wwn.model));
+		strlcpy(dev->t10_wwn.revision, dev->transport->inquiry_rev,
+			sizeof(dev->t10_wwn.revision));
+	}
Quoted 8 lines

drivers/target/target_core_device.c struct se_device *target_alloc_device(struct se_hba *hba, const char *name) · line 832

Quoted 4 lines
drivers/target/target_core_device.c +1 -0
+
  	return dev;
  }
 

This is odd. I'd rather have it consistent across backends, ie either move the initialisation into the backends, or provide a means to check if the inquiry data has already been pre-filled.
But this check really is awkward.

Not quite sure I follow here. I could the default setting to the target_backend_ops.alloc_device() code paths, but I don't think the duplication would make this much cleaner, if at all.
I can look into this further if you like (target_backend_ops.inquiry_rev could be dropped that way), but my preference would be to do so as a follow-up patch-set.

Cheers, David

#3 lore raw
In reply to David Disseldorp
Quoted 17 lines · David Disseldorp
Quoted 8 lines
Quoted 8 lines
drivers/target/target_core_device.c +8 -0
+	if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) {
+		strlcpy(dev->t10_wwn.vendor, "LIO-ORG",
+			sizeof(dev->t10_wwn.vendor));
+		strlcpy(dev->t10_wwn.model, dev->transport->inquiry_prod,
+			sizeof(dev->t10_wwn.model));
+		strlcpy(dev->t10_wwn.revision, dev->transport->inquiry_rev,
+			sizeof(dev->t10_wwn.revision));
+	}
Quoted 8 lines
Quoted 4 lines

+
return dev;
}

This is odd. I'd rather have it consistent across backends, ie either move the initialisation into the backends, or provide a means to check if the inquiry data has already been pre-filled.
But this check really is awkward.

Quoted 5 lines

Not quite sure I follow here. I could the default setting to the target_backend_ops.alloc_device() code paths, but I don't think the duplication would make this much cleaner, if at all.
I can look into this further if you like (target_backend_ops.inquiry_rev could be dropped that way),

Looking a little closer, I think we can drop the conditional completely and set the vendor/model/rev defaults for all cases here:
- target_core_pscsi overwrites the defaults in the pscsi_configure_device() callback.
+ the contents is then only used for configfs via $pscsi_dev/info, $pscsi_dev/statistics/scsi_lu/vend, etc.
- target_core_user doesn't touch the defaults, nor are they used for anything outside of configfs.

Quoted 2 lines

but my preference would be to do so as a
follow-up patch-set.

This is still my preference.

Cheers, David

#4 lore raw
In reply to David Disseldorp

On Sat, 2018-12-01 at 15:59 +-0100, Hannes Reinecke wrote:
+AD4 On 12/1/18 12:34 AM, David Disseldorp wrote:
+AD4 +AD4 Initialise the t10+AF8-wwn vendor, model and revision defaults when a
+AD4 +AD4 device is allocated instead of when it's enabled. This ensures that
+AD4 +AD4 custom vendor or model strings set prior to enablement are not later
+AD4 +AD4 overwritten with default values.
+AD4 +AD4
+AD4 +AD4 Signed-off-by: David Disseldorp +ADw-ddiss+AEA-suse.de+AD4
+AD4 +AD4 ---
+AD4 +AD4 drivers/target/target+AF8-core+AF8-device.c +AHw 34 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+------------------
+AD4 +AD4 1 file changed, 17 insertions(+-), 17 deletions(-)
+AD4 +AD4 +AD4 diff --git a/drivers/target/target+AF8-core+AF8-device.c
+AD4
+AD4 b/drivers/target/target+AF8-core+AF8-device.c
+AD4 +AD4 index 5512871f50e4..6318d59a1564 100644
+AD4 +AD4 --- a/drivers/target/target+AF8-core+AF8-device.c
+AD4 +AD4 +-+-+- b/drivers/target/target+AF8-core+AF8-device.c
+AD4 +AD4 +AEAAQA -810,6 +-810,23 +AEAAQA struct se+AF8-device +ACo-target+AF8-alloc+AF8-device(struct se+AF8-hba +ACo-hba, const char +ACo-name)
+AD4 +AD4 mutex+AF8-init(+ACY-xcopy+AF8-lun-+AD4-lun+AF8-tg+AF8-pt+AF8-md+AF8-mutex)+ADs
+AD4 +AD4 xcopy+AF8-lun-+AD4-lun+AF8-tpg +AD0 +ACY-xcopy+AF8-pt+AF8-tpg+ADs
+AD4 +AD4
+AD4 +AD4 +- /+ACo
+AD4 +AD4 +- +ACo Preload the initial INQUIRY const values if we are doing
+AD4 +AD4 +- +ACo anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI
+AD4 +AD4 +- +ACo passthrough because this is being provided by the backend LLD.
+AD4 +AD4 +- +ACo-/
+AD4 +AD4 +- BUILD+AF8-BUG+AF8-ON(sizeof(dev-+AD4-t10+AF8-wwn.vendor) +ACEAPQ INQUIRY+AF8-VENDOR+AF8-LEN +- 1)+ADs
+AD4 +AD4 +- BUILD+AF8-BUG+AF8-ON(sizeof(dev-+AD4-t10+AF8-wwn.model) +ACEAPQ INQUIRY+AF8-MODEL+AF8-LEN +- 1)+ADs
+AD4 +AD4 +- BUILD+AF8-BUG+AF8-ON(sizeof(dev-+AD4-t10+AF8-wwn.revision) +ACEAPQ INQUIRY+AF8-REVISION+AF8-LEN +- 1)+ADs
+AD4 +AD4 +- if (+ACE(dev-+AD4-transport-+AD4-transport+AF8-flags +ACY TRANSPORT+AF8-FLAG+AF8-PASSTHROUGH)) +AHs
+AD4 +AD4 +- strlcpy(dev-+AD4-t10+AF8-wwn.vendor, +ACI-LIO-ORG+ACI,
+AD4 +AD4 +- sizeof(dev-+AD4-t10+AF8-wwn.vendor))+ADs
+AD4 +AD4 +- strlcpy(dev-+AD4-t10+AF8-wwn.model, dev-+AD4-transport-+AD4-inquiry+AF8-prod,
+AD4 +AD4 +- sizeof(dev-+AD4-t10+AF8-wwn.model))+ADs
+AD4 +AD4 +- strlcpy(dev-+AD4-t10+AF8-wwn.revision, dev-+AD4-transport-+AD4-inquiry+AF8-rev,
+AD4 +AD4 +- sizeof(dev-+AD4-t10+AF8-wwn.revision))+ADs
+AD4 +AD4 +- +AH0
+AD4 +AD4 +-
+AD4 +AD4 return dev+ADs
+AD4 +AD4 +AH0
+AD4 +AD4
+AD4
+AD4 This is odd. I'd rather have it consistent across backends, ie either
+AD4 move the initialisation into the backends, or provide a means to check
+AD4 if the inquiry data has already been pre-filled.
+AD4 But this check really is awkward.

Agreed. I also would like to see that that if-condition is removed ...

Thanks,

Bart.