1 Subject: Netlink interface for SCSI sense codes
2 From: Hannes Reinecke <hare@suse.de>
3 Date: Fri Nov 21 10:08:01 2008 +0100:
4 Git: 97746dc5543ef9113c927022dc54ccd26915563d
6 Inform the userspace about SCSI sense codes; some of them
7 carry vital information where userspace should react to.
9 Signed-off-by: Hannes Reinecke <hare@suse.de>
11 diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
12 index 3863617..266e5a5 100644
13 --- a/drivers/scsi/scsi_error.c
14 +++ b/drivers/scsi/scsi_error.c
16 #include <linux/interrupt.h>
17 #include <linux/blkdev.h>
18 #include <linux/delay.h>
19 +#include <linux/netlink.h>
20 +#include <net/netlink.h>
22 #include <scsi/scsi.h>
23 #include <scsi/scsi_cmnd.h>
25 #include <scsi/scsi_transport.h>
26 #include <scsi/scsi_host.h>
27 #include <scsi/scsi_ioctl.h>
28 +#include <scsi/scsi_netlink_ml.h>
30 #include "scsi_priv.h"
31 #include "scsi_logging.h"
32 @@ -224,6 +227,80 @@ static inline void scsi_eh_prt_fail_stats(struct Scsi_Host *shost,
36 +#ifdef CONFIG_SCSI_NETLINK
38 + * scsi_post_sense_event - called to post a 'Sense Code' event
40 + * @sdev: SCSI device the sense code occured on
41 + * @sshdr: SCSI sense code
44 + * 0 on succesful return
45 + * otherwise, failing error code
48 +static void scsi_post_sense_event(struct scsi_device *sdev,
49 + struct scsi_sense_hdr *sshdr)
51 + struct sk_buff *skb;
52 + struct nlmsghdr *nlh;
53 + struct scsi_nl_sense_msg *msg;
57 + if (!scsi_nl_sock) {
62 + len = SCSI_NL_MSGALIGN(sizeof(*msg));
63 + skblen = NLMSG_SPACE(len);
65 + skb = alloc_skb(skblen, GFP_ATOMIC);
71 + nlh = nlmsg_put(skb, 0, 0, SCSI_TRANSPORT_MSG,
72 + skblen - sizeof(*nlh), 0);
77 + msg = NLMSG_DATA(nlh);
79 + INIT_SCSI_NL_HDR(&msg->snlh, SCSI_NL_TRANSPORT_ML,
80 + ML_NL_SCSI_SENSE, len);
81 + msg->host_no = sdev->host->host_no;
82 + msg->channel = sdev->channel;
84 + msg->lun = sdev->lun;
85 + msg->sense = (sshdr->response_code << 24) | (sshdr->sense_key << 16) |
86 + (sshdr->asc << 8) | sshdr->ascq;
88 + err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_ML_EVENTS,
90 + if (err && (err != -ESRCH))
91 + /* nlmsg_multicast already kfree_skb'd */
99 + sdev_printk(KERN_WARNING, sdev,
100 + "Dropped SCSI Msg %02x/%02x/%02x/%02x: err %d\n",
101 + sshdr->response_code, sshdr->sense_key,
102 + sshdr->asc, sshdr->ascq, err);
106 +static inline void scsi_post_sense_event(struct scsi_device *sdev,
107 + struct scsi_sense_hdr *sshdr) {}
111 * scsi_check_sense - Examine scsi cmd sense
112 * @scmd: Cmd to have sense checked.
113 @@ -246,6 +323,8 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
114 if (scsi_sense_is_deferred(&sshdr))
117 + scsi_post_sense_event(sdev, &sshdr);
119 if (sdev->scsi_dh_data && sdev->scsi_dh_data->scsi_dh &&
120 sdev->scsi_dh_data->scsi_dh->check_sense) {
122 diff --git a/include/scsi/scsi_netlink.h b/include/scsi/scsi_netlink.h
123 index 536752c..ac7c766 100644
124 --- a/include/scsi/scsi_netlink.h
125 +++ b/include/scsi/scsi_netlink.h
127 /* SCSI Transport Broadcast Groups */
128 /* leaving groups 0 and 1 unassigned */
129 #define SCSI_NL_GRP_FC_EVENTS (1<<2) /* Group 2 */
130 -#define SCSI_NL_GRP_CNT 3
131 +#define SCSI_NL_GRP_ML_EVENTS (1<<3) /* Group 3 */
132 +#define SCSI_NL_GRP_CNT 4
135 /* SCSI_TRANSPORT_MSG event message header */
136 @@ -56,7 +57,8 @@ struct scsi_nl_hdr {
137 /* scsi_nl_hdr->transport value */
138 #define SCSI_NL_TRANSPORT 0
139 #define SCSI_NL_TRANSPORT_FC 1
140 -#define SCSI_NL_MAX_TRANSPORTS 2
141 +#define SCSI_NL_TRANSPORT_ML 2
142 +#define SCSI_NL_MAX_TRANSPORTS 3
144 /* Transport-based scsi_nl_hdr->msgtype values are defined in each transport */
146 diff --git a/include/scsi/scsi_netlink_ml.h b/include/scsi/scsi_netlink_ml.h
148 index 0000000..c988458
150 +++ b/include/scsi/scsi_netlink_ml.h
153 + * SCSI Midlayer Netlink Interface
155 + * Copyright (C) 2008 Hannes Reinecke, SuSE Linux Products GmbH
157 + * This program is free software; you can redistribute it and/or modify
158 + * it under the terms of the GNU General Public License as published by
159 + * the Free Software Foundation; either version 2 of the License, or
160 + * (at your option) any later version.
162 + * This program is distributed in the hope that it will be useful,
163 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
164 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
165 + * GNU General Public License for more details.
167 + * You should have received a copy of the GNU General Public License
168 + * along with this program; if not, write to the Free Software
169 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
172 +#ifndef SCSI_NETLINK_ML_H
173 +#define SCSI_NETLINK_ML_H
175 +#include <scsi/scsi_netlink.h>
178 + * This file intended to be included by both kernel and user space
182 + * FC Transport Message Types
184 + /* kernel -> user */
185 +#define ML_NL_SCSI_SENSE 0x0100
186 + /* user -> kernel */
191 + * Message Structures :
194 +/* macro to round up message lengths to 8byte boundary */
195 +#define SCSI_NL_MSGALIGN(len) (((len) + 7) & ~7)
199 + * SCSI Midlayer SCSI Sense messages :
200 + * SCSI_NL_SCSI_SENSE
203 +struct scsi_nl_sense_msg {
204 + struct scsi_nl_hdr snlh; /* must be 1st element ! */
211 +} __attribute__((aligned(sizeof(uint64_t))));
214 +#endif /* SCSI_NETLINK_ML_H */