From 462906cdeebc07875a4c8653c86ca02c09280f78 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Tue, 14 Apr 2009 10:19:02 +1000 Subject: [PATCH] incremental_container: preserve 'in_sync' flag when adding to existing array. When building container members with -IR, we need to ensure that devices added to an active array preserve the 'in_sync' status so they don't needlessly get rebuilt. So allow sysfs_add_disk to do this (only works in kernels since 2.6.30) and pass the relevant flag down. Signed-off-by: NeilBrown --- Assemble.c | 2 +- Manage.c | 2 +- managemon.c | 2 +- mdadm.h | 3 ++- sysfs.c | 8 ++++++-- util.c | 3 ++- 6 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Assemble.c b/Assemble.c index 73d6ee23..4cf54058 100644 --- a/Assemble.c +++ b/Assemble.c @@ -1228,7 +1228,7 @@ int assemble_container_content(struct supertype *st, int mdfd, sysfs_free(sra); for (dev = content->devs; dev; dev = dev->next) - if (sysfs_add_disk(content, dev) == 0) + if (sysfs_add_disk(content, dev, 1) == 0) working++; else if (errno == EEXIST) preexist++; diff --git a/Manage.c b/Manage.c index 7afd89b7..1f38fa54 100644 --- a/Manage.c +++ b/Manage.c @@ -702,7 +702,7 @@ int Manage_subdevs(char *devname, int fd, tst->ss->getinfo_super(tst, &new_mdi); new_mdi.disk.major = disc.major; new_mdi.disk.minor = disc.minor; - if (sysfs_add_disk(sra, &new_mdi) != 0) { + if (sysfs_add_disk(sra, &new_mdi, 0) != 0) { fprintf(stderr, Name ": add new device to external metadata" " failed for %s\n", dv->devname); close(container_fd); diff --git a/managemon.c b/managemon.c index e02c77ea..3835c995 100644 --- a/managemon.c +++ b/managemon.c @@ -395,7 +395,7 @@ static void manage_member(struct mdstat_ent *mdstat, * and open files for each newdev */ for (d = newdev; d ; d = d->next) { struct mdinfo *newd; - if (sysfs_add_disk(&newa->info, d) < 0) + if (sysfs_add_disk(&newa->info, d, 0) < 0) continue; newd = malloc(sizeof(*newd)); *newd = *d; diff --git a/mdadm.h b/mdadm.h index 83a7944b..357dc433 100644 --- a/mdadm.h +++ b/mdadm.h @@ -373,7 +373,8 @@ extern int sysfs_get_str(struct mdinfo *sra, struct mdinfo *dev, char *name, char *val, int size); extern int sysfs_set_safemode(struct mdinfo *sra, unsigned long ms); extern int sysfs_set_array(struct mdinfo *info, int vers); -extern int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd); +extern int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, + int in_sync); extern int sysfs_disk_to_scsi_id(int fd, __u32 *id); extern int sysfs_unique_holder(int devnum, long rdev); extern int load_sys(char *path, char *buf); diff --git a/sysfs.c b/sysfs.c index d4a1e495..711dce13 100644 --- a/sysfs.c +++ b/sysfs.c @@ -530,7 +530,7 @@ int sysfs_set_array(struct mdinfo *info, int vers) return rv; } -int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd) +int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int in_sync) { char dv[100]; char nm[100]; @@ -556,8 +556,12 @@ int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd) rv = sysfs_set_num(sra, sd, "offset", sd->data_offset); rv |= sysfs_set_num(sra, sd, "size", (sd->component_size+1) / 2); if (sra->array.level != LEVEL_CONTAINER) { + if (in_sync) + /* This can correctly fail if array isn't started, + * yet, so just ignore status for now. + */ + sysfs_set_str(sra, sd, "state", "in_sync"); rv |= sysfs_set_num(sra, sd, "slot", sd->disk.raid_disk); -// rv |= sysfs_set_str(sra, sd, "state", "in_sync"); } return rv; } diff --git a/util.c b/util.c index 02fc4633..35bb91bb 100644 --- a/util.c +++ b/util.c @@ -1092,7 +1092,8 @@ int add_disk(int mdfd, struct supertype *st, int rv; #ifndef MDASSEMBLE if (st->ss->external) { - rv = sysfs_add_disk(sra, info); + rv = sysfs_add_disk(sra, info, + info->disk.state & (1<devs; sd2; sd2=sd2->next) -- 2.39.2