[PATCH] scsi: sd: support specify probe type of build-in driver

From: Jianlin Lv
Date: Tue Jun 06 2023 - 01:12:57 EST


When SCSI disks are located on different SCSI hosts within a system,
asynchronous detection can lead to non-deterministic SCSI disk names.

This patch introduces the 'sd_probe_type=' kernel boot parameter.

In scenarios where SCSI disk name sensitivity is crucial, the probe type
of the build-in sd driver can be set to synchronous. As a result,
the scsi disk names are deterministic.

Signed-off-by: Jianlin Lv <iecedge@xxxxxxxxx>
---
.../admin-guide/kernel-parameters.txt | 9 ++++++++
drivers/scsi/sd.c | 23 +++++++++++++++++++
2 files changed, 32 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index 9e5bab29685f..083f741d63bb 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -5611,6 +5611,15 @@
non-zero "wait" parameter. See weight_single
and weight_many.

+ sd_probe_type= [HW,SCSI] Manual setup probe type of built-in scsi disk driver
+ Format: <int>
+ Default: 1
+ <int> -- device driver probe type to try
+ 0 - PROBE_DEFAULT_STRATEGY
+ 1 - PROBE_PREFER_ASYNCHRONOUS
+ 2 - PROBE_FORCE_SYNCHRONOUS
+ Example: sd_probe_type=1
+
skew_tick= [KNL] Offset the periodic timer tick per cpu to mitigate
xtime_lock contention on larger systems, and/or RCU lock
contention on all systems with CONFIG_MAXSMP set.
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index 1624d528aa1f..78b80b9e5618 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -121,6 +121,9 @@ static void scsi_disk_release(struct device *cdev);

static DEFINE_IDA(sd_index_ida);

+/* Probe type of SCSI Disk Driver */
+static int sd_probe_type = PROBE_PREFER_ASYNCHRONOUS;
+
static mempool_t *sd_page_pool;
static struct lock_class_key sd_bio_compl_lkclass;

@@ -3826,6 +3829,25 @@ static int sd_resume_runtime(struct device *dev)
return sd_resume(dev);
}

+#ifndef MODULE
+
+/* Set the boot options to sd driver.
+ * Syntax is defined in Documentation/admin-guide/kernel-parameters.txt.
+ */
+static int __init sd_probe_setup(char *str)
+{
+ int probe_type = -1;
+
+ if (get_option(&str, &probe_type) && probe_type >= 0 && probe_type < 3)
+ sd_probe_type = probe_type;
+
+ return 1;
+}
+
+__setup("sd_probe_type=", sd_probe_setup);
+
+#endif
+
/**
* init_sd - entry point for this driver (both when built in or when
* a module).
@@ -3858,6 +3880,7 @@ static int __init init_sd(void)
goto err_out_class;
}

+ sd_template.gendrv.probe_type = sd_probe_type;
err = scsi_register_driver(&sd_template.gendrv);
if (err)
goto err_out_driver;
--
2.25.1