diff options
author | Vijay Bellur <vijay@gluster.com> | 2010-07-19 05:54:25 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-07-19 05:11:05 -0700 |
commit | a6b90707bf68fe62bf115cfb143d9df69627cb64 (patch) | |
tree | 86a98f2e31bd9ec3cdba8b05386ef2d928bc09ed /xlators/mgmt/glusterd/src/glusterd-ha.c | |
parent | 87ec1b72dac8f50f9eb4ba3b127baca19993ae94 (diff) |
Changes for volume commands
Signed-off-by: Vijay Bellur <vijay@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1161 (gluster volume start command segfaults glusterd)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1161
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-ha.c')
-rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-ha.c | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-ha.c b/xlators/mgmt/glusterd/src/glusterd-ha.c index 49e73703d..ebf6ce066 100644 --- a/xlators/mgmt/glusterd/src/glusterd-ha.c +++ b/xlators/mgmt/glusterd/src/glusterd-ha.c @@ -28,7 +28,6 @@ #include "compat.h" #include "dict.h" #include "protocol-common.h" -//#include "transport.h" #include "xlator.h" #include "logging.h" #include "timer.h" @@ -49,6 +48,7 @@ #include <sys/resource.h> #include <inttypes.h> +#include <dirent.h> int32_t glusterd_ha_create_volume (glusterd_volinfo_t *volinfo) @@ -111,31 +111,58 @@ glusterd_ha_delete_volume (glusterd_volinfo_t *volinfo) { char pathname[PATH_MAX] = {0,}; int32_t ret = -1; - char filepath[PATH_MAX] = {0,}; + glusterd_conf_t *priv = NULL; + DIR *dir = NULL; + struct dirent *entry = NULL; + char path[PATH_MAX] = {0,}; GF_ASSERT (volinfo); - snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR, - volinfo->volname); + priv = THIS->private; - snprintf (filepath, 1024, "%s/info", pathname); - ret = unlink (filepath); + GF_ASSERT (priv); + snprintf (pathname, 1024, "%s/vols/%s", priv->workdir, + volinfo->volname); - if (-1 == ret) { - gf_log ("", GF_LOG_ERROR, "unlink() failed on path %s," - "errno: %d", filepath, errno); + dir = opendir (pathname); + if (!dir) goto out; + + entry = readdir (dir); + while (entry != NULL) { + if (!strcmp (entry->d_name, ".") || + !strcmp (entry->d_name, "..")) { + entry = readdir (dir); + continue; + } + snprintf (path, PATH_MAX, "%s/%s", pathname, entry->d_name); + if (DT_DIR == entry->d_type) + ret = rmdir (path); + else + ret = unlink (path); + + gf_log ("", GF_LOG_NORMAL, "%s %s", + ret?"Failed to remove":"Removed", + entry->d_name); + if (ret) + gf_log ("", GF_LOG_NORMAL, "errno:%d", errno); + entry = readdir (dir); + memset (path, 0, sizeof(path)); } - ret = rmdir (pathname); + ret = closedir (dir); + if (ret) { + gf_log ("", GF_LOG_NORMAL, "Failed to close dir, errno:%d", + errno); + } - if (-1 == ret) { - gf_log ("", GF_LOG_ERROR, "rmdir() failed on path %s," - "errno: %d", pathname, errno); - goto out; + ret = rmdir (pathname); + if (ret) { + gf_log ("", GF_LOG_ERROR, "Failed to rmdir: %s, errno: %d", + pathname, errno); } -out: +out: gf_log ("", GF_LOG_DEBUG, "Returning %d", ret); return ret; |