diff options
author | Guoqing Jiang <gqjiang@suse.com> | 2015-06-10 13:42:12 +0800 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2015-06-17 09:43:31 +1000 |
commit | 7e6e839a265190e15742c4ecdd050aa1d9f208c6 (patch) | |
tree | ee0e037be5a8faec38f9163e1f67b56b8bb8fe1b /super1.c | |
parent | 0aa2f15b207c46ccaf4aa7a082ef7fdd186c7609 (diff) | |
download | mdadm-7e6e839a265190e15742c4ecdd050aa1d9f208c6.tar.gz |
mdadm: change the num of cluster node
This extends nodes option for assemble mode, make the num of
cluster node could be change by user.
Before that, it is necessary to ensure there are enough space
for those nodes, calc_bitmap_size is introduced to calculate
the bitmap size of each node.
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'super1.c')
-rw-r--r-- | super1.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -134,6 +134,20 @@ struct misc_dev_info { |MD_FEATURE_NEW_OFFSET \ ) +/* return how many bytes are needed for bitmap, for cluster-md each node + * should have it's own bitmap */ +static unsigned int calc_bitmap_size(bitmap_super_t *bms, unsigned int boundary) +{ + unsigned long long bits, bytes; + + bits = __le64_to_cpu(bms->sync_size) / (__le32_to_cpu(bms->chunksize)>>9); + bytes = (bits+7) >> 3; + bytes += sizeof(bitmap_super_t); + bytes = ROUND_UP(bytes, boundary); + + return bytes; +} + static unsigned int calc_sb_1_csum(struct mdp_superblock_1 * sb) { unsigned int disk_csum, csum; @@ -2190,6 +2204,7 @@ static int write_bitmap1(struct supertype *st, int fd, enum bitmap_update update int towrite, n; struct align_fd afd; unsigned int i = 0; + unsigned long long total_bm_space, bm_space_per_node; switch (update) { case NameUpdate: @@ -2199,6 +2214,28 @@ static int write_bitmap1(struct supertype *st, int fd, enum bitmap_update update strncpy((char *)bms->cluster_name, st->cluster_name, 64); } break; + case NodeNumUpdate: + /* cluster md only supports superblock 1.2 now */ + if (st->minor_version != 2) { + pr_err("Warning: cluster md only works with superblock 1.2\n"); + return -EINVAL; + } + + /* Each node has an independent bitmap, it is necessary to calculate the + * space is enough or not, first get how many bytes for the total bitmap */ + bm_space_per_node = calc_bitmap_size(bms, 4096); + + total_bm_space = 512 * (__le64_to_cpu(sb->data_offset) - __le64_to_cpu(sb->super_offset)); + total_bm_space = total_bm_space - 4096; /* leave another 4k for superblock */ + + if (bm_space_per_node * st->nodes > total_bm_space) { + pr_err("Warning: The max num of nodes can't exceed %llu\n", + total_bm_space / bm_space_per_node); + return -ENOMEM; + } + + bms->nodes = __cpu_to_le32(st->nodes); + break; case NoUpdate: default: break; |