diff options
| author | Poornima G <pgurusid@redhat.com> | 2018-06-27 14:59:40 +0530 | 
|---|---|---|
| committer | Amar Tumballi <amarts@redhat.com> | 2018-07-11 04:11:59 +0000 | 
| commit | 69f77d28c3ecacba77fbae2f789b5110641347f3 (patch) | |
| tree | 746f1470476a981b6becaedb6c7c1e681f457f41 /xlators/storage | |
| parent | af6c6429f9743f287baaad68f8e3d56ed7390d1b (diff) | |
md-cache: Do not invalidate cache post set/remove xattr
Since setxattr and removexattr fops cbk do not carry poststat,
the stat cache was being invalidated in setxatr/remoxattr cbk.
Hence the further lookup wouldn't be served from cache.
To prevent this invalidation, md-cache is modified to get
the poststat in set/removexattr_cbk in dict.
Co-authored with Xavi Hernandez.
Change-Id: I6b946be2d20b807e2578825743c25ba5927a60b4
fixes: bz#1586018
Signed-off-by: Xavi Hernandez <xhernandez@redhat.com>
Signed-off-by: Poornima G <pgurusid@redhat.com>
Diffstat (limited to 'xlators/storage')
| -rw-r--r-- | xlators/storage/posix/src/posix-entry-ops.c | 2 | ||||
| -rw-r--r-- | xlators/storage/posix/src/posix-helpers.c | 49 | ||||
| -rw-r--r-- | xlators/storage/posix/src/posix-inode-fd-ops.c | 85 | ||||
| -rw-r--r-- | xlators/storage/posix/src/posix.h | 2 | 
4 files changed, 85 insertions, 53 deletions
diff --git a/xlators/storage/posix/src/posix-entry-ops.c b/xlators/storage/posix/src/posix-entry-ops.c index 4241b574bc4..9089603c0fa 100644 --- a/xlators/storage/posix/src/posix-entry-ops.c +++ b/xlators/storage/posix/src/posix-entry-ops.c @@ -1238,7 +1238,7 @@ posix_unlink (call_frame_t *frame, xlator_t *this,                                  "fstat failed on fd=%d", fd);                          goto out;                  } -                op_ret = posix_set_iatt_in_dict (unwind_dict, &postbuf); +                op_ret = posix_set_iatt_in_dict (unwind_dict, NULL, &postbuf);          }          op_ret = posix_pstat (this, loc->parent, loc->pargfid, par_path, diff --git a/xlators/storage/posix/src/posix-helpers.c b/xlators/storage/posix/src/posix-helpers.c index b02adf308ff..f4165cc1111 100644 --- a/xlators/storage/posix/src/posix-helpers.c +++ b/xlators/storage/posix/src/posix-helpers.c @@ -2846,25 +2846,56 @@ posix_is_bulk_removexattr (char *name, dict_t *xdata)  }  int32_t -posix_set_iatt_in_dict (dict_t *dict, struct iatt *in_stbuf) +posix_set_iatt_in_dict (dict_t *dict, struct iatt *preop, struct iatt *postop)  {          int ret             = -1;          struct iatt *stbuf  = NULL;          int32_t len         = sizeof(struct iatt); +        struct iatt *prebuf = NULL; +        struct iatt *postbuf = NULL; -        if (!dict || !in_stbuf) +        if (!dict)                  return ret; -        stbuf = GF_CALLOC (1, len, gf_common_mt_char); -        if (!stbuf) -                return ret; +        if (postop) { +                stbuf = GF_CALLOC (1, len, gf_common_mt_char); +                if (!stbuf) +                        goto out; +                memcpy (stbuf, postop, len); +                ret = dict_set_iatt (dict, DHT_IATT_IN_XDATA_KEY, stbuf, +                                     false); +                if (ret < 0) { +                        GF_FREE (stbuf); +                        goto out; +                } +        } -        memcpy (stbuf, in_stbuf, len); +        if (preop) { +                prebuf = GF_CALLOC (1, len, gf_common_mt_char); +                if (!prebuf) +                        goto out; +                memcpy (prebuf, preop, len); +                ret = dict_set_iatt (dict, GF_PRESTAT, prebuf, false); +                if (ret < 0) { +                        GF_FREE (prebuf); +                        goto out; +                } +        } -        ret = dict_set_iatt (dict, DHT_IATT_IN_XDATA_KEY, stbuf, false); -        if (ret) -                GF_FREE (stbuf); +        if (postop) { +                postbuf = GF_CALLOC (1, len, gf_common_mt_char); +                if (!postbuf) +                        goto out; +                memcpy (postbuf, postop, len); +                ret = dict_set_iatt (dict, GF_POSTSTAT, postbuf, false); +                if (ret < 0) { +                        GF_FREE (postbuf); +                        goto out; +                } +        } +        ret = 0; +out:          return ret;  } diff --git a/xlators/storage/posix/src/posix-inode-fd-ops.c b/xlators/storage/posix/src/posix-inode-fd-ops.c index af13a622feb..0e7d3762ac8 100644 --- a/xlators/storage/posix/src/posix-inode-fd-ops.c +++ b/xlators/storage/posix/src/posix-inode-fd-ops.c @@ -2212,7 +2212,8 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,          int32_t       op_errno                = 0;          char *        real_path               = NULL;          char         *acl_xattr               = NULL; -        struct iatt   stbuf                   = {0}; +        struct iatt   preop                   = {0}; +        struct iatt   postop                  = {0};          int32_t       ret                     = 0;          ssize_t       acl_size                = 0;          dict_t       *xattr                   = NULL; @@ -2245,7 +2246,7 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,                  goto out;          } -        posix_pstat(this, loc->inode, loc->gfid, real_path, &stbuf, _gf_false); +        posix_pstat(this, loc->inode, loc->gfid, real_path, &preop, _gf_false);          op_ret = -1; @@ -2259,7 +2260,7 @@ posix_setxattr (call_frame_t *frame, xlator_t *this,                  /*TODO: move the following to a different function */                  LOCK (&loc->inode->lock);                  { -                state = posix_cs_check_status (this, real_path, NULL, &stbuf); +                state = posix_cs_check_status (this, real_path, NULL, &preop);                  if (state != GF_CS_LOCAL) {                          op_errno = EINVAL;                          ret = posix_cs_set_state (this, &xattr, state, real_path, @@ -2350,7 +2351,7 @@ unlock:          filler.real_path = real_path;          filler.this = this; -        filler.stbuf = &stbuf; +        filler.stbuf = &preop;  #ifdef GF_DARWIN_HOST_OS          filler.flags = map_xattr_flags(flags); @@ -2374,14 +2375,12 @@ unlock:   * This is used by DHT to redirect FOPs if the file is being migrated   * Ignore errors for now   */ -        if (xdata && dict_get (xdata, DHT_IATT_IN_XDATA_KEY)) { -                ret = posix_pstat(this, loc->inode, loc->gfid, real_path, -                                  &stbuf, _gf_false); -                if (ret) -                        goto out; +        ret = posix_pstat(this, loc->inode, loc->gfid, real_path, &postop, +                          _gf_false); +        if (ret) +               goto out; -               ret = posix_set_iatt_in_dict (xattr, &stbuf); -        } +        ret = posix_set_iatt_in_dict (xattr, &preop, &postop);  /*   * ACL can be set on a file/folder using GF_POSIX_ACL_*_KEY xattrs which @@ -3720,7 +3719,8 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,          struct posix_fd   *pfd            = NULL;          int                _fd            = -1;          int                ret            = -1; -        struct  iatt       stbuf          = {0,}; +        struct  iatt       preop          = {0,}; +        struct  iatt       postop         = {0,};          dict_t            *xattr          = NULL;          posix_xattr_filler_t filler       = {0,};          struct  posix_private *priv       = NULL; @@ -3744,7 +3744,7 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,          }          _fd = pfd->fd; -        ret = posix_fdstat (this, fd->inode, pfd->fd, &stbuf); +        ret = posix_fdstat (this, fd->inode, pfd->fd, &preop);          if (ret == -1) {                  op_errno = errno;                  gf_msg (this->name, GF_LOG_ERROR, op_errno, @@ -3759,7 +3759,7 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,          filler.fdnum = _fd;          filler.this = this;          filler.frame = frame; -        filler.stbuf = &stbuf; +        filler.stbuf = &preop;          filler.fd = fd;  #ifdef GF_DARWIN_HOST_OS          filler.flags = map_xattr_flags(flags); @@ -3785,21 +3785,19 @@ posix_fsetxattr (call_frame_t *frame, xlator_t *this,                  }          } -        if (xdata && dict_get (xdata, DHT_IATT_IN_XDATA_KEY)) { -                ret = posix_fdstat (this, fd->inode, pfd->fd, &stbuf); -                if (ret == -1) { -                        op_errno = errno; -                        gf_msg (this->name, GF_LOG_ERROR, op_errno, -                                P_MSG_XATTR_FAILED, "fsetxattr (fstat)" -                                "failed on fd=%p", fd); -                        goto out; -                } - -                xattr = dict_new (); -                if (!xattr) -                        goto out; -                ret = posix_set_iatt_in_dict (xattr, &stbuf); +        ret = posix_fdstat (this, fd->inode, pfd->fd, &postop); +        if (ret == -1) { +                op_errno = errno; +                gf_msg (this->name, GF_LOG_ERROR, op_errno, +                        P_MSG_XATTR_FAILED, "fsetxattr (fstat)" +                        "failed on fd=%p", fd); +                goto out;          } +        xattr = dict_new (); +        if (!xattr) +                goto out; + +        ret = posix_set_iatt_in_dict (xattr, &preop, &postop);  out:          SET_TO_OLD_FS_ID (); @@ -3877,7 +3875,8 @@ posix_common_removexattr (call_frame_t *frame, loc_t *loc, fd_t *fd,          char                 *real_path       = NULL;          struct posix_fd      *pfd             = NULL;          int                  op_ret           = 0; -        struct iatt          stbuf            = {0}; +        struct iatt          preop            = {0,}; +        struct iatt          postop           = {0,};          int                  ret              = 0;          int                  _fd              = -1;          xlator_t             *this            = frame->this; @@ -3913,6 +3912,12 @@ posix_common_removexattr (call_frame_t *frame, loc_t *loc, fd_t *fd,                  goto out;          } +        if (loc) +                ret = posix_pstat(this, inode, loc->gfid, real_path, +                                  &preop, _gf_false); +        else +                ret = posix_fdstat (this, inode, _fd, &preop); +          if (gf_get_index_by_elem (disallow_removexattrs, (char *)name) >= 0) {                  gf_msg (this->name, GF_LOG_WARNING, 0, P_MSG_XATTR_NOT_REMOVED,                          "Remove xattr called on %s for file/dir %s with gfid: " @@ -3968,24 +3973,20 @@ posix_common_removexattr (call_frame_t *frame, loc_t *loc, fd_t *fd,          if (loc) {                  posix_set_ctime (frame, this, real_path, -1, inode, NULL); +                ret = posix_pstat(this, inode, loc->gfid, real_path, &postop, +                                  _gf_false);          } else {                  posix_set_ctime (frame, this, NULL, _fd, inode, NULL); +                ret = posix_fdstat (this, inode, _fd, &postop);          } +        if (ret) +                goto out; +        *xdata_rsp = dict_new(); +        if (!*xdata_rsp) +                goto out; -        if (xdata && dict_get (xdata, DHT_IATT_IN_XDATA_KEY)) { -                if (loc) -                        ret = posix_pstat(this, inode, loc->gfid, -                                          real_path, &stbuf, _gf_false); -                else -                        ret = posix_fdstat (this, inode, _fd, &stbuf); -                if (ret) -                        goto out; -                *xdata_rsp = dict_new(); -                if (!*xdata_rsp) -                        goto out; +        ret = posix_set_iatt_in_dict (*xdata_rsp, &preop, &postop); -                ret = posix_set_iatt_in_dict (*xdata_rsp, &stbuf); -        }          op_ret = 0;  out:          SET_TO_OLD_FS_ID (); diff --git a/xlators/storage/posix/src/posix.h b/xlators/storage/posix/src/posix.h index db525ad9379..a58d510df2e 100644 --- a/xlators/storage/posix/src/posix.h +++ b/xlators/storage/posix/src/posix.h @@ -396,7 +396,7 @@ gf_boolean_t  posix_is_bulk_removexattr (char *name, dict_t *dict);  int32_t -posix_set_iatt_in_dict (dict_t *, struct iatt *); +posix_set_iatt_in_dict (dict_t *, struct iatt *, struct iatt *);  mode_t  posix_override_umask (mode_t , mode_t);  | 
