summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c256
1 files changed, 97 insertions, 159 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 2b2cc1adc..66fdf4178 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -58,14 +58,12 @@ int
glusterd_snapshot_restore (dict_t *dict, char **op_errstr)
{
int ret = -1;
- int64_t i = 0;
- int64_t volcount = 0;
char *volname = NULL;
char *snapname = NULL;
xlator_t *this = NULL;
+ glusterd_volinfo_t *snap_volinfo = NULL;
glusterd_volinfo_t *volinfo = NULL;
glusterd_snap_t *snap = NULL;
- char key[PATH_MAX] = {0,};
this = THIS;
@@ -73,68 +71,48 @@ glusterd_snapshot_restore (dict_t *dict, char **op_errstr)
GF_ASSERT (dict);
GF_ASSERT (op_errstr);
- ret = dict_get_int64 (dict, "volcount", &volcount);
+ ret = dict_get_str (dict, "snapname", &snapname);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get volume count");
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get "
+ "snap name");
goto out;
}
- /* If we are performing snapshot restore of a CG then volcount will be
- * greater than 1 else volcount will be 1.
- */
- for (i = 0; i < volcount; ++i) {
- /* TODO: Start the index from 0 when Jarvis code is fixed */
- snprintf (key, sizeof (key), "volname%ld", i+1);
- ret = dict_get_str (dict, key, &volname);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to "
- "get volume name");
- goto out;
- }
-
- ret = glusterd_volinfo_find (volname, &volinfo);
- if (ret) {
- ret = gf_asprintf (op_errstr, "Volume (%s) not found",
- volname);
- if (ret < 0) {
- goto out;
- }
- gf_log (this->name, GF_LOG_ERROR, "%s", *op_errstr);
- ret = -1;
+ snap = glusterd_find_snap_by_name (snapname);
+ if (NULL == snap) {
+ ret = gf_asprintf (op_errstr, "Snap (%s) not found",
+ snapname);
+ if (ret < 0) {
goto out;
}
+ gf_log (this->name, GF_LOG_ERROR, "%s", *op_errstr);
+ ret = -1;
+ goto out;
+ }
- ret = dict_get_str (dict, "snapname", &snapname);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "snap name");
- goto out;
- }
+ /* TODO : As of now there is only volume in snapshot.
+ * Change this when multiple volume snapshot is introduced
+ */
+ snap_volinfo = list_entry (snap->volumes.next, glusterd_volinfo_t,
+ vol_list);
- snap = glusterd_find_snap_by_name (snapname);
- if (NULL == snap) {
- ret = gf_asprintf (op_errstr, "Snap (%s) not found",
- snapname);
- if (ret < 0) {
- goto out;
- }
- gf_log (this->name, GF_LOG_ERROR, "%s", *op_errstr);
- ret = -1;
- goto out;
- }
+ ret = glusterd_volinfo_find (snap_volinfo->parent_volname, &volinfo);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Could not get volinfo of "
+ "%s", snap_volinfo->parent_volname);
+ goto out;
+ }
- /* Restore the snap for the entire volume */
- ret = gd_restore_snap_volume (volinfo, snap->snap_volume);
- if (ret) {
- /* No need to update op_errstr because it is assumed
- * that the called function will do that in case of
- * failure.
- */
- gf_log (this->name, GF_LOG_ERROR, "Failed to restore "
- "snap for %s volume", volname);
- goto out;
- }
+ ret = gd_restore_snap_volume (volinfo, snap_volinfo);
+ if (ret) {
+ /* No need to update op_errstr because it is assumed
+ * that the called function will do that in case of
+ * failure.
+ */
+ gf_log (this->name, GF_LOG_ERROR, "Failed to restore "
+ "snap for %s volume", volname);
+ goto out;
}
ret = 0; /* Success */
@@ -162,12 +140,11 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr,
dict_t *rsp_dict)
{
int ret = -1;
- int64_t i = 0;
- int64_t volcount = 0;
+ int32_t i = 0;
+ int32_t volcount = 0;
gf_boolean_t snap_restored = _gf_false;
char *volname = NULL;
char *snapname = NULL;
- char *cgname = NULL;
glusterd_volinfo_t *volinfo = NULL;
glusterd_snap_t *snap = NULL;
xlator_t *this = NULL;
@@ -180,30 +157,46 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr,
GF_ASSERT (op_errstr);
GF_ASSERT (rsp_dict);
- ret = dict_get_str (dict, "cgname", &cgname);
+ ret = dict_get_str (dict, "snapname", &snapname);
if (ret) {
- ret = dict_get_str (dict, "snapname", &snapname);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "neither snapname nor cgname");
- goto out;
- }
- ret = dict_set_str (rsp_dict, "snapname", snapname);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to set "
- "snap name");
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get "
+ "snap name");
+ goto out;
+ }
+
+ snap = glusterd_find_snap_by_name (snapname);
+ if (NULL == snap) {
+ ret = gf_asprintf (op_errstr, "Snap (%s) not found",
+ snapname);
+ if (ret < 0) {
goto out;
}
- } else {
- ret = dict_set_str (rsp_dict, "cgname", cgname);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to set "
- "CG name");
+ gf_log (this->name, GF_LOG_ERROR, "%s", *op_errstr);
+ ret = -1;
+ goto out;
+ }
+
+ snap_restored = snap->snap_restored;
+
+ if (snap_restored) {
+ ret = gf_asprintf (op_errstr, "Snap (%s) already "
+ "restored", snapname);
+ if (ret < 0) {
goto out;
}
+ gf_log (this->name, GF_LOG_ERROR, "%s", *op_errstr);
+ ret = -1;
+ goto out;
}
- ret = dict_get_int64 (dict, "volcount", &volcount);
+ ret = dict_set_str (rsp_dict, "snapname", snapname);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to set "
+ "snap name");
+ goto out;
+ }
+
+ ret = dict_get_int32 (dict, "volcount", &volcount);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to get volume count");
@@ -217,7 +210,7 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr,
*/
for (i = 0; i < volcount; ++i) {
/* TODO: Start the index from 0 when Jarvis code is fixed */
- snprintf (key, sizeof (key), "volname%ld", i+1);
+ snprintf (key, sizeof (key), "volname%d", i+1);
ret = dict_get_str (dict, key, &volname);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to "
@@ -248,37 +241,6 @@ glusterd_snapshot_restore_prevalidate (dict_t *dict, char **op_errstr,
goto out;
}
- ret = dict_get_str (dict, "snapname", &snapname);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "snap name");
- goto out;
- }
-
- snap = glusterd_find_snap_by_name (snapname);
- if (NULL == snap) {
- ret = gf_asprintf (op_errstr, "Snap (%s) not found",
- snapname);
- if (ret < 0) {
- goto out;
- }
- gf_log (this->name, GF_LOG_ERROR, "%s", *op_errstr);
- ret = -1;
- goto out;
- }
-
- snap_restored = snap->snap_restored;
-
- if (snap_restored) {
- ret = gf_asprintf (op_errstr, "Snap (%s) already "
- "restored", snapname);
- if (ret < 0) {
- goto out;
- }
- gf_log (this->name, GF_LOG_ERROR, "%s", *op_errstr);
- ret = -1;
- goto out;
- }
}
ret = 0;
@@ -2338,13 +2300,13 @@ glusterd_handle_snapshot_restore (rpcsvc_request_t *req, glusterd_op_t op,
dict_t *dict, char *err_str, size_t len)
{
int ret = -1;
- int64_t vol_count = 0;
- char *volname = NULL;
char *snapname = NULL;
- char *cgname = NULL;
glusterd_conf_t *conf = NULL;
- glusterd_snap_cg_t *cg = NULL;
xlator_t *this = NULL;
+ glusterd_snap_t *snap = NULL;
+ glusterd_volinfo_t *snap_volinfo = NULL;
+ int32_t i = 0;
+ char key[PATH_MAX] = "";
this = THIS;
GF_ASSERT (this);
@@ -2355,63 +2317,39 @@ glusterd_handle_snapshot_restore (rpcsvc_request_t *req, glusterd_op_t op,
GF_ASSERT (dict);
GF_ASSERT (err_str);
- /* If volume name is provided then volcount will be set */
- ret = dict_get_int64 (dict, "volcount", &vol_count);
+ ret = dict_get_str (dict, "snapname", &snapname);
if (ret) {
- /* If volcount is not provided then cgname must be there */
- ret = dict_get_str (dict, "cgname", &cgname);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to "
- "get neither volcount nor cgname");
- goto out;
- }
- } else {
- /* TODO: Change the index to 0 when Jarvis code is fixed */
- ret = dict_get_str (dict, "volname1", &volname);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to "
- "get volname");
- goto out;
- }
- ret = dict_get_str (dict, "snapname", &snapname);
- if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to "
- "get snapname");
- goto out;
- }
+ gf_log (this->name, GF_LOG_ERROR, "Failed to "
+ "get snapname");
+ goto out;
}
- if (NULL != cgname) { /* Snapshot restore of CG */
- cg = glusterd_find_snap_cg_by_name (conf, cgname);
-
- if (NULL == cg) {
- snprintf (err_str, len, "CG %s not found", cgname);
- gf_log (this->name, GF_LOG_WARNING, "%s", err_str);
- ret = -1;
- goto out;
- }
-
- LOCK (&cg->lock);
- {
- /* First get the snap name of the CG */
- ret = glusterd_get_cg_snap_name_lk (dict, cg);
- if (ret) {
- goto unlock;
- }
-
- /* Then get the volumes belong to CG */
- ret = glusterd_get_cg_volume_names_lk (dict, cg);
- }
-unlock:
- UNLOCK (&cg->lock);
+ snap = glusterd_find_snap_by_name (snapname);
+ if (!snap) {
+ snprintf (err_str, len, "Snap (%s) does not exist", snapname);
+ gf_log (this->name, GF_LOG_ERROR, "%s", err_str);
+ ret = -1;
+ goto out;
+ }
+ list_for_each_entry (snap_volinfo, &snap->volumes, vol_list) {
+ i++;
+ snprintf (key, sizeof (key), "volname%d", i);
+ ret = dict_set_str (dict, key, snap_volinfo->parent_volname);
if (ret) {
- gf_log (this->name, GF_LOG_ERROR, "Failed to get "
- "volume names or snap name of %s CG", cgname);
+ gf_log (this->name, GF_LOG_ERROR, "Could not set "
+ "parent volume name");
goto out;
}
}
+ ret = dict_set_int32 (dict, "volcount", i);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR,
+ "Could not save volume count");
+ goto out;
+ }
+
ret = glusterd_mgmt_v3_initiate_snap_phases (req, op, dict);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "Failed to initiate snap "