]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Introduce devid2kname - slightly different to devid2devnm.
authorNeilBrown <neilb@suse.de>
Thu, 1 Aug 2013 04:32:04 +0000 (14:32 +1000)
committerNeilBrown <neilb@suse.de>
Thu, 1 Aug 2013 04:32:04 +0000 (14:32 +1000)
The purpose od devid2devnm is to return a kernel name of an
md device, whether that device is a whole device or a partition,
we want the whole device.  md4, never md4p2.

In one place I was using devid2devnm where I really wanted the
partition if there was one ... and wasn't really interested in it
being an md device.
So introduce a new 'devid2kname' for that case.

Signed-off-by: NeilBrown <neilb@suse.de>
lib.c
mdadm.h
sysfs.c

diff --git a/lib.c b/lib.c
index 8285f346c25e2fe4254ab851b43e43c2ae6a7b16..6808f62d77ced0d6b044f48fa43a9b289f55b16b 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -58,6 +58,32 @@ static int mdp_major = -1;
        return mdp_major;
 }
 
+char *devid2kname(int devid)
+{
+       char path[30];
+       char link[200];
+       static char devnm[32];
+       char *cp;
+       int n;
+
+       /* Look at the
+        * /sys/dev/block/%d:%d link which must look like
+        * and take the last component.
+        */
+       sprintf(path, "/sys/dev/block/%d:%d", major(devid),
+               minor(devid));
+       n = readlink(path, link, sizeof(link)-1);
+       if (n > 0) {
+               link[n] = 0;
+               cp = strrchr(link, '/');
+               if (cp) {
+                       strcpy(devnm, cp+1);
+                       return devnm;
+               }
+       }
+       return NULL;
+}
+
 char *devid2devnm(int devid)
 {
        char path[30];
diff --git a/mdadm.h b/mdadm.h
index 5463bfba868338513031dffc5127f188240fda93..c5d9c3010aab8a18f9766ea2402488e8389f71b9 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -1349,6 +1349,7 @@ extern void print_r10_layout(int layout);
 extern char *find_free_devnm(int use_partitions);
 
 extern void put_md_name(char *name);
+extern char *devid2kname(int devid);
 extern char *devid2devnm(int devid);
 extern int devnm2devid(char *devnm);
 extern char *get_md_name(char *devnm);
diff --git a/sysfs.c b/sysfs.c
index 13558c5fd0516e1c4a19f355a77f5df62b57e924..9a1d856960e82ba78d16b12b6da5cf4bf0efe455 100644 (file)
--- a/sysfs.c
+++ b/sysfs.c
@@ -682,7 +682,7 @@ int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int resume)
                return rv;
 
        memset(nm, 0, sizeof(nm));
-       dname = devid2devnm(makedev(sd->disk.major, sd->disk.minor));
+       dname = devid2kname(makedev(sd->disk.major, sd->disk.minor));
        strcpy(sd->sys_name, "dev-");
        strcpy(sd->sys_name+4, dname);