From 0431869cec4c673309d9aa30a2df4b778bc0bd24 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Wed, 10 Oct 2012 18:27:32 +1100 Subject: Fix up interactions between --assemble and --incremental If --incremental has partly assembled an array and --assemble is asked to assemble it, the just finds remaining devices and makes a new array. Not good. So: 1/ modify locking policy so that assemble can be sure that no --incremental is running once it locks the map file 2/ Assemble() checks the map file for a duplicate and adds to that array instead of creating a new one. Signed-off-by: NeilBrown --- Incremental.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'Incremental.c') diff --git a/Incremental.c b/Incremental.c index 1615c4df..9b5ac27d 100644 --- a/Incremental.c +++ b/Incremental.c @@ -116,7 +116,7 @@ int Incremental(char *devname, struct context *c, devname); return rv; } - dfd = dev_open(devname, O_RDONLY|O_EXCL); + dfd = dev_open(devname, O_RDONLY); if (dfd < 0) { if (c->verbose >= 0) pr_err("cannot open %s: %s.\n", @@ -270,6 +270,22 @@ int Incremental(char *devname, struct context *c, if (map_lock(&map)) pr_err("failed to get exclusive lock on " "mapfile\n"); + /* Now check we can get O_EXCL. If not, probably "mdadm -A" has + * taken over + */ + dfd = dev_open(devname, O_RDONLY|O_EXCL); + if (dfd < 0) { + if (c->verbose >= 0) + pr_err("cannot reopen %s: %s.\n", + devname, strerror(errno)); + goto out_unlock; + } + /* Cannot hold it open while we add the device to the array, + * so we must release the O_EXCL and depend on the map_lock() + */ + close(dfd); + dfd = -1; + mp = map_by_uuid(&map, info.uuid); if (mp) mdfd = open_dev(mp->devnum); -- cgit v1.2.3