diff options
author | Ravishankar N <ravishankar@redhat.com> | 2016-07-28 20:42:45 +0530 |
---|---|---|
committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2016-07-29 23:03:52 -0700 |
commit | fe1054110ac54750ca0333a727d83b14a98e165e (patch) | |
tree | a747d706d951e3141ee56eff1af19c22a33276c5 | |
parent | c579303bfc4704187b1a41f658b8b3dc75b55c56 (diff) |
posix: leverage FALLOC_FL_ZERO_RANGE in zerofill fop
Backport of http://review.gluster.org/#/c/15037/
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.
Change-Id: Iceaf0cbc57c52dac63540872e8538d79e8dee631
BUG: 1361483
Signed-off-by: Ravishankar N <ravishankar@redhat.com>
Reviewed-on: http://review.gluster.org/15044
Smoke: Gluster Build System <jenkins@build.gluster.org>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
-rw-r--r-- | xlators/storage/posix/src/posix.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index a963f8a3b6b..bce074b4fd1 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -821,6 +821,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; @@ -851,6 +852,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 done; + ret = _posix_do_zerofill (pfd->fd, offset, len, pfd->flags & O_DIRECT); if (ret < 0) { ret = -errno; @@ -871,6 +880,7 @@ posix_do_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, } } +done: ret = posix_fdstat (this, pfd->fd, statpost); if (ret == -1) { ret = -errno; |