Seperate disk util code out of fio.c
[fio.git] / os-linux.h
index b147d4f3b340c0fd2bb5f352b469beb97e6b57e7..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
 #define FIO_HAVE_IOSCHED_SWITCH
 #define FIO_HAVE_ODIRECT
 #define FIO_HAVE_HUGETLB
-
-/*
- * Only for x86 currently
- */
-#if defined(__i386__)
-#define FIO_HAVE_SYSLET
-#endif
+#define FIO_HAVE_RAWBIND
 
 #define OS_MAP_ANON            (MAP_ANONYMOUS)
 
@@ -39,7 +35,7 @@ typedef struct drand48_data os_random_state_t;
        posix_fadvise((fd), (off_t)(off), (len), (advice))
 
 #define fio_setaffinity(td)            \
-       sched_setaffinity((td)->pid, sizeof((td)->cpumask), &(td)->cpumask)
+       sched_setaffinity((td)->pid, sizeof((td)->o.cpumask), &(td)->o.cpumask)
 #define fio_getaffinity(pid, ptr)      \
        sched_getaffinity((pid), sizeof(cpu_set_t), (ptr))
 
@@ -102,9 +98,9 @@ async_wait(unsigned long min_wait_events, unsigned long user_ring_idx,
                        user_ring_idx, ahu);
 }
 
-static inline long async_thread(void)
+static inline long async_thread(void *event, struct async_head_user *ahu)
 {
-       return syscall(__NR_async_thread);
+       return syscall(__NR_async_thread, event, ahu);
 }
 
 static inline long umem_add(unsigned long *uptr, unsigned long inc)
@@ -131,10 +127,7 @@ enum {
 
 static inline int blockdev_invalidate_cache(int fd)
 {
-       if (!ioctl(fd, BLKFLSBUF))
-               return 0;
-
-       return errno;
+       return ioctl(fd, BLKFLSBUF);
 }
 
 static inline int blockdev_size(int fd, unsigned long long *bytes)
@@ -178,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