From 0f2c1fdee27cf6c35dee129d14f7226a20464c23 Mon Sep 17 00:00:00 2001 From: Ravishankar N Date: Thu, 28 Jul 2016 20:42:45 +0530 Subject: posix: leverage FALLOC_FL_ZERO_RANGE in zerofill fop posix_zerofill() implements zerofilling of a given (offset,length) by doing a writev in a loop followed by an optional fsync on the file. fallocate(2) has a FALLOC_FL_ZERO_RANGE flag which does away with all this and provides the same result (from a userspace application point of view) with a single syscall. This patch attempts the zerofill with the latter and falls back to the former if it fails. Tested using a libgfapi based C program on XFS and observed using gdb that posix_zerofill()'s call to fallocate with FALLOC_FL_ZERO_RANGE was a success. > Reviewed-on: http://review.gluster.org/15037 > Reviewed-on: http://review.gluster.org/15100 > Smoke: Gluster Build System > CentOS-regression: Gluster Build System > NetBSD-regression: NetBSD Build System > Reviewed-by: Pranith Kumar Karampuri BUG: 1363750 Change-Id: I77e9b7de0d59c255f06b0c39c43a276990081727 Signed-off-by: Ravishankar N Signed-off-by: Oleksandr Natalenko Reviewed-on: http://review.gluster.org/15082 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System Reviewed-by: Prashanth Pai CentOS-regression: Gluster Build System Reviewed-by: Pranith Kumar Karampuri --- xlators/storage/posix/src/posix.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index 290ff4e3f8e..ec1793e37a0 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -820,6 +820,7 @@ posix_do_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, { int32_t ret = -1; int32_t op_errno = 0; + int32_t flags = 0; struct posix_fd *pfd = NULL; gf_boolean_t locked = _gf_false; @@ -850,6 +851,14 @@ posix_do_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, goto out; } + /* See if we can use FALLOC_FL_ZERO_RANGE to perform the zero fill. + * If it fails, fall back to _posix_do_zerofill() and an optional fsync. + */ + flags = FALLOC_FL_ZERO_RANGE; + ret = sys_fallocate (pfd->fd, flags, offset, len); + if (ret == 0) + goto fsync; + ret = _posix_do_zerofill (pfd->fd, offset, len, pfd->flags & O_DIRECT); if (ret < 0) { ret = -errno; @@ -859,6 +868,7 @@ posix_do_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, goto out; } +fsync: if (pfd->flags & (O_SYNC|O_DSYNC)) { ret = fsync (pfd->fd); if (ret) { -- cgit