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 <behlendorf1@llnl.gov> Signed-off-by: legend-hua <liu.hua130@zte.com.cn> Closes #5101
This commit is contained in:
parent
30f3f2e13c
commit
a34f7ab332
|
@ -98,11 +98,18 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
|
#if defined(FALLOC_FL_PUNCH_HOLE) && defined(FALLOC_FL_KEEP_SIZE)
|
||||||
if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
|
if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
|
||||||
start_off, off_len) < 0) {
|
start_off, off_len) < 0) {
|
||||||
perror("fallocate");
|
perror("fallocate");
|
||||||
return (1);
|
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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue