From 1c7b3eaf87492e875d7ad05f183e98fa306e48c2 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Tue, 8 Jan 2013 09:42:49 -0800 Subject: RHEL 6.4 compat, fallocate() In the upstream kernel the FALLOC_FL_PUNCH_HOLE #define was introduced after the fallocate() function was moved from the inode_operations to the file_operations structure. Therefore, the SPL code assumed that if FALLOC_FL_PUNCH_HOLE was defined it was safe to use f_ops->fallocate(). Unfortunately, the RHEL6.4 kernel has only backported the FALLOC_FL_PUNCH_HOLE #define and not the fallocate() change. To address this compatibility issue the spl_filp_fallocate() helper function was added to properly detect which interface is available. Signed-off-by: Brian Behlendorf --- module/spl/spl-vnode.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'module/spl/spl-vnode.c') diff --git a/module/spl/spl-vnode.c b/module/spl/spl-vnode.c index 0ecd9addf..d8da9814b 100644 --- a/module/spl/spl-vnode.c +++ b/module/spl/spl-vnode.c @@ -654,13 +654,15 @@ int vn_space(vnode_t *vp, int cmd, struct flock *bfp, int flag, ASSERT(bfp->l_start >= 0 && bfp->l_len > 0); #ifdef FALLOC_FL_PUNCH_HOLE - if (vp->v_file->f_op->fallocate) { - error = -vp->v_file->f_op->fallocate(vp->v_file, - FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, - bfp->l_start, bfp->l_len); - if (!error) - SRETURN(0); - } + /* + * When supported by the underlying file system preferentially + * use the fallocate() callback to preallocate the space. + */ + error = -spl_filp_fallocate(vp->v_file, + FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE, + bfp->l_start, bfp->l_len); + if (error == 0) + SRETURN(0); #endif #ifdef HAVE_INODE_TRUNCATE_RANGE -- cgit v1.2.3