Commit 2b1be558 authored by James Smart's avatar James Smart Committed by Martin K. Petersen

scsi: scsi_transport_fc: refactor event posting routines

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: default avatarJames Smart <jsmart2021@gmail.com>
Reviewed-by: default avatarEwan D. Milne <emilne@redhat.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent a7dff3ad
...@@ -523,20 +523,23 @@ fc_get_event_number(void) ...@@ -523,20 +523,23 @@ fc_get_event_number(void)
} }
EXPORT_SYMBOL(fc_get_event_number); 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 * @shost: host the event occurred on
* @event_number: fc event number obtained from get_fc_event_number() * @event_number: fc event number obtained from get_fc_event_number()
* @event_code: fc_host event being posted * @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: * Notes:
* This routine assumes no locks are held on entry. * This routine assumes no locks are held on entry.
*/ */
void void
fc_host_post_event(struct Scsi_Host *shost, u32 event_number, fc_host_post_fc_event(struct Scsi_Host *shost, u32 event_number,
enum fc_host_event_code event_code, u32 event_data) enum fc_host_event_code event_code,
u32 data_len, char *data_buf, u64 vendor_id)
{ {
struct sk_buff *skb; struct sk_buff *skb;
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
...@@ -545,12 +548,15 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number, ...@@ -545,12 +548,15 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
u32 len; u32 len;
int err; int err;
if (!data_buf || data_len < 4)
data_len = 0;
if (!scsi_nl_sock) { if (!scsi_nl_sock) {
err = -ENOENT; err = -ENOENT;
goto send_fail; goto send_fail;
} }
len = FC_NL_MSGALIGN(sizeof(*event)); len = FC_NL_MSGALIGN(sizeof(*event) + data_len);
skb = nlmsg_new(len, GFP_KERNEL); skb = nlmsg_new(len, GFP_KERNEL);
if (!skb) { if (!skb) {
...@@ -568,12 +574,13 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number, ...@@ -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, INIT_SCSI_NL_HDR(&event->snlh, SCSI_NL_TRANSPORT_FC,
FC_NL_ASYNC_EVENT, len); FC_NL_ASYNC_EVENT, len);
event->seconds = ktime_get_real_seconds(); event->seconds = ktime_get_real_seconds();
event->vendor_id = 0; event->vendor_id = vendor_id;
event->host_no = shost->host_no; 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_num = event_number;
event->event_code = event_code; 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, nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS,
GFP_KERNEL); GFP_KERNEL);
...@@ -586,14 +593,35 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number, ...@@ -586,14 +593,35 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
printk(KERN_WARNING printk(KERN_WARNING
"%s: Dropped Event : host %d %s data 0x%08x - err %d\n", "%s: Dropped Event : host %d %s data 0x%08x - err %d\n",
__func__, shost->host_no, __func__, shost->host_no,
(name) ? name : "<unknown>", event_data, err); (name) ? name : "<unknown>",
(data_len) ? *((u32 *)data_buf) : 0xFFFFFFFF, err);
return; 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); 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 * @shost: host the event occurred on
* @event_number: fc event number obtained from get_fc_event_number() * @event_number: fc event number obtained from get_fc_event_number()
* @data_len: amount, in bytes, of vendor unique data * @data_len: amount, in bytes, of vendor unique data
...@@ -607,58 +635,12 @@ void ...@@ -607,58 +635,12 @@ void
fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number, 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)
{ {
struct sk_buff *skb; fc_host_post_fc_event(shost, event_number, FCH_EVT_VENDOR_UNIQUE,
struct nlmsghdr *nlh; data_len, data_buf, vendor_id);
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;
} }
EXPORT_SYMBOL(fc_host_post_vendor_event); EXPORT_SYMBOL(fc_host_post_vendor_event);
static __init int fc_transport_init(void) static __init int fc_transport_init(void)
{ {
int error; int error;
......
...@@ -798,10 +798,15 @@ u32 fc_get_event_number(void); ...@@ -798,10 +798,15 @@ u32 fc_get_event_number(void);
void fc_host_post_event(struct Scsi_Host *shost, u32 event_number, void fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
enum fc_host_event_code event_code, u32 event_data); enum fc_host_event_code event_code, u32 event_data);
void fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number, 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() /* Note: when specifying vendor_id to fc_host_post_vendor_event()
* be sure to read the Vendor Type and ID formatting requirements * or fc_host_post_fc_event(), be sure to read the Vendor Type
* specified in scsi_netlink.h * 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 *fc_vport_create(struct Scsi_Host *shost, int channel,
struct fc_vport_identifiers *); struct fc_vport_identifiers *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment