From 1e6780efd7320250a213eca25ee85bbf217825c4 Mon Sep 17 00:00:00 2001 From: Rajesh Amaravathi Date: Fri, 30 Sep 2011 18:05:38 +0530 Subject: glusterd: allow non-related directories with same prefix Earlier, using two directories with names like /test and /test1 failed volume creation. This patch sees that the next character is checked to be '/' to conclude that they are recursive. Eg: /test and /test2 succeed, while /test and /test/alpha does not. BUG: 3645 Change-Id: Idc90211a7a572200ed983c87c4344271f53b0132 Reviewed-on: http://review.gluster.com/544 Tested-by: Gluster Build System Reviewed-by: Jeff Darcy Reviewed-by: Amar Tumballi --- xlators/mgmt/glusterd/src/glusterd-utils.c | 43 +++++++++--------------------- 1 file changed, 13 insertions(+), 30 deletions(-) (limited to 'xlators/mgmt') diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c index 0b399da096d..1e797a88200 100644 --- a/xlators/mgmt/glusterd/src/glusterd-utils.c +++ b/xlators/mgmt/glusterd/src/glusterd-utils.c @@ -57,6 +57,7 @@ #include #include #include +#include #ifdef GF_SOLARIS_HOST_OS #include #endif @@ -716,10 +717,6 @@ glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path, glusterd_brickinfo_t *brickiter = NULL; uuid_t peer_uuid = {0}; int32_t ret = -1; - int32_t brick_path_len = 0; - int32_t path_len = 0; - int32_t smaller_path = 0; - gf_boolean_t is_path_smaller = _gf_true; if (uuid) { uuid_copy (peer_uuid, uuid); @@ -729,7 +726,6 @@ glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path, goto out; } ret = -1; - path_len = strlen (path); list_for_each_entry (brickiter, &volinfo->bricks, brick_list) { if (uuid_is_null (brickiter->uuid) && @@ -737,10 +733,6 @@ glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path, goto out; if (uuid_compare (peer_uuid, brickiter->uuid)) continue; - brick_path_len = strlen (brickiter->path); - smaller_path = min (brick_path_len, path_len); - if (smaller_path != path_len) - is_path_smaller = _gf_false; if (!strcmp (brickiter->path, path)) { gf_log (THIS->name, GF_LOG_INFO, "Found brick"); @@ -748,27 +740,18 @@ glusterd_volume_brickinfo_get (uuid_t uuid, char *hostname, char *path, if (brickinfo) *brickinfo = brickiter; break; - } else if (path_match == GF_PATH_PARTIAL && - !strncmp (brickiter->path, path, smaller_path)) { - /* GF_PATH_PARTIAL:check during create, add-brick ops */ - if (is_path_smaller == _gf_true && - brickiter->path[smaller_path] == '/') { - gf_log (THIS->name, GF_LOG_ERROR, - "given path %s lies within brick %s", - path, brickiter->path); - *brickinfo = brickiter; - ret = 0; - break; - } else if (path[smaller_path] == '/') { - gf_log (THIS->name, GF_LOG_ERROR, - "brick %s is a part of %s", - brickiter->path, path); - *brickinfo = brickiter; - ret = 0; - break; - } else { - ret = -1; - } + } + if (path_match != GF_PATH_PARTIAL) + continue; + + 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; } } -- cgit