diff options
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-store.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 8a673ccbe..37bf8bdaf 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -1249,17 +1249,18 @@ glusterd_store_snap_cg_write (int fd, glusterd_snap_cg_t *cg) int ret = -1; char buf[PATH_MAX] = {0, }; uint64_t count = 0; + glusterd_volinfo_t *volinfo = NULL; GF_ASSERT (fd > 0); GF_ASSERT (cg); - ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAP_NAME, - cg->cg_name); + snprintf (buf, sizeof (buf), "%"PRIu64, cg->volume_count); + ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_CG_VOL_COUNT, buf); if (ret) goto out; - snprintf (buf, sizeof (buf), "%"PRIu64, cg->volume_count); - ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_CG_VOL_COUNT, buf); + ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAP_NAME, + cg->cg_name); if (ret) goto out; @@ -1281,8 +1282,9 @@ glusterd_store_snap_cg_write (int fd, glusterd_snap_cg_t *cg) goto out; } while (count < cg->volume_count) { + volinfo = cg->volumes[count]; ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_ID, - uuid_utoa (cg->volumes[count].volume_id)); + uuid_utoa (volinfo->volume_id)); if (ret) goto out; @@ -1314,6 +1316,11 @@ glusterd_store_perform_snap_cg_store (glusterd_snap_cg_t *cg) ret = glusterd_store_snap_cg_write (fd, cg); if (ret) goto out; + + ret = gf_store_rename_tmppath (cg->shandle); + if (ret) + goto out; + out: if (ret && (fd > 0)) gf_store_unlink_tmppath (cg->shandle); @@ -1822,7 +1829,7 @@ glusterd_store_delete_snap_cg (glusterd_snap_cg_t *cg) snprintf (trashdir, sizeof (trashdir), "%s/"GLUSTERD_TRASH"/%s", priv->workdir, GLUSTERD_VOL_SNAP_CG_DIR_PREFIX); - ret = mkdir (trashdir, 0777); + ret = mkdir_p (trashdir, 0777, _gf_true); if (ret && errno != EEXIST) { gf_log (this->name, GF_LOG_ERROR, "Failed to create trash " "directory, reason : %s", strerror (errno)); @@ -1861,6 +1868,7 @@ out: gf_log (this->name, GF_LOG_DEBUG, "Returning %d", ret); return ret; } + int32_t glusterd_store_delete_volume (glusterd_volinfo_t *volinfo, glusterd_volinfo_t *snapinfo) @@ -1986,7 +1994,6 @@ out: return ret; } - int glusterd_store_global_info (xlator_t *this) { @@ -2847,6 +2854,7 @@ glusterd_store_retrieve_volume (char *volname, glusterd_snap_t *snap) list_add_tail (&volinfo->vol_list, &priv->volumes); } else { // as of now snap volume are also added to the list of volume + volinfo->is_snap_volume = _gf_true; snap->snap_volume = volinfo; list_add_tail (&volinfo->vol_list, &priv->volumes); } @@ -2955,7 +2963,7 @@ out: } int32_t -glusterd_store_retrieve_snap_cg (char *cg_name, glusterd_conf_t *priv) +glusterd_store_retrieve_snap_cg (char *cg_store_name, glusterd_conf_t *priv) { int32_t ret = -1; gf_store_iter_t *iter = NULL; @@ -2969,13 +2977,13 @@ glusterd_store_retrieve_snap_cg (char *cg_name, glusterd_conf_t *priv) gf_store_handle_t *tmp_shandle = NULL; uint64_t count = 0; glusterd_volinfo_t *volinfo = NULL; - glusterd_volinfo_t *tmpinfo = NULL; uuid_t vol_id = {0, }; - GF_ASSERT (cg_name); + GF_ASSERT (cg_store_name); GF_ASSERT (priv); - glusterd_store_snap_cgfpath_set (cg_name, path, sizeof (path)); + snprintf (path, sizeof (path), "%s/%s/%s", priv->workdir, + GLUSTERD_VOL_SNAP_CG_DIR_PREFIX, cg_store_name); ret = gf_store_handle_retrieve (path, &tmp_shandle); if (ret) goto out; @@ -2983,6 +2991,7 @@ glusterd_store_retrieve_snap_cg (char *cg_name, glusterd_conf_t *priv) ret = gf_store_iter_new (tmp_shandle, &iter); if (ret) goto out; + ret = gf_store_iter_get_matching (iter, GLUSTERD_STORE_KEY_CG_VOL_COUNT, &value); @@ -3000,20 +3009,18 @@ glusterd_store_retrieve_snap_cg (char *cg_name, glusterd_conf_t *priv) "Failed to create snap cg object"); goto out; } - cg->shandle = tmp_shandle; GLUSTERD_GET_SNAP_CG_DIR (cg_path, priv); snprintf (path, sizeof (path), "%s/%s", cg_path, - cg_name); - cg->volume_count = atoi (value); + cg_store_name); ret = gf_store_iter_get_next (iter, &key, &value, &op_errno); while (!ret) { if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_NAME, sizeof (*key))) { - strncpy (cg->cg_name, value, sizeof (*value)); + strncpy (cg->cg_name, value, sizeof (value)); } else if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_STATUS, sizeof (*key))) { cg->cg_status = atoi (value); @@ -3024,26 +3031,26 @@ glusterd_store_retrieve_snap_cg (char *cg_name, glusterd_conf_t *priv) sizeof (*key))) { cg->description = gf_strdup (value); } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_ID, - sizeof (*key))) { - uuid_parse (key, vol_id); + sizeof (*key))) { + uuid_parse (value, vol_id); ret = glusterd_volinfo_find_by_volume_id (vol_id, &volinfo); if (ret) break; if (count < vol_count) { - tmpinfo = &cg->volumes[count]; - tmpinfo = volinfo; + cg->volumes[count] = volinfo; count++; } } GF_FREE (value); value = NULL; + ret = gf_store_iter_get_next (iter, &key, &value, &op_errno); } ret = glusterd_add_snap_cg (priv, cg); if (ret) { gf_log (THIS->name, GF_LOG_ERROR, "Failed to add %s to" - " cg_list", cg_name); + " cg_list", cg_store_name); goto out; } @@ -3060,6 +3067,7 @@ out: return ret; } + int32_t glusterd_store_retrieve_snap_list (char *volname) { |