diff options
author | Kaushal M <kaushal@redhat.com> | 2014-05-28 16:57:14 +0530 |
---|---|---|
committer | Krishnan Parthasarathi <kparthas@redhat.com> | 2014-06-05 23:15:07 -0700 |
commit | f2b42887c1f9780980abe491ed34a13a7b3d4583 (patch) | |
tree | 43f738e82d51c55a45ef53fc78b6ced7c09fbb1d /xlators/mgmt/glusterd/src/glusterd-store.c | |
parent | 77498fdbbca8554880eae4b8f559b9d6876e35b7 (diff) |
glusterd: Preserve backward compatibility during sync and store
The glusterd volinfo struct gained several new members to support the
volume snapshot feature. These members are also being exported/imported
during volume sync and being stored/restored. This export/import and
save/restore explicitly required these members to be present, and would
fail if they were not. This lead to the failure of backward
compatibility, preventing new peers from correctly interacting with
older peers (especially during a rolling upgrade).
This patch contains changes needed to preserve the backward
compatibility in the places specified. The snapshot members of the
volinfo will now be exported/imported and stored only when the cluster
op-version is >= 4, ie. all peers in the cluster support snapshot.
No change is required for the restore code as, the new members will be
left at the default zero values if corresponding entries are absent in
the stored volinfo.
Change-Id: I79e4bc5780c991ec305b7b5e7d71c16afb6a4c40
BUG: 1101903
Reviewed-on: http://review.gluster.org/7944
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Atin Mukherjee <amukherj@redhat.com>
Reviewed-by: Krishnan Parthasarathi <kparthas@redhat.com>
Tested-by: Krishnan Parthasarathi <kparthas@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-store.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.c | 155 |
1 files changed, 112 insertions, 43 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 98fc8b592e3..d8887644afb 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -249,6 +249,58 @@ glusterd_store_create_brick_shandle_on_absence (glusterd_volinfo_t *volinfo, return ret; } +/* Store the bricks snapshot details only if required + * + * The snapshot details will be stored only if the cluster op-version is + * greater than or equal to 4 + */ +int +gd_store_brick_snap_details_write (int fd, glusterd_brickinfo_t *brickinfo) +{ + int ret = -1; + xlator_t *this = NULL; + glusterd_conf_t *conf = NULL; + char value[256] = {0,}; + + this = THIS; + GF_ASSERT (this != NULL); + conf = this->private; + GF_VALIDATE_OR_GOTO (this->name, (conf != NULL), out); + + GF_VALIDATE_OR_GOTO (this->name, (fd > 0), out); + GF_VALIDATE_OR_GOTO (this->name, (brickinfo != NULL), out); + + if (conf->op_version < GD_OP_VERSION_4) { + ret = 0; + goto out; + } + + if (strlen(brickinfo->device_path) > 0) { + snprintf (value, sizeof(value), "%s", brickinfo->device_path); + ret = gf_store_save_value (fd, + GLUSTERD_STORE_KEY_BRICK_DEVICE_PATH, value); + if (ret) + goto out; + } + + if (strlen(brickinfo->mount_dir) > 0) { + memset (value, 0, sizeof (value)); + snprintf (value, sizeof(value), "%s", brickinfo->mount_dir); + ret = gf_store_save_value (fd, + GLUSTERD_STORE_KEY_BRICK_MOUNT_DIR, value); + if (ret) + goto out; + } + + memset (value, 0, sizeof (value)); + snprintf (value, sizeof(value), "%d", brickinfo->snap_status); + ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS, + value); + +out: + return ret; +} + int32_t glusterd_store_brickinfo_write (int fd, glusterd_brickinfo_t *brickinfo) { @@ -286,25 +338,7 @@ glusterd_store_brickinfo_write (int fd, glusterd_brickinfo_t *brickinfo) if (ret) goto out; - if (strlen(brickinfo->device_path) > 0) { - snprintf (value, sizeof(value), "%s", brickinfo->device_path); - ret = gf_store_save_value (fd, - GLUSTERD_STORE_KEY_BRICK_DEVICE_PATH, value); - if (ret) - goto out; - } - - if (strlen(brickinfo->mount_dir) > 0) { - snprintf (value, sizeof(value), "%s", brickinfo->mount_dir); - ret = gf_store_save_value (fd, - GLUSTERD_STORE_KEY_BRICK_MOUNT_DIR, value); - if (ret) - goto out; - } - - snprintf (value, sizeof(value), "%d", brickinfo->snap_status); - ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_BRICK_SNAP_STATUS, - value); + ret = gd_store_brick_snap_details_write (fd, brickinfo); if (ret) goto out; @@ -568,6 +602,64 @@ int _storeopts (dict_t *this, char *key, data_t *value, void *data) return 0; } +/* Store the volumes snapshot details only if required + * + * The snapshot details will be stored only if the cluster op-version is + * greater than or equal to 4 + */ +int +glusterd_volume_write_snap_details (int fd, glusterd_volinfo_t *volinfo) +{ + int ret = -1; + xlator_t *this = NULL; + glusterd_conf_t *conf = NULL; + char buf[PATH_MAX] = {0,}; + + this = THIS; + GF_ASSERT (this != NULL); + conf = this->private; + GF_VALIDATE_OR_GOTO (this->name, (conf != NULL), out); + + GF_VALIDATE_OR_GOTO (this->name, (fd > 0), out); + GF_VALIDATE_OR_GOTO (this->name, (volinfo != NULL), out); + + if (conf->op_version < GD_OP_VERSION_4) { + ret = 0; + goto out; + } + + snprintf (buf, sizeof (buf), "%s", volinfo->parent_volname); + ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_PARENT_VOLNAME, buf); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "Failed to store " + GLUSTERD_STORE_KEY_PARENT_VOLNAME); + goto out; + } + + ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_RESTORED_SNAP, + uuid_utoa (volinfo->restored_from_snap)); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "Unable to write restored_from_snap"); + goto out; + } + + memset (buf, 0, sizeof (buf)); + snprintf (buf, sizeof (buf), "%"PRIu64, volinfo->snap_max_hard_limit); + ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT, + buf); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "Unable to write snap-max-hard-limit"); + goto out; + } + +out: + if (ret) + gf_log (this->name, GF_LOG_ERROR, "Failed to write snap details" + " for volume %s", volinfo->volname); + return ret; +} int32_t glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo) { @@ -622,14 +714,6 @@ glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo) if (ret) goto out; - snprintf (buf, sizeof (buf), "%s", volinfo->parent_volname); - ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_PARENT_VOLNAME, buf); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, "Failed to store " - GLUSTERD_STORE_KEY_PARENT_VOLNAME); - goto out; - } - ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_ID, uuid_utoa (volinfo->volume_id)); if (ret) @@ -669,22 +753,7 @@ glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo) goto out; } - ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_RESTORED_SNAP, - uuid_utoa (volinfo->restored_from_snap)); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, - "Unable to write restored_from_snap"); - goto out; - } - - snprintf (buf, sizeof (buf), "%"PRIu64, volinfo->snap_max_hard_limit); - ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT, - buf); - if (ret) { - gf_log (this->name, GF_LOG_ERROR, - "Unable to write snap-max-hard-limit"); - goto out; - } + ret = glusterd_volume_write_snap_details (fd, volinfo); out: if (ret) |