diff options
5 files changed, 69 insertions, 32 deletions
diff --git a/tests/bugs/snapshot/bug-1202436-calculate-quota-cksum-during-snap-restore.t b/tests/bugs/snapshot/bug-1202436-calculate-quota-cksum-during-snap-restore.t new file mode 100644 index 00000000000..300b300febe --- /dev/null +++ b/tests/bugs/snapshot/bug-1202436-calculate-quota-cksum-during-snap-restore.t @@ -0,0 +1,39 @@ +#!/bin/bash + +. $(dirname $0)/../../include.rc +. $(dirname $0)/../../cluster.rc +. $(dirname $0)/../../volume.rc +. $(dirname $0)/../../snapshot.rc + +cleanup; + +TEST verify_lvm_version +TEST launch_cluster 2 +TEST setup_lvm 1 + +TEST $CLI_1 volume create $V0 $H1:$L1 +EXPECT 'Created' volinfo_field $V0 'Status' + +TEST $CLI_1 volume start $V0 +EXPECT 'Started' volinfo_field $V0 'Status' + +# Quota is not working with cluster test framework +# Need to check why, Until then commenting out this +#TEST $CLI_1 volume quota $V0 enable +#EXPECT 'on' volinfo_field $V0 'features.quota' + +TEST $CLI_1 snapshot create ${V0}_snap $V0 +EXPECT '1' get_snap_count CLI_1 $V0 + +TEST $CLI_1 volume stop $V0 +EXPECT 'Stopped' volinfo_field $V0 'Status' + +TEST $CLI_1 snapshot restore $($CLI_1 snapshot list) +EXPECT '0' get_snap_count CLI_1 $V0 + +TEST $CLI_1 peer probe $H2 +EXPECT_WITHIN $PROBE_TIMEOUT 1 peer_count + +cleanup; + + diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c index 8819f69c594..1da8a5b4490 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.c @@ -3054,7 +3054,8 @@ out: int32_t glusterd_copy_quota_files (glusterd_volinfo_t *src_vol, - glusterd_volinfo_t *dest_vol) { + glusterd_volinfo_t *dest_vol, + gf_boolean_t *conf_present) { int32_t ret = -1; char src_dir[PATH_MAX] = ""; @@ -3104,33 +3105,7 @@ glusterd_copy_quota_files (glusterd_volinfo_t *src_vol, goto out; } - ret = snprintf (src_path, sizeof (src_path), "%s/quota.cksum", - src_dir); - if (ret < 0) - goto out; - - /* If quota.conf is present and quota.cksum is not present, then - * that scenario is considered as invalid, hence error out. - */ - ret = lstat (src_path, &stbuf); - if (ret) { - ret = -1; - gf_log (this->name, GF_LOG_ERROR, "%s not found", src_path); - goto out; - } - - ret = snprintf (dest_path, sizeof (dest_path), "%s/quota.cksum", - dest_dir); - if (ret < 0) - goto out; - - ret = glusterd_copy_file (src_path, dest_path); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, "Failed to copy %s in %s", - src_path, dest_path); - goto out; - } - + *conf_present = _gf_true; out: return ret; diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h index 07a9709b65f..68906dcf59e 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot-utils.h @@ -96,7 +96,8 @@ glusterd_restore_geo_rep_files (glusterd_volinfo_t *snap_vol); int32_t glusterd_copy_quota_files (glusterd_volinfo_t *src_vol, - glusterd_volinfo_t *dest_vol); + glusterd_volinfo_t *dest_vol, + gf_boolean_t *conf_present); int glusterd_snap_use_rsp_dict (dict_t *aggr, dict_t *rsp_dict); diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index 6d1f79b65d0..cdd19cd354d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -4707,7 +4707,8 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, int32_t brick_count = 0; xlator_t *this = NULL; int64_t brick_order = 0; - char *clonename = NULL; + char *clonename = NULL; + gf_boolean_t conf_present = _gf_false; this = THIS; GF_ASSERT (this); @@ -4834,7 +4835,7 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, goto out; } - ret = glusterd_copy_quota_files (origin_vol, snap_vol); + ret = glusterd_copy_quota_files (origin_vol, snap_vol, &conf_present); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to copy quota " "config and cksum for volume %s", origin_vol->volname); @@ -8781,6 +8782,7 @@ gd_restore_snap_volume (dict_t *dict, dict_t *rsp_dict, glusterd_conf_t *conf = NULL; glusterd_volinfo_t *temp_volinfo = NULL; glusterd_volinfo_t *voliter = NULL; + gf_boolean_t conf_present = _gf_false; this = THIS; GF_ASSERT (this); @@ -8870,7 +8872,7 @@ gd_restore_snap_volume (dict_t *dict, dict_t *rsp_dict, snap_vol->snapshot->snapname); } - ret = glusterd_copy_quota_files (snap_vol, orig_vol); + ret = glusterd_copy_quota_files (snap_vol, orig_vol, &conf_present); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to restore " "quota files for snap %s", @@ -8878,6 +8880,25 @@ gd_restore_snap_volume (dict_t *dict, dict_t *rsp_dict, goto out; } + if (conf_present) { + /* TO calculate checksum of quota conf we need to send + * second argument as _gf_true + */ + ret = glusterd_compute_cksum (new_volinfo, _gf_true); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to compute " + "checksum for quota conf file"); + goto out; + } + + ret = glusterd_store_save_quota_version_and_cksum (new_volinfo); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to " + "store quota version and cksum"); + goto out; + } + } + /* New volinfo always shows the status as created. Therefore * set the status to the original volume's status. */ glusterd_set_volume_status (new_volinfo, orig_vol->status); diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 4863733f84c..468b3c0af45 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -560,6 +560,7 @@ glusterd_volinfo_dup (glusterd_volinfo_t *volinfo, new_volinfo->transport_type = volinfo->transport_type; new_volinfo->brick_count = volinfo->brick_count; new_volinfo->tier_info = volinfo->tier_info; + new_volinfo->quota_conf_version = volinfo->quota_conf_version; dict_copy (volinfo->dict, new_volinfo->dict); dict_copy (volinfo->gsync_slaves, new_volinfo->gsync_slaves); |