]> Git Repo - linux.git/blobdiff - drivers/md/dm-thin.c
dm persistent data: add btree_walk
[linux.git] / drivers / md / dm-thin.c
index 5409607d487533593d29c2207d857896121364a3..35d9d0396cc23252e1b8aab56adb5948a24a2329 100644 (file)
@@ -26,6 +26,9 @@
 #define PRISON_CELLS 1024
 #define COMMIT_PERIOD HZ
 
+DECLARE_DM_KCOPYD_THROTTLE_WITH_MODULE_PARM(snapshot_copy_throttle,
+               "A percentage of time allocated for copy on write");
+
 /*
  * The block size of the device holding pool data must be
  * between 64KB and 1GB.
@@ -330,14 +333,20 @@ static void requeue_io(struct thin_c *tc)
  * target.
  */
 
+static bool block_size_is_power_of_two(struct pool *pool)
+{
+       return pool->sectors_per_block_shift >= 0;
+}
+
 static dm_block_t get_bio_block(struct thin_c *tc, struct bio *bio)
 {
+       struct pool *pool = tc->pool;
        sector_t block_nr = bio->bi_sector;
 
-       if (tc->pool->sectors_per_block_shift < 0)
-               (void) sector_div(block_nr, tc->pool->sectors_per_block);
+       if (block_size_is_power_of_two(pool))
+               block_nr >>= pool->sectors_per_block_shift;
        else
-               block_nr >>= tc->pool->sectors_per_block_shift;
+               (void) sector_div(block_nr, pool->sectors_per_block);
 
        return block_nr;
 }
@@ -348,12 +357,12 @@ static void remap(struct thin_c *tc, struct bio *bio, dm_block_t block)
        sector_t bi_sector = bio->bi_sector;
 
        bio->bi_bdev = tc->pool_dev->bdev;
-       if (tc->pool->sectors_per_block_shift < 0)
-               bio->bi_sector = (block * pool->sectors_per_block) +
-                                sector_div(bi_sector, pool->sectors_per_block);
-       else
+       if (block_size_is_power_of_two(pool))
                bio->bi_sector = (block << pool->sectors_per_block_shift) |
                                (bi_sector & (pool->sectors_per_block - 1));
+       else
+               bio->bi_sector = (block * pool->sectors_per_block) +
+                                sector_div(bi_sector, pool->sectors_per_block);
 }
 
 static void remap_to_origin(struct thin_c *tc, struct bio *bio)
@@ -1636,7 +1645,7 @@ static struct pool *pool_create(struct mapped_device *pool_md,
                goto bad_prison;
        }
 
-       pool->copier = dm_kcopyd_client_create();
+       pool->copier = dm_kcopyd_client_create(&dm_kcopyd_throttle);
        if (IS_ERR(pool->copier)) {
                r = PTR_ERR(pool->copier);
                *error = "Error creating pool's kcopyd client";
@@ -1938,7 +1947,7 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
        pt->data_dev = data_dev;
        pt->low_water_blocks = low_water_blocks;
        pt->adjusted_pf = pt->requested_pf = pf;
-       ti->num_flush_requests = 1;
+       ti->num_flush_bios = 1;
 
        /*
         * Only need to enable discards if the pool should pass
@@ -1946,7 +1955,7 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
         * processing will cause mappings to be removed from the btree.
         */
        if (pf.discard_enabled && pf.discard_passdown) {
-               ti->num_discard_requests = 1;
+               ti->num_discard_bios = 1;
 
                /*
                 * Setting 'discards_supported' circumvents the normal
@@ -2299,8 +2308,8 @@ static void emit_flags(struct pool_features *pf, char *result,
  *    <transaction id> <used metadata sectors>/<total metadata sectors>
  *    <used data sectors>/<total data sectors> <held metadata root>
  */
-static int pool_status(struct dm_target *ti, status_type_t type,
-                      unsigned status_flags, char *result, unsigned maxlen)
+static void pool_status(struct dm_target *ti, status_type_t type,
+                       unsigned status_flags, char *result, unsigned maxlen)
 {
        int r;
        unsigned sz = 0;
@@ -2326,32 +2335,41 @@ static int pool_status(struct dm_target *ti, status_type_t type,
                if (!(status_flags & DM_STATUS_NOFLUSH_FLAG) && !dm_suspended(ti))
                        (void) commit_or_fallback(pool);
 
-               r = dm_pool_get_metadata_transaction_id(pool->pmd,
-                                                       &transaction_id);
-               if (r)
-                       return r;
+               r = dm_pool_get_metadata_transaction_id(pool->pmd, &transaction_id);
+               if (r) {
+                       DMERR("dm_pool_get_metadata_transaction_id returned %d", r);
+                       goto err;
+               }
 
-               r = dm_pool_get_free_metadata_block_count(pool->pmd,
-                                                         &nr_free_blocks_metadata);
-               if (r)
-                       return r;
+               r = dm_pool_get_free_metadata_block_count(pool->pmd, &nr_free_blocks_metadata);
+               if (r) {
+                       DMERR("dm_pool_get_free_metadata_block_count returned %d", r);
+                       goto err;
+               }
 
                r = dm_pool_get_metadata_dev_size(pool->pmd, &nr_blocks_metadata);
-               if (r)
-                       return r;
+               if (r) {
+                       DMERR("dm_pool_get_metadata_dev_size returned %d", r);
+                       goto err;
+               }
 
-               r = dm_pool_get_free_block_count(pool->pmd,
-                                                &nr_free_blocks_data);
-               if (r)
-                       return r;
+               r = dm_pool_get_free_block_count(pool->pmd, &nr_free_blocks_data);
+               if (r) {
+                       DMERR("dm_pool_get_free_block_count returned %d", r);
+                       goto err;
+               }
 
                r = dm_pool_get_data_dev_size(pool->pmd, &nr_blocks_data);
-               if (r)
-                       return r;
+               if (r) {
+                       DMERR("dm_pool_get_data_dev_size returned %d", r);
+                       goto err;
+               }
 
                r = dm_pool_get_metadata_snap(pool->pmd, &held_root);
-               if (r)
-                       return r;
+               if (r) {
+                       DMERR("dm_pool_get_metadata_snap returned %d", r);
+                       goto err;
+               }
 
                DMEMIT("%llu %llu/%llu %llu/%llu ",
                       (unsigned long long)transaction_id,
@@ -2388,8 +2406,10 @@ static int pool_status(struct dm_target *ti, status_type_t type,
                emit_flags(&pt->requested_pf, result, sz, maxlen);
                break;
        }
+       return;
 
-       return 0;
+err:
+       DMEMIT("Error");
 }
 
 static int pool_iterate_devices(struct dm_target *ti,
@@ -2414,11 +2434,6 @@ static int pool_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
        return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
 }
 
-static bool block_size_is_power_of_two(struct pool *pool)
-{
-       return pool->sectors_per_block_shift >= 0;
-}
-
 static void set_discard_limits(struct pool_c *pt, struct queue_limits *limits)
 {
        struct pool *pool = pt->pool;
@@ -2432,15 +2447,8 @@ static void set_discard_limits(struct pool_c *pt, struct queue_limits *limits)
        if (pt->adjusted_pf.discard_passdown) {
                data_limits = &bdev_get_queue(pt->data_dev->bdev)->limits;
                limits->discard_granularity = data_limits->discard_granularity;
-       } else if (block_size_is_power_of_two(pool))
+       } else
                limits->discard_granularity = pool->sectors_per_block << SECTOR_SHIFT;
-       else
-               /*
-                * Use largest power of 2 that is a factor of sectors_per_block
-                * but at least DATA_DEV_BLOCK_SIZE_MIN_SECTORS.
-                */
-               limits->discard_granularity = max(1 << (ffs(pool->sectors_per_block) - 1),
-                                                 DATA_DEV_BLOCK_SIZE_MIN_SECTORS) << SECTOR_SHIFT;
 }
 
 static void pool_io_hints(struct dm_target *ti, struct queue_limits *limits)
@@ -2468,7 +2476,7 @@ static struct target_type pool_target = {
        .name = "thin-pool",
        .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE |
                    DM_TARGET_IMMUTABLE,
-       .version = {1, 6, 0},
+       .version = {1, 6, 1},
        .module = THIS_MODULE,
        .ctr = pool_ctr,
        .dtr = pool_dtr,
@@ -2588,17 +2596,17 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
        if (r)
                goto bad_thin_open;
 
-       ti->num_flush_requests = 1;
+       ti->num_flush_bios = 1;
        ti->flush_supported = true;
        ti->per_bio_data_size = sizeof(struct dm_thin_endio_hook);
 
        /* In case the pool supports discards, pass them on. */
        if (tc->pool->pf.discard_enabled) {
                ti->discards_supported = true;
-               ti->num_discard_requests = 1;
+               ti->num_discard_bios = 1;
                ti->discard_zeroes_data_unsupported = true;
-               /* Discard requests must be split on a block boundary */
-               ti->split_discard_requests = true;
+               /* Discard bios must be split on a block boundary */
+               ti->split_discard_bios = true;
        }
 
        dm_put(pool_md);
@@ -2676,8 +2684,8 @@ static void thin_postsuspend(struct dm_target *ti)
 /*
  * <nr mapped sectors> <highest mapped sector>
  */
-static int thin_status(struct dm_target *ti, status_type_t type,
-                      unsigned status_flags, char *result, unsigned maxlen)
+static void thin_status(struct dm_target *ti, status_type_t type,
+                       unsigned status_flags, char *result, unsigned maxlen)
 {
        int r;
        ssize_t sz = 0;
@@ -2687,7 +2695,7 @@ static int thin_status(struct dm_target *ti, status_type_t type,
 
        if (get_pool_mode(tc->pool) == PM_FAIL) {
                DMEMIT("Fail");
-               return 0;
+               return;
        }
 
        if (!tc->td)
@@ -2696,12 +2704,16 @@ static int thin_status(struct dm_target *ti, status_type_t type,
                switch (type) {
                case STATUSTYPE_INFO:
                        r = dm_thin_get_mapped_count(tc->td, &mapped);
-                       if (r)
-                               return r;
+                       if (r) {
+                               DMERR("dm_thin_get_mapped_count returned %d", r);
+                               goto err;
+                       }
 
                        r = dm_thin_get_highest_mapped_block(tc->td, &highest);
-                       if (r < 0)
-                               return r;
+                       if (r < 0) {
+                               DMERR("dm_thin_get_highest_mapped_block returned %d", r);
+                               goto err;
+                       }
 
                        DMEMIT("%llu ", mapped * tc->pool->sectors_per_block);
                        if (r)
@@ -2721,7 +2733,10 @@ static int thin_status(struct dm_target *ti, status_type_t type,
                }
        }
 
-       return 0;
+       return;
+
+err:
+       DMEMIT("Error");
 }
 
 static int thin_iterate_devices(struct dm_target *ti,
@@ -2748,7 +2763,7 @@ static int thin_iterate_devices(struct dm_target *ti,
 
 static struct target_type thin_target = {
        .name = "thin",
-       .version = {1, 7, 0},
+       .version = {1, 7, 1},
        .module = THIS_MODULE,
        .ctr = thin_ctr,
        .dtr = thin_dtr,
This page took 0.0440120000000001 seconds and 4 git commands to generate.