Add fallocate and use it instead of posix_fallocate if possible (#398)
authorLiu Bo <liub.liubo@gmail.com>
Thu, 18 Apr 2019 08:55:42 +0000 (01:55 -0700)
committerNikolaus Rath <Nikolaus@rath.org>
Thu, 18 Apr 2019 08:55:42 +0000 (09:55 +0100)
fuse.ko has supported FALLOC_FL_KEEP_SIZE and FALLOC_FL_PUNCH_HOLE at this
moment and more modes may be supported in the future.

fallocate(2) supports modes while posix_fallocate(2) does not, so this
makes lo_fallocate use fallocate(2) instead.

Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
example/passthrough_ll.c
meson.build

index 1598958de9149913f835b465c7aebc9407703ef6..b6ecaffb64fdddc87558a5486f994dc643f97e2a 100644 (file)
@@ -936,12 +936,19 @@ static void lo_fallocate(fuse_req_t req, fuse_ino_t ino, int mode,
        int err;
        (void) ino;
 
+#ifdef HAVE_FALLOCATE
+       err = fallocate(fi->fh, mode, offset, length);
+       if (err < 0)
+               err = errno;
+
+#elif HAVE_POSIX_FALLOCATE
        if (mode) {
                fuse_reply_err(req, EOPNOTSUPP);
                return;
        }
 
        err = posix_fallocate(fi->fh, offset, length);
+#endif
 
        fuse_reply_err(req, err);
 }
index 9c35745966549553d0d7f83a4924551c497f51ad..5797fec3fa7eff51efe375e56154ab8765880ac0 100644 (file)
@@ -36,7 +36,7 @@ cfg.set_quoted('PACKAGE_VERSION', meson.project_version())
 # Test for presence of some functions
 test_funcs = [ 'fork', 'fstatat', 'openat', 'readlinkat', 'pipe2',
                'splice', 'vmsplice', 'posix_fallocate', 'fdatasync',
-               'utimensat', 'copy_file_range' ]
+               'utimensat', 'copy_file_range', 'fallocate' ]
 foreach func : test_funcs
     cfg.set('HAVE_' + func.to_upper(),
         cc.has_function(func, prefix: include_default, args: args_default))