From b3031351b0e69195413f5f5b9cad2752e3eb713d Mon Sep 17 00:00:00 2001 From: Sachin Pandit Date: Sat, 26 Apr 2014 14:06:47 +0530 Subject: glusterd/snapshot : Copy the quota config and cksum file before taking a snapshot Quota config and cksum file needs to be copied before taking a snapshot, so that when a snapshot is restored these files is copied back to the original place, and the restored snap volume can make use of these quota files. Before taking a snapshot the quota files are copied to /var/lib/glusterd/snaps//quota/ Change-Id: Id175f28d4ee47be64d7491c6aae81a1794928490 BUG: 1061685 Signed-off-by: Sachin Pandit Reviewed-on: http://review.gluster.org/7527 Reviewed-by: Vijaikumar Mallikarjuna Reviewed-by: Raghavendra G Reviewed-by: Rajesh Joseph Tested-by: Gluster Build System Reviewed-by: Vijay Bellur --- xlators/mgmt/glusterd/src/glusterd-snapshot.c | 19 +++++- xlators/mgmt/glusterd/src/glusterd-utils.c | 96 ++++++++++++++++++++++++++- xlators/mgmt/glusterd/src/glusterd-utils.h | 4 ++ 3 files changed, 116 insertions(+), 3 deletions(-) diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index ad787070e8c..9c64fe2d61a 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -410,7 +410,6 @@ out: return ret; } - int32_t glusterd_copy_geo_rep_files (glusterd_volinfo_t *origin_vol, glusterd_volinfo_t *snap_vol, dict_t *rsp_dict) @@ -3714,6 +3713,13 @@ glusterd_do_snap_vol (glusterd_volinfo_t *origin_vol, glusterd_snap_t *snap, goto out; } + ret = glusterd_copy_quota_files (origin_vol, snap_vol); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to copy quota " + "config and cksum for volume %s", origin_vol->volname); + goto out; + } + ret = generate_brick_volfiles (snap_vol); if (ret) { gf_log (this->name, GF_LOG_ERROR, "generating the brick " @@ -6068,7 +6074,16 @@ gd_restore_snap_volume (dict_t *rsp_dict, ret = glusterd_restore_geo_rep_files (snap_vol); if (ret) { gf_log (this->name, GF_LOG_ERROR, "Failed to restore " - "geo-rep files"); + "geo-rep files for snap %s", + snap_vol->snapshot->snapname); + goto out; + } + + ret = glusterd_copy_quota_files (snap_vol, orig_vol); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to restore " + "quota files for snap %s", + snap_vol->snapshot->snapname); goto out; } diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index db08ce56495..65aa5e1bf7d 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -11618,6 +11618,8 @@ glusterd_copy_file (const char *source, const char *destination) int src_fd = -1; int dest_fd = -1; int read_len = -1; + struct stat stbuf = {0,}; + mode_t dest_mode = 0; this = THIS; GF_ASSERT (this); @@ -11625,6 +11627,15 @@ glusterd_copy_file (const char *source, const char *destination) GF_ASSERT (source); GF_ASSERT (destination); + /* Here is stat is made to get the file permission of source file*/ + ret = lstat (source, &stbuf); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "%s not found", source); + goto out; + } + + dest_mode = stbuf.st_mode & 0777; + src_fd = open (source, O_RDONLY); if (src_fd < 0) { ret = -1; @@ -11633,7 +11644,7 @@ glusterd_copy_file (const char *source, const char *destination) goto out; } - dest_fd = open (destination, O_CREAT | O_RDWR, 755); + dest_fd = open (destination, O_CREAT | O_RDWR, dest_mode); if (dest_fd < 0) { ret = -1; gf_log (this->name, GF_LOG_ERROR, @@ -11805,6 +11816,89 @@ out: return ret; } +int32_t +glusterd_copy_quota_files (glusterd_volinfo_t *src_vol, + glusterd_volinfo_t *dest_vol) { + + int32_t ret = -1; + char src_dir[PATH_MAX] = ""; + char dest_dir[PATH_MAX] = ""; + char src_path[PATH_MAX] = ""; + char dest_path[PATH_MAX] = ""; + xlator_t *this = NULL; + glusterd_conf_t *priv = NULL; + struct stat stbuf = {0,}; + + this = THIS; + GF_ASSERT (this); + priv = this->private; + GF_ASSERT (priv); + + GF_ASSERT (src_vol); + GF_ASSERT (dest_vol); + + GLUSTERD_GET_VOLUME_DIR (src_dir, src_vol, priv); + + GLUSTERD_GET_VOLUME_DIR (dest_dir, dest_vol, priv); + + ret = snprintf (src_path, sizeof (src_path), "%s/quota.conf", + src_dir); + if (ret < 0) + goto out; + + /* quota.conf is not present if quota is not enabled, Hence ignoring + * the absence of this file + */ + ret = lstat (src_path, &stbuf); + if (ret) { + ret = 0; + gf_log (this->name, GF_LOG_DEBUG, "%s not found", src_path); + goto out; + } + + ret = snprintf (dest_path, sizeof (dest_path), "%s/quota.conf", + 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; + } + + 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; + } + +out: + return ret; + +} int32_t glusterd_restore_geo_rep_files (glusterd_volinfo_t *snap_vol) diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h index 9a731c4330c..9c0c861830e 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.h +++ b/xlators/mgmt/glusterd/src/glusterd-utils.h @@ -773,4 +773,8 @@ glusterd_get_geo_rep_session (char *slave_key, char *origin_volname, int32_t 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); #endif -- cgit