Skip to content

Commit b98938d

Browse files
GuoqingJiangshligit
authored andcommitted
md-cluster: introduce cluster_check_sync_size
Support resize is a little complex for clustered raid, since we need to ensure all the nodes share the same knowledge about the size of raid. We achieve the goal by check the sync_size which is in each node's bitmap, we can only change the capacity after cluster_check_sync_size returns 0. Also, get_bitmap_from_slot is added to get a slot's bitmap. And we exported some funcs since they are used in cluster_check_sync_size(). We can also reuse get_bitmap_from_slot to remove redundant code existed in bitmap_copy_from_slot. Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: Guoqing Jiang <gqjiang@suse.com> Signed-off-by: Shaohua Li <shli@fb.com>
1 parent 7da3d20 commit b98938d

3 files changed

Lines changed: 93 additions & 10 deletions

File tree

‎drivers/md/bitmap.c‎

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ void bitmap_update_sb(struct bitmap *bitmap)
471471
kunmap_atomic(sb);
472472
write_page(bitmap, bitmap->storage.sb_page, 1);
473473
}
474+
EXPORT_SYMBOL(bitmap_update_sb);
474475

475476
/* print out the bitmap file superblock */
476477
void bitmap_print_sb(struct bitmap *bitmap)
@@ -1727,7 +1728,7 @@ void bitmap_flush(struct mddev *mddev)
17271728
/*
17281729
* free memory that was allocated
17291730
*/
1730-
static void bitmap_free(struct bitmap *bitmap)
1731+
void bitmap_free(struct bitmap *bitmap)
17311732
{
17321733
unsigned long k, pages;
17331734
struct bitmap_page *bp;
@@ -1761,6 +1762,7 @@ static void bitmap_free(struct bitmap *bitmap)
17611762
kfree(bp);
17621763
kfree(bitmap);
17631764
}
1765+
EXPORT_SYMBOL(bitmap_free);
17641766

17651767
void bitmap_destroy(struct mddev *mddev)
17661768
{
@@ -1920,6 +1922,27 @@ int bitmap_load(struct mddev *mddev)
19201922
}
19211923
EXPORT_SYMBOL_GPL(bitmap_load);
19221924

1925+
struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
1926+
{
1927+
int rv = 0;
1928+
struct bitmap *bitmap;
1929+
1930+
bitmap = bitmap_create(mddev, slot);
1931+
if (IS_ERR(bitmap)) {
1932+
rv = PTR_ERR(bitmap);
1933+
return ERR_PTR(rv);
1934+
}
1935+
1936+
rv = bitmap_init_from_disk(bitmap, 0);
1937+
if (rv) {
1938+
bitmap_free(bitmap);
1939+
return ERR_PTR(rv);
1940+
}
1941+
1942+
return bitmap;
1943+
}
1944+
EXPORT_SYMBOL(get_bitmap_from_slot);
1945+
19231946
/* Loads the bitmap associated with slot and copies the resync information
19241947
* to our bitmap
19251948
*/
@@ -1929,14 +1952,13 @@ int bitmap_copy_from_slot(struct mddev *mddev, int slot,
19291952
int rv = 0, i, j;
19301953
sector_t block, lo = 0, hi = 0;
19311954
struct bitmap_counts *counts;
1932-
struct bitmap *bitmap = bitmap_create(mddev, slot);
1933-
1934-
if (IS_ERR(bitmap))
1935-
return PTR_ERR(bitmap);
1955+
struct bitmap *bitmap;
19361956

1937-
rv = bitmap_init_from_disk(bitmap, 0);
1938-
if (rv)
1939-
goto err;
1957+
bitmap = get_bitmap_from_slot(mddev, slot);
1958+
if (IS_ERR(bitmap)) {
1959+
pr_err("%s can't get bitmap from slot %d\n", __func__, slot);
1960+
return -1;
1961+
}
19401962

19411963
counts = &bitmap->counts;
19421964
for (j = 0; j < counts->chunks; j++) {
@@ -1963,8 +1985,7 @@ int bitmap_copy_from_slot(struct mddev *mddev, int slot,
19631985
bitmap_unplug(mddev->bitmap);
19641986
*low = lo;
19651987
*high = hi;
1966-
err:
1967-
bitmap_free(bitmap);
1988+
19681989
return rv;
19691990
}
19701991
EXPORT_SYMBOL_GPL(bitmap_copy_from_slot);

‎drivers/md/bitmap.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,10 @@ void bitmap_daemon_work(struct mddev *mddev);
267267

268268
int bitmap_resize(struct bitmap *bitmap, sector_t blocks,
269269
int chunksize, int init);
270+
struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot);
270271
int bitmap_copy_from_slot(struct mddev *mddev, int slot,
271272
sector_t *lo, sector_t *hi, bool clear_bits);
273+
void bitmap_free(struct bitmap *bitmap);
272274
#endif
273275

274276
#endif

‎drivers/md/md-cluster.c‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,66 @@ static void metadata_update_cancel(struct mddev *mddev)
10911091
unlock_comm(cinfo);
10921092
}
10931093

1094+
/*
1095+
* return 0 if all the bitmaps have the same sync_size
1096+
*/
1097+
int cluster_check_sync_size(struct mddev *mddev)
1098+
{
1099+
int i, rv;
1100+
bitmap_super_t *sb;
1101+
unsigned long my_sync_size, sync_size = 0;
1102+
int node_num = mddev->bitmap_info.nodes;
1103+
int current_slot = md_cluster_ops->slot_number(mddev);
1104+
struct bitmap *bitmap = mddev->bitmap;
1105+
char str[64];
1106+
struct dlm_lock_resource *bm_lockres;
1107+
1108+
sb = kmap_atomic(bitmap->storage.sb_page);
1109+
my_sync_size = sb->sync_size;
1110+
kunmap_atomic(sb);
1111+
1112+
for (i = 0; i < node_num; i++) {
1113+
if (i == current_slot)
1114+
continue;
1115+
1116+
bitmap = get_bitmap_from_slot(mddev, i);
1117+
if (IS_ERR(bitmap)) {
1118+
pr_err("can't get bitmap from slot %d\n", i);
1119+
return -1;
1120+
}
1121+
1122+
/*
1123+
* If we can hold the bitmap lock of one node then
1124+
* the slot is not occupied, update the sb.
1125+
*/
1126+
snprintf(str, 64, "bitmap%04d", i);
1127+
bm_lockres = lockres_init(mddev, str, NULL, 1);
1128+
if (!bm_lockres) {
1129+
pr_err("md-cluster: Cannot initialize %s\n", str);
1130+
lockres_free(bm_lockres);
1131+
return -1;
1132+
}
1133+
bm_lockres->flags |= DLM_LKF_NOQUEUE;
1134+
rv = dlm_lock_sync(bm_lockres, DLM_LOCK_PW);
1135+
if (!rv)
1136+
bitmap_update_sb(bitmap);
1137+
lockres_free(bm_lockres);
1138+
1139+
sb = kmap_atomic(bitmap->storage.sb_page);
1140+
if (sync_size == 0)
1141+
sync_size = sb->sync_size;
1142+
else if (sync_size != sb->sync_size) {
1143+
kunmap_atomic(sb);
1144+
bitmap_free(bitmap);
1145+
return -1;
1146+
}
1147+
kunmap_atomic(sb);
1148+
bitmap_free(bitmap);
1149+
}
1150+
1151+
return (my_sync_size == sync_size) ? 0 : -1;
1152+
}
1153+
10941154
static int resync_start(struct mddev *mddev)
10951155
{
10961156
struct md_cluster_info *cinfo = mddev->cluster_info;

0 commit comments

Comments
 (0)