Fix disk utilization and ioscheduler switch on raw devices
[fio.git] / os-linux.h
index 1ed3d3b650b206921c0c22a5b1e3c656820d228e..561b273db94e3dcd590e7e6dbfa24e39c497ba00 100644 (file)
@@ -7,6 +7,8 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <linux/unistd.h>
+#include <linux/raw.h>
+#include <linux/major.h>
 
 #define FIO_HAVE_LIBAIO
 #define FIO_HAVE_POSIXAIO
@@ -19,6 +21,7 @@
 #define FIO_HAVE_IOSCHED_SWITCH
 #define FIO_HAVE_ODIRECT
 #define FIO_HAVE_HUGETLB
+#define FIO_HAVE_RAWBIND
 
 #define OS_MAP_ANON            (MAP_ANONYMOUS)
 
@@ -168,4 +171,33 @@ static inline double os_random_double(os_random_state_t *rs)
        return val;
 }
 
+static inline void fio_lookup_raw(dev_t dev, int *majdev, int *mindev)
+{
+       struct raw_config_request rq;
+       int fd;
+
+       if (major(dev) != RAW_MAJOR)
+               return;
+
+       /*
+        * we should be able to find /dev/rawctl or /dev/raw/rawctl
+        */
+       fd = open("/dev/rawctl", O_RDONLY);
+       if (fd < 0) {
+               fd = open("/dev/raw/rawctl", O_RDONLY);
+               if (fd < 0)
+                       return;
+       }
+
+       rq.raw_minor = minor(dev);
+       if (ioctl(fd, RAW_GETBIND, &rq) < 0) {
+               close(fd);
+               return;
+       }
+
+       close(fd);
+       *majdev = rq.block_major;
+       *mindev = rq.block_minor;
+}
+
 #endif