On 13/09/2022 20:57, Bart Van Assche wrote:
Instead of clearing the host template module pointer if the LLD kernel
module is being unloaded, set the 'drop_module_ref' SCSI device member.
This patch prepares for constifying the SCSI host template.
Cc: Christoph Hellwig <hch@xxxxxx>
Cc: Ming Lei <ming.lei@xxxxxxxxxx>
Cc: Hannes Reinecke <hare@xxxxxxx>
Cc: John Garry <john.garry@xxxxxxxxxx>
Cc: Mike Christie <michael.christie@xxxxxxxxxx>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxx>
Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
drivers/scsi/scsi_sysfs.c | 7 +++----
include/scsi/scsi_device.h | 1 +
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 5d61f58399dc..822ae60a64b9 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -454,7 +454,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
sdev = container_of(work, struct scsi_device, ew.work);
- mod = sdev->host->hostt->module;
+ mod = sdev->drop_module_ref ? sdev->host->hostt->module : NULL;
I suppose that this works.
My reservation is that there were some concerns of current module
referencing solution, so may not be better to build directly on it:
https://lore.kernel.org/linux-scsi/Ynt0aFMX+z%2FUhGJ2@xxxxxxxxxxxxx/
Thanks,
John
scsi_dh_release_device(sdev);
@@ -525,9 +525,8 @@ static void scsi_device_dev_release(struct device *dev)
{
struct scsi_device *sdp = to_scsi_device(dev);
- /* Set module pointer as NULL in case of module unloading */
- if (!try_module_get(sdp->host->hostt->module))
- sdp->host->hostt->module = NULL;
+ if (try_module_get(sdp->host->hostt->module))
+ sdp->drop_module_ref = true;
execute_in_process_context(scsi_device_dev_release_usercontext,
&sdp->ew);
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index 2493bd65351a..b03176b69056 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -214,6 +214,7 @@ struct scsi_device {
* creation time */
unsigned ignore_media_change:1; /* Ignore MEDIA CHANGE on resume */
unsigned silence_suspend:1; /* Do not print runtime PM related messages */
+ unsigned drop_module_ref:1;
unsigned int queue_stopped; /* request queue is quiesced */
bool offline_already; /* Device offline message logged */
.