diff options
| author | Krutika Dhananjay <kdhananj@redhat.com> | 2016-01-13 16:19:15 +0530 | 
|---|---|---|
| committer | Pranith Kumar Karampuri <pkarampu@redhat.com> | 2016-01-22 22:02:32 -0800 | 
| commit | e67712c06b64fb659824b3f79164f2789693acee (patch) | |
| tree | be6c735bb977bd8c486a80649a9237773c140192 | |
| parent | ea94b2b8767e0d477a672355d758e0e8393362ee (diff) | |
features/shard: Implement zerofill FOP
Change-Id: Iabb89a502cc560edd7fe3755623c74a2ccb853d5
BUG: 1261841
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
Reviewed-on: http://review.gluster.org/13234
Smoke: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
Tested-by: Pranith Kumar Karampuri <pkarampu@redhat.com>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.com>
| -rw-r--r-- | tests/bugs/shard/bug-shard-zerofill.c | 59 | ||||
| -rw-r--r-- | tests/bugs/shard/bug-shard-zerofill.t | 50 | ||||
| -rw-r--r-- | xlators/features/shard/src/shard.c | 53 | ||||
| -rw-r--r-- | xlators/storage/posix/src/posix.c | 28 | 
4 files changed, 164 insertions, 26 deletions
diff --git a/tests/bugs/shard/bug-shard-zerofill.c b/tests/bugs/shard/bug-shard-zerofill.c new file mode 100644 index 00000000000..2ec411921cf --- /dev/null +++ b/tests/bugs/shard/bug-shard-zerofill.c @@ -0,0 +1,59 @@ +#include <stdio.h> +#include "glfs.h" +#include "glfs-handles.h" + +int +main (int argc, char *argv[]) +{ +        glfs_t    *fs = NULL; +        glfs_fd_t *fd = NULL; +        int        ret = 1; + +        if (argc != 4) { +                fprintf (stderr, "Syntax: %s <host> <volname> <file-path> \n", argv[0]); +                return 1; +        } + +        fs = glfs_new (argv[2]); +        if (!fs) { +                fprintf (stderr, "glfs_new: returned NULL\n"); +                return 1; +        } + +        ret = glfs_set_volfile_server (fs, "tcp", argv[1], 24007); +        if (ret != 0) { +                fprintf (stderr, "glfs_set_volfile_server: retuned %d\n", ret); +                goto out; +        } +        ret = glfs_set_logging (fs, "/var/log/glusterfs/glfs-dis.log", 7); +        if (ret != 0) { +                fprintf (stderr, "glfs_set_logging: returned %d\n", ret); +                goto out; +        } +        ret = glfs_init (fs); +        if (ret != 0) { +                fprintf (stderr, "glfs_init: returned %d\n", ret); +                goto out; +        } + +        fd = glfs_open (fs, argv[3], O_RDWR); +        if (fd == NULL) { +                fprintf (stderr, "glfs_open: returned NULL\n"); +                goto out; +        } + +        /* Zero-fill "foo" with 10MB of data */ +        ret = glfs_zerofill (fd, 0, 10485760); +        if (ret <= 0) { +                fprintf (stderr, "glfs_zerofill: returned %d\n", ret); +                goto out; +        } + +        glfs_close(fd); + +        ret = 0; + +out: +        glfs_fini (fs); +        return ret; +} diff --git a/tests/bugs/shard/bug-shard-zerofill.t b/tests/bugs/shard/bug-shard-zerofill.t new file mode 100644 index 00000000000..d5113001b69 --- /dev/null +++ b/tests/bugs/shard/bug-shard-zerofill.t @@ -0,0 +1,50 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../volume.rc + +function file_all_zeroes { +        < $1 tr -d '\0' | read -n 1 || echo 1 +} + +cleanup + +TEST glusterd +TEST pidof glusterd +TEST $CLI volume create $V0 replica 2 $H0:$B0/${V0}{0..3} +TEST $CLI volume set $V0 features.shard on +TEST $CLI volume start $V0 + +TEST $GFS --volfile-id=$V0 --volfile-server=$H0 $M0 + +# Create a file. +TEST touch $M0/foo + +gfid_foo=`getfattr -n glusterfs.gfid.string $M0/foo 2>/dev/null \ +          | grep glusterfs.gfid.string | cut -d '"' -f 2` + +TEST gcc -Wall -O2 -I api/src -o $(dirname $0)/bug-shard-zerofill $(dirname $0)/bug-shard-zerofill.c -lgfapi +TEST $(dirname $0)/bug-shard-zerofill $H0 $V0 /foo + +# This should ensure /.shard is created on the bricks. +TEST stat $B0/${V0}0/.shard +TEST stat $B0/${V0}1/.shard +TEST stat $B0/${V0}2/.shard +TEST stat $B0/${V0}3/.shard + +EXPECT "4194304" echo `find $B0 -name $gfid_foo.1 | xargs stat -c %s` +EXPECT "2097152" echo `find $B0 -name $gfid_foo.2 | xargs stat -c %s` + +EXPECT "1" file_all_zeroes $M0/foo + +TEST `echo "abc" >> $M0/foo` + +EXPECT_NOT "1" file_all_zeroes $M0/foo + +TEST umount $M0 +TEST $CLI volume stop $V0 +TEST $CLI volume delete $V0 + +TEST rm -f $(dirname $0)/bug-shard-zerofill + +cleanup diff --git a/xlators/features/shard/src/shard.c b/xlators/features/shard/src/shard.c index 89a47ef2ce2..e46d4dc33ec 100644 --- a/xlators/features/shard/src/shard.c +++ b/xlators/features/shard/src/shard.c @@ -498,6 +498,10 @@ shard_common_inode_write_failure_unwind (glusterfs_fop_t fop,                  SHARD_STACK_UNWIND (fallocate, frame, op_ret, op_errno,                                      NULL, NULL, NULL);                  break; +        case GF_FOP_ZEROFILL: +                SHARD_STACK_UNWIND (zerofill, frame, op_ret, op_errno, +                                    NULL, NULL, NULL); +                break;          default:                  gf_msg (THIS->name, GF_LOG_WARNING, 0, SHARD_MSG_INVALID_FOP,                          "Invalid fop id = %d", fop); @@ -523,6 +527,10 @@ shard_common_inode_write_success_unwind (glusterfs_fop_t fop,                  SHARD_STACK_UNWIND (fallocate, frame, op_ret, 0, &local->prebuf,                                      &local->postbuf, local->xattr_rsp);                  break; +        case GF_FOP_ZEROFILL: +                SHARD_STACK_UNWIND (zerofill, frame, op_ret, 0, &local->prebuf, +                                    &local->postbuf, local->xattr_rsp); +                break;          default:                  gf_msg (THIS->name, GF_LOG_WARNING, 0, SHARD_MSG_INVALID_FOP,                          "Invalid fop id = %d", fop); @@ -3520,7 +3528,7 @@ shard_common_inode_write_do_cbk (call_frame_t *frame, void *cookie,  int  shard_common_inode_write_wind (call_frame_t *frame, xlator_t *this, -                               fd_t *anon_fd, struct iovec *vec, int count, +                               fd_t *fd, struct iovec *vec, int count,                                 off_t shard_offset, size_t size)  {          shard_local_t *local = NULL; @@ -3529,19 +3537,25 @@ shard_common_inode_write_wind (call_frame_t *frame, xlator_t *this,          switch (local->fop) {          case GF_FOP_WRITE: -                STACK_WIND_COOKIE (frame, shard_common_inode_write_do_cbk, -                                   anon_fd, FIRST_CHILD(this), -                                   FIRST_CHILD(this)->fops->writev, anon_fd, -                                   vec, count, shard_offset, local->flags, +                STACK_WIND_COOKIE (frame, shard_common_inode_write_do_cbk, fd, +                                   FIRST_CHILD(this), +                                   FIRST_CHILD(this)->fops->writev, fd, vec, +                                   count, shard_offset, local->flags,                                     local->iobref, local->xattr_req);                  break;          case GF_FOP_FALLOCATE: -                STACK_WIND_COOKIE (frame, shard_common_inode_write_do_cbk, -                                   anon_fd, FIRST_CHILD(this), -                                   FIRST_CHILD(this)->fops->fallocate, anon_fd, +                STACK_WIND_COOKIE (frame, shard_common_inode_write_do_cbk, fd, +                                   FIRST_CHILD(this), +                                   FIRST_CHILD(this)->fops->fallocate, fd,                                     local->flags, shard_offset, size,                                     local->xattr_req);                  break; +        case GF_FOP_ZEROFILL: +                STACK_WIND_COOKIE (frame, shard_common_inode_write_do_cbk, fd, +                                   FIRST_CHILD(this), +                                   FIRST_CHILD(this)->fops->zerofill, fd, +                                   shard_offset, size, local->xattr_req); +                break;          default:                  gf_msg (this->name, GF_LOG_WARNING, 0, SHARD_MSG_INVALID_FOP,                          "Invalid fop id = %d", local->fop); @@ -4479,6 +4493,11 @@ shard_common_inode_write_begin (call_frame_t *frame, xlator_t *this,                                           FIRST_CHILD(this)->fops->fallocate, fd,                                           flags, offset, len, xdata);                          break; +                case GF_FOP_ZEROFILL: +                        STACK_WIND_TAIL (frame, FIRST_CHILD(this), +                                         FIRST_CHILD(this)->fops->zerofill, +                                         fd, offset, len, xdata); +                        break;                  default:                  gf_msg (this->name, GF_LOG_WARNING, 0, SHARD_MSG_INVALID_FOP,                          "Invalid fop id = %d", fop); @@ -4573,24 +4592,22 @@ shard_fallocate (call_frame_t *frame, xlator_t *this, fd_t *fd,  }  int -shard_discard (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, -              size_t len, dict_t *xdata) +shard_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, +                off_t len, dict_t *xdata)  { -        /* TBD */ -        gf_msg (this->name, GF_LOG_INFO, ENOTSUP, SHARD_MSG_FOP_NOT_SUPPORTED, -                "discard called on %s.", uuid_utoa (fd->inode->gfid)); -        SHARD_STACK_UNWIND (discard, frame, -1, ENOTSUP, NULL, NULL, NULL); +        shard_common_inode_write_begin (frame, this, GF_FOP_ZEROFILL, fd, NULL, +                                        0, offset, 0, len, NULL, xdata);          return 0;  }  int -shard_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, -                off_t len, dict_t *xdata) +shard_discard (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, +              size_t len, dict_t *xdata)  {          /* TBD */          gf_msg (this->name, GF_LOG_INFO, ENOTSUP, SHARD_MSG_FOP_NOT_SUPPORTED, -                "zerofill called on %s.", uuid_utoa (fd->inode->gfid)); -        SHARD_STACK_UNWIND (zerofill, frame, -1, ENOTSUP, NULL, NULL, NULL); +                "discard called on %s.", uuid_utoa (fd->inode->gfid)); +        SHARD_STACK_UNWIND (discard, frame, -1, ENOTSUP, NULL, NULL, NULL);          return 0;  } diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c index e834fc09752..b0c23716a64 100644 --- a/xlators/storage/posix/src/posix.c +++ b/xlators/storage/posix/src/posix.c @@ -809,12 +809,13 @@ err:  }  static int32_t -posix_do_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, -                  off_t offset, off_t len, struct iatt *statpre, -                  struct iatt *statpost) +posix_do_zerofill (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, +                   off_t len, struct iatt *statpre, struct iatt *statpost, +                   dict_t *xdata)  { -        struct posix_fd *pfd       = NULL; -        int32_t          ret       = -1; +        int32_t            ret       = -1; +        struct posix_fd   *pfd       = NULL; +        gf_boolean_t       locked    = _gf_false;          DECLARE_OLD_FS_ID_VAR; @@ -830,6 +831,11 @@ posix_do_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd,                  goto out;          } +        if (dict_get (xdata, GLUSTERFS_WRITE_UPDATE_ATOMIC)) { +                locked = _gf_true; +                LOCK(&fd->inode->lock); +        } +          ret = posix_fdstat (this, pfd->fd, statpre);          if (ret == -1) {                  ret = -errno; @@ -837,7 +843,8 @@ posix_do_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd,                          "pre-operation fstat failed on fd = %p", fd);                  goto out;          } -        ret = _posix_do_zerofill(pfd->fd, offset, len, pfd->flags & O_DIRECT); + +        ret = _posix_do_zerofill (pfd->fd, offset, len, pfd->flags & O_DIRECT);          if (ret < 0) {                  ret = -errno;                  gf_msg (this->name, GF_LOG_ERROR, errno, P_MSG_ZEROFILL_FAILED, @@ -845,6 +852,7 @@ posix_do_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd,                          pfd->fd, len);                  goto out;          } +          if (pfd->flags & (O_SYNC|O_DSYNC)) {                  ret = sys_fsync (pfd->fd);                  if (ret) { @@ -865,6 +873,10 @@ posix_do_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd,          }  out: +	if (locked) { +		UNLOCK (&fd->inode->lock); +		locked = _gf_false; +	}          SET_TO_OLD_FS_ID ();          return ret; @@ -932,8 +944,8 @@ posix_zerofill(call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset,          struct  iatt statpre             = {0,};          struct  iatt statpost            = {0,}; -        ret = posix_do_zerofill(frame, this, fd, offset, len, -                                 &statpre, &statpost); +        ret = posix_do_zerofill (frame, this, fd, offset, len, +                                 &statpre, &statpost, xdata);          if (ret < 0)                  goto err;  | 
