diff options
Diffstat (limited to 'xlators')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-snapshot.c | 2 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.c | 110 | ||||
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-store.h | 4 |
3 files changed, 103 insertions, 13 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c index b8ecb61c2..db1afd37b 100644 --- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c +++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c @@ -3166,7 +3166,7 @@ glusterd_do_snap (glusterd_volinfo_t *volinfo, char *snapname, dict_t *dict, goto out; } - ret = glusterd_store_perform_snap_store (volinfo); + ret = glusterd_store_perform_snap_store (volinfo, snapname); if (ret) { gf_log (this->name, GF_LOG_WARNING, "could not do volume store" " after taking the snapshot (volume: %s)", diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c index 84682316d..5dfc96485 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.c +++ b/xlators/mgmt/glusterd/src/glusterd-store.c @@ -1522,20 +1522,108 @@ out: } int32_t -glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo) +glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo, char *snapname) { - int fd = -1; - int32_t ret = -1; - glusterd_snap_t *entry = NULL; - glusterd_snap_t *tmp = NULL; - uint64_t count = 0; + int fd = -1; + int32_t ret = -1; + glusterd_snap_t *entry = NULL; + glusterd_snap_t *tmp = NULL; + uint64_t count = 0; char buf[PATH_MAX] = {0,}; + xlator_t *this = NULL; GF_ASSERT (volinfo); + GF_ASSERT (snapname); + + this = THIS; + GF_ASSERT (this); ret = glusterd_store_create_snaps_dir (volinfo); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to create the snaps " + "directory for the volume %s (snap: %s)", + volinfo->volname, snapname); + goto out; + } + + ret = glusterd_store_create_snap_list_sh_on_absence (volinfo); if (ret) goto out; + fd = gf_store_mkstemp (volinfo->snap_list_shandle); + if (fd <= 0) { + ret = -1; + goto out; + } + + LOCK (&volinfo->lock); + { + list_for_each_entry_safe (entry, tmp, &volinfo->snaps, + snap_list) { + if (!strcmp (entry->snap_name, snapname)) { + ret = glusterd_store_snap_list_write (fd, entry, + count); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "Failed to write snap list to" + " store"); + goto unlock; + } + ret = glusterd_store_snap_volume (volinfo, + entry); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, + "Failed to store snap volume"); + goto unlock; + } + } + count++; + } + GF_ASSERT (count == volinfo->snap_count); + snprintf (buf, sizeof(buf), "%"PRIu64, count); + ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAP_COUNT, + buf); + if (ret) + goto unlock; + } +unlock: + UNLOCK (&volinfo->lock); + + ret = gf_store_rename_tmppath (volinfo->snap_list_shandle); + if (ret) + goto out; + +out: + if (ret && (fd > 0)) + gf_store_unlink_tmppath (volinfo->snap_list_shandle); + if (fd > 0) + close (fd); + + gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret); + return ret; +} + +int32_t +glusterd_store_perform_all_snap_store (glusterd_volinfo_t *volinfo) +{ + int fd = -1; + int32_t ret = -1; + glusterd_snap_t *entry = NULL; + glusterd_snap_t *tmp = NULL; + uint64_t count = 0; + char buf[PATH_MAX] = {0,}; + xlator_t *this = NULL; + + GF_ASSERT (volinfo); + + this = THIS; + GF_ASSERT (this); + + ret = glusterd_store_create_snaps_dir (volinfo); + if (ret) { + gf_log (this->name, GF_LOG_ERROR, "failed to create the snaps " + "directory for the volume %s", volinfo->volname); + goto out; + } ret = glusterd_store_create_snap_list_sh_on_absence (volinfo); if (ret) @@ -1552,13 +1640,13 @@ glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo) snap_list) { ret = glusterd_store_snap_list_write (fd, entry, count); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "Failed to " + gf_log (this->name, GF_LOG_ERROR, "Failed to " "write snap list to store"); goto unlock; } ret = glusterd_store_snap_volume (volinfo, entry); if (ret) { - gf_log (THIS->name, GF_LOG_ERROR, "Failed to " + gf_log (this->name, GF_LOG_ERROR, "Failed to " "store snap volume"); goto unlock; } @@ -1583,7 +1671,7 @@ out: if (fd > 0) close (fd); - gf_log ("", GF_LOG_TRACE, "Returning %d", ret); + gf_log (this->name, GF_LOG_TRACE, "Returning %d", ret); return ret; } @@ -1843,7 +1931,7 @@ glusterd_store_volinfo (glusterd_volinfo_t *volinfo, glusterd_volinfo_ver_ac_t a if (ret) goto out; - ret = glusterd_store_perform_snap_store (volinfo); + ret = glusterd_store_perform_all_snap_store (volinfo); if (ret) goto out; @@ -3508,7 +3596,7 @@ glusterd_store_retrieve_volumes (xlator_t *this) ret = glusterd_volinfo_find (entry->d_name, &volinfo); ret = glusterd_store_create_snap_list_sh_on_absence (volinfo); - ret = glusterd_store_perform_snap_store (volinfo); + ret = glusterd_store_perform_all_snap_store (volinfo); //ret = glusterd_store_perform_snap_list_store (volinfo); TODO: Fix this } diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h index b8123f644..8ddd3e6bd 100644 --- a/xlators/mgmt/glusterd/src/glusterd-store.h +++ b/xlators/mgmt/glusterd/src/glusterd-store.h @@ -156,7 +156,9 @@ glusterd_replace_slash_with_hyphen (char *str); int32_t glusterd_store_perform_volume_store (glusterd_volinfo_t *volinfo); int32_t -glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo); +glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo, char *snapname); +int32_t +glusterd_store_perform_all_snap_store (glusterd_volinfo_t *volinfo); int32_t glusterd_store_perform_snap_list_store (glusterd_volinfo_t *volinfo); int32_t |