Skip to content

Commit

Permalink
mdadm: remove bitmap file support
Browse files Browse the repository at this point in the history
Because it's marked deprecated for a long time now, and it's not worthy
to support it for new bitmap.

Now that we don't need to store filename for bitmap, also declare a new
enum type bitmap_type to simplify code.

Signed-off-by: Yu Kuai <[email protected]>
Signed-off-by: Mariusz Tkaczyk <[email protected]>
  • Loading branch information
YuKuai-huawei authored and mtkaczyk committed Dec 3, 2024
1 parent e97c4e1 commit 581ba13
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 296 deletions.
33 changes: 1 addition & 32 deletions Assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ static int load_devices(struct devs *devices, char *devmap,
struct mddev_dev *tmpdev;
int devcnt = 0;
int nextspare = 0;
int bitmap_done = 0;
int most_recent = -1;
int bestcnt = 0;
int *best = *bestp;
Expand Down Expand Up @@ -661,7 +660,7 @@ static int load_devices(struct devs *devices, char *devmap,
if (c->update == UOPT_UUID && !ident->uuid_set)
random_uuid((__u8 *)ident->uuid);

if (c->update == UOPT_PPL && ident->bitmap_fd >= 0) {
if (c->update == UOPT_PPL && ident->btype != BitmapNone) {
pr_err("PPL is not compatible with bitmap\n");
close(mdfd);
free(devices);
Expand Down Expand Up @@ -728,16 +727,6 @@ static int load_devices(struct devs *devices, char *devmap,
if (tst->ss->store_super(tst, dfd))
pr_err("Could not re-write superblock on %s.\n",
devname);

if (c->update == UOPT_UUID &&
ident->bitmap_fd >= 0 && !bitmap_done) {
if (bitmap_update_uuid(ident->bitmap_fd,
content->uuid,
tst->ss->swapuuid) != 0)
pr_err("Could not update uuid on external bitmap.\n");
else
bitmap_done = 1;
}
} else {
dfd = dev_open(devname,
tmpdev->disposition == 'I'
Expand Down Expand Up @@ -1057,26 +1046,6 @@ static int start_array(int mdfd,
mddev, strerror(errno));
return 1;
}
if (ident->bitmap_fd >= 0) {
if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) {
pr_err("SET_BITMAP_FILE failed.\n");
return 1;
}
} else if (ident->bitmap_file) {
/* From config file */
int bmfd = open(ident->bitmap_file, O_RDWR);
if (bmfd < 0) {
pr_err("Could not open bitmap file %s\n",
ident->bitmap_file);
return 1;
}
if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) {
pr_err("Failed to set bitmapfile for %s\n", mddev);
close(bmfd);
return 1;
}
close(bmfd);
}

/* First, add the raid disks, but add the chosen one last */
for (i = 0; i <= bestcnt; i++) {
Expand Down
35 changes: 1 addition & 34 deletions Build.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ int Build(struct mddev_ident *ident, struct mddev_dev *devlist, struct shape *s,
dev_t rdev;
int subdevs = 0, missing_disks = 0;
struct mddev_dev *dv;
int bitmap_fd;
unsigned long long bitmapsize;
int mdfd;
char chosen_name[1024];
int uuid[4] = {0,0,0,0};
Expand Down Expand Up @@ -110,13 +108,6 @@ int Build(struct mddev_ident *ident, struct mddev_dev *devlist, struct shape *s,
goto abort;
}

if (s->bitmap_file && str_is_none(s->bitmap_file) == true)
s->bitmap_file = NULL;
if (s->bitmap_file && s->level <= 0) {
pr_err("bitmaps not meaningful with level %s\n",
map_num(pers, s->level)?:"given");
goto abort;
}
/* now add the devices */
for ((i=0), (dv = devlist) ; dv ; i++, dv=dv->next) {
mdu_disk_info_t disk;
Expand Down Expand Up @@ -150,31 +141,7 @@ int Build(struct mddev_ident *ident, struct mddev_dev *devlist, struct shape *s,
goto abort;
}
}
/* now to start it */
if (s->bitmap_file) {
bitmap_fd = open(s->bitmap_file, O_RDWR);
if (bitmap_fd < 0) {
int major = BITMAP_MAJOR_HI;
bitmapsize = s->size >> 9; /* FIXME wrong for RAID10 */
if (CreateBitmap(s->bitmap_file, 1, NULL,
s->bitmap_chunk, c->delay,
s->write_behind, bitmapsize, major)) {
goto abort;
}
bitmap_fd = open(s->bitmap_file, O_RDWR);
if (bitmap_fd < 0) {
pr_err("%s cannot be opened.\n", s->bitmap_file);
goto abort;
}
}
if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) {
pr_err("Cannot set bitmap file for %s: %s\n", chosen_name,
strerror(errno));
close(bitmap_fd);
goto abort;
}
close(bitmap_fd);
}

if (ioctl(mdfd, RUN_ARRAY, &param)) {
pr_err("RUN_ARRAY failed: %s\n", strerror(errno));
if (s->chunk & (s->chunk - 1)) {
Expand Down
36 changes: 4 additions & 32 deletions Create.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,6 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
int insert_point = subdevs * 2; /* where to insert a missing drive */
int total_slots;
int rv;
int bitmap_fd;
int have_container = 0;
int container_fd = -1;
int need_mdmon = 0;
Expand All @@ -534,9 +533,9 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
struct map_ent *map = NULL;
unsigned long long newsize;
mdu_array_info_t inf;

int major_num = BITMAP_MAJOR_HI;
if (s->bitmap_file && strcmp(s->bitmap_file, "clustered") == 0) {

if (s->btype == BitmapCluster) {
major_num = BITMAP_MAJOR_CLUSTERED;
if (c->nodes <= 1) {
pr_err("At least 2 nodes are needed for cluster-md\n");
Expand Down Expand Up @@ -618,7 +617,7 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
pr_err("You haven't given enough devices (real or missing) to create this array\n");
return 1;
}
if (s->bitmap_file && s->level <= 0) {
if (s->btype != BitmapNone && s->level <= 0) {
pr_err("bitmaps not meaningful with level %s\n",
map_num(pers, s->level)?:"given");
return 1;
Expand Down Expand Up @@ -949,9 +948,6 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
}
}

if (s->bitmap_file && str_is_none(s->bitmap_file) == true)
s->bitmap_file = NULL;

if (s->consistency_policy == CONSISTENCY_POLICY_PPL &&
!st->ss->write_init_ppl) {
pr_err("%s metadata does not support PPL\n", st->ss->name);
Expand Down Expand Up @@ -1186,8 +1182,7 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
* to stop another mdadm from finding and using those devices.
*/

if (s->bitmap_file && (strcmp(s->bitmap_file, "internal") == 0 ||
strcmp(s->bitmap_file, "clustered") == 0)) {
if (s->btype == BitmapInternal || s->btype == BitmapCluster) {
if (!st->ss->add_internal_bitmap) {
pr_err("internal bitmaps not supported with %s metadata\n",
st->ss->name);
Expand All @@ -1199,7 +1194,6 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
pr_err("Given bitmap chunk size not supported.\n");
goto abort_locked;
}
s->bitmap_file = NULL;
}

if (sysfs_init(&info, mdfd, NULL)) {
Expand Down Expand Up @@ -1241,28 +1235,6 @@ int Create(struct supertype *st, struct mddev_ident *ident, int subdevs,
goto abort_locked;
}

if (s->bitmap_file) {
int uuid[4];

st->ss->uuid_from_super(st, uuid);
if (CreateBitmap(s->bitmap_file, c->force, (char*)uuid, s->bitmap_chunk,
c->delay, s->write_behind,
bitmapsize,
major_num)) {
goto abort_locked;
}
bitmap_fd = open(s->bitmap_file, O_RDWR);
if (bitmap_fd < 0) {
pr_err("weird: %s cannot be opened\n",
s->bitmap_file);
goto abort_locked;
}
if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) {
pr_err("Cannot set bitmap file for %s: %s\n", chosen_name, strerror(errno));
goto abort_locked;
}
}

if (add_disks(mdfd, &info, s, c, st, &map, devlist, total_slots,
have_container, insert_point, major_num, chosen_name))
goto abort_locked;
Expand Down
94 changes: 10 additions & 84 deletions Grow.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
* find all the active devices, and write the bitmap block
* to all devices
*/
mdu_bitmap_file_t bmf;
mdu_array_info_t array;
struct supertype *st;
char *subarray = NULL;
Expand All @@ -294,40 +293,21 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
struct mdinfo *mdi;

/*
* We only ever get called if s->bitmap_file is != NULL, so this check
* We only ever get called if bitmap is not none, so this check
* is just here to quiet down static code checkers.
*/
if (!s->bitmap_file)
if (s->btype == BitmapUnknown)
return 1;

if (strcmp(s->bitmap_file, "clustered") == 0)
if (s->btype == BitmapCluster)
major = BITMAP_MAJOR_CLUSTERED;

if (ioctl(fd, GET_BITMAP_FILE, &bmf) != 0) {
if (errno == ENOMEM)
pr_err("Memory allocation failure.\n");
else
pr_err("bitmaps not supported by this kernel.\n");
return 1;
}
if (bmf.pathname[0]) {
if (str_is_none(s->bitmap_file) == true) {
if (ioctl(fd, SET_BITMAP_FILE, -1) != 0) {
pr_err("failed to remove bitmap %s\n",
bmf.pathname);
return 1;
}
return 0;
}
pr_err("%s already has a bitmap (%s)\n", devname, bmf.pathname);
return 1;
}
if (md_get_array_info(fd, &array) != 0) {
pr_err("cannot get array status for %s\n", devname);
return 1;
}
if (array.state & (1 << MD_SB_BITMAP_PRESENT)) {
if (str_is_none(s->bitmap_file) == true) {
if (s->btype == BitmapNone) {
array.state &= ~(1 << MD_SB_BITMAP_PRESENT);
if (md_set_array_info(fd, &array) != 0) {
if (array.state & (1 << MD_SB_CLUSTERED))
Expand All @@ -342,10 +322,11 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
return 1;
}

if (str_is_none(s->bitmap_file) == true) {
if (s->btype == BitmapNone) {
pr_err("no bitmap found on %s\n", devname);
return 1;
}

if (array.level <= 0) {
pr_err("Bitmaps not meaningful with level %s\n",
map_num(pers, array.level)?:"of this array");
Expand All @@ -371,7 +352,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
ncopies = (array.layout & 255) * ((array.layout >> 8) & 255);
bitmapsize = bitmapsize * array.raid_disks / ncopies;

if (strcmp(s->bitmap_file, "clustered") == 0 &&
if (s->btype == BitmapCluster &&
!is_near_layout_10(array.layout)) {
pr_err("only near layout is supported with clustered raid10\n");
return 1;
Expand Down Expand Up @@ -402,8 +383,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
free(mdi);
}

if (strcmp(s->bitmap_file, "internal") == 0 ||
strcmp(s->bitmap_file, "clustered") == 0) {
if (s->btype == BitmapInternal || s->btype == BitmapCluster) {
int rv;
int d;
int offset_setable = 0;
Expand Down Expand Up @@ -432,7 +412,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
if (!dv)
continue;
if ((disk.state & (1 << MD_DISK_WRITEMOSTLY)) &&
(strcmp(s->bitmap_file, "clustered") == 0)) {
s->btype == BitmapCluster) {
pr_err("%s disks marked write-mostly are not supported with clustered bitmap\n",devname);
free(mdi);
return 1;
Expand Down Expand Up @@ -471,7 +451,7 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
mdi->bitmap_offset);
free(mdi);
} else {
if (strcmp(s->bitmap_file, "clustered") == 0)
if (s->btype == BitmapCluster)
array.state |= (1 << MD_SB_CLUSTERED);
array.state |= (1 << MD_SB_BITMAP_PRESENT);
rv = md_set_array_info(fd, &array);
Expand All @@ -482,60 +462,6 @@ int Grow_addbitmap(char *devname, int fd, struct context *c, struct shape *s)
pr_err("failed to set internal bitmap.\n");
return 1;
}
} else {
int uuid[4];
int bitmap_fd;
int d;
int max_devs = st->max_devs;

/* try to load a superblock */
for (d = 0; d < max_devs; d++) {
mdu_disk_info_t disk;
char *dv;
int fd2;
disk.number = d;
if (md_get_disk_info(fd, &disk) < 0)
continue;
if ((disk.major==0 && disk.minor == 0) ||
(disk.state & (1 << MD_DISK_REMOVED)))
continue;
dv = map_dev(disk.major, disk.minor, 1);
if (!dv)
continue;
fd2 = dev_open(dv, O_RDONLY);
if (fd2 >= 0) {
if (st->ss->load_super(st, fd2, NULL) == 0) {
close(fd2);
st->ss->uuid_from_super(st, uuid);
break;
}
close(fd2);
}
}
if (d == max_devs) {
pr_err("cannot find UUID for array!\n");
return 1;
}
if (CreateBitmap(s->bitmap_file, c->force, (char*)uuid,
s->bitmap_chunk, c->delay, s->write_behind,
bitmapsize, major)) {
return 1;
}
bitmap_fd = open(s->bitmap_file, O_RDWR);
if (bitmap_fd < 0) {
pr_err("weird: %s cannot be opened\n", s->bitmap_file);
return 1;
}
if (ioctl(fd, SET_BITMAP_FILE, bitmap_fd) < 0) {
int err = errno;
if (errno == EBUSY)
pr_err("Cannot add bitmap while array is resyncing or reshaping etc.\n");
pr_err("Cannot set bitmap file for %s: %s\n",
devname, strerror(err));
close_fd(&bitmap_fd);
return 1;
}
close_fd(&bitmap_fd);
}

return 0;
Expand Down
Loading

0 comments on commit 581ba13

Please sign in to comment.