summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-handler.c60
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c47
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-sm.h1
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c28
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.h29
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.h2
6 files changed, 102 insertions, 65 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-handler.c b/xlators/mgmt/glusterd/src/glusterd-handler.c
index 07a7fca85fa..af672c9336c 100644
--- a/xlators/mgmt/glusterd/src/glusterd-handler.c
+++ b/xlators/mgmt/glusterd/src/glusterd-handler.c
@@ -1025,28 +1025,30 @@ out:
int
glusterd_handle_create_volume (rpcsvc_request_t *req)
{
- int32_t ret = -1;
- gf1_cli_create_vol_req cli_req = {0,};
- dict_t *dict = NULL;
- glusterd_brickinfo_t *brickinfo = NULL;
- char *brick = NULL;
- char *bricks = NULL;
- char *volname = NULL;
- int brick_count = 0;
- char *tmpptr = NULL;
- int i = 0;
- glusterd_peerinfo_t *peerinfo = NULL;
- char *brick_list = NULL;
- void *cli_rsp = NULL;
- char err_str[1048];
- gf1_cli_create_vol_rsp rsp = {0,};
- glusterd_conf_t *priv = NULL;
- int err_ret = 0;
- glusterd_brickinfo_t *tmpbrkinfo = NULL;
- glusterd_volinfo_t *volinfo = NULL;
- xlator_t *this = NULL;
- char *free_ptr = NULL;
- char *trans_type = NULL;
+ int32_t ret = -1;
+ gf1_cli_create_vol_req cli_req = {0,};
+ dict_t *dict = NULL;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ char *brick = NULL;
+ char *bricks = NULL;
+ char *volname = NULL;
+ int brick_count = 0;
+ char *tmpptr = NULL;
+ int i = 0;
+ glusterd_peerinfo_t *peerinfo = NULL;
+ char *brick_list = NULL;
+ void *cli_rsp = NULL;
+ char err_str[1048];
+ gf1_cli_create_vol_rsp rsp = {0,};
+ glusterd_conf_t *priv = NULL;
+ int err_ret = 0;
+ glusterd_brickinfo_t *tmpbrkinfo = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ xlator_t *this = NULL;
+ char *free_ptr = NULL;
+ char *trans_type = NULL;
+ uuid_t volume_id = {0,};
+ char volid[64] = {0,};
GF_ASSERT (req);
@@ -1111,6 +1113,16 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
goto out;
}
+ uuid_generate (volume_id);
+ uuid_unparse (volume_id, volid);
+ free_ptr = gf_strdup (volid);
+ ret = dict_set_dynstr (dict, "volume-id", free_ptr);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "unable to set volume-id");
+ goto out;
+ }
+ free_ptr = NULL;
+
if (bricks) {
brick_list = gf_strdup (bricks);
free_ptr = brick_list;
@@ -2598,6 +2610,10 @@ glusterd_create_volume (rpcsvc_request_t *req, dict_t *dict)
if (!data)
goto out;
+ data = dict_get (dict, "volume-id");
+ if (!data)
+ goto out;
+
ret = glusterd_op_txn_begin ();
out:
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 9dbd90f7641..f77e5ab3ba5 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -975,22 +975,23 @@ out:
static int
glusterd_op_create_volume (gd1_mgmt_stage_op_req *req)
{
- int ret = 0;
- dict_t *dict = NULL;
- char *volname = NULL;
- glusterd_conf_t *priv = NULL;
- glusterd_volinfo_t *volinfo = NULL;
- glusterd_brickinfo_t *brickinfo = NULL;
- xlator_t *this = NULL;
- char *brick = NULL;
- int32_t count = 0;
- int32_t i = 1;
- char *bricks = NULL;
- char *brick_list = NULL;
- char *free_ptr = NULL;
- char *saveptr = NULL;
- int32_t sub_count = 0;
- char *trans_type = NULL;
+ int ret = 0;
+ dict_t *dict = NULL;
+ char *volname = NULL;
+ glusterd_conf_t *priv = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_brickinfo_t *brickinfo = NULL;
+ xlator_t *this = NULL;
+ char *brick = NULL;
+ int32_t count = 0;
+ int32_t i = 1;
+ char *bricks = NULL;
+ char *brick_list = NULL;
+ char *free_ptr = NULL;
+ char *saveptr = NULL;
+ int32_t sub_count = 0;
+ char *trans_type = NULL;
+ char *str = NULL;
GF_ASSERT (req);
@@ -1072,14 +1073,24 @@ glusterd_op_create_volume (gd1_mgmt_stage_op_req *req)
goto out;
}
- if (strcasecmp (trans_type, "rdma") == 0) {
+ ret = dict_get_str (dict, "volume-id", &str);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "Unable to get volume-id");
+ goto out;
+ }
+ ret = uuid_parse (str, volinfo->volume_id);
+ if (ret) {
+ gf_log ("", GF_LOG_ERROR, "unable to parse uuid %s", str);
+ goto out;
+ }
+
+ if (strcasecmp (trans_type, "rdma") == 0) {
volinfo->transport_type = GF_TRANSPORT_RDMA;
} else {
volinfo->transport_type = GF_TRANSPORT_TCP;
}
volinfo->sub_count = sub_count;
-
if (bricks) {
brick_list = gf_strdup (bricks);
free_ptr = brick_list;
diff --git a/xlators/mgmt/glusterd/src/glusterd-sm.h b/xlators/mgmt/glusterd/src/glusterd-sm.h
index 2bd2601cbda..2442c6eb13a 100644
--- a/xlators/mgmt/glusterd/src/glusterd-sm.h
+++ b/xlators/mgmt/glusterd/src/glusterd-sm.h
@@ -42,7 +42,6 @@ struct glusterd_store_handle_ {
char *path;
int fd;
FILE *read;
- FILE *write;
};
typedef struct glusterd_store_handle_ glusterd_store_handle_t;
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 6e7fbd3b2c0..b18693eb25f 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -319,6 +319,12 @@ glusterd_store_create_volume (glusterd_volinfo_t *volinfo)
if (ret)
goto out;
+ uuid_unparse (volinfo->volume_id, buf);
+ ret = glusterd_store_save_value (volinfo->shandle,
+ GLUSTERD_STORE_KEY_VOL_ID, buf);
+ if (ret)
+ goto out;
+
list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
ret = glusterd_store_create_brick (volinfo, brickinfo);
if (ret)
@@ -498,17 +504,8 @@ glusterd_store_save_value (glusterd_store_handle_t *handle,
goto out;
}
- handle->write = fdopen (handle->fd, "a+");
-
- if (!handle->write) {
- gf_log ("", GF_LOG_ERROR, "Unable to open file %s errno: %d",
- handle->path, errno);
- goto out;
- }
-
snprintf (buf, sizeof (buf), "%s=%s\n", key, value);
ret = write (handle->fd, buf, strlen (buf));
- //ret = fprintf (handle->write, "%s=%s\n", key, value);
if (ret < 0) {
gf_log ("", GF_LOG_CRITICAL, "Unable to store key: %s,"
@@ -524,7 +521,6 @@ out:
if (handle->fd > 0) {
close (handle->fd);
- handle->write = NULL;
handle->fd = -1;
}
@@ -955,6 +951,12 @@ glusterd_store_retrieve_volume (char *volname)
} else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_TRANSPORT,
strlen (GLUSTERD_STORE_KEY_VOL_TRANSPORT))) {
volinfo->transport_type = atoi (value);
+ } else if (!strncmp (key, GLUSTERD_STORE_KEY_VOL_ID,
+ strlen (GLUSTERD_STORE_KEY_VOL_ID))) {
+ ret = uuid_parse (value, volinfo->volume_id);
+ if (ret)
+ gf_log ("", GF_LOG_WARNING,
+ "failed to parse uuid");
} else {
gf_log ("", GF_LOG_ERROR, "Unknown key: %s",
key);
@@ -1082,6 +1084,12 @@ glusterd_store_update_volume (glusterd_volinfo_t *volinfo)
if (ret)
goto out;
+ uuid_unparse (volinfo->volume_id, buf);
+ ret = glusterd_store_save_value (volinfo->shandle,
+ GLUSTERD_STORE_KEY_VOL_ID, buf);
+ if (ret)
+ goto out;
+
list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
ret = glusterd_store_create_brick (volinfo, brickinfo);
if (ret)
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.h b/xlators/mgmt/glusterd/src/glusterd-store.h
index f12cb276be4..ff426f61791 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.h
+++ b/xlators/mgmt/glusterd/src/glusterd-store.h
@@ -38,23 +38,24 @@
#include "rpcsvc.h"
-#define GLUSTERD_STORE_UUID_KEY "UUID"
-
-#define GLUSTERD_STORE_KEY_VOL_TYPE "type"
-#define GLUSTERD_STORE_KEY_VOL_COUNT "count"
-#define GLUSTERD_STORE_KEY_VOL_STATUS "status"
-#define GLUSTERD_STORE_KEY_VOL_PORT "port"
-#define GLUSTERD_STORE_KEY_VOL_SUB_COUNT "sub_count"
-#define GLUSTERD_STORE_KEY_VOL_BRICK "brick"
-#define GLUSTERD_STORE_KEY_VOL_VERSION "version"
-#define GLUSTERD_STORE_KEY_VOL_TRANSPORT "transport-type"
+#define GLUSTERD_STORE_UUID_KEY "UUID"
+
+#define GLUSTERD_STORE_KEY_VOL_TYPE "type"
+#define GLUSTERD_STORE_KEY_VOL_COUNT "count"
+#define GLUSTERD_STORE_KEY_VOL_STATUS "status"
+#define GLUSTERD_STORE_KEY_VOL_PORT "port"
+#define GLUSTERD_STORE_KEY_VOL_SUB_COUNT "sub_count"
+#define GLUSTERD_STORE_KEY_VOL_BRICK "brick"
+#define GLUSTERD_STORE_KEY_VOL_VERSION "version"
+#define GLUSTERD_STORE_KEY_VOL_TRANSPORT "transport-type"
+#define GLUSTERD_STORE_KEY_VOL_ID "volume-id"
#define GLUSTERD_STORE_KEY_BRICK_HOSTNAME "hostname"
-#define GLUSTERD_STORE_KEY_BRICK_PATH "path"
+#define GLUSTERD_STORE_KEY_BRICK_PATH "path"
-#define GLUSTERD_STORE_KEY_PEER_UUID "uuid"
-#define GLUSTERD_STORE_KEY_PEER_HOSTNAME "hostname"
-#define GLUSTERD_STORE_KEY_PEER_STATE "state"
+#define GLUSTERD_STORE_KEY_PEER_UUID "uuid"
+#define GLUSTERD_STORE_KEY_PEER_HOSTNAME "hostname"
+#define GLUSTERD_STORE_KEY_PEER_STATE "state"
#define glusterd_for_each_entry(entry, dir) \
do {\
diff --git a/xlators/mgmt/glusterd/src/glusterd.h b/xlators/mgmt/glusterd/src/glusterd.h
index ad89613fc58..d733a84f4d3 100644
--- a/xlators/mgmt/glusterd/src/glusterd.h
+++ b/xlators/mgmt/glusterd/src/glusterd.h
@@ -143,6 +143,8 @@ struct glusterd_volinfo_ {
/* All xlator options */
dict_t *dict;
+
+ uuid_t volume_id;
};
typedef struct glusterd_volinfo_ glusterd_volinfo_t;