Enable FIO_HAVE_CHARDEV_SIZE on DragonFlyBSD
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 11 Jun 2015 11:24:11 +0000 (20:24 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Fri, 12 Jun 2015 14:16:26 +0000 (23:16 +0900)
DragonFlyBSD no longer has block device just like FreeBSD got rid of
it at some point. Enable FIO_HAVE_CHARDEV_SIZE and implement get-size
functions with DragonFlyBSD's ioctl so fio can retrieve correct size
when targets are not regular files.

The following result verifies that df(1) shows the same fs size as
chardev_size() with regards to the character device (block device if
it were on Linux).

--
 # uname
 DragonFly
 # cat ./test3.c
 #include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include "os/os-dragonfly.h"

 int main(int argc, char *argv[]) {
         struct fio_file f;
         unsigned long long bytes;

         f.fd = open(argv[1], O_RDONLY);
         if (f.fd < 0) {
                 perror("open");
                 exit(1);
         }

         if (chardev_size(&f, &bytes)) {
                 perror("ioctl");
                 exit(1);
         }
         printf("%s %llu\n", argv[1], bytes);
         close(f.fd);
         return 0;
 }
 # gcc -Wall -g ./test3.c -o test3
 # file /dev/da8
 /dev/da8: character special (30/504430663)
 # ./test3 /dev/da8
 /dev/da8 31004295168
 # newfs /dev/da8 > /dev/null
 # mount -t ufs /dev/da8 /mnt
 # df -TH /mnt
 Filesystem  Type   Size   Used  Avail Capacity  Mounted on
 /dev/da8    ufs     31G   2.0k    28G     0%    /mnt

os/os-dragonfly.h

index 2a2b198f375059551e9063bd87f2987e87d17169..b67c660f00f651106d1501d0c18b8b1d84df2b44 100644 (file)
@@ -8,14 +8,15 @@
 #include <sys/param.h>
 #include <sys/sysctl.h>
 #include <sys/statvfs.h>
 #include <sys/param.h>
 #include <sys/sysctl.h>
 #include <sys/statvfs.h>
+#include <sys/diskslice.h>
 
 #include "../file.h"
 
 #define FIO_HAVE_ODIRECT
 
 #include "../file.h"
 
 #define FIO_HAVE_ODIRECT
-#define FIO_USE_GENERIC_BDEV_SIZE
 #define FIO_USE_GENERIC_RAND
 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
 #define FIO_HAVE_FS_STAT
 #define FIO_USE_GENERIC_RAND
 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
 #define FIO_HAVE_FS_STAT
+#define FIO_HAVE_CHARDEV_SIZE
 #define FIO_HAVE_GETTID
 
 #undef FIO_HAVE_CPU_AFFINITY   /* XXX notyet */
 #define FIO_HAVE_GETTID
 
 #undef FIO_HAVE_CPU_AFFINITY   /* XXX notyet */
 
 typedef off_t off64_t;
 
 
 typedef off_t off64_t;
 
+static inline int blockdev_size(struct fio_file *f, unsigned long long *bytes)
+{
+       struct partinfo pi;
+
+       if (!ioctl(f->fd, DIOCGPART, &pi)) {
+               *bytes = (unsigned long long) pi.media_size;
+               return 0;
+       }
+
+       *bytes = 0;
+       return errno;
+}
+
+static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
+{
+       return blockdev_size(f, bytes);
+}
+
 static inline int blockdev_invalidate_cache(struct fio_file *f)
 {
        return EINVAL;
 static inline int blockdev_invalidate_cache(struct fio_file *f)
 {
        return EINVAL;