Documentation/device-mapper/thin-provisioning.txt | 8 +- drivers/md/dm-thin-metadata.c | 23 ++++--- drivers/md/dm-thin.c | 25 +++++--- drivers/md/persistent-data/dm-block-manager.c | 63 ++++++++++---------- drivers/md/persistent-data/dm-btree-internal.h | 13 ++-- drivers/md/persistent-data/dm-btree-remove.c | 3 +- drivers/md/persistent-data/dm-btree-spine.c | 3 +- drivers/md/persistent-data/dm-btree.c | 64 ++++++++++--------- drivers/md/persistent-data/dm-space-map-common.h | 11 ++-- drivers/md/persistent-data/dm-space-map-disk.c | 28 +++++---- drivers/md/persistent-data/dm-space-map-metadata.c | 46 +++++++++------ drivers/md/persistent-data/dm-space-map.h | 10 ++- 12 files changed, 165 insertions(+), 132 deletions(-) diff --git a/Documentation/device-mapper/thin-provisioning.txt b/Documentation/device-mapper/thin-provisioning.txt index 894a164..ad971cf 100644 --- a/Documentation/device-mapper/thin-provisioning.txt +++ b/Documentation/device-mapper/thin-provisioning.txt @@ -10,10 +10,10 @@ stored on the same data volume. Simplifying administration and allowing sharing of data between volumes (thus reducing disk usage). Another big feature is support for arbitrary depth of recursive -snapshots (snapshots of snapshots of snapshots ...). Previous -implementations of snapshots did this by chaining together lookup -tables, and so performance was O(depth). This implementation uses a -single data structure so we won't get this degradation with depth +snapshots (snapshots of snapshots of snapshots ...). The previous +implementation of snapshots did this by chaining together lookup +tables, and so performance was O(depth). This new implementation uses +a single data structure so we won't get this degradation with depth (fragmentation may be an issue however in some scenarios). Metadata is stored on a separate device from data, this gives the diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c index 477ebc6..bf4d937 100644 --- a/drivers/md/dm-thin-metadata.c +++ b/drivers/md/dm-thin-metadata.c @@ -57,14 +57,14 @@ struct thin_super_block { __le32 compat_flags; __le32 compat_ro_flags; __le32 incompat_flags; -} __attribute__ ((packed)); +} __packed; struct device_details { __le64 mapped_blocks; __le64 transaction_id; /* when created */ __le32 creation_time; __le32 snapshotted_time; -} __attribute__ ((packed)); +} __packed; struct dm_thin_metadata { struct hlist_node hash; @@ -178,7 +178,7 @@ static struct dm_block_validator sb_validator_ = { static uint64_t pack_dm_block_time(dm_block_t b, uint32_t t) { - return ((b << 24) | t); + return (b << 24) | t; } static void unpack_dm_block_time(uint64_t v, dm_block_t *b, uint32_t *t) @@ -324,9 +324,9 @@ static struct dm_thin_metadata *alloc_mmd(struct dm_block_manager *bm, size_t space_map_root_offset = offsetof(struct thin_super_block, metadata_space_map_root); - r = dm_tm_open_with_sm(bm, THIN_SUPERBLOCK_LOCATION, &sb_validator_, - space_map_root_offset, SPACE_MAP_ROOT_SIZE, - &tm, &sm, &sblock); + r = dm_tm_open_with_sm(bm, THIN_SUPERBLOCK_LOCATION, + &sb_validator_, space_map_root_offset, + SPACE_MAP_ROOT_SIZE, &tm, &sm, &sblock); if (r < 0) { DMERR("tm_open_with_sm failed"); dm_block_manager_destroy(bm); @@ -424,7 +424,8 @@ static int begin_transaction(struct dm_thin_metadata *mmd) u32 features; struct thin_super_block *sb; - BUG_ON(mmd->sblock); + /* dm_thin_metadata_commit() resets mmd->sblock */ + WARN_ON(mmd->sblock); mmd->need_commit = 0; /* superblock is unlocked via dm_tm_commit() */ r = dm_bm_write_lock(mmd->bm, THIN_SUPERBLOCK_LOCATION, @@ -801,7 +802,8 @@ static int __delete_device(struct dm_thin_metadata *mmd, list_del(&msd->list); kfree(msd); - r = dm_btree_remove(&mmd->details_info, mmd->details_root, &key, &mmd->details_root); + r = dm_btree_remove(&mmd->details_info, mmd->details_root, + &key, &mmd->details_root); if (r) return r; @@ -828,7 +830,8 @@ int dm_thin_metadata_delete_device(struct dm_thin_metadata *mmd, static int __trim_thin_dev(struct dm_ms_device *msd, sector_t new_size) { struct dm_thin_metadata *mmd = msd->mmd; - uint64_t key[2] = { msd->id, new_size - 1 }; /* FIXME: convert new size to blocks */ + /* FIXME: convert new size to blocks */ + uint64_t key[2] = { msd->id, new_size - 1 }; msd->changed = 1; @@ -857,7 +860,7 @@ int dm_thin_metadata_trim_thin_dev(struct dm_thin_metadata *mmd, __close_device(msd); } - // FIXME: update mapped_blocks + /* FIXME: update mapped_blocks */ up_write(&mmd->root_lock); diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index beccb97..171bdaf 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c @@ -169,7 +169,8 @@ static uint32_t hash_key(struct bio_prison *prison, struct cell_key *key) return (uint32_t) (hash & prison->hash_mask); } -static struct cell *__search_bucket(struct hlist_head *bucket, struct cell_key *key) +static struct cell *__search_bucket(struct hlist_head *bucket, + struct cell_key *key) { struct cell *cell; struct hlist_node *tmp; @@ -357,7 +358,8 @@ static unsigned ds_next(unsigned index) static void __sweep(struct deferred_set *ds, struct list_head *head) { - while ((ds->sweeper != ds->current_entry) && !ds->entries[ds->sweeper].count) { + while ((ds->sweeper != ds->current_entry) && + !ds->entries[ds->sweeper].count) { list_splice_init(&ds->entries[ds->sweeper].work_items, head); ds->sweeper = ds_next(ds->sweeper); } @@ -1259,7 +1261,8 @@ static int bind_control_target(struct pool *pool, struct dm_target *ti) struct pool_c *pt = ti->private; pool->ti = ti; - pool->low_water_mark = dm_div_up(pt->low_water_mark, pool->sectors_per_block); + pool->low_water_mark = dm_div_up(pt->low_water_mark, + pool->sectors_per_block); pool->zero_new_blocks = pt->zero_new_blocks; return 0; } @@ -1400,13 +1403,17 @@ static struct pool *pool_create(const char *metadata_path, pool->triggered = 0; bio_list_init(&pool->retry_list); ds_init(&pool->ds); - pool->mapping_pool = mempool_create_kmalloc_pool(1024, sizeof(struct new_mapping)); /* FIXME: magic numbers, error handling */ + /* FIXME: magic number */ + pool->mapping_pool = + mempool_create_kmalloc_pool(1024, sizeof(struct new_mapping)); if (!pool->mapping_pool) { *error = "Error creating pool's mapping mempool"; err_p = ERR_PTR(-ENOMEM); goto bad_mapping_pool; } - pool->endio_hook_pool = mempool_create_kmalloc_pool(10240, sizeof(struct endio_hook)); /* FIXME: magic numbers, error handling */ + /* FIXME: magic number */ + pool->endio_hook_pool = + mempool_create_kmalloc_pool(10240, sizeof(struct endio_hook)); if (!pool->endio_hook_pool) { *error = "Error creating pool's endio_hook mempool"; err_p = ERR_PTR(-ENOMEM); @@ -1656,7 +1663,7 @@ static int pool_preresume(struct dm_target *ti) } if (data_size < sb_data_size) { - DMERR("pool target too small was %llu blocks, expected %llu blocks\n", + DMERR("pool target too small, is %llu blocks (expected %llu)", data_size, sb_data_size); return -EINVAL; @@ -2081,7 +2088,8 @@ static int thin_status(struct dm_target *ti, status_type_t type, DMEMIT("%llu ", mapped * mc->pool->sectors_per_block); if (r) - DMEMIT("%llu", ((highest + 1) * mc->pool->sectors_per_block) - 1); + DMEMIT("%llu", ((highest + 1) * + mc->pool->sectors_per_block) - 1); else DMEMIT("-"); break; @@ -2099,12 +2107,11 @@ static int thin_status(struct dm_target *ti, status_type_t type, return 0; } -/* bvec merge method. */ static int thin_bvec_merge(struct dm_target *ti, struct bvec_merge_data *bvm, struct bio_vec *biovec, int max_size) { struct thin_c *mc = ti->private; - struct pool * pool = mc->pool; + struct pool *pool = mc->pool; /* * We fib here, because the space may not have been provisioned yet diff --git a/drivers/md/persistent-data/dm-block-manager.c b/drivers/md/persistent-data/dm-block-manager.c index 7c0f8d6..5fb696d 100644 --- a/drivers/md/persistent-data/dm-block-manager.c +++ b/drivers/md/persistent-data/dm-block-manager.c @@ -16,7 +16,7 @@ enum dm_block_state { BS_READING, BS_WRITING, BS_READ_LOCKED, - BS_READ_LOCKED_DIRTY, /* block was dirty before it was read locked */ + BS_READ_LOCKED_DIRTY, /* block was dirty before it was read locked */ BS_WRITE_LOCKED, BS_DIRTY, BS_ERROR @@ -127,9 +127,9 @@ static void __insert_block(struct dm_block_manager *bm, struct dm_block *b) * Study this to understand the state machine. * * Alternatively install graphviz and run: - * grep DOT dm-block-manager.c | grep -v ' ' | - * sed -e 's/.*DOT: //' -e 's/\*\///' | - * dot -Tps -o states.ps + * grep DOT dm-block-manager.c | grep -v ' ' | + * sed -e 's/.*DOT: //' -e 's/\*\///' | + * dot -Tps -o states.ps * * Assumes bm->lock is held. *--------------------------------------------------------------*/ @@ -353,7 +353,7 @@ static void __clear_errors(struct dm_block_manager *bm) * Waiting *--------------------------------------------------------------*/ #ifdef __CHECKER__ -# define __retains(x) __attribute__((context(x,1,1))) +# define __retains(x) __attribute__((context(x, 1, 1))) #else # define __retains(x) #endif @@ -368,30 +368,30 @@ static inline void unplug(void) {} #endif #define __wait_block(wq, lock, flags, sched_fn, condition) \ -do { \ - int ret = 0; \ - \ - DEFINE_WAIT(wait); \ - add_wait_queue(wq, &wait); \ - \ - for (;;) { \ - prepare_to_wait(wq, &wait, TASK_INTERRUPTIBLE); \ - if (condition) \ - break; \ - \ - spin_unlock_irqrestore(lock, flags); \ - if (signal_pending(current)) { \ - ret = -ERESTARTSYS; \ - spin_lock_irqsave(lock, flags); \ - break; \ - } \ - \ - sched_fn(); \ - spin_lock_irqsave(lock, flags); \ - } \ - \ - finish_wait(wq, &wait); \ - return ret; \ +do { \ + int ret = 0; \ + \ + DEFINE_WAIT(wait); \ + add_wait_queue(wq, &wait); \ + \ + for (;;) { \ + prepare_to_wait(wq, &wait, TASK_INTERRUPTIBLE); \ + if (condition) \ + break; \ + \ + spin_unlock_irqrestore(lock, flags); \ + if (signal_pending(current)) { \ + ret = -ERESTARTSYS; \ + spin_lock_irqsave(lock, flags); \ + break; \ + } \ + \ + sched_fn(); \ + spin_lock_irqsave(lock, flags); \ + } \ + \ + finish_wait(wq, &wait); \ + return ret; \ } while (0) static int __wait_io(struct dm_block *b, unsigned long *flags) @@ -492,7 +492,7 @@ static int recycle_block(struct dm_block_manager *bm, dm_block_t where, /* did the io succeed ? */ if (b->state == BS_ERROR) { /* Since this is a read that has failed we can - * clear the error immediately. Failed writes are + * clear the error immediately. Failed writes are * revealed during a commit. */ __transition(b, BS_EMPTY); @@ -663,7 +663,8 @@ dm_block_manager_create(struct block_device *bdev, for (i = 0; i < hash_size; i++) INIT_HLIST_HEAD(bm->buckets + i); - if (!(bm->io = dm_io_client_create())) { + bm->io = dm_io_client_create(); + if (!bm->io) { kfree(bm); return NULL; } diff --git a/drivers/md/persistent-data/dm-btree-internal.h b/drivers/md/persistent-data/dm-btree-internal.h index 79ce1f5..be688a1 100644 --- a/drivers/md/persistent-data/dm-btree-internal.h +++ b/drivers/md/persistent-data/dm-btree-internal.h @@ -14,8 +14,8 @@ */ enum node_flags { - INTERNAL_NODE = 1, - LEAF_NODE = 1 << 1 + INTERNAL_NODE = 1, + LEAF_NODE = 1 << 1 }; /* @@ -29,12 +29,12 @@ struct node_header { __le32 nr_entries; __le32 max_entries; -} __attribute__((packed)); +} __packed; struct node { struct node_header header; __le64 keys[0]; -} __attribute__((packed)); +} __packed; /* @@ -46,8 +46,9 @@ struct node { void inc_children(struct dm_transaction_manager *tm, struct node *n, struct dm_btree_value_type *vt); -// FIXME: I don't like the bn_ prefix for these, refers to an old struct block_node -int bn_read_lock(struct dm_btree_info *info, dm_block_t b, struct dm_block **result); +/* FIXME: change bn_ prefix for these, refers to an old struct block_node */ +int bn_read_lock(struct dm_btree_info *info, dm_block_t b, + struct dm_block **result); int bn_shadow(struct dm_btree_info *info, dm_block_t orig, struct dm_btree_value_type *vt, struct dm_block **result, int *inc); int bn_new_block(struct dm_btree_info *info, struct dm_block **result); diff --git a/drivers/md/persistent-data/dm-btree-remove.c b/drivers/md/persistent-data/dm-btree-remove.c index d80b106..4b616e3 100644 --- a/drivers/md/persistent-data/dm-btree-remove.c +++ b/drivers/md/persistent-data/dm-btree-remove.c @@ -146,7 +146,8 @@ static int init_child(struct dm_btree_info *info, struct node *parent, result->index = index; root = value64(parent, index); - r = dm_tm_shadow_block(info->tm, root, &btree_node_validator, &result->block, &inc); + r = dm_tm_shadow_block(info->tm, root, &btree_node_validator, + &result->block, &inc); if (r) return r; diff --git a/drivers/md/persistent-data/dm-btree-spine.c b/drivers/md/persistent-data/dm-btree-spine.c index c42f1dd..cacdfda 100644 --- a/drivers/md/persistent-data/dm-btree-spine.c +++ b/drivers/md/persistent-data/dm-btree-spine.c @@ -61,7 +61,8 @@ int bn_shadow(struct dm_btree_info *info, dm_block_t orig, { int r; - r = dm_tm_shadow_block(info->tm, orig, &btree_node_validator, result, inc); + r = dm_tm_shadow_block(info->tm, orig, &btree_node_validator, + result, inc); if (r == 0 && *inc) inc_children(info->tm, dm_block_data(*result), vt); diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c index 71d9574..7ec3dcd 100644 --- a/drivers/md/persistent-data/dm-btree.c +++ b/drivers/md/persistent-data/dm-btree.c @@ -21,7 +21,7 @@ static int bsearch(struct node *n, uint64_t key, int want_hi) { int lo = -1, hi = __le32_to_cpu(n->header.nr_entries); - while(hi - lo > 1) { + while (hi - lo > 1) { int mid = lo + ((hi - lo) / 2); uint64_t mid_key = __le64_to_cpu(n->keys[mid]); @@ -286,7 +286,7 @@ static int btree_lookup_raw(struct ro_spine *s, dm_block_t block, uint64_t key, if (flags & INTERNAL_NODE) block = value64(ro_node(s), i); - } while (!(flags & LEAF_NODE)); + } while (!(flags & LEAF_NODE)); *result_key = __le64_to_cpu(ro_node(s)->keys[i]); memcpy(v, value_ptr(ro_node(s), i, value_size), value_size); @@ -383,7 +383,7 @@ int dm_btree_lookup_ge(struct dm_btree_info *info, dm_block_t root, { unsigned level, last_level = info->levels - 1; int r; - __le64 internal_value; + __le64 internal_value; struct ro_spine spine; init_ro_spine(&spine, info); @@ -423,27 +423,27 @@ EXPORT_SYMBOL_GPL(dm_btree_lookup_ge); * another child. * * Before: - * +--------+ - * | Parent | - * +--------+ + * +--------+ + * | Parent | + * +--------+ * | - * v - * +----------+ + * v + * +----------+ * | A ++++++ | * +----------+ * * * After: - * +--------+ - * | Parent | - * +--------+ - * | | - * v +------+ - * +---------+ | - * | A* +++ | v - * +---------+ +-------+ - * | B +++ | - * +-------+ + * +--------+ + * | Parent | + * +--------+ + * | | + * v +------+ + * +---------+ | + * | A* +++ | v + * +---------+ +-------+ + * | B +++ | + * +-------+ * * Where A* is a shadow of A. */ @@ -511,21 +511,21 @@ static int btree_split_sibling(struct shadow_spine *s, dm_block_t root, * * Before: * +----------+ - * | A ++++++ | - * +----------+ + * | A ++++++ | + * +----------+ * * * After: - * +------------+ + * +------------+ * | A (shadow) | * +------------+ - * | | - * +------+ +----+ - * | | - * v v + * | | + * +------+ +----+ + * | | + * v v * +-------+ +-------+ * | B +++ | | C +++ | - * +-------+ +-------+ + * +-------+ +-------+ */ static int btree_split_beneath(struct shadow_spine *s, uint64_t key) { @@ -570,7 +570,8 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key) size = __le32_to_cpu(p->header.flags) & INTERNAL_NODE ? sizeof(__le64) : s->info->value_type.size; memcpy(value_ptr(l, 0, size), value_ptr(p, 0, size), nr_left * size); - memcpy(value_ptr(r, 0, size), value_ptr(p, nr_left, size), nr_right * size); + memcpy(value_ptr(r, 0, size), value_ptr(p, nr_left, size), + nr_right * size); /* new_parent should just point to l and r now */ p->header.flags = __cpu_to_le32(INTERNAL_NODE); @@ -584,7 +585,10 @@ static int btree_split_beneath(struct shadow_spine *s, uint64_t key) p->keys[1] = r->keys[0]; memcpy(value_ptr(p, 1, sizeof(__le64)), &val, sizeof(__le64)); - /* rejig the spine. This is ugly, since it knows too much about the spine */ + /* + * rejig the spine. This is ugly, since it knows too + * much about the spine + */ if (s->nodes[0] != new_parent) { bn_unlock(s->info, s->nodes[0]); s->nodes[0] = new_parent; @@ -605,7 +609,7 @@ static int btree_insert_raw(struct shadow_spine *s, dm_block_t root, struct dm_btree_value_type *vt, uint64_t key, unsigned *index) { - int r, i = *index, inc, top = 1; + int r, i = *index, inc, top = 1; struct node *node; for (;;) { @@ -659,7 +663,7 @@ static int btree_insert_raw(struct shadow_spine *s, dm_block_t root, root = value64(node, i); top = 0; - } + } if (i < 0 || __le64_to_cpu(node->keys[i]) != key) i++; diff --git a/drivers/md/persistent-data/dm-space-map-common.h b/drivers/md/persistent-data/dm-space-map-common.h index e451079..6635d5b 100644 --- a/drivers/md/persistent-data/dm-space-map-common.h +++ b/drivers/md/persistent-data/dm-space-map-common.h @@ -25,7 +25,7 @@ struct index_entry { __le64 blocknr; __le32 nr_free; __le32 none_free_before; -} __attribute__ ((packed)); +} __packed; #define MAX_METADATA_BITMAPS 255 @@ -35,7 +35,7 @@ struct metadata_index { __le64 blocknr; struct index_entry index[MAX_METADATA_BITMAPS]; -} __attribute__ ((packed)); +} __packed; struct ll_disk { struct dm_transaction_manager *tm; @@ -46,7 +46,8 @@ struct ll_disk { uint32_t entries_per_block; dm_block_t nr_blocks; dm_block_t nr_allocated; - dm_block_t bitmap_root; /* sometimes a btree root, sometimes a simple index */ + dm_block_t bitmap_root; /* sometimes a btree root, + * sometimes a simple index */ dm_block_t ref_count_root; struct metadata_index mi; @@ -57,7 +58,7 @@ struct sm_root { __le64 nr_allocated; __le64 bitmap_root; __le64 ref_count_root; -} __attribute__ ((packed)); +} __packed; #define ENTRIES_PER_BYTE 4 @@ -65,7 +66,7 @@ struct bitmap_header { __le32 csum; __le32 not_used; __le64 blocknr; -} __attribute__ ((packed)); +} __packed; /* * These bitops work on a blocks worth of bits. diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c index 588a56f..492f2bc 100644 --- a/drivers/md/persistent-data/dm-space-map-disk.c +++ b/drivers/md/persistent-data/dm-space-map-disk.c @@ -30,7 +30,7 @@ static int bitmap_check(struct dm_block_validator *v, __le32 csum; if (dm_block_location(b) != __le64_to_cpu(header->blocknr)) { - DMERR("bitmap check failed blocknr %llu wanted %llu", + DMERR("bitmap check failed blocknr %llu wanted %llu", __le64_to_cpu(header->blocknr), dm_block_location(b)); return -ENOTBLK; } @@ -69,7 +69,7 @@ void *dm_bitmap_data(struct dm_block *b) static unsigned bitmap_word_used(void *addr, unsigned b) { __le64 *words = (__le64 *) addr; - __le64 *w = words + (b >> ENTRIES_SHIFT); + __le64 *w = words + (b >> ENTRIES_SHIFT); uint64_t bits = __le64_to_cpu(*w); return ((bits & WORD_MASK_LOW) == WORD_MASK_LOW || @@ -80,10 +80,10 @@ static unsigned bitmap_word_used(void *addr, unsigned b) unsigned sm_lookup_bitmap(void *addr, unsigned b) { __le64 *words = (__le64 *) addr; - __le64 *w = words + (b >> ENTRIES_SHIFT); + __le64 *w = words + (b >> ENTRIES_SHIFT); b = (b & (ENTRIES_PER_WORD - 1)) << 1; - return ((!!test_bit_le(b, (void*) w) << 1)) | + return ((!!test_bit_le(b, (void *) w) << 1)) | (!!test_bit_le(b + 1, (void *) w)); } @@ -136,7 +136,7 @@ static int ll_init(struct ll_disk *io, struct dm_transaction_manager *tm) /* * Because the new bitmap blocks are created via a shadow * operation, the old entry has already had it's reference count - * decremented. So we don't need the btree to do any book + * decremented. So we don't need the btree to do any book * keeping. */ io->bitmap_info.value_type.size = sizeof(struct index_entry); @@ -255,7 +255,6 @@ static int ll_lookup_bitmap(struct ll_disk *io, dm_block_t b, uint32_t *result) struct dm_block *blk; do_div(index, io->entries_per_block); - r = dm_btree_lookup(&io->bitmap_info, io->bitmap_root, &index, &ie); if (r < 0) return r; @@ -306,15 +305,16 @@ static int ll_find_free_block(struct ll_disk *io, dm_block_t begin, if (__le32_to_cpu(ie.nr_free) > 0) { struct dm_block *blk; unsigned position; - uint32_t bit_end = (i == index_end - 1) ? - mod64(end, io->entries_per_block) : - io->entries_per_block; + uint32_t bit_end; r = dm_tm_read_lock(io->tm, __le64_to_cpu(ie.blocknr), &dm_sm_bitmap_validator, &blk); if (r < 0) return r; + bit_end = (i == index_end - 1) ? + mod64(end, io->entries_per_block) : io->entries_per_block; + r = sm_find_free(dm_bitmap_data(blk), max((unsigned)begin, (unsigned)__le32_to_cpu(ie.none_free_before)), @@ -365,7 +365,6 @@ static int ll_insert(struct ll_disk *io, dm_block_t b, uint32_t ref_count) if (ref_count <= 2) { sm_set_bitmap(bm, bit, ref_count); - BUG_ON(sm_lookup_bitmap(bm, bit) != ref_count); if (old > 2) { r = dm_btree_remove(&io->ref_count_info, io->ref_count_root, @@ -474,13 +473,15 @@ static int sm_disk_get_nr_free(struct dm_space_map *sm, dm_block_t *count) return 0; } -static int sm_disk_get_count(struct dm_space_map *sm, dm_block_t b, uint32_t *result) +static int sm_disk_get_count(struct dm_space_map *sm, dm_block_t b, + uint32_t *result) { struct sm_disk *smd = container_of(sm, struct sm_disk, sm); return ll_lookup(&smd->ll, b, result); } -static int sm_disk_count_is_more_than_one(struct dm_space_map *sm, dm_block_t b, int *result) +static int sm_disk_count_is_more_than_one(struct dm_space_map *sm, dm_block_t b, + int *result) { int r; uint32_t count; @@ -492,7 +493,8 @@ static int sm_disk_count_is_more_than_one(struct dm_space_map *sm, dm_block_t b, return count > 1; } -static int sm_disk_set_count(struct dm_space_map *sm, dm_block_t b, uint32_t count) +static int sm_disk_set_count(struct dm_space_map *sm, dm_block_t b, + uint32_t count) { struct sm_disk *smd = container_of(sm, struct sm_disk, sm); return ll_insert(&smd->ll, b, count); diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c index 6d194ae..9081ff2 100644 --- a/drivers/md/persistent-data/dm-space-map-metadata.c +++ b/drivers/md/persistent-data/dm-space-map-metadata.c @@ -148,7 +148,6 @@ static int ll_open(struct ll_disk *ll, struct dm_transaction_manager *tm, ll->nr_blocks = __le64_to_cpu(smr->nr_blocks); ll->nr_allocated = __le64_to_cpu(smr->nr_allocated); - ll->bitmap_root = __le64_to_cpu(smr->bitmap_root); r = dm_tm_read_lock(tm, __le64_to_cpu(smr->bitmap_root), @@ -220,24 +219,29 @@ static int ll_find_free_block(struct ll_disk *ll, dm_block_t begin, if (__le32_to_cpu(ie->nr_free) > 0) { struct dm_block *blk; unsigned position; - uint32_t bit_end = (i == index_end - 1) ? end : ll->entries_per_block; + uint32_t bit_end; r = dm_tm_read_lock(ll->tm, __le64_to_cpu(ie->blocknr), &dm_sm_bitmap_validator, &blk); if (r < 0) return r; + + bit_end = (i == index_end - 1) ? + end : ll->entries_per_block; - r = sm_find_free(dm_bitmap_data(blk), begin, bit_end, &position); + r = sm_find_free(dm_bitmap_data(blk), begin, + bit_end, &position); if (r < 0) { dm_tm_unlock(ll->tm, blk); - return r; + return r; /* avoiding retry (FIXME: explain why) */ } r = dm_tm_unlock(ll->tm, blk); if (r < 0) return r; - *result = i * ll->entries_per_block + (dm_block_t) position; + *result = i * ll->entries_per_block + + (dm_block_t) position; return 0; } } @@ -261,7 +265,7 @@ static int ll_insert(struct ll_disk *ll, dm_block_t b, uint32_t ref_count) r = dm_tm_shadow_block(ll->tm, __le64_to_cpu(ie->blocknr), &dm_sm_bitmap_validator, &nb, &inc); if (r < 0) { - DMERR("shadow failed"); + DMERR("dm_tm_shadow_block() failed"); return r; } ie->blocknr = __cpu_to_le64(dm_block_location(nb)); @@ -277,9 +281,9 @@ static int ll_insert(struct ll_disk *ll, dm_block_t b, uint32_t ref_count) return r; if (old > 2) { - r = dm_btree_remove(&ll->ref_count_info, ll->ref_count_root, + r = dm_btree_remove(&ll->ref_count_info, + ll->ref_count_root, &b, &ll->ref_count_root); - if (r) { sm_set_bitmap(bm, bit, old); return r; @@ -337,7 +341,10 @@ static int ll_dec(struct ll_disk *ll, dm_block_t b) if (r) return r; - return rc ? ll_insert(ll, b, rc - 1) : -EINVAL; + if (!rc) + return -EINVAL; + + return ll_insert(ll, b, rc - 1); } static int ll_commit(struct ll_disk *ll) @@ -400,7 +407,7 @@ static int add_bop(struct sm_metadata *smm, enum block_op_type type, dm_block_t struct block_op *op; if (smm->nr_uncommitted == MAX_RECURSIVE_ALLOCATIONS) { - BUG_ON(1); + BUG(); return -1; } @@ -438,8 +445,11 @@ static void out(struct sm_metadata *smm) BUG_ON(!smm->recursion_count); if (smm->recursion_count == 1 && smm->nr_uncommitted) { - while (smm->nr_uncommitted && !r) - r = commit_bop(smm, smm->uncommitted + --smm->nr_uncommitted); + while (smm->nr_uncommitted && !r) { + smm->nr_uncommitted--; + r = commit_bop(smm, smm->uncommitted + + smm->nr_uncommitted); + } } smm->recursion_count--; @@ -463,7 +473,7 @@ static void sm_metadata_destroy(struct dm_space_map *sm) static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks) { - BUG_ON(1); + BUG(); return -1; } @@ -695,12 +705,12 @@ static struct dm_space_map ops_ = { */ static void sm_bootstrap_destroy(struct dm_space_map *sm) { - BUG_ON(1); + BUG(); } static int sm_bootstrap_extend(struct dm_space_map *sm, dm_block_t extra_blocks) { - BUG_ON(1); + BUG(); return -1; } @@ -734,7 +744,7 @@ static int sm_bootstrap_count_is_more_than_one(struct dm_space_map *sm, static int sm_bootstrap_set_count(struct dm_space_map *sm, dm_block_t b, uint32_t count) { - BUG_ON(1); + BUG(); return -1; } @@ -771,14 +781,14 @@ static int sm_bootstrap_commit(struct dm_space_map *sm) static int sm_bootstrap_root_size(struct dm_space_map *sm, size_t *result) { - BUG_ON(1); + BUG(); return -1; } static int sm_bootstrap_copy_root(struct dm_space_map *sm, void *where, size_t max) { - BUG_ON(1); + BUG(); return -1; } diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h index 54ce6aa..8e73daa 100644 --- a/drivers/md/persistent-data/dm-space-map.h +++ b/drivers/md/persistent-data/dm-space-map.h @@ -10,7 +10,6 @@ * is referenced. It needs to be persisted to disk as part of the * transaction. */ - struct dm_space_map { void (*destroy)(struct dm_space_map *sm); @@ -20,7 +19,8 @@ struct dm_space_map { int (*get_nr_free)(struct dm_space_map *sm, dm_block_t *count); int (*get_count)(struct dm_space_map *sm, dm_block_t b, uint32_t *result); - int (*count_is_more_than_one)(struct dm_space_map *sm, dm_block_t b, int *result); + int (*count_is_more_than_one)(struct dm_space_map *sm, dm_block_t b, + int *result); int (*set_count)(struct dm_space_map *sm, dm_block_t b, uint32_t count); int (*commit)(struct dm_space_map *sm); @@ -28,7 +28,8 @@ struct dm_space_map { int (*inc_block)(struct dm_space_map *sm, dm_block_t b); int (*dec_block)(struct dm_space_map *sm, dm_block_t b); - int (*new_block)(struct dm_space_map *sm, dm_block_t *b); /* increments the returned block */ + /* new_block will increment the returned block */ + int (*new_block)(struct dm_space_map *sm, dm_block_t *b); /* * The root contains all the information needed to persist the @@ -67,7 +68,8 @@ static inline int dm_sm_get_count(struct dm_space_map *sm, dm_block_t b, return sm->get_count(sm, b, result); } -static inline int dm_sm_count_is_more_than_one(struct dm_space_map *sm, dm_block_t b, int *result) +static inline int dm_sm_count_is_more_than_one(struct dm_space_map *sm, + dm_block_t b, int *result) { return sm->count_is_more_than_one(sm, b, result); }