From patchwork Wed Mar 30 06:39:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KY Srinivasan X-Patchwork-Id: 8692891 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6120DC0553 for ; Wed, 30 Mar 2016 06:39:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DEFEE201E4 for ; Wed, 30 Mar 2016 06:39:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F53A20166 for ; Wed, 30 Mar 2016 06:39:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753314AbcC3Gje (ORCPT ); Wed, 30 Mar 2016 02:39:34 -0400 Received: from mail-bn1bn0103.outbound.protection.outlook.com ([157.56.110.103]:40096 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752692AbcC3Gjc (ORCPT ); Wed, 30 Mar 2016 02:39:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=jnyfercKeHqEr0U1r5NHuDDktwMHRyXunaEM3BGO7hk=; b=II2wBpWBDRB6IEx23BlwMGC2NO0TpllmCckoURAeCtO86ESGkNt0DbnxG3OYYH9zDJIeXpM1nC+CZC4thlpgGS/3Hdlle3N9Sjq+QR1cu57daknmUyVDEBzRnvX2g7efvv7QKqVrvbeU47v6GM+J1pmPyVzKGWdcFKTH3KSzvto= Received: from CY1PR03MB2137.namprd03.prod.outlook.com (10.166.206.134) by CY1PR03MB2137.namprd03.prod.outlook.com (10.166.206.134) with Microsoft SMTP Server (TLS) id 15.1.447.15; Wed, 30 Mar 2016 06:39:27 +0000 Received: from CY1PR03MB2137.namprd03.prod.outlook.com ([10.166.206.134]) by CY1PR03MB2137.namprd03.prod.outlook.com ([10.166.206.134]) with mapi id 15.01.0447.024; Wed, 30 Mar 2016 06:39:27 +0000 From: KY Srinivasan To: James Bottomley , "Martin K. Petersen" CC: Christoph Hellwig , "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , "devel@linuxdriverproject.org" , "ohering@suse.com" , "jbottomley@parallels.com" , "linux-scsi@vger.kernel.org" , "apw@canonical.com" , "vkuznets@redhat.com" , "jasowang@redhat.com" , "hare@suse.de" Subject: RE: [PATCH 1/1] scsi: storvsc: Support manual scan of FC hosts on Hyper-V Thread-Topic: [PATCH 1/1] scsi: storvsc: Support manual scan of FC hosts on Hyper-V Thread-Index: AQHRfJwVxmC/c4dGFU6pOCq9n5PNBJ9ahymAgAAMrpCAAHVoVYAAAK9QgAGlwg6AAAhlAIAAAUtAgAAH9oCAAAHrsIADEgoAgBHO2BA= Date: Wed, 30 Mar 2016 06:39:27 +0000 Message-ID: References: <1457819568-6586-1-git-send-email-kys@microsoft.com> <20160315134009.GA3595@infradead.org> <1458169666.4793.62.camel@HansenPartnership.com> <1458171653.4793.68.camel@HansenPartnership.com> <1458340866.2892.7.camel@HansenPartnership.com> In-Reply-To: <1458340866.2892.7.camel@HansenPartnership.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: HansenPartnership.com; dkim=none (message not signed) header.d=none; HansenPartnership.com; dmarc=none action=none header.from=microsoft.com; x-originating-ip: [12.139.153.2] x-ms-office365-filtering-correlation-id: d7e06d68-cd4e-4cd5-a0e1-08d358660a9d x-microsoft-exchange-diagnostics: 1; CY1PR03MB2137; 5:KO8CbWO6b+T2kA9FrOwRpwHGgcWcLUzGto5pjuP2AaB/jlpc8oJfFpcIaXRbFhf1cusprE9Ciswn3e0U0rWq5iZBoijGIMBaGWCcSjg97wcQxFzQAuJ7HX1aWsmV00GSS87a/iEz2voHSI9lsJnzfg==; 24:tSWpiCNmiSA0qXvuFzI9zUcTe4OAX5L0ShqaxOHZub3jVFexL2E3hnCUNUBz6x8W/R4ngHtK8Asoqutr40QiNYBOztJKr0cr5XwTM3E59mU= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CY1PR03MB2137; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(61425038)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001)(61426038)(61427038); SRVR:CY1PR03MB2137; BCL:0; PCL:0; RULEID:; SRVR:CY1PR03MB2137; x-forefront-prvs: 08978A8F5C x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(6009001)(377454003)(377424004)(24454002)(13464003)(122556002)(74316001)(76576001)(5002640100001)(66066001)(5003600100002)(87936001)(93886004)(189998001)(5890100001)(586003)(81166005)(92566002)(5008740100001)(77096005)(5001770100001)(86362001)(3660700001)(3280700002)(19580405001)(4326007)(102836003)(54356999)(6116002)(3846002)(76176999)(50986999)(1220700001)(2906002)(1096002)(5004730100002)(99286002)(2900100001)(106116001)(5005710100001)(2950100001)(86612001)(10090500001)(33656002)(575784001)(8990500004)(11100500001)(10400500002)(10290500002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR03MB2137; H:CY1PR03MB2137.namprd03.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Mar 2016 06:39:27.5664 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB2137 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 > -----Original Message----- > From: James Bottomley [mailto:James.Bottomley@HansenPartnership.com] > Sent: Friday, March 18, 2016 3:41 PM > To: KY Srinivasan ; Martin K. Petersen > > Cc: Christoph Hellwig ; gregkh@linuxfoundation.org; > linux-kernel@vger.kernel.org; devel@linuxdriverproject.org; > ohering@suse.com; jbottomley@parallels.com; linux-scsi@vger.kernel.org; > apw@canonical.com; vkuznets@redhat.com; jasowang@redhat.com; > hare@suse.de > Subject: Re: [PATCH 1/1] scsi: storvsc: Support manual scan of FC hosts on > Hyper-V > > On Thu, 2016-03-17 at 00:01 +0000, KY Srinivasan wrote: > > The only attributes I would be interested are: > > 1) node name > > 2) port name > > > > Ideally, if this can show under /sys/class/fc_host/hostx/port_name > > and node_name, > > it will be ideal since all user scripts can work. > > OK, like this? > > From 7af7c428e7e04ddcc87fda12d6571e3dff8ae024 Mon Sep 17 00:00:00 > 2001 > From: James Bottomley > Date: Fri, 18 Mar 2016 15:35:45 -0700 > Subject: scsi_transport_fc: introduce lightweight class for virtualization > systems > > The FC transport class is very heavily tilted towards helping things > which operate a fabric (as it should be). However, there seems to be > a need for a lightweight version for use in virtual systems that > simply want to show pass through FC information without making any use > of the heavyweight functions. This is an attempt to give them what > they want: the lightweight class has no vports or rports and only two > host attributes. Essentially, it's designed for the HV storvsc > driver, but if other virtualizataion systems have similar problems, we > can add more attributes. > > Signed-off-by: James Bottomley > --- > drivers/scsi/scsi_transport_fc.c | 94 > ++++++++++++++++++++++++++++++++++++++++ > include/scsi/scsi_transport_fc.h | 3 ++ > 2 files changed, 97 insertions(+) > > diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c > index 8a88226..a9fcb4d 100644 > --- a/drivers/scsi/scsi_transport_fc.c > +++ b/drivers/scsi/scsi_transport_fc.c > @@ -351,6 +351,27 @@ struct fc_internal { > > #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t) > > +#define FC_LW_HOST_NUM_ATTRS 2 > +struct fc_lw_internal { > + struct scsi_transport_template t; > + struct fc_function_template *f; > + > + /* > + * For attributes : each object has : > + * An array of the actual attributes structures > + * An array of null-terminated pointers to the attribute > + * structures - used for mid-layer interaction. > + * > + * The attribute containers for the starget and host are are > + * part of the midlayer. As the remote port is specific to the > + * fc transport, we must provide the attribute container. > + */ > + struct device_attribute > private_host_attrs[FC_LW_HOST_NUM_ATTRS]; > + struct device_attribute *host_attrs[FC_LW_HOST_NUM_ATTRS + 1]; > +}; > + > +#define to_fc_lw_internal(tmpl) container_of(tmpl, struct > fc_lw_internal, t) > + > static int fc_target_setup(struct transport_container *tc, struct device *dev, > struct device *cdev) > { > @@ -472,6 +493,12 @@ static int fc_host_remove(struct transport_container > *tc, struct device *dev, > return 0; > } > > +static DECLARE_TRANSPORT_CLASS(fc_lw_host_class, > + "fc_host", > + NULL, > + NULL, > + NULL); > + > static DECLARE_TRANSPORT_CLASS(fc_host_class, > "fc_host", > fc_host_setup, > @@ -1968,6 +1995,25 @@ static int fc_host_match(struct > attribute_container *cont, > return &i->t.host_attrs.ac == cont; > } > > +static int fc_lw_host_match(struct attribute_container *cont, > + struct device *dev) > +{ > + struct Scsi_Host *shost; > + struct fc_lw_internal *i; > + > + if (!scsi_is_host_device(dev)) > + return 0; > + > + shost = dev_to_shost(dev); > + if (!shost->transportt || shost->transportt->host_attrs.ac.class > + != &fc_lw_host_class.class) > + return 0; > + > + i = to_fc_lw_internal(shost->transportt); > + > + return &i->t.host_attrs.ac == cont; > +} > + > static int fc_target_match(struct attribute_container *cont, > struct device *dev) > { > @@ -2171,6 +2217,54 @@ static int fc_it_nexus_response(struct Scsi_Host > *shost, u64 nexus, int result) > return i->f->it_nexus_response(shost, nexus, result); > } > > +/** > + * fc_attach_lw_transport - light weight attach function > + * @ft: function template for optional attributes > + * > + * This attach function is to be used only for virtual FC emulators > + * which do not have a physical fabric underneath them and thus only > + * need a few attributes and no helper functions > + */ > +struct scsi_transport_template * > +fc_lw_attach_transport(struct fc_function_template *ft) > +{ > + int count; > + struct fc_lw_internal *i = kzalloc(sizeof(struct fc_lw_internal), > + GFP_KERNEL); > + > + if (unlikely(!i)) > + return NULL; > + > + i->t.host_attrs.ac.attrs = &i->host_attrs[0]; > + i->t.host_attrs.ac.class = &fc_lw_host_class.class; > + i->t.host_attrs.ac.match = fc_lw_host_match; > + i->t.host_size = sizeof(struct fc_host_attrs); > + transport_container_register(&i->t.host_attrs); > + > + i->f = ft; > + > + count = 0; > + SETUP_HOST_ATTRIBUTE_RD(node_name); > + SETUP_HOST_ATTRIBUTE_RD(port_name); > + > + BUG_ON(count > FC_HOST_NUM_ATTRS); > + > + i->host_attrs[count] = NULL; > + > + return &i->t; > +} > +EXPORT_SYMBOL(fc_lw_attach_transport); > + > +void fc_lw_release_transport(struct scsi_transport_template *t) > +{ > + struct fc_lw_internal *i = to_fc_lw_internal(t); > + > + transport_container_unregister(&i->t.host_attrs); > + > + kfree(i); > +} > +EXPORT_SYMBOL(fc_lw_release_transport); > + > struct scsi_transport_template * > fc_attach_transport(struct fc_function_template *ft) > { > diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h > index 784bc2c..b0a9a64 100644 > --- a/include/scsi/scsi_transport_fc.h > +++ b/include/scsi/scsi_transport_fc.h > @@ -835,6 +835,9 @@ fc_vport_set_state(struct fc_vport *vport, enum > fc_vport_state new_state) > vport->vport_state = new_state; > } > > +struct scsi_transport_template *fc_lw_attach_transport( > + struct fc_function_template *); > +void fc_lw_release_transport(struct scsi_transport_template *); > struct scsi_transport_template *fc_attach_transport( > struct fc_function_template *); > void fc_release_transport(struct scsi_transport_template *); > -- > 2.6.2 James, It was great talking to you this afternoon. Is this what you had in mind: drivers/scsi/scsi_transport_fc.c | 133 ++++++++++++++++++++++++++++++++++++-- include/scsi/scsi_transport_fc.h | 3 + 2 files changed, 130 insertions(+), 6 deletions(-) -- 1.7.4.1 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c index 24eaaf6..b8cadd2 100644 --- a/drivers/scsi/scsi_transport_fc.c +++ b/drivers/scsi/scsi_transport_fc.c @@ -351,6 +351,27 @@ struct fc_internal { #define to_fc_internal(tmpl) container_of(tmpl, struct fc_internal, t) +#define FC_LW_HOST_NUM_ATTRS 2 +struct fc_lw_internal { + struct scsi_transport_template t; + struct fc_function_template *f; + + /* + * For attributes : each object has : + * An array of the actual attributes structures + * An array of null-terminated pointers to the attribute + * structures - used for mid-layer interaction. + * + * The attribute containers for the starget and host are are + * part of the midlayer. As the remote port is specific to the + * fc transport, we must provide the attribute container. + */ + struct device_attribute private_host_attrs[FC_LW_HOST_NUM_ATTRS]; + struct device_attribute *host_attrs[FC_LW_HOST_NUM_ATTRS + 1]; +}; + +#define to_fc_lw_internal(tmpl) container_of(tmpl, struct fc_lw_internal, t) + static int fc_target_setup(struct transport_container *tc, struct device *dev, struct device *cdev) { @@ -472,6 +493,12 @@ static int fc_host_remove(struct transport_container *tc, struct device *dev, return 0; } +static DECLARE_TRANSPORT_CLASS(fc_lw_host_class, + "fc_host", + NULL, + NULL, + NULL); + static DECLARE_TRANSPORT_CLASS(fc_host_class, "fc_host", fc_host_setup, @@ -654,11 +681,20 @@ send_vendor_fail: EXPORT_SYMBOL(fc_host_post_vendor_event); +static bool transport_inited; +static bool lw_transport_inited; -static __init int fc_transport_init(void) +static int fc_transport_init(bool lw_transport) { int error; + bool inited = cmpxchg(&transport_inited, transport_inited, true); + /* + * If transport has already been inited, just return. + */ + if (inited) + return 0; + atomic_set(&fc_event_seq, 0); error = transport_class_register(&fc_host_class); @@ -670,9 +706,15 @@ static __init int fc_transport_init(void) error = transport_class_register(&fc_rport_class); if (error) goto unreg_vport_class; - error = transport_class_register(&fc_transport_class); + if (lw_transport) + error = transport_class_register(&fc_lw_host_class); + else + error = transport_class_register(&fc_transport_class); if (error) goto unreg_rport_class; + + if (lw_transport) + lw_transport_inited = true; return 0; unreg_rport_class: @@ -686,8 +728,12 @@ unreg_host_class: static void __exit fc_transport_exit(void) { - transport_class_unregister(&fc_transport_class); + if (lw_transport_inited) + transport_class_unregister(&fc_lw_host_class); + else + transport_class_unregister(&fc_transport_class); transport_class_unregister(&fc_rport_class); + if (lw_transport_inited) transport_class_unregister(&fc_host_class); transport_class_unregister(&fc_vport_class); } @@ -1968,6 +2014,25 @@ static int fc_host_match(struct attribute_container *cont, return &i->t.host_attrs.ac == cont; } +static int fc_lw_host_match(struct attribute_container *cont, + struct device *dev) +{ + struct Scsi_Host *shost; + struct fc_lw_internal *i; + + if (!scsi_is_host_device(dev)) + return 0; + + shost = dev_to_shost(dev); + if (!shost->transportt || shost->transportt->host_attrs.ac.class + != &fc_lw_host_class.class) + return 0; + + i = to_fc_lw_internal(shost->transportt); + + return &i->t.host_attrs.ac == cont; +} + static int fc_target_match(struct attribute_container *cont, struct device *dev) { @@ -2171,13 +2236,70 @@ static int fc_it_nexus_response(struct Scsi_Host *shost, u64 nexus, int result) return i->f->it_nexus_response(shost, nexus, result); } +/** + * fc_attach_lw_transport - light weight attach function + * @ft: function template for optional attributes + * + * This attach function is to be used only for virtual FC emulators + * which do not have a physical fabric underneath them and thus only + * need a few attributes and no helper functions + */ +struct scsi_transport_template * +fc_lw_attach_transport(struct fc_function_template *ft) +{ + int count; + struct fc_lw_internal *i; + + if (fc_transport_init(true)) + return NULL; + + i = kzalloc(sizeof(struct fc_lw_internal), + GFP_KERNEL); + + if (unlikely(!i)) + return NULL; + + i->t.host_attrs.ac.attrs = &i->host_attrs[0]; + i->t.host_attrs.ac.class = &fc_lw_host_class.class; + i->t.host_attrs.ac.match = fc_lw_host_match; + i->t.host_size = sizeof(struct fc_host_attrs); + transport_container_register(&i->t.host_attrs); + + i->f = ft; + + count = 0; + SETUP_HOST_ATTRIBUTE_RD(node_name); + SETUP_HOST_ATTRIBUTE_RD(port_name); + + BUG_ON(count > FC_HOST_NUM_ATTRS); + + i->host_attrs[count] = NULL; + + return &i->t; +} +EXPORT_SYMBOL(fc_lw_attach_transport); + +void fc_lw_release_transport(struct scsi_transport_template *t) +{ + struct fc_lw_internal *i = to_fc_lw_internal(t); + + transport_container_unregister(&i->t.host_attrs); + + kfree(i); +} +EXPORT_SYMBOL(fc_lw_release_transport); + struct scsi_transport_template * fc_attach_transport(struct fc_function_template *ft) { int count; - struct fc_internal *i = kzalloc(sizeof(struct fc_internal), - GFP_KERNEL); + struct fc_internal *i; + + if (fc_transport_init(false)) + return NULL; + i = kzalloc(sizeof(struct fc_internal), + GFP_KERNEL); if (unlikely(!i)) return NULL; @@ -4148,5 +4270,4 @@ MODULE_AUTHOR("James Smart"); MODULE_DESCRIPTION("FC Transport Attributes"); MODULE_LICENSE("GPL"); -module_init(fc_transport_init); module_exit(fc_transport_exit); diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h index 784bc2c..b0a9a64 100644 --- a/include/scsi/scsi_transport_fc.h +++ b/include/scsi/scsi_transport_fc.h @@ -835,6 +835,9 @@ fc_vport_set_state(struct fc_vport *vport, enum fc_vport_state new_state) vport->vport_state = new_state; } +struct scsi_transport_template *fc_lw_attach_transport( + struct fc_function_template *); +void fc_lw_release_transport(struct scsi_transport_template *); struct scsi_transport_template *fc_attach_transport( struct fc_function_template *); void fc_release_transport(struct scsi_transport_template *);