diff --git a/libbcachefs.c b/libbcachefs.c index 393d3685..f78ebf04 100644 --- a/libbcachefs.c +++ b/libbcachefs.c @@ -241,7 +241,7 @@ struct bch_sb *bch2_format(struct bch_opt_strs fs_opt_strs, /* Disk labels*/ for (i = devs; i < devs + nr_devs; i++) { - struct bch_member *m = mi->members + (i - devs); + struct bch_member *m; int idx; if (!i->label) @@ -251,6 +251,13 @@ struct bch_sb *bch2_format(struct bch_opt_strs fs_opt_strs, if (idx < 0) die("error creating disk path: %s", strerror(-idx)); + /* + * Recompute mi and m after each sb modification: its location + * in memory may have changed due to reallocation. + */ + mi = bch2_sb_get_members(sb.sb); + m = mi->members + (i - devs); + SET_BCH_MEMBER_GROUP(m, idx + 1); }