From afb9634a98f25b83f27a95dddec55981ec0bcd2c Mon Sep 17 00:00:00 2001 From: Erez Zadok Date: Mon, 25 Jul 2005 23:49:41 +0000 Subject: [PATCH] * amd/conf.c (gopt_forced_unmounts): check Linux kernel version and alert if your version may be too old for MNT_FORCE to work (before 2.4.0) or for MNT_DETACH to work (before 2.6.0). Otherwise it may be impossible to pin down the exact kernel version in which we should enable this feature. * conf/umount/umount_linux.c (umount2_fs): if MNT_FORCE returned EBUSY, then don't try to stat(2) before MNT_DETACH because it could hang. --- ChangeLog | 12 ++++++++++++ amd/conf.c | 23 ++++++++++++++++++++++- conf/umount/umount_linux.c | 16 ++++++++++++---- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 77613b1..c182432 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-07-25 Erez Zadok + + * amd/conf.c (gopt_forced_unmounts): check Linux kernel version + and alert if your version may be too old for MNT_FORCE to work + (before 2.4.0) or for MNT_DETACH to work (before 2.6.0). + Otherwise it may be impossible to pin down the exact kernel + version in which we should enable this feature. + + * conf/umount/umount_linux.c (umount2_fs): if MNT_FORCE returned + EBUSY, then don't try to stat(2) before MNT_DETACH because it + could hang. + 2005-07-21 Erez Zadok * conf/umount/umount_linux.c (umount_fs): cleanup this function, diff --git a/amd/conf.c b/amd/conf.c index 73877c5..be7be77 100644 --- a/amd/conf.c +++ b/amd/conf.c @@ -37,7 +37,7 @@ * SUCH DAMAGE. * * - * $Id: conf.c,v 1.33 2005/07/20 03:32:30 ezk Exp $ + * $Id: conf.c,v 1.34 2005/07/25 23:49:41 ezk Exp $ * */ @@ -502,6 +502,27 @@ gopt_forced_unmounts(const char *val) fprintf(stderr, "conf: forced_unmounts unsupported on this system.\n"); return 1; #else /* defined(MNT2_GEN_OPT_DETACH) || defined(MNT2_GEN_OPT_FORCE) */ +# ifdef __linux__ + /* + * HACK ALERT: Linux has had MNT_FORCE since 2.2, but it hasn't gotten + * stable until 2.4. And it had MNT_DETACH since 2.4, but it hasn't + * gotten stable since 2.6. So alert users if they're trying to use a + * feature that may not work well on their older kernel. + */ + { + struct utsname un; + if (uname(&un) >= 0) { +# ifdef MNT2_GEN_OPT_FORCE + if (strcmp(un.release, "2.4.0") < 0) + fprintf(stderr, "warning: forced-unmounts (MNT_FORCE) may not work well before 2.4.0\n"); +# endif /* MNT2_GEN_OPT_FORCE */ +# ifdef MNT2_GEN_OPT_DETACH + if (strcmp(un.release, "2.6.0") < 0) + fprintf(stderr, "warning: lazy-unmounts (MNT_DETACH) may not work well before 2.6.0\n"); +# endif /* MNT2_GEN_OPT_DETACH */ + } + } +# endif /* __linux__ */ gopt.flags |= CFM_FORCED_UNMOUNTS; return 0; #endif /* defined(MNT2_GEN_OPT_DETACH) || defined(MNT2_GEN_OPT_FORCE) */ diff --git a/conf/umount/umount_linux.c b/conf/umount/umount_linux.c index 041b677..6ab85df 100644 --- a/conf/umount/umount_linux.c +++ b/conf/umount/umount_linux.c @@ -37,7 +37,7 @@ * SUCH DAMAGE. * * - * $Id: umount_linux.c,v 1.7 2005/07/21 05:22:47 ezk Exp $ + * $Id: umount_linux.c,v 1.8 2005/07/25 23:49:41 ezk Exp $ * */ @@ -246,9 +246,17 @@ umount2_fs(const char *mntdir, u_int unmount_flags) * only do the forced unmount if the older Amd process died. */ if (unmount_flags & AMU_UMOUNT_DETACH) { - struct stat dummy; - dlog("umount_fs: try stat() before unmount/detach"); - error = stat(mntdir, &dummy); + /* + * If I got an EBUSY from the above FORCE, then don't try to stat(), or + * it will hang. + */ + if (error < 0 && errno == EBUSY) { + error = 0; + } else { + struct stat dummy; + dlog("umount_fs: try stat() before unmount/detach"); + error = stat(mntdir, &dummy); + } if (!error || (errno == ESTALE || errno == EIO)) { if (error < 0) plog(XLOG_INFO, "unmount2_fs: trying unmount/detach of %s (%m)", -- 2.43.0