summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libglusterfs/src/store.c31
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-snapshot.c32
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c33
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.h1
4 files changed, 78 insertions, 19 deletions
diff --git a/libglusterfs/src/store.c b/libglusterfs/src/store.c
index 55027fa9b..64497e9bb 100644
--- a/libglusterfs/src/store.c
+++ b/libglusterfs/src/store.c
@@ -168,10 +168,12 @@ int
gf_store_read_and_tokenize (FILE *file, char *str, char **iter_key,
char **iter_val, gf_store_op_errno_t *store_errno)
{
- int32_t ret = -1;
- char *savetok = NULL;
- char *key = NULL;
- char *value = NULL;
+ int32_t ret = -1;
+ char *savetok = NULL;
+ char *key = NULL;
+ char *value = NULL;
+ char *temp = NULL;
+ size_t str_len = 0;
GF_ASSERT (file);
GF_ASSERT (str);
@@ -179,8 +181,12 @@ gf_store_read_and_tokenize (FILE *file, char *str, char **iter_key,
GF_ASSERT (iter_val);
GF_ASSERT (store_errno);
- ret = fscanf (file, "%s", str);
- if (ret <= 0 || feof (file)) {
+ temp = fgets (str, PATH_MAX, file);
+ str_len = strlen(str);
+ str[str_len - 1] = '\0';
+ /* Truncate the "\n", as fgets stores "\n" in str */
+
+ if (temp == NULL || feof (file)) {
ret = -1;
*store_errno = GD_STORE_EOF;
goto out;
@@ -253,8 +259,13 @@ gf_store_retrieve_value (gf_store_handle_t *handle, char *key, char **value)
goto out;
}
- scan_str = GF_CALLOC (1, st.st_size,
+ /* "st.st_size + 1" is used as we are fetching each
+ * line of a file using fgets, fgets will append "\0"
+ * to the end of the string
+ */
+ scan_str = GF_CALLOC (1, st.st_size + 1,
gf_common_mt_char);
+
if (scan_str == NULL) {
ret = -1;
store_errno = GD_STORE_ENOMEM;
@@ -532,7 +543,11 @@ gf_store_iter_get_next (gf_store_iter_t *iter, char **key, char **value,
goto out;
}
- scan_str = GF_CALLOC (1, st.st_size,
+ /* "st.st_size + 1" is used as we are fetching each
+ * line of a file using fgets, fgets will append "\0"
+ * to the end of the string
+ */
+ scan_str = GF_CALLOC (1, st.st_size + 1,
gf_common_mt_char);
if (!scan_str) {
ret = -1;
diff --git a/xlators/mgmt/glusterd/src/glusterd-snapshot.c b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
index 8386b44c5..acc8bef16 100644
--- a/xlators/mgmt/glusterd/src/glusterd-snapshot.c
+++ b/xlators/mgmt/glusterd/src/glusterd-snapshot.c
@@ -2695,7 +2695,7 @@ int32_t
glusterd_snap_create (glusterd_volinfo_t *volinfo,
glusterd_volinfo_t *snap_volinfo,
char *description, uuid_t *cg_id,
- char *cg_name)
+ glusterd_snap_cg_t *cg, char *cg_name)
{
glusterd_snap_t *snap = NULL;
xlator_t *this = NULL;
@@ -2724,8 +2724,26 @@ glusterd_snap_create (glusterd_volinfo_t *volinfo,
// for now ignore if description is not strduped
- if (description)
- snap->description = gf_strdup (description);
+ if (description) {
+ if (cg_id) {
+ cg->description = gf_strdup (description);
+ if (cg->description == NULL) {
+ gf_log ("", GF_LOG_ERROR,
+ "Saving the CG Description Failed");
+ ret = -1;
+ goto out;
+ }
+ }
+ else {
+ snap->description = gf_strdup (description);
+ if (snap->description == NULL) {
+ gf_log ("", GF_LOG_ERROR,
+ "Saving the Snap Description Failed");
+ ret = -1;
+ goto out;
+ }
+ }
+ }
snap->time_stamp = time (NULL);
uuid_copy (snap->snap_id, snap_volinfo->volume_id);
if (cg_id){
@@ -3047,7 +3065,7 @@ out:
*/
int32_t
glusterd_do_snap (glusterd_volinfo_t *volinfo, char *snapname, dict_t *dict,
- gf_boolean_t cg, uuid_t *cg_id, int volcount,
+ glusterd_snap_cg_t *cg, uuid_t *cg_id, int volcount,
uuid_t snap_volid, char *cg_name)
{
char *snap_brick_mount_path = "";
@@ -3191,7 +3209,7 @@ glusterd_do_snap (glusterd_volinfo_t *volinfo, char *snapname, dict_t *dict,
// for now continue the snap, if getting description fails.
ret = glusterd_snap_create (volinfo, snap_volume, description, cg_id,
- cg_name);
+ cg, cg_name);
if (ret) {
gf_log (this->name, GF_LOG_ERROR, "creating the"
"snap object failed for the volume %s",
@@ -4107,11 +4125,11 @@ glusterd_snapshot_create_commit (dict_t *dict, char **op_errstr,
*/
if (is_cg) {
ret = glusterd_do_snap (volinfo, tmp, dict,
- is_cg, cg_id, i, *snap_volid, name);
+ cg, cg_id, i, *snap_volid, name);
}
else {
ret = glusterd_do_snap (volinfo, tmp, dict,
- is_cg, cg_id, i, *snap_volid, NULL);
+ cg, cg_id, i, *snap_volid, NULL);
}
if (ret) {
gf_log (this->name, GF_LOG_WARNING, "taking the "
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 1a00aac88..d6e071b74 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -1222,6 +1222,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 +1252,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 +1297,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)
@@ -3070,7 +3080,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 +3225,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;
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h
index 13d408c44..02e723fe2 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.h
+++ b/xlators/mgmt/glusterd/src/glusterd-store.h
@@ -63,6 +63,7 @@ typedef enum glusterd_store_ver_ac_{
#define GLUSTERD_STORE_KEY_SNAP_NAME "name"
#define GLUSTERD_STORE_KEY_SNAP_ID "snap-id"
#define GLUSTERD_STORE_KEY_SNAP_CG_ID "cg-id"
+#define GLUSTERD_STORE_KEY_SNAP_CG_NAME "cg-name"
#define GLUSTERD_STORE_KEY_SNAP_DESC "desc"
#define GLUSTERD_STORE_KEY_SNAP_TIMESTAMP "time-stamp"
#define GLUSTERD_STORE_KEY_SNAP_STATUS "status"