From 950bc34477adcaa8788f09255d2fcfa19c052b0f Mon Sep 17 00:00:00 2001 From: Przemyslaw Czarnowski Date: Mon, 22 Nov 2010 20:58:06 +1100 Subject: [PATCH] added --path to give the information on the 'path-id' of removed device allows to identify the port to which given device is plugged in. In case of hot-removal, udev can pass this information for future use (eg. write this name as 'cookie' allowing to detect the fact of reinserting device to the same port). --path parameter has been added to device removal handle (and char *path has been added to IncrementalRemove() to pass this value) in order to pass path-id to this handler. Signed-off-by: Przemyslaw Czarnowski Signed-off-by: NeilBrown --- Incremental.c | 8 +++++++- ReadMe.c | 2 ++ mdadm.c | 17 +++++++++++------ mdadm.h | 3 ++- udev-md-raid.rules | 2 +- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Incremental.c b/Incremental.c index b7bf0b4f..a2235530 100644 --- a/Incremental.c +++ b/Incremental.c @@ -1351,17 +1351,23 @@ static int Incremental_container(struct supertype *st, char *devname, * raid arrays, and if so first fail (if needed) and then remove the device. * * @devname - The device we want to remove + * @id_path - name as found in /dev/disk/by-path for this device * * Note: the device name must be a kernel name like "sda", so * that we can find it in /proc/mdstat */ -int IncrementalRemove(char *devname, int verbose) +int IncrementalRemove(char *devname, char *id_path, int verbose) { int mdfd; int rv; struct mdstat_ent *ent; struct mddev_dev devlist; + if (!id_path) + dprintf(Name ": incremental removal without --path " + "lacks the possibility to re-add new device in this " + "port\n"); + if (strchr(devname, '/')) { fprintf(stderr, Name ": incremental removal requires a " "kernel device name, not a file: %s\n", devname); diff --git a/ReadMe.c b/ReadMe.c index b97c55e7..07abdb7d 100644 --- a/ReadMe.c +++ b/ReadMe.c @@ -191,6 +191,8 @@ struct option long_options[] = { /* For Incremental */ {"rebuild-map", 0, 0, 'r'}, + {"path", 1, 0, IncrementalPath}, + {0, 0, 0, 0} }; diff --git a/mdadm.c b/mdadm.c index 4a854748..0eef6bc8 100644 --- a/mdadm.c +++ b/mdadm.c @@ -104,6 +104,7 @@ int main(int argc, char *argv[]) int rebuild_map = 0; int auto_update_home = 0; char *subarray = NULL; + char *remove_path = NULL; int print_help = 0; FILE *outf; @@ -943,6 +944,9 @@ int main(int argc, char *argv[]) case O(INCREMENTAL, 'r'): rebuild_map = 1; continue; + case O(INCREMENTAL, IncrementalPath): + remove_path = optarg; + continue; } /* We have now processed all the valid options. Anything else is * an error @@ -1586,12 +1590,13 @@ int main(int argc, char *argv[]) rv = 1; break; } - if (devmode == 'f') { - rv = IncrementalRemove(devlist->devname, verbose-quiet); - break; - } - rv = Incremental(devlist->devname, verbose-quiet, runstop, - ss, homehost, require_homehost, autof); + if (devmode == 'f') + rv = IncrementalRemove(devlist->devname, remove_path, + verbose-quiet); + else + rv = Incremental(devlist->devname, verbose-quiet, + runstop, ss, homehost, + require_homehost, autof); break; case AUTODETECT: autodetect(); diff --git a/mdadm.h b/mdadm.h index 9d5e1c0c..c6fdebed 100644 --- a/mdadm.h +++ b/mdadm.h @@ -280,6 +280,7 @@ enum special_options { DetailPlatform, KillSubarray, UpdateSubarray, /* 16 */ + IncrementalPath }; /* structures read from config file */ @@ -928,7 +929,7 @@ extern int Incremental(char *devname, int verbose, int runstop, int autof); extern void RebuildMap(void); extern int IncrementalScan(int verbose); -extern int IncrementalRemove(char *devname, int verbose); +extern int IncrementalRemove(char *devname, char *path, int verbose); extern int CreateBitmap(char *filename, int force, char uuid[16], unsigned long chunksize, unsigned long daemon_sleep, unsigned long write_behind, diff --git a/udev-md-raid.rules b/udev-md-raid.rules index f9607f37..a4a57ac8 100644 --- a/udev-md-raid.rules +++ b/udev-md-raid.rules @@ -3,7 +3,7 @@ SUBSYSTEM!="block", GOTO="md_end" # handle potential components of arrays -ENV{ID_FS_TYPE}=="linux_raid_member", ACTION=="remove", RUN+="/sbin/mdadm -If $name" +ENV{ID_FS_TYPE}=="linux_raid_member", ACTION=="remove", RUN+="/sbin/mdadm -If $name --path $env{ID_PATH}" ENV{ID_FS_TYPE}=="linux_raid_member", ACTION=="add", RUN+="/sbin/mdadm --incremental $env{DEVNAME}" # handle md arrays -- 2.39.2