From patchwork Sat May 6 23:29:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 679702 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 385E5C77B73 for ; Sat, 6 May 2023 23:30:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbjEFXal (ORCPT ); Sat, 6 May 2023 19:30:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbjEFXaj (ORCPT ); Sat, 6 May 2023 19:30:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32E1544B0 for ; Sat, 6 May 2023 16:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683415796; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hYyQlEMhSGqDHAeBkFmR50DWq7fNvIgSCciz+KWBYp8=; b=JHtE6YLi6gBCECYxeqE055KkNez+YR8c7FdS1HZ4uhF6BcEcrcvUizAqq6C+kXlhvINI7P dGgWRwQuiPP71XIo3rjPmLRg0dJCMY8c9m2hPr5RuYLvLx9SI7wIc9dtckfv3SpemHJZoI 09QfOEJxDibIQZf1TfS8vkLUqtb1FgA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-561-6lRs3NMePeu1eoQ-2i5ylg-1; Sat, 06 May 2023 19:29:55 -0400 X-MC-Unique: 6lRs3NMePeu1eoQ-2i5ylg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 94E143806700; Sat, 6 May 2023 23:29:54 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.2.16.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE2F535443; Sat, 6 May 2023 23:29:53 +0000 (UTC) From: Chris Leech To: Lee Duncan , linux-scsi@vger.kernel.org, open-iscsi@googlegroups.com, netdev@vger.kernel.org Cc: Chris Leech Subject: [PATCH 02/11] iscsi: associate endpoints with a host Date: Sat, 6 May 2023 16:29:21 -0700 Message-Id: <20230506232930.195451-3-cleech@redhat.com> In-Reply-To: <20230506232930.195451-1-cleech@redhat.com> References: <20230506232930.195451-1-cleech@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Right 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. Signed-off-by: Lee Duncan Signed-off-by: Chris Leech --- 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(-) diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c index bb9aaff92ca3..e1085b5fdbb3 100644 --- a/drivers/infiniband/ulp/iser/iscsi_iser.c +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c @@ -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); diff --git a/drivers/scsi/be2iscsi/be_iscsi.c b/drivers/scsi/be2iscsi/be_iscsi.c index 8aeaddc93b16..c893d193f5ef 100644 --- a/drivers/scsi/be2iscsi/be_iscsi.c +++ b/drivers/scsi/be2iscsi/be_iscsi.c @@ -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); diff --git a/drivers/scsi/bnx2i/bnx2i_iscsi.c b/drivers/scsi/bnx2i/bnx2i_iscsi.c index 9971f32a663c..169a790950dd 100644 --- a/drivers/scsi/bnx2i/bnx2i_iscsi.c +++ b/drivers/scsi/bnx2i/bnx2i_iscsi.c @@ -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; diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c index abde60a50cf7..3620f4f04771 100644 --- a/drivers/scsi/cxgbi/libcxgbi.c +++ b/drivers/scsi/cxgbi/libcxgbi.c @@ -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"); diff --git a/drivers/scsi/qedi/qedi_iscsi.c b/drivers/scsi/qedi/qedi_iscsi.c index 6ed8ef97642c..08e2ebf6a06a 100644 --- a/drivers/scsi/qedi/qedi_iscsi.c +++ b/drivers/scsi/qedi/qedi_iscsi.c @@ -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; diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index 7001d50a674c..b8e452009cf4 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -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); diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index be69cea9c6f8..2f9348178450 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -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) diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h index 34c03707fb6e..8ade6a03f85a 100644 --- a/include/scsi/scsi_transport_iscsi.h +++ b/include/scsi/scsi_transport_iscsi.h @@ -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); From patchwork Sat May 6 23:29:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 679701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AAC0FC77B75 for ; Sat, 6 May 2023 23:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229845AbjEFXat (ORCPT ); Sat, 6 May 2023 19:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229472AbjEFXar (ORCPT ); Sat, 6 May 2023 19:30:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A018D86BE for ; Sat, 6 May 2023 16:30:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683415800; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hOHSraviY9mZliuyISn1d0pP58ToTj0Cf77c0+s6vA8=; b=BWulIqFOo91IkUv7sXLo7G95vdNPHsxnYhFxLAwoIbIDV+MoOBL+55nFSMioSUV6TwGWxF TMvRvfvYK+A8Fqj5G0BBjC1bJ/t4OS40Kax7ZEB2Bhcxy01nVhfF/cEXkIPljotSmW9XCM twnItvx9qTpiZ/z0vOFjoZRDILZYYNE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-149-FTF0SyUxO3OMLl5eyfJ9lg-1; Sat, 06 May 2023 19:29:55 -0400 X-MC-Unique: FTF0SyUxO3OMLl5eyfJ9lg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 632D4811E7C; Sat, 6 May 2023 23:29:55 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.2.16.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0C5F35443; Sat, 6 May 2023 23:29:54 +0000 (UTC) From: Chris Leech To: Lee Duncan , linux-scsi@vger.kernel.org, open-iscsi@googlegroups.com, netdev@vger.kernel.org Cc: Chris Leech Subject: [PATCH 03/11] iscsi: sysfs filtering by network namespace Date: Sat, 6 May 2023 16:29:22 -0700 Message-Id: <20230506232930.195451-4-cleech@redhat.com> In-Reply-To: <20230506232930.195451-1-cleech@redhat.com> References: <20230506232930.195451-1-cleech@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org 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: Lee Duncan Reviewed-by: Hannes Reinecke Signed-off-by: Chris Leech --- drivers/scsi/scsi_transport_iscsi.c | 127 ++++++++++++++++++++++++---- include/scsi/scsi_transport_iscsi.h | 1 + 2 files changed, 113 insertions(+), 15 deletions(-) diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 2f9348178450..814aef6da4a3 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -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; diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h index 8ade6a03f85a..d795e65a1f75 100644 --- a/include/scsi/scsi_transport_iscsi.h +++ b/include/scsi/scsi_transport_iscsi.h @@ -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) \ From patchwork Sat May 6 23:29:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 679700 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D660DC77B73 for ; Sat, 6 May 2023 23:31:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229837AbjEFXb2 (ORCPT ); Sat, 6 May 2023 19:31:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229658AbjEFXb0 (ORCPT ); Sat, 6 May 2023 19:31:26 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BB279ED8 for ; Sat, 6 May 2023 16:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683415803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+1cVNseZS6i/Rnc9e2Ivy422uws3w9zosipOwCiaRjY=; b=ZEnwEL1v6paD2dpjiJ7XDsRbKLSfbJojLBGST40J4Ut8CTrku8UqeRIidWKceuCCme2zxm YuvX3ODf0sKe+stph4nDl8I5PEPbleQYzNarcIG5Cjw8FyE4n5HFcQjArCUKFu/RyaG2V9 iks/2eFtKqnMglOcCAJ0VgxNH8LToB4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-260-j-USAqdmNsWrKDRjIGrhJg-1; Sat, 06 May 2023 19:29:58 -0400 X-MC-Unique: j-USAqdmNsWrKDRjIGrhJg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9430C29ABA00; Sat, 6 May 2023 23:29:57 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.2.16.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DB9D35443; Sat, 6 May 2023 23:29:56 +0000 (UTC) From: Chris Leech To: Lee Duncan , linux-scsi@vger.kernel.org, open-iscsi@googlegroups.com, netdev@vger.kernel.org Cc: Chris Leech Subject: [PATCH 06/11] iscsi: set netns for tcp and iser hosts Date: Sat, 6 May 2023 16:29:25 -0700 Message-Id: <20230506232930.195451-7-cleech@redhat.com> In-Reply-To: <20230506232930.195451-1-cleech@redhat.com> References: <20230506232930.195451-1-cleech@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org This 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. Signed-off-by: Chris Leech --- 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(-) diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c index 67b93581034c..077bf9eea19f 100644 --- a/drivers/infiniband/ulp/iser/iscsi_iser.c +++ b/drivers/infiniband/ulp/iser/iscsi_iser.c @@ -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) diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c index 9637d4bc2bc9..c401efac0149 100644 --- a/drivers/scsi/iscsi_tcp.c +++ b/drivers/scsi/iscsi_tcp.c @@ -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) diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index 0fda8905eabd..9d06beefbdf8 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -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"); diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 9db1db669c22..d8b05f3361c8 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -191,6 +191,8 @@ 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 (ep->netns) + return ep->netns; if (!shost) return &init_net; ihost = shost->shost_data; @@ -229,7 +231,7 @@ static struct attribute_group iscsi_endpoint_group = { }; struct iscsi_endpoint * -iscsi_create_endpoint(struct Scsi_Host *shost, int dd_size) +__iscsi_create_endpoint(struct Scsi_Host *shost, int dd_size, struct net *net) { struct iscsi_endpoint *ep; int err, id; @@ -257,6 +259,8 @@ iscsi_create_endpoint(struct Scsi_Host *shost, int dd_size) ep->dev.class = &iscsi_endpoint_class; if (shost) ep->dev.parent = &shost->shost_gendev; + if (net) + ep->netns = net; dev_set_name(&ep->dev, "ep-%d", id); err = device_register(&ep->dev); if (err) @@ -284,8 +288,21 @@ iscsi_create_endpoint(struct Scsi_Host *shost, int dd_size) kfree(ep); return NULL; } + +struct iscsi_endpoint * +iscsi_create_endpoint(struct Scsi_Host *shost, int dd_size) +{ + return __iscsi_create_endpoint(shost, dd_size, NULL); +} EXPORT_SYMBOL_GPL(iscsi_create_endpoint); +struct iscsi_endpoint * +iscsi_create_endpoint_net(struct net *net, int dd_size) +{ + return __iscsi_create_endpoint(NULL, dd_size, net); +} +EXPORT_SYMBOL_GPL(iscsi_create_endpoint_net); + void iscsi_destroy_endpoint(struct iscsi_endpoint *ep) { sysfs_remove_group(&ep->dev.kobj, &iscsi_endpoint_group); @@ -1608,10 +1625,15 @@ static int iscsi_setup_host(struct transport_container *tc, struct device *dev, { struct Scsi_Host *shost = dev_to_shost(dev); struct iscsi_cls_host *ihost = shost->shost_data; + struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); + struct iscsi_transport *transport = priv->iscsi_transport; memset(ihost, 0, sizeof(*ihost)); mutex_init(&ihost->mutex); - ihost->netns = &init_net; + if (transport->get_netns) + ihost->netns = transport->get_netns(shost); + else + ihost->netns = &init_net; iscsi_bsg_host_add(shost, ihost); /* ignore any bsg add error - we just can't do sgio */ @@ -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; - 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); + } + if (!session) return -ENOMEM; @@ -3231,10 +3260,10 @@ static int iscsi_if_ep_connect(struct net *net, struct Scsi_Host *shost = NULL; int non_blocking, err = 0; - if (!transport->ep_connect) - return -EINVAL; - if (msg_type == ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST) { + if (!transport->ep_connect) + return -EINVAL; + shost = iscsi_host_lookup(net, ev->u.ep_connect_through_host.host_no); if (!shost) { @@ -3244,11 +3273,17 @@ static int iscsi_if_ep_connect(struct net *net, return -ENODEV; } non_blocking = ev->u.ep_connect_through_host.non_blocking; - } else + dst_addr = (struct sockaddr *)((char *)ev + sizeof(*ev)); + ep = transport->ep_connect(shost, dst_addr, non_blocking); + } else { + if (!transport->ep_connect_net) + return -EINVAL; + non_blocking = ev->u.ep_connect.non_blocking; + dst_addr = (struct sockaddr *)((char *)ev + sizeof(*ev)); + ep = transport->ep_connect_net(net, dst_addr, non_blocking); + } - dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev)); - ep = transport->ep_connect(shost, dst_addr, non_blocking); if (IS_ERR(ep)) { err = PTR_ERR(ep); goto release_host; @@ -4028,7 +4063,8 @@ static int iscsi_if_transport_conn(struct net *net, if (!ev->r.retcode) WRITE_ONCE(conn->state, ISCSI_CONN_BOUND); - if (ev->r.retcode || !transport->ep_connect) + if (ev->r.retcode || (!transport->ep_connect && + !transport->ep_connect_net)) break; ep = iscsi_lookup_endpoint(net, ev->u.b_conn.transport_eph); @@ -4106,7 +4142,7 @@ iscsi_if_recv_msg(struct net *net, struct sk_buff *skb, portid, ev->u.c_session.initial_cmdsn, ev->u.c_session.cmds_max, - ev->u.c_session.queue_depth); + ev->u.c_session.queue_depth, net); break; /* MARK */ case ISCSI_UEVENT_CREATE_BOUND_SESSION: @@ -4121,7 +4157,7 @@ iscsi_if_recv_msg(struct net *net, struct sk_buff *skb, portid, ev->u.c_bound_session.initial_cmdsn, ev->u.c_bound_session.cmds_max, - ev->u.c_bound_session.queue_depth); + ev->u.c_bound_session.queue_depth, net); iscsi_put_endpoint(ep); break; case ISCSI_UEVENT_DESTROY_SESSION: @@ -4388,7 +4424,7 @@ static ssize_t show_conn_ep_param_##param(struct device *dev, \ */ \ mutex_lock(&conn->ep_mutex); \ ep = conn->ep; \ - if (!ep && t->ep_connect) { \ + if (!ep && (t->ep_connect || t->ep_connect_net)) { \ mutex_unlock(&conn->ep_mutex); \ return -ENOTCONN; \ } \ diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h index 7282555adfd5..e7d1e6bf3a6d 100644 --- a/include/scsi/libiscsi.h +++ b/include/scsi/libiscsi.h @@ -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. */ diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h index 5e667c85a469..83bcdd2bcde4 100644 --- a/include/scsi/scsi_transport_iscsi.h +++ b/include/scsi/scsi_transport_iscsi.h @@ -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); From patchwork Sat May 6 23:29:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 679699 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E8FEC7EE22 for ; Sat, 6 May 2023 23:31:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229460AbjEFXbb (ORCPT ); Sat, 6 May 2023 19:31:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229778AbjEFXb1 (ORCPT ); Sat, 6 May 2023 19:31:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1C4D8A55 for ; Sat, 6 May 2023 16:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683415801; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=V+nHcWBThg87r9MWxGBVMEs5l/DzTXNHp2qWU+92EFI=; b=avenX7z6Re1kaYs+WTHVEKK8CQw2afIzStkhsoJE2lUlQL+5Yyx0sReJuTLrRGCUTAOUDe tGc6uP39TaPoOns7pY4u4Kfr5Yi8CV5MgiUB+fsDozXaeNsueEPlvTbghwqhH7pVL3s9ZH zBbfWXZXAsKh/mjPmJ1FgScOpXk9m50= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-636-kFcNSu0DPOi7v81CHisY-A-1; Sat, 06 May 2023 19:29:58 -0400 X-MC-Unique: kFcNSu0DPOi7v81CHisY-A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4CDDE101A55C; Sat, 6 May 2023 23:29:58 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.2.16.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8A7535443; Sat, 6 May 2023 23:29:57 +0000 (UTC) From: Chris Leech To: Lee Duncan , linux-scsi@vger.kernel.org, open-iscsi@googlegroups.com, netdev@vger.kernel.org Cc: Chris Leech Subject: [PATCH 07/11] iscsi: convert flashnode devices from bus to class Date: Sat, 6 May 2023 16:29:26 -0700 Message-Id: <20230506232930.195451-8-cleech@redhat.com> In-Reply-To: <20230506232930.195451-1-cleech@redhat.com> References: <20230506232930.195451-1-cleech@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Lee Duncan 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. Signed-off-by: Lee Duncan Reviewed-by: Hannes Reinecke Signed-off-by: Chris Leech --- 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(-) diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index 55fe6aca93d0..bc06020565e4 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -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); diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index d8b05f3361c8..2fae14aa291e 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -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); diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h index 83bcdd2bcde4..f9d003753f11 100644 --- a/include/scsi/scsi_transport_iscsi.h +++ b/include/scsi/scsi_transport_iscsi.h @@ -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); From patchwork Sat May 6 23:29:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 679697 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A55A8C77B73 for ; Sat, 6 May 2023 23:31:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230049AbjEFXbj (ORCPT ); Sat, 6 May 2023 19:31:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230034AbjEFXbh (ORCPT ); Sat, 6 May 2023 19:31:37 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 33481A5CC for ; Sat, 6 May 2023 16:30:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683415803; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vDpom2RztN/03ErGZSbI4RmJgyW3xZZd2IBq9VSMG1g=; b=CPKRS3qdCPuKlZ3/sQRZlDOgQKHCTTmjHQtPVwP/XTF2P1lBil2/qHk6b4eBPqVxmWxRY0 80uI6rHp9sIM8KAXaWfwO2ekvDAh6uybiLNXys9AE4KpLdM5jTmXaGKbe4WWyss2t/68Kf j865EwfWOsisCbIfriK5derUYugNB7M= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-203-KjmGpJ7KO0S6tdkt50H7SA-1; Sat, 06 May 2023 19:29:59 -0400 X-MC-Unique: KjmGpJ7KO0S6tdkt50H7SA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 054E8101A531; Sat, 6 May 2023 23:29:59 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.2.16.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 71A3635443; Sat, 6 May 2023 23:29:58 +0000 (UTC) From: Chris Leech To: Lee Duncan , linux-scsi@vger.kernel.org, open-iscsi@googlegroups.com, netdev@vger.kernel.org Cc: Chris Leech Subject: [PATCH 08/11] iscsi: rename iscsi_bus_flash_* to iscsi_flash_* Date: Sat, 6 May 2023 16:29:27 -0700 Message-Id: <20230506232930.195451-9-cleech@redhat.com> In-Reply-To: <20230506232930.195451-1-cleech@redhat.com> References: <20230506232930.195451-1-cleech@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Lee Duncan These are cleanups after the bus to class conversion for flashnode devices. Signed-off-by: Lee Duncan Reviewed-by: Hannes Reinecke Signed-off-by: Chris Leech --- 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(-) diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c index bc06020565e4..bf5e2b3ce8ce 100644 --- a/drivers/scsi/qla4xxx/ql4_os.c +++ b/drivers/scsi/qla4xxx/ql4_os.c @@ -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); diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 2fae14aa291e..26b3d479b6ac 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -875,7 +875,7 @@ static ssize_t \ show_##type##_##name(struct device *dev, struct device_attribute *attr, \ char *buf) \ { \ - struct iscsi_bus_flash_session *fnode_sess = \ + struct iscsi_flash_session *fnode_sess = \ iscsi_dev_to_flash_session(dev);\ struct iscsi_transport *t = fnode_sess->transport; \ return t->get_flashnode_param(fnode_sess, param, buf); \ @@ -975,7 +975,7 @@ static umode_t iscsi_flashnode_sess_attr_is_visible(struct kobject *kobj, int i) { struct device *dev = container_of(kobj, struct device, kobj); - struct iscsi_bus_flash_session *fnode_sess = + struct iscsi_flash_session *fnode_sess = iscsi_dev_to_flash_session(dev); struct iscsi_transport *t = fnode_sess->transport; int param; @@ -1066,7 +1066,7 @@ static const struct attribute_group *iscsi_flashnode_sess_attr_groups[] = { static void iscsi_flashnode_sess_release(struct device *dev) { - struct iscsi_bus_flash_session *fnode_sess = + struct iscsi_flash_session *fnode_sess = iscsi_dev_to_flash_session(dev); kfree(fnode_sess->targetname); @@ -1076,7 +1076,7 @@ static void iscsi_flashnode_sess_release(struct device *dev) } static const struct device_type iscsi_flashnode_sess_dev_type = { - .name = "iscsi_flashnode_sess_dev_type", + .name = "iscsi_flashnode_sess", .groups = iscsi_flashnode_sess_attr_groups, .release = iscsi_flashnode_sess_release, }; @@ -1093,8 +1093,8 @@ static ssize_t \ show_##type##_##name(struct device *dev, struct device_attribute *attr, \ char *buf) \ { \ - struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);\ - struct iscsi_bus_flash_session *fnode_sess = \ + struct iscsi_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev);\ + struct iscsi_flash_session *fnode_sess = \ iscsi_flash_conn_to_flash_session(fnode_conn);\ struct iscsi_transport *t = fnode_conn->transport; \ return t->get_flashnode_param(fnode_sess, param, buf); \ @@ -1183,7 +1183,7 @@ static umode_t iscsi_flashnode_conn_attr_is_visible(struct kobject *kobj, int i) { struct device *dev = container_of(kobj, struct device, kobj); - struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev); + struct iscsi_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev); struct iscsi_transport *t = fnode_conn->transport; int param; @@ -1259,7 +1259,7 @@ static const struct attribute_group *iscsi_flashnode_conn_attr_groups[] = { static void iscsi_flashnode_conn_release(struct device *dev) { - struct iscsi_bus_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev); + struct iscsi_flash_conn *fnode_conn = iscsi_dev_to_flash_conn(dev); kfree(fnode_conn->ipaddress); kfree(fnode_conn->redirect_ipaddr); @@ -1268,12 +1268,28 @@ static void iscsi_flashnode_conn_release(struct device *dev) } static const struct device_type iscsi_flashnode_conn_dev_type = { - .name = "iscsi_flashnode_conn_dev_type", + .name = "iscsi_flashnode_conn", .groups = iscsi_flashnode_conn_attr_groups, .release = iscsi_flashnode_conn_release, }; -static struct class iscsi_flashnode_bus = { +/** + * iscsi_is_flashnode_conn_dev - verify passed device is to be flashnode conn + * @dev: device to verify + * @data: pointer to data containing value to use for verification + * + * Verifies if the passed device is flashnode conn device + * + * Returns: + * 1 on success + * 0 on failure + */ +static int iscsi_is_flashnode_conn_dev(struct device *dev, void *data) +{ + return dev->type == &iscsi_flashnode_conn_dev_type; +} + +static struct class iscsi_flashnode = { .name = "iscsi_flashnode", }; @@ -1290,12 +1306,12 @@ static struct class iscsi_flashnode_bus = { * pointer to allocated flashnode sess on success * %NULL on failure */ -struct iscsi_bus_flash_session * +struct iscsi_flash_session * iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index, struct iscsi_transport *transport, int dd_size) { - struct iscsi_bus_flash_session *fnode_sess; + struct iscsi_flash_session *fnode_sess; int err; fnode_sess = kzalloc(sizeof(*fnode_sess) + dd_size, GFP_KERNEL); @@ -1305,7 +1321,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.class = &iscsi_flashnode_bus; + fnode_sess->dev.class = &iscsi_flashnode; fnode_sess->dev.parent = &shost->shost_gendev; dev_set_name(&fnode_sess->dev, "flashnode_sess-%u:%u", shost->host_no, index); @@ -1338,13 +1354,13 @@ EXPORT_SYMBOL_GPL(iscsi_create_flashnode_sess); * pointer to allocated flashnode conn on success * %NULL on failure */ -struct iscsi_bus_flash_conn * +struct iscsi_flash_conn * iscsi_create_flashnode_conn(struct Scsi_Host *shost, - struct iscsi_bus_flash_session *fnode_sess, + struct iscsi_flash_session *fnode_sess, struct iscsi_transport *transport, int dd_size) { - struct iscsi_bus_flash_conn *fnode_conn; + struct iscsi_flash_conn *fnode_conn; int err; fnode_conn = kzalloc(sizeof(*fnode_conn) + dd_size, GFP_KERNEL); @@ -1353,7 +1369,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.class = &iscsi_flashnode_bus; + fnode_conn->dev.class = &iscsi_flashnode; 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); @@ -1373,23 +1389,7 @@ iscsi_create_flashnode_conn(struct Scsi_Host *shost, } EXPORT_SYMBOL_GPL(iscsi_create_flashnode_conn); -/** - * iscsi_is_flashnode_conn_dev - verify passed device is to be flashnode conn - * @dev: device to verify - * @data: pointer to data containing value to use for verification - * - * Verifies if the passed device is flashnode conn device - * - * Returns: - * 1 on success - * 0 on failure - */ -static int iscsi_is_flashnode_conn_dev(struct device *dev, void *data) -{ - return dev->type == &iscsi_flashnode_conn_dev_type; -} - -static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn *fnode_conn) +static int iscsi_destroy_flashnode_conn(struct iscsi_flash_conn *fnode_conn) { device_unregister(&fnode_conn->dev); return 0; @@ -1397,10 +1397,10 @@ static int iscsi_destroy_flashnode_conn(struct iscsi_bus_flash_conn *fnode_conn) static int flashnode_match_index(struct device *dev, void *data) { - struct iscsi_bus_flash_session *fnode_sess = NULL; + struct iscsi_flash_session *fnode_sess = NULL; int ret = 0; - if (dev->type != &iscsi_flashnode_sess_dev_type) + if (!iscsi_is_flashnode_session_dev(dev)) goto exit_match_index; fnode_sess = iscsi_dev_to_flash_session(dev); @@ -1421,10 +1421,10 @@ static int flashnode_match_index(struct device *dev, void *data) * pointer to found flashnode session object on success * %NULL on failure */ -static struct iscsi_bus_flash_session * +static struct iscsi_flash_session * iscsi_get_flashnode_by_index(struct Scsi_Host *shost, uint32_t idx) { - struct iscsi_bus_flash_session *fnode_sess = NULL; + struct iscsi_flash_session *fnode_sess = NULL; struct device *dev; dev = device_find_child(&shost->shost_gendev, &idx, @@ -1468,7 +1468,7 @@ EXPORT_SYMBOL_GPL(iscsi_find_flashnode_sess); * %NULL on failure */ struct device * -iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess) +iscsi_find_flashnode_conn(struct iscsi_flash_session *fnode_sess) { return device_find_child(&fnode_sess->dev, NULL, iscsi_is_flashnode_conn_dev); @@ -1490,7 +1490,7 @@ static int iscsi_iter_destroy_flashnode_conn_fn(struct device *dev, void *data) * Deletes the flashnode session entry and all children flashnode connection * entries from sysfs */ -void iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess) +void iscsi_destroy_flashnode_sess(struct iscsi_flash_session *fnode_sess) { int err; @@ -1506,7 +1506,7 @@ EXPORT_SYMBOL_GPL(iscsi_destroy_flashnode_sess); static int iscsi_iter_destroy_flashnode_fn(struct device *dev, void *data) { - if (dev->type != &iscsi_flashnode_sess_dev_type) + if (!iscsi_is_flashnode_session_dev(dev)) return 0; iscsi_destroy_flashnode_sess(iscsi_dev_to_flash_session(dev)); @@ -3644,8 +3644,8 @@ static int iscsi_set_flashnode_param(struct net *net, { char *data = (char *)ev + sizeof(*ev); struct Scsi_Host *shost; - struct iscsi_bus_flash_session *fnode_sess; - struct iscsi_bus_flash_conn *fnode_conn; + struct iscsi_flash_session *fnode_sess; + struct iscsi_flash_conn *fnode_conn; struct device *dev; uint32_t idx; int err = 0; @@ -3733,7 +3733,7 @@ static int iscsi_del_flashnode(struct net *net, struct iscsi_uevent *ev) { struct Scsi_Host *shost; - struct iscsi_bus_flash_session *fnode_sess; + struct iscsi_flash_session *fnode_sess; uint32_t idx; int err = 0; @@ -3774,8 +3774,8 @@ static int iscsi_login_flashnode(struct net *net, struct iscsi_uevent *ev) { struct Scsi_Host *shost; - struct iscsi_bus_flash_session *fnode_sess; - struct iscsi_bus_flash_conn *fnode_conn; + struct iscsi_flash_session *fnode_sess; + struct iscsi_flash_conn *fnode_conn; struct device *dev; uint32_t idx; int err = 0; @@ -3827,8 +3827,8 @@ static int iscsi_logout_flashnode(struct net *net, struct iscsi_uevent *ev) { struct Scsi_Host *shost; - struct iscsi_bus_flash_session *fnode_sess; - struct iscsi_bus_flash_conn *fnode_conn; + struct iscsi_flash_session *fnode_sess; + struct iscsi_flash_conn *fnode_conn; struct device *dev; uint32_t idx; int err = 0; @@ -5229,7 +5229,7 @@ static __init int iscsi_transport_init(void) if (err) goto unregister_conn_class; - err = class_register(&iscsi_flashnode_bus); + err = class_register(&iscsi_flashnode); if (err) goto unregister_session_class; @@ -5252,7 +5252,7 @@ static __init int iscsi_transport_init(void) unregister_pernet_subsys: unregister_pernet_subsys(&iscsi_net_ops); unregister_flashnode_bus: - class_unregister(&iscsi_flashnode_bus); + class_unregister(&iscsi_flashnode); unregister_session_class: transport_class_unregister(&iscsi_session_class); unregister_conn_class: @@ -5272,7 +5272,7 @@ static void __exit iscsi_transport_exit(void) { destroy_workqueue(iscsi_conn_cleanup_workq); unregister_pernet_subsys(&iscsi_net_ops); - class_unregister(&iscsi_flashnode_bus); + class_unregister(&iscsi_flashnode); transport_class_unregister(&iscsi_connection_class); transport_class_unregister(&iscsi_session_class); transport_class_unregister(&iscsi_host_class); diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h index f9d003753f11..a23b511b6f53 100644 --- a/include/scsi/scsi_transport_iscsi.h +++ b/include/scsi/scsi_transport_iscsi.h @@ -26,8 +26,8 @@ struct iscsi_task; struct sockaddr; struct iscsi_iface; struct bsg_job; -struct iscsi_bus_flash_session; -struct iscsi_bus_flash_conn; +struct iscsi_flash_session; +struct iscsi_flash_conn; /** * struct iscsi_transport - iSCSI Transport template @@ -149,18 +149,18 @@ struct iscsi_transport { uint32_t *num_entries, char *buf); int (*delete_chap) (struct Scsi_Host *shost, uint16_t chap_tbl_idx); int (*set_chap) (struct Scsi_Host *shost, void *data, int len); - int (*get_flashnode_param) (struct iscsi_bus_flash_session *fnode_sess, - int param, char *buf); - int (*set_flashnode_param) (struct iscsi_bus_flash_session *fnode_sess, - struct iscsi_bus_flash_conn *fnode_conn, - void *data, int len); - int (*new_flashnode) (struct Scsi_Host *shost, const char *buf, - int len); - int (*del_flashnode) (struct iscsi_bus_flash_session *fnode_sess); - int (*login_flashnode) (struct iscsi_bus_flash_session *fnode_sess, - struct iscsi_bus_flash_conn *fnode_conn); - int (*logout_flashnode) (struct iscsi_bus_flash_session *fnode_sess, - struct iscsi_bus_flash_conn *fnode_conn); + int (*get_flashnode_param)(struct iscsi_flash_session *fnode_sess, + int param, char *buf); + int (*set_flashnode_param)(struct iscsi_flash_session *fnode_sess, + struct iscsi_flash_conn *fnode_conn, + void *data, int len); + int (*new_flashnode)(struct Scsi_Host *shost, const char *buf, + int len); + int (*del_flashnode)(struct iscsi_flash_session *fnode_sess); + int (*login_flashnode)(struct iscsi_flash_session *fnode_sess, + struct iscsi_flash_conn *fnode_conn); + int (*logout_flashnode)(struct iscsi_flash_session *fnode_sess, + struct iscsi_flash_conn *fnode_conn); 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); @@ -342,7 +342,7 @@ struct iscsi_iface { dev_to_shost(_iface->dev.parent) -struct iscsi_bus_flash_conn { +struct iscsi_flash_conn { struct list_head conn_list; /* item in connlist */ void *dd_data; /* LLD private data */ struct iscsi_transport *transport; @@ -380,14 +380,14 @@ struct iscsi_bus_flash_conn { }; #define iscsi_dev_to_flash_conn(_dev) \ - container_of(_dev, struct iscsi_bus_flash_conn, dev) + container_of(_dev, struct iscsi_flash_conn, dev) #define iscsi_flash_conn_to_flash_session(_conn) \ iscsi_dev_to_flash_session(_conn->dev.parent) #define ISID_SIZE 6 -struct iscsi_bus_flash_session { +struct iscsi_flash_session { struct list_head sess_list; /* item in session_list */ struct iscsi_transport *transport; unsigned int target_id; @@ -442,7 +442,7 @@ struct iscsi_bus_flash_session { }; #define iscsi_dev_to_flash_session(_dev) \ - container_of(_dev, struct iscsi_bus_flash_session, dev) + container_of(_dev, struct iscsi_flash_session, dev) #define iscsi_flash_session_to_shost(_session) \ dev_to_shost(_session->dev.parent) @@ -503,17 +503,17 @@ extern struct device * iscsi_find_flashnode(struct Scsi_Host *shost, void *data, int (*fn)(struct device *dev, void *data)); -extern struct iscsi_bus_flash_session * +extern struct iscsi_flash_session * iscsi_create_flashnode_sess(struct Scsi_Host *shost, int index, struct iscsi_transport *transport, int dd_size); -extern struct iscsi_bus_flash_conn * +extern struct iscsi_flash_conn * iscsi_create_flashnode_conn(struct Scsi_Host *shost, - struct iscsi_bus_flash_session *fnode_sess, + struct iscsi_flash_session *fnode_sess, struct iscsi_transport *transport, int dd_size); extern void -iscsi_destroy_flashnode_sess(struct iscsi_bus_flash_session *fnode_sess); +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, @@ -522,7 +522,9 @@ extern struct device * iscsi_find_flashnode_sess(struct Scsi_Host *shost, void *data, int (*fn)(struct device *dev, void *data)); extern struct device * -iscsi_find_flashnode_conn(struct iscsi_bus_flash_session *fnode_sess); +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); From patchwork Sat May 6 23:29:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Leech X-Patchwork-Id: 679698 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECB05C77B73 for ; Sat, 6 May 2023 23:31:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229780AbjEFXbg (ORCPT ); Sat, 6 May 2023 19:31:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjEFXbe (ORCPT ); Sat, 6 May 2023 19:31:34 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6138811540 for ; Sat, 6 May 2023 16:30:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683415804; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hqhmg8Av0eHkGffW04hqyQM86CV5Jf1/OdaPhsIJszw=; b=Pri8hs7aUqSKeThoyWtJYgZ3FyIh3ty97vPwvBRNvsvdDNPHyn/QeV/siokDOQZYj8YM1W tbf+YiCUKDdM22QaLoUY5FV10lZKPtYKpGiscbuXDxEwVH1xXNvGaOqIRMz2Omf7v4I30t 81ilZaN1K3fM+LjSVAJ98pXOoeIu7rY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-372-Sw4aRg4WPYKqbogOMpK5Nw-1; Sat, 06 May 2023 19:30:00 -0400 X-MC-Unique: Sw4aRg4WPYKqbogOMpK5Nw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B0E9F857DD7; Sat, 6 May 2023 23:29:59 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.2.16.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 294E6440BC; Sat, 6 May 2023 23:29:59 +0000 (UTC) From: Chris Leech To: Lee Duncan , linux-scsi@vger.kernel.org, open-iscsi@googlegroups.com, netdev@vger.kernel.org Cc: Chris Leech Subject: [PATCH 09/11] iscsi: filter flashnode sysfs by net namespace Date: Sat, 6 May 2023 16:29:28 -0700 Message-Id: <20230506232930.195451-10-cleech@redhat.com> In-Reply-To: <20230506232930.195451-1-cleech@redhat.com> References: <20230506232930.195451-1-cleech@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Lee Duncan This finishes the net namespace support for flashnode sysfs devices. Signed-off-by: Lee Duncan Reviewed-by: Hannes Reinecke Signed-off-by: Chris Leech --- drivers/scsi/scsi_transport_iscsi.c | 34 +++++++++++++++++++++++++++++ include/scsi/scsi_transport_iscsi.h | 4 ---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c index 26b3d479b6ac..cd3228293a64 100644 --- a/drivers/scsi/scsi_transport_iscsi.c +++ b/drivers/scsi/scsi_transport_iscsi.c @@ -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, }; /** diff --git a/include/scsi/scsi_transport_iscsi.h b/include/scsi/scsi_transport_iscsi.h index a23b511b6f53..a540e085de8d 100644 --- a/include/scsi/scsi_transport_iscsi.h +++ b/include/scsi/scsi_transport_iscsi.h @@ -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);