diff options
author | karthik-us <ksubrahm@redhat.com> | 2017-04-04 18:57:32 +0530 |
---|---|---|
committer | Niels de Vos <ndevos@redhat.com> | 2017-04-07 08:09:30 -0400 |
commit | a2c3f86db8c9eea19359ddef9d9595b2d372814c (patch) | |
tree | b161d3855487125ac091326a3941572d665b23ad /xlators | |
parent | a01d6f460c09c67f647aa529fc38a229e8461d4e (diff) |
features/worm: Adding implementation for ftruncate
Problem:
Since the ftruncate fop was not handled in the worm feature, when
truncate and write was happening on a worm-retained/worm file, it was
giving the EROFS error but truncating the file, which is not correct.
> Change-Id: I1a7e904655210d78bce9e01652ac56f3783b5aed
> BUG: 1438810
> Signed-off-by: karthik-us <ksubrahm@redhat.com>
> Reviewed-on: https://review.gluster.org/16995
> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
> Reviewed-by: Niels de Vos <ndevos@redhat.com>
> CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Ravishankar N <ravishankar@redhat.com>
> Smoke: Gluster Build System <jenkins@build.gluster.org>
> Reviewed-by: Amar Tumballi <amarts@redhat.com>
> Reviewed-by: Raghavendra Talur <rtalur@redhat.com>
(cherry picked from commit c5a4a77848024d2adf8cd4f35d550ba90c174fc7)
Change-Id: Ic5e904b5bb3d76954a143f92fbfd8959fec884b8
BUG: 1439112
Signed-off-by: karthik-us <ksubrahm@redhat.com>
Reviewed-on: https://review.gluster.org/17000
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: Ravishankar N <ravishankar@redhat.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/features/read-only/src/worm.c | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/xlators/features/read-only/src/worm.c b/xlators/features/read-only/src/worm.c index 3e32d65dbac..dd9d720e569 100644 --- a/xlators/features/read-only/src/worm.c +++ b/xlators/features/read-only/src/worm.c @@ -35,7 +35,7 @@ worm_open (call_frame_t *frame, xlator_t *this, loc_t *loc, int32_t flags, fd_t *fd, dict_t *xdata) { if (is_readonly_or_worm_enabled (this) && - (flags & (O_WRONLY | O_RDWR | O_APPEND))) { + (flags & (O_WRONLY | O_RDWR | O_APPEND | O_TRUNC))) { STACK_UNWIND_STRICT (open, frame, -1, EROFS, NULL, NULL); return 0; } @@ -175,7 +175,7 @@ worm_truncate (call_frame_t *frame, xlator_t *this, loc_t *loc, off_t offset, goto out; } op_errno = gf_worm_state_transition (this, _gf_false, loc, - GF_FOP_TRUNCATE); + GF_FOP_TRUNCATE); out: if (op_errno) @@ -190,6 +190,41 @@ out: static int32_t +worm_ftruncate (call_frame_t *frame, xlator_t *this, fd_t *fd, off_t offset, + dict_t *xdata) +{ + int op_errno = EROFS; + read_only_priv_t *priv = NULL; + + priv = this->private; + GF_ASSERT (priv); + if (is_readonly_or_worm_enabled (this)) + goto out; + if (!priv->worm_file) { + op_errno = 0; + goto out; + } + + if (is_wormfile (this, _gf_true, fd)) { + op_errno = 0; + goto out; + } + op_errno = gf_worm_state_transition (this, _gf_true, fd, + GF_FOP_FTRUNCATE); + +out: + if (op_errno) + STACK_UNWIND_STRICT (ftruncate, frame, -1, op_errno, NULL, NULL, + NULL); + else + STACK_WIND_TAIL (frame, FIRST_CHILD (this), + FIRST_CHILD (this)->fops->ftruncate, + fd, offset, xdata); + return 0; +} + + +static int32_t worm_setattr (call_frame_t *frame, xlator_t *this, loc_t *loc, struct iatt *stbuf, int32_t valid, dict_t *xdata) { @@ -557,6 +592,7 @@ struct xlator_fops fops = { .link = worm_link, .unlink = worm_unlink, .truncate = worm_truncate, + .ftruncate = worm_ftruncate, .create = worm_create, .rmdir = ro_rmdir, |