summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRajesh Amaravathi <rajesh@redhat.com>2012-05-10 16:24:45 +0530
committerAnand Avati <avati@redhat.com>2012-05-22 00:53:12 -0700
commitfa287178ac714071ceacf8697bd36cc8a8a8da00 (patch)
tree684f2e2fc6527c8873f395704d5b799146383837
parentbb2fc0a23e46413a14baef1846a9873681d32fe2 (diff)
core: canonicalize paths
canonicalize paths during add-brick, creation of volume, setting nfs.export-dir in volgen BUG: 789870 Change-Id: I1d3788ac850359b0def0457113831e825a475d58 Signed-off-by: Rajesh Amaravathi <rajesh@redhat.com> Reviewed-on: http://review.gluster.com/3315 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
-rw-r--r--cli/src/cli-cmd-parser.c16
-rw-r--r--cli/src/cli.c64
-rw-r--r--cli/src/cli.h3
-rw-r--r--libglusterfs/src/common-utils.c52
-rw-r--r--libglusterfs/src/common-utils.h1
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c3
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c4
7 files changed, 63 insertions, 80 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 6c8d374ebc1..02eb2c36992 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -80,7 +80,7 @@ cli_cmd_bricks_parse (const char **words, int wordcount, int brick_index,
goto out;
} else {
delimiter = strrchr (words[brick_index], ':');
- ret = cli_canonicalize_path (delimiter + 1);
+ ret = gf_canonicalize_path (delimiter + 1);
if (ret)
goto out;
}
@@ -979,7 +979,7 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount,
goto out;
} else {
delimiter = strrchr(words[brick_index], ':');
- ret = cli_canonicalize_path (delimiter + 1);
+ ret = gf_canonicalize_path (delimiter + 1);
if (ret)
goto out;
}
@@ -1073,7 +1073,7 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount,
goto out;
} else {
delimiter = strrchr ((char *)words[3], ':');
- ret = cli_canonicalize_path (delimiter + 1);
+ ret = gf_canonicalize_path (delimiter + 1);
if (ret)
goto out;
}
@@ -1094,7 +1094,7 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount,
goto out;
} else {
delimiter = strrchr ((char *)words[4], ':');
- ret = cli_canonicalize_path (delimiter + 1);
+ ret = gf_canonicalize_path (delimiter + 1);
if (ret)
goto out;
}
@@ -1202,7 +1202,7 @@ cli_cmd_log_filename_parse (const char **words, int wordcount, dict_t **options)
ret = -1;
goto out;
} else {
- ret = cli_canonicalize_path (delimiter + 1);
+ ret = gf_canonicalize_path (delimiter + 1);
if (ret)
goto out;
}
@@ -1318,7 +1318,7 @@ cli_cmd_log_locate_parse (const char **words, int wordcount, dict_t **options)
ret = -1;
goto out;
} else {
- ret = cli_canonicalize_path (delimiter + 1);
+ ret = gf_canonicalize_path (delimiter + 1);
if (ret)
goto out;
}
@@ -1369,7 +1369,7 @@ cli_cmd_log_rotate_parse (const char **words, int wordcount, dict_t **options)
ret = -1;
goto out;
} else {
- ret = cli_canonicalize_path (delimiter + 1);
+ ret = gf_canonicalize_path (delimiter + 1);
if (ret)
goto out;
}
@@ -1758,7 +1758,7 @@ cli_cmd_volume_top_parse (const char **words, int wordcount,
ret = -1;
goto out;
} else {
- ret = cli_canonicalize_path (delimiter + 1);
+ ret = gf_canonicalize_path (delimiter + 1);
if (ret)
goto out;
}
diff --git a/cli/src/cli.c b/cli/src/cli.c
index 6a5ecf698c9..89b5a8bd40f 100644
--- a/cli/src/cli.c
+++ b/cli/src/cli.c
@@ -577,70 +577,6 @@ cli_local_wipe (cli_local_t *local)
return;
}
-/* If the path exists use realpath(3) to handle extra slashes and to resolve
- * symlinks else strip the extra slashes in the path and return */
-
-int
-cli_canonicalize_path (char *path)
-{
- struct stat sb = {0};
- int ret = -1;
- char *tmppath = NULL;
- char *dir = NULL;
- char *tmpstr = NULL;
- int path_len = 0;
-
- if (!path)
- return ret;
-
- ret = stat (path, &sb);
- if (ret == -1) {
- /* Strip the extra slashes and return */
- tmppath = gf_strdup (path);
- if (tmppath == NULL) {
- ret = -1;
- gf_log ("cli", GF_LOG_ERROR, "Out of memory.");
- goto out;
- }
- bzero (path, strlen(path));
- path[0] = '/';
- dir = strtok_r(tmppath, "/", &tmpstr);
- while (dir) {
- strncpy ((path + path_len + 1), dir, strlen(dir));
- path_len = strlen (path);
- dir = strtok_r(NULL, "/", &tmpstr);
- if (dir)
- strncpy((path + path_len), "/", 1);
- }
- if (path_len == 0)
- path[1] = '\0';
- else
- path[path_len] = '\0';
- ret = 0;
- goto out;
- } else {
- tmppath = gf_strdup(path);
- if (tmppath == NULL) {
- ret = -1;
- gf_log ("cli", GF_LOG_ERROR, "Out of memory.");
- goto out;
- }
- if (realpath (tmppath, path) == NULL) {
- cli_out ("Path manipulation failed: %s",
- strerror(errno));
- gf_log ("cli", GF_LOG_ERROR, "Path manipulation "
- "failed: %s", strerror(errno));
- ret = -1;
- goto out;
- }
- ret = 0;
- }
-out:
- if (tmppath)
- GF_FREE(tmppath);
- return ret;
-}
-
struct cli_state *global_state;
int
diff --git a/cli/src/cli.h b/cli/src/cli.h
index 0b769812c5d..76b92e91d47 100644
--- a/cli/src/cli.h
+++ b/cli/src/cli.h
@@ -262,9 +262,6 @@ int
cli_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
void *data);
-int
-cli_canonicalize_path (char *path);
-
int32_t
cli_cmd_volume_profile_parse (const char **words, int wordcount,
dict_t **options);
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 737487d1d72..c9c396762ab 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1953,11 +1953,6 @@ out:
* power of two is returned.
*/
-/*
- * rounds up nr to next power of two. If nr is already a power of two, next
- * power of two is returned.
- */
-
inline int32_t
gf_roundup_next_power_of_two (uint32_t nr)
{
@@ -2092,3 +2087,50 @@ gf_strip_whitespace (char *str, int len)
GF_FREE (new_str);
return new_len;
}
+
+/* If the path exists use realpath(3) to handle extra slashes and to resolve
+ * symlinks else strip the extra slashes in the path and return */
+
+int
+gf_canonicalize_path (char *path)
+{
+ int ret = -1;
+ int path_len = 0;
+ int dir_path_len = 0;
+ char *tmppath = NULL;
+ char *dir = NULL;
+ char *tmpstr = NULL;
+
+ if (!path || *path != '/')
+ goto out;
+
+ tmppath = gf_strdup (path);
+ if (!tmppath)
+ goto out;
+
+ /* Strip the extra slashes and return */
+ bzero (path, strlen(path));
+ path[0] = '/';
+ dir = strtok_r(tmppath, "/", &tmpstr);
+
+ while (dir) {
+ dir_path_len = strlen(dir);
+ strncpy ((path + path_len + 1), dir, dir_path_len);
+ path_len += dir_path_len + 1;
+ dir = strtok_r (NULL, "/", &tmpstr);
+ if (dir)
+ strncpy ((path + path_len), "/", 1);
+ }
+ path[path_len] = '\0';
+ ret = 0;
+
+ out:
+ if (ret)
+ gf_log ("common-utils", GF_LOG_ERROR,
+ "Path manipulation failed");
+
+ if (tmppath)
+ GF_FREE(tmppath);
+
+ return ret;
+}
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index b2533ae175d..9903edad456 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -486,4 +486,5 @@ char *get_path_name (char *word, char **path);
void gf_path_strip_trailing_slashes (char *path);
uint64_t get_mem_size ();
int gf_strip_whitespace (char *str, int len);
+int gf_canonicalize_path (char *path);
#endif /* _COMMON_UTILS_H */
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 1b5a58dd73d..987244e7518 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -763,7 +763,10 @@ glusterd_brickinfo_from_brick (char *brick,
GF_ASSERT (path);
ret = glusterd_brickinfo_new (&new_brickinfo);
+ if (ret)
+ goto out;
+ ret = gf_canonicalize_path (path);
if (ret)
goto out;
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c
index 4e2a40cd08c..c8ff573b10b 100644
--- a/xlators/mgmt/glusterd/src/glusterd-volgen.c
+++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c
@@ -2686,6 +2686,10 @@ nfs_option_handler (volgen_graph_t *graph,
volinfo->volname);
if (ret != -1) {
+ ret = gf_canonicalize_path (vme->value);
+ if (ret)
+ return -1;
+
ret = xlator_set_option (xl, aa, vme->value);
GF_FREE (aa);
}