summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-rebalance.c
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-05-26 03:32:27 +0000
committerAnand Avati <avati@gluster.com>2011-05-26 08:55:22 -0700
commit9072b817b0803f999081c6244b18a9ae8fb0234c (patch)
tree919d47d2ea6d42975dac3dd9293f925d6e7849e6 /xlators/mgmt/glusterd/src/glusterd-rebalance.c
parent302ad26982d1eb7762e743e14dda627ffb317379 (diff)
reimplement invocation of external programs with run API
Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2562 (invoke external commands precisely with fork + exec) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2562
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-rebalance.c')
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-rebalance.c47
1 files changed, 26 insertions, 21 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-rebalance.c b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
index fec0a1b2e19..ee778d21534 100644
--- a/xlators/mgmt/glusterd/src/glusterd-rebalance.c
+++ b/xlators/mgmt/glusterd/src/glusterd-rebalance.c
@@ -36,6 +36,7 @@
#include "glusterd-op-sm.h"
#include "glusterd-utils.h"
#include "glusterd-store.h"
+#include "run.h"
#include "syscall.h"
#include "cli1.h"
@@ -264,7 +265,6 @@ glusterd_defrag_start (void *data)
{
glusterd_volinfo_t *volinfo = data;
glusterd_defrag_info_t *defrag = NULL;
- char cmd_str[1024] = {0,};
int ret = -1;
struct stat stbuf = {0,};
char value[128] = {0,};
@@ -339,8 +339,7 @@ out:
gf_log ("rebalance", GF_LOG_INFO, "rebalance on %s complete",
defrag->mount);
- snprintf (cmd_str, 1024, "umount -l %s", defrag->mount);
- ret = system (cmd_str);
+ ret = runcmd ("umount", "-l", defrag->mount, NULL);
LOCK_DESTROY (&defrag->lock);
GF_FREE (defrag);
}
@@ -527,7 +526,7 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr,
{
int ret = -1;
glusterd_defrag_info_t *defrag = NULL;
- char cmd_str[4096] = {0,};
+ runner_t runner = {0,};
glusterd_conf_t *priv = NULL;
priv = THIS->private;
@@ -552,35 +551,41 @@ glusterd_handle_defrag_start (glusterd_volinfo_t *volinfo, char *op_errstr,
snprintf (defrag->mount, 1024, "%s/mount/%s",
priv->workdir, volinfo->volname);
/* Create a directory, mount glusterfs over it, start glusterfs-defrag */
- snprintf (cmd_str, sizeof (cmd_str), "mkdir -p %s", defrag->mount);
- ret = system (cmd_str);
-
+ runinit (&runner);
+ runner_add_args (&runner, "mkdir", "-p", defrag->mount, NULL);
+ ret = runner_run_reuse (&runner);
if (ret) {
- gf_log("glusterd", GF_LOG_DEBUG, "command: %s failed", cmd_str);
+ runner_log (&runner, "glusterd", GF_LOG_DEBUG, "command failed");
+ runner_end (&runner);
goto out;
}
-
- snprintf (cmd_str, sizeof (cmd_str),
- "%s/sbin/glusterfs -s localhost --volfile-id %s "
- "--xlator-option *dht.use-readdirp=yes "
- "--xlator-option *dht.lookup-unhashed=yes %s",
- GFS_PREFIX, volinfo->volname,
- defrag->mount);
- ret = gf_system (cmd_str);
+ runner_end (&runner);
+
+ runinit (&runner);
+ runner_add_args (&runner, GFS_PREFIX"/sbin/glusterfs",
+ "-s", "localhost", "--volfile-id", volinfo->volname,
+ "--xlator-option", "*dht.use-readdirp=yes",
+ "--xlator-option", "*dht.lookup-unhashed=yes",
+ volinfo->volname, defrag->mount, NULL);
+ ret = runner_run_reuse (&runner);
if (ret) {
- gf_log("glusterd", GF_LOG_DEBUG, "command: %s failed", cmd_str);
+ runner_log (&runner, "glusterd", GF_LOG_DEBUG, "command failed");
+ runner_end (&runner);
goto out;
}
+ runner_end (&runner);
volinfo->defrag_status = GF_DEFRAG_STATUS_LAYOUT_FIX_STARTED;
ret = pthread_create (&defrag->th, NULL, glusterd_defrag_start,
volinfo);
if (ret) {
- snprintf (cmd_str, sizeof (cmd_str), "umount -l %s", defrag->mount);
- if (system (cmd_str))
- gf_log("glusterd", GF_LOG_DEBUG, "command: %s "
- "failed", cmd_str);
+ runinit (&runner);
+ runner_add_args (&runner, "umount", "-l", defrag->mount, NULL);
+ ret = runner_run_reuse (&runner);
+ if (ret)
+ runner_log (&runner, "glusterd", GF_LOG_DEBUG, "command failed");
+ runner_end (&runner);
}
out:
gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);