diff mbox

[RFC,2/4] iscsi: sysfs filtering by network namespace

Message ID 1431555167-23995-3-git-send-email-cleech@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Leech May 13, 2015, 10:12 p.m. UTC
This makes the iscsi_host, iscsi_session, iscsi_connection, and
iscsi_endpoint transport class devices only visible in sysfs under a
matching network namespace.  The network namespace for all of these
objects is tracked in the iscsi_cls_host structure.
---
 drivers/scsi/scsi_transport_iscsi.c | 114 ++++++++++++++++++++++++++++++------
 include/scsi/scsi_transport_iscsi.h |   1 +
 2 files changed, 98 insertions(+), 17 deletions(-)

Comments

Chris Leech May 21, 2015, 8:49 p.m. UTC | #1
On Wed, May 13, 2015 at 03:12:45PM -0700, Chris Leech wrote:
> This makes the iscsi_host, iscsi_session, iscsi_connection, and
> iscsi_endpoint transport class devices only visible in sysfs under a
> matching network namespace.  The network namespace for all of these
> objects is tracked in the iscsi_cls_host structure.

I noticed that I didn't change iscsi_iface, but it should probably be
handled the same was as iscsi_endpoint.

I had intentionally skipped over all the flashnode stuff, until I had a
chance to go back and take a closer look.

Is there any particular reason why the flashnode support was implemented
as a bus?  Following the pattern of everything else in
scsi_transport_iscsi it should probably have been two classes
(iscsi_flash_session and iscsi_flash_conn).  It's an issue as sysfs
tagging only works on a per-class basis right now.

I can see a couple of ways forward.

1) Extend sysfs tagging to work with device_type as well as class, and
   use that for the two types on the flashnode "bus"

2) Change the flashnode code to use classes instead of a bus.  
   Keeping a single iscsi_flashnode class and continuing to use the two
   device_types for sessions and connections should result in the only
   visible change being /sys/bus/iscsi_flashnode moving to
   /sys/class/iscsi_flashnode.

I prefer #2, but it looks like the open-iscsi tools would need to be
updated (not all code paths follow the recommendations to ignore
bus/class differences and check all subsystem locations).  And I don't
know for sure that there aren't any other tools using this interface
(it's only implemented for qla4xxx).

- Chris
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mike Christie May 22, 2015, 3:49 p.m. UTC | #2
On 5/21/15, 3:49 PM, Chris Leech wrote:
> On Wed, May 13, 2015 at 03:12:45PM -0700, Chris Leech wrote:
>> This makes the iscsi_host, iscsi_session, iscsi_connection, and
>> iscsi_endpoint transport class devices only visible in sysfs under a
>> matching network namespace.  The network namespace for all of these
>> objects is tracked in the iscsi_cls_host structure.
>
> I noticed that I didn't change iscsi_iface, but it should probably be
> handled the same was as iscsi_endpoint.
>
> I had intentionally skipped over all the flashnode stuff, until I had a
> chance to go back and take a closer look.
>
> Is there any particular reason why the flashnode support was implemented
> as a bus?  Following the pattern of everything else in
> scsi_transport_iscsi it should probably have been two classes
> (iscsi_flash_session and iscsi_flash_conn).  It's an issue as sysfs
> tagging only works on a per-class basis right now.
>


At some point upstream started telling us to stop using classes and use 
buses instead. It was around the time the fcoe's fcoe_sysfs stuff was 
being reviewed. In the middle of this mail is the comment about using 
buses instead of classes for fcoe:

http://www.spinics.net/lists/linux-scsi/msg58168.html

> I can see a couple of ways forward.
>
> 1) Extend sysfs tagging to work with device_type as well as class, and
>     use that for the two types on the flashnode "bus"

If we are supposed to be using buses instead of classes then I think is 
correct.

>
> 2) Change the flashnode code to use classes instead of a bus.
>     Keeping a single iscsi_flashnode class and continuing to use the two
>     device_types for sessions and connections should result in the only
>     visible change being /sys/bus/iscsi_flashnode moving to
>     /sys/class/iscsi_flashnode.

If we can use classes, this is fine with me.

>
> I prefer #2, but it looks like the open-iscsi tools would need to be
> updated (not all code paths follow the recommendations to ignore
> bus/class differences and check all subsystem locations).  And I don't
> know for sure that there aren't any other tools using this interface
> (it's only implemented for qla4xxx).
>

Ccing qlogic. I do not think any tools use it. I do not even know if 
anyone uses iscsiadm to manage it. Qlogic?


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 88a3347..2b146cb 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -161,9 +161,33 @@  static void iscsi_endpoint_release(struct device *dev)
 	kfree(ep);
 }
 
+static const struct net *iscsi_host_net(struct iscsi_cls_host *ihost)
+{
+	return ihost->netns;
+}
+
+static const struct net *iscsi_endpoint_net(struct iscsi_endpoint *ep)
+{
+	struct iscsi_cls_conn *cls_conn = ep->conn;
+	struct iscsi_cls_session *cls_session = iscsi_conn_to_session(cls_conn);
+	struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
+	struct iscsi_cls_host *ihost = shost->shost_data;
+
+	return iscsi_host_net(ihost);
+}
+
+static const void *iscsi_endpoint_namespace(struct device *dev)
+{
+	struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
+
+	return iscsi_endpoint_net(ep);
+}
+
 static struct class iscsi_endpoint_class = {
 	.name = "iscsi_endpoint",
 	.dev_release = iscsi_endpoint_release,
+	.ns_type = &net_ns_type_operations,
+	.namespace = iscsi_endpoint_namespace,
 };
 
 static ssize_t
@@ -1570,6 +1594,7 @@  static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
 	memset(ihost, 0, sizeof(*ihost));
 	atomic_set(&ihost->nr_scans, 0);
 	mutex_init(&ihost->mutex);
+	ihost->netns = &init_net;
 
 	iscsi_bsg_host_add(shost, ihost);
 	/* ignore any bsg add error - we just can't do sgio */
@@ -1590,23 +1615,78 @@  static int iscsi_remove_host(struct transport_container *tc,
 	return 0;
 }
 
-static DECLARE_TRANSPORT_CLASS(iscsi_host_class,
-			       "iscsi_host",
-			       iscsi_setup_host,
-			       iscsi_remove_host,
-			       NULL);
-
-static DECLARE_TRANSPORT_CLASS(iscsi_session_class,
-			       "iscsi_session",
-			       NULL,
-			       NULL,
-			       NULL);
-
-static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,
-			       "iscsi_connection",
-			       NULL,
-			       NULL,
-			       NULL);
+#define DECLARE_TRANSPORT_CLASS_NS(cls, nm, su, rm, cfg, ns, nslookup)	\
+struct transport_class cls = {						\
+	.class = {							\
+		.name = nm,						\
+		.ns_type = ns,						\
+		.namespace = nslookup,					\
+	},								\
+	.setup = su,							\
+	.remove = rm,							\
+	.configure = cfg,						\
+}
+
+static const void *iscsi_host_namespace(struct device *dev)
+{
+	struct Scsi_Host *shost = transport_class_to_shost(dev);
+	struct iscsi_cls_host *ihost = shost->shost_data;
+
+	return iscsi_host_net(ihost);
+}
+
+static DECLARE_TRANSPORT_CLASS_NS(iscsi_host_class,
+				  "iscsi_host",
+				  iscsi_setup_host,
+				  iscsi_remove_host,
+				  NULL,
+				  &net_ns_type_operations,
+				  iscsi_host_namespace);
+
+static const struct net *iscsi_sess_net(struct iscsi_cls_session *cls_session)
+{
+	struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
+	struct iscsi_cls_host *ihost = shost->shost_data;
+
+	return iscsi_host_net(ihost);
+}
+
+static const void *iscsi_sess_namespace(struct device *dev)
+{
+	struct iscsi_cls_session *cls_session = transport_class_to_session(dev);
+
+	return iscsi_sess_net(cls_session);
+}
+
+static DECLARE_TRANSPORT_CLASS_NS(iscsi_session_class,
+				  "iscsi_session",
+				  NULL,
+				  NULL,
+				  NULL,
+				  &net_ns_type_operations,
+				  iscsi_sess_namespace);
+
+static const struct net *iscsi_conn_net(struct iscsi_cls_conn *cls_conn)
+{
+	struct iscsi_cls_session *cls_session = iscsi_conn_to_session(cls_conn);
+
+	return iscsi_sess_net(cls_session);
+}
+
+static const void *iscsi_conn_namespace(struct device *dev)
+{
+	struct iscsi_cls_conn *cls_conn = transport_class_to_conn(dev);
+
+	return iscsi_conn_net(cls_conn);
+}
+
+static DECLARE_TRANSPORT_CLASS_NS(iscsi_connection_class,
+				  "iscsi_connection",
+				  NULL,
+				  NULL,
+				  NULL,
+				  &net_ns_type_operations,
+				  iscsi_conn_namespace);
 
 struct iscsi_net {
 	struct sock *nls;
diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h
index 2555ee5..860ac0c 100644
--- a/include/scsi/scsi_transport_iscsi.h
+++ b/include/scsi/scsi_transport_iscsi.h
@@ -275,6 +275,7 @@  struct iscsi_cls_host {
 	struct request_queue *bsg_q;
 	uint32_t port_speed;
 	uint32_t port_state;
+	struct net *netns;
 };
 
 #define iscsi_job_to_shost(_job) \