Skip to content

Commit 82ed4db

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: split scsi_request out of struct request
And require all drivers that want to support BLOCK_PC to allocate it as the first thing of their private data. To support this the legacy IDE and BSG code is switched to set cmd_size on their queues to let the block layer allocate the additional space. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 8ae94eb commit 82ed4db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+458
-410
lines changed

block/blk-core.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
132132
rq->__sector = (sector_t) -1;
133133
INIT_HLIST_NODE(&rq->hash);
134134
RB_CLEAR_NODE(&rq->rb_node);
135-
rq->cmd = rq->__cmd;
136-
rq->cmd_len = BLK_MAX_CDB;
137135
rq->tag = -1;
138136
rq->internal_tag = -1;
139137
rq->start_time = jiffies;
@@ -160,8 +158,6 @@ static void req_bio_endio(struct request *rq, struct bio *bio,
160158

161159
void blk_dump_rq_flags(struct request *rq, char *msg)
162160
{
163-
int bit;
164-
165161
printk(KERN_INFO "%s: dev %s: type=%x, flags=%llx\n", msg,
166162
rq->rq_disk ? rq->rq_disk->disk_name : "?", rq->cmd_type,
167163
(unsigned long long) rq->cmd_flags);
@@ -171,13 +167,6 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
171167
blk_rq_sectors(rq), blk_rq_cur_sectors(rq));
172168
printk(KERN_INFO " bio %p, biotail %p, len %u\n",
173169
rq->bio, rq->biotail, blk_rq_bytes(rq));
174-
175-
if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
176-
printk(KERN_INFO " cdb: ");
177-
for (bit = 0; bit < BLK_MAX_CDB; bit++)
178-
printk("%02x ", rq->cmd[bit]);
179-
printk("\n");
180-
}
181170
}
182171
EXPORT_SYMBOL(blk_dump_rq_flags);
183172

@@ -1315,18 +1304,6 @@ struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
13151304
}
13161305
EXPORT_SYMBOL(blk_get_request);
13171306

1318-
/**
1319-
* blk_rq_set_block_pc - initialize a request to type BLOCK_PC
1320-
* @rq: request to be initialized
1321-
*
1322-
*/
1323-
void blk_rq_set_block_pc(struct request *rq)
1324-
{
1325-
rq->cmd_type = REQ_TYPE_BLOCK_PC;
1326-
memset(rq->__cmd, 0, sizeof(rq->__cmd));
1327-
}
1328-
EXPORT_SYMBOL(blk_rq_set_block_pc);
1329-
13301307
/**
13311308
* blk_requeue_request - put a request back on queue
13321309
* @q: request queue where request should be inserted
@@ -2459,14 +2436,6 @@ void blk_start_request(struct request *req)
24592436
wbt_issue(req->q->rq_wb, &req->issue_stat);
24602437
}
24612438

2462-
/*
2463-
* We are now handing the request to the hardware, initialize
2464-
* resid_len to full count and add the timeout handler.
2465-
*/
2466-
req->resid_len = blk_rq_bytes(req);
2467-
if (unlikely(blk_bidi_rq(req)))
2468-
req->next_rq->resid_len = blk_rq_bytes(req->next_rq);
2469-
24702439
BUG_ON(test_bit(REQ_ATOM_COMPLETE, &req->atomic_flags));
24712440
blk_add_timer(req);
24722441
}

block/blk-exec.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
#include "blk.h"
1212
#include "blk-mq-sched.h"
1313

14-
/*
15-
* for max sense size
16-
*/
17-
#include <scsi/scsi_cmnd.h>
18-
1914
/**
2015
* blk_end_sync_rq - executes a completion event on a request
2116
* @rq: request to complete
@@ -101,16 +96,9 @@ int blk_execute_rq(struct request_queue *q, struct gendisk *bd_disk,
10196
struct request *rq, int at_head)
10297
{
10398
DECLARE_COMPLETION_ONSTACK(wait);
104-
char sense[SCSI_SENSE_BUFFERSIZE];
10599
int err = 0;
106100
unsigned long hang_check;
107101

108-
if (!rq->sense) {
109-
memset(sense, 0, sizeof(sense));
110-
rq->sense = sense;
111-
rq->sense_len = 0;
112-
}
113-
114102
rq->end_io_data = &wait;
115103
blk_execute_rq_nowait(q, bd_disk, rq, at_head, blk_end_sync_rq);
116104

@@ -124,11 +112,6 @@ int blk_execute_rq(struct request_queue *q, struct gendisk *bd_disk,
124112
if (rq->errors)
125113
err = -EIO;
126114

127-
if (rq->sense == sense) {
128-
rq->sense = NULL;
129-
rq->sense_len = 0;
130-
}
131-
132115
return err;
133116
}
134117
EXPORT_SYMBOL(blk_execute_rq);

block/blk-mq.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,7 @@ void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
199199
rq->special = NULL;
200200
/* tag was already set */
201201
rq->errors = 0;
202-
203-
rq->cmd = rq->__cmd;
204-
205202
rq->extra_len = 0;
206-
rq->sense_len = 0;
207-
rq->resid_len = 0;
208-
rq->sense = NULL;
209203

210204
INIT_LIST_HEAD(&rq->timeout_list);
211205
rq->timeout = 0;
@@ -487,10 +481,6 @@ void blk_mq_start_request(struct request *rq)
487481

488482
trace_block_rq_issue(q, rq);
489483

490-
rq->resid_len = blk_rq_bytes(rq);
491-
if (unlikely(blk_bidi_rq(rq)))
492-
rq->next_rq->resid_len = blk_rq_bytes(rq->next_rq);
493-
494484
if (test_bit(QUEUE_FLAG_STATS, &q->queue_flags)) {
495485
blk_stat_set_issue_time(&rq->issue_stat);
496486
rq->rq_flags |= RQF_STATS;

block/bsg-lib.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,24 @@ void bsg_job_done(struct bsg_job *job, int result,
7171
{
7272
struct request *req = job->req;
7373
struct request *rsp = req->next_rq;
74+
struct scsi_request *rq = scsi_req(req);
7475
int err;
7576

7677
err = job->req->errors = result;
7778
if (err < 0)
7879
/* we're only returning the result field in the reply */
79-
job->req->sense_len = sizeof(u32);
80+
rq->sense_len = sizeof(u32);
8081
else
81-
job->req->sense_len = job->reply_len;
82+
rq->sense_len = job->reply_len;
8283
/* we assume all request payload was transferred, residual == 0 */
83-
req->resid_len = 0;
84+
rq->resid_len = 0;
8485

8586
if (rsp) {
86-
WARN_ON(reply_payload_rcv_len > rsp->resid_len);
87+
WARN_ON(reply_payload_rcv_len > scsi_req(rsp)->resid_len);
8788

8889
/* set reply (bidi) residual */
89-
rsp->resid_len -= min(reply_payload_rcv_len, rsp->resid_len);
90+
scsi_req(rsp)->resid_len -=
91+
min(reply_payload_rcv_len, scsi_req(rsp)->resid_len);
9092
}
9193
blk_complete_request(req);
9294
}
@@ -113,6 +115,7 @@ static int bsg_map_buffer(struct bsg_buffer *buf, struct request *req)
113115
if (!buf->sg_list)
114116
return -ENOMEM;
115117
sg_init_table(buf->sg_list, req->nr_phys_segments);
118+
scsi_req(req)->resid_len = blk_rq_bytes(req);
116119
buf->sg_cnt = blk_rq_map_sg(req->q, req, buf->sg_list);
117120
buf->payload_len = blk_rq_bytes(req);
118121
return 0;
@@ -127,6 +130,7 @@ static int bsg_create_job(struct device *dev, struct request *req)
127130
{
128131
struct request *rsp = req->next_rq;
129132
struct request_queue *q = req->q;
133+
struct scsi_request *rq = scsi_req(req);
130134
struct bsg_job *job;
131135
int ret;
132136

@@ -140,9 +144,9 @@ static int bsg_create_job(struct device *dev, struct request *req)
140144
job->req = req;
141145
if (q->bsg_job_size)
142146
job->dd_data = (void *)&job[1];
143-
job->request = req->cmd;
144-
job->request_len = req->cmd_len;
145-
job->reply = req->sense;
147+
job->request = rq->cmd;
148+
job->request_len = rq->cmd_len;
149+
job->reply = rq->sense;
146150
job->reply_len = SCSI_SENSE_BUFFERSIZE; /* Size of sense buffer
147151
* allocated */
148152
if (req->bio) {
@@ -228,9 +232,15 @@ struct request_queue *bsg_setup_queue(struct device *dev, char *name,
228232
struct request_queue *q;
229233
int ret;
230234

231-
q = blk_init_queue(bsg_request_fn, NULL);
235+
q = blk_alloc_queue(GFP_KERNEL);
232236
if (!q)
233237
return ERR_PTR(-ENOMEM);
238+
q->cmd_size = sizeof(struct scsi_request);
239+
q->request_fn = bsg_request_fn;
240+
241+
ret = blk_init_allocated_queue(q);
242+
if (ret)
243+
goto out_cleanup_queue;
234244

235245
q->queuedata = dev;
236246
q->bsg_job_size = dd_job_size;
@@ -243,10 +253,12 @@ struct request_queue *bsg_setup_queue(struct device *dev, char *name,
243253
if (ret) {
244254
printk(KERN_ERR "%s: bsg interface failed to "
245255
"initialize - register queue\n", dev->kobj.name);
246-
blk_cleanup_queue(q);
247-
return ERR_PTR(ret);
256+
goto out_cleanup_queue;
248257
}
249258

250259
return q;
260+
out_cleanup_queue:
261+
blk_cleanup_queue(q);
262+
return ERR_PTR(ret);
251263
}
252264
EXPORT_SYMBOL_GPL(bsg_setup_queue);

block/bsg.c

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ struct bsg_command {
8585
struct bio *bidi_bio;
8686
int err;
8787
struct sg_io_v4 hdr;
88-
char sense[SCSI_SENSE_BUFFERSIZE];
8988
};
9089

9190
static void bsg_free_command(struct bsg_command *bc)
@@ -140,26 +139,28 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
140139
struct sg_io_v4 *hdr, struct bsg_device *bd,
141140
fmode_t has_write_perm)
142141
{
142+
struct scsi_request *req = scsi_req(rq);
143+
143144
if (hdr->request_len > BLK_MAX_CDB) {
144-
rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
145-
if (!rq->cmd)
145+
req->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
146+
if (!req->cmd)
146147
return -ENOMEM;
147148
}
148149

149-
if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
150+
if (copy_from_user(req->cmd, (void __user *)(unsigned long)hdr->request,
150151
hdr->request_len))
151152
return -EFAULT;
152153

153154
if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
154-
if (blk_verify_command(rq->cmd, has_write_perm))
155+
if (blk_verify_command(req->cmd, has_write_perm))
155156
return -EPERM;
156157
} else if (!capable(CAP_SYS_RAWIO))
157158
return -EPERM;
158159

159160
/*
160161
* fill in request structure
161162
*/
162-
rq->cmd_len = hdr->request_len;
163+
req->cmd_len = hdr->request_len;
163164

164165
rq->timeout = msecs_to_jiffies(hdr->timeout);
165166
if (!rq->timeout)
@@ -205,8 +206,7 @@ bsg_validate_sgv4_hdr(struct sg_io_v4 *hdr, int *rw)
205206
* map sg_io_v4 to a request.
206207
*/
207208
static struct request *
208-
bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
209-
u8 *sense)
209+
bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm)
210210
{
211211
struct request_queue *q = bd->queue;
212212
struct request *rq, *next_rq = NULL;
@@ -236,7 +236,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
236236
rq = blk_get_request(q, rw, GFP_KERNEL);
237237
if (IS_ERR(rq))
238238
return rq;
239-
blk_rq_set_block_pc(rq);
239+
scsi_req_init(rq);
240240

241241
ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd, has_write_perm);
242242
if (ret)
@@ -280,13 +280,9 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, fmode_t has_write_perm,
280280
goto out;
281281
}
282282

283-
rq->sense = sense;
284-
rq->sense_len = 0;
285-
286283
return rq;
287284
out:
288-
if (rq->cmd != rq->__cmd)
289-
kfree(rq->cmd);
285+
scsi_req_free_cmd(scsi_req(rq));
290286
blk_put_request(rq);
291287
if (next_rq) {
292288
blk_rq_unmap_user(next_rq->bio);
@@ -393,6 +389,7 @@ static struct bsg_command *bsg_get_done_cmd(struct bsg_device *bd)
393389
static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
394390
struct bio *bio, struct bio *bidi_bio)
395391
{
392+
struct scsi_request *req = scsi_req(rq);
396393
int ret = 0;
397394

398395
dprintk("rq %p bio %p 0x%x\n", rq, bio, rq->errors);
@@ -407,27 +404,27 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
407404
hdr->info |= SG_INFO_CHECK;
408405
hdr->response_len = 0;
409406

410-
if (rq->sense_len && hdr->response) {
407+
if (req->sense_len && hdr->response) {
411408
int len = min_t(unsigned int, hdr->max_response_len,
412-
rq->sense_len);
409+
req->sense_len);
413410

414411
ret = copy_to_user((void __user *)(unsigned long)hdr->response,
415-
rq->sense, len);
412+
req->sense, len);
416413
if (!ret)
417414
hdr->response_len = len;
418415
else
419416
ret = -EFAULT;
420417
}
421418

422419
if (rq->next_rq) {
423-
hdr->dout_resid = rq->resid_len;
424-
hdr->din_resid = rq->next_rq->resid_len;
420+
hdr->dout_resid = req->resid_len;
421+
hdr->din_resid = scsi_req(rq->next_rq)->resid_len;
425422
blk_rq_unmap_user(bidi_bio);
426423
blk_put_request(rq->next_rq);
427424
} else if (rq_data_dir(rq) == READ)
428-
hdr->din_resid = rq->resid_len;
425+
hdr->din_resid = req->resid_len;
429426
else
430-
hdr->dout_resid = rq->resid_len;
427+
hdr->dout_resid = req->resid_len;
431428

432429
/*
433430
* If the request generated a negative error number, return it
@@ -439,8 +436,7 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
439436
ret = rq->errors;
440437

441438
blk_rq_unmap_user(bio);
442-
if (rq->cmd != rq->__cmd)
443-
kfree(rq->cmd);
439+
scsi_req_free_cmd(req);
444440
blk_put_request(rq);
445441

446442
return ret;
@@ -625,7 +621,7 @@ static int __bsg_write(struct bsg_device *bd, const char __user *buf,
625621
/*
626622
* get a request, fill in the blanks, and add to request queue
627623
*/
628-
rq = bsg_map_hdr(bd, &bc->hdr, has_write_perm, bc->sense);
624+
rq = bsg_map_hdr(bd, &bc->hdr, has_write_perm);
629625
if (IS_ERR(rq)) {
630626
ret = PTR_ERR(rq);
631627
rq = NULL;
@@ -911,12 +907,11 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
911907
struct bio *bio, *bidi_bio = NULL;
912908
struct sg_io_v4 hdr;
913909
int at_head;
914-
u8 sense[SCSI_SENSE_BUFFERSIZE];
915910

916911
if (copy_from_user(&hdr, uarg, sizeof(hdr)))
917912
return -EFAULT;
918913

919-
rq = bsg_map_hdr(bd, &hdr, file->f_mode & FMODE_WRITE, sense);
914+
rq = bsg_map_hdr(bd, &hdr, file->f_mode & FMODE_WRITE);
920915
if (IS_ERR(rq))
921916
return PTR_ERR(rq);
922917

0 commit comments

Comments
 (0)