diff mbox series

[RFC,v2,05/18] scsi: core: Allocate SCSI host sdev when required

Message ID 1654770559-101375-6-git-send-email-john.garry@huawei.com (mailing list archive)
State New, archived
Headers show
Series blk-mq/libata/scsi: SCSI driver tagging improvements | expand

Commit Message

John Garry June 9, 2022, 10:29 a.m. UTC
When the shost supports reserved commands then allocate the SCSI host sdev.

As noted later, we need to use this for libata internal commands.

Signed-off-by: John Garry <john.garry@huawei.com>
---
 drivers/scsi/hosts.c     | 5 +++++
 include/scsi/scsi_host.h | 1 +
 2 files changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 5c9b05a8fec8..67930a61b222 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -298,6 +298,8 @@  int scsi_add_host_with_dma(struct Scsi_Host *shost, struct device *dev,
 
 	scsi_proc_host_add(shost);
 	scsi_autopm_put_host(shost);
+	if (shost->nr_reserved_cmds)
+		shost->sdev = scsi_get_host_dev(shost); // TODO: Add error handling
 	return error;
 
 	/*
@@ -360,6 +362,9 @@  static void scsi_host_dev_release(struct device *dev)
 
 	if (shost->shost_state != SHOST_CREATED)
 		put_device(parent);
+	if (shost->sdev)
+		scsi_free_host_dev(shost->sdev);
+
 	kfree(shost);
 }
 
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 88c8504395c8..2e14d65b7444 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -566,6 +566,7 @@  struct Scsi_Host {
 	wait_queue_head_t       host_wait;
 	struct scsi_host_template *hostt;
 	struct scsi_transport_template *transportt;
+	struct scsi_device *sdev;
 
 	/* Area to keep a shared tag map */
 	struct blk_mq_tag_set	tag_set;