From feab51f8f710f28a63a5b01ec59a5a609a45525b Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Mon, 22 Nov 2010 19:35:25 +1100 Subject: [PATCH] open_subarray: pass subarray name as explicit arg. Rather than hiding this arg in the 'st' structure, pass it explicitly. This is a first step to getting rid of 'subarray' from 'supertype'. The strcpy in open_subarray should have better error checking, but it will disappear soon so there is little point. Signed-off-by: NeilBrown subarray, sizeof(st->subarray), "%s", subarray) >= - (int)sizeof(st->subarray)) { - if (!quiet) - fprintf(stderr, - Name ": Input overflow for subarray '%s' > %zu bytes\n", - subarray, sizeof(st->subarray) - 1); - return 2; - } - - fd = open_subarray(dev, st, quiet); + fd = open_subarray(dev, subarray, st, quiet); if (fd < 0) return 2; diff --git a/Manage.c b/Manage.c index d9530a48..c3322f4d 100644 --- a/Manage.c +++ b/Manage.c @@ -1037,16 +1037,8 @@ int Update_subarray(char *dev, char *subarray, char *update, mddev_ident_t ident int fd, rv = 2; memset(st, 0, sizeof(*st)); - if (snprintf(st->subarray, sizeof(st->subarray), "%s", subarray) >= - (signed)sizeof(st->subarray)) { - if (!quiet) - fprintf(stderr, - Name ": Input overflow for subarray '%s' > %zu bytes\n", - subarray, sizeof(st->subarray) - 1); - return 2; - } - fd = open_subarray(dev, st, quiet); + fd = open_subarray(dev, subarray, st, quiet); if (fd < 0) return 2; diff --git a/mdadm.h b/mdadm.h index 6f7f06f5..9ca3223a 100644 --- a/mdadm.h +++ b/mdadm.h @@ -1032,7 +1032,7 @@ extern int open_container(int fd); extern int is_container_member(struct mdstat_ent *ent, char *devname); extern int is_subarray_active(char *subarray, char *devname); int is_container_active(char *devname); -extern int open_subarray(char *dev, struct supertype *st, int quiet); +extern int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet); extern struct superswitch *version_to_superswitch(char *vers); extern int mdmon_running(int devnum); diff --git a/util.c b/util.c index 27989636..b965c8d7 100644 --- a/util.c +++ b/util.c @@ -1441,12 +1441,12 @@ int is_container_active(char *container) /* open_subarray - opens a subarray in a container * @dev: container device name - * @st: supertype with only ->subarray set + * @st: empty supertype * @quiet: block reporting errors flag * * On success returns an fd to a container and fills in *st */ -int open_subarray(char *dev, struct supertype *st, int quiet) +int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet) { struct mdinfo *mdi; int fd, err = 1; @@ -1498,6 +1498,8 @@ int open_subarray(char *dev, 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", -- 2.39.2