summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvra Sengupta <asengupt@redhat.com>2013-12-05 01:51:35 +0000
committerAvra Sengupta <asengupt@redhat.com>2013-12-17 00:16:11 +0000
commiteed0caca2d35ece6a8eba977937f31599d6d9021 (patch)
treeb3f1fdba2b0338ac5c302f19a7d4ca1b15e04024
parent005b445d684f30e8611c9b2a374cdc798a6cdcbb (diff)
glusterd/snapshot: Fix for cksum mismatches at snap create.
Also fixes peer rejects on glusterd restart Change-Id: I1671416c1f3fd2afea450cc3b4c632de187351ca Signed-off-by: Avra Sengupta <asengupt@redhat.com>
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c86
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.h3
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c6
3 files changed, 84 insertions, 11 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 3e98e2f..cc56f90 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -678,9 +678,12 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
char *device = NULL;
char *tmpstr = NULL;
char *snap_brick_dir = NULL;
+ char *username = NULL;
+ char *password = NULL;
char snap_brick_path[PATH_MAX] = "";
char *mnt_pt = NULL;
char snapname[PATH_MAX] = "";
+ char tmpname[PATH_MAX] = "";
char tmp[2046] = "";
char volname_buf[PATH_MAX] = "";
char snap_mount[PATH_MAX] = "";
@@ -698,6 +701,7 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
gf_boolean_t is_cg = _gf_false;
uuid_t *cg_id = NULL;
uuid_t *snap_volid = NULL;
+ uuid_t tmp_uuid = {0};
xlator_t *this = NULL;
this = THIS;
@@ -810,6 +814,30 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
snprintf (snapname, sizeof (snapname), "%s_%s", name, tmp);
}
+ /* generate internal username and password for the snap*/
+
+ uuid_generate (tmp_uuid);
+ username = gf_strdup (uuid_utoa (tmp_uuid));
+ snprintf (tmpname, sizeof(tmpname), "volume%ld_username", i+1);
+ ret = dict_set_dynstr (dict, tmpname, username);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set snap username for "
+ "volume %s", volname);
+ GF_FREE (username);
+ goto out;
+ }
+
+ uuid_generate (tmp_uuid);
+ password = gf_strdup (uuid_utoa (tmp_uuid));
+ snprintf (tmpname, sizeof(tmpname), "volume%ld_password", i+1);
+ ret = dict_set_dynstr (dict, tmpname, password);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set snap password for "
+ "volume %s", volname);
+ GF_FREE (password);
+ goto out;
+ }
+
//Also check whether geo replication is running
brick_count = 0;
@@ -907,7 +935,6 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
memset (snapbrckcnt, '\0', sizeof(snapbrckcnt));
ret = snprintf (snapbrckcnt, sizeof(snapbrckcnt) - 1,
"vol%ld_brickcount", i+1);
- snapbrckcnt[ret] = '\0';
ret = dict_set_int64 (rsp_dict, snapbrckcnt, brick_count);
if (ret) {
@@ -928,7 +955,6 @@ glusterd_snapshot_create_prevalidate (dict_t *dict, char **op_errstr,
memset (snapvolidname, '\0', sizeof(snapvolidname));
ret = snprintf (snapvolidname, sizeof(snapvolidname) - 1,
"vol%ld_volid", i+1);
- snapvolidname[ret] = '\0';
uuid_generate (*snap_volid);
ret = dict_set_bin (dict, snapvolidname, snap_volid, sizeof(uuid_t));
@@ -3015,8 +3041,11 @@ glusterd_do_snap (glusterd_volinfo_t *volinfo, char *snapname, dict_t *dict,
{
char *snap_brick_mount_path = "";
char snapmntname[PATH_MAX] = "";
+ char tmpname[PATH_MAX] = "";
char *device = NULL;
char *description = NULL;
+ char *username = NULL;
+ char *password = NULL;
glusterd_brickinfo_t *snap_brickinfo = NULL;
glusterd_brickinfo_t *brickinfo = NULL;
glusterd_conf_t *priv = NULL;
@@ -3039,6 +3068,27 @@ glusterd_do_snap (glusterd_volinfo_t *volinfo, char *snapname, dict_t *dict,
sizeof(snap_volume->parent_volname) - 1);
uuid_copy (snap_volume->volume_id, snap_volid);
+ /* fetch internal username and password for the snap*/
+
+ snprintf (tmpname, sizeof(tmpname), "volume%d_username", volcount);
+ ret = dict_get_str (dict, tmpname, &username);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get snap username for "
+ "volume %s", volinfo->volname);
+ goto out;
+ }
+
+ snprintf (tmpname, sizeof(tmpname), "volume%d_password", volcount);
+ ret = dict_get_str (dict, tmpname, &password);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get snap password for "
+ "volume %s", volinfo->volname);
+ goto out;
+ }
+
+ glusterd_auth_set_username (snap_volume, username);
+ glusterd_auth_set_password (snap_volume, password);
+
/* Adding snap brickinfos to the snap volinfo */
brick_count = 0;
list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
@@ -3093,14 +3143,19 @@ glusterd_do_snap (glusterd_volinfo_t *volinfo, char *snapname, dict_t *dict,
ret = glusterd_take_snapshot (brickinfo,
volinfo->volname,
snapname, dict, &device);
- /* continue with the snapshot even though snapshot
- on one of the bricks fails. At the end check
- whether the snapshot volume meets quorum or not.
- If so, then the snapshot can be treated as success.
- If not, undo the changes and return failure to cli.
+ /* Fail the snapshot even though snapshot on one of
+ the bricks fails. At the end when we check whether
+ the snapshot volume meets quorum or not, then the
+ the snapshot can either be treated as success, or
+ in case of failure we can undo the changes and return
+ failure to cli.
*/
- if (ret)
- continue;
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Failed to take snapshot of %s:%s",
+ brickinfo->hostname, brickinfo->path);
+ goto out;
+ }
/* create the complete brick here */
ret = glusterd_snap_brick_create (device, snap_volume,
@@ -3181,6 +3236,19 @@ glusterd_do_snap (glusterd_volinfo_t *volinfo, char *snapname, dict_t *dict,
snap_volume->status = GLUSTERD_STATUS_STARTED;
+ ret = glusterd_store_perform_snap_volume_store (volinfo, snap_volume);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Failed to store snapshot volinfo (%s) for volume "
+ "%s", snap_volume->volname, volinfo->volname);
+ goto out;
+ }
+
+ ret = glusterd_volume_compute_cksum (volinfo, snap_volume);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Failed to compute cksum for %s", snap_volume->volname);
+ goto out;
+ }
+
out:
if (ret)
glusterd_volinfo_delete (snap_volume);
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h
index 27472c0..69ee30d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.h
+++ b/xlators/mgmt/glusterd/src/glusterd-store.h
@@ -153,4 +153,7 @@ int32_t
glusterd_store_snap_cg (glusterd_snap_cg_t *cg);
int32_t
glusterd_store_delete_snap_cg (glusterd_snap_cg_t *cg);
+int32_t
+glusterd_store_perform_snap_volume_store (glusterd_volinfo_t *volinfo,
+ glusterd_volinfo_t *snap_volinfo);
#endif
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index e9df28b..545d8bc 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -2065,8 +2065,10 @@ glusterd_volume_compute_cksum (glusterd_volinfo_t *volinfo,
if (ret)
goto out;
- volinfo->cksum = cksum;
-
+ if (snap_volinfo)
+ snap_volinfo->cksum = cksum;
+ else
+ volinfo->cksum = cksum;
out:
if (fd > 0)
close (fd);