use struct udev_device during discovery
authorHannes Reinecke <hare@suse.de>
Thu, 19 Apr 2012 09:09:00 +0000 (11:09 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Fri, 20 Apr 2012 17:47:35 +0000 (19:47 +0200)
We can save quite some parsing etc. by just using struct udev_device.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/discovery.c

index d68324b..fd0f827 100644 (file)
@@ -56,34 +56,24 @@ out:
 }
 
 static int
-path_discover (vector pathvec, struct config * conf, char * devname, int flag)
+path_discover (vector pathvec, struct config * conf,
+              struct udev_device *udevice, int flag)
 {
-       char path[FILE_NAME_SIZE];
        struct path * pp;
+       const char * devname;
 
+       devname = udev_device_get_sysname(udevice);
        if (!devname)
                return 0;
 
        if (filter_devnode(conf->blist_devnode, conf->elist_devnode,
-                          devname) > 0)
+                          (char *)devname) > 0)
                return 0;
 
-       if(safe_sprintf(path, "%s/block/%s/device", sysfs_path,
-                       devname)) {
-               condlog(0, "path too small");
-               return 1;
-       }
-
-       if (strncmp(devname,"cciss",5) && !filepresent(path)) {
-               condlog(4, "path %s not present", path);
-               return 0;
-       }
-
-       pp = find_path_by_dev(pathvec, devname);
-
+       pp = find_path_by_dev(pathvec, (char *)devname);
        if (!pp) {
                pp = store_pathinfo(pathvec, conf->hwtable,
-                                   devname, flag);
+                                   (char *)devname, flag);
                return (pp ? 0 : 1);
        }
        return pathinfo(pp, conf->hwtable, flag);
@@ -94,8 +84,8 @@ path_discovery (vector pathvec, struct config * conf, int flag)
 {
        struct udev_enumerate *udev_iter;
        struct udev_list_entry *entry;
-       char *devpath;
-       char *devptr;
+       struct udev_device *udevice;
+       const char *devpath;
        int r = 0;
 
        udev_iter = udev_enumerate_new(conf->udev);
@@ -109,13 +99,15 @@ path_discovery (vector pathvec, struct config * conf, int flag)
                                udev_enumerate_get_list_entry(udev_iter)) {
                devpath = udev_list_entry_get_name(entry);
                condlog(4, "Discover device %s", devpath);
-               devptr = strrchr(devpath, '/');
-               if (devptr)
-                       devptr++;
-               else
-                       devptr = devpath;
-
-               r += path_discover(pathvec, conf, devptr, flag);
+               udevice = udev_device_new_from_syspath(conf->udev, devpath);
+               if (!udevice) {
+                       condlog(4, "%s: no udev information", devpath);
+                       r++;
+                       continue;
+               }
+               if(!strncmp(udev_device_get_devtype(udevice), "disk", 4))
+                       r += path_discover(pathvec, conf, udevice, flag);
+               udev_device_unref(udevice);
        }
        udev_enumerate_unref(udev_iter);
        condlog(4, "Discovery status %d", r);