All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Leech <cleech@redhat.com>
To: netdev@vger.kernel.org, containers@lists.linux-foundation.org
Subject: [PATCH 3/9] iscsi: sysfs filtering by network namespace
Date: Tue,  7 Nov 2017 14:45:07 -0800	[thread overview]
Message-ID: <20171107224513.4217-4-cleech@redhat.com> (raw)
In-Reply-To: <20171107224513.4217-1-cleech@redhat.com>

This makes the iscsi_host, iscsi_session, iscsi_connection, iscsi_iface,
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.

Signed-off-by: Chris Leech <cleech@redhat.com>
---
 drivers/scsi/scsi_transport_iscsi.c | 128 +++++++++++++++++++++++++++++++-----
 include/scsi/scsi_transport_iscsi.h |   1 +
 2 files changed, 112 insertions(+), 17 deletions(-)

diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 6ab7ca82b121..d29c095ccc7d 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -161,9 +161,31 @@ static void iscsi_endpoint_release(struct device *dev)
 	kfree(ep);
 }
 
+static struct net *iscsi_host_net(struct iscsi_cls_host *ihost)
+{
+	return ihost->netns;
+}
+
+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;
+
+	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
@@ -285,10 +307,26 @@ static void iscsi_iface_release(struct device *dev)
 	put_device(parent);
 }
 
+static struct net *iscsi_iface_net(struct iscsi_iface *iface)
+{
+	struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
+	struct iscsi_cls_host *ihost = shost->shost_data;
+
+	return iscsi_host_net(ihost);
+}
+
+static const void *iscsi_iface_namespace(struct device *dev)
+{
+	struct iscsi_iface *iface = iscsi_dev_to_iface(dev);
+
+	return iscsi_iface_net(iface);
+}
 
 static struct class iscsi_iface_class = {
 	.name = "iscsi_iface",
 	.dev_release = iscsi_iface_release,
+	.ns_type = &net_ns_type_operations,
+	.namespace = iscsi_iface_namespace,
 };
 
 #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store)	\
@@ -1566,6 +1604,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 */
@@ -1586,23 +1625,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 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 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 3b40fea93556..8c8191dfdc21 100644
--- a/include/scsi/scsi_transport_iscsi.h
+++ b/include/scsi/scsi_transport_iscsi.h
@@ -279,6 +279,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) \
-- 
2.9.5

  parent reply	other threads:[~2017-11-07 22:46 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-31 22:40 [PATCH 0/9] use network namespace for iSCSI control interfaces Chris Leech
2017-10-31 22:40 ` [PATCH 1/9] iscsi: create per-net iscsi netlink kernel sockets Chris Leech
2017-10-31 22:40   ` Chris Leech
2017-10-31 22:41 ` [PATCH 8/9] iscsi: rename iscsi_bus_flash_* to iscsi_flash_* Chris Leech
2017-10-31 22:41   ` Chris Leech
     [not found] ` <20171031224104.17735-1-cleech-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-10-31 22:40   ` [PATCH 2/9] iscsi: associate endpoints with a host Chris Leech
2017-10-31 22:40     ` Chris Leech
2017-10-31 22:40   ` [PATCH 3/9] iscsi: sysfs filtering by network namespace Chris Leech
2017-10-31 22:40     ` Chris Leech
2017-10-31 22:40   ` [PATCH 4/9] iscsi: make all iSCSI netlink multicast namespace aware Chris Leech
2017-10-31 22:40     ` Chris Leech
2017-10-31 22:41   ` [PATCH 5/9] iscsi: set netns for iscsi_tcp hosts Chris Leech
2017-10-31 22:41     ` Chris Leech
2017-10-31 22:41   ` [PATCH 6/9] iscsi: check net namespace for all iscsi lookups Chris Leech
2017-10-31 22:41     ` Chris Leech
2017-10-31 22:41   ` [PATCH 7/9] iscsi: convert flashnode devices from bus to class Chris Leech
2017-10-31 22:41     ` Chris Leech
2017-10-31 22:41   ` [PATCH 9/9] iscsi: filter flashnode sysfs by net namespace Chris Leech
2017-10-31 22:41     ` Chris Leech
2017-11-07 17:44 ` [PATCH 0/9] use network namespace for iSCSI control interfaces Chris Leech
2017-11-07 18:01 ` network namespace, netlink and sysfs changes for iSCSI (Re: [PATCH 0/9] use network namespace for iSCSI control interfaces) Chris Leech
     [not found]   ` <20171107180156.GD29597-r8IHplWLGbA5tHQWs+pTeqPFFGjUI2lm2LY78lusg7I@public.gmane.org>
2017-11-07 20:28     ` Greg Kroah-Hartman
2017-11-07 22:45     ` [PATCH 0/9] use network namespace for iSCSI control interfaces Chris Leech
2017-11-07 22:45       ` [PATCH 2/9] iscsi: associate endpoints with a host Chris Leech
2017-11-07 22:45       ` Chris Leech [this message]
2017-11-07 22:45       ` [PATCH 5/9] iscsi: set netns for iscsi_tcp hosts Chris Leech
2017-11-07 22:45       ` [PATCH 6/9] iscsi: check net namespace for all iscsi lookups Chris Leech
     [not found]       ` <20171107224513.4217-1-cleech-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-11-07 22:45         ` [PATCH 1/9] iscsi: create per-net iscsi netlink kernel sockets Chris Leech
2017-11-07 22:45         ` [PATCH 2/9] iscsi: associate endpoints with a host Chris Leech
2017-11-07 22:45         ` [PATCH 3/9] iscsi: sysfs filtering by network namespace Chris Leech
2017-11-07 22:45         ` [PATCH 4/9] iscsi: make all iSCSI netlink multicast namespace aware Chris Leech
2017-11-07 22:45         ` [PATCH 5/9] iscsi: set netns for iscsi_tcp hosts Chris Leech
2017-11-07 22:45         ` [PATCH 6/9] iscsi: check net namespace for all iscsi lookups Chris Leech
2017-11-07 22:45         ` [PATCH 7/9] iscsi: convert flashnode devices from bus to class Chris Leech
2017-11-07 22:45         ` [PATCH 8/9] iscsi: rename iscsi_bus_flash_* to iscsi_flash_* Chris Leech
2017-11-07 22:45         ` [PATCH 9/9] iscsi: filter flashnode sysfs by net namespace Chris Leech
2017-11-08 10:31         ` [PATCH 0/9] use network namespace for iSCSI control interfaces David Laight
     [not found]           ` <063D6719AE5E284EB5DD2968C1650D6DD00B618E-VkEWCZq2GCInGFn1LkZF6NBPR1lH4CV8@public.gmane.org>
2017-11-15  0:25             ` Chris Leech
2017-11-15  0:25           ` Chris Leech
2017-11-21 11:26             ` David Laight
2017-11-21 19:46               ` Eric W. Biederman
     [not found]               ` <687d0196888f4325aebc0989a8e12ced-1XygrNkDbNvwg4NCKwmqgw@public.gmane.org>
2017-11-21 19:46                 ` Eric W. Biederman
2017-11-21 20:20                 ` Chris Leech
     [not found]             ` <20171115002521.GA21082-r8IHplWLGbA5tHQWs+pTeqPFFGjUI2lm2LY78lusg7I@public.gmane.org>
2017-11-21 11:26               ` David Laight
2017-11-07 22:45       ` [PATCH 7/9] iscsi: convert flashnode devices from bus to class Chris Leech
2017-11-07 22:45       ` [PATCH 8/9] iscsi: rename iscsi_bus_flash_* to iscsi_flash_* Chris Leech
2017-11-07 22:45       ` [PATCH 9/9] iscsi: filter flashnode sysfs by net namespace Chris Leech
2017-11-07 20:45   ` network namespace, netlink and sysfs changes for iSCSI (Re: [PATCH 0/9] use network namespace for iSCSI control interfaces) James Bottomley
     [not found]     ` <1510087526.3118.37.camel-d9PhHud1JfjCXq6kfMZ53/egYHeGw8Jk@public.gmane.org>
2017-11-07 22:32       ` Chris Leech

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171107224513.4217-4-cleech@redhat.com \
    --to=cleech@redhat.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.