summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd
diff options
context:
space:
mode:
authorKrishnan Parthasarathi <kparthas@redhat.com>2012-07-12 17:35:37 +0530
committerAnand Avati <avati@redhat.com>2012-07-19 09:09:33 -0700
commit9f5b8911b484230304fa52c0fcd92f696a4af74a (patch)
tree39c349e2bec47d1078d8452d84125f16928cdff4 /xlators/mgmt/glusterd
parentc0b07bdf5d253cf5620726f149700960e962b8ec (diff)
glusterd: Refactored brickinfo APIs
This patch modifies the existing brickinfo function signatures and/or names to do one thing right and call them by 'appropriate' names. - Decoupled brickinfo_get and is_brickpath_available - Removed dead comment about realpath(3) in canonicalize_path - Renamed glusterd_brickinfo_from_brick to glusterd_brickinfo_new_from_brick to make the name of the function reflect that an allocation is happening Change-Id: I29daba6d431ca799d43c927b9dfbaeda327e83e8 BUG: 764890 Signed-off-by: Krishnan Parthasarathi <kparthas@redhat.com> Reviewed-on: http://review.gluster.com/3668 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Amar Tumballi <amarts@redhat.com>
Diffstat (limited to 'xlators/mgmt/glusterd')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-brick-ops.c46
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-log-ops.c31
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-op-sm.c30
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-replace-brick.c37
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-store.c6
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c152
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h16
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volume-ops.c24
9 files changed, 145 insertions, 199 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
index 640b8cb0d..ce81c0c79 100644
--- a/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-brick-ops.c
@@ -740,8 +740,7 @@ glusterd_handle_remove_brick (rpcsvc_request_t *req)
i, brick);
ret = glusterd_volume_brickinfo_get_by_brick(brick, volinfo,
- &brickinfo,
- GF_PATH_COMPLETE);
+ &brickinfo);
if (ret) {
snprintf(err_str, 2048,"Incorrect brick %s for volume"
" %s", brick, volname);
@@ -904,7 +903,7 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count,
}
while ( i <= count) {
- ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
+ ret = glusterd_brickinfo_new_from_brick (brick, &brickinfo);
if (ret)
goto out;
@@ -953,12 +952,6 @@ glusterd_op_perform_add_bricks (glusterd_volinfo_t *volinfo, int32_t count,
while (i <= count) {
- ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo,
- &brickinfo,
- GF_PATH_PARTIAL);
- if (ret)
- goto out;
-
if (GLUSTERD_STATUS_STARTED == volinfo->status) {
ret = glusterd_brick_start (volinfo, brickinfo);
if (ret)
@@ -982,7 +975,6 @@ glusterd_op_perform_remove_brick (glusterd_volinfo_t *volinfo, char *brick,
int force, int *need_migrate)
{
glusterd_brickinfo_t *brickinfo = NULL;
- char *dup_brick = NULL;
int32_t ret = -1;
glusterd_conf_t *priv = NULL;
@@ -992,12 +984,8 @@ glusterd_op_perform_remove_brick (glusterd_volinfo_t *volinfo, char *brick,
priv = THIS->private;
GF_ASSERT (priv);
- dup_brick = gf_strdup (brick);
- if (!dup_brick)
- goto out;
-
- ret = glusterd_volume_brickinfo_get_by_brick (dup_brick, volinfo,
- &brickinfo, GF_PATH_COMPLETE);
+ ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo,
+ &brickinfo);
if (ret)
goto out;
@@ -1027,9 +1015,8 @@ glusterd_op_perform_remove_brick (glusterd_volinfo_t *volinfo, char *brick,
}
brickinfo->decommissioned = 1;
+ ret = 0;
out:
- GF_FREE (dup_brick);
-
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -1129,27 +1116,14 @@ glusterd_op_stage_add_brick (dict_t *dict, char **op_errstr)
}
- ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo,
- &brickinfo,
- GF_PATH_PARTIAL);
- if (!ret) {
+ ret = glusterd_brickinfo_new_from_brick (brick, &brickinfo);
+ if (ret) {
gf_log (THIS->name, GF_LOG_ERROR,
- "Adding duplicate brick: %s", brick);
- snprintf (msg, sizeof (msg), "Brick %s is already a "
- "part of the volume", brick);
- *op_errstr = gf_strdup (msg);
- ret = -1;
+ "Add-brick: Unable"
+ " to get brickinfo");
goto out;
- } else {
- ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
- if (ret) {
- gf_log (THIS->name, GF_LOG_ERROR,
- "Add-brick: Unable"
- " to get brickinfo");
- goto out;
- }
- brick_alloc = _gf_true;
}
+ brick_alloc = _gf_true;
ret = glusterd_new_brick_validate (brick, brickinfo, msg,
sizeof (msg));
diff --git a/xlators/mgmt/glusterd/src/glusterd-log-ops.c b/xlators/mgmt/glusterd/src/glusterd-log-ops.c
index 3ac78a917..b5fd5eff6 100644
--- a/xlators/mgmt/glusterd/src/glusterd-log-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-log-ops.c
@@ -141,16 +141,13 @@ glusterd_op_stage_log_rotate (dict_t *dict, char **op_errstr)
goto out;
}
- if (strchr (brick, ':')) {
- ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo, NULL,
- GF_PATH_COMPLETE);
- if (ret) {
- snprintf (msg, sizeof (msg), "Incorrect brick %s "
- "for volume %s", brick, volname);
- gf_log ("", GF_LOG_ERROR, "%s", msg);
- *op_errstr = gf_strdup (msg);
- goto out;
- }
+ ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo, NULL);
+ if (ret) {
+ snprintf (msg, sizeof (msg), "Incorrect brick %s "
+ "for volume %s", brick, volname);
+ gf_log ("", GF_LOG_ERROR, "%s", msg);
+ *op_errstr = gf_strdup (msg);
+ goto out;
}
out:
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
@@ -201,15 +198,11 @@ glusterd_op_log_rotate (dict_t *dict)
if (ret)
goto cont;
- if (!strchr (brick, ':'))
- brick = NULL;
- else {
- ret = glusterd_brickinfo_from_brick (brick, &tmpbrkinfo);
- if (ret) {
- gf_log ("glusterd", GF_LOG_ERROR,
- "cannot get brickinfo from brick");
- goto out;
- }
+ ret = glusterd_brickinfo_new_from_brick (brick, &tmpbrkinfo);
+ if (ret) {
+ gf_log ("glusterd", GF_LOG_ERROR,
+ "cannot get brickinfo from brick");
+ goto out;
}
cont:
diff --git a/xlators/mgmt/glusterd/src/glusterd-op-sm.c b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
index 26817d4e3..d6855b904 100644
--- a/xlators/mgmt/glusterd/src/glusterd-op-sm.c
+++ b/xlators/mgmt/glusterd/src/glusterd-op-sm.c
@@ -654,7 +654,6 @@ glusterd_op_stage_status_volume (dict_t *dict, char **op_errstr)
xlator_t *this = NULL;
glusterd_conf_t *priv = NULL;
glusterd_brickinfo_t *brickinfo = NULL;
- glusterd_brickinfo_t *tmpbrickinfo = NULL;
glusterd_volinfo_t *volinfo = NULL;
dict_t *vol_opts = NULL;
gf_boolean_t nfs_disabled = _gf_false;
@@ -742,21 +741,8 @@ glusterd_op_stage_status_volume (dict_t *dict, char **op_errstr)
if (ret)
goto out;
- ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
- if (ret) {
- snprintf (msg, sizeof (msg), "%s is not a brick",
- brick);
- gf_log (THIS->name, GF_LOG_ERROR, "%s", msg);
- goto out;
- }
-
- ret = glusterd_volume_brickinfo_get (NULL,
- brickinfo->hostname,
- brickinfo->path,
- volinfo,
- &tmpbrickinfo,
- GF_PATH_COMPLETE);
-
+ ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo,
+ &brickinfo);
if (ret) {
snprintf (msg, sizeof(msg), "No brick %s in"
" volume %s", brick, volname);
@@ -1523,8 +1509,7 @@ glusterd_op_status_volume (dict_t *dict, char **op_errstr,
ret = glusterd_volume_brickinfo_get_by_brick (brick,
volinfo,
- &brickinfo,
- GF_PATH_COMPLETE);
+ &brickinfo);
if (ret)
goto out;
@@ -3528,8 +3513,7 @@ glusterd_bricks_select_remove_brick (dict_t *dict, char **op_errstr)
}
ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo,
- &brickinfo,
- GF_PATH_COMPLETE);
+ &brickinfo);
if (ret)
goto out;
if (glusterd_is_brick_started (brickinfo)) {
@@ -3670,8 +3654,7 @@ glusterd_bricks_select_profile_volume (dict_t *dict, char **op_errstr)
ret = dict_get_str (dict, "brick", &brick);
if (!ret) {
ret = glusterd_volume_brickinfo_get_by_brick (brick, volinfo,
- &brickinfo,
- GF_PATH_COMPLETE);
+ &brickinfo);
if (ret)
goto out;
@@ -4007,8 +3990,7 @@ glusterd_bricks_select_status_volume (dict_t *dict, char **op_errstr)
}
ret = glusterd_volume_brickinfo_get_by_brick (brickname,
volinfo,
- &brickinfo,
- GF_PATH_COMPLETE);
+ &brickinfo);
if (ret)
goto out;
diff --git a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
index 5bd6a55b9..fc35a4406 100644
--- a/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
+++ b/xlators/mgmt/glusterd/src/glusterd-replace-brick.c
@@ -363,8 +363,7 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr,
}
ret = glusterd_volume_brickinfo_get_by_brick (src_brick, volinfo,
- &src_brickinfo,
- GF_PATH_COMPLETE);
+ &src_brickinfo);
if (ret) {
snprintf (msg, sizeof (msg), "brick: %s does not exist in "
"volume: %s", src_brick, volname);
@@ -432,18 +431,20 @@ glusterd_op_stage_replace_brick (dict_t *dict, char **op_errstr,
ret = -1;
goto out;
}
- if (!glusterd_brickinfo_get (NULL, host, path, NULL)) {
- snprintf(msg, sizeof(msg), "Brick: %s:%s already in use",
- host, path);
+
+ ret = glusterd_brickinfo_new_from_brick (dst_brick, &dst_brickinfo);
+ if (ret)
+ goto out;
+
+ ret = glusterd_new_brick_validate (dst_brick, dst_brickinfo,
+ msg, sizeof (msg));
+ if (ret) {
*op_errstr = gf_strdup (msg);
ret = -1;
+ gf_log (THIS->name, GF_LOG_ERROR, *op_errstr);
goto out;
}
- ret = glusterd_brickinfo_from_brick (dst_brick, &dst_brickinfo);
- if (ret)
- goto out;
-
if (!glusterd_is_rb_ongoing (volinfo) &&
(replace_op == GF_REPLACE_OP_START ||
replace_op == GF_REPLACE_OP_COMMIT_FORCE)) {
@@ -1321,14 +1322,8 @@ glusterd_op_perform_replace_brick (glusterd_volinfo_t *volinfo,
GF_ASSERT (volinfo);
- ret = glusterd_brickinfo_from_brick (new_brick,
- &new_brickinfo);
- if (ret)
- goto out;
-
- ret = glusterd_volume_brickinfo_get_by_brick (old_brick, volinfo,
- &old_brickinfo,
- GF_PATH_COMPLETE);
+ ret = glusterd_brickinfo_new_from_brick (new_brick,
+ &new_brickinfo);
if (ret)
goto out;
@@ -1355,8 +1350,8 @@ glusterd_op_perform_replace_brick (glusterd_volinfo_t *volinfo,
goto out;
}
-
out:
+
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -1421,8 +1416,7 @@ glusterd_op_replace_brick (dict_t *dict, dict_t *rsp_dict)
}
ret = glusterd_volume_brickinfo_get_by_brick (src_brick, volinfo,
- &src_brickinfo,
- GF_PATH_COMPLETE);
+ &src_brickinfo);
if (ret) {
gf_log ("", GF_LOG_DEBUG, "Unable to get src-brickinfo");
goto out;
@@ -1742,8 +1736,7 @@ glusterd_do_replace_brick (void *data)
}
ret = glusterd_volume_brickinfo_get_by_brick (src_brick, volinfo,
- &src_brickinfo,
- GF_PATH_COMPLETE);
+ &src_brickinfo);
if (ret) {
gf_log ("", GF_LOG_DEBUG, "Unable to get src-brickinfo");
goto out;
diff --git a/xlators/mgmt/glusterd/src/glusterd-store.c b/xlators/mgmt/glusterd/src/glusterd-store.c
index 5fb18d0ae..2f392f576 100644
--- a/xlators/mgmt/glusterd/src/glusterd-store.c
+++ b/xlators/mgmt/glusterd/src/glusterd-store.c
@@ -234,7 +234,7 @@ glusterd_store_is_valid_brickpath (char *volname, char *brick)
int32_t ret = 0;
size_t volname_len = strlen (volname);
- ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
+ ret = glusterd_brickinfo_new_from_brick (brick, &brickinfo);
if (ret) {
gf_log ("", GF_LOG_WARNING, "brick path validation failed");
ret = 0;
@@ -1991,13 +1991,13 @@ glusterd_store_retrieve_rbstate (char *volname)
if (volinfo->rb_status > GF_RB_STATUS_NONE) {
if (!strncmp (key, GLUSTERD_STORE_KEY_RB_SRC_BRICK,
strlen (GLUSTERD_STORE_KEY_RB_SRC_BRICK))) {
- ret = glusterd_brickinfo_from_brick (value,
+ ret = glusterd_brickinfo_new_from_brick (value,
&volinfo->src_brick);
if (ret)
goto out;
} else if (!strncmp (key, GLUSTERD_STORE_KEY_RB_DST_BRICK,
strlen (GLUSTERD_STORE_KEY_RB_DST_BRICK))) {
- ret = glusterd_brickinfo_from_brick (value,
+ ret = glusterd_brickinfo_new_from_brick (value,
&volinfo->dst_brick);
if (ret)
goto out;
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index feb81d8de..987615a57 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -735,8 +735,8 @@ glusterd_resolve_brick (glusterd_brickinfo_t *brickinfo)
}
int32_t
-glusterd_brickinfo_from_brick (char *brick,
- glusterd_brickinfo_t **brickinfo)
+glusterd_brickinfo_new_from_brick (char *brick,
+ glusterd_brickinfo_t **brickinfo)
{
int32_t ret = -1;
glusterd_brickinfo_t *new_brickinfo = NULL;
@@ -780,11 +780,69 @@ out:
return ret;
}
+static gf_boolean_t
+_is_prefix (char *str1, char *str2)
+{
+ GF_ASSERT (str1);
+ GF_ASSERT (str2);
+
+ int i = 0;
+ int small_len = 0;
+ gf_boolean_t prefix = _gf_true;
+
+ small_len = min (strlen (str1), strlen (str2));
+ for (i = 0; i < small_len; i++) {
+ if (str1[i] != str2[i]) {
+ prefix = _gf_false;
+ break;
+ }
+
+ }
+
+ return prefix;
+}
+
+/* Checks if @path is available in the peer identified by @uuid
+ * 'availability' is determined by querying current state of volumes
+ * in the cluster. */
+gf_boolean_t
+glusterd_is_brickpath_available (uuid_t uuid, char *path)
+{
+ glusterd_brickinfo_t *brickinfo = NULL;
+ glusterd_volinfo_t *volinfo = NULL;
+ glusterd_conf_t *priv = NULL;
+ gf_boolean_t available = _gf_false;
+ char tmp_path[PATH_MAX+1] = {0};
+ char tmp_brickpath[PATH_MAX+1] = {0};
+
+ priv = THIS->private;
+
+ strncpy (tmp_path, path, PATH_MAX);
+ /* path may not yet exist */
+ if (!realpath (path, tmp_path) && (errno != ENOENT))
+ goto out;
+
+ list_for_each_entry (volinfo, &priv->volumes, vol_list) {
+ list_for_each_entry (brickinfo, &volinfo->bricks, brick_list) {
+ if (uuid_compare (uuid, brickinfo->uuid))
+ continue;
+
+ if (!realpath (brickinfo->path, tmp_brickpath))
+ goto out;
+
+ if (_is_prefix (tmp_brickpath, tmp_path))
+ goto out;
+ }
+ }
+ available = _gf_true;
+out:
+ return available;
+}
+
int32_t
glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path,
glusterd_volinfo_t *volinfo,
- glusterd_brickinfo_t **brickinfo,
- gf_path_match_t path_match)
+ glusterd_brickinfo_t **brickinfo)
{
glusterd_brickinfo_t *brickiter = NULL;
uuid_t peer_uuid = {0};
@@ -800,34 +858,19 @@ glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path,
ret = -1;
list_for_each_entry (brickiter, &volinfo->bricks, brick_list) {
- if (uuid_is_null (brickiter->uuid) &&
- glusterd_resolve_brick (brickiter))
+ if ((uuid_is_null (brickiter->uuid)) &&
+ (glusterd_resolve_brick (brickiter) != 0))
goto out;
if (uuid_compare (peer_uuid, brickiter->uuid))
continue;
- if (!strcmp (brickiter->path, path)) {
+ if (strcmp (brickiter->path, path) == 0) {
gf_log (THIS->name, GF_LOG_INFO, "Found brick");
ret = 0;
if (brickinfo)
*brickinfo = brickiter;
break;
}
-
- if (path_match != GF_PATH_PARTIAL)
- continue;
-
-#ifdef GF_LINUX_HOST_OS
- if (!fnmatch (path, brickiter->path, FNM_LEADING_DIR) ||
- !fnmatch (brickiter->path, path, FNM_LEADING_DIR)) {
- gf_log (THIS->name, GF_LOG_ERROR,
- "paths %s and %s are recursive",
- path, brickiter->path);
- *brickinfo = brickiter;
- ret = 0;
- break;
- }
-#endif
}
out:
@@ -838,40 +881,23 @@ out:
int32_t
glusterd_volume_brickinfo_get_by_brick (char *brick,
glusterd_volinfo_t *volinfo,
- glusterd_brickinfo_t **brickinfo,
- gf_path_match_t path_match)
+ glusterd_brickinfo_t **brickinfo)
{
int32_t ret = -1;
- char *hostname = NULL;
- char *path = NULL;
- char *tmp_host = NULL;
- char *tmp_path = NULL;
+ glusterd_brickinfo_t *tmp_brickinfo = NULL;
GF_ASSERT (brick);
GF_ASSERT (volinfo);
- gf_log ("", GF_LOG_INFO, "brick: %s", brick);
-
- tmp_host = gf_strdup (brick);
- if (tmp_host)
- get_host_name (tmp_host, &hostname);
- tmp_path = gf_strdup (brick);
- if (tmp_path)
- get_path_name (tmp_path, &path);
-
- if (!hostname || !path) {
- gf_log ("", GF_LOG_ERROR,
- "brick %s is not of form <HOSTNAME>:<export-dir>",
- brick);
- ret = -1;
+ ret = glusterd_brickinfo_new_from_brick (brick, &tmp_brickinfo);
+ if (ret)
goto out;
- }
- ret = glusterd_volume_brickinfo_get (NULL, hostname, path, volinfo,
- brickinfo, path_match);
+ ret = glusterd_volume_brickinfo_get (NULL, tmp_brickinfo->hostname,
+ tmp_brickinfo->path, volinfo,
+ brickinfo);
+ (void) glusterd_brickinfo_delete (tmp_brickinfo);
out:
- GF_FREE (tmp_host);
- GF_FREE (tmp_path);
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);
return ret;
}
@@ -885,7 +911,7 @@ glusterd_is_brick_decommissioned (glusterd_volinfo_t *volinfo, char *hostname,
int ret = -1;
ret = glusterd_volume_brickinfo_get (NULL, hostname, path, volinfo,
- &brickinfo, GF_PATH_COMPLETE);
+ &brickinfo);
if (ret)
goto out;
decommissioned = brickinfo->decommissioned;
@@ -2289,7 +2315,7 @@ glusterd_import_volinfo (dict_t *vols, int count,
if (ret)
goto out;
- ret = glusterd_brickinfo_from_brick (src_brick,
+ ret = glusterd_brickinfo_new_from_brick (src_brick,
&new_volinfo->src_brick);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to create"
@@ -2304,7 +2330,7 @@ glusterd_import_volinfo (dict_t *vols, int count,
if (ret)
goto out;
- ret = glusterd_brickinfo_from_brick (dst_brick,
+ ret = glusterd_brickinfo_new_from_brick (dst_brick,
&new_volinfo->dst_brick);
if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to create"
@@ -2366,8 +2392,7 @@ glusterd_volinfo_copy_brick_portinfo (glusterd_volinfo_t *new_volinfo,
ret = glusterd_volume_brickinfo_get (new_brickinfo->uuid,
new_brickinfo->hostname,
new_brickinfo->path,
- old_volinfo, &old_brickinfo,
- GF_PATH_COMPLETE);
+ old_volinfo, &old_brickinfo);
if ((0 == ret) && glusterd_is_brick_started (old_brickinfo)) {
new_brickinfo->port = old_brickinfo->port;
}
@@ -2393,8 +2418,7 @@ glusterd_volinfo_stop_stale_bricks (glusterd_volinfo_t *new_volinfo,
ret = glusterd_volume_brickinfo_get (old_brickinfo->uuid,
old_brickinfo->hostname,
old_brickinfo->path,
- new_volinfo, &new_brickinfo,
- GF_PATH_COMPLETE);
+ new_volinfo, &new_brickinfo);
if (ret) {
ret = glusterd_brick_stop (old_volinfo, old_brickinfo);
if (ret)
@@ -3373,9 +3397,9 @@ glusterd_brickinfo_get (uuid_t uuid, char *hostname, char *path,
list_for_each_entry (volinfo, &priv->volumes, vol_list) {
ret = glusterd_volume_brickinfo_get (uuid, hostname, path,
- volinfo, brickinfo,
- GF_PATH_COMPLETE);
- if (!ret)
+ volinfo, brickinfo);
+ if (ret == 0)
+ /*Found*/
goto out;
}
out:
@@ -4250,7 +4274,6 @@ glusterd_new_brick_validate (char *brick, glusterd_brickinfo_t *brickinfo,
char *op_errstr, size_t len)
{
glusterd_brickinfo_t *newbrickinfo = NULL;
- glusterd_brickinfo_t *tmpbrkinfo = NULL;
int ret = -1;
gf_boolean_t is_allocated = _gf_false;
glusterd_peerinfo_t *peerinfo = NULL;
@@ -4267,7 +4290,7 @@ glusterd_new_brick_validate (char *brick, glusterd_brickinfo_t *brickinfo,
GF_ASSERT (op_errstr);
if (!brickinfo) {
- ret = glusterd_brickinfo_from_brick (brick, &newbrickinfo);
+ ret = glusterd_brickinfo_new_from_brick (brick, &newbrickinfo);
if (ret)
goto out;
is_allocated = _gf_true;
@@ -4297,11 +4320,10 @@ glusterd_new_brick_validate (char *brick, glusterd_brickinfo_t *brickinfo,
goto out;
}
brick_validation:
- ret = glusterd_brickinfo_get (newbrickinfo->uuid,
- newbrickinfo->hostname,
- newbrickinfo->path, &tmpbrkinfo);
- if (!ret) {
- snprintf(op_errstr, len, "Brick: %s already in use",
+ if (!glusterd_is_brickpath_available (newbrickinfo->uuid,
+ newbrickinfo->path)) {
+ snprintf(op_errstr, len, "Brick: %s not available. Brick may "
+ "be containing or be contained by an existing brick",
brick);
gf_log (THIS->name, GF_LOG_ERROR, "%s", op_errstr);
ret = -1;
@@ -4836,7 +4858,7 @@ glusterd_delete_brick (glusterd_volinfo_t* volinfo,
ret = glusterd_volume_brickinfo_get (brickinfo->uuid,
brickinfo->hostname,
brickinfo->path, volinfo,
- NULL, GF_PATH_COMPLETE);
+ NULL);
GF_ASSERT (0 == ret);
#endif
glusterd_delete_volfile (volinfo, brickinfo);
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index 0990ae524..c538345fd 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -38,12 +38,6 @@
#include "rpc-clnt.h"
#include "protocol-common.h"
-/* For brick search using path: partial or complete */
-typedef enum {
- GF_PATH_COMPLETE = 0,
- GF_PATH_PARTIAL
-} gf_path_match_t;
-
struct glusterd_lock_ {
uuid_t owner;
time_t timestamp;
@@ -112,7 +106,7 @@ int32_t
glusterd_brickinfo_new (glusterd_brickinfo_t **brickinfo);
int32_t
-glusterd_brickinfo_from_brick (char *brick, glusterd_brickinfo_t **brickinfo);
+glusterd_brickinfo_new_from_brick (char *brick, glusterd_brickinfo_t **brickinfo);
int32_t
glusterd_friend_cleanup (glusterd_peerinfo_t *peerinfo);
@@ -153,8 +147,8 @@ glusterd_is_cli_op_req (int32_t op);
int32_t
glusterd_volume_brickinfo_get_by_brick (char *brick,
glusterd_volinfo_t *volinfo,
- glusterd_brickinfo_t **brickinfo,
- gf_path_match_t path_match);
+ glusterd_brickinfo_t **brickinfo);
+
int32_t
glusterd_is_local_addr (char *hostname);
@@ -299,8 +293,8 @@ glusterd_volume_brickinfos_delete (glusterd_volinfo_t *volinfo);
int32_t
glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path,
glusterd_volinfo_t *volinfo,
- glusterd_brickinfo_t **brickinfo,
- gf_path_match_t path_match);
+ glusterd_brickinfo_t **brickinfo);
+
int
glusterd_brickinfo_get (uuid_t uuid, char *hostname, char *path,
glusterd_brickinfo_t **brickinfo);
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 268116019..28d37d7ed 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -3110,7 +3110,7 @@ glusterd_is_valid_volfpath (char *volname, char *brick)
glusterd_volinfo_t *volinfo = NULL;
int32_t ret = 0;
- ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
+ ret = glusterd_brickinfo_new_from_brick (brick, &brickinfo);
if (ret) {
gf_log ("", GF_LOG_WARNING, "brick path validation failed");
ret = 0;
diff --git a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
index f706ac674..829985022 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volume-ops.c
@@ -58,7 +58,6 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
char *trans_type = NULL;
uuid_t volume_id = {0,};
uuid_t tmp_uuid = {0};
- glusterd_brickinfo_t *tmpbrkinfo = NULL;
glusterd_volinfo_t tmpvolinfo = {{0},};
int32_t type = 0;
char *username = NULL;
@@ -126,12 +125,12 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
}
ret = dict_get_int32 (dict, "type", &type);
- /*if (ret) {
+ if (ret) {
gf_log ("", GF_LOG_ERROR, "Unable to get type");
snprintf (err_str, sizeof (err_str), "Unable to get volume "
"type");
goto out;
- }*/
+ }
ret = dict_get_str (dict, "transport", &trans_type);
if (ret) {
@@ -173,7 +172,7 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
i++;
brick= strtok_r (brick_list, " \n", &tmpptr);
brick_list = tmpptr;
- ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
+ ret = glusterd_brickinfo_new_from_brick (brick, &brickinfo);
if (ret) {
snprintf (err_str, sizeof (err_str), "Unable to get "
"brick info from brick %s", brick);
@@ -184,18 +183,7 @@ glusterd_handle_create_volume (rpcsvc_request_t *req)
sizeof (err_str));
if (ret)
goto out;
- ret = glusterd_volume_brickinfo_get (brickinfo->uuid,
- brickinfo->hostname,
- brickinfo->path,
- &tmpvolinfo, &tmpbrkinfo,
- GF_PATH_PARTIAL);
- if (!ret) {
- ret = -1;
- snprintf (err_str, sizeof (err_str), "Brick: %s:%s, %s"
- " one of the bricks contain the other",
- tmpbrkinfo->hostname, tmpbrkinfo->path, brick);
- goto out;
- }
+
list_add_tail (&brickinfo->brick_list, &tmpvolinfo.bricks);
brickinfo = NULL;
}
@@ -701,7 +689,7 @@ glusterd_op_stage_create_volume (dict_t *dict, char **op_errstr)
goto out;
}
- ret = glusterd_brickinfo_from_brick (brick, &brick_info);
+ ret = glusterd_brickinfo_new_from_brick (brick, &brick_info);
if (ret)
goto out;
snprintf (cmd_str, 1024, "%s", brick_info->path);
@@ -1396,7 +1384,7 @@ glusterd_op_create_volume (dict_t *dict, char **op_errstr)
brick = strtok_r (brick_list+1, " \n", &saveptr);
while ( i <= count) {
- ret = glusterd_brickinfo_from_brick (brick, &brickinfo);
+ ret = glusterd_brickinfo_new_from_brick (brick, &brickinfo);
if (ret)
goto out;