summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-store.c
diff options
context:
space:
mode:
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-store.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c183
1 files changed, 142 insertions, 41 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 1a00aac88..41633ebd8 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -607,14 +607,13 @@ int _storeopts (dict_t *this, char *key, data_t *value, void *data)
int32_t
glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo)
{
- char *str = NULL;
+ char *str = NULL;
+ char buf[PATH_MAX] = {0,};
+ int32_t ret = -1;
GF_ASSERT (fd > 0);
GF_ASSERT (volinfo);
- char buf[PATH_MAX] = {0,};
- int32_t ret = -1;
-
snprintf (buf, sizeof (buf), "%d", volinfo->type);
ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_TYPE, buf);
if (ret)
@@ -703,6 +702,14 @@ glusterd_volume_exclude_options_write (int fd, glusterd_volinfo_t *volinfo)
goto out;
}
+ snprintf (buf, sizeof (buf), "%d", volinfo->is_volume_restored);
+ ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_VOL_IS_RESTORED, buf);
+ if (ret) {
+ gf_log (THIS->name, GF_LOG_ERROR,
+ "Unable to write is_volume_restored");
+ 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);
@@ -1222,6 +1229,16 @@ glusterd_store_snap_list_write (int fd, glusterd_snap_t *snap, uint64_t count)
if (ret)
goto out;
+ if ( strlen(snap->cg_name) > 0 ) {
+ snprintf (key, sizeof (key), "%s-%"PRIu64,
+ GLUSTERD_STORE_KEY_SNAP_CG_NAME, count);
+ ret = gf_store_save_value (fd, key, snap->cg_name);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Failed to store cg_name");
+ goto out;
+ }
+ }
+
snprintf (key, sizeof (key), "%s-%"PRIu64, GLUSTERD_STORE_KEY_SNAP_ID,
count);
ret = gf_store_save_value (fd, key, uuid_utoa(snap->snap_id));
@@ -1242,7 +1259,7 @@ glusterd_store_snap_list_write (int fd, glusterd_snap_t *snap, uint64_t count)
goto out;
if (snap->description) {
- snprintf (buf, sizeof (buf), "%s\n", snap->description);
+ snprintf (buf, sizeof (buf), "%s", snap->description);
snprintf (key, sizeof (key), "%s-%"PRIu64,
GLUSTERD_STORE_KEY_SNAP_DESC, count);
ret = gf_store_save_value (fd, key, buf);
@@ -1287,7 +1304,7 @@ glusterd_store_snap_cg_write (int fd, glusterd_snap_cg_t *cg)
goto out;
if (cg->description) {
- snprintf (buf, sizeof (buf), "%s\n", cg->description);
+ snprintf (buf, sizeof (buf), "%s", cg->description);
ret = gf_store_save_value (fd, GLUSTERD_STORE_KEY_SNAP_DESC,
buf);
if (ret)
@@ -1509,11 +1526,17 @@ glusterd_store_perform_snap_store (glusterd_volinfo_t *volinfo)
list_for_each_entry_safe (entry, tmp, &volinfo->snaps,
snap_list) {
ret = glusterd_store_snap_list_write (fd, entry, count);
- if (ret)
+ 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)
+ if (ret) {
+ gf_log (THIS->name, GF_LOG_ERROR, "Failed to "
+ "store snap volume");
goto unlock;
+ }
count++;
}
snprintf (buf, sizeof(buf), "%"PRIu64, count);
@@ -2670,53 +2693,66 @@ out:
return ret;
}
-int32_t
-glusterd_store_retrieve_volume (char *volname, glusterd_snap_t *snap)
-{
- int32_t ret = -1;
- glusterd_volinfo_t *volinfo = NULL;
- gf_store_iter_t *iter = NULL;
- char *key = NULL;
- char *value = NULL;
- char volpath[PATH_MAX] = {0,};
- glusterd_conf_t *priv = NULL;
- char path[PATH_MAX] = {0,};
- int exists = 0;
- gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
- glusterd_volinfo_t *parent_vol = NULL;
-
- GF_ASSERT (volname);
- ret = glusterd_volinfo_new (&volinfo);
- if (ret)
- goto out;
+int
+glusterd_store_update_volinfo (glusterd_volinfo_t *volinfo,
+ glusterd_snap_t *snap)
+{
+ int ret = -1;
+ int exists = 0;
+ uint64_t count = 0;
+ char *key = NULL;
+ char *value = NULL;
+ char volpath[PATH_MAX] = {0,};
+ char path[PATH_MAX] = {0,};
+ xlator_t *this = NULL;
+ glusterd_conf_t *conf = NULL;
+ gf_store_iter_t *iter = NULL;
+ gf_store_op_errno_t op_errno = GD_STORE_SUCCESS;
+ glusterd_volinfo_t *parent_vol = NULL;
- priv = THIS->private;
+ this = THIS;
+ GF_ASSERT (this);
+ conf = THIS->private;
+ GF_ASSERT (volinfo);
if (snap) {
- ret = glusterd_volinfo_find (volname, &parent_vol);
- if (ret)
+ ret = glusterd_volinfo_find (volinfo->parent_volname,
+ &parent_vol);
+ if (ret) {
+ gf_log (this->name, GF_LOG_DEBUG, "Failed to get parent"
+ " volume for %s snap volume", volinfo->volname);
goto out;
- strncpy (volinfo->volname, snap->snap_name, GLUSTERD_MAX_VOLUME_NAME);
- GLUSTERD_GET_SNAP_DIR (volpath, parent_vol, snap->snap_name, priv);
+ }
+
+ GLUSTERD_GET_SNAP_DIR (volpath, parent_vol, snap->snap_name,
+ conf);
} else {
- strncpy (volinfo->volname, volname, GLUSTERD_MAX_VOLUME_NAME);
- GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, priv);
+ GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, conf);
}
+
snprintf (path, sizeof (path), "%s/%s", volpath,
GLUSTERD_VOLUME_INFO_FILE);
ret = gf_store_handle_retrieve (path, &volinfo->shandle);
- if (ret)
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "snap handle is NULL");
goto out;
+ }
ret = gf_store_iter_new (volinfo->shandle, &iter);
- if (ret)
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get new store "
+ "iter");
goto out;
+ }
ret = gf_store_iter_get_next (iter, &key, &value, &op_errno);
- if (ret)
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to get next store "
+ "iter");
goto out;
+ }
while (!ret) {
gf_log ("", GF_LOG_DEBUG, "key = %s value = %s", key, value);
@@ -2791,6 +2827,9 @@ glusterd_store_retrieve_volume (char *volname, glusterd_snap_t *snap)
} else if (!strncmp (key, GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT,
strlen (GLUSTERD_STORE_KEY_SNAP_MAX_HARD_LIMIT))) {
volinfo->snap_max_hard_limit = (uint64_t) atoll (value);
+ } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_IS_RESTORED,
+ strlen (GLUSTERD_STORE_KEY_VOL_IS_RESTORED))) {
+ volinfo->is_volume_restored = atoi (value);
} else if (!strncmp (key, GLUSTERD_STORE_KEY_PARENT_VOLNAME,
strlen (GLUSTERD_STORE_KEY_PARENT_VOLNAME))) {
strncpy (volinfo->parent_volname, value, sizeof(volinfo->parent_volname) - 1);
@@ -2881,10 +2920,57 @@ glusterd_store_retrieve_volume (char *volname, glusterd_snap_t *snap)
goto out;
ret = gf_store_iter_destroy (iter);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to destroy store "
+ "iter");
+ goto out;
+ }
+
+ ret = 0;
+out:
+ return ret;
+}
+int32_t
+glusterd_store_retrieve_volume (char *volname, glusterd_snap_t *snap)
+{
+ int32_t ret = -1;
+ char volpath[PATH_MAX] = {0,};
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_conf_t *priv = NULL;
+ glusterd_volinfo_t *parent_vol = NULL;
+ xlator_t *this = NULL;
+
+ this = THIS;
+ GF_ASSERT (this);
+ priv = this->private;
+ GF_ASSERT (priv);
+ GF_ASSERT (volname);
+
+ ret = glusterd_volinfo_new (&volinfo);
if (ret)
goto out;
+ priv = THIS->private;
+
+ if (snap) {
+ ret = glusterd_volinfo_find (volname, &parent_vol);
+ if (ret)
+ goto out;
+ strncpy (volinfo->volname, snap->snap_name, GLUSTERD_MAX_VOLUME_NAME);
+ GLUSTERD_GET_SNAP_DIR (volpath, parent_vol, snap->snap_name, priv);
+ } else {
+ strncpy (volinfo->volname, volname, GLUSTERD_MAX_VOLUME_NAME);
+ GLUSTERD_GET_VOLUME_DIR(volpath, volinfo, priv);
+ }
+
+ ret = glusterd_store_update_volinfo (volinfo, snap);
+ if (ret) {
+ gf_log (this->name, GF_LOG_ERROR, "Failed to update volinfo "
+ "for %s volume", volname);
+ goto out;
+ }
+
if (snap)
ret = glusterd_store_retrieve_bricks (parent_vol, volinfo);
else
@@ -2906,12 +2992,12 @@ glusterd_store_retrieve_volume (char *volname, glusterd_snap_t *snap)
// 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);
+ list_add_tail (&volinfo->vol_list, &priv->volumes);
}
out:
- gf_log ("", GF_LOG_DEBUG, "Returning with %d", ret);
+ gf_log ("", GF_LOG_TRACE, "Returning with %d", ret);
return ret;
}
@@ -3070,7 +3156,7 @@ glusterd_store_retrieve_snap_cg (char *cg_store_name, glusterd_conf_t *priv)
if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_NAME,
sizeof (*key))) {
- strncpy (cg->cg_name, value, sizeof (value));
+ strcpy (cg->cg_name, value);
} else if (!strncmp(key, GLUSTERD_STORE_KEY_SNAP_STATUS,
sizeof (*key))) {
cg->cg_status = atoi (value);
@@ -3215,11 +3301,26 @@ glusterd_store_retrieve_snap_list (char *volname)
GF_FREE (value);
value = NULL;
+ if (!uuid_is_null(snap -> cg_id)) {
+ snprintf (key, sizeof (key), "%s-%"PRIu64,
+ GLUSTERD_STORE_KEY_SNAP_CG_NAME, count);
+ ret = gf_store_retrieve_value (shandle, key, &value);
+ if (ret){
+ gf_log ("", GF_LOG_ERROR,"Failed to retreive "
+ "CG name");
+ goto out;
+ }
+ strcpy (snap->cg_name, value);
+ GF_FREE (value);
+ value = NULL;
+ }
+
snprintf (key, sizeof (key), "%s-%"PRIu64,
GLUSTERD_STORE_KEY_SNAP_DESC, count);
ret = gf_store_retrieve_value (shandle, key, &value);
if (!ret) {
- snap->description = value;
+ if (uuid_is_null (snap -> cg_id))
+ snap->description = value;
value = NULL;
} else {
ret = 0;