NeilBrown: Don't remove md devices with standard names.
Martin F. Krafft
madduck at alioth.debian.org
Fri Sep 3 09:54:42 UTC 2010
Module: mdadm
Branch: build
Commit: b1702f4826e29419fa368fe63dca38422a01fc7e
URL: http://git.debian.org/?p=pkg-mdadm/mdadm.git;a=commit;h=b1702f4826e29419fa368fe63dca38422a01fc7e
Author: NeilBrown <neilb at suse.de>
Date: Tue Aug 31 15:21:40 2010 +1000
Don't remove md devices with standard names.
If udev is not in use, we create device in /dev when assembling
arrays and remove them when stopping the array.
However it may not always be correct to remove the device. If
the array was started with kernel auto-detect, them mdadm didn't
create anything and so shouldn't remove anything.
We don't record whether we created things, so just don't remove
anything with a 'standard' name. Only remove symlinks to the
standard name as we almost certainly created those.
Reported-by: Petre Rodan <petre.rodan at avira.com>
Signed-off-by: NeilBrown <neilb at suse.de>
---
Manage.c | 44 +++++++++++++++++++++-----------------------
1 files changed, 21 insertions(+), 23 deletions(-)
diff --git a/Manage.c b/Manage.c
index 0b3a66c..b39e1d9 100644
--- a/Manage.c
+++ b/Manage.c
@@ -118,9 +118,11 @@ int Manage_ro(char *devname, int fd, int readonly)
static void remove_devices(int devnum, char *path)
{
- /* Remove all 'standard' devices for 'devnum', including
- * partitions. Also remove names at 'path' - possibly with
- * partition suffixes - which link to those names.
+ /*
+ * Remove names at 'path' - possibly with
+ * partition suffixes - which link to the 'standard'
+ * name for devnum. These were probably created
+ * by mdadm when the array was assembled.
*/
char base[40];
char *path2;
@@ -130,36 +132,32 @@ static void remove_devices(int devnum, char *path)
char *be;
char *pe;
+ if (!path)
+ return;
+
if (devnum >= 0)
sprintf(base, "/dev/md%d", devnum);
else
sprintf(base, "/dev/md_d%d", -1-devnum);
be = base + strlen(base);
- if (path) {
- path2 = malloc(strlen(path)+20);
- strcpy(path2, path);
- pe = path2 + strlen(path2);
- } else
- path2 = path = NULL;
+
+ path2 = malloc(strlen(path)+20);
+ strcpy(path2, path);
+ pe = path2 + strlen(path2);
for (part = 0; part < 16; part++) {
if (part) {
sprintf(be, "p%d", part);
- if (path) {
- if (isdigit(pe[-1]))
- sprintf(pe, "p%d", part);
- else
- sprintf(pe, "%d", part);
- }
- }
- /* FIXME test if really is md device ?? */
- unlink(base);
- if (path) {
- n = readlink(path2, link, sizeof(link));
- if (n && (int)strlen(base) == n &&
- strncmp(link, base, n) == 0)
- unlink(path2);
+
+ if (isdigit(pe[-1]))
+ sprintf(pe, "p%d", part);
+ else
+ sprintf(pe, "%d", part);
}
+ n = readlink(path2, link, sizeof(link));
+ if (n && (int)strlen(base) == n &&
+ strncmp(link, base, n) == 0)
+ unlink(path2);
}
free(path2);
}
More information about the pkg-mdadm-commits
mailing list