summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrishnan Parthasarathi <kp@gluster.com>2012-05-16 18:22:35 +0530
committerAnand Avati <avati@redhat.com>2012-05-21 13:46:18 -0700
commita2b7f11f279b9acc74c1a3b6d893fda7c160683d (patch)
tree756adc0753d6e6947a4e825068a5866aa91b406c
parentcfcc252514f3c3e99a3f40ca3415f77c2295a8e0 (diff)
common-utils: Simplified mkdir_p interface and put it to use.
- Simplified mkdir_p interface. - Removed mkdir_if_missing from codebase - Modified glusterd consumers of mkdir_if_missing to use mkdir_p with allow_symlinks=_gf_true. This implicitly assumes that glusterd is in 'control' of the brick path and glusterd's working dir in the sense that the symlinks (if any) in any of the above mentioned paths are under the 'storage administrator's control. Change-Id: I7383ad5cff11b123e1e0d2fe6da0c81e03c52ed2 BUG: 823132 Signed-off-by: Krishnan Parthasarathi <kp@gluster.com> Reviewed-on: http://review.gluster.com/3378 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
-rw-r--r--libglusterfs/src/common-utils.c10
-rw-r--r--libglusterfs/src/common-utils.h2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-hooks.c8
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rebalance.c2
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c41
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.h9
-rw-r--r--xlators/mgmt/glusterd/src/glusterd.c8
7 files changed, 14 insertions, 66 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 4b8807be1eb..737487d1d72 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -59,17 +59,14 @@ struct dnscache6 {
/* works similar to mkdir(1) -p.
- * @start returns the point in path from which components were created
- * @start is -1 if the entire path existed before.
*/
int
-mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks, int *start)
+mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks)
{
int i = 0;
int ret = -1;
char dir[PATH_MAX] = {0,};
struct stat stbuf = {0,};
- int created = -1;
strcpy (dir, path);
i = (dir[0] == '/')? 1: 0;
@@ -85,9 +82,6 @@ mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks, int *start)
goto out;
}
- if (ret && errno == EEXIST)
- created = i;
-
if (ret && errno == EEXIST && !allow_symlinks) {
ret = lstat (dir, &stbuf);
if (ret)
@@ -113,8 +107,6 @@ mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks, int *start)
}
ret = 0;
- if (start)
- *start = created;
out:
return ret;
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 69d57c8d431..b2533ae175d 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -393,7 +393,7 @@ memdup (const void *ptr, size_t size)
}
int
-mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks, int *start);
+mkdir_p (char *path, mode_t mode, gf_boolean_t allow_symlinks);
/*
* rounds up nr to power of two. If nr is already a power of two, just returns
* nr
diff --git a/xlators/mgmt/glusterd/src/glusterd-hooks.c b/xlators/mgmt/glusterd/src/glusterd-hooks.c
index ba428b0f359..b0c4c2638f7 100644
--- a/xlators/mgmt/glusterd/src/glusterd-hooks.c
+++ b/xlators/mgmt/glusterd/src/glusterd-hooks.c
@@ -93,7 +93,7 @@ glusterd_hooks_create_hooks_directory (char *basedir)
priv = THIS->private;
snprintf (path, sizeof (path), "%s/hooks", basedir);
- ret = mkdir_if_missing (path, NULL);
+ ret = mkdir_p (path, 0777, _gf_true);
if (ret) {
gf_log (THIS->name, GF_LOG_CRITICAL, "Unable to create %s due"
"to %s", path, strerror (errno));
@@ -101,7 +101,7 @@ glusterd_hooks_create_hooks_directory (char *basedir)
}
GLUSTERD_GET_HOOKS_DIR (version_dir, GLUSTERD_HOOK_VER, priv);
- ret = mkdir_if_missing (version_dir, NULL);
+ ret = mkdir_p (version_dir, 0777, _gf_true);
if (ret) {
gf_log (THIS->name, GF_LOG_CRITICAL, "Unable to create %s due "
"to %s", version_dir, strerror (errno));
@@ -115,7 +115,7 @@ glusterd_hooks_create_hooks_directory (char *basedir)
snprintf (path, sizeof (path), "%s/%s", version_dir,
cmd_subdir);
- ret = mkdir_if_missing (path, NULL);
+ ret = mkdir_p (path, 0777, _gf_true);
if (ret) {
gf_log (THIS->name, GF_LOG_CRITICAL,
"Unable to create %s due to %s",
@@ -127,7 +127,7 @@ glusterd_hooks_create_hooks_directory (char *basedir)
type++) {
snprintf (path, sizeof (path), "%s/%s/%s",
version_dir, cmd_subdir, type_subdir[type]);
- ret = mkdir_if_missing (path, NULL);
+ ret = mkdir_p (path, 0777, _gf_true);
if (ret) {
gf_log (THIS->name, GF_LOG_CRITICAL,
"Unable to create %s due to %s",
diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
index 686b9b36db3..8312610f5be 100644
--- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c
+++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
@@ -262,7 +262,7 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr,
glusterd_store_perform_node_state_store (volinfo);
GLUSTERD_GET_DEFRAG_DIR (defrag_path, volinfo, priv);
- ret = mkdir_p (defrag_path, 0777, 0, NULL);
+ ret = mkdir_p (defrag_path, 0777, _gf_true);
if (ret) {
gf_log (THIS->name, GF_LOG_ERROR, "Failed to create "
"directory %s", defrag_path);
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index ea0ee68e680..1b5a58dd73d 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -4474,9 +4474,8 @@ glusterd_brick_create_path (char *host, char *path, uuid_t uuid,
int ret = -1;
char msg[2048] = {0,};
gf_boolean_t in_use = _gf_false;
- gf_boolean_t created = _gf_true;
- ret = mkdir_if_missing (path, &created);
+ ret = mkdir_p (path, 0777, _gf_true);
if (ret)
goto out;
@@ -4510,8 +4509,6 @@ glusterd_brick_create_path (char *host, char *path, uuid_t uuid,
snprintf (msg, sizeof (msg), "Failed to set extended "
"attributes %s, reason: %s",
GF_XATTR_VOL_ID_KEY, strerror (errno));
- if (created)
- rmdir (path);
goto out;
}
@@ -4862,38 +4859,6 @@ glusterd_delete_all_bricks (glusterd_volinfo_t* volinfo)
return ret;
}
-/* @new should be used by caller only if ret is zero.
- * caller should set @new to 'true' by default.*/
-int
-mkdir_if_missing (char *path, gf_boolean_t *new)
-{
- struct stat st = {0,};
- int ret = 0;
- gf_boolean_t created = _gf_true;
-
- ret = mkdir (path, 0777);
- if (ret && errno != EEXIST)
- goto out;
-
- if (ret && errno == EEXIST)
- created = _gf_false;
-
- ret = stat (path, &st);
- if (ret == -1 || !S_ISDIR (st.st_mode)) {
- ret = -1;
- goto out;
- }
-
- if (new)
- *new = created;
-
-out:
- if (ret)
- gf_log ("", GF_LOG_WARNING, "Failed to create the"
- " directory %s", path);
- return ret;
-}
-
int
glusterd_start_gsync (glusterd_volinfo_t *master_vol, char *slave,
char *glusterd_uuid_str, char **op_errstr)
@@ -4921,7 +4886,7 @@ glusterd_start_gsync (glusterd_volinfo_t *master_vol, char *slave,
goto out;
snprintf (buf, PATH_MAX, "%s/"GEOREP"/%s", priv->workdir, master_vol->volname);
- ret = mkdir_if_missing (buf, NULL);
+ ret = mkdir_p (buf, 0777, _gf_true);
if (ret) {
errcode = -1;
goto out;
@@ -4929,7 +4894,7 @@ glusterd_start_gsync (glusterd_volinfo_t *master_vol, char *slave,
snprintf (buf, PATH_MAX, DEFAULT_LOG_FILE_DIRECTORY"/"GEOREP"/%s",
master_vol->volname);
- ret = mkdir_if_missing (buf, NULL);
+ ret = mkdir_p (buf, 0777, _gf_true);
if (ret) {
errcode = -1;
goto out;
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.h b/xlators/mgmt/glusterd/src/glusterd-utils.h
index d149cb9d0dd..c1b2ee9aea9 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.h
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.h
@@ -57,15 +57,6 @@ typedef struct glusterd_voldict_ctx_ {
char *val_name;
} glusterd_voldict_ctx_t;
-/* Moved the definition from gluster-utils.c avoiding
- * extern'ing in multiple places.
- * (Indeed, XXX: we'd rather need a general
- * "mkdir -p" like routine in libglusterfs)
-*/
-
-int
-mkdir_if_missing (char *path, gf_boolean_t *new);
-
int
glusterd_compare_lines (const void *a, const void *b);
diff --git a/xlators/mgmt/glusterd/src/glusterd.c b/xlators/mgmt/glusterd/src/glusterd.c
index a2c59d0de15..58890985f96 100644
--- a/xlators/mgmt/glusterd/src/glusterd.c
+++ b/xlators/mgmt/glusterd/src/glusterd.c
@@ -344,7 +344,7 @@ glusterd_crt_georep_folders (char *georepdir, glusterd_conf_t *conf)
}
snprintf (georepdir, PATH_MAX, "%s/"GEOREP, conf->workdir);
- ret = mkdir_if_missing (georepdir, NULL);
+ ret = mkdir_p (georepdir, 0777, _gf_true);
if (-1 == ret) {
gf_log ("glusterd", GF_LOG_CRITICAL,
"Unable to create "GEOREP" directory %s",
@@ -359,7 +359,7 @@ glusterd_crt_georep_folders (char *georepdir, glusterd_conf_t *conf)
georepdir);
goto out;
}
- ret = mkdir_if_missing (DEFAULT_LOG_FILE_DIRECTORY"/"GEOREP, NULL);
+ ret = mkdir_p (DEFAULT_LOG_FILE_DIRECTORY"/"GEOREP, 0777, _gf_true);
if (-1 == ret) {
gf_log ("glusterd", GF_LOG_CRITICAL,
"Unable to create "GEOREP" log directory");
@@ -373,8 +373,8 @@ glusterd_crt_georep_folders (char *georepdir, glusterd_conf_t *conf)
georepdir);
goto out;
}
- ret = mkdir_if_missing (DEFAULT_LOG_FILE_DIRECTORY"/"GEOREP"-slaves",
- NULL);
+ ret = mkdir_p (DEFAULT_LOG_FILE_DIRECTORY"/"GEOREP"-slaves", 0777,
+ _gf_true);
if (-1 == ret) {
gf_log ("glusterd", GF_LOG_CRITICAL,
"Unable to create "GEOREP" slave log directory");