From 473c34f895c49bf2bd327ece586d3613cd86c068 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Sun, 21 Sep 2014 13:57:47 +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. BUG: 1129939 Change-Id: Ia91167c0652f8ddab85136324b08f87c5ac1e51d Signed-off-by: Emmanuel Dreyfus Reviewed-on: http://review.gluster.org/8649 Tested-by: Gluster Build System Reviewed-by: Csaba Henk Reviewed-by: Vijay Bellur --- libglusterfs/src/compat.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'libglusterfs/src/compat.c') 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; +} -- cgit