iSER creates endpoints before hosts and sessions, so we need to keep
compatibility with virtual device paths and not always expect a parent
host.

Signed-off-by: Chris Leech <cle...@redhat.com>
---
 drivers/scsi/scsi_transport_iscsi.c | 9 ++++++---
 include/scsi/scsi_transport_iscsi.h | 3 ++-
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/scsi_transport_iscsi.c 
b/drivers/scsi/scsi_transport_iscsi.c
index 41f0de2165e0..b8e451a8c76c 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -189,8 +189,10 @@ static struct net *iscsi_host_net(struct iscsi_cls_host 
*ihost)
 static struct net *iscsi_endpoint_net(struct iscsi_endpoint *ep)
 {
        struct Scsi_Host *shost = iscsi_endpoint_to_shost(ep);
-       struct iscsi_cls_host *ihost = shost->shost_data;
-
+       struct iscsi_cls_host *ihost;
+       if (!shost)
+               return &init_net;
+       ihost = shost->shost_data;
        return iscsi_host_net(ihost);
 }
 
@@ -252,7 +254,8 @@ iscsi_create_endpoint(struct Scsi_Host *shost, int dd_size)
 
        ep->id = id;
        ep->dev.class = &iscsi_endpoint_class;
-       ep->dev.parent = &shost->shost_gendev;
+       if (shost)
+               ep->dev.parent = &shost->shost_gendev;
        dev_set_name(&ep->dev, "ep-%d", id);
        err = device_register(&ep->dev);
         if (err)
diff --git a/include/scsi/scsi_transport_iscsi.h 
b/include/scsi/scsi_transport_iscsi.h
index d233618a17de..bb6734e900e0 100644
--- a/include/scsi/scsi_transport_iscsi.h
+++ b/include/scsi/scsi_transport_iscsi.h
@@ -293,8 +293,9 @@ struct iscsi_cls_session {
 #define iscsi_session_to_shost(_session) \
        dev_to_shost(_session->dev.parent)
 
+/* endpoints might not have a parent host (iSER) */
 #define iscsi_endpoint_to_shost(_ep) \
-       dev_to_shost(_ep->dev.parent)
+       dev_to_shost(&_ep->dev)
 
 extern struct net *iscsi_sess_net(struct iscsi_cls_session *session);
 
-- 
2.39.2

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to open-iscsi+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/open-iscsi/20230421050521.49903-2-cleech%40redhat.com.

Reply via email to