@@ -107,41 +107,21 @@ struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev)
107107}
108108EXPORT_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
146126static 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);
366349void 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}
371354EXPORT_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}
421414EXPORT_SYMBOL (blk_run_queue );
@@ -428,7 +421,7 @@ void blk_put_queue(struct request_queue *q)
428421void 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 );
795788out :
796789 return rq ;
0 commit comments