]> Git Repo - linux.git/commitdiff
Merge branch 'blk-mq/core' into for-3.13/core
authorJens Axboe <[email protected]>
Fri, 8 Nov 2013 16:08:12 +0000 (09:08 -0700)
committerJens Axboe <[email protected]>
Fri, 8 Nov 2013 16:08:12 +0000 (09:08 -0700)
Signed-off-by: Jens Axboe <[email protected]>
Conflicts:
block/blk-timeout.c

1  2 
block/blk-core.c
block/blk-timeout.c
drivers/scsi/sd.c
include/linux/bio.h

diff --combined block/blk-core.c
index 25f13479f552562bc2e406f3ebed2bf150e93fe9,936876ab662dffcbb3c0f23f8819debbdf90b348..8bdd0121212a51a1dba3c568c5a6a3e070447318
@@@ -16,6 -16,7 +16,7 @@@
  #include <linux/backing-dev.h>
  #include <linux/bio.h>
  #include <linux/blkdev.h>
+ #include <linux/blk-mq.h>
  #include <linux/highmem.h>
  #include <linux/mm.h>
  #include <linux/kernel_stat.h>
@@@ -48,7 -49,7 +49,7 @@@ DEFINE_IDA(blk_queue_ida)
  /*
   * For the allocated request tables
   */
- static struct kmem_cache *request_cachep;
+ struct kmem_cache *request_cachep = NULL;
  
  /*
   * For queue allocation
@@@ -60,42 -61,6 +61,6 @@@ struct kmem_cache *blk_requestq_cachep
   */
  static struct workqueue_struct *kblockd_workqueue;
  
- static void drive_stat_acct(struct request *rq, int new_io)
- {
-       struct hd_struct *part;
-       int rw = rq_data_dir(rq);
-       int cpu;
-       if (!blk_do_io_stat(rq))
-               return;
-       cpu = part_stat_lock();
-       if (!new_io) {
-               part = rq->part;
-               part_stat_inc(cpu, part, merges[rw]);
-       } else {
-               part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq));
-               if (!hd_struct_try_get(part)) {
-                       /*
-                        * The partition is already being removed,
-                        * the request will be accounted on the disk only
-                        *
-                        * We take a reference on disk->part0 although that
-                        * partition will never be deleted, so we can treat
-                        * it as any other partition.
-                        */
-                       part = &rq->rq_disk->part0;
-                       hd_struct_get(part);
-               }
-               part_round_stats(cpu, part);
-               part_inc_in_flight(part, rw);
-               rq->part = part;
-       }
-       part_stat_unlock();
- }
  void blk_queue_congestion_threshold(struct request_queue *q)
  {
        int nr;
@@@ -145,7 -110,6 +110,6 @@@ void blk_rq_init(struct request_queue *
        rq->cmd = rq->__cmd;
        rq->cmd_len = BLK_MAX_CDB;
        rq->tag = -1;
-       rq->ref_count = 1;
        rq->start_time = jiffies;
        set_start_time_ns(rq);
        rq->part = NULL;
@@@ -174,9 -138,9 +138,9 @@@ void blk_dump_rq_flags(struct request *
  {
        int bit;
  
-       printk(KERN_INFO "%s: dev %s: type=%x, flags=%x\n", msg,
+       printk(KERN_INFO "%s: dev %s: type=%x, flags=%llx\n", msg,
                rq->rq_disk ? rq->rq_disk->disk_name : "?", rq->cmd_type,
-               rq->cmd_flags);
+               (unsigned long long) rq->cmd_flags);
  
        printk(KERN_INFO "  sector %llu, nr/cnr %u/%u\n",
               (unsigned long long)blk_rq_pos(rq),
@@@ -595,9 -559,12 +559,12 @@@ struct request_queue *blk_alloc_queue_n
        if (!q)
                return NULL;
  
+       if (percpu_counter_init(&q->mq_usage_counter, 0))
+               goto fail_q;
        q->id = ida_simple_get(&blk_queue_ida, 0, 0, gfp_mask);
        if (q->id < 0)
-               goto fail_q;
+               goto fail_c;
  
        q->backing_dev_info.ra_pages =
                        (VM_MAX_READAHEAD * 1024) / PAGE_CACHE_SIZE;
        q->bypass_depth = 1;
        __set_bit(QUEUE_FLAG_BYPASS, &q->queue_flags);
  
+       init_waitqueue_head(&q->mq_freeze_wq);
        if (blkcg_init_queue(q))
 -              goto fail_id;
 +              goto fail_bdi;
  
        return q;
  
 +fail_bdi:
 +      bdi_destroy(&q->backing_dev_info);
  fail_id:
        ida_simple_remove(&blk_queue_ida, q->id);
+ fail_c:
+       percpu_counter_destroy(&q->mq_usage_counter);
  fail_q:
        kmem_cache_free(blk_requestq_cachep, q);
        return NULL;
@@@ -741,17 -710,9 +712,17 @@@ blk_init_allocated_queue(struct request
  
        q->sg_reserved_size = INT_MAX;
  
 +      /* Protect q->elevator from elevator_change */
 +      mutex_lock(&q->sysfs_lock);
 +
        /* init elevator */
 -      if (elevator_init(q, NULL))
 +      if (elevator_init(q, NULL)) {
 +              mutex_unlock(&q->sysfs_lock);
                return NULL;
 +      }
 +
 +      mutex_unlock(&q->sysfs_lock);
 +
        return q;
  }
  EXPORT_SYMBOL(blk_init_allocated_queue);
@@@ -1119,7 -1080,8 +1090,8 @@@ retry
        goto retry;
  }
  
- struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
+ static struct request *blk_old_get_request(struct request_queue *q, int rw,
+               gfp_t gfp_mask)
  {
        struct request *rq;
  
  
        return rq;
  }
+ struct request *blk_get_request(struct request_queue *q, int rw, gfp_t gfp_mask)
+ {
+       if (q->mq_ops)
+               return blk_mq_alloc_request(q, rw, gfp_mask, false);
+       else
+               return blk_old_get_request(q, rw, gfp_mask);
+ }
  EXPORT_SYMBOL(blk_get_request);
  
  /**
@@@ -1221,7 -1191,7 +1201,7 @@@ EXPORT_SYMBOL(blk_requeue_request)
  static void add_acct_request(struct request_queue *q, struct request *rq,
                             int where)
  {
-       drive_stat_acct(rq, 1);
+       blk_account_io_start(rq, true);
        __elv_add_request(q, rq, where);
  }
  
@@@ -1282,8 -1252,6 +1262,6 @@@ void __blk_put_request(struct request_q
  {
        if (unlikely(!q))
                return;
-       if (unlikely(--req->ref_count))
-               return;
  
        blk_pm_put_request(req);
  
@@@ -1312,12 -1280,17 +1290,17 @@@ EXPORT_SYMBOL_GPL(__blk_put_request)
  
  void blk_put_request(struct request *req)
  {
-       unsigned long flags;
        struct request_queue *q = req->q;
  
-       spin_lock_irqsave(q->queue_lock, flags);
-       __blk_put_request(q, req);
-       spin_unlock_irqrestore(q->queue_lock, flags);
+       if (q->mq_ops)
+               blk_mq_free_request(req);
+       else {
+               unsigned long flags;
+               spin_lock_irqsave(q->queue_lock, flags);
+               __blk_put_request(q, req);
+               spin_unlock_irqrestore(q->queue_lock, flags);
+       }
  }
  EXPORT_SYMBOL(blk_put_request);
  
@@@ -1353,8 -1326,8 +1336,8 @@@ void blk_add_request_payload(struct req
  }
  EXPORT_SYMBOL_GPL(blk_add_request_payload);
  
static bool bio_attempt_back_merge(struct request_queue *q, struct request *req,
-                                  struct bio *bio)
+ bool bio_attempt_back_merge(struct request_queue *q, struct request *req,
+                           struct bio *bio)
  {
        const int ff = bio->bi_rw & REQ_FAILFAST_MASK;
  
        req->__data_len += bio->bi_size;
        req->ioprio = ioprio_best(req->ioprio, bio_prio(bio));
  
-       drive_stat_acct(req, 0);
+       blk_account_io_start(req, false);
        return true;
  }
  
static bool bio_attempt_front_merge(struct request_queue *q,
-                                   struct request *req, struct bio *bio)
bool bio_attempt_front_merge(struct request_queue *q, struct request *req,
+                            struct bio *bio)
  {
        const int ff = bio->bi_rw & REQ_FAILFAST_MASK;
  
        req->__data_len += bio->bi_size;
        req->ioprio = ioprio_best(req->ioprio, bio_prio(bio));
  
-       drive_stat_acct(req, 0);
+       blk_account_io_start(req, false);
        return true;
  }
  
  /**
-  * attempt_plug_merge - try to merge with %current's plugged list
+  * blk_attempt_plug_merge - try to merge with %current's plugged list
   * @q: request_queue new bio is being queued at
   * @bio: new bio being queued
   * @request_count: out parameter for number of traversed plugged requests
   * reliable access to the elevator outside queue lock.  Only check basic
   * merging parameters without querying the elevator.
   */
static bool attempt_plug_merge(struct request_queue *q, struct bio *bio,
-                              unsigned int *request_count)
bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
+                           unsigned int *request_count)
  {
        struct blk_plug *plug;
        struct request *rq;
        bool ret = false;
+       struct list_head *plug_list;
  
 +      if (blk_queue_nomerges(q))
 +              goto out;
 +
        plug = current->plug;
        if (!plug)
                goto out;
        *request_count = 0;
  
-       list_for_each_entry_reverse(rq, &plug->list, queuelist) {
+       if (q->mq_ops)
+               plug_list = &plug->mq_list;
+       else
+               plug_list = &plug->list;
+       list_for_each_entry_reverse(rq, plug_list, queuelist) {
                int el_ret;
  
                if (rq->q == q)
@@@ -1505,7 -1481,7 +1494,7 @@@ void blk_queue_bio(struct request_queu
         * Check if we can merge with the plugged list before grabbing
         * any locks.
         */
-       if (attempt_plug_merge(q, bio, &request_count))
+       if (blk_attempt_plug_merge(q, bio, &request_count))
                return;
  
        spin_lock_irq(q->queue_lock);
@@@ -1573,7 -1549,7 +1562,7 @@@ get_rq
                        }
                }
                list_add_tail(&req->queuelist, &plug->list);
-               drive_stat_acct(req, 1);
+               blk_account_io_start(req, true);
        } else {
                spin_lock_irq(q->queue_lock);
                add_acct_request(q, req, where);
@@@ -2027,7 -2003,7 +2016,7 @@@ unsigned int blk_rq_err_bytes(const str
  }
  EXPORT_SYMBOL_GPL(blk_rq_err_bytes);
  
static void blk_account_io_completion(struct request *req, unsigned int bytes)
+ void blk_account_io_completion(struct request *req, unsigned int bytes)
  {
        if (blk_do_io_stat(req)) {
                const int rw = rq_data_dir(req);
        }
  }
  
static void blk_account_io_done(struct request *req)
+ void blk_account_io_done(struct request *req)
  {
        /*
         * Account IO completion.  flush_rq isn't accounted as a
@@@ -2089,6 -2065,42 +2078,42 @@@ static inline struct request *blk_pm_pe
  }
  #endif
  
+ void blk_account_io_start(struct request *rq, bool new_io)
+ {
+       struct hd_struct *part;
+       int rw = rq_data_dir(rq);
+       int cpu;
+       if (!blk_do_io_stat(rq))
+               return;
+       cpu = part_stat_lock();
+       if (!new_io) {
+               part = rq->part;
+               part_stat_inc(cpu, part, merges[rw]);
+       } else {
+               part = disk_map_sector_rcu(rq->rq_disk, blk_rq_pos(rq));
+               if (!hd_struct_try_get(part)) {
+                       /*
+                        * The partition is already being removed,
+                        * the request will be accounted on the disk only
+                        *
+                        * We take a reference on disk->part0 although that
+                        * partition will never be deleted, so we can treat
+                        * it as any other partition.
+                        */
+                       part = &rq->rq_disk->part0;
+                       hd_struct_get(part);
+               }
+               part_round_stats(cpu, part);
+               part_inc_in_flight(part, rw);
+               rq->part = part;
+       }
+       part_stat_unlock();
+ }
  /**
   * blk_peek_request - peek at the top of a request queue
   * @q: request queue to peek at
@@@ -2240,7 -2252,6 +2265,7 @@@ void blk_start_request(struct request *
        if (unlikely(blk_bidi_rq(req)))
                req->next_rq->resid_len = blk_rq_bytes(req->next_rq);
  
 +      BUG_ON(test_bit(REQ_ATOM_COMPLETE, &req->atomic_flags));
        blk_add_timer(req);
  }
  EXPORT_SYMBOL(blk_start_request);
@@@ -2465,7 -2476,6 +2490,6 @@@ static void blk_finish_request(struct r
        if (req->cmd_flags & REQ_DONTPREP)
                blk_unprep_request(req);
  
        blk_account_io_done(req);
  
        if (req->end_io)
@@@ -2887,6 -2897,7 +2911,7 @@@ void blk_start_plug(struct blk_plug *pl
  
        plug->magic = PLUG_MAGIC;
        INIT_LIST_HEAD(&plug->list);
+       INIT_LIST_HEAD(&plug->mq_list);
        INIT_LIST_HEAD(&plug->cb_list);
  
        /*
@@@ -2984,6 -2995,10 +3009,10 @@@ void blk_flush_plug_list(struct blk_plu
        BUG_ON(plug->magic != PLUG_MAGIC);
  
        flush_plug_callbacks(plug, from_schedule);
+       if (!list_empty(&plug->mq_list))
+               blk_mq_flush_plug_list(plug, from_schedule);
        if (list_empty(&plug->list))
                return;
  
diff --combined block/blk-timeout.c
index abf725c655fc0ecece67e80990e9fca92bf87c48,22846cf3595abbb4d93faeef52c4e2de81a740bf..bba81c9348e1cca630fc9d2515f27633d997c03a
@@@ -7,6 -7,7 +7,7 @@@
  #include <linux/fault-inject.h>
  
  #include "blk.h"
+ #include "blk-mq.h"
  
  #ifdef CONFIG_FAIL_IO_TIMEOUT
  
@@@ -31,7 -32,7 +32,7 @@@ static int __init fail_io_timeout_debug
        struct dentry *dir = fault_create_debugfs_attr("fail_io_timeout",
                                                NULL, &fail_io_timeout);
  
 -      return IS_ERR(dir) ? PTR_ERR(dir) : 0;
 +      return PTR_ERR_OR_ZERO(dir);
  }
  
  late_initcall(fail_io_timeout_debugfs);
@@@ -88,11 -89,18 +89,19 @@@ static void blk_rq_timed_out(struct req
                ret = q->rq_timed_out_fn(req);
        switch (ret) {
        case BLK_EH_HANDLED:
-               __blk_complete_request(req);
+               /* Can we use req->errors here? */
+               if (q->mq_ops)
+                       blk_mq_complete_request(req, req->errors);
+               else
+                       __blk_complete_request(req);
                break;
        case BLK_EH_RESET_TIMER:
-               blk_add_timer(req);
 -              blk_clear_rq_complete(req);
+               if (q->mq_ops)
+                       blk_mq_add_timer(req);
+               else
+                       blk_add_timer(req);
++
 +              blk_clear_rq_complete(req);
                break;
        case BLK_EH_NOT_HANDLED:
                /*
        }
  }
  
+ void blk_rq_check_expired(struct request *rq, unsigned long *next_timeout,
+                         unsigned int *next_set)
+ {
+       if (time_after_eq(jiffies, rq->deadline)) {
+               list_del_init(&rq->timeout_list);
+               /*
+                * Check if we raced with end io completion
+                */
+               if (!blk_mark_rq_complete(rq))
+                       blk_rq_timed_out(rq);
+       } else if (!*next_set || time_after(*next_timeout, rq->deadline)) {
+               *next_timeout = rq->deadline;
+               *next_set = 1;
+       }
+ }
  void blk_rq_timed_out_timer(unsigned long data)
  {
        struct request_queue *q = (struct request_queue *) data;
  
        spin_lock_irqsave(q->queue_lock, flags);
  
-       list_for_each_entry_safe(rq, tmp, &q->timeout_list, timeout_list) {
-               if (time_after_eq(jiffies, rq->deadline)) {
-                       list_del_init(&rq->timeout_list);
-                       /*
-                        * Check if we raced with end io completion
-                        */
-                       if (blk_mark_rq_complete(rq))
-                               continue;
-                       blk_rq_timed_out(rq);
-               } else if (!next_set || time_after(next, rq->deadline)) {
-                       next = rq->deadline;
-                       next_set = 1;
-               }
-       }
+       list_for_each_entry_safe(rq, tmp, &q->timeout_list, timeout_list)
+               blk_rq_check_expired(rq, &next, &next_set);
  
        if (next_set)
                mod_timer(&q->timeout, round_jiffies_up(next));
@@@ -157,15 -169,7 +170,7 @@@ void blk_abort_request(struct request *
  }
  EXPORT_SYMBOL_GPL(blk_abort_request);
  
- /**
-  * blk_add_timer - Start timeout timer for a single request
-  * @req:      request that is about to start running.
-  *
-  * Notes:
-  *    Each request has its own timer, and as it is added to the queue, we
-  *    set up the timer. When the request completes, we cancel the timer.
-  */
- void blk_add_timer(struct request *req)
+ void __blk_add_timer(struct request *req, struct list_head *timeout_list)
  {
        struct request_queue *q = req->q;
        unsigned long expiry;
                return;
  
        BUG_ON(!list_empty(&req->timeout_list));
 -      BUG_ON(test_bit(REQ_ATOM_COMPLETE, &req->atomic_flags));
  
        /*
         * Some LLDs, like scsi, peek at the timeout to prevent a
                req->timeout = q->rq_timeout;
  
        req->deadline = jiffies + req->timeout;
-       list_add_tail(&req->timeout_list, &q->timeout_list);
+       if (timeout_list)
+               list_add_tail(&req->timeout_list, timeout_list);
  
        /*
         * If the timer isn't already pending or this timeout is earlier
        if (!timer_pending(&q->timeout) ||
            time_before(expiry, q->timeout.expires))
                mod_timer(&q->timeout, expiry);
+ }
+ /**
+  * blk_add_timer - Start timeout timer for a single request
+  * @req:      request that is about to start running.
+  *
+  * Notes:
+  *    Each request has its own timer, and as it is added to the queue, we
+  *    set up the timer. When the request completes, we cancel the timer.
+  */
+ void blk_add_timer(struct request *req)
+ {
+       __blk_add_timer(req, &req->q->timeout_list);
  }
  
diff --combined drivers/scsi/sd.c
index 5693f6d7eddb8b20cd9b3e0374a4e73e60ab7aa2,dae6133a538d967d0285730c0228c5bbd6f02872..7fe4faaa149bf78515694e196105612536c0119c
@@@ -1002,7 -1002,7 +1002,7 @@@ static int sd_prep_fn(struct request_qu
                SCpnt->cmnd[0] = READ_6;
                SCpnt->sc_data_direction = DMA_FROM_DEVICE;
        } else {
-               scmd_printk(KERN_ERR, SCpnt, "Unknown command %x\n", rq->cmd_flags);
+               scmd_printk(KERN_ERR, SCpnt, "Unknown command %llx\n", (unsigned long long) rq->cmd_flags);
                goto out;
        }
  
@@@ -2854,7 -2854,6 +2854,7 @@@ static void sd_probe_async(void *data, 
                gd->events |= DISK_EVENT_MEDIA_CHANGE;
        }
  
 +      blk_pm_runtime_init(sdp->request_queue, dev);
        add_disk(gd);
        if (sdkp->capacity)
                sd_dif_config_host(sdkp);
  
        sd_printk(KERN_NOTICE, sdkp, "Attached SCSI %sdisk\n",
                  sdp->removable ? "removable " : "");
 -      blk_pm_runtime_init(sdp->request_queue, dev);
        scsi_autopm_put_device(sdp);
        put_device(&sdkp->dev);
  }
diff --combined include/linux/bio.h
index 162036aca741997f81449df43e5d54af5097c11a,4c2775443dcf8750d90b8ba910fe62b2f89cae0c..060ff695085c596f2ddcd2166e7825290d75bd3d
@@@ -218,7 -218,6 +218,7 @@@ struct bio_pair 
  };
  extern struct bio_pair *bio_split(struct bio *bi, int first_sectors);
  extern void bio_pair_release(struct bio_pair *dbio);
 +extern void bio_trim(struct bio *bio, int offset, int size);
  
  extern struct bio_set *bioset_create(unsigned int, unsigned int);
  extern void bioset_free(struct bio_set *);
@@@ -420,6 -419,8 +420,8 @@@ static inline void bio_list_init(struc
        bl->head = bl->tail = NULL;
  }
  
+ #define BIO_EMPTY_LIST        { NULL, NULL }
  #define bio_list_for_each(bio, bl) \
        for (bio = (bl)->head; bio; bio = bio->bi_next)
  
This page took 0.136071 seconds and 4 git commands to generate.