Fix disk utilization and ioscheduler switch on raw devices

Add a method for mapping a raw device to the real block device,
so our sysfs lookup stuff works as expected.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/os-linux.h b/os-linux.h
index 1ed3d3b..561b273 100644
--- a/os-linux.h
+++ b/os-linux.h
@@ -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 @@
 	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