summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorJunaid <junaid@gluster.com>2011-04-09 05:34:23 +0000
committerAnand Avati <avati@gluster.com>2011-04-10 23:52:24 -0700
commit0a05984fd99577a1ea5bf8d2cdddd08d9a88ba75 (patch)
treea93024829bd5c863ceaf82c1cb9c16b253454343 /cli
parent11c2526e045a5a9b168175d5fd658302a8dcb31b (diff)
cli: Cleanup the maintainence mount points used by quota.
Signed-off-by: Junaid <junaid@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2704 (Stale mount-points seen after execting quota list command) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2704
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli-rpc-ops.c69
1 files changed, 38 insertions, 31 deletions
diff --git a/cli/src/cli-rpc-ops.c b/cli/src/cli-rpc-ops.c
index 7afd38524fc..07cfdb0c867 100644
--- a/cli/src/cli-rpc-ops.c
+++ b/cli/src/cli-rpc-ops.c
@@ -32,7 +32,8 @@
#include "compat-errno.h"
#include "cli-cmd.h"
#include <sys/uio.h>
-
+#include <stdlib.h>
+#include <sys/mount.h>
#include "cli1-xdr.h"
#include "cli1.h"
#include "protocol-common.h"
@@ -1308,46 +1309,43 @@ out:
int32_t
print_limit_list (char *volname, char *limit_list)
{
- char mount [1024] = {0, };
- char cmd_str [1024] = {0, };
- char path [1024] = {0, };
- char ret_str [1024] = {0, };
- char value [1024] = {0, };
- char umount_str [1024] = {0, };
- int64_t size = 0;
- int64_t limit_value = 0;
- int32_t i, j, k, len, ret;
-
- if (volname == NULL || limit_list == NULL)
- return -1;
-
- snprintf (mount, sizeof (mount), "/etc/glusterd/mountlist/%s", volname);
-
- snprintf (cmd_str, sizeof (cmd_str), "mkdir -p %s", mount);
-
- snprintf (umount_str, sizeof (umount_str), "umount %s>>/dev/null 2>&1", mount);
- system (umount_str);
-
- ret = system (cmd_str);
- if (ret) {
+ int64_t size = 0;
+ int64_t limit_value = 0;
+ int32_t i, j, k;
+ int32_t len = 0, ret = -1;
+ char path [PATH_MAX] = {0, };
+ char ret_str [1024] = {0, };
+ char value [1024] = {0, };
+ char mountdir [] = "/tmp/mntXXXXXX";
+ char cmd_str [PATH_MAX + 1024] = {0, };
+
+ GF_VALIDATE_OR_GOTO ("cli", volname, out);
+ GF_VALIDATE_OR_GOTO ("cli", limit_list, out);
+
+ if (mkdtemp (mountdir) == NULL) {
+ gf_log ("cli", GF_LOG_WARNING, "failed to create a temporary "
+ "mount directory");
ret = -1;
goto out;
}
+ /* Mount a temporary client to fetch the disk usage
+ * of the directory on which the limit is set.
+ */
snprintf (cmd_str, sizeof (cmd_str), GFS_PREFIX "/sbin/glusterfs -s localhost "
- "--volfile-id %s %s", volname, mount);
+ "--volfile-id %s %s", volname, mountdir);
ret = system (cmd_str);
if (ret) {
+ gf_log ("cli", GF_LOG_WARNING, "failed to mount glusterfs client");
ret = -1;
- goto out;
+ goto rm_dir;
}
len = strlen (limit_list);
-
if (len == 0) {
cli_out ("quota limit not set ");
- goto out;
+ goto unmount;
}
i = 0;
@@ -1371,8 +1369,8 @@ print_limit_list (char *volname, char *limit_list)
}
value [j] = '\0';
- memset (&cmd_str, 0, 1024);
- snprintf (cmd_str, sizeof (cmd_str), "%s%s", mount, path);
+ memset (&cmd_str, 0, sizeof (cmd_str));
+ snprintf (cmd_str, sizeof (cmd_str), "%s/%s", mountdir, path);
ret = getxattr (cmd_str, "trusted.limit.list", (void *) ret_str, 4096);
if (ret < 0) {
@@ -1385,9 +1383,18 @@ print_limit_list (char *volname, char *limit_list)
}
i++;
}
-out:
- system (umount_str);
+unmount:
+ memset (&cmd_str, 0, sizeof (cmd_str));
+#if GF_LINUX_HOST_OS
+ snprintf (cmd_str, sizeof (cmd_str), "umount -l %s", mountdir);
+#else
+ snprintf (cmd_str, sizeof (cmd_str), "umount %s", mountdir);
+#endif
+ system (cmd_str);
+rm_dir:
+ rmdir (mountdir);
+out:
return ret;
}