diff options
author | Soumya Koduri <skoduri@redhat.com> | 2016-10-06 13:13:44 +0530 |
---|---|---|
committer | Raghavendra G <rgowdapp@redhat.com> | 2016-11-03 20:19:47 -0700 |
commit | b0f4fc9d05a1e5169205b88e81ca0fbdd28b3dd2 (patch) | |
tree | ec05654b648b3ba1fb3fe5a71f8aec374fa521c9 /xlators/performance/md-cache/src/md-cache.c | |
parent | 7c4f26a7a966729da3f3a2d30a590dee23cae3f4 (diff) |
md-cache: Invalidate cache entry for open() with O_TRUNC
When a file is opened with O_TRUNC flag set, its size gets
set to '0'. This case needs to be handled in md-cache to
avoid sending incorrect cached stat.
This is backport of below mainline patch -
http://review.gluster.org/#/c/15618/
> Change-Id: I95d1f8a6634734898883ede010c3e7b0b7eb97d9
> BUG: 1382266
> Signed-off-by: Soumya Koduri <skoduri@redhat.com>
> Reviewed-on: http://review.gluster.org/15618
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: jiffin tony Thottan <jthottan@redhat.com>
> Tested-by: jiffin tony Thottan <jthottan@redhat.com>
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
> (cherry picked from commit 6ca5d6382f03685b31b12accb095093cf1486603)
Change-Id: I92349f5b48aef07f3790db7aae25bfa2ddb5947e
BUG: 1391450
Signed-off-by: Soumya Koduri <skoduri@redhat.com>
Reviewed-on: http://review.gluster.org/15771
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: Kaleb KEITHLEY <kkeithle@redhat.com>
Diffstat (limited to 'xlators/performance/md-cache/src/md-cache.c')
-rw-r--r-- | xlators/performance/md-cache/src/md-cache.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/xlators/performance/md-cache/src/md-cache.c b/xlators/performance/md-cache/src/md-cache.c index 31bc8d8187d..30443761c56 100644 --- a/xlators/performance/md-cache/src/md-cache.c +++ b/xlators/performance/md-cache/src/md-cache.c @@ -1506,6 +1506,53 @@ mdc_create (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, } +static int +mdc_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, + dict_t *xdata) +{ + mdc_local_t *local = NULL; + + local = frame->local; + + if (op_ret || !local) + goto out; + + if (local->fd->flags & O_TRUNC) { + /* O_TRUNC modifies file size. Hence invalidate the + * cache entry to fetch latest attributes. */ + mdc_inode_iatt_invalidate (this, local->fd->inode); + } + +out: + MDC_STACK_UNWIND (open, frame, op_ret, op_errno, fd, xdata); + return 0; +} + + +static int +mdc_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int flags, + fd_t *fd, dict_t *xdata) +{ + mdc_local_t *local = NULL; + + if (!fd || !IA_ISREG(fd->inode->ia_type) || + !(fd->flags & O_TRUNC)) { + goto out; + } + + local = mdc_local_get (frame); + + local->fd = fd_ref (fd); + +out: + STACK_WIND (frame, mdc_open_cbk, + FIRST_CHILD(this), FIRST_CHILD(this)->fops->open, + loc, flags, fd, xdata); + return 0; +} + + int mdc_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, int32_t op_ret, int32_t op_errno, @@ -2385,6 +2432,7 @@ struct xlator_fops fops = { .rename = mdc_rename, .link = mdc_link, .create = mdc_create, + .open = mdc_open, .readv = mdc_readv, .writev = mdc_writev, .setattr = mdc_setattr, |