|
|
74096c |
From d7c52ddd2cbadb1d9a55767c2f7fe6ba38d9a2ed Mon Sep 17 00:00:00 2001
|
|
|
74096c |
From: Sheetal Pamecha <spamecha@redhat.com>
|
|
|
74096c |
Date: Wed, 20 Nov 2019 12:42:12 +0530
|
|
|
74096c |
Subject: [PATCH 431/449] glusterd: check for same node while adding bricks in
|
|
|
74096c |
disperse volume
|
|
|
74096c |
|
|
|
74096c |
The optimal way for configuring disperse and replicate volumes
|
|
|
74096c |
is to have all bricks in different nodes.
|
|
|
74096c |
|
|
|
74096c |
During create operation it fails saying it is not optimal, user
|
|
|
74096c |
must use force to over-ride this behavior. Implementing same
|
|
|
74096c |
during add-brick operation to avoid situation where all the added
|
|
|
74096c |
bricks end up from same host. Operation will error out accordingly.
|
|
|
74096c |
and this can be over-ridden by using force same as create.
|
|
|
74096c |
|
|
|
74096c |
> Upstream Patch Link: https://review.gluster.org/#/c/glusterfs/+/23729
|
|
|
74096c |
> fixes: #1047
|
|
|
74096c |
> Change-Id: I3ee9c97c1a14b73f4532893bc00187ef9355238b
|
|
|
74096c |
> Signed-off-by: Sheetal Pamecha <spamecha@redhat.com>
|
|
|
74096c |
|
|
|
74096c |
BUG: 1524457
|
|
|
74096c |
Change-Id: I3ee9c97c1a14b73f4532893bc00187ef9355238b
|
|
|
74096c |
Signed-off-by: Sheetal Pamecha <spamecha@redhat.com>
|
|
|
74096c |
Reviewed-on: https://code.engineering.redhat.com/gerrit/202621
|
|
|
74096c |
Tested-by: RHGS Build Bot <nigelb@redhat.com>
|
|
|
74096c |
Reviewed-by: Sanju Rakonde <srakonde@redhat.com>
|
|
|
74096c |
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
|
|
|
74096c |
---
|
|
|
74096c |
xlators/mgmt/glusterd/src/glusterd-brick-ops.c | 20 +-
|
|
|
74096c |
xlators/mgmt/glusterd/src/glusterd-utils.c | 224 ++++++++++++++++++
|
|
|
74096c |
xlators/mgmt/glusterd/src/glusterd-utils.h | 4 +
|
|
|
74096c |
xlators/mgmt/glusterd/src/glusterd-volume-ops.c | 293 +++---------------------
|
|
|
74096c |
4 files changed, 276 insertions(+), 265 deletions(-)
|
|
|
74096c |
|
|
|
74096c |
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
|
|
|
74096c |
index c5141de..d424f31 100644
|
|
|
74096c |
--- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
|
|
|
74096c |
+++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
|
|
|
74096c |
@@ -21,7 +21,6 @@
|
|
|
74096c |
#include "glusterd-messages.h"
|
|
|
74096c |
#include "glusterd-server-quorum.h"
|
|
|
74096c |
#include <glusterfs/run.h>
|
|
|
74096c |
-#include "glusterd-volgen.h"
|
|
|
74096c |
#include <glusterfs/syscall.h>
|
|
|
74096c |
#include <sys/signal.h>
|
|
|
74096c |
|
|
|
74096c |
@@ -1575,6 +1574,25 @@ glusterd_op_stage_add_brick(dict_t *dict, char **op_errstr, dict_t *rsp_dict)
|
|
|
74096c |
|
|
|
74096c |
is_force = dict_get_str_boolean(dict, "force", _gf_false);
|
|
|
74096c |
|
|
|
74096c |
+ /* Check brick order if the volume type is replicate or disperse. If
|
|
|
74096c |
+ * force at the end of command not given then check brick order.
|
|
|
74096c |
+ */
|
|
|
74096c |
+
|
|
|
74096c |
+ if (!is_force) {
|
|
|
74096c |
+ if ((volinfo->type == GF_CLUSTER_TYPE_REPLICATE) ||
|
|
|
74096c |
+ (volinfo->type == GF_CLUSTER_TYPE_DISPERSE)) {
|
|
|
74096c |
+ ret = glusterd_check_brick_order(dict, msg, volinfo->type);
|
|
|
74096c |
+ if (ret) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER,
|
|
|
74096c |
+ "Not adding brick because of "
|
|
|
74096c |
+ "bad brick order. %s",
|
|
|
74096c |
+ msg);
|
|
|
74096c |
+ *op_errstr = gf_strdup(msg);
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
if (volinfo->replica_count < replica_count && !is_force) {
|
|
|
74096c |
cds_list_for_each_entry(brickinfo, &volinfo->bricks, brick_list)
|
|
|
74096c |
{
|
|
|
74096c |
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
|
|
|
74096c |
index a1299bc..14e23d1 100644
|
|
|
74096c |
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
|
|
|
74096c |
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
|
|
|
74096c |
@@ -14759,3 +14759,227 @@ glusterd_is_profile_on(glusterd_volinfo_t *volinfo)
|
|
|
74096c |
return _gf_true;
|
|
|
74096c |
return _gf_false;
|
|
|
74096c |
}
|
|
|
74096c |
+
|
|
|
74096c |
+static gf_ai_compare_t
|
|
|
74096c |
+glusterd_compare_addrinfo(struct addrinfo *first, struct addrinfo *next)
|
|
|
74096c |
+{
|
|
|
74096c |
+ int ret = -1;
|
|
|
74096c |
+ struct addrinfo *tmp1 = NULL;
|
|
|
74096c |
+ struct addrinfo *tmp2 = NULL;
|
|
|
74096c |
+ char firstip[NI_MAXHOST] = {0.};
|
|
|
74096c |
+ char nextip[NI_MAXHOST] = {
|
|
|
74096c |
+ 0,
|
|
|
74096c |
+ };
|
|
|
74096c |
+
|
|
|
74096c |
+ for (tmp1 = first; tmp1 != NULL; tmp1 = tmp1->ai_next) {
|
|
|
74096c |
+ ret = getnameinfo(tmp1->ai_addr, tmp1->ai_addrlen, firstip, NI_MAXHOST,
|
|
|
74096c |
+ NULL, 0, NI_NUMERICHOST);
|
|
|
74096c |
+ if (ret)
|
|
|
74096c |
+ return GF_AI_COMPARE_ERROR;
|
|
|
74096c |
+ for (tmp2 = next; tmp2 != NULL; tmp2 = tmp2->ai_next) {
|
|
|
74096c |
+ ret = getnameinfo(tmp2->ai_addr, tmp2->ai_addrlen, nextip,
|
|
|
74096c |
+ NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
|
|
74096c |
+ if (ret)
|
|
|
74096c |
+ return GF_AI_COMPARE_ERROR;
|
|
|
74096c |
+ if (!strcmp(firstip, nextip)) {
|
|
|
74096c |
+ return GF_AI_COMPARE_MATCH;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+ return GF_AI_COMPARE_NO_MATCH;
|
|
|
74096c |
+}
|
|
|
74096c |
+
|
|
|
74096c |
+/* Check for non optimal brick order for Replicate/Disperse :
|
|
|
74096c |
+ * Checks if bricks belonging to a replicate or disperse
|
|
|
74096c |
+ * volume are present on the same server
|
|
|
74096c |
+ */
|
|
|
74096c |
+int32_t
|
|
|
74096c |
+glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type)
|
|
|
74096c |
+{
|
|
|
74096c |
+ int ret = -1;
|
|
|
74096c |
+ int i = 0;
|
|
|
74096c |
+ int j = 0;
|
|
|
74096c |
+ int k = 0;
|
|
|
74096c |
+ xlator_t *this = NULL;
|
|
|
74096c |
+ addrinfo_list_t *ai_list = NULL;
|
|
|
74096c |
+ addrinfo_list_t *ai_list_tmp1 = NULL;
|
|
|
74096c |
+ addrinfo_list_t *ai_list_tmp2 = NULL;
|
|
|
74096c |
+ char *brick = NULL;
|
|
|
74096c |
+ char *brick_list = NULL;
|
|
|
74096c |
+ char *brick_list_dup = NULL;
|
|
|
74096c |
+ char *brick_list_ptr = NULL;
|
|
|
74096c |
+ char *tmpptr = NULL;
|
|
|
74096c |
+ char *volname = NULL;
|
|
|
74096c |
+ int32_t brick_count = 0;
|
|
|
74096c |
+ int32_t sub_count = 0;
|
|
|
74096c |
+ struct addrinfo *ai_info = NULL;
|
|
|
74096c |
+ char brick_addr[128] = {
|
|
|
74096c |
+ 0,
|
|
|
74096c |
+ };
|
|
|
74096c |
+ int addrlen = 0;
|
|
|
74096c |
+
|
|
|
74096c |
+ const char failed_string[2048] =
|
|
|
74096c |
+ "Failed to perform brick order "
|
|
|
74096c |
+ "check. Use 'force' at the end of the command"
|
|
|
74096c |
+ " if you want to override this behavior. ";
|
|
|
74096c |
+ const char found_string[2048] =
|
|
|
74096c |
+ "Multiple bricks of a %s "
|
|
|
74096c |
+ "volume are present on the same server. This "
|
|
|
74096c |
+ "setup is not optimal. Bricks should be on "
|
|
|
74096c |
+ "different nodes to have best fault tolerant "
|
|
|
74096c |
+ "configuration. Use 'force' at the end of the "
|
|
|
74096c |
+ "command if you want to override this "
|
|
|
74096c |
+ "behavior. ";
|
|
|
74096c |
+
|
|
|
74096c |
+ this = THIS;
|
|
|
74096c |
+
|
|
|
74096c |
+ GF_ASSERT(this);
|
|
|
74096c |
+
|
|
|
74096c |
+ ai_list = MALLOC(sizeof(addrinfo_list_t));
|
|
|
74096c |
+ ai_list->info = NULL;
|
|
|
74096c |
+ CDS_INIT_LIST_HEAD(&ai_list->list);
|
|
|
74096c |
+
|
|
|
74096c |
+ ret = dict_get_strn(dict, "volname", SLEN("volname"), &volname);
|
|
|
74096c |
+ if (ret) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
|
|
|
74096c |
+ "Unable to get volume name");
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ ret = dict_get_strn(dict, "bricks", SLEN("bricks"), &brick_list);
|
|
|
74096c |
+ if (ret) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
|
|
|
74096c |
+ "Bricks check : Could not "
|
|
|
74096c |
+ "retrieve bricks list");
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ ret = dict_get_int32n(dict, "count", SLEN("count"), &brick_count);
|
|
|
74096c |
+ if (ret) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
|
|
|
74096c |
+ "Bricks check : Could not "
|
|
|
74096c |
+ "retrieve brick count");
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ if (type != GF_CLUSTER_TYPE_DISPERSE) {
|
|
|
74096c |
+ ret = dict_get_int32n(dict, "replica-count", SLEN("replica-count"),
|
|
|
74096c |
+ &sub_count);
|
|
|
74096c |
+ if (ret) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
|
|
|
74096c |
+ "Bricks check : Could"
|
|
|
74096c |
+ " not retrieve replica count");
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ gf_msg_debug(this->name, 0,
|
|
|
74096c |
+ "Replicate cluster type "
|
|
|
74096c |
+ "found. Checking brick order.");
|
|
|
74096c |
+ } else {
|
|
|
74096c |
+ ret = dict_get_int32n(dict, "disperse-count", SLEN("disperse-count"),
|
|
|
74096c |
+ &sub_count);
|
|
|
74096c |
+ if (ret) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
|
|
|
74096c |
+ "Bricks check : Could"
|
|
|
74096c |
+ " not retrieve disperse count");
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_DISPERSE_CLUSTER_FOUND,
|
|
|
74096c |
+ "Disperse cluster type"
|
|
|
74096c |
+ " found. Checking brick order.");
|
|
|
74096c |
+ }
|
|
|
74096c |
+ brick_list_dup = brick_list_ptr = gf_strdup(brick_list);
|
|
|
74096c |
+ /* Resolve hostnames and get addrinfo */
|
|
|
74096c |
+ while (i < brick_count) {
|
|
|
74096c |
+ ++i;
|
|
|
74096c |
+ brick = strtok_r(brick_list_dup, " \n", &tmpptr);
|
|
|
74096c |
+ brick_list_dup = tmpptr;
|
|
|
74096c |
+ if (brick == NULL)
|
|
|
74096c |
+ goto check_failed;
|
|
|
74096c |
+ tmpptr = strrchr(brick, ':');
|
|
|
74096c |
+ if (tmpptr == NULL)
|
|
|
74096c |
+ goto check_failed;
|
|
|
74096c |
+ addrlen = strlen(brick) - strlen(tmpptr);
|
|
|
74096c |
+ strncpy(brick_addr, brick, addrlen);
|
|
|
74096c |
+ brick_addr[addrlen] = '\0';
|
|
|
74096c |
+ ret = getaddrinfo(brick_addr, NULL, NULL, &ai_info);
|
|
|
74096c |
+ if (ret != 0) {
|
|
|
74096c |
+ ret = 0;
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_HOSTNAME_RESOLVE_FAIL,
|
|
|
74096c |
+ "unable to resolve host name for addr %s", brick_addr);
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ ai_list_tmp1 = MALLOC(sizeof(addrinfo_list_t));
|
|
|
74096c |
+ if (ai_list_tmp1 == NULL) {
|
|
|
74096c |
+ ret = 0;
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, ENOMEM, GD_MSG_NO_MEMORY,
|
|
|
74096c |
+ "failed to allocate "
|
|
|
74096c |
+ "memory");
|
|
|
74096c |
+ freeaddrinfo(ai_info);
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ ai_list_tmp1->info = ai_info;
|
|
|
74096c |
+ cds_list_add_tail(&ai_list_tmp1->list, &ai_list->list);
|
|
|
74096c |
+ ai_list_tmp1 = NULL;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ i = 0;
|
|
|
74096c |
+ ai_list_tmp1 = cds_list_entry(ai_list->list.next, addrinfo_list_t, list);
|
|
|
74096c |
+
|
|
|
74096c |
+ /* Check for bad brick order */
|
|
|
74096c |
+ while (i < brick_count) {
|
|
|
74096c |
+ ++i;
|
|
|
74096c |
+ ai_info = ai_list_tmp1->info;
|
|
|
74096c |
+ ai_list_tmp1 = cds_list_entry(ai_list_tmp1->list.next, addrinfo_list_t,
|
|
|
74096c |
+ list);
|
|
|
74096c |
+ if (0 == i % sub_count) {
|
|
|
74096c |
+ j = 0;
|
|
|
74096c |
+ continue;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ ai_list_tmp2 = ai_list_tmp1;
|
|
|
74096c |
+ k = j;
|
|
|
74096c |
+ while (k < sub_count - 1) {
|
|
|
74096c |
+ ++k;
|
|
|
74096c |
+ ret = glusterd_compare_addrinfo(ai_info, ai_list_tmp2->info);
|
|
|
74096c |
+ if (GF_AI_COMPARE_ERROR == ret)
|
|
|
74096c |
+ goto check_failed;
|
|
|
74096c |
+ if (GF_AI_COMPARE_MATCH == ret)
|
|
|
74096c |
+ goto found_bad_brick_order;
|
|
|
74096c |
+ ai_list_tmp2 = cds_list_entry(ai_list_tmp2->list.next,
|
|
|
74096c |
+ addrinfo_list_t, list);
|
|
|
74096c |
+ }
|
|
|
74096c |
+ ++j;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ gf_msg_debug(this->name, 0, "Brick order okay");
|
|
|
74096c |
+ ret = 0;
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+
|
|
|
74096c |
+check_failed:
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER_CHECK_FAIL,
|
|
|
74096c |
+ "Failed bad brick order check");
|
|
|
74096c |
+ snprintf(err_str, sizeof(failed_string), failed_string);
|
|
|
74096c |
+ ret = -1;
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+
|
|
|
74096c |
+found_bad_brick_order:
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_BAD_BRKORDER,
|
|
|
74096c |
+ "Bad brick order found");
|
|
|
74096c |
+ if (type == GF_CLUSTER_TYPE_DISPERSE) {
|
|
|
74096c |
+ snprintf(err_str, sizeof(found_string), found_string, "disperse");
|
|
|
74096c |
+ } else {
|
|
|
74096c |
+ snprintf(err_str, sizeof(found_string), found_string, "replicate");
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ ret = -1;
|
|
|
74096c |
+out:
|
|
|
74096c |
+ ai_list_tmp2 = NULL;
|
|
|
74096c |
+ GF_FREE(brick_list_ptr);
|
|
|
74096c |
+ cds_list_for_each_entry(ai_list_tmp1, &ai_list->list, list)
|
|
|
74096c |
+ {
|
|
|
74096c |
+ if (ai_list_tmp1->info)
|
|
|
74096c |
+ freeaddrinfo(ai_list_tmp1->info);
|
|
|
74096c |
+ free(ai_list_tmp2);
|
|
|
74096c |
+ ai_list_tmp2 = ai_list_tmp1;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ free(ai_list_tmp2);
|
|
|
74096c |
+ return ret;
|
|
|
74096c |
+}
|
|
|
74096c |
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
|
|
|
74096c |
index ead16b2..e2e2454 100644
|
|
|
74096c |
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
|
|
|
74096c |
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
|
|
|
74096c |
@@ -881,4 +881,8 @@ glusterd_is_profile_on(glusterd_volinfo_t *volinfo);
|
|
|
74096c |
|
|
|
74096c |
char *
|
|
|
74096c |
search_brick_path_from_proc(pid_t brick_pid, char *brickpath);
|
|
|
74096c |
+
|
|
|
74096c |
+int32_t
|
|
|
74096c |
+glusterd_check_brick_order(dict_t *dict, char *err_str, int32_t type);
|
|
|
74096c |
+
|
|
|
74096c |
#endif
|
|
|
74096c |
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
|
|
|
74096c |
index 93042ab..8da2ff3 100644
|
|
|
74096c |
--- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
|
|
|
74096c |
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
|
|
|
74096c |
@@ -41,240 +41,6 @@
|
|
|
74096c |
#define glusterd_op_start_volume_args_get(dict, volname, flags) \
|
|
|
74096c |
glusterd_op_stop_volume_args_get(dict, volname, flags)
|
|
|
74096c |
|
|
|
74096c |
-gf_ai_compare_t
|
|
|
74096c |
-glusterd_compare_addrinfo(struct addrinfo *first, struct addrinfo *next)
|
|
|
74096c |
-{
|
|
|
74096c |
- int ret = -1;
|
|
|
74096c |
- struct addrinfo *tmp1 = NULL;
|
|
|
74096c |
- struct addrinfo *tmp2 = NULL;
|
|
|
74096c |
- char firstip[NI_MAXHOST] = {0.};
|
|
|
74096c |
- char nextip[NI_MAXHOST] = {
|
|
|
74096c |
- 0,
|
|
|
74096c |
- };
|
|
|
74096c |
-
|
|
|
74096c |
- for (tmp1 = first; tmp1 != NULL; tmp1 = tmp1->ai_next) {
|
|
|
74096c |
- ret = getnameinfo(tmp1->ai_addr, tmp1->ai_addrlen, firstip, NI_MAXHOST,
|
|
|
74096c |
- NULL, 0, NI_NUMERICHOST);
|
|
|
74096c |
- if (ret)
|
|
|
74096c |
- return GF_AI_COMPARE_ERROR;
|
|
|
74096c |
- for (tmp2 = next; tmp2 != NULL; tmp2 = tmp2->ai_next) {
|
|
|
74096c |
- ret = getnameinfo(tmp2->ai_addr, tmp2->ai_addrlen, nextip,
|
|
|
74096c |
- NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
|
|
|
74096c |
- if (ret)
|
|
|
74096c |
- return GF_AI_COMPARE_ERROR;
|
|
|
74096c |
- if (!strcmp(firstip, nextip)) {
|
|
|
74096c |
- return GF_AI_COMPARE_MATCH;
|
|
|
74096c |
- }
|
|
|
74096c |
- }
|
|
|
74096c |
- }
|
|
|
74096c |
- return GF_AI_COMPARE_NO_MATCH;
|
|
|
74096c |
-}
|
|
|
74096c |
-
|
|
|
74096c |
-/* Check for non optimal brick order for replicate :
|
|
|
74096c |
- * Checks if bricks belonging to a replicate volume
|
|
|
74096c |
- * are present on the same server
|
|
|
74096c |
- */
|
|
|
74096c |
-int32_t
|
|
|
74096c |
-glusterd_check_brick_order(dict_t *dict, char *err_str)
|
|
|
74096c |
-{
|
|
|
74096c |
- int ret = -1;
|
|
|
74096c |
- int i = 0;
|
|
|
74096c |
- int j = 0;
|
|
|
74096c |
- int k = 0;
|
|
|
74096c |
- xlator_t *this = NULL;
|
|
|
74096c |
- addrinfo_list_t *ai_list = NULL;
|
|
|
74096c |
- addrinfo_list_t *ai_list_tmp1 = NULL;
|
|
|
74096c |
- addrinfo_list_t *ai_list_tmp2 = NULL;
|
|
|
74096c |
- char *brick = NULL;
|
|
|
74096c |
- char *brick_list = NULL;
|
|
|
74096c |
- char *brick_list_dup = NULL;
|
|
|
74096c |
- char *brick_list_ptr = NULL;
|
|
|
74096c |
- char *tmpptr = NULL;
|
|
|
74096c |
- char *volname = NULL;
|
|
|
74096c |
- int32_t brick_count = 0;
|
|
|
74096c |
- int32_t type = GF_CLUSTER_TYPE_NONE;
|
|
|
74096c |
- int32_t sub_count = 0;
|
|
|
74096c |
- struct addrinfo *ai_info = NULL;
|
|
|
74096c |
- char brick_addr[128] = {
|
|
|
74096c |
- 0,
|
|
|
74096c |
- };
|
|
|
74096c |
- int addrlen = 0;
|
|
|
74096c |
-
|
|
|
74096c |
- const char failed_string[2048] =
|
|
|
74096c |
- "Failed to perform brick order "
|
|
|
74096c |
- "check. Use 'force' at the end of the command"
|
|
|
74096c |
- " if you want to override this behavior. ";
|
|
|
74096c |
- const char found_string[2048] =
|
|
|
74096c |
- "Multiple bricks of a %s "
|
|
|
74096c |
- "volume are present on the same server. This "
|
|
|
74096c |
- "setup is not optimal. Bricks should be on "
|
|
|
74096c |
- "different nodes to have best fault tolerant "
|
|
|
74096c |
- "configuration. Use 'force' at the end of the "
|
|
|
74096c |
- "command if you want to override this "
|
|
|
74096c |
- "behavior. ";
|
|
|
74096c |
-
|
|
|
74096c |
- this = THIS;
|
|
|
74096c |
-
|
|
|
74096c |
- GF_ASSERT(this);
|
|
|
74096c |
-
|
|
|
74096c |
- ai_list = MALLOC(sizeof(addrinfo_list_t));
|
|
|
74096c |
- ai_list->info = NULL;
|
|
|
74096c |
- CDS_INIT_LIST_HEAD(&ai_list->list);
|
|
|
74096c |
-
|
|
|
74096c |
- ret = dict_get_strn(dict, "volname", SLEN("volname"), &volname);
|
|
|
74096c |
- if (ret) {
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
|
|
|
74096c |
- "Unable to get volume name");
|
|
|
74096c |
- goto out;
|
|
|
74096c |
- }
|
|
|
74096c |
-
|
|
|
74096c |
- ret = dict_get_int32n(dict, "type", SLEN("type"), &type);
|
|
|
74096c |
- if (ret) {
|
|
|
74096c |
- snprintf(err_str, 512, "Unable to get type of volume %s", volname);
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "%s",
|
|
|
74096c |
- err_str);
|
|
|
74096c |
- goto out;
|
|
|
74096c |
- }
|
|
|
74096c |
-
|
|
|
74096c |
- ret = dict_get_strn(dict, "bricks", SLEN("bricks"), &brick_list);
|
|
|
74096c |
- if (ret) {
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
|
|
|
74096c |
- "Bricks check : Could not "
|
|
|
74096c |
- "retrieve bricks list");
|
|
|
74096c |
- goto out;
|
|
|
74096c |
- }
|
|
|
74096c |
-
|
|
|
74096c |
- ret = dict_get_int32n(dict, "count", SLEN("count"), &brick_count);
|
|
|
74096c |
- if (ret) {
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
|
|
|
74096c |
- "Bricks check : Could not "
|
|
|
74096c |
- "retrieve brick count");
|
|
|
74096c |
- goto out;
|
|
|
74096c |
- }
|
|
|
74096c |
-
|
|
|
74096c |
- if (type != GF_CLUSTER_TYPE_DISPERSE) {
|
|
|
74096c |
- ret = dict_get_int32n(dict, "replica-count", SLEN("replica-count"),
|
|
|
74096c |
- &sub_count);
|
|
|
74096c |
- if (ret) {
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
|
|
|
74096c |
- "Bricks check : Could"
|
|
|
74096c |
- " not retrieve replica count");
|
|
|
74096c |
- goto out;
|
|
|
74096c |
- }
|
|
|
74096c |
- gf_msg_debug(this->name, 0,
|
|
|
74096c |
- "Replicate cluster type "
|
|
|
74096c |
- "found. Checking brick order.");
|
|
|
74096c |
- } else {
|
|
|
74096c |
- ret = dict_get_int32n(dict, "disperse-count", SLEN("disperse-count"),
|
|
|
74096c |
- &sub_count);
|
|
|
74096c |
- if (ret) {
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_DICT_GET_FAILED,
|
|
|
74096c |
- "Bricks check : Could"
|
|
|
74096c |
- " not retrieve disperse count");
|
|
|
74096c |
- goto out;
|
|
|
74096c |
- }
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_DISPERSE_CLUSTER_FOUND,
|
|
|
74096c |
- "Disperse cluster type"
|
|
|
74096c |
- " found. Checking brick order.");
|
|
|
74096c |
- }
|
|
|
74096c |
-
|
|
|
74096c |
- brick_list_dup = brick_list_ptr = gf_strdup(brick_list);
|
|
|
74096c |
- /* Resolve hostnames and get addrinfo */
|
|
|
74096c |
- while (i < brick_count) {
|
|
|
74096c |
- ++i;
|
|
|
74096c |
- brick = strtok_r(brick_list_dup, " \n", &tmpptr);
|
|
|
74096c |
- brick_list_dup = tmpptr;
|
|
|
74096c |
- if (brick == NULL)
|
|
|
74096c |
- goto check_failed;
|
|
|
74096c |
- tmpptr = strrchr(brick, ':');
|
|
|
74096c |
- if (tmpptr == NULL)
|
|
|
74096c |
- goto check_failed;
|
|
|
74096c |
- addrlen = strlen(brick) - strlen(tmpptr);
|
|
|
74096c |
- strncpy(brick_addr, brick, addrlen);
|
|
|
74096c |
- brick_addr[addrlen] = '\0';
|
|
|
74096c |
- ret = getaddrinfo(brick_addr, NULL, NULL, &ai_info);
|
|
|
74096c |
- if (ret != 0) {
|
|
|
74096c |
- ret = 0;
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_HOSTNAME_RESOLVE_FAIL,
|
|
|
74096c |
- "unable to resolve host name for addr %s", brick_addr);
|
|
|
74096c |
- goto out;
|
|
|
74096c |
- }
|
|
|
74096c |
- ai_list_tmp1 = MALLOC(sizeof(addrinfo_list_t));
|
|
|
74096c |
- if (ai_list_tmp1 == NULL) {
|
|
|
74096c |
- ret = 0;
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_ERROR, ENOMEM, GD_MSG_NO_MEMORY,
|
|
|
74096c |
- "failed to allocate "
|
|
|
74096c |
- "memory");
|
|
|
74096c |
- freeaddrinfo(ai_info);
|
|
|
74096c |
- goto out;
|
|
|
74096c |
- }
|
|
|
74096c |
- ai_list_tmp1->info = ai_info;
|
|
|
74096c |
- cds_list_add_tail(&ai_list_tmp1->list, &ai_list->list);
|
|
|
74096c |
- ai_list_tmp1 = NULL;
|
|
|
74096c |
- }
|
|
|
74096c |
-
|
|
|
74096c |
- i = 0;
|
|
|
74096c |
- ai_list_tmp1 = cds_list_entry(ai_list->list.next, addrinfo_list_t, list);
|
|
|
74096c |
-
|
|
|
74096c |
- /* Check for bad brick order */
|
|
|
74096c |
- while (i < brick_count) {
|
|
|
74096c |
- ++i;
|
|
|
74096c |
- ai_info = ai_list_tmp1->info;
|
|
|
74096c |
- ai_list_tmp1 = cds_list_entry(ai_list_tmp1->list.next, addrinfo_list_t,
|
|
|
74096c |
- list);
|
|
|
74096c |
- if (0 == i % sub_count) {
|
|
|
74096c |
- j = 0;
|
|
|
74096c |
- continue;
|
|
|
74096c |
- }
|
|
|
74096c |
- ai_list_tmp2 = ai_list_tmp1;
|
|
|
74096c |
- k = j;
|
|
|
74096c |
- while (k < sub_count - 1) {
|
|
|
74096c |
- ++k;
|
|
|
74096c |
- ret = glusterd_compare_addrinfo(ai_info, ai_list_tmp2->info);
|
|
|
74096c |
- if (GF_AI_COMPARE_ERROR == ret)
|
|
|
74096c |
- goto check_failed;
|
|
|
74096c |
- if (GF_AI_COMPARE_MATCH == ret)
|
|
|
74096c |
- goto found_bad_brick_order;
|
|
|
74096c |
- ai_list_tmp2 = cds_list_entry(ai_list_tmp2->list.next,
|
|
|
74096c |
- addrinfo_list_t, list);
|
|
|
74096c |
- }
|
|
|
74096c |
- ++j;
|
|
|
74096c |
- }
|
|
|
74096c |
- gf_msg_debug(this->name, 0, "Brick order okay");
|
|
|
74096c |
- ret = 0;
|
|
|
74096c |
- goto out;
|
|
|
74096c |
-
|
|
|
74096c |
-check_failed:
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER_CHECK_FAIL,
|
|
|
74096c |
- "Failed bad brick order check");
|
|
|
74096c |
- snprintf(err_str, sizeof(failed_string), failed_string);
|
|
|
74096c |
- ret = -1;
|
|
|
74096c |
- goto out;
|
|
|
74096c |
-
|
|
|
74096c |
-found_bad_brick_order:
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_BAD_BRKORDER,
|
|
|
74096c |
- "Bad brick order found");
|
|
|
74096c |
- if (type == GF_CLUSTER_TYPE_DISPERSE) {
|
|
|
74096c |
- snprintf(err_str, sizeof(found_string), found_string, "disperse");
|
|
|
74096c |
- } else {
|
|
|
74096c |
- snprintf(err_str, sizeof(found_string), found_string, "replicate");
|
|
|
74096c |
- }
|
|
|
74096c |
-
|
|
|
74096c |
- ret = -1;
|
|
|
74096c |
-out:
|
|
|
74096c |
- ai_list_tmp2 = NULL;
|
|
|
74096c |
- GF_FREE(brick_list_ptr);
|
|
|
74096c |
- cds_list_for_each_entry(ai_list_tmp1, &ai_list->list, list)
|
|
|
74096c |
- {
|
|
|
74096c |
- if (ai_list_tmp1->info)
|
|
|
74096c |
- freeaddrinfo(ai_list_tmp1->info);
|
|
|
74096c |
- free(ai_list_tmp2);
|
|
|
74096c |
- ai_list_tmp2 = ai_list_tmp1;
|
|
|
74096c |
- }
|
|
|
74096c |
- free(ai_list_tmp2);
|
|
|
74096c |
- return ret;
|
|
|
74096c |
-}
|
|
|
74096c |
-
|
|
|
74096c |
int
|
|
|
74096c |
__glusterd_handle_create_volume(rpcsvc_request_t *req)
|
|
|
74096c |
{
|
|
|
74096c |
@@ -1337,6 +1103,35 @@ glusterd_op_stage_create_volume(dict_t *dict, char **op_errstr,
|
|
|
74096c |
}
|
|
|
74096c |
}
|
|
|
74096c |
|
|
|
74096c |
+ /*Check brick order if the volume type is replicate or disperse. If
|
|
|
74096c |
+ * force at the end of command not given then check brick order.
|
|
|
74096c |
+ */
|
|
|
74096c |
+ if (is_origin_glusterd(dict)) {
|
|
|
74096c |
+ ret = dict_get_int32n(dict, "type", SLEN("type"), &type);
|
|
|
74096c |
+ if (ret) {
|
|
|
74096c |
+ snprintf(msg, sizeof(msg),
|
|
|
74096c |
+ "Unable to get type of "
|
|
|
74096c |
+ "volume %s",
|
|
|
74096c |
+ volname);
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "%s",
|
|
|
74096c |
+ msg);
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
+ if (!is_force) {
|
|
|
74096c |
+ if ((type == GF_CLUSTER_TYPE_REPLICATE) ||
|
|
|
74096c |
+ (type == GF_CLUSTER_TYPE_DISPERSE)) {
|
|
|
74096c |
+ ret = glusterd_check_brick_order(dict, msg, type);
|
|
|
74096c |
+ if (ret) {
|
|
|
74096c |
+ gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER,
|
|
|
74096c |
+ "Not creating volume because of "
|
|
|
74096c |
+ "bad brick order");
|
|
|
74096c |
+ goto out;
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+ }
|
|
|
74096c |
+
|
|
|
74096c |
while (i < brick_count) {
|
|
|
74096c |
i++;
|
|
|
74096c |
brick = strtok_r(brick_list, " \n", &tmpptr);
|
|
|
74096c |
@@ -1423,36 +1218,6 @@ glusterd_op_stage_create_volume(dict_t *dict, char **op_errstr,
|
|
|
74096c |
brick_info = NULL;
|
|
|
74096c |
}
|
|
|
74096c |
|
|
|
74096c |
- /*Check brick order if the volume type is replicate or disperse. If
|
|
|
74096c |
- * force at the end of command not given then check brick order.
|
|
|
74096c |
- */
|
|
|
74096c |
- if (is_origin_glusterd(dict)) {
|
|
|
74096c |
- ret = dict_get_int32n(dict, "type", SLEN("type"), &type);
|
|
|
74096c |
- if (ret) {
|
|
|
74096c |
- snprintf(msg, sizeof(msg),
|
|
|
74096c |
- "Unable to get type of "
|
|
|
74096c |
- "volume %s",
|
|
|
74096c |
- volname);
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_WARNING, 0, GD_MSG_DICT_GET_FAILED, "%s",
|
|
|
74096c |
- msg);
|
|
|
74096c |
- goto out;
|
|
|
74096c |
- }
|
|
|
74096c |
-
|
|
|
74096c |
- if (!is_force) {
|
|
|
74096c |
- if ((type == GF_CLUSTER_TYPE_REPLICATE) ||
|
|
|
74096c |
- (type == GF_CLUSTER_TYPE_DISPERSE)) {
|
|
|
74096c |
- ret = glusterd_check_brick_order(dict, msg);
|
|
|
74096c |
- if (ret) {
|
|
|
74096c |
- gf_msg(this->name, GF_LOG_ERROR, 0, GD_MSG_BAD_BRKORDER,
|
|
|
74096c |
- "Not "
|
|
|
74096c |
- "creating volume because of "
|
|
|
74096c |
- "bad brick order");
|
|
|
74096c |
- goto out;
|
|
|
74096c |
- }
|
|
|
74096c |
- }
|
|
|
74096c |
- }
|
|
|
74096c |
- }
|
|
|
74096c |
-
|
|
|
74096c |
ret = dict_set_int32n(rsp_dict, "brick_count", SLEN("brick_count"),
|
|
|
74096c |
local_brick_count);
|
|
|
74096c |
if (ret) {
|
|
|
74096c |
--
|
|
|
74096c |
1.8.3.1
|
|
|
74096c |
|