From aa534678baad80689a642ba1bd602a00a267ac03 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 22 Jun 2010 16:30:59 -0700 Subject: Rename subarray v2 Allow the name of the array stored in the metadata to be updated. In some cases the metadata format may not be able to support this rename without modifying the UUID. In these cases the request will be blocked. Otherwise we allow the rename to take place, even for active arrays. This assumes that the user understands the difference between the kernel node name, the device node symlink name, and the metadata specific name. Anticipating further need to modify subarrays in-place, introduce the ->update_subarray() superswitch method. A future potential use case is setting storage pool (spare-group) identifiers. Signed-off-by: Dan Williams --- Manage.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'Manage.c') diff --git a/Manage.c b/Manage.c index f6fb3ef..cca1503 100644 --- a/Manage.c +++ b/Manage.c @@ -869,4 +869,57 @@ int autodetect(void) } return rv; } + +int Update_subarray(char *dev, char *subarray, char *update, mddev_ident_t ident, int quiet) +{ + struct supertype supertype, *st = &supertype; + int fd, rv = 2; + + memset(st, 0, sizeof(*st)); + if (snprintf(st->subarray, sizeof(st->subarray), "%s", subarray) >= + 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); + if (fd < 0) + return 2; + + if (!st->ss->update_subarray) { + if (!quiet) + fprintf(stderr, + Name ": Operation not supported for %s metadata\n", + st->ss->name); + goto free_super; + } + + if (mdmon_running(st->devnum)) + st->update_tail = &st->updates; + + rv = st->ss->update_subarray(st, update, ident); + + if (rv) { + if (!quiet) + fprintf(stderr, Name ": Failed to update %s of subarray-%s in %s\n", + update, subarray, dev); + } else if (st->update_tail) + flush_metadata_updates(st); + else + st->ss->sync_metadata(st); + + if (rv == 0 && strcmp(update, "name") == 0 && !quiet) + fprintf(stderr, + Name ": Updated subarray-%s name from %s, UUIDs may have changed\n", + subarray, dev); + + free_super: + st->ss->free_super(st); + close(fd); + + return rv; +} #endif -- cgit