Add os_trim() support for DragonFlyBSD
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 14 Jul 2016 12:27:42 +0000 (21:27 +0900)
committerJens Axboe <axboe@fb.com>
Thu, 14 Jul 2016 15:31:11 +0000 (08:31 -0700)
It has the same interface as Linux kernel with a different ioctl name.

Signed-off-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
Makefile
os/os-dragonfly.h

index c617d6f495359bbce43c1759c8114a821095dda6..a9cd151f6e20c3694a2636d4f9a7c56ae8389537 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -157,6 +157,7 @@ ifeq ($(CONFIG_TARGET_OS), NetBSD)
   LDFLAGS += -rdynamic
 endif
 ifeq ($(CONFIG_TARGET_OS), DragonFly)
+  SOURCE += trim.c
   LIBS  += -lpthread -lrt
   LDFLAGS += -rdynamic
 endif
index b67c660f00f651106d1501d0c18b8b1d84df2b44..d776d1f75635f655ea8020b4b319740f68cac3fd 100644 (file)
@@ -9,6 +9,7 @@
 #include <sys/sysctl.h>
 #include <sys/statvfs.h>
 #include <sys/diskslice.h>
+#include <sys/ioctl_compat.h>
 
 #include "../file.h"
 
@@ -16,6 +17,7 @@
 #define FIO_USE_GENERIC_RAND
 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
 #define FIO_HAVE_FS_STAT
+#define FIO_HAVE_TRIM
 #define FIO_HAVE_CHARDEV_SIZE
 #define FIO_HAVE_GETTID
 
@@ -84,6 +86,20 @@ static inline unsigned long long get_fs_free_size(const char *path)
        return ret;
 }
 
+static inline int os_trim(int fd, unsigned long long start,
+                         unsigned long long len)
+{
+       off_t range[2];
+
+       range[0] = start;
+       range[1] = len;
+
+       if (!ioctl(fd, IOCTLTRIM, range))
+               return 0;
+
+       return errno;
+}
+
 #ifdef MADV_FREE
 #define FIO_MADV_FREE  MADV_FREE
 #endif