summaryrefslogtreecommitdiffstats
path: root/glusterfsd/src/glusterfsd.c
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2011-05-15 04:52:33 +0000
committerAnand Avati <avati@gluster.com>2011-05-19 15:41:47 -0700
commitc5d781e05599e9e7ad736d42c9c1033992c76ded (patch)
treeaff88649bc98a6c8babc3d75760fae2ef36b4cc3 /glusterfsd/src/glusterfsd.c
parent357df32e16dd21e7aedb699c7bd99cac9b95a040 (diff)
upon daemonizing, wait on mtab update to terminate in parent
This fixes the race in between the mtab update attempts of mount and umount when we do a lazy umount right after mounting, in order to hide the given fs instance; yet this way we still avoid the deadlock of the fs and mount which we can hit if we wait unconditionally for the mtab update to terminate (cf. bz #511). Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Anand Avati <avati@gluster.com> BUG: 2690 (race between mtab updates of mount and umount) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2690
Diffstat (limited to 'glusterfsd/src/glusterfsd.c')
-rw-r--r--glusterfsd/src/glusterfsd.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
index 9406d74ac63..2d2024409ee 100644
--- a/glusterfsd/src/glusterfsd.c
+++ b/glusterfsd/src/glusterfsd.c
@@ -25,6 +25,7 @@
#include <sys/types.h>
#include <sys/resource.h>
#include <sys/file.h>
+#include <sys/wait.h>
#include <netdb.h>
#include <signal.h>
#include <libgen.h>
@@ -75,11 +76,7 @@
#include <fnmatch.h>
#include "rpc-clnt.h"
-#ifdef GF_DARWIN_HOST_OS
#include "daemon.h"
-#else
-#define os_daemon(u, v) daemon (u, v)
-#endif
/* using argp for command line parsing */
@@ -315,6 +312,16 @@ create_fuse_mount (glusterfs_ctx_t *ctx)
break;
}
+ if (!cmd_args->no_daemon_mode) {
+ ret = dict_set_static_ptr (master->options, "sync-mtab",
+ "enable");
+ if (ret < 0) {
+ gf_log ("glusterfsd", GF_LOG_ERROR,
+ "failed to set dict value for key sync-mtab");
+ goto err;
+ }
+ }
+
ret = xlator_init (master);
if (ret) {
gf_log ("", GF_LOG_DEBUG, "failed to initialize fuse translator");
@@ -1310,6 +1317,7 @@ daemonize (glusterfs_ctx_t *ctx)
{
int ret = -1;
cmd_args_t *cmd_args = NULL;
+ int cstatus = 0;
cmd_args = &ctx->cmd_args;
@@ -1323,11 +1331,24 @@ daemonize (glusterfs_ctx_t *ctx)
if (cmd_args->debug_mode)
goto postfork;
- ret = os_daemon (0, 0);
- if (ret == -1) {
+ ret = os_daemon_return (0, 0);
+ switch (ret) {
+ case -1:
gf_log ("daemonize", GF_LOG_ERROR,
"Daemonization failed: %s", strerror(errno));
goto out;
+ case 0:
+ break;
+ default:
+ if (ctx->mtab_pid > 0) {
+ ret = waitpid (ctx->mtab_pid, &cstatus, 0);
+ if (!(ret == ctx->mtab_pid && cstatus == 0)) {
+ gf_log ("daemonize", GF_LOG_ERROR,
+ "/etc/mtab update failed");
+ exit (1);
+ }
+ }
+ _exit (0);
}
postfork: