Make iscsid-kernel communications namespace-aware
Subsystems (10)
Chris Leech
maintainerv2 cover Make iscsid-kernel communications namespace-aware
This set of patches modifies the kernel iSCSI initiator communications so that they are namespace-aware. The goal is to allow multiple iSCSI daemon (iscsid) to run at once as long as they are in separate namespaces, and so that iscsid can run in containers.
Container runtime environments seem to want to containerize their own components, and there have been complaints about the need to run iscsid from the host network namespace. There are still priviledged capabilities needed for iscsid, but these changes address the namespace issue.
I've tested with iscsi_tcp and iser over rxe with an unmodified iscsid running in a podman container.
Note that with iscsi_tcp, the connected socket will keep the network namespace alive after container exit. The namespace will exit once the connection terminates, and I'd recommend running with a iSCSI noop_out_timeout set to error out the connection after the routing has been removed.
v2: Changes from Lee's last RFC posting
- Minor changes to patches 2 & 3 to not break iSER
- Large changes in patch 6, merging in patches posted to the previous discussion. Use of current when setting the netns on an iscsi_tcp session has been removed, instead an unbound (from a host) session creation with an explicit netns interface has been added. Similar changes for iSER endpoints have been added, and iSER support for non-default network namespaces was enabled.
- The addition of patches 10 & 11 from the previous discussions to force removal of sessions on namespace exit.
Chris Leech, Lee Duncan (11):
iscsi: create per-net iscsi netlink kernel sockets
iscsi: associate endpoints with a host
iscsi: sysfs filtering by network namespace
iscsi: make all iSCSI netlink multicast namespace aware
iscsi: check net namespace for all iscsi lookup
iscsi: set netns for tcp and iser hosts
iscsi: convert flashnode devices from bus to class
iscsi: rename iscsi_bus_flash_* to iscsi_flash_*
iscsi: filter flashnode sysfs by net namespace
iscsi: make session and connection lists per-net
iscsi: force destroy sesions when a network namespace exits
drivers/infiniband/ulp/iser/iscsi_iser.c | 61 +- drivers/scsi/be2iscsi/be_iscsi.c | 6 +- drivers/scsi/bnx2i/bnx2i_iscsi.c | 6 +- drivers/scsi/cxgbi/libcxgbi.c | 6 +- drivers/scsi/iscsi_tcp.c | 15 +- drivers/scsi/libiscsi.c | 16 + drivers/scsi/qedi/qedi_iscsi.c | 6 +- drivers/scsi/qla4xxx/ql4_os.c | 64 +- drivers/scsi/scsi_transport_iscsi.c | 790 ++++++++++++++++------- include/scsi/libiscsi.h | 4 + include/scsi/scsi_transport_iscsi.h | 75 ++- 11 files changed, 725 insertions(+), 324 deletions(-)
Signature · 1 line
2.39.2
Chris Leech
maintainerPATCH v2 1/11 iscsi: create per-net iscsi netlink kernel sockets
From: Lee Duncan <[email protected]>
Prepare iSCSI netlink to operate in multiple namespaces.
--- drivers/scsi/scsi_transport_iscsi.c | 73 +++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 10 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +63 -10
@@ -13,6 +13,8 @@#include <linux/bsg-lib.h> #include <linux/idr.h> #include <net/tcp.h> +#include <net/net_namespace.h> +#include <net/netns/generic.h> #include <scsi/scsi.h> #include <scsi/scsi_host.h> #include <scsi/scsi_device.h>
@@ -1597,7 +1599,11 @@ static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,NULL , NULL); -static struct sock *nls; +struct iscsi_net { +struct sock *nls; +}; + +static int iscsi_net_id__read_mostly ;static DEFINE_MUTEX (rx_queue_mutex);static LIST_HEAD (sesslist);
@@ -2552,14 +2558,32 @@ iscsi_if_transport_lookup(struct iscsi_transport *tt) }static int -iscsi_multicast_skb (struct sk_buff *skb,uint32_t group,gfp_t gfp) +iscsi_multicast_netns (struct net *net,struct sk_buff *skb, +uint32_t group,gfp_t gfp) { +struct sock *nls; +struct iscsi_net *isn; + + isn =net_generic (net, iscsi_net_id); + nls = isn->nls;return nlmsg_multicast (nls, skb,0 , group, gfp); } +static int +iscsi_multicast_skb (struct sk_buff *skb,uint32_t group,gfp_t gfp) +{ +return iscsi_multicast_netns (&init_net, skb, group, gfp); +} +static int iscsi_unicast_skb (struct sk_buff *skb,u32 portid) { +struct sock *nls; +struct iscsi_net *isn; +struct net *net = &init_net; + + isn =net_generic (net, iscsi_net_id); + nls = isn->nls;return nlmsg_unicast (nls, skb, portid); }
@@ -4937,13 +4961,42 @@ void iscsi_dbg_trace(void (*trace)(struct device *dev, struct va_format *), }EXPORT_SYMBOL_GPL (iscsi_dbg_trace); -static __init int iscsi_transport_init (void ) +static int __net_init iscsi_net_init (struct net *net) { -int err; +struct sock *nls; +struct iscsi_net *isn;struct netlink_kernel_cfg cfg = { .groups =1 , .input = iscsi_if_rx, }; + + nls =netlink_kernel_create (net,NETLINK_ISCSI , &cfg); +if (!nls) +return -ENOMEM ; + isn =net_generic (net, iscsi_net_id); + isn->nls = nls; +return 0 ; +} + +static void __net_exit iscsi_net_exit(struct net *net) +{ +struct iscsi_net *isn; + + isn =net_generic (net, iscsi_net_id); +netlink_kernel_release (isn->nls); + isn->nls =NULL ; +} + +static struct pernet_operations iscsi_net_ops = { + .init = iscsi_net_init, + .exit = iscsi_net_exit, + .id = &iscsi_net_id, + .size =sizeof (struct iscsi_net ), +}; + +static __init int iscsi_transport_init (void ) +{ +int err;printk (KERN_INFO "Loading iSCSI transport class v%s.\n" ,ISCSI_TRANSPORT_VERSION );
@@ -4977,8 +5030,8 @@ static __init int iscsi_transport_init(void)if (err) goto unregister_session_class; - nls =netlink_kernel_create (&init_net,NETLINK_ISCSI , &cfg); -if (!nls) { + err =register_pernet_subsys (&iscsi_net_ops); +if (err) { err = -ENOBUFS ; goto unregister_flashnode_bus; }
@@ -4988,13 +5041,13 @@ static __init int iscsi_transport_init(void) "iscsi_conn_cleanup");if (!iscsi_conn_cleanup_workq) { err = -ENOMEM ; - goto release_nls; + goto unregister_pernet_subsys; }return 0 ; -release_nls: -netlink_kernel_release (nls); +unregister_pernet_subsys: +unregister_pernet_subsys (&iscsi_net_ops); unregister_flashnode_bus:bus_unregister (&iscsi_flashnode_bus); unregister_session_class:
@@ -5015,7 +5068,7 @@ static __init int iscsi_transport_init(void) static void __exit iscsi_transport_exit(void) {destroy_workqueue (iscsi_conn_cleanup_workq); -netlink_kernel_release (nls); +unregister_pernet_subsys (&iscsi_net_ops);bus_unregister (&iscsi_flashnode_bus);transport_class_unregister (&iscsi_connection_class);transport_class_unregister (&iscsi_session_class);
Signature · 1 line
2.39.2
Chris Leech
maintainerPATCH v2 2/11 iscsi: associate endpoints with a host
In reply to Chris LeechRight now the iscsi_endpoint is only linked to a connection once that connection has been established. For net namespace filtering of the sysfs objects, associate an endpoint with the host that it was allocated for when it is created, when possible.
iSER creates endpoints before hosts and sessions, so we need to keep compatibility with virtual device paths and not always expect a parent host.
--- drivers/infiniband/ulp/iser/iscsi_iser.c | 2 +- drivers/scsi/be2iscsi/be_iscsi.c | 2 +- drivers/scsi/bnx2i/bnx2i_iscsi.c | 2 +- drivers/scsi/cxgbi/libcxgbi.c | 2 +- drivers/scsi/qedi/qedi_iscsi.c | 2 +- drivers/scsi/qla4xxx/ql4_os.c | 2 +- drivers/scsi/scsi_transport_iscsi.c | 4 +++- include/scsi/scsi_transport_iscsi.h | 7 ++++++- 8 files changed, 15 insertions(+), 8 deletions(-)
drivers/infiniband/ulp/iser/iscsi_iser.c +1 -1
@@ -802,7 +802,7 @@ static struct iscsi_endpoint *iscsi_iser_ep_connect(struct Scsi_Host *shost,struct iser_conn *iser_conn;struct iscsi_endpoint *ep; - ep =iscsi_create_endpoint (0 ); + ep =iscsi_create_endpoint (shost,0 );if (!ep)return ERR_PTR (-ENOMEM );
drivers/scsi/be2iscsi/be_iscsi.c +1 -1
@@ -1168,7 +1168,7 @@ beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,return ERR_PTR (ret); } - ep =iscsi_create_endpoint (sizeof (struct beiscsi_endpoint )); + ep =iscsi_create_endpoint (shost,sizeof (struct beiscsi_endpoint ));if (!ep) { ret = -ENOMEM ;return ERR_PTR (ret);
drivers/scsi/bnx2i/bnx2i_iscsi.c +1 -1
@@ -384,7 +384,7 @@ static struct iscsi_endpoint *bnx2i_alloc_ep(struct bnx2i_hba *hba)struct bnx2i_endpoint *bnx2i_ep;u32 ec_div; - ep =iscsi_create_endpoint (sizeof (*bnx2i_ep)); + ep =iscsi_create_endpoint (hba->shost,sizeof (*bnx2i_ep));if (!ep) {printk (KERN_ERR "bnx2i: Could not allocate ep\n" );return NULL ;
drivers/scsi/cxgbi/libcxgbi.c +1 -1
@@ -2926,7 +2926,7 @@ struct iscsi_endpoint *cxgbi_ep_connect(struct Scsi_Host *shost, goto release_conn; } - ep =iscsi_create_endpoint (sizeof (*cep)); + ep =iscsi_create_endpoint (shost,sizeof (*cep));if (!ep) { err = -ENOMEM ;pr_info ("iscsi alloc ep, OOM.\n" );
drivers/scsi/qedi/qedi_iscsi.c +1 -1
@@ -931,7 +931,7 @@ qedi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,return ERR_PTR (-ENXIO ); } - ep =iscsi_create_endpoint (sizeof (struct qedi_endpoint )); + ep =iscsi_create_endpoint (shost,sizeof (struct qedi_endpoint ));if (!ep) {QEDI_ERR (&qedi->dbg_ctx,"endpoint create fail\n" ); ret = -ENOMEM ;
drivers/scsi/qla4xxx/ql4_os.c +1 -1
@@ -1717,7 +1717,7 @@ qla4xxx_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr, } ha =iscsi_host_priv (shost); - ep =iscsi_create_endpoint (sizeof (struct qla_endpoint )); + ep =iscsi_create_endpoint (shost,sizeof (struct qla_endpoint ));if (!ep) { ret = -ENOMEM ;return ERR_PTR (ret);
drivers/scsi/scsi_transport_iscsi.c +3 -1
@@ -204,7 +204,7 @@ static struct attribute_group iscsi_endpoint_group = { };struct iscsi_endpoint * -iscsi_create_endpoint (int dd_size) +iscsi_create_endpoint (struct Scsi_Host *shost,int dd_size) {struct iscsi_endpoint *ep;int err, id;
@@ -230,6 +230,8 @@ iscsi_create_endpoint(int dd_size) ep->id = id; ep->dev.class = &iscsi_endpoint_class; +if (shost) + ep->dev.parent = &shost->shost_gendev;dev_set_name (&ep->dev,"ep-%d" , id); err =device_register (&ep->dev);if (err)
include/scsi/scsi_transport_iscsi.h +6 -1
@@ -287,6 +287,10 @@ 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) +#define starget_to_session (_stgt) \ iscsi_dev_to_session(_stgt->dev.parent)
@@ -462,7 +466,8 @@ extern void iscsi_put_conn(struct iscsi_cls_conn *conn);extern void iscsi_get_conn (struct iscsi_cls_conn *conn);extern void iscsi_unblock_session (struct iscsi_cls_session *session);extern void iscsi_block_session (struct iscsi_cls_session *session); -extern struct iscsi_endpoint *iscsi_create_endpoint (int dd_size); +extern struct iscsi_endpoint *iscsi_create_endpoint (struct Scsi_Host *shost, +int dd_size);extern void iscsi_destroy_endpoint (struct iscsi_endpoint *ep);extern struct iscsi_endpoint *iscsi_lookup_endpoint (u64 handle);extern void iscsi_put_endpoint (struct iscsi_endpoint *ep);
Signature · 1 line
2.39.2
Chris Leech
maintainerPATCH v2 3/11 iscsi: sysfs filtering by network namespace
In reply to Chris LeechThis 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.
--- drivers/scsi/scsi_transport_iscsi.c | 127 ++++++++++++++++++++++++---- include/scsi/scsi_transport_iscsi.h | 1 + 2 files changed, 113 insertions(+), 15 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +112 -15
@@ -181,9 +181,34 @@ 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; + +if (!shost) +return &init_net; + ihost = shost->shost_data; +return iscsi_host_net (ihost); +} + +static const void *iscsi_endpoint_namespace (const 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
@@ -309,10 +334,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 (const 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 +1607,7 @@ static int iscsi_setup_host(struct transport_container *tc, struct device *dev,memset (ihost,0 ,sizeof (*ihost));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 */
@@ -1583,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); +#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 DECLARE_TRANSPORT_CLASS(iscsi_session_class, -"iscsi_session" , -NULL , -NULL , - NULL); +static const void *iscsi_host_namespace (const 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 (const 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 (const struct device *dev) +{ +struct iscsi_cls_conn *cls_conn =transport_class_to_conn (dev); + +return iscsi_conn_net (cls_conn); +} -static DECLARE_TRANSPORT_CLASS(iscsi_connection_class, -"iscsi_connection" , -NULL , -NULL , - NULL); +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;
include/scsi/scsi_transport_iscsi.h +1 -0
@@ -299,6 +299,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) \
Signature · 1 line
2.39.2
[email protected]
maintainerRe: [PATCH 03/11] iscsi: sysfs filtering by network namespace
drivers/scsi/scsi_transport_iscsi.c static int iscsi_remove_host(struct transport_container *tc, · line 1638
Quoted 11 lines · Chris Leech
drivers/scsi/scsi_transport_iscsi.c +11
-0+#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, \ +}
I think this would be in the transport class for others to use in the future and or you want to name it differently so it doesn't clash with the future transport class naming. Same as other places in the patch.
Chris Leech
maintainerPATCH v2 4/11 iscsi: make all iSCSI netlink multicast namespace aware
In reply to Chris LeechFrom: Lee Duncan <[email protected]>
Make use of the per-net netlink sockets. Responses are sent back on the same socket/namespace the request was received on. Async events are reported on the socket/namespace stored in the iscsi_cls_host associated with the event.
--- drivers/scsi/scsi_transport_iscsi.c | 92 +++++++++++++++++++---------- 1 file changed, 60 insertions(+), 32 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +60 -32
@@ -2657,8 +2657,8 @@ iscsi_if_transport_lookup(struct iscsi_transport *tt) }static int -iscsi_multicast_netns (struct net *net,struct sk_buff *skb, -uint32_t group,gfp_t gfp) +iscsi_multicast_skb (struct net *net,struct sk_buff *skb, +uint32_t group,gfp_t gfp) {struct sock *nls;struct iscsi_net *isn;
@@ -2669,17 +2669,10 @@ iscsi_multicast_netns(struct net *net, struct sk_buff *skb, }static int -iscsi_multicast_skb (struct sk_buff *skb,uint32_t group,gfp_t gfp) -{ -return iscsi_multicast_netns (&init_net, skb, group, gfp); -} - -static int -iscsi_unicast_skb (struct sk_buff *skb,u32 portid) +iscsi_unicast_skb (struct net *net,struct sk_buff *skb,u32 portid) {struct sock *nls;struct iscsi_net *isn; -struct net *net = &init_net; isn =net_generic (net, iscsi_net_id); nls = isn->nls;
@@ -2694,6 +2687,7 @@ int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,struct iscsi_uevent *ev;char *pdu;struct iscsi_internal *priv; +struct net *net;int len =nlmsg_total_size (sizeof (*ev) +sizeof (struct iscsi_hdr ) + data_size);
@@ -2720,7 +2714,8 @@ int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,memcpy (pdu, hdr,sizeof (struct iscsi_hdr ));memcpy (pdu +sizeof (struct iscsi_hdr ), data, data_size); -return iscsi_multicast_skb (skb,ISCSI_NL_GRP_ISCSID ,GFP_ATOMIC ); + net =iscsi_conn_net (conn); +return iscsi_multicast_skb (net, skb,ISCSI_NL_GRP_ISCSID ,GFP_ATOMIC ); }EXPORT_SYMBOL_GPL (iscsi_recv_pdu);
@@ -2731,6 +2726,7 @@ int iscsi_offload_mesg(struct Scsi_Host *shost,struct nlmsghdr *nlh;struct sk_buff *skb;struct iscsi_uevent *ev; +struct net *net;int len =nlmsg_total_size (sizeof (*ev) + data_size); skb =alloc_skb (len,GFP_ATOMIC );
@@ -2755,7 +2751,8 @@ int iscsi_offload_mesg(struct Scsi_Host *shost,memcpy ((char *)ev +sizeof (*ev), data, data_size); -return iscsi_multicast_skb (skb,ISCSI_NL_GRP_UIP ,GFP_ATOMIC ); + net =iscsi_host_net (shost->shost_data); +return iscsi_multicast_skb (net, skb,ISCSI_NL_GRP_UIP ,GFP_ATOMIC ); }EXPORT_SYMBOL_GPL (iscsi_offload_mesg);
@@ -2765,6 +2762,7 @@ void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)struct sk_buff *skb;struct iscsi_uevent *ev;struct iscsi_internal *priv; +struct net *net;int len =nlmsg_total_size (sizeof (*ev));unsigned long flags;int state;
@@ -2812,7 +2810,8 @@ void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error) ev->r.connerror.cid = conn->cid; ev->r.connerror.sid =iscsi_conn_get_sid (conn); -iscsi_multicast_skb (skb,ISCSI_NL_GRP_ISCSID ,GFP_ATOMIC ); + net =iscsi_conn_net (conn); +iscsi_multicast_skb (net, skb,ISCSI_NL_GRP_ISCSID ,GFP_ATOMIC );iscsi_cls_conn_printk (KERN_INFO , conn,"detected conn error (%d)\n" , error);
@@ -2826,6 +2825,7 @@ void iscsi_conn_login_event(struct iscsi_cls_conn *conn,struct sk_buff *skb;struct iscsi_uevent *ev;struct iscsi_internal *priv; +struct net *net;int len =nlmsg_total_size (sizeof (*ev)); priv =iscsi_if_transport_lookup (conn->transport);
@@ -2846,7 +2846,9 @@ void iscsi_conn_login_event(struct iscsi_cls_conn *conn, ev->r.conn_login.state = state; ev->r.conn_login.cid = conn->cid; ev->r.conn_login.sid =iscsi_conn_get_sid (conn); -iscsi_multicast_skb (skb,ISCSI_NL_GRP_ISCSID ,GFP_ATOMIC ); + + net =iscsi_conn_net (conn); +iscsi_multicast_skb (net, skb,ISCSI_NL_GRP_ISCSID ,GFP_ATOMIC );iscsi_cls_conn_printk (KERN_INFO , conn,"detected conn login (%d)\n" , state);
@@ -2857,11 +2859,17 @@ void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport, enum iscsi_host_event_code code, uint32_t data_size, uint8_t *data) { + struct Scsi_Host *shost; +struct net *net;struct nlmsghdr *nlh;struct sk_buff *skb;struct iscsi_uevent *ev;int len =nlmsg_total_size (sizeof (*ev) + data_size); + shost =scsi_host_lookup (host_no); +if (!shost) +return ; + skb =alloc_skb (len,GFP_NOIO );if (!skb) { printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n",
@@ -2880,7 +2888,9 @@ void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport,if (data_size)memcpy ((char *)ev +sizeof (*ev), data, data_size); -iscsi_multicast_skb (skb,ISCSI_NL_GRP_ISCSID ,GFP_NOIO ); + net =iscsi_host_net (shost->shost_data); +scsi_host_put (shost); +iscsi_multicast_skb (net, skb,ISCSI_NL_GRP_ISCSID ,GFP_NOIO ); }EXPORT_SYMBOL_GPL (iscsi_post_host_event);
@@ -2888,11 +2898,17 @@ void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport, uint32_t status, uint32_t pid, uint32_t data_size, uint8_t *data) { + struct Scsi_Host *shost; +struct net *net;struct nlmsghdr *nlh;struct sk_buff *skb;struct iscsi_uevent *ev;int len =nlmsg_total_size (sizeof (*ev) + data_size); + shost =scsi_host_lookup (host_no); +if (!shost) +return ; + skb =alloc_skb (len,GFP_NOIO );if (!skb) {printk (KERN_ERR "gracefully ignored ping comp: OOM\n" );
@@ -2909,12 +2925,15 @@ void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport, ev->r.ping_comp.data_size = data_size;memcpy ((char *)ev +sizeof (*ev), data, data_size); -iscsi_multicast_skb (skb,ISCSI_NL_GRP_ISCSID ,GFP_NOIO ); + net =iscsi_host_net (shost->shost_data); +scsi_host_put (shost); +iscsi_multicast_skb (net, skb,ISCSI_NL_GRP_ISCSID ,GFP_NOIO ); }EXPORT_SYMBOL_GPL (iscsi_ping_comp_event);static int -iscsi_if_send_reply (u32 portid,int type,void *payload,int size) +iscsi_if_send_reply (struct net *net,u32 portid,int type, +void *payload,int size) {struct sk_buff *skb;struct nlmsghdr *nlh;
@@ -2928,11 +2947,11 @@ iscsi_if_send_reply(u32 portid, int type, void *payload, int size) nlh =__nlmsg_put (skb,0 ,0 , type, (len -sizeof (*nlh)),0 );memcpy (nlmsg_data (nlh), payload, size); -return iscsi_unicast_skb (skb, portid); +return iscsi_unicast_skb (net, skb, portid); }static int -iscsi_if_get_stats (struct iscsi_transport *transport,struct nlmsghdr *nlh) +iscsi_if_get_stats (struct net *net,struct iscsi_transport *transport,struct nlmsghdr *nlh) {struct iscsi_uevent *ev =nlmsg_data (nlh);struct iscsi_stats *stats;
@@ -2989,7 +3008,7 @@ iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)skb_trim (skbstat,NLMSG_ALIGN (actual_size)); nlhstat->nlmsg_len = actual_size; - err =iscsi_multicast_skb (skbstat,ISCSI_NL_GRP_ISCSID , + err =iscsi_multicast_skb (net, skbstat,ISCSI_NL_GRP_ISCSID ,GFP_ATOMIC ); }while (err <0 && err != -ECONNREFUSED );
@@ -3009,6 +3028,7 @@ int iscsi_session_event(struct iscsi_cls_session *session,struct iscsi_uevent *ev;struct sk_buff *skb;struct nlmsghdr *nlh; +struct net *net;int rc, len =nlmsg_total_size (sizeof (*ev)); priv =iscsi_if_transport_lookup (session->transport);
@@ -3053,7 +3073,8 @@ int iscsi_session_event(struct iscsi_cls_session *session,* this will occur if the daemon is not up, so we just warn * the user and when the daemon is restarted it will handle it */ - rc =iscsi_multicast_skb (skb,ISCSI_NL_GRP_ISCSID ,GFP_KERNEL ); + net =iscsi_sess_net (session); + rc =iscsi_multicast_skb (net, skb,ISCSI_NL_GRP_ISCSID ,GFP_KERNEL );if (rc == -ESRCH )iscsi_cls_session_printk (KERN_ERR , session, "Cannot notify userspace of session "
@@ -3416,7 +3437,8 @@ iscsi_send_ping(struct iscsi_transport *transport, struct iscsi_uevent *ev) }static int -iscsi_get_chap (struct iscsi_transport *transport,struct nlmsghdr *nlh) +iscsi_get_chap (struct net *net,struct iscsi_transport *transport, +struct nlmsghdr *nlh) {struct iscsi_uevent *ev =nlmsg_data (nlh);struct Scsi_Host *shost =NULL ;
@@ -3475,7 +3497,7 @@ iscsi_get_chap(struct iscsi_transport *transport, struct nlmsghdr *nlh)skb_trim (skbchap,NLMSG_ALIGN (actual_size)); nlhchap->nlmsg_len = actual_size; - err =iscsi_multicast_skb (skbchap,ISCSI_NL_GRP_ISCSID , + err =iscsi_multicast_skb (net, skbchap,ISCSI_NL_GRP_ISCSID ,GFP_KERNEL ); }while (err <0 && err != -ECONNREFUSED );
@@ -3822,7 +3844,8 @@ static int iscsi_logout_flashnode_sid(struct iscsi_transport *transport, }static int -iscsi_get_host_stats (struct iscsi_transport *transport,struct nlmsghdr *nlh) +iscsi_get_host_stats (struct net *net,struct iscsi_transport *transport, +struct nlmsghdr *nlh) {struct iscsi_uevent *ev =nlmsg_data (nlh);struct Scsi_Host *shost =NULL ;
@@ -3882,8 +3905,8 @@ iscsi_get_host_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)skb_trim (skbhost_stats,NLMSG_ALIGN (actual_size)); nlhhost_stats->nlmsg_len = actual_size; - err =iscsi_multicast_skb (skbhost_stats,ISCSI_NL_GRP_ISCSID , -GFP_KERNEL ); + err =iscsi_multicast_skb (net, skbhost_stats, +ISCSI_NL_GRP_ISCSID ,GFP_KERNEL ); }while (err <0 && err != -ECONNREFUSED ); exit_host_stats:
@@ -4005,7 +4028,8 @@ static int iscsi_if_transport_conn(struct iscsi_transport *transport, }static int -iscsi_if_recv_msg (struct sk_buff *skb,struct nlmsghdr *nlh,uint32_t *group) +iscsi_if_recv_msg (struct net *net,struct sk_buff *skb, +struct nlmsghdr *nlh,uint32_t *group) {int err =0 ;u32 portid;
@@ -4100,7 +4124,7 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group) err =iscsi_if_transport_conn (transport, nlh);break ;case ISCSI_UEVENT_GET_STATS : - err =iscsi_if_get_stats (transport, nlh); + err =iscsi_if_get_stats (net, transport, nlh);break ;case ISCSI_UEVENT_TRANSPORT_EP_CONNECT :case ISCSI_UEVENT_TRANSPORT_EP_POLL :
@@ -4125,7 +4149,7 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group) err =iscsi_send_ping (transport, ev);break ;case ISCSI_UEVENT_GET_CHAP : - err =iscsi_get_chap (transport, nlh); + err =iscsi_get_chap (net, transport, nlh);break ;case ISCSI_UEVENT_DELETE_CHAP : err =iscsi_delete_chap (transport, ev);
@@ -4156,7 +4180,7 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group) nlmsg_attrlen(nlh, sizeof(*ev)));break ;case ISCSI_UEVENT_GET_HOST_STATS : - err =iscsi_get_host_stats (transport, nlh); + err =iscsi_get_host_stats (net, transport, nlh);break ;default : err = -ENOSYS ;
@@ -4174,6 +4198,8 @@ iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group)static void iscsi_if_rx (struct sk_buff *skb) { +struct sock *sk = skb->sk; +struct net *net =sock_net (sk);u32 portid =NETLINK_CB (skb).portid;mutex_lock (&rx_queue_mutex);
@@ -4196,7 +4222,7 @@ iscsi_if_rx(struct sk_buff *skb)if (rlen > skb->len) rlen = skb->len; - err =iscsi_if_recv_msg (skb, nlh, &group); + err =iscsi_if_recv_msg (net, skb, nlh, &group);if (err) { ev->type =ISCSI_KEVENT_IF_ERROR ; ev->iferror = err;
@@ -4212,7 +4238,9 @@ iscsi_if_rx(struct sk_buff *skb)break ;if (ev->type ==ISCSI_UEVENT_GET_CHAP && !err)break ; - err =iscsi_if_send_reply (portid, nlh->nlmsg_type, +if (ev->type ==ISCSI_UEVENT_GET_HOST_STATS && !err) +break ; + err =iscsi_if_send_reply (net, portid, nlh->nlmsg_type, ev,sizeof (*ev));if (err == -EAGAIN && --retries <0 ) {printk (KERN_WARNING "Send reply failed, error %d\n" , err);
Signature · 1 line
2.39.2
[email protected]
maintainerRe: [PATCH 04/11] iscsi: make all iSCSI netlink multicast namespace aware
Quoted 7 lines · Chris Leech
drivers/scsi/scsi_transport_iscsi.c +2
-0@@ -2857,11 +2859,17 @@ void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport, enum iscsi_host_event_code code, uint32_t data_size, uint8_t *data) { + struct Scsi_Host *shost; +struct net *net;struct nlmsghdr *nlh;
drivers/scsi/scsi_transport_iscsi.c void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport, · line 2874
Quoted 10 lines
drivers/scsi/scsi_transport_iscsi.c +4
-0struct sk_buff *skb;struct iscsi_uevent *ev;int len =nlmsg_total_size (sizeof (*ev) + data_size); + shost =scsi_host_lookup (host_no); +if (!shost) +return ; + skb =alloc_skb (len,GFP_NOIO );if (!skb) {
Need scsi_host_put. Maybe just grab the net and do the put before the alloc_skb.
Quoted 19 lines
drivers/scsi/scsi_transport_iscsi.c +5
-1printk(KERN_ERR "gracefully ignored host event (%d):%d OOM\n",@@ -2880,7 +2888,9 @@ void iscsi_post_host_event(uint32_t host_no, struct iscsi_transport *transport,if (data_size)memcpy ((char *)ev +sizeof (*ev), data, data_size); -iscsi_multicast_skb (skb,ISCSI_NL_GRP_ISCSID ,GFP_NOIO ); + net =iscsi_host_net (shost->shost_data); +scsi_host_put (shost); +iscsi_multicast_skb (net, skb,ISCSI_NL_GRP_ISCSID ,GFP_NOIO ); }EXPORT_SYMBOL_GPL (iscsi_post_host_event);@@ -2888,11 +2898,17 @@ void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport, uint32_t status, uint32_t pid, uint32_t data_size, uint8_t *data) { + struct Scsi_Host *shost; +struct net *net;struct nlmsghdr *nlh;
drivers/scsi/scsi_transport_iscsi.c void iscsi_ping_comp_event(uint32_t host_no, struct iscsi_transport *transport, · line 2913
Quoted 10 lines
drivers/scsi/scsi_transport_iscsi.c +4
-0struct sk_buff *skb;struct iscsi_uevent *ev;int len =nlmsg_total_size (sizeof (*ev) + data_size); + shost =scsi_host_lookup (host_no); +if (!shost) +return ; + skb =alloc_skb (len,GFP_NOIO );if (!skb) {
Same as above.
Chris Leech
maintainerPATCH v2 5/11 iscsi: check net namespace for all iscsi lookup
In reply to Chris LeechFrom: Lee Duncan <[email protected]>
All internal lookups of iSCSI transport objects need to be filtered by net namespace.
--- drivers/infiniband/ulp/iser/iscsi_iser.c | 5 +- drivers/scsi/be2iscsi/be_iscsi.c | 4 +- drivers/scsi/bnx2i/bnx2i_iscsi.c | 4 +- drivers/scsi/cxgbi/libcxgbi.c | 4 +- drivers/scsi/qedi/qedi_iscsi.c | 4 +- drivers/scsi/qla4xxx/ql4_os.c | 8 +- drivers/scsi/scsi_transport_iscsi.c | 202 ++++++++++++++--------- include/scsi/scsi_transport_iscsi.h | 5 +- 8 files changed, 149 insertions(+), 87 deletions(-)
drivers/infiniband/ulp/iser/iscsi_iser.c +4 -1
@@ -456,15 +456,18 @@ static int iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session,struct iscsi_conn *conn = cls_conn->dd_data;struct iser_conn *iser_conn;struct iscsi_endpoint *ep; +struct net *net;int error; error =iscsi_conn_bind (cls_session, cls_conn, is_leading);if (error)return error; +/* the transport ep handle comes from user space so it must be * verified against the global ib connections list */ - ep =iscsi_lookup_endpoint (transport_eph); + net =iscsi_sess_net (cls_session); + ep =iscsi_lookup_endpoint (net, transport_eph);if (!ep) {iser_err ("can't bind eph %llx\n" , (unsigned long long )transport_eph);
drivers/scsi/be2iscsi/be_iscsi.c +3 -1
@@ -183,8 +183,10 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,struct iscsi_endpoint *ep;uint16_t cri_index;int rc =0 ; +struct net *net; - ep =iscsi_lookup_endpoint (transport_fd); + net =iscsi_sess_net (cls_session); + ep =iscsi_lookup_endpoint (net, transport_fd);if (!ep)return -EINVAL ;
drivers/scsi/bnx2i/bnx2i_iscsi.c +3 -1
@@ -1411,9 +1411,11 @@ static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session,struct bnx2i_hba *hba =iscsi_host_priv (shost);struct bnx2i_endpoint *bnx2i_ep;struct iscsi_endpoint *ep; +struct net *net;int ret_code; - ep =iscsi_lookup_endpoint (transport_fd); + net =iscsi_sess_net (cls_session); + ep =iscsi_lookup_endpoint (net, transport_fd);if (!ep)return -EINVAL ;/*
drivers/scsi/cxgbi/libcxgbi.c +3 -1
@@ -2676,9 +2676,11 @@ int cxgbi_bind_conn(struct iscsi_cls_session *cls_session,struct iscsi_endpoint *ep;struct cxgbi_endpoint *cep;struct cxgbi_sock *csk; +struct net *net;int err; - ep =iscsi_lookup_endpoint (transport_eph); + net =iscsi_sess_net (cls_session); + ep =iscsi_lookup_endpoint (net, transport_eph);if (!ep)return -EINVAL ;
drivers/scsi/qedi/qedi_iscsi.c +3 -1
@@ -389,8 +389,10 @@ static int qedi_conn_bind(struct iscsi_cls_session *cls_session,struct qedi_endpoint *qedi_ep;struct iscsi_endpoint *ep;int rc =0 ; +struct net *net; - ep =iscsi_lookup_endpoint (transport_fd); + net =iscsi_sess_net (cls_session); + ep =iscsi_lookup_endpoint (net, transport_fd);if (!ep)return -EINVAL ;
drivers/scsi/qla4xxx/ql4_os.c +5 -3
@@ -3217,6 +3217,7 @@ static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,struct ddb_entry *ddb_entry;struct scsi_qla_host *ha;struct iscsi_session *sess; +struct net *net; sess = cls_session->dd_data; ddb_entry = sess->dd_data;
@@ -3225,11 +3226,12 @@ static int qla4xxx_conn_bind(struct iscsi_cls_session *cls_session,DEBUG2 (ql4_printk (KERN_INFO , ha,"%s: sid = %d, cid = %d\n" , __func__, cls_session->sid, cls_conn->cid)); -if (iscsi_conn_bind (cls_session, cls_conn, is_leading)) -return -EINVAL ; - ep =iscsi_lookup_endpoint (transport_fd); + net =iscsi_sess_net (cls_session); + ep =iscsi_lookup_endpoint (net, transport_fd);if (!ep)return -EINVAL ; +if (iscsi_conn_bind (cls_session, cls_conn, is_leading)) +return -EINVAL ; conn = cls_conn->dd_data; qla_conn = conn->dd_data; qla_conn->qla_ep = ep->dd_data;
drivers/scsi/scsi_transport_iscsi.c +124 -78
622 lines not on this page · raw message
include/scsi/scsi_transport_iscsi.h +4 -1
@@ -291,6 +291,8 @@ struct iscsi_cls_session {#define iscsi_endpoint_to_shost (_ep) \ dev_to_shost(&_ep->dev) +extern struct net *iscsi_sess_net (struct iscsi_cls_session *session); +#define starget_to_session (_stgt) \ iscsi_dev_to_session(_stgt->dev.parent)
@@ -470,7 +472,8 @@ extern void iscsi_block_session(struct iscsi_cls_session *session);extern struct iscsi_endpoint *iscsi_create_endpoint (struct Scsi_Host *shost,int dd_size);extern void iscsi_destroy_endpoint (struct iscsi_endpoint *ep); -extern struct iscsi_endpoint *iscsi_lookup_endpoint (u64 handle); +extern struct iscsi_endpoint *iscsi_lookup_endpoint (struct net *net, +u64 handle);extern void iscsi_put_endpoint (struct iscsi_endpoint *ep);extern int iscsi_block_scsi_eh (struct scsi_cmnd *cmd); extern struct iscsi_iface *iscsi_create_iface(struct Scsi_Host *shost,
Signature · 1 line
2.39.2
Mike Christie
maintainerRe: [PATCH 05/11] iscsi: check net namespace for all iscsi lookup
drivers/scsi/scsi_transport_iscsi.c iscsi_if_recv_msg(struct net *net, struct sk_buff *skb, · line 4111
Quoted 5 lines · Chris Leech
drivers/scsi/scsi_transport_iscsi.c +1
-0@@ -4065,8 +4108,10 @@ iscsi_if_recv_msg(struct net *net, struct sk_buff *skb, ev->u.c_session.cmds_max, ev->u.c_session.queue_depth);break ; +/* MARK */
Got an extra comment in there.
Quoted 4 lines
drivers/scsi/scsi_transport_iscsi.c +2
-1case ISCSI_UEVENT_CREATE_BOUND_SESSION : - ep =iscsi_lookup_endpoint (ev->u.c_bound_session.ep_handle); + ep =iscsi_lookup_endpoint (net, + ev->u.c_bound_session.ep_handle);
Chris Leech
maintainerPATCH v2 6/11 iscsi: set netns for tcp and iser hosts
In reply to Chris LeechThis lets iscsi_tcp and ib_iser operate in multiple namespaces.
The logic to store the network namespace during virtual host creation (due to the way transport-class object setup callbacks function) is in libiscsi, and shared between iscsi_tcp and ib_iser.
There are a few changes to do so:
* Distinguish between bound and unbound session creation with different transport functions, instead of just checking for a NULL endpoint.
This let's the transport code pass the network namespace into the unbound session creation of iscsi_tcp, without changing the offloading drivers which all expect an bound endpoint.
iSER has compatibility checks to work without a bound endpoint, so expose both transport functions there.
* Split endpoint creation into host-bound and with a specified namespace, for iSER's use of endpoint objects + virtual host-per-session.
This is much like was done with sessions for iscsi_tcp.
--- drivers/infiniband/ulp/iser/iscsi_iser.c | 56 ++++++++++++++------ drivers/scsi/iscsi_tcp.c | 15 +++--- drivers/scsi/libiscsi.c | 16 ++++++ drivers/scsi/scsi_transport_iscsi.c | 66 ++++++++++++++++++------ include/scsi/libiscsi.h | 4 ++ include/scsi/scsi_transport_iscsi.h | 12 +++++ 6 files changed, 130 insertions(+), 39 deletions(-)
drivers/infiniband/ulp/iser/iscsi_iser.c +40 -16
@@ -593,20 +593,10 @@ static inline unsigned int iser_dif_prot_caps(int prot_caps)return ret; } -/** -* iscsi_iser_session_create() - create an iscsi-iser session -* @ep: iscsi end-point handle -* @cmds_max: maximum commands in this session -* @qdepth: session command queue depth -* @initial_cmdsn: initiator command sequnce number -* -* Allocates and adds a scsi host, expose DIF supprot if -* exists, and sets up an iscsi session. -*/ static struct iscsi_cls_session * -iscsi_iser_session_create (struct iscsi_endpoint *ep, +__iscsi_iser_session_create (struct iscsi_endpoint *ep,uint16_t cmds_max,uint16_t qdepth, -uint32_t initial_cmdsn) +uint32_t initial_cmdsn,struct net *net) {struct iscsi_cls_session *cls_session;struct Scsi_Host *shost;
@@ -656,6 +646,8 @@ iscsi_iser_session_create(struct iscsi_endpoint *ep,if (!(ib_dev->attrs.kernel_cap_flags &IBK_SG_GAPS_REG )) shost->virt_boundary_mask =SZ_4K -1 ; +iscsi_host_set_netns (shost, ep->netns); +if (iscsi_host_add (shost, ib_dev->dev.parent)) {mutex_unlock (&iser_conn->state_mutex); goto free_host;
@@ -663,6 +655,7 @@ iscsi_iser_session_create(struct iscsi_endpoint *ep,mutex_unlock (&iser_conn->state_mutex); }else { shost->can_queue =min_t (u16, cmds_max,ISER_DEF_XMIT_CMDS_MAX ); +iscsi_host_set_netns (shost, net);if (iscsi_host_add (shost,NULL )) goto free_host; }
@@ -694,6 +687,34 @@ iscsi_iser_session_create(struct iscsi_endpoint *ep,return NULL ; } +/** +* iscsi_iser_session_create() - create an iscsi-iser session +* @ep: iscsi end-point handle +* @cmds_max: maximum commands in this session +* @qdepth: session command queue depth +* @initial_cmdsn: initiator command sequnce number +* +* Allocates and adds a scsi host, expose DIF support if +* exists, and sets up an iscsi session. +*/ +static struct iscsi_cls_session * +iscsi_iser_session_create (struct iscsi_endpoint *ep, +uint16_t cmds_max,uint16_t qdepth, +uint32_t initial_cmdsn) +{ +return __iscsi_iser_session_create (ep, cmds_max, qdepth, + initial_cmdsn,NULL ); +} + +static struct iscsi_cls_session * +iscsi_iser_session_create_net (struct net *net, +uint16_t cmds_max,uint16_t qdepth, +uint32_t initial_cmdsn) +{ +return __iscsi_iser_session_create (NULL , cmds_max, qdepth, + initial_cmdsn, net); +} +static int iscsi_iser_set_param (struct iscsi_cls_conn *cls_conn,enum iscsi_param param,char *buf,int buflen) {
@@ -797,7 +818,7 @@ static int iscsi_iser_get_ep_param(struct iscsi_endpoint *ep,* Return: iscsi_endpoint created by iscsi layer or ERR_PTR(error) * if fails. */ -static struct iscsi_endpoint *iscsi_iser_ep_connect (struct Scsi_Host *shost, +static struct iscsi_endpoint *iscsi_iser_ep_connect (struct net *net,struct sockaddr *dst_addr,int non_blocking) {
@@ -805,7 +826,7 @@ static struct iscsi_endpoint *iscsi_iser_ep_connect(struct Scsi_Host *shost,struct iser_conn *iser_conn;struct iscsi_endpoint *ep; - ep =iscsi_create_endpoint (shost,0 ); + ep =iscsi_create_endpoint_net (net,0 );if (!ep)return ERR_PTR (-ENOMEM );
@@ -983,6 +1004,7 @@ static struct iscsi_transport iscsi_iser_transport = { .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_TEXT_NEGO,/* session management */ .create_session = iscsi_iser_session_create, + .create_session_net = iscsi_iser_session_create_net, .destroy_session = iscsi_iser_session_destroy,/* connection management */ .create_conn = iscsi_iser_conn_create,
@@ -1010,9 +1032,11 @@ static struct iscsi_transport iscsi_iser_transport = {/* recovery */ .session_recovery_timedout = iscsi_session_recovery_timedout, - .ep_connect = iscsi_iser_ep_connect, + .ep_connect_net = iscsi_iser_ep_connect, .ep_poll = iscsi_iser_ep_poll, - .ep_disconnect = iscsi_iser_ep_disconnect + .ep_disconnect = iscsi_iser_ep_disconnect, +/* net namespace */ + .get_netns = iscsi_host_get_netns, };static int __init iser_init (void )
drivers/scsi/iscsi_tcp.c +7 -8
@@ -921,7 +921,7 @@ iscsi_sw_tcp_conn_get_stats(struct iscsi_cls_conn *cls_conn, }static struct iscsi_cls_session * -iscsi_sw_tcp_session_create (struct iscsi_endpoint *ep,uint16_t cmds_max, +iscsi_sw_tcp_session_create (struct net *net,uint16_t cmds_max,uint16_t qdepth,uint32_t initial_cmdsn) {struct iscsi_cls_session *cls_session;
@@ -930,11 +930,6 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max,struct Scsi_Host *shost;int rc; -if (ep) { -printk (KERN_ERR "iscsi_tcp: invalid ep %p.\n" , ep); -return NULL ; - } - shost =iscsi_host_alloc (&iscsi_sw_tcp_sht,sizeof (struct iscsi_sw_tcp_host ),1 );if (!shost)
@@ -951,6 +946,9 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max, goto free_host; shost->can_queue = rc; + tcp_sw_host =iscsi_host_priv (shost); +iscsi_host_set_netns (shost, net); +if (iscsi_host_add (shost,NULL )) goto free_host;
@@ -967,7 +965,6 @@ iscsi_sw_tcp_session_create(struct iscsi_endpoint *ep, uint16_t cmds_max, goto remove_session;/* We are now fully setup so expose the session to sysfs. */ - tcp_sw_host =iscsi_host_priv (shost); tcp_sw_host->session = session;return cls_session;
@@ -1098,7 +1095,7 @@ static struct iscsi_transport iscsi_sw_tcp_transport = { .caps = CAP_RECOVERY_L0 | CAP_MULTI_R2T | CAP_HDRDGST | CAP_DATADGST,/* session management */ - .create_session = iscsi_sw_tcp_session_create, + .create_session_net = iscsi_sw_tcp_session_create, .destroy_session = iscsi_sw_tcp_session_destroy,/* connection management */ .create_conn = iscsi_sw_tcp_conn_create,
@@ -1126,6 +1123,8 @@ static struct iscsi_transport iscsi_sw_tcp_transport = { .alloc_pdu = iscsi_sw_tcp_pdu_alloc,/* recovery */ .session_recovery_timedout = iscsi_session_recovery_timedout, +/* net namespace */ + .get_netns = iscsi_host_get_netns, };static int __init iscsi_sw_tcp_init (void )
drivers/scsi/libiscsi.c +16 -0
@@ -3929,6 +3929,22 @@ int iscsi_host_set_param(struct Scsi_Host *shost, enum iscsi_host_param param, }EXPORT_SYMBOL_GPL (iscsi_host_set_param); +void iscsi_host_set_netns (struct Scsi_Host *shost,struct net *netns) +{ +struct iscsi_host *ihost =shost_priv (shost); + + ihost->net_ns = netns; +} +EXPORT_SYMBOL_GPL (iscsi_host_set_netns); + +struct net *iscsi_host_get_netns (struct Scsi_Host *shost) +{ +struct iscsi_host *ihost =shost_priv (shost); + +return ihost->net_ns; +} +EXPORT_SYMBOL_GPL (iscsi_host_get_netns); +MODULE_AUTHOR ("Mike Christie" );MODULE_DESCRIPTION ("iSCSI library functions" );MODULE_LICENSE ("GPL" );
drivers/scsi/scsi_transport_iscsi.c +51 -15
151 lines not on this page · raw message
include/scsi/libiscsi.h +4 -0
@@ -383,6 +383,7 @@ struct iscsi_host {int state;struct workqueue_struct *workq; +struct net *net_ns; };/*
@@ -492,6 +493,9 @@ extern void iscsi_pool_free(struct iscsi_pool *);extern int iscsi_pool_init (struct iscsi_pool *,int ,void ***,int );extern int iscsi_switch_str_param (char **,char *); +extern void iscsi_host_set_netns (struct Scsi_Host *,struct net *); +extern struct net *iscsi_host_get_netns (struct Scsi_Host *); +/* * inline functions to deal with padding. */
include/scsi/scsi_transport_iscsi.h +12 -0
@@ -35,6 +35,8 @@ struct iscsi_bus_flash_conn;* @name: transport name * @caps: iSCSI Data-Path capabilities * @create_session: create new iSCSI session object +* @create_session_net: create new iSCSI session object without a bound host, +* but with a specified net namespace * @destroy_session: destroy existing iSCSI session object * @create_conn: create new iSCSI connection * @bind_conn: associate this connection with existing iSCSI session
@@ -79,6 +81,9 @@ struct iscsi_transport {struct iscsi_cls_session *(*create_session) (struct iscsi_endpoint *ep,uint16_t cmds_max,uint16_t qdepth,uint32_t sn); +struct iscsi_cls_session *(*create_session_net) (struct net *net, +uint16_t cmds_max,uint16_t qdepth, +uint32_t sn);void (*destroy_session) (struct iscsi_cls_session *session);struct iscsi_cls_conn *(*create_conn) (struct iscsi_cls_session *sess,uint32_t cid);
@@ -122,6 +127,9 @@ struct iscsi_transport {struct iscsi_endpoint *(*ep_connect) (struct Scsi_Host *shost,struct sockaddr *dst_addr,int non_blocking); +struct iscsi_endpoint *(*ep_connect_net) (struct net *net, +struct sockaddr *dst_addr, +int non_blocking);int (*ep_poll) (struct iscsi_endpoint *ep,int timeout_ms);void (*ep_disconnect) (struct iscsi_endpoint *ep); int (*tgt_dscvr) (struct Scsi_Host *shost, enum iscsi_tgt_dscvr type,
@@ -156,6 +164,7 @@ struct iscsi_transport {int (*logout_flashnode_sid) (struct iscsi_cls_session *cls_sess);int (*get_host_stats) (struct Scsi_Host *shost,char *buf,int len);u8 (*check_protection)(struct iscsi_task *task,sector_t *sector); +struct net *(*get_netns)(struct Scsi_Host *shost); };/*
@@ -315,6 +324,7 @@ struct iscsi_endpoint {struct device dev;int id;struct iscsi_cls_conn *conn; +struct net *netns;/* used if there's no parent shost */ };struct iscsi_iface {
@@ -471,6 +481,8 @@ extern void iscsi_unblock_session(struct iscsi_cls_session *session);extern void iscsi_block_session (struct iscsi_cls_session *session);extern struct iscsi_endpoint *iscsi_create_endpoint (struct Scsi_Host *shost,int dd_size); +extern struct iscsi_endpoint *iscsi_create_endpoint_net (struct net *net, +int dd_size);extern void iscsi_destroy_endpoint (struct iscsi_endpoint *ep);extern struct iscsi_endpoint *iscsi_lookup_endpoint (struct net *net,u64 handle);
Signature · 1 line
2.39.2
kernel test robot
build botRe: [PATCH 06/11] iscsi: set netns for tcp and iser hosts
kernel test robot noticed the following build warnings:
Hi Chris,
kernel test robot noticed the following build warnings:
[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on jejb-scsi/for-next horms-ipvs/master linus/master v6.3 next-20230505] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Chris-Leech/iscsi-create-per-net-iscsi-netlink-kernel-sockets/20230507-073308 base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next patch link: https://lore.kernel.org/r/20230506232930.195451-7-cleech%40redhat.com patch subject: [PATCH 06/11] iscsi: set netns for tcp and iser hosts config: powerpc-randconfig-r016-20230507 (https://download.01.org/0day-ci/archive/20230507/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project b0fb98227c90adf2536c9ad644a74d5e92961111)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install powerpc cross compiling tool for clang build
# apt-get install binutils-powerpc-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/a287abe6fb8da0c4af44c1d83fad9ca4fcb7184f
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Chris-Leech/iscsi-create-per-net-iscsi-netlink-kernel-sockets/20230507-073308 git checkout a287abe6fb8da0c4af44c1d83fad9ca4fcb7184f
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=powerpc SHELL=/bin/bash drivers/scsi/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/scsi/scsi_transport_iscsi.c:234:1: warning: no previous prototype for function '__iscsi_create_endpoint' [-Wmissing-prototypes]
__iscsi_create_endpoint(struct Scsi_Host *shost, int dd_size, struct net *net)
^
drivers/scsi/scsi_transport_iscsi.c:233:1: note: declare 'static' if the function is not intended to be used outside of this translation unit struct iscsi_endpoint *
^
static
1 warning generated.
vim +/__iscsi_create_endpoint +234 drivers/scsi/scsi_transport_iscsi.c
232
233 struct iscsi_endpoint *
> 234 __iscsi_create_endpoint(struct Scsi_Host *shost, int dd_size, struct net *net)
235 {
236 struct iscsi_endpoint *ep;
237 int err, id;
238
239 ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL);
240 if (!ep)
241 return NULL;
242
243 mutex_lock(&iscsi_ep_idr_mutex);
244
245 /*
246 * First endpoint id should be 1 to comply with user space
247 * applications (iscsid).
248 */
249 id = idr_alloc(&iscsi_ep_idr, ep, 1, -1, GFP_NOIO);
250 if (id < 0) {
251 mutex_unlock(&iscsi_ep_idr_mutex);
252 printk(KERN_ERR "Could not allocate endpoint ID. Error %d.\n",
253 id);
254 goto free_ep;
255 }
256 mutex_unlock(&iscsi_ep_idr_mutex);
257
258 ep->id = id;
259 ep->dev.class = &iscsi_endpoint_class;
260 if (shost)
261 ep->dev.parent = &shost->shost_gendev;
262 if (net)
263 ep->netns = net;
264 dev_set_name(&ep->dev, "ep-%d", id);
265 err = device_register(&ep->dev);
266 if (err)
267 goto put_dev;
268
269 err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group);
270 if (err)
271 goto unregister_dev;
272
273 if (dd_size)
274 ep->dd_data = &ep[1];
275 return ep;
276
277 unregister_dev:
278 device_unregister(&ep->dev);
279 return NULL;
280
281 put_dev:
282 mutex_lock(&iscsi_ep_idr_mutex);
283 idr_remove(&iscsi_ep_idr, id);
284 mutex_unlock(&iscsi_ep_idr_mutex);
285 put_device(&ep->dev);
286 return NULL;
287 free_ep:
288 kfree(ep);
289 return NULL;
290 }
291
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [PATCH 06/11] iscsi: set netns for tcp and iser hosts
In reply to Chris Leechkernel test robot noticed the following build warnings:
Hi Chris,
kernel test robot noticed the following build warnings:
[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on jejb-scsi/for-next horms-ipvs/master linus/master v6.3 next-20230505] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Chris-Leech/iscsi-create-per-net-iscsi-netlink-kernel-sockets/20230507-073308 base: https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next patch link: https://lore.kernel.org/r/20230506232930.195451-7-cleech%40redhat.com patch subject: [PATCH 06/11] iscsi: set netns for tcp and iser hosts config: i386-randconfig-a005 (https://download.01.org/0day-ci/archive/20230507/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/a287abe6fb8da0c4af44c1d83fad9ca4fcb7184f
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Chris-Leech/iscsi-create-per-net-iscsi-netlink-kernel-sockets/20230507-073308 git checkout a287abe6fb8da0c4af44c1d83fad9ca4fcb7184f
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash drivers/scsi/
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/scsi/scsi_transport_iscsi.c:234:1: warning: no previous prototype for '__iscsi_create_endpoint' [-Wmissing-prototypes]
234 | __iscsi_create_endpoint(struct Scsi_Host *shost, int dd_size, struct net *net)
| ^~~~~~~~~~~~~~~~~~~~~~~
vim +/__iscsi_create_endpoint +234 drivers/scsi/scsi_transport_iscsi.c
232
233 struct iscsi_endpoint *
> 234 __iscsi_create_endpoint(struct Scsi_Host *shost, int dd_size, struct net *net)
235 {
236 struct iscsi_endpoint *ep;
237 int err, id;
238
239 ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL);
240 if (!ep)
241 return NULL;
242
243 mutex_lock(&iscsi_ep_idr_mutex);
244
245 /*
246 * First endpoint id should be 1 to comply with user space
247 * applications (iscsid).
248 */
249 id = idr_alloc(&iscsi_ep_idr, ep, 1, -1, GFP_NOIO);
250 if (id < 0) {
251 mutex_unlock(&iscsi_ep_idr_mutex);
252 printk(KERN_ERR "Could not allocate endpoint ID. Error %d.\n",
253 id);
254 goto free_ep;
255 }
256 mutex_unlock(&iscsi_ep_idr_mutex);
257
258 ep->id = id;
259 ep->dev.class = &iscsi_endpoint_class;
260 if (shost)
261 ep->dev.parent = &shost->shost_gendev;
262 if (net)
263 ep->netns = net;
264 dev_set_name(&ep->dev, "ep-%d", id);
265 err = device_register(&ep->dev);
266 if (err)
267 goto put_dev;
268
269 err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group);
270 if (err)
271 goto unregister_dev;
272
273 if (dd_size)
274 ep->dd_data = &ep[1];
275 return ep;
276
277 unregister_dev:
278 device_unregister(&ep->dev);
279 return NULL;
280
281 put_dev:
282 mutex_lock(&iscsi_ep_idr_mutex);
283 idr_remove(&iscsi_ep_idr, id);
284 mutex_unlock(&iscsi_ep_idr_mutex);
285 put_device(&ep->dev);
286 return NULL;
287 free_ep:
288 kfree(ep);
289 return NULL;
290 }
291
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
[email protected]
maintainerRe: [PATCH 06/11] iscsi: set netns for tcp and iser hosts
In reply to Chris LeechQuoted 10 lines · Chris Leech
drivers/infiniband/ulp/iser/iscsi_iser.c +2
-0@@ -656,6 +646,8 @@ iscsi_iser_session_create(struct iscsi_endpoint *ep,if (!(ib_dev->attrs.kernel_cap_flags &IBK_SG_GAPS_REG )) shost->virt_boundary_mask =SZ_4K -1 ; +iscsi_host_set_netns (shost, ep->netns); +if (iscsi_host_add (shost, ib_dev->dev.parent)) {mutex_unlock (&iser_conn->state_mutex); goto free_host;
drivers/infiniband/ulp/iser/iscsi_iser.c iscsi_iser_session_create(struct iscsi_endpoint *ep, · line 658
Quoted 4 lines
drivers/infiniband/ulp/iser/iscsi_iser.c +1
-0@@ -663,6 +655,7 @@ iscsi_iser_session_create(struct iscsi_endpoint *ep,mutex_unlock (&iser_conn->state_mutex); }else { shost->can_queue =min_t (u16, cmds_max,ISER_DEF_XMIT_CMDS_MAX ); +iscsi_host_set_netns (shost, net);
Just a nit, but use a consistent coding style. Do you like newlines before/after like above or not like here.
Quoted 6 lines
drivers/infiniband/ulp/iser/iscsi_iser.c +0
-0if (iscsi_host_add (shost,NULL )) goto free_host; }@@ -694,6 +687,34 @@ iscsi_iser_session_create(struct iscsi_endpoint *ep,return NULL ; }
drivers/infiniband/ulp/iser/iscsi_iser.c iscsi_iser_session_create(struct iscsi_endpoint *ep, · line 698
Quoted 10 lines
drivers/infiniband/ulp/iser/iscsi_iser.c +9
-0+/** +* iscsi_iser_session_create() - create an iscsi-iser session +* @ep: iscsi end-point handle +* @cmds_max: maximum commands in this session +* @qdepth: session command queue depth +* @initial_cmdsn: initiator command sequnce number +* +* Allocates and adds a scsi host, expose DIF support if +* exists, and sets up an iscsi session.
Maybe you want these comments for __iscsi_iser_session_create so you can describe the ep vs a net args. Or it's just odd to have it for only the ep function.
Quoted 11 lines
drivers/scsi/scsi_transport_iscsi.c +1
-1@@ -3106,14 +3128,21 @@ static int iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep, struct iscsi_uevent *ev, pid_t pid, uint32_t initial_cmdsn, uint16_t cmds_max, - uint16_t queue_depth) + uint16_t queue_depth, struct net *net) { struct iscsi_transport *transport = priv->iscsi_transport;struct iscsi_cls_session *session;struct Scsi_Host *shost;
drivers/scsi/scsi_transport_iscsi.c static int · line 3144
Quoted 10 lines
drivers/scsi/scsi_transport_iscsi.c +8
-2- session = transport->create_session (ep, cmds_max, queue_depth, - initial_cmdsn); +if (ep) { + session = transport->create_session (ep, cmds_max, queue_depth, + initial_cmdsn); + }else { + session = transport->create_session_net (net, cmds_max, + queue_depth, + initial_cmdsn); + }
No {}s are neede here and above. It will also match the other code you adding.
Chris Leech
maintainerPATCH v2 7/11 iscsi: convert flashnode devices from bus to class
In reply to Chris LeechFrom: Lee Duncan <[email protected]>
The flashnode session and connection devices should be filtered by net namespace along with the iscsi_host, but we can't do that with a bus device. As these don't use any of the bus matching functionality, they make more sense as a class device anyway.
--- drivers/scsi/qla4xxx/ql4_os.c | 2 +- drivers/scsi/scsi_transport_iscsi.c | 36 ++++++++++++----------------- include/scsi/scsi_transport_iscsi.h | 2 ++ 3 files changed, 18 insertions(+), 22 deletions(-)
drivers/scsi/qla4xxx/ql4_os.c +1 -1
@@ -7185,7 +7185,7 @@ static int qla4xxx_sysfs_ddb_is_non_persistent(struct device *dev, void *data) {struct iscsi_bus_flash_session *fnode_sess; -if (!iscsi_flashnode_bus_match (dev,NULL )) +if (!iscsi_is_flashnode_session_dev (dev))return 0 ; fnode_sess =iscsi_dev_to_flash_session (dev);
drivers/scsi/scsi_transport_iscsi.c +15 -21
@@ -1081,6 +1081,12 @@ static const struct device_type iscsi_flashnode_sess_dev_type = { .release = iscsi_flashnode_sess_release, }; +bool iscsi_is_flashnode_session_dev (struct device *dev) +{ +return dev->type == &iscsi_flashnode_sess_dev_type; +} +EXPORT_SYMBOL_GPL (iscsi_is_flashnode_session_dev); +/* flash node connection attrs show */ #define iscsi_flashnode_conn_attr_show (type, name, param) \ static ssize_t \
@@ -1267,20 +1273,8 @@ static const struct device_type iscsi_flashnode_conn_dev_type = { .release = iscsi_flashnode_conn_release, }; -static struct bus_type iscsi_flashnode_bus; - -int iscsi_flashnode_bus_match (struct device *dev, -struct device_driver *drv) -{ -if (dev->bus == &iscsi_flashnode_bus) -return 1 ; -return 0 ; -} -EXPORT_SYMBOL_GPL (iscsi_flashnode_bus_match); - -static struct bus_type iscsi_flashnode_bus = { +static struct class iscsi_flashnode_bus = { .name ="iscsi_flashnode" , - .match = &iscsi_flashnode_bus_match, };/**
@@ -1311,7 +1305,7 @@ iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index, fnode_sess->transport = transport; fnode_sess->target_id = index; fnode_sess->dev.type = &iscsi_flashnode_sess_dev_type; - fnode_sess->dev.bus = &iscsi_flashnode_bus; + fnode_sess->dev.class = &iscsi_flashnode_bus; fnode_sess->dev.parent = &shost->shost_gendev;dev_set_name (&fnode_sess->dev,"flashnode_sess-%u:%u" , shost->host_no, index);
@@ -1359,7 +1353,7 @@ iscsi_create_flashnode_conn(struct Scsi_Host *shost, fnode_conn->transport = transport; fnode_conn->dev.type = &iscsi_flashnode_conn_dev_type; - fnode_conn->dev.bus = &iscsi_flashnode_bus; + fnode_conn->dev.class = &iscsi_flashnode_bus; fnode_conn->dev.parent = &fnode_sess->dev;dev_set_name (&fnode_conn->dev,"flashnode_conn-%u:%u:0" , shost->host_no, fnode_sess->target_id);
@@ -1392,7 +1386,7 @@ EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn);*/ static int iscsi_is_flashnode_conn_dev (struct device *dev,void *data) { -return dev->bus == &iscsi_flashnode_bus; +return dev->type == &iscsi_flashnode_conn_dev_type; }static int iscsi_destroy_flashnode_conn (struct iscsi_bus_flash_conn *fnode_conn)
@@ -1406,7 +1400,7 @@ static int flashnode_match_index(struct device *dev, void *data)struct iscsi_bus_flash_session *fnode_sess =NULL ;int ret =0 ; -if (!iscsi_flashnode_bus_match (dev,NULL )) +if (dev->type != &iscsi_flashnode_sess_dev_type) goto exit_match_index; fnode_sess =iscsi_dev_to_flash_session (dev);
@@ -1512,7 +1506,7 @@ EXPORT_SYMBOL_GPL(iscsi_destroy_flashnode_sess);static int iscsi_iter_destroy_flashnode_fn (struct device *dev,void *data) { -if (!iscsi_flashnode_bus_match (dev,NULL )) +if (dev->type != &iscsi_flashnode_sess_dev_type)return 0 ;iscsi_destroy_flashnode_sess (iscsi_dev_to_flash_session (dev));
@@ -5235,7 +5229,7 @@ static __init int iscsi_transport_init(void)if (err) goto unregister_conn_class; - err =bus_register (&iscsi_flashnode_bus); + err =class_register (&iscsi_flashnode_bus);if (err) goto unregister_session_class;
@@ -5258,7 +5252,7 @@ static __init int iscsi_transport_init(void) unregister_pernet_subsys:unregister_pernet_subsys (&iscsi_net_ops); unregister_flashnode_bus: -bus_unregister (&iscsi_flashnode_bus); +class_unregister (&iscsi_flashnode_bus); unregister_session_class:transport_class_unregister (&iscsi_session_class); unregister_conn_class:
@@ -5278,7 +5272,7 @@ static void __exit iscsi_transport_exit(void) {destroy_workqueue (iscsi_conn_cleanup_workq);unregister_pernet_subsys (&iscsi_net_ops); -bus_unregister (&iscsi_flashnode_bus); +class_unregister (&iscsi_flashnode_bus);transport_class_unregister (&iscsi_connection_class);transport_class_unregister (&iscsi_session_class);transport_class_unregister (&iscsi_host_class);
include/scsi/scsi_transport_iscsi.h +2 -0
@@ -524,6 +524,8 @@ iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data,extern struct device *iscsi_find_flashnode_conn (struct iscsi_bus_flash_session *fnode_sess); +extern bool iscsi_is_flashnode_session_dev (struct device *dev); +extern char *iscsi_get_ipaddress_state_name (enum iscsi_ipaddress_state port_state);extern char *iscsi_get_router_state_name (enum iscsi_router_state router_state);
Signature · 1 line
2.39.2
[email protected]
maintainerRe: [PATCH 07/11] iscsi: convert flashnode devices from bus to class
Quoted 7 lines · Chris Leech
From: Lee Duncan <[email protected]>
The flashnode session and connection devices should be filtered by net namespace along with the
iscsi_host, but we can't do that with a bus device. As these don't use any of the bus matching functionality, they make more sense as a class device anyway.
Will offload always use the default namespace? If so, there's no need to touch this code right?
Chris Leech
maintainerPATCH v2 8/11 iscsi: rename iscsi_bus_flash_* to iscsi_flash_*
In reply to Chris LeechFrom: Lee Duncan <[email protected]>
These are cleanups after the bus to class conversion for flashnode devices.
--- drivers/scsi/qla4xxx/ql4_os.c | 52 +++++++------- drivers/scsi/scsi_transport_iscsi.c | 102 ++++++++++++++-------------- include/scsi/scsi_transport_iscsi.h | 48 ++++++------- 3 files changed, 102 insertions(+), 100 deletions(-)
drivers/scsi/qla4xxx/ql4_os.c +26 -26
@@ -168,20 +168,20 @@ static int qla4xxx_host_reset(struct Scsi_Host *shost, int reset_type);* iSCSI Flash DDB sysfs entry points */ static int -qla4xxx_sysfs_ddb_set_param (struct iscsi_bus_flash_session *fnode_sess, -struct iscsi_bus_flash_conn *fnode_conn, +qla4xxx_sysfs_ddb_set_param (struct iscsi_flash_session *fnode_sess, +struct iscsi_flash_conn *fnode_conn,void *data,int len);static int -qla4xxx_sysfs_ddb_get_param (struct iscsi_bus_flash_session *fnode_sess, +qla4xxx_sysfs_ddb_get_param (struct iscsi_flash_session *fnode_sess,int param,char *buf);static int qla4xxx_sysfs_ddb_add (struct Scsi_Host *shost,const char *buf,int len);static int -qla4xxx_sysfs_ddb_delete (struct iscsi_bus_flash_session *fnode_sess); -static int qla4xxx_sysfs_ddb_login (struct iscsi_bus_flash_session *fnode_sess, -struct iscsi_bus_flash_conn *fnode_conn); -static int qla4xxx_sysfs_ddb_logout (struct iscsi_bus_flash_session *fnode_sess, -struct iscsi_bus_flash_conn *fnode_conn); +qla4xxx_sysfs_ddb_delete (struct iscsi_flash_session *fnode_sess); +static int qla4xxx_sysfs_ddb_login (struct iscsi_flash_session *fnode_sess, +struct iscsi_flash_conn *fnode_conn); +static int qla4xxx_sysfs_ddb_logout (struct iscsi_flash_session *fnode_sess, +struct iscsi_flash_conn *fnode_conn);static int qla4xxx_sysfs_ddb_logout_sid (struct iscsi_cls_session *cls_sess); static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
@@ -3494,8 +3494,8 @@ static int qla4xxx_task_xmit(struct iscsi_task *task)return -ENOSYS ; } -static int qla4xxx_copy_from_fwddb_param (struct iscsi_bus_flash_session *sess, -struct iscsi_bus_flash_conn *conn, +static int qla4xxx_copy_from_fwddb_param (struct iscsi_flash_session *sess, +struct iscsi_flash_conn *conn,struct dev_db_entry *fw_ddb_entry) {unsigned long options =0 ;
@@ -3636,8 +3636,8 @@ static int qla4xxx_copy_from_fwddb_param(struct iscsi_bus_flash_session *sess,return rc; } -static int qla4xxx_copy_to_fwddb_param (struct iscsi_bus_flash_session *sess, -struct iscsi_bus_flash_conn *conn, +static int qla4xxx_copy_to_fwddb_param (struct iscsi_flash_session *sess, +struct iscsi_flash_conn *conn,struct dev_db_entry *fw_ddb_entry) {uint16_t options;
@@ -7183,7 +7183,7 @@ static void qla4xxx_build_new_nt_list(struct scsi_qla_host *ha,**/ static int qla4xxx_sysfs_ddb_is_non_persistent (struct device *dev,void *data) { -struct iscsi_bus_flash_session *fnode_sess; +struct iscsi_flash_session *fnode_sess;if (!iscsi_is_flashnode_session_dev (dev))return 0 ;
@@ -7213,8 +7213,8 @@ static int qla4xxx_sysfs_ddb_tgt_create(struct scsi_qla_host *ha,struct dev_db_entry *fw_ddb_entry, uint16_t *idx, int user) { - struct iscsi_bus_flash_session *fnode_sess = NULL; -struct iscsi_bus_flash_conn *fnode_conn =NULL ; + struct iscsi_flash_session *fnode_sess = NULL; +struct iscsi_flash_conn *fnode_conn =NULL ;int rc =QLA_ERROR ; fnode_sess = iscsi_create_flashnode_sess(ha->host, *idx,
@@ -7353,8 +7353,8 @@ static int qla4xxx_sysfs_ddb_add(struct Scsi_Host *shost, const char *buf,* This writes the contents of target ddb buffer to Flash with a valid cookie * value in order to make the ddb entry persistent. **/ -static int qla4xxx_sysfs_ddb_apply (struct iscsi_bus_flash_session *fnode_sess, -struct iscsi_bus_flash_conn *fnode_conn) +static int qla4xxx_sysfs_ddb_apply (struct iscsi_flash_session *fnode_sess, +struct iscsi_flash_conn *fnode_conn) {struct Scsi_Host *shost =iscsi_flash_session_to_shost (fnode_sess);struct scsi_qla_host *ha =to_qla_host (shost);
@@ -7543,8 +7543,8 @@ static int qla4xxx_ddb_login_nt(struct scsi_qla_host *ha,* * This logs in to the specified target **/ -static int qla4xxx_sysfs_ddb_login (struct iscsi_bus_flash_session *fnode_sess, -struct iscsi_bus_flash_conn *fnode_conn) +static int qla4xxx_sysfs_ddb_login (struct iscsi_flash_session *fnode_sess, +struct iscsi_flash_conn *fnode_conn) {struct Scsi_Host *shost =iscsi_flash_session_to_shost (fnode_sess);struct scsi_qla_host *ha =to_qla_host (shost);
@@ -7727,8 +7727,8 @@ static int qla4xxx_sysfs_ddb_logout_sid(struct iscsi_cls_session *cls_sess)* * This performs log out from the specified target **/ -static int qla4xxx_sysfs_ddb_logout (struct iscsi_bus_flash_session *fnode_sess, -struct iscsi_bus_flash_conn *fnode_conn) +static int qla4xxx_sysfs_ddb_logout (struct iscsi_flash_session *fnode_sess, +struct iscsi_flash_conn *fnode_conn) {struct Scsi_Host *shost =iscsi_flash_session_to_shost (fnode_sess);struct scsi_qla_host *ha =to_qla_host (shost);
@@ -7837,12 +7837,12 @@ static int qla4xxx_sysfs_ddb_logout(struct iscsi_bus_flash_session *fnode_sess, }static int -qla4xxx_sysfs_ddb_get_param (struct iscsi_bus_flash_session *fnode_sess, +qla4xxx_sysfs_ddb_get_param (struct iscsi_flash_session *fnode_sess,int param,char *buf) {struct Scsi_Host *shost =iscsi_flash_session_to_shost (fnode_sess);struct scsi_qla_host *ha =to_qla_host (shost); -struct iscsi_bus_flash_conn *fnode_conn; +struct iscsi_flash_conn *fnode_conn;struct ql4_chap_table chap_tbl;struct device *dev;int parent_type;
@@ -8091,8 +8091,8 @@ qla4xxx_sysfs_ddb_get_param(struct iscsi_bus_flash_session *fnode_sess,* This sets the parameter of flash ddb entry and writes them to flash **/ static int -qla4xxx_sysfs_ddb_set_param (struct iscsi_bus_flash_session *fnode_sess, -struct iscsi_bus_flash_conn *fnode_conn, +qla4xxx_sysfs_ddb_set_param (struct iscsi_flash_session *fnode_sess, +struct iscsi_flash_conn *fnode_conn,void *data,int len) {struct Scsi_Host *shost =iscsi_flash_session_to_shost (fnode_sess);
@@ -8319,7 +8319,7 @@ qla4xxx_sysfs_ddb_set_param(struct iscsi_bus_flash_session *fnode_sess,* * This invalidates the flash ddb entry at the given index **/ -static int qla4xxx_sysfs_ddb_delete (struct iscsi_bus_flash_session *fnode_sess) +static int qla4xxx_sysfs_ddb_delete (struct iscsi_flash_session *fnode_sess) {struct Scsi_Host *shost =iscsi_flash_session_to_shost (fnode_sess);struct scsi_qla_host *ha =to_qla_host (shost);
drivers/scsi/scsi_transport_iscsi.c +51 -51
268 lines not on this page · raw message
include/scsi/scsi_transport_iscsi.h +25 -23
103 lines not on this page · raw message
Signature · 1 line
2.39.2
Chris Leech
maintainerPATCH v2 9/11 iscsi: filter flashnode sysfs by net namespace
In reply to Chris LeechFrom: Lee Duncan <[email protected]>
This finishes the net namespace support for flashnode sysfs devices.
--- drivers/scsi/scsi_transport_iscsi.c | 34 +++++++++++++++++++++++++++++ include/scsi/scsi_transport_iscsi.h | 4 ---- 2 files changed, 34 insertions(+), 4 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +34 -0
@@ -1289,8 +1289,42 @@ static int iscsi_is_flashnode_conn_dev(struct device *dev, void *data)return dev->type == &iscsi_flashnode_conn_dev_type; } +static struct net *iscsi_flashnode_sess_net (struct iscsi_flash_session *f_sess) +{ +struct Scsi_Host *shost =iscsi_flash_session_to_shost (f_sess); +struct iscsi_cls_host *ihost = shost->shost_data; + +return iscsi_host_net (ihost); +} + +static struct net *iscsi_flashnode_conn_net (struct iscsi_flash_conn *f_conn) +{ +struct iscsi_flash_session *f_sess = +iscsi_flash_conn_to_flash_session (f_conn); + +return iscsi_flashnode_sess_net (f_sess); +} + +static const void *iscsi_flashnode_namespace (const struct device *dev) +{ +struct iscsi_flash_conn *f_conn; +struct iscsi_flash_session *f_sess; +struct device *dev_tmp = (struct device *)dev; + +if (iscsi_is_flashnode_conn_dev (dev_tmp,NULL )) { + f_conn =iscsi_dev_to_flash_conn (dev); +return iscsi_flashnode_conn_net (f_conn); + }else if (iscsi_is_flashnode_session_dev (dev_tmp)) { + f_sess =iscsi_dev_to_flash_session (dev); +return iscsi_flashnode_sess_net (f_sess); + } +return NULL ; +} +static struct class iscsi_flashnode = { .name ="iscsi_flashnode" , + .ns_type = &net_ns_type_operations, + .namespace = iscsi_flashnode_namespace, };/**
include/scsi/scsi_transport_iscsi.h +0 -4
@@ -516,8 +516,6 @@ extern void iscsi_destroy_flashnode_sess(struct iscsi_flash_session *fnode_sess);extern void iscsi_destroy_all_flashnode (struct Scsi_Host *shost); -extern int iscsi_flashnode_bus_match (struct device *dev, -struct device_driver *drv);extern struct device *iscsi_find_flashnode_sess (struct Scsi_Host *shost,void *data,int (*fn)(struct device *dev,void *data));
@@ -526,8 +524,6 @@ iscsi_find_flashnode_conn(struct iscsi_flash_session *fnode_sess);extern bool iscsi_is_flashnode_session_dev (struct device *dev); -extern bool iscsi_is_flashnode_session_dev (struct device *dev); -extern char *iscsi_get_ipaddress_state_name (enum iscsi_ipaddress_state port_state);extern char *iscsi_get_router_state_name (enum iscsi_router_state router_state);
Signature · 1 line
2.39.2
Chris Leech
maintainerPATCH v2 10/11 iscsi: make session and connection lists per-net
In reply to Chris LeechEliminate the comparisions on list lookups, and it will make it easier to shut down session on net namespace exit in the next patch.
--- drivers/scsi/scsi_transport_iscsi.c | 104 ++++++++++++++++------------ 1 file changed, 61 insertions(+), 43 deletions(-)
drivers/scsi/scsi_transport_iscsi.c +61 -43
@@ -1755,17 +1755,16 @@ static DECLARE_TRANSPORT_CLASS_NS(iscsi_connection_class,struct iscsi_net {struct sock *nls; +spinlock_t sesslock; +struct list_head sesslist; +spinlock_t connlock; +struct list_head connlist; +struct list_head connlist_err; };static int iscsi_net_id__read_mostly ;static DEFINE_MUTEX (rx_queue_mutex); -static LIST_HEAD (sesslist); -static DEFINE_SPINLOCK (sesslock); -static LIST_HEAD (connlist); -static LIST_HEAD (connlist_err); -static DEFINE_SPINLOCK (connlock); -static uint32_t iscsi_conn_get_sid (struct iscsi_cls_conn *conn) {struct iscsi_cls_session *sess =iscsi_dev_to_session (conn->dev.parent);
@@ -1780,19 +1779,18 @@ static struct iscsi_cls_session *iscsi_session_lookup(struct net *net, {unsigned long flags;struct iscsi_cls_session *sess; -struct net *ns; +struct iscsi_net *isn; -spin_lock_irqsave (&sesslock, flags); -list_for_each_entry (sess, &sesslist, sess_list) { + isn =net_generic (net, iscsi_net_id); + +spin_lock_irqsave (&isn->sesslock, flags); +list_for_each_entry (sess, &isn->sesslist, sess_list) {if (sess->sid == sid) { - ns =iscsi_sess_net (sess); -if (ns != net) -continue ; -spin_unlock_irqrestore (&sesslock, flags); +spin_unlock_irqrestore (&isn->sesslock, flags);return sess; } } -spin_unlock_irqrestore (&sesslock, flags); +spin_unlock_irqrestore (&isn->sesslock, flags);return NULL ; }
@@ -1804,19 +1802,18 @@ static struct iscsi_cls_conn *iscsi_conn_lookup(struct net *net, uint32_t sid, {unsigned long flags;struct iscsi_cls_conn *conn; -struct net *ns; +struct iscsi_net *isn; -spin_lock_irqsave (&connlock, flags); -list_for_each_entry (conn, &connlist, conn_list) { + isn =net_generic (net, iscsi_net_id); + +spin_lock_irqsave (&isn->connlock, flags); +list_for_each_entry (conn, &isn->connlist, conn_list) {if ((conn->cid == cid) && (iscsi_conn_get_sid (conn) == sid)) { - ns =iscsi_conn_net (conn); -if (ns != net) -continue ; -spin_unlock_irqrestore (&connlock, flags); +spin_unlock_irqrestore (&isn->connlock, flags);return conn; } } -spin_unlock_irqrestore (&connlock, flags); +spin_unlock_irqrestore (&isn->connlock, flags);return NULL ; }
@@ -2228,6 +2225,9 @@ EXPORT_SYMBOL_GPL(iscsi_alloc_session);int iscsi_add_session (struct iscsi_cls_session *session,unsigned int target_id) {struct Scsi_Host *shost =iscsi_session_to_shost (session); +struct iscsi_cls_host *ihost = shost->shost_data; +struct net *net =iscsi_host_net (ihost); +struct iscsi_net *isn =net_generic (net, iscsi_net_id);unsigned long flags;int id =0 ;int err;
@@ -2271,9 +2271,9 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id) goto release_dev; } -spin_lock_irqsave (&sesslock, flags); -list_add (&session->sess_list, &sesslist); -spin_unlock_irqrestore (&sesslock, flags); +spin_lock_irqsave (&isn->sesslock, flags); +list_add (&session->sess_list, &isn->sesslist); +spin_unlock_irqrestore (&isn->sesslock, flags);iscsi_session_event (session,ISCSI_KEVENT_CREATE_SESSION );ISCSI_DBG_TRANS_SESSION (session,"Completed session adding\n" );
@@ -2343,15 +2343,17 @@ static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data)void iscsi_remove_session (struct iscsi_cls_session *session) { +struct net *net =iscsi_sess_net (session); +struct iscsi_net *isn =net_generic (net, iscsi_net_id);unsigned long flags;int err;ISCSI_DBG_TRANS_SESSION (session,"Removing session\n" ); -spin_lock_irqsave (&sesslock, flags); +spin_lock_irqsave (&isn->sesslock, flags);if (!list_empty (&session->sess_list))list_del (&session->sess_list); -spin_unlock_irqrestore (&sesslock, flags); +spin_unlock_irqrestore (&isn->sesslock, flags);if (!cancel_work_sync (&session->block_work))cancel_delayed_work_sync (&session->recovery_work);
@@ -2562,20 +2564,22 @@ static int iscsi_iter_force_destroy_conn_fn(struct device *dev, void *data)void iscsi_force_destroy_session (struct iscsi_cls_session *session) {struct iscsi_transport *transport = session->transport; +struct net *net =iscsi_sess_net (session); +struct iscsi_net *isn =net_generic (net, iscsi_net_id);unsigned long flags;WARN_ON_ONCE (system_state ==SYSTEM_RUNNING ); -spin_lock_irqsave (&sesslock, flags); +spin_lock_irqsave (&isn->sesslock, flags);if (list_empty (&session->sess_list)) { -spin_unlock_irqrestore (&sesslock, flags); +spin_unlock_irqrestore (&isn->sesslock, flags);/* * Conn/ep is already freed. Session is being torn down via * async path. For shutdown we don't care about it so return. */ return ; } -spin_unlock_irqrestore (&sesslock, flags); +spin_unlock_irqrestore (&isn->sesslock, flags);device_for_each_child (&session->dev,NULL , iscsi_iter_force_destroy_conn_fn);
@@ -2646,6 +2650,8 @@ int iscsi_add_conn(struct iscsi_cls_conn *conn)int err;unsigned long flags;struct iscsi_cls_session *session =iscsi_dev_to_session (conn->dev.parent); +struct net *net =iscsi_sess_net (session); +struct iscsi_net *isn =net_generic (net, iscsi_net_id); err =device_add (&conn->dev);if (err) {
@@ -2661,9 +2667,9 @@ int iscsi_add_conn(struct iscsi_cls_conn *conn)return err; } -spin_lock_irqsave (&connlock, flags); -list_add (&conn->conn_list, &connlist); -spin_unlock_irqrestore (&connlock, flags); +spin_lock_irqsave (&isn->connlock, flags); +list_add (&conn->conn_list, &isn->connlist); +spin_unlock_irqrestore (&isn->connlock, flags);return 0 ; }
@@ -2678,11 +2684,14 @@ EXPORT_SYMBOL_GPL(iscsi_add_conn);*/ void iscsi_remove_conn (struct iscsi_cls_conn *conn) { +struct net *net =iscsi_conn_net (conn); +struct iscsi_net *isn =net_generic (net, iscsi_net_id); +unsigned long flags; -spin_lock_irqsave (&connlock, flags); +spin_lock_irqsave (&isn->connlock, flags);list_del (&conn->conn_list); -spin_unlock_irqrestore (&connlock, flags); +spin_unlock_irqrestore (&isn->connlock, flags);transport_unregister_device (&conn->dev);device_del (&conn->dev);
@@ -3466,20 +3475,21 @@ iscsi_set_path(struct net *net, struct iscsi_transport *transport,return err; } -static int iscsi_session_has_conns (int sid) +static int iscsi_session_has_conns (struct net *net,int sid) { +struct iscsi_net *isn =net_generic (net, iscsi_net_id);struct iscsi_cls_conn *conn;unsigned long flags;int found =0 ; -spin_lock_irqsave (&connlock, flags); -list_for_each_entry (conn, &connlist, conn_list) { +spin_lock_irqsave (&isn->connlock, flags); +list_for_each_entry (conn, &isn->connlist, conn_list) {if (iscsi_conn_get_sid (conn) == sid) { found =1 ;break ; } } -spin_unlock_irqrestore (&connlock, flags); +spin_unlock_irqrestore (&isn->connlock, flags);return found; }
@@ -4192,7 +4202,7 @@ iscsi_if_recv_msg(struct net *net, struct sk_buff *skb, session =iscsi_session_lookup (net, ev->u.d_session.sid);if (!session) err = -EINVAL ; -else if (iscsi_session_has_conns (ev->u.d_session.sid)) +else if (iscsi_session_has_conns (net, ev->u.d_session.sid)) err = -EBUSY ;else transport->destroy_session (session);
@@ -4201,15 +4211,16 @@ iscsi_if_recv_msg(struct net *net, struct sk_buff *skb, session =iscsi_session_lookup (net, ev->u.d_session.sid);if (!session) err = -EINVAL ; -else if (iscsi_session_has_conns (ev->u.d_session.sid)) +else if (iscsi_session_has_conns (net, ev->u.d_session.sid)) err = -EBUSY ;else { +struct iscsi_net *isn =net_generic (net, iscsi_net_id);unsigned long flags;/* Prevent this session from being found again */ -spin_lock_irqsave (&sesslock, flags); +spin_lock_irqsave (&isn->sesslock, flags);list_del_init (&session->sess_list); -spin_unlock_irqrestore (&sesslock, flags); +spin_unlock_irqrestore (&isn->sesslock, flags);queue_work (system_unbound_wq, &session->destroy_work); }
@@ -5211,6 +5222,13 @@ static int __net_init iscsi_net_init(struct net *net)if (!nls)return -ENOMEM ; isn =net_generic (net, iscsi_net_id); + +INIT_LIST_HEAD (&isn->sesslist); +spin_lock_init (&isn->sesslock); +INIT_LIST_HEAD (&isn->connlist); +INIT_LIST_HEAD (&isn->connlist_err); +spin_lock_init (&isn->connlock); + isn->nls = nls;return 0 ; }
Signature · 1 line
2.39.2
[email protected]
maintainerRe: [PATCH 10/11] iscsi: make session and connection lists per-net
drivers/scsi/scsi_transport_iscsi.c static DECLARE_TRANSPORT_CLASS_NS(iscsi_connection_class, · line 1761
Quoted 12 lines · Chris Leech
drivers/scsi/scsi_transport_iscsi.c +4
-0@@ -1755,17 +1755,16 @@ static DECLARE_TRANSPORT_CLASS_NS(iscsi_connection_class,struct iscsi_net {struct sock *nls; +spinlock_t sesslock; +struct list_head sesslist; +spinlock_t connlock; +struct list_head connlist;
Instead of lists use an xarray. That was actually one of the TODO items from Lee's talk last year on lots of sessions. You can kill that and do iscsi ns at the same time :)
drivers/scsi/scsi_transport_iscsi.c static DECLARE_TRANSPORT_CLASS_NS(iscsi_connection_class, · line 1763
Quoted 2 lines
drivers/scsi/scsi_transport_iscsi.c +1
-0+struct list_head connlist_err; };
connlist_err is not used so you can kill it.
Chris Leech
maintainerPATCH v2 11/11 iscsi: force destroy sesions when a network namespace exits
In reply to Chris LeechThe namespace is gone, so there is no userspace to clean up. Force close all the sessions.
This should be enough for software transports, there's no implementation of migrating physical iSCSI hosts between network namespaces currently.
--- drivers/scsi/scsi_transport_iscsi.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/scsi/scsi_transport_iscsi.c +16 -0
@@ -5235,9 +5235,25 @@ static int __net_init iscsi_net_init(struct net *net) static void __net_exit iscsi_net_exit(struct net *net) { +struct iscsi_cls_session *session, *tmp;struct iscsi_net *isn; +unsigned long flags; +LIST_HEAD (sessions); isn =net_generic (net, iscsi_net_id); + +spin_lock_irqsave (&isn->sesslock, flags); +list_replace_init (&isn->sesslist, &sessions); +spin_unlock_irqrestore (&isn->sesslock, flags); + +/* force session destruction, there is no userspace anymore */ +list_for_each_entry_safe (session, tmp, &sessions, sess_list) { +device_for_each_child (&session->dev,NULL , + iscsi_iter_force_destroy_conn_fn); +flush_work (&session->destroy_work); +__iscsi_destroy_session (&session->destroy_work); + } +netlink_kernel_release (isn->nls); isn->nls =NULL ; }
Signature · 1 line
2.39.2
[email protected]
maintainerRe: [PATCH 11/11] iscsi: force destroy sesions when a network namespace exits
Quoted 26 lines · Chris Leech
The namespace is gone, so there is no userspace to clean up. Force close all the sessions.
This should be enough for software transports, there's no implementation of migrating physical iSCSI hosts between network namespaces currently.
Reviewed-by Hannes Reinecke <[email protected]>Signed-off-by Chris Leech <[email protected]>--- drivers/scsi/scsi_transport_iscsi.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)drivers/scsi/scsi_transport_iscsi.c +3
-0@@ -5235,9 +5235,25 @@ static int __net_init iscsi_net_init(struct net *net) static void __net_exit iscsi_net_exit(struct net *net) { +struct iscsi_cls_session *session, *tmp;struct iscsi_net *isn; +unsigned long flags; +LIST_HEAD (sessions); isn =net_generic (net, iscsi_net_id);
drivers/scsi/scsi_transport_iscsi.c static int __net_init iscsi_net_init(struct net *net) · line 5253
Quoted 10 lines
drivers/scsi/scsi_transport_iscsi.c +10
-0+ +spin_lock_irqsave (&isn->sesslock, flags); +list_replace_init (&isn->sesslist, &sessions); +spin_unlock_irqrestore (&isn->sesslock, flags); + +/* force session destruction, there is no userspace anymore */ +list_for_each_entry_safe (session, tmp, &sessions, sess_list) { +device_for_each_child (&session->dev,NULL , + iscsi_iter_force_destroy_conn_fn); +flush_work (&session->destroy_work);
I think if this flush_work actually flushed, then we would be doing a use after free because the running work would free the session from under us.
We should never have a running destroy_work and be ale to see it on the sesslist right? Maybe a WARN_ON or something else so it doesn't look like a possible bug.
Quoted 6 lines
drivers/scsi/scsi_transport_iscsi.c +3
-0+__iscsi_destroy_session (&session->destroy_work); + } +netlink_kernel_release (isn->nls); isn->nls =NULL ; }
[email protected]
maintainerRe: [PATCH 11/11] iscsi: force destroy sesions when a network namespace exits
Quoted 41 lines · On 5/10/23 1:09 PM, [email protected] wrote:
Quoted 26 lines · Chris Leech
The namespace is gone, so there is no userspace to clean up. Force close all the sessions.
This should be enough for software transports, there's no implementation of migrating physical iSCSI hosts between network namespaces currently.
Reviewed-by Hannes Reinecke <[email protected]>Signed-off-by Chris Leech <[email protected]>--- drivers/scsi/scsi_transport_iscsi.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)drivers/scsi/scsi_transport_iscsi.c +3
-0@@ -5235,9 +5235,25 @@ static int __net_init iscsi_net_init(struct net *net) static void __net_exit iscsi_net_exit(struct net *net) { +struct iscsi_cls_session *session, *tmp;struct iscsi_net *isn; +unsigned long flags; +LIST_HEAD (sessions); isn =net_generic (net, iscsi_net_id);drivers/scsi/scsi_transport_iscsi.c static int __net_init iscsi_net_init(struct net *net) · line 5253
Quoted 10 lines
drivers/scsi/scsi_transport_iscsi.c +10
-0+ +spin_lock_irqsave (&isn->sesslock, flags); +list_replace_init (&isn->sesslist, &sessions); +spin_unlock_irqrestore (&isn->sesslock, flags); + +/* force session destruction, there is no userspace anymore */ +list_for_each_entry_safe (session, tmp, &sessions, sess_list) { +device_for_each_child (&session->dev,NULL , + iscsi_iter_force_destroy_conn_fn); +flush_work (&session->destroy_work);I think if this
flush_workactually flushed, then we would be doing a use after free because the running work would free the session from under us.
Quoted 3 lines
We should never have a running
destroy_workand be ale to see it on the sesslist right? Maybe aWARN_ONor something else so it doesn't look like a possible bug.
Maybe not a WARN_ON. What happens if there is running destroy_works for this namespace and we return from this function?
Quoted 9 lines
Quoted 8 lines
drivers/scsi/scsi_transport_iscsi.c +3
-0+__iscsi_destroy_session (&session->destroy_work); + } +netlink_kernel_release (isn->nls); isn->nls =NULL ; }
[email protected]
maintainerQuoted 2 lines · Chris Leech
Note that with
iscsi_tcp, the connected socket will keep the network namespace alive after container exit. The namespace will exit once the
What happens for iser? Is it the same?