Pass subarray arg explicitly to ->update_subarray.

This is better than hiding it in the supertype structure
where we are never quite sure who needs it.

Signed-off-by: NeilBrown <neilb@suse.de>
This commit is contained in:
NeilBrown 2010-11-22 20:24:50 +11:00
parent a1f976a013
commit a951a4f78f
4 changed files with 26 additions and 13 deletions

View File

@ -1054,7 +1054,7 @@ int Update_subarray(char *dev, char *subarray, char *update, mddev_ident_t ident
if (mdmon_running(st->devnum))
st->update_tail = &st->updates;
rv = st->ss->update_subarray(st, update, ident);
rv = st->ss->update_subarray(st, subarray, update, ident);
if (rv) {
if (!quiet)

View File

@ -629,7 +629,8 @@ extern struct superswitch {
/* Permit subarray's to be deleted from inactive containers */
int (*kill_subarray)(struct supertype *st); /* optional */
/* Permit subarray's to be modified */
int (*update_subarray)(struct supertype *st, char *update, mddev_ident_t ident); /* optional */
int (*update_subarray)(struct supertype *st, char *subarray,
char *update, mddev_ident_t ident); /* optional */
/* for mdmon */
int (*open_new)(struct supertype *c, struct active_array *a,

View File

@ -4229,19 +4229,19 @@ static int kill_subarray_imsm(struct supertype *st)
return 0;
}
static int update_subarray_imsm(struct supertype *st, char *update, mddev_ident_t ident)
static int update_subarray_imsm(struct supertype *st, char *subarray,
char *update, mddev_ident_t ident)
{
/* update the subarray currently referenced by ->current_vol */
struct intel_super *super = st->sb;
struct imsm_super *mpb = super->anchor;
if (super->current_vol < 0)
return 2;
if (strcmp(update, "name") == 0) {
char *name = ident->name;
char *ep;
int vol;
if (is_subarray_active(st->subarray, st->devname)) {
if (is_subarray_active(subarray, st->devname)) {
fprintf(stderr,
Name ": Unable to update name of active subarray\n");
return 2;
@ -4250,20 +4250,24 @@ static int update_subarray_imsm(struct supertype *st, char *update, mddev_ident_
if (!check_name(super, name, 0))
return 2;
vol = strtoul(subarray, &ep, 10);
if (*ep != '\0' || vol >= super->anchor->num_raid_devs)
return 2;
if (st->update_tail) {
struct imsm_update_rename_array *u = malloc(sizeof(*u));
if (!u)
return 2;
u->type = update_rename_array;
u->dev_idx = super->current_vol;
u->dev_idx = vol;
snprintf((char *) u->name, MAX_RAID_SERIAL_LEN, "%s", name);
append_metadata_update(st, u, sizeof(*u));
} else {
struct imsm_dev *dev;
int i;
dev = get_imsm_dev(super, super->current_vol);
dev = get_imsm_dev(super, vol);
snprintf((char *) dev->volume, MAX_RAID_SERIAL_LEN, "%s", name);
for (i = 0; i < mpb->num_raid_devs; i++) {
dev = get_imsm_dev(super, i);

16
util.c
View File

@ -1446,6 +1446,7 @@ int is_container_active(char *container)
int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet)
{
struct mdinfo *mdi;
struct mdinfo *info;
int fd, err = 1;
fd = open(dev, O_RDWR|O_EXCL);
@ -1495,12 +1496,10 @@ int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet)
goto free_sysfs;
}
strncpy(st->subarray, subarray, sizeof(st->subarray)-1);
if (st->ss->load_super(st, fd, NULL)) {
if (!quiet)
fprintf(stderr, Name ": Failed to find subarray-%s in %s\n",
st->subarray, dev);
fprintf(stderr, Name ": Failed to load metadata for %s\n",
dev);
goto free_name;
}
@ -1510,6 +1509,15 @@ int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet)
goto free_super;
}
info = st->ss->container_content(st, subarray);
if (!info) {
if (!quiet)
fprintf(stderr, Name ": Failed to find subarray-%s in %s\n",
subarray, dev);
goto free_super;
}
free(info);
err = 0;
free_super: