From patchwork Fri Apr 5 23:04:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Smart X-Patchwork-Id: 10887951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AC651390 for ; Fri, 5 Apr 2019 23:04:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54412286D7 for ; Fri, 5 Apr 2019 23:04:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4619F28B35; Fri, 5 Apr 2019 23:04:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1B6B286D7 for ; Fri, 5 Apr 2019 23:04:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726360AbfDEXEe (ORCPT ); Fri, 5 Apr 2019 19:04:34 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34447 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726124AbfDEXEd (ORCPT ); Fri, 5 Apr 2019 19:04:33 -0400 Received: by mail-pg1-f195.google.com with SMTP id v12so3820270pgq.1 for ; Fri, 05 Apr 2019 16:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Y4D2HB19WTdoWK9hqQYIPRUylkEuXA7nzRGNCOJ75VE=; b=uB5M7Hg6rRYF+dj66J9mCMro7uzn59qalhalISKWR3KvP6wGa9WY/LquoRmZSavtgb jn1BaK2xO6X3rUU/h0wPJ4CX3YKYcEN5hXT9ZFGKXzaOh4XvIPyzCbZQ4Xvw0aWJ4+Q3 YjAt+gf7K8lUwrSWC4nZS+7iJvpmiL0JGBQhqQd8eWbfXsL8YnbGEkECpqrv+do/DfIB vhBiLwhU3raWl2Vu9ddXzp+0Mh8DmKBSZv4BNqyeX/kbREjM+rKJctmynuDbPmyqEd3I VbgFr0dQYyviAucoxYLN5SOkVN+aDpaKq2xj6Ps2mME5zArx3gxiWLRVK2P4pHN1oGz+ 0QzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Y4D2HB19WTdoWK9hqQYIPRUylkEuXA7nzRGNCOJ75VE=; b=TDsKKkXfD4rGs78qJE2kfOzT0k1QU1G11GgrcC9VC404Dq5JvfoBC40ejFFMsgf0tT 2mZJpLV9xLJ2RASMcoQJjxQSBVtWon1TGyXZXzJdxs1bQXe87GyANY/B2ClvJZ6u4ZKu M//FX+J5aiAmR8jU9jHE7jalb6OryDkDCZ68PynTwzd0odBJOACUiT52paVeTKt+Yx78 G7d7imaGlXJgxQvnbvi5g7kIrhEcgSnrMjUL7Bssoj+OuDd52Mv9lvtlCyBDlS2L9Iuf /FHGbXWRtzAVC8kbJYQnD01MRCXU6/YwpDpBjAPAjaefO/ykpTYqPLvWk03S9s3T8Yqf dEpg== X-Gm-Message-State: APjAAAUjrrwHX19/5ySJOPYq3Lz2miAXlR4eNdD1nIQVLetpHq68fOzX caEJkQ++baftFGsjIddq6LrlZ6+L X-Google-Smtp-Source: APXvYqxesLmQ7nZo/RqizH+I75kMX2sD7qvVKYEOTWOCao2c0SothJEkZW9YnNi8/lo13lMAIWrscg== X-Received: by 2002:a65:64cf:: with SMTP id t15mr14318879pgv.322.1554505473040; Fri, 05 Apr 2019 16:04:33 -0700 (PDT) Received: from os42.localdomain ([192.19.223.250]) by smtp.gmail.com with ESMTPSA id j67sm30805068pfc.72.2019.04.05.16.04.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Apr 2019 16:04:32 -0700 (PDT) From: James Smart To: linux-scsi@vger.kernel.org Cc: muneendra.kumar@broadcom.com, James Smart Subject: [PATCH 2/4] scsi_transport_fc: refactor event posting routines Date: Fri, 5 Apr 2019 16:04:21 -0700 Message-Id: <20190405230423.4316-3-jsmart2021@gmail.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20190405230423.4316-1-jsmart2021@gmail.com> References: <20190405230423.4316-1-jsmart2021@gmail.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are two routines generating transport events that do the same thing with only a couple of values set differently. Refactor so there's a single routine doing the netlink operations to send the event. All the differences are passed as arguments. Export the symbol so the generic routine can be called by llds. Modify the existing two event routines to use the helper. Signed-off-by: James Smart Reviewed-by: Ewan D. Milne --- drivers/scsi/scsi_transport_fc.c | 100 ++++++++++++++++----------------------- include/scsi/scsi_transport_fc.h | 11 +++-- 2 files changed, 49 insertions(+), 62 deletions(-) diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c index d7035270d274..9bea4dfbe128 100644 --- a/drivers/scsi/scsi_transport_fc.c +++ b/drivers/scsi/scsi_transport_fc.c @@ -523,20 +523,23 @@ fc_get_event_number(void) } EXPORT_SYMBOL(fc_get_event_number); - /** - * fc_host_post_event - called to post an even on an fc_host. + * fc_host_post_fc_event - routine to do the work of posting an event + * on an fc_host. * @shost: host the event occurred on * @event_number: fc event number obtained from get_fc_event_number() * @event_code: fc_host event being posted - * @event_data: 32bits of data for the event being posted + * @data_len: amount, in bytes, of event data + * @data_buf: pointer to event data + * @vendor_id: value for Vendor id * * Notes: * This routine assumes no locks are held on entry. */ void -fc_host_post_event(struct Scsi_Host *shost, u32 event_number, - enum fc_host_event_code event_code, u32 event_data) +fc_host_post_fc_event(struct Scsi_Host *shost, u32 event_number, + enum fc_host_event_code event_code, + u32 data_len, char *data_buf, u64 vendor_id) { struct sk_buff *skb; struct nlmsghdr *nlh; @@ -545,12 +548,15 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number, u32 len; int err; + if (!data_buf || data_len < 4) + data_len = 0; + if (!scsi_nl_sock) { err = -ENOENT; goto send_fail; } - len = FC_NL_MSGALIGN(sizeof(*event)); + len = FC_NL_MSGALIGN(sizeof(*event) + data_len); skb = nlmsg_new(len, GFP_KERNEL); if (!skb) { @@ -568,12 +574,13 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number, INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, FC_NL_ASYNC_EVENT, len); event->seconds = ktime_get_real_seconds(); - event->vendor_id = 0; + event->vendor_id = vendor_id; event->host_no = shost->host_no; - event->event_datalen = sizeof(u32); /* bytes */ + event->event_datalen = data_len; /* bytes */ event->event_num = event_number; event->event_code = event_code; - event->event_data = event_data; + if (data_len) + memcpy(&event->event_data, data_buf, data_len); nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS, GFP_KERNEL); @@ -586,14 +593,35 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number, printk(KERN_WARNING "%s: Dropped Event : host %d %s data 0x%08x - err %d\n", __func__, shost->host_no, - (name) ? name : "", event_data, err); + (name) ? name : "", + (data_len) ? *((u32 *)data_buf) : 0xFFFFFFFF, err); return; } +EXPORT_SYMBOL(fc_host_post_fc_event); + +/** + * fc_host_post_event - called to post an even on an fc_host. + * @shost: host the event occurred on + * @event_number: fc event number obtained from get_fc_event_number() + * @event_code: fc_host event being posted + * @event_data: 32bits of data for the event being posted + * + * Notes: + * This routine assumes no locks are held on entry. + */ +void +fc_host_post_event(struct Scsi_Host *shost, u32 event_number, + enum fc_host_event_code event_code, u32 event_data) +{ + fc_host_post_fc_event(shost, event_number, event_code, + (u32)sizeof(u32), (char *)&event_data, 0); +} EXPORT_SYMBOL(fc_host_post_event); /** - * fc_host_post_vendor_event - called to post a vendor unique event on an fc_host + * fc_host_post_vendor_event - called to post a vendor unique event + * on an fc_host * @shost: host the event occurred on * @event_number: fc event number obtained from get_fc_event_number() * @data_len: amount, in bytes, of vendor unique data @@ -607,58 +635,12 @@ void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number, u32 data_len, char * data_buf, u64 vendor_id) { - struct sk_buff *skb; - struct nlmsghdr *nlh; - struct fc_nl_event *event; - u32 len; - int err; - - if (!scsi_nl_sock) { - err = -ENOENT; - goto send_vendor_fail; - } - - len = FC_NL_MSGALIGN(sizeof(*event) + data_len); - - skb = nlmsg_new(len, GFP_KERNEL); - if (!skb) { - err = -ENOBUFS; - goto send_vendor_fail; - } - - nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG, len, 0); - if (!nlh) { - err = -ENOBUFS; - goto send_vendor_fail_skb; - } - event = nlmsg_data(nlh); - - INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC, - FC_NL_ASYNC_EVENT, len); - event->seconds = ktime_get_real_seconds(); - event->vendor_id = vendor_id; - event->host_no = shost->host_no; - event->event_datalen = data_len; /* bytes */ - event->event_num = event_number; - event->event_code = FCH_EVT_VENDOR_UNIQUE; - memcpy(&event->event_data, data_buf, data_len); - - nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS, - GFP_KERNEL); - return; - -send_vendor_fail_skb: - kfree_skb(skb); -send_vendor_fail: - printk(KERN_WARNING - "%s: Dropped Event : host %d vendor_unique - err %d\n", - __func__, shost->host_no, err); - return; + fc_host_post_fc_event(shost, event_number, FCH_EVT_VENDOR_UNIQUE, + data_len, data_buf, vendor_id); } EXPORT_SYMBOL(fc_host_post_vendor_event); - static __init int fc_transport_init(void) { int error; diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h index 15da45dc2a5d..7998b322ed13 100644 --- a/include/scsi/scsi_transport_fc.h +++ b/include/scsi/scsi_transport_fc.h @@ -798,10 +798,15 @@ u32 fc_get_event_number(void); void fc_host_post_event(struct Scsi_Host *shost, u32 event_number, enum fc_host_event_code event_code, u32 event_data); void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number, - u32 data_len, char * data_buf, u64 vendor_id); + u32 data_len, char *data_buf, u64 vendor_id); +void fc_host_post_fc_event(struct Scsi_Host *shost, u32 event_number, + enum fc_host_event_code event_code, + u32 data_len, char *data_buf, u64 vendor_id); /* Note: when specifying vendor_id to fc_host_post_vendor_event() - * be sure to read the Vendor Type and ID formatting requirements - * specified in scsi_netlink.h + * or fc_host_post_fc_event(), be sure to read the Vendor Type + * and ID formatting requirements specified in scsi_netlink.h + * Note: when calling fc_host_post_fc_event(), vendor_id may be + * specified as 0. */ struct fc_vport *fc_vport_create(struct Scsi_Host *shost, int channel, struct fc_vport_identifiers *);