From c5d781e05599e9e7ad736d42c9c1033992c76ded Mon Sep 17 00:00:00 2001 From: Csaba Henk Date: Sun, 15 May 2011 04:52:33 +0000 Subject: 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 Signed-off-by: Anand Avati BUG: 2690 (race between mtab updates of mount and umount) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2690 --- glusterfsd/src/Makefile.am | 10 ++-------- glusterfsd/src/glusterfsd.c | 33 +++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) (limited to 'glusterfsd') diff --git a/glusterfsd/src/Makefile.am b/glusterfsd/src/Makefile.am index 537eda0bbdd..2056ca89806 100644 --- a/glusterfsd/src/Makefile.am +++ b/glusterfsd/src/Makefile.am @@ -1,9 +1,6 @@ sbin_PROGRAMS = glusterfsd -glusterfsd_SOURCES = glusterfsd.c glusterfsd-mgmt.c -if GF_DARWIN_HOST_OS -glusterfsd_SOURCES += $(CONTRIBDIR)/apple/daemon.c -endif +glusterfsd_SOURCES = glusterfsd.c glusterfsd-mgmt.c $(CONTRIBDIR)/apple/daemon.c glusterfsd_LDADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(top_builddir)/rpc/rpc-lib/src/libgfrpc.la \ $(top_builddir)/rpc/xdr/src/libgfxdr.la \ @@ -14,10 +11,7 @@ noinst_HEADERS = glusterfsd.h glusterfsd-mem-types.h AM_CFLAGS = -fPIC -Wall -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D$(GF_HOST_OS)\ -I$(top_srcdir)/libglusterfs/src -DDATADIR=\"$(localstatedir)\" \ -DCONFDIR=\"$(sysconfdir)/glusterfs\" $(GF_GLUSTERFS_CFLAGS) \ - -I$(top_srcdir)/rpc/rpc-lib/src -I$(top_srcdir)/rpc/xdr/src -if GF_DARWIN_HOST_OS -AM_CFLAGS += -I$(CONTRIBDIR)/apple -endif + -I$(top_srcdir)/rpc/rpc-lib/src -I$(top_srcdir)/rpc/xdr/src -I$(CONTRIBDIR)/apple CLEANFILES = 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 #include #include +#include #include #include #include @@ -75,11 +76,7 @@ #include #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: -- cgit