Skip to content

Commit bd5d435

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.dk/linux-2.6-block
* 'for-linus' of git://git.kernel.dk/linux-2.6-block: block: Skip I/O merges when disabled block: add large command support block: replace sizeof(rq->cmd) with BLK_MAX_CDB ide: use blk_rq_init() to initialize the request block: use blk_rq_init() to initialize the request block: rename and export rq_init() block: no need to initialize rq->cmd with blk_get_request block: no need to initialize rq->cmd in prepare_flush_fn hook block/blk-barrier.c:blk_ordered_cur_seq() mustn't be inline block/elevator.c:elv_rq_merge_ok() mustn't be inline block: make queue flags non-atomic block: add dma alignment and padding support to blk_rq_map_kern unexport blk_max_pfn ps3disk: Remove superfluous cast block: make rq_init() do a full memset() relay: fix splice problem
2 parents fee4b19 + ac9fafa commit bd5d435

38 files changed

Lines changed: 275 additions & 120 deletions

‎block/blk-barrier.c‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ EXPORT_SYMBOL(blk_queue_ordered);
5353
/*
5454
* Cache flushing for ordered writes handling
5555
*/
56-
inline unsigned blk_ordered_cur_seq(struct request_queue *q)
56+
unsigned blk_ordered_cur_seq(struct request_queue *q)
5757
{
5858
if (!q->ordseq)
5959
return 0;
@@ -143,10 +143,8 @@ static void queue_flush(struct request_queue *q, unsigned which)
143143
end_io = post_flush_end_io;
144144
}
145145

146+
blk_rq_init(q, rq);
146147
rq->cmd_flags = REQ_HARDBARRIER;
147-
rq_init(q, rq);
148-
rq->elevator_private = NULL;
149-
rq->elevator_private2 = NULL;
150148
rq->rq_disk = q->bar_rq.rq_disk;
151149
rq->end_io = end_io;
152150
q->prepare_flush_fn(q, rq);
@@ -167,14 +165,11 @@ static inline struct request *start_ordered(struct request_queue *q,
167165
blkdev_dequeue_request(rq);
168166
q->orig_bar_rq = rq;
169167
rq = &q->bar_rq;
170-
rq->cmd_flags = 0;
171-
rq_init(q, rq);
168+
blk_rq_init(q, rq);
172169
if (bio_data_dir(q->orig_bar_rq->bio) == WRITE)
173170
rq->cmd_flags |= REQ_RW;
174171
if (q->ordered & QUEUE_ORDERED_FUA)
175172
rq->cmd_flags |= REQ_FUA;
176-
rq->elevator_private = NULL;
177-
rq->elevator_private2 = NULL;
178173
init_request_from_bio(rq, q->orig_bar_rq->bio);
179174
rq->end_io = bar_end_io;
180175

‎block/blk-core.c‎

Lines changed: 34 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -107,41 +107,21 @@ struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev)
107107
}
108108
EXPORT_SYMBOL(blk_get_backing_dev_info);
109109

110-
/*
111-
* We can't just memset() the structure, since the allocation path
112-
* already stored some information in the request.
113-
*/
114-
void rq_init(struct request_queue *q, struct request *rq)
110+
void blk_rq_init(struct request_queue *q, struct request *rq)
115111
{
112+
memset(rq, 0, sizeof(*rq));
113+
116114
INIT_LIST_HEAD(&rq->queuelist);
117115
INIT_LIST_HEAD(&rq->donelist);
118116
rq->q = q;
119117
rq->sector = rq->hard_sector = (sector_t) -1;
120-
rq->nr_sectors = rq->hard_nr_sectors = 0;
121-
rq->current_nr_sectors = rq->hard_cur_sectors = 0;
122-
rq->bio = rq->biotail = NULL;
123118
INIT_HLIST_NODE(&rq->hash);
124119
RB_CLEAR_NODE(&rq->rb_node);
125-
rq->rq_disk = NULL;
126-
rq->nr_phys_segments = 0;
127-
rq->nr_hw_segments = 0;
128-
rq->ioprio = 0;
129-
rq->special = NULL;
130-
rq->buffer = NULL;
120+
rq->cmd = rq->__cmd;
131121
rq->tag = -1;
132-
rq->errors = 0;
133122
rq->ref_count = 1;
134-
rq->cmd_len = 0;
135-
memset(rq->cmd, 0, sizeof(rq->cmd));
136-
rq->data_len = 0;
137-
rq->extra_len = 0;
138-
rq->sense_len = 0;
139-
rq->data = NULL;
140-
rq->sense = NULL;
141-
rq->end_io = NULL;
142-
rq->end_io_data = NULL;
143-
rq->next_rq = NULL;
144123
}
124+
EXPORT_SYMBOL(blk_rq_init);
145125

146126
static void req_bio_endio(struct request *rq, struct bio *bio,
147127
unsigned int nbytes, int error)
@@ -194,7 +174,7 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
194174

195175
if (blk_pc_request(rq)) {
196176
printk(KERN_INFO " cdb: ");
197-
for (bit = 0; bit < sizeof(rq->cmd); bit++)
177+
for (bit = 0; bit < BLK_MAX_CDB; bit++)
198178
printk("%02x ", rq->cmd[bit]);
199179
printk("\n");
200180
}
@@ -220,7 +200,8 @@ void blk_plug_device(struct request_queue *q)
220200
if (blk_queue_stopped(q))
221201
return;
222202

223-
if (!test_and_set_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags)) {
203+
if (!test_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags)) {
204+
__set_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags);
224205
mod_timer(&q->unplug_timer, jiffies + q->unplug_delay);
225206
blk_add_trace_generic(q, NULL, 0, BLK_TA_PLUG);
226207
}
@@ -235,9 +216,10 @@ int blk_remove_plug(struct request_queue *q)
235216
{
236217
WARN_ON(!irqs_disabled());
237218

238-
if (!test_and_clear_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags))
219+
if (!test_bit(QUEUE_FLAG_PLUGGED, &q->queue_flags))
239220
return 0;
240221

222+
queue_flag_clear(QUEUE_FLAG_PLUGGED, q);
241223
del_timer(&q->unplug_timer);
242224
return 1;
243225
}
@@ -333,15 +315,16 @@ void blk_start_queue(struct request_queue *q)
333315
{
334316
WARN_ON(!irqs_disabled());
335317

336-
clear_bit(QUEUE_FLAG_STOPPED, &q->queue_flags);
318+
queue_flag_clear(QUEUE_FLAG_STOPPED, q);
337319

338320
/*
339321
* one level of recursion is ok and is much faster than kicking
340322
* the unplug handling
341323
*/
342-
if (!test_and_set_bit(QUEUE_FLAG_REENTER, &q->queue_flags)) {
324+
if (!test_bit(QUEUE_FLAG_REENTER, &q->queue_flags)) {
325+
queue_flag_set(QUEUE_FLAG_REENTER, q);
343326
q->request_fn(q);
344-
clear_bit(QUEUE_FLAG_REENTER, &q->queue_flags);
327+
queue_flag_clear(QUEUE_FLAG_REENTER, q);
345328
} else {
346329
blk_plug_device(q);
347330
kblockd_schedule_work(&q->unplug_work);
@@ -366,7 +349,7 @@ EXPORT_SYMBOL(blk_start_queue);
366349
void blk_stop_queue(struct request_queue *q)
367350
{
368351
blk_remove_plug(q);
369-
set_bit(QUEUE_FLAG_STOPPED, &q->queue_flags);
352+
queue_flag_set(QUEUE_FLAG_STOPPED, q);
370353
}
371354
EXPORT_SYMBOL(blk_stop_queue);
372355

@@ -395,27 +378,37 @@ EXPORT_SYMBOL(blk_sync_queue);
395378
* blk_run_queue - run a single device queue
396379
* @q: The queue to run
397380
*/
398-
void blk_run_queue(struct request_queue *q)
381+
void __blk_run_queue(struct request_queue *q)
399382
{
400-
unsigned long flags;
401-
402-
spin_lock_irqsave(q->queue_lock, flags);
403383
blk_remove_plug(q);
404384

405385
/*
406386
* Only recurse once to avoid overrunning the stack, let the unplug
407387
* handling reinvoke the handler shortly if we already got there.
408388
*/
409389
if (!elv_queue_empty(q)) {
410-
if (!test_and_set_bit(QUEUE_FLAG_REENTER, &q->queue_flags)) {
390+
if (!test_bit(QUEUE_FLAG_REENTER, &q->queue_flags)) {
391+
queue_flag_set(QUEUE_FLAG_REENTER, q);
411392
q->request_fn(q);
412-
clear_bit(QUEUE_FLAG_REENTER, &q->queue_flags);
393+
queue_flag_clear(QUEUE_FLAG_REENTER, q);
413394
} else {
414395
blk_plug_device(q);
415396
kblockd_schedule_work(&q->unplug_work);
416397
}
417398
}
399+
}
400+
EXPORT_SYMBOL(__blk_run_queue);
401+
402+
/**
403+
* blk_run_queue - run a single device queue
404+
* @q: The queue to run
405+
*/
406+
void blk_run_queue(struct request_queue *q)
407+
{
408+
unsigned long flags;
418409

410+
spin_lock_irqsave(q->queue_lock, flags);
411+
__blk_run_queue(q);
419412
spin_unlock_irqrestore(q->queue_lock, flags);
420413
}
421414
EXPORT_SYMBOL(blk_run_queue);
@@ -428,7 +421,7 @@ void blk_put_queue(struct request_queue *q)
428421
void blk_cleanup_queue(struct request_queue *q)
429422
{
430423
mutex_lock(&q->sysfs_lock);
431-
set_bit(QUEUE_FLAG_DEAD, &q->queue_flags);
424+
queue_flag_set_unlocked(QUEUE_FLAG_DEAD, q);
432425
mutex_unlock(&q->sysfs_lock);
433426

434427
if (q->elevator)
@@ -607,6 +600,8 @@ blk_alloc_request(struct request_queue *q, int rw, int priv, gfp_t gfp_mask)
607600
if (!rq)
608601
return NULL;
609602

603+
blk_rq_init(q, rq);
604+
610605
/*
611606
* first three bits are identical in rq->cmd_flags and bio->bi_rw,
612607
* see bio.h and blkdev.h
@@ -789,8 +784,6 @@ static struct request *get_request(struct request_queue *q, int rw_flags,
789784
if (ioc_batching(q, ioc))
790785
ioc->nr_batch_requests--;
791786

792-
rq_init(q, rq);
793-
794787
blk_add_trace_generic(q, bio, rw, BLK_TA_GETRQ);
795788
out:
796789
return rq;

‎block/blk-map.c‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,43 @@ EXPORT_SYMBOL(blk_rq_unmap_user);
255255
* @kbuf: the kernel buffer
256256
* @len: length of user data
257257
* @gfp_mask: memory allocation flags
258+
*
259+
* Description:
260+
* Data will be mapped directly if possible. Otherwise a bounce
261+
* buffer is used.
258262
*/
259263
int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
260264
unsigned int len, gfp_t gfp_mask)
261265
{
266+
unsigned long kaddr;
267+
unsigned int alignment;
268+
int reading = rq_data_dir(rq) == READ;
269+
int do_copy = 0;
262270
struct bio *bio;
263271

264272
if (len > (q->max_hw_sectors << 9))
265273
return -EINVAL;
266274
if (!len || !kbuf)
267275
return -EINVAL;
268276

269-
bio = bio_map_kern(q, kbuf, len, gfp_mask);
277+
kaddr = (unsigned long)kbuf;
278+
alignment = queue_dma_alignment(q) | q->dma_pad_mask;
279+
do_copy = ((kaddr & alignment) || (len & alignment));
280+
281+
if (do_copy)
282+
bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
283+
else
284+
bio = bio_map_kern(q, kbuf, len, gfp_mask);
285+
270286
if (IS_ERR(bio))
271287
return PTR_ERR(bio);
272288

273289
if (rq_data_dir(rq) == WRITE)
274290
bio->bi_rw |= (1 << BIO_RW);
275291

292+
if (do_copy)
293+
rq->cmd_flags |= REQ_COPY_USER;
294+
276295
blk_rq_bio_prep(q, rq, bio);
277296
blk_queue_bounce(q, &rq->bio);
278297
rq->buffer = rq->data = NULL;

‎block/blk-merge.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void blk_recalc_rq_segments(struct request *rq)
5555
if (!rq->bio)
5656
return;
5757

58-
cluster = q->queue_flags & (1 << QUEUE_FLAG_CLUSTER);
58+
cluster = test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
5959
hw_seg_size = seg_size = 0;
6060
phys_size = hw_size = nr_phys_segs = nr_hw_segs = 0;
6161
rq_for_each_segment(bv, rq, iter) {
@@ -128,7 +128,7 @@ EXPORT_SYMBOL(blk_recount_segments);
128128
static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
129129
struct bio *nxt)
130130
{
131-
if (!(q->queue_flags & (1 << QUEUE_FLAG_CLUSTER)))
131+
if (!test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags))
132132
return 0;
133133

134134
if (!BIOVEC_PHYS_MERGEABLE(__BVEC_END(bio), __BVEC_START(nxt)))
@@ -175,7 +175,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
175175
int nsegs, cluster;
176176

177177
nsegs = 0;
178-
cluster = q->queue_flags & (1 << QUEUE_FLAG_CLUSTER);
178+
cluster = test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
179179

180180
/*
181181
* for each bio in rq

‎block/blk-settings.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ unsigned long blk_max_low_pfn;
1414
EXPORT_SYMBOL(blk_max_low_pfn);
1515

1616
unsigned long blk_max_pfn;
17-
EXPORT_SYMBOL(blk_max_pfn);
1817

1918
/**
2019
* blk_queue_prep_rq - set a prepare_request function for queue
@@ -288,7 +287,7 @@ void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b)
288287
t->max_segment_size = min(t->max_segment_size, b->max_segment_size);
289288
t->hardsect_size = max(t->hardsect_size, b->hardsect_size);
290289
if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags))
291-
clear_bit(QUEUE_FLAG_CLUSTER, &t->queue_flags);
290+
queue_flag_clear(QUEUE_FLAG_CLUSTER, t);
292291
}
293292
EXPORT_SYMBOL(blk_queue_stack_limits);
294293

‎block/blk-sysfs.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,25 @@ static ssize_t queue_max_hw_sectors_show(struct request_queue *q, char *page)
135135
return queue_var_show(max_hw_sectors_kb, (page));
136136
}
137137

138+
static ssize_t queue_nomerges_show(struct request_queue *q, char *page)
139+
{
140+
return queue_var_show(blk_queue_nomerges(q), page);
141+
}
142+
143+
static ssize_t queue_nomerges_store(struct request_queue *q, const char *page,
144+
size_t count)
145+
{
146+
unsigned long nm;
147+
ssize_t ret = queue_var_store(&nm, page, count);
148+
149+
if (nm)
150+
set_bit(QUEUE_FLAG_NOMERGES, &q->queue_flags);
151+
else
152+
clear_bit(QUEUE_FLAG_NOMERGES, &q->queue_flags);
153+
154+
return ret;
155+
}
156+
138157

139158
static struct queue_sysfs_entry queue_requests_entry = {
140159
.attr = {.name = "nr_requests", .mode = S_IRUGO | S_IWUSR },
@@ -170,13 +189,20 @@ static struct queue_sysfs_entry queue_hw_sector_size_entry = {
170189
.show = queue_hw_sector_size_show,
171190
};
172191

192+
static struct queue_sysfs_entry queue_nomerges_entry = {
193+
.attr = {.name = "nomerges", .mode = S_IRUGO | S_IWUSR },
194+
.show = queue_nomerges_show,
195+
.store = queue_nomerges_store,
196+
};
197+
173198
static struct attribute *default_attrs[] = {
174199
&queue_requests_entry.attr,
175200
&queue_ra_entry.attr,
176201
&queue_max_hw_sectors_entry.attr,
177202
&queue_max_sectors_entry.attr,
178203
&queue_iosched_entry.attr,
179204
&queue_hw_sector_size_entry.attr,
205+
&queue_nomerges_entry.attr,
180206
NULL,
181207
};
182208

‎block/blk-tag.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void __blk_queue_free_tags(struct request_queue *q)
7070
__blk_free_tags(bqt);
7171

7272
q->queue_tags = NULL;
73-
q->queue_flags &= ~(1 << QUEUE_FLAG_QUEUED);
73+
queue_flag_clear(QUEUE_FLAG_QUEUED, q);
7474
}
7575

7676
/**
@@ -98,7 +98,7 @@ EXPORT_SYMBOL(blk_free_tags);
9898
**/
9999
void blk_queue_free_tags(struct request_queue *q)
100100
{
101-
clear_bit(QUEUE_FLAG_QUEUED, &q->queue_flags);
101+
queue_flag_clear(QUEUE_FLAG_QUEUED, q);
102102
}
103103
EXPORT_SYMBOL(blk_queue_free_tags);
104104

@@ -188,7 +188,7 @@ int blk_queue_init_tags(struct request_queue *q, int depth,
188188
rc = blk_queue_resize_tags(q, depth);
189189
if (rc)
190190
return rc;
191-
set_bit(QUEUE_FLAG_QUEUED, &q->queue_flags);
191+
queue_flag_set(QUEUE_FLAG_QUEUED, q);
192192
return 0;
193193
} else
194194
atomic_inc(&tags->refcnt);
@@ -197,7 +197,7 @@ int blk_queue_init_tags(struct request_queue *q, int depth,
197197
* assign it, all done
198198
*/
199199
q->queue_tags = tags;
200-
q->queue_flags |= (1 << QUEUE_FLAG_QUEUED);
200+
queue_flag_set(QUEUE_FLAG_QUEUED, q);
201201
INIT_LIST_HEAD(&q->tag_busy_list);
202202
return 0;
203203
fail:

‎block/blk.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
extern struct kmem_cache *blk_requestq_cachep;
1111
extern struct kobj_type blk_queue_ktype;
1212

13-
void rq_init(struct request_queue *q, struct request *rq);
1413
void init_request_from_bio(struct request *req, struct bio *bio);
1514
void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
1615
struct bio *bio);

0 commit comments

Comments
 (0)