From patchwork Wed May 13 22:12:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 6400601 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1FCB19F32B for ; Wed, 13 May 2015 22:14:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 333D620263 for ; Wed, 13 May 2015 22:14:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 216B72025A for ; Wed, 13 May 2015 22:14:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965318AbbEMWN4 (ORCPT ); Wed, 13 May 2015 18:13:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35039 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934496AbbEMWNR (ORCPT ); Wed, 13 May 2015 18:13:17 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t4DMDFW9026855 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 13 May 2015 18:13:15 -0400 Received: from straylight.hirudinean.org.com ([10.3.113.8]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t4DMDDgC019894; Wed, 13 May 2015 18:13:14 -0400 From: Chris Leech To: , , netdev@vger.kernel.org Subject: [RFC PATCH 1/4] iscsi: create per-net iscsi nl kernel sockets Date: Wed, 13 May 2015 15:12:44 -0700 Message-Id: <1431555167-23995-2-git-send-email-cleech@redhat.com> In-Reply-To: <1431555167-23995-1-git-send-email-cleech@redhat.com> References: <1431555167-23995-1-git-send-email-cleech@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Prepare iSCSI netlink to operate in multiple namespaces. --- drivers/scsi/scsi_transport_iscsi.c | 67 +++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 10 deletions(-) diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 67d43e3..88a3347 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -26,6 +26,8 @@ #include #include #include +#include +#include #include #include #include @@ -1606,7 +1608,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); @@ -2338,11 +2344,23 @@ 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); +} + int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr, char *data, uint32_t data_size) { @@ -4505,13 +4523,42 @@ int iscsi_unregister_transport(struct iscsi_transport *tt) } EXPORT_SYMBOL_GPL(iscsi_unregister_transport); -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); @@ -4545,8 +4592,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; } @@ -4554,13 +4601,13 @@ static __init int iscsi_transport_init(void) iscsi_eh_timer_workq = create_singlethread_workqueue("iscsi_eh"); if (!iscsi_eh_timer_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: @@ -4581,7 +4628,7 @@ unregister_transport_class: static void __exit iscsi_transport_exit(void) { destroy_workqueue(iscsi_eh_timer_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);