From a34f7ab332a66c2857b212abb6082fcc0e762519 Mon Sep 17 00:00:00 2001 From: legend-hua Date: Sun, 18 Sep 2016 06:20:10 +0800 Subject: [PATCH] Fix FALLOC_FL_PUNCH_HOLE use in randfree_file.c The FALLOC_FL_PUNCH_HOLE flag was introduced in the 2.6.38 kernel. To prevent breaking the build on older systems wrap its use in a conditional. When FALLOC_FL_PUNCH_HOLE isn't available return a non-zero status and error message. Reviewed-by: Brian Behlendorf Signed-off-by: legend-hua Closes #5101 --- tests/zfs-tests/cmd/randfree_file/randfree_file.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/zfs-tests/cmd/randfree_file/randfree_file.c b/tests/zfs-tests/cmd/randfree_file/randfree_file.c index ff30c24c09..05797448c9 100644 --- a/tests/zfs-tests/cmd/randfree_file/randfree_file.c +++ b/tests/zfs-tests/cmd/randfree_file/randfree_file.c @@ -98,11 +98,18 @@ main(int argc, char *argv[]) free(buf); +#if defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE) if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, start_off, off_len) < 0) { perror("fallocate"); return (1); } +#else /* !(defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE)) */ + { + perror("FALLOC_FL_PUNCH_HOLE unsupported"); + return (1); + } +#endif /* defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE) */ return (0); }