summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-utils.c
diff options
context:
space:
mode:
authorPranith K <pranithk@gluster.com>2010-10-12 03:08:46 +0000
committerVijay Bellur <vijay@dev.gluster.com>2010-10-12 02:39:06 -0700
commita6304aec8c366ad7853f95348aa6c73a0b873678 (patch)
treecbce6540c22e43aead754becb49407d2c3803543 /xlators/mgmt/glusterd/src/glusterd-utils.c
parent9bad9d59f0f19fe20f90c6ed80e25c7db08b3371 (diff)
mgmt/glusterd: create brick path if does not exist
Signed-off-by: Pranith Kumar K <pranithk@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 971 (dynamic volume management) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=971
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-utils.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-utils.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-utils.c b/xlators/mgmt/glusterd/src/glusterd-utils.c
index 1ce1dac27b4..f6fa6f66e92 100644
--- a/xlators/mgmt/glusterd/src/glusterd-utils.c
+++ b/xlators/mgmt/glusterd/src/glusterd-utils.c
@@ -2387,3 +2387,39 @@ glusterd_rb_check_bricks (glusterd_volinfo_t *volinfo,
}
return 0;
}
+
+int
+glusterd_brick_create_path (char *host, char *path, mode_t mode,
+ char **op_errstr)
+{
+ int ret = -1;
+ char msg[2048] = {0};
+ struct stat st_buf = {0};
+
+ ret = stat (path, &st_buf);
+ if ((!ret) && (!S_ISDIR (st_buf.st_mode))) {
+ snprintf (msg, sizeof (msg), "brick %s:%s, "
+ "path %s is not a directory", host, path, path);
+ gf_log ("", GF_LOG_ERROR, "%s", msg);
+ *op_errstr = gf_strdup (msg);
+ ret = -1;
+ goto out;
+ } else if (!ret) {
+ goto out;
+ }
+
+ ret = mkdir (path, mode);
+ if ((ret == -1) && (EEXIST != errno)) {
+ snprintf (msg, sizeof (msg), "brick: %s:%s, path "
+ "creation failed, reason: %s",
+ host, path, strerror(errno));
+ gf_log ("glusterd",GF_LOG_ERROR, "%s", msg);
+ *op_errstr = gf_strdup (msg);
+ } else {
+ ret = 0;
+ }
+
+out:
+ gf_log ("", GF_LOG_DEBUG, "returning %d", ret);
+ return ret;
+}