[libmultipath] working claimed device detection
authorroot <root@potab.(none)>
Wed, 17 Aug 2005 16:01:59 +0000 (18:01 +0200)
committerroot <root@potab.(none)>
Wed, 17 Aug 2005 16:01:59 +0000 (18:01 +0200)
done with O_EXCL

libmultipath/discovery.c
libmultipath/discovery.h

index f171afaeba7b5b70e37f7d201148f17ff17d2b46..2b2784c7e81978d785d4b85d3e8100ce54a3236a 100644 (file)
@@ -3,6 +3,7 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/stat.h>
+#include <errno.h>
 
 #include <sysfs/dlist.h>
 #include <sysfs/libsysfs.h>
@@ -201,7 +202,7 @@ opennode (char * dev, int mode)
        while (--loop) {
                fd = open(devpath, mode);
 
-               if (fd > 0)
+               if (fd > 0 || errno != ENOENT)
                        return fd;
 
                usleep(1000 * 1000 / WAIT_LOOP_PER_SECOND);
@@ -210,16 +211,17 @@ opennode (char * dev, int mode)
        return -1;
 }
 
-#if 0
 int
-get_claimed(int fd)
+get_claimed(char * devname)
 {
-       /*
-        * FIXME : O_EXCL always fails ?
-        */
+       int fd = opennode(devname, O_EXCL);
+
+       if (fd < 0)
+               return 1;
+
+       close(fd);
        return 0;
 }      
-#endif
 
 extern int
 devt2devname (char *devname, char *devt)
@@ -587,6 +589,10 @@ pathinfo (struct path *pp, vector hwtable, int mask)
        /*
         * then those not available through sysfs
         */
+       if (mask & DI_CLAIMED) {
+               pp->claimed = get_claimed(pp->dev);
+               condlog(3, "claimed = %i", pp->claimed);
+       }
        if (pp->fd <= 0)
                pp->fd = opennode(pp->dev, O_RDONLY);
 
@@ -596,12 +602,6 @@ pathinfo (struct path *pp, vector hwtable, int mask)
        if (pp->bus == SYSFS_BUS_SCSI)
                if (scsi_ioctl_pathinfo(pp, mask))
                        return 1;
-#if 0
-       if (mask & DI_CLAIMED) {
-               pp->claimed = get_claimed(pp->fd);
-               condlog(3, "claimed = %i", pp->claimed);
-       }
-#endif
 
        /* get and store hwe pointer */
        pp->hwe = find_hwe(hwtable, pp->vendor_id, pp->product_id);
index b0834945872aa992f47bb1de7ef5d321e9598cac..ec8e537011a1a24b6c6436af0ccb039aaf8ebe00 100644 (file)
@@ -36,11 +36,6 @@ int devt2devname (char *, char *);
 int pathinfo (struct path *, vector hwtable, int mask);
 struct path * store_pathinfo (vector pathvec, vector hwtable,
                              char * devname, int flag);
-       
-
-#if 0
-int get_claimed(int fd);
-#endif
 
 /*
  * discovery bitmask