Commit 15d10b611fa94b52f004a08a1d4cf7b39de3cba3
Committed by
Jens Axboe
1 parent
2c9ecdf40a
Exists in
master
and in
20 other branches
bsg: add SCSI transport-level request support
This enables bsg to handle SCSI transport-level request like SAS management protocol (SMP). - add BSG_SUB_PROTOCOL_{SCSI_CMD, SCSI_TMF, SCSI_TRANSPORT} definitions. - SCSI transport-level requests skip blk_verify_command(). Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Showing 2 changed files with 27 additions and 6 deletions Side-by-side Diff
block/bsg.c
... | ... | @@ -208,7 +208,11 @@ |
208 | 208 | if (copy_from_user(rq->cmd, (void *)(unsigned long)hdr->request, |
209 | 209 | hdr->request_len)) |
210 | 210 | return -EFAULT; |
211 | - if (blk_verify_command(rq->cmd, has_write_perm)) | |
211 | + | |
212 | + if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) { | |
213 | + if (blk_verify_command(rq->cmd, has_write_perm)) | |
214 | + return -EPERM; | |
215 | + } else if (!capable(CAP_SYS_RAWIO)) | |
212 | 216 | return -EPERM; |
213 | 217 | |
214 | 218 | /* |
... | ... | @@ -232,6 +236,8 @@ |
232 | 236 | static int |
233 | 237 | bsg_validate_sgv4_hdr(request_queue_t *q, struct sg_io_v4 *hdr, int *rw) |
234 | 238 | { |
239 | + int ret = 0; | |
240 | + | |
235 | 241 | if (hdr->guard != 'Q') |
236 | 242 | return -EINVAL; |
237 | 243 | if (hdr->request_len > BLK_MAX_CDB) |
238 | 244 | |
... | ... | @@ -240,13 +246,22 @@ |
240 | 246 | hdr->din_xfer_len > (q->max_sectors << 9)) |
241 | 247 | return -EIO; |
242 | 248 | |
243 | - /* not supported currently */ | |
244 | - if (hdr->protocol || hdr->subprotocol) | |
245 | - return -EINVAL; | |
249 | + switch (hdr->protocol) { | |
250 | + case BSG_PROTOCOL_SCSI: | |
251 | + switch (hdr->subprotocol) { | |
252 | + case BSG_SUB_PROTOCOL_SCSI_CMD: | |
253 | + case BSG_SUB_PROTOCOL_SCSI_TRANSPORT: | |
254 | + break; | |
255 | + default: | |
256 | + ret = -EINVAL; | |
257 | + } | |
258 | + break; | |
259 | + default: | |
260 | + ret = -EINVAL; | |
261 | + } | |
246 | 262 | |
247 | 263 | *rw = hdr->dout_xfer_len ? WRITE : READ; |
248 | - | |
249 | - return 0; | |
264 | + return ret; | |
250 | 265 | } |
251 | 266 | |
252 | 267 | /* |
include/linux/bsg.h
1 | 1 | #ifndef BSG_H |
2 | 2 | #define BSG_H |
3 | 3 | |
4 | +#define BSG_PROTOCOL_SCSI 0 | |
5 | + | |
6 | +#define BSG_SUB_PROTOCOL_SCSI_CMD 0 | |
7 | +#define BSG_SUB_PROTOCOL_SCSI_TMF 1 | |
8 | +#define BSG_SUB_PROTOCOL_SCSI_TRANSPORT 2 | |
9 | + | |
4 | 10 | struct sg_io_v4 { |
5 | 11 | __s32 guard; /* [i] 'Q' to differentiate from v3 */ |
6 | 12 | __u32 protocol; /* [i] 0 -> SCSI , .... */ |