diff options
-rwxr-xr-x | tests/features/worm.t | 8 | ||||
-rw-r--r-- | xlators/features/read-only/src/read-only.h | 1 | ||||
-rw-r--r-- | xlators/features/read-only/src/worm-helper.c | 2 | ||||
-rw-r--r-- | xlators/features/read-only/src/worm.c | 10 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volume-set.c | 8 |
5 files changed, 28 insertions, 1 deletions
diff --git a/tests/features/worm.t b/tests/features/worm.t index c725f5858ec..9766dc1ad2b 100755 --- a/tests/features/worm.t +++ b/tests/features/worm.t @@ -64,6 +64,14 @@ TEST `echo "worm 2" >> $M0/file3` EXPECT 'worm 1' cat $M0/file3 TEST ! rm -f $M0/file3 +## Test for checking if Worm files are undeletable after setting worm-files-deletable as 0. +TEST $CLI volume set $V0 features.worm-files-deletable 0 +TEST `echo "worm 1" > $M0/file4` +TEST chmod 0444 $M0/file4 +sleep 10 +TEST `echo "worm 1" >> $M0/file4` +TEST ! rm -f $M0/file4 + TEST $CLI volume stop $V0 EXPECT 'Stopped' volinfo_field $V0 'Status' diff --git a/xlators/features/read-only/src/read-only.h b/xlators/features/read-only/src/read-only.h index d0263e74179..aae625f5eaf 100644 --- a/xlators/features/read-only/src/read-only.h +++ b/xlators/features/read-only/src/read-only.h @@ -28,6 +28,7 @@ typedef struct { typedef struct { gf_boolean_t readonly_or_worm_enabled; gf_boolean_t worm_file; + gf_boolean_t worm_files_deletable; uint64_t reten_period; uint64_t com_period; char *reten_mode; diff --git a/xlators/features/read-only/src/worm-helper.c b/xlators/features/read-only/src/worm-helper.c index 425e48123b1..0770f9d77c4 100644 --- a/xlators/features/read-only/src/worm-helper.c +++ b/xlators/features/read-only/src/worm-helper.c @@ -379,7 +379,7 @@ gf_worm_state_transition (xlator_t *this, gf_boolean_t fop_with_fd, &reten_state, &stbuf); } if (reten_state.worm && !reten_state.retain && - op == GF_FOP_UNLINK) { + priv->worm_files_deletable && op == GF_FOP_UNLINK) { op_errno = 0; goto out; } diff --git a/xlators/features/read-only/src/worm.c b/xlators/features/read-only/src/worm.c index a1474b6bc27..cbe7df8e798 100644 --- a/xlators/features/read-only/src/worm.c +++ b/xlators/features/read-only/src/worm.c @@ -542,6 +542,8 @@ init (xlator_t *this) uint64, out); GF_OPTION_INIT ("auto-commit-period", priv->com_period, uint64, out); GF_OPTION_INIT ("retention-mode", priv->reten_mode, str, out); + GF_OPTION_INIT ("worm-files-deletable", priv->worm_files_deletable, + bool, out); this->private = priv; ret = 0; @@ -569,6 +571,8 @@ reconfigure (xlator_t *this, dict_t *options) out); GF_OPTION_RECONF ("auto-commit-period", priv->com_period, options, uint64, out); + GF_OPTION_RECONF ("worm-files-deletable", priv->worm_files_deletable, + options, bool, out); ret = 0; out: gf_log (this->name, GF_LOG_DEBUG, "returning %d", ret); @@ -632,6 +636,12 @@ struct volume_options options[] = { .description = "When \"on\", activates the file level worm. " "It is turned \"off\" by default." }, + { .key = {"worm-files-deletable"}, + .type = GF_OPTION_TYPE_BOOL, + .default_value = "on", + .description = "When \"off\", doesn't allow the Worm files" + "to be deleted. It is turned \"on\" by default." + }, { .key = {"default-retention-period"}, .type = GF_OPTION_TYPE_TIME, .default_value = "120", diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-set.c b/xlators/mgmt/glusterd/src/glusterd-volume-set.c index 4b3b9350ef2..7155228ce81 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volume-set.c +++ b/xlators/mgmt/glusterd/src/glusterd-volume-set.c @@ -2738,6 +2738,14 @@ struct volopt_map_entry glusterd_volopt_map[] = { .op_version = GD_OP_VERSION_3_8_0, .flags = VOLOPT_FLAG_CLIENT_OPT | VOLOPT_FLAG_XLATOR_OPT }, + { .key = "features.worm-files-deletable", + .voltype = "features/worm", + .option = "worm-files-deletable", + .value = "on", + .validate_fn = validate_boolean, + .op_version = GD_OP_VERSION_3_13_0, + .flags = VOLOPT_FLAG_CLIENT_OPT | VOLOPT_FLAG_XLATOR_OPT + }, { .key = "features.default-retention-period", .voltype = "features/worm", .option = "default-retention-period", |