dm mpath: remove unnecessary casts in front of ti->private
[cascardo/linux.git] / drivers / md / dm-mpath.c
index 5b06a94..cfe5591 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/delay.h>
 #include <scsi/scsi_dh.h>
 #include <linux/atomic.h>
+#include <linux/blk-mq.h>
 
 #define DM_MSG_PREFIX "multipath"
 #define DM_PG_INIT_DELAY_MSECS 2000
@@ -228,30 +229,35 @@ static void free_multipath(struct multipath *m)
        kfree(m);
 }
 
-static int set_mapinfo(struct multipath *m, union map_info *info)
+static struct dm_mpath_io *get_mpio(union map_info *info)
+{
+       return info->ptr;
+}
+
+static struct dm_mpath_io *set_mpio(struct multipath *m, union map_info *info)
 {
        struct dm_mpath_io *mpio;
 
        if (!m->mpio_pool) {
                /* Use blk-mq pdu memory requested via per_io_data_size */
-               mpio = info->ptr;
+               mpio = get_mpio(info);
                memset(mpio, 0, sizeof(*mpio));
                return mpio;
        }
 
        mpio = mempool_alloc(m->mpio_pool, GFP_ATOMIC);
        if (!mpio)
-               return -ENOMEM;
+               return NULL;
 
        memset(mpio, 0, sizeof(*mpio));
        info->ptr = mpio;
 
-       return 0;
+       return mpio;
 }
 
-static void clear_mapinfo(struct multipath *m, union map_info *info)
+static void clear_request_fn_mpio(struct multipath *m, union map_info *info)
 {
-       /* Only needed for non blk-mq */
+       /* Only needed for non blk-mq (.request_fn) multipath */
        if (m->mpio_pool) {
                struct dm_mpath_io *mpio = info->ptr;
 
@@ -396,7 +402,7 @@ static int __multipath_map(struct dm_target *ti, struct request *clone,
                           union map_info *map_context,
                           struct request *rq, struct request **__clone)
 {
-       struct multipath *m = (struct multipath *) ti->private;
+       struct multipath *m = ti->private;
        int r = DM_MAPIO_REQUEUE;
        size_t nr_bytes = clone ? blk_rq_bytes(clone) : blk_rq_bytes(rq);
        struct pgpath *pgpath;
@@ -421,11 +427,11 @@ static int __multipath_map(struct dm_target *ti, struct request *clone,
                goto out_unlock;
        }
 
-       if (set_mapinfo(m, map_context) < 0)
+       mpio = set_mpio(m, map_context);
+       if (!mpio)
                /* ENOMEM, requeue */
                goto out_unlock;
 
-       mpio = map_context->ptr;
        mpio->pgpath = pgpath;
        mpio->nr_bytes = nr_bytes;
 
@@ -447,11 +453,11 @@ static int __multipath_map(struct dm_target *ti, struct request *clone,
                 * .request_fn stacked on blk-mq path(s) and
                 * blk-mq stacked on blk-mq path(s).
                 */
-               *__clone = blk_get_request(bdev_get_queue(bdev),
-                                          rq_data_dir(rq), GFP_ATOMIC);
+               *__clone = blk_mq_alloc_request(bdev_get_queue(bdev),
+                                               rq_data_dir(rq), BLK_MQ_REQ_NOWAIT);
                if (IS_ERR(*__clone)) {
                        /* ENOMEM, requeue */
-                       clear_mapinfo(m, map_context);
+                       clear_request_fn_mpio(m, map_context);
                        return r;
                }
                (*__clone)->bio = (*__clone)->biotail = NULL;
@@ -486,7 +492,7 @@ static int multipath_clone_and_map(struct dm_target *ti, struct request *rq,
 
 static void multipath_release_clone(struct request *clone)
 {
-       blk_put_request(clone);
+       blk_mq_free_request(clone);
 }
 
 /*
@@ -1317,21 +1323,21 @@ static int multipath_end_io(struct dm_target *ti, struct request *clone,
                            int error, union map_info *map_context)
 {
        struct multipath *m = ti->private;
-       struct dm_mpath_io *mpio = map_context->ptr;
+       struct dm_mpath_io *mpio = get_mpio(map_context);
        struct pgpath *pgpath;
        struct path_selector *ps;
        int r;
 
        BUG_ON(!mpio);
 
-       r  = do_end_io(m, clone, error, mpio);
+       r = do_end_io(m, clone, error, mpio);
        pgpath = mpio->pgpath;
        if (pgpath) {
                ps = &pgpath->pg->ps;
                if (ps->type->end_io)
                        ps->type->end_io(ps, &pgpath->path, mpio->nr_bytes);
        }
-       clear_mapinfo(m, map_context);
+       clear_request_fn_mpio(m, map_context);
 
        return r;
 }
@@ -1344,7 +1350,7 @@ static int multipath_end_io(struct dm_target *ti, struct request *clone,
  */
 static void multipath_presuspend(struct dm_target *ti)
 {
-       struct multipath *m = (struct multipath *) ti->private;
+       struct multipath *m = ti->private;
 
        queue_if_no_path(m, 0, 1);
 }
@@ -1363,7 +1369,7 @@ static void multipath_postsuspend(struct dm_target *ti)
  */
 static void multipath_resume(struct dm_target *ti)
 {
-       struct multipath *m = (struct multipath *) ti->private;
+       struct multipath *m = ti->private;
        unsigned long flags;
 
        spin_lock_irqsave(&m->lock, flags);
@@ -1392,7 +1398,7 @@ static void multipath_status(struct dm_target *ti, status_type_t type,
 {
        int sz = 0;
        unsigned long flags;
-       struct multipath *m = (struct multipath *) ti->private;
+       struct multipath *m = ti->private;
        struct priority_group *pg;
        struct pgpath *p;
        unsigned pg_num;
@@ -1500,7 +1506,7 @@ static int multipath_message(struct dm_target *ti, unsigned argc, char **argv)
 {
        int r = -EINVAL;
        struct dm_dev *dev;
-       struct multipath *m = (struct multipath *) ti->private;
+       struct multipath *m = ti->private;
        action_fn action;
 
        mutex_lock(&m->work_mutex);