From 89de9adbf2b7d446abe9a27c8e384d205a996176 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Fri, 26 Sep 2014 02:28:15 +0200 Subject: Do not hardcode umount(8) path, emulate lazy umount 1) Use a system-dependent macro for umount(8) location instead of relying on $PATH to find it, for security and portability sake. 2) Introduce gf_umount_lazy() to replace umount -l (-l for lazy) invocations, which is only supported on Linux; On Linux behavior in unchanged. On other systems, we fork an external process (umountd) that will take care of periodically attempt to unmount, and optionally rmdir. Backport of Ia91167c0652f8ddab85136324b08f87c5ac1edd51d BUG: 1138897 Change-Id: I9d82c87e85af0dee79f2de39bc697c486b7103c8 Signed-off-by: Emmanuel Dreyfus Reviewed-on: http://review.gluster.org/8863 Tested-by: Gluster Build System Reviewed-by: Csaba Henk Reviewed-by: Vijay Bellur --- libglusterfs/src/Makefile.am | 3 ++- libglusterfs/src/compat.c | 39 +++++++++++++++++++++++++++++++++++++++ libglusterfs/src/compat.h | 15 +++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) (limited to 'libglusterfs/src') diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am index 25ee4c27a8b..318058b3195 100644 --- a/libglusterfs/src/Makefile.am +++ b/libglusterfs/src/Makefile.am @@ -4,7 +4,8 @@ libglusterfs_la_CFLAGS = -Wall $(GF_CFLAGS) $(GF_DARWIN_LIBGLUSTERFS_CFLAGS) \ libglusterfs_la_CPPFLAGS = $(GF_CPPFLAGS) -D__USE_FILE_OFFSET64 \ -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" \ -I$(top_srcdir)/rpc/rpc-lib/src/ -I$(CONTRIBDIR)/rbtree \ - -I$(CONTRIBDIR)/libexecinfo + -I$(CONTRIBDIR)/libexecinfo \ + -DSBIN_DIR=\"$(sbindir)\" libglusterfs_la_LIBADD = @LEXLIB@ libglusterfs_la_LDFLAGS = -version-info $(LIBGLUSTERFS_LT_VERSION) diff --git a/libglusterfs/src/compat.c b/libglusterfs/src/compat.c index eb6d8d4b7f1..93e7b45a69e 100644 --- a/libglusterfs/src/compat.c +++ b/libglusterfs/src/compat.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -28,6 +29,7 @@ #include "common-utils.h" #include "iatt.h" #include "inode.h" +#include "run.h" #ifdef GF_SOLARIS_HOST_OS int @@ -543,3 +545,40 @@ strnlen(const char *string, size_t maxlen) return len; } #endif /* STRNLEN */ + +int +gf_umount_lazy (char *xlname, char *path, int rmdir_flag) +{ + int ret = -1; + runner_t runner = {0,}; + + runinit (&runner); +#ifdef GF_LINUX_HOST_OS + runner_add_args (&runner, _PATH_UMOUNT, "-l", path, NULL); +#else + if (rmdir_flag) + runner_add_args (&runner, SBIN_DIR "/umountd", + "-r", path, NULL); + else + runner_add_args (&runner, SBIN_DIR "/umountd", + path, NULL); +#endif + ret = runner_run (&runner); + if (ret) { + gf_log (xlname, GF_LOG_ERROR, + "Lazy unmount of %s failed: %s", + path, strerror (errno)); + } + +#ifdef GF_LINUX_HOST_OS + if (!ret && rmdir_flag) { + ret = rmdir (path); + if (ret) + gf_log (xlname, GF_LOG_WARNING, + "rmdir %s failed: %s", + path, strerror (errno)); + } +#endif + + return ret; +} diff --git a/libglusterfs/src/compat.h b/libglusterfs/src/compat.h index 5920fce992b..20d15c44e70 100644 --- a/libglusterfs/src/compat.h +++ b/libglusterfs/src/compat.h @@ -40,6 +40,10 @@ #ifdef HAVE_ENDIAN_H #include #endif + +#ifndef _PATH_UMOUNT +#define _PATH_UMOUNT "/bin/umount" +#endif #endif /* GF_LINUX_HOST_OS */ #ifdef HAVE_XATTR_H @@ -161,6 +165,9 @@ enum { #define FALLOC_FL_KEEP_SIZE 0x01 /* default is extend size */ #define FALLOC_FL_PUNCH_HOLE 0x02 /* de-allocates range */ +#ifndef _PATH_UMOUNT + #define _PATH_UMOUNT "/sbin/umount" +#endif #endif /* GF_BSD_HOST_OS */ #ifdef GF_DARWIN_HOST_OS @@ -239,6 +246,9 @@ int32_t gf_darwin_compat_listxattr (int len, dict_t *dict, int size); int32_t gf_darwin_compat_getxattr (const char *key, dict_t *dict); int32_t gf_darwin_compat_setxattr (dict_t *dict); +#ifndef _PATH_UMOUNT + #define _PATH_UMOUNT "/sbin/umount" +#endif #endif /* GF_DARWIN_HOST_OS */ #ifdef GF_SOLARIS_HOST_OS @@ -318,6 +328,9 @@ enum { #ifndef _PATH_MOUNTED #define _PATH_MOUNTED "/etc/mtab" #endif +#ifndef _PATH_UMOUNT + #define _PATH_UMOUNT "/sbin/umount" +#endif #ifndef O_ASYNC #ifdef FASYNC @@ -464,4 +477,6 @@ int gf_mkostemp (char *tmpl, int suffixlen, int flags); #pragma GCC poison system popen #endif +int gf_umount_lazy(char *xlname, char *path, int rmdir); + #endif /* __COMPAT_H__ */ -- cgit