summaryrefslogtreecommitdiffstats
path: root/managemon.c
diff options
context:
space:
mode:
authorDan Williams <dan.j.williams@intel.com>2008-08-19 09:19:51 +0200
committerNeilBrown <neilb@suse.de>2008-08-19 09:19:51 +0200
commit43dad3d6fb475bfefd2028e9dea1c15a83bb2d03 (patch)
tree5d244bcaebbbc71e24db7c6cf6bd75f401e6b646 /managemon.c
parentmdmon: remove devices from container (diff)
downloadmdadm-43dad3d6fb475bfefd2028e9dea1c15a83bb2d03.tar.xz
mdadm-43dad3d6fb475bfefd2028e9dea1c15a83bb2d03.zip
mdadm: add device to a container
Adding a device updates the container and then mdmon takes action upon noticing a change in devices. This reuses the container version of add_to_super to create a new record for the device. Signed-off-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'managemon.c')
-rw-r--r--managemon.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/managemon.c b/managemon.c
index d2925ae4..96120077 100644
--- a/managemon.c
+++ b/managemon.c
@@ -218,6 +218,34 @@ static void queue_metadata_update(struct metadata_update *mu)
*qp = mu;
}
+static void add_disk_to_container(struct supertype *st, struct mdinfo *sd)
+{
+ int dfd;
+ char nm[20];
+ struct metadata_update *update = NULL;
+ mdu_disk_info_t dk = {
+ .number = -1,
+ .major = sd->disk.major,
+ .minor = sd->disk.minor,
+ .raid_disk = -1,
+ .state = 0,
+ };
+
+ dprintf("%s: add %d:%d to container\n",
+ __func__, sd->disk.major, sd->disk.minor);
+
+ sprintf(nm, "%d:%d", sd->disk.major, sd->disk.minor);
+ dfd = dev_open(nm, O_RDWR);
+ if (dfd < 0)
+ return;
+
+ st->update_tail = &update;
+ st->ss->add_to_super(st, &dk, dfd, NULL);
+ st->ss->write_init_super(st);
+ queue_metadata_update(update);
+ st->update_tail = NULL;
+}
+
static void manage_container(struct mdstat_ent *mdstat,
struct supertype *container)
{
@@ -256,6 +284,16 @@ static void manage_container(struct mdstat_ent *mdstat,
} else
cdp = &(*cdp)->next;
}
+
+ /* check for additions */
+ for (di = mdi->devs; di; di = di->next) {
+ for (cd = container->devs; cd; cd = cd->next)
+ if (di->disk.major == cd->disk.major &&
+ di->disk.minor == cd->disk.minor)
+ break;
+ if (!cd)
+ add_disk_to_container(container, di);
+ }
sysfs_free(mdi);
container->devcnt = mdstat->devcnt;
}