From: jiyin@redhat.com
To: steved@redhat.com
Cc: linux-nfs@vger.kernel.org, "Jianhong.Yin" <yin-jianhong@163.com>
Subject: [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true'
Date: Fri, 19 Oct 2018 16:03:54 +0800 [thread overview]
Message-ID: <20181019080354.26141-1-jiyin@redhat.com> (raw)
From: "Jianhong.Yin" <yin-jianhong@163.com>
see: https://bugzilla.redhat.com/show_bug.cgi?id=1629705
mount.nfs4 -o context=system_u:object_r:user_home_dir_t:s0,sharecache $serv:$expdir $nfsmp
mount.nfs4 -o context=system_u:object_r:xferlog_t:s0,sharecache $serv:$expdir $nfsmp2
^^^ here mount fail, but return true. it confuse user!
according: https://patchwork.kernel.org/patch/10602607/#22234047
add function is_mounted_already()
- if (errno == EBUSY)
+ if (errno == EBUSY && is_mounted_already(mi->spec, mi->node))
return EX_SUCCESS;
Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
---
utils/mount/stropts.c | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
index 4d2e37e..4be7e61 100644
--- a/utils/mount/stropts.c
+++ b/utils/mount/stropts.c
@@ -48,6 +48,7 @@
#include "version.h"
#include "parse_dev.h"
#include "conffile.h"
+#include <mntent.h>
#ifndef NFS_PROGRAM
#define NFS_PROGRAM (100003)
@@ -1056,6 +1057,27 @@ static int nfs_is_permanent_error(int error)
}
}
+static int is_mounted_already(const char *fsname, const char *dir)
+{
+ struct mntent *ent;
+ FILE *fp;
+ int ret = 0;
+
+ fp = setmntent("/proc/mounts", "r");
+ if (fp == NULL) {
+ perror("[unlikely] setmntent(3) fail");
+ exit(1);
+ }
+ while (NULL != (ent = getmntent(fp))) {
+ if (!strcmp(ent->mnt_fsname, fsname) && !strcmp(ent->mnt_dir, dir)) {
+ ret = 1;
+ break;
+ }
+ }
+ endmntent(fp);
+ return ret;
+}
+
/*
* Handle "foreground" NFS mounts.
*
@@ -1078,13 +1100,8 @@ static int nfsmount_fg(struct nfsmount_info *mi)
if (nfs_try_mount(mi))
return EX_SUCCESS;
- if (errno == EBUSY)
- /* The only cause of EBUSY is if exactly the desired
- * filesystem is already mounted. That can arguably
- * be seen as success. "mount -a" tries to optimise
- * out this case but sometimes fails. Help it out
- * by pretending everything is rosy
- */
+ /* if EBUSY is caused by re-mount, ignore the error */
+ if (errno == EBUSY && is_mounted_already(mi->spec, mi->node))
return EX_SUCCESS;
if (nfs_is_permanent_error(errno))
--
2.17.1
next reply other threads:[~2018-10-19 16:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-19 8:03 jiyin [this message]
2018-10-19 17:36 ` [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true' Steve Dickson
[not found] ` <17c11e3b.5987.1668f873fb0.Coremail.yin-jianhong@163.com>
2018-10-20 14:35 ` Steve Dickson
2018-10-22 2:56 ` Jianhong Yin
2018-10-22 3:14 ` Jianhong Yin
2018-10-22 14:10 ` Steve Dickson
2018-10-23 2:40 ` Jianhong Yin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181019080354.26141-1-jiyin@redhat.com \
--to=jiyin@redhat.com \
--cc=linux-nfs@vger.kernel.org \
--cc=steved@redhat.com \
--cc=yin-jianhong@163.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox