Skip to content

Commit

Permalink
Mark Linux fallocate extensions as specific to Linux
Browse files Browse the repository at this point in the history
fallocate(2) is a Linux-specific system call which in unavailable
on other platforms.

Reviewed-by: Jorgen Lundman <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Matt Macy <[email protected]>
Closes #9633
  • Loading branch information
mattmacy authored and behlendorf committed Nov 30, 2019
1 parent 77323bc commit f348c78
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/libzpool/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,11 @@ zfs_file_fsync(zfs_file_t *fp, int flags)
int
zfs_file_fallocate(zfs_file_t *fp, int mode, loff_t offset, loff_t len)
{
#ifdef __linux__
return (fallocate(fp->f_fd, mode, offset, len));
#else
return (EOPNOTSUPP);
#endif
}

/*
Expand Down
8 changes: 5 additions & 3 deletions module/os/linux/zfs/vdev_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
#include <sys/fcntl.h>
#include <sys/vnode.h>
#include <sys/zfs_file.h>

#ifdef _KERNEL

This comment has been minimized.

Copy link
@likema

likema Sep 25, 2021

It would cause building rpm error on RHEL 7

../../module/os/linux/zfs/vdev_file.c: In function 'vdev_file_io_start':
../../module/os/linux/zfs/vdev_file.c:287:10: error: 'FALLOC_FL_PUNCH_HOLE' undeclared (first use in this function)
   mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
          ^~~~~~~~~~~~~~~~~~~~
../../module/os/linux/zfs/vdev_file.c:287:10: note: each undeclared identifier is reported only once for each function it appears in
  CC       zap_micro.lo
  CC       zcp.lo
../../module/os/linux/zfs/vdev_file.c:287:33: error: 'FALLOC_FL_KEEP_SIZE' undeclared (first use in this function); did you mean 'FALLOC_FL_PUNCH_HOLE'?
   mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
                                 ^~~~~~~~~~~~~~~~~~~
                                 FALLOC_FL_PUNCH_HOLE
Makefile:1304: recipe for target 'vdev_file.lo' failed
make[5]: *** [vdev_file.lo] Error 1
make[5]: *** Waiting for unfinished jobs....
make[5]: Leaving directory '/tmp/zfs-build--Ro74zrKi/BUILD/zfs-2.0.6/lib/libzpool'
Makefile:695: recipe for target 'all-recursive' failed
make[4]: Leaving directory '/tmp/zfs-build--Ro74zrKi/BUILD/zfs-2.0.6/lib'
make[4]: *** [all-recursive] Error 1
make[3]: *** [all-recursive] Error 1
Makefile:896: recipe for target 'all-recursive' failed
#include <linux/falloc.h>

#endif
/*
* Virtual device vector for files.
*/
Expand Down Expand Up @@ -268,10 +268,12 @@ vdev_file_io_start(zio_t *zio)
zio_execute(zio);
return;
} else if (zio->io_type == ZIO_TYPE_TRIM) {
int mode;
int mode = 0;

ASSERT3U(zio->io_size, !=, 0);
#ifdef __linux__
mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
#endif
zio->io_error = zfs_file_fallocate(vf->vf_file,
mode, zio->io_offset, zio->io_size);
zio_execute(zio);
Expand Down

0 comments on commit f348c78

Please sign in to comment.