fix issue: mount -osharecache failure but return 'true'
Subsystems (2)
PATCH 1/1 fix issue: mount -osharecache failure but return 'true'
From: "Jianhong.Yin" <[email protected]>
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;
--- utils/mount/stropts.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-)
utils/mount/stropts.c +24 -7
@@ -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))
Signature · 1 line
2.17.1
Quoted 6 lines · On 10/19/18 4:03 AM, [email protected] wrote:
From: "Jianhong.Yin" <[email protected]>
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!
Why should it fail? Two different mounts are being used and using -o sharecache which is the default the way...
steved.
Quoted 69 lines
according: https://patchwork.kernel.org/patch/10602607/#22234047
add functionis_mounted_already()utils/mount/stropts.c +1
-1-if (errno ==EBUSY ) +if (errno ==EBUSY &&is_mounted_already (mi->spec, mi->node))return EX_SUCCESS;Signed-off-by Jianhong Yin <[email protected]>--- utils/mount/stropts.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-)utils/mount/stropts.c +24
-7@@ -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))
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hello,
Quoted 4 lines · 尹剑虹
Hi Steved
The scenario is: these two mountings use different "context=" and sharecache option, in this case mount(2) return fail with EBUSY.
Fair enough.... I did miss the different contexts...
But we already have a routine that check mount points is_mountpoint() used my mountd. I would rather use that.
I'll resend the patch...
Thanks!!
steved.
Quoted 96 lines
Jianhong
尹剑虹
邮箱:[email protected]签名由 网易邮箱大师 <https://mail.163.com/dashi/dlpro.html?from=mail88> 定制
On 10/20/2018 01:36, Steve Dickson <mailto:[email protected]> wrote: On 10/19/18 4:03 AM, [email protected] wrote: > From: "Jianhong.Yin" <[email protected]> > > 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! Why should it fail? Two different mounts are being used and using -o sharecache which is the default the way... steved. > > 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 <[email protected]> > --- > 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)) >
----- 原始邮件 -----
Quoted 10 lines
发件人: "Steve Dickson" <[email protected]>
收件人: "尹剑虹" <[email protected]>
抄送: [email protected], [email protected]
发送时间: 星期六, 2018年 10 月 20日 下午 10:35:48
主题: Re: [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true'Hello,
Quoted 1 line · 尹剑虹
Quoted 8 lines
Quoted 4 lines
Hi Steved
The scenario is: these two mountings use different "context=" and sharecache option, in this case mount(2) return fail with EBUSY.
Fair enough.... I did miss the different contexts...
But we already have a routine that check mount points
is_mountpoint()used my mountd. I would rather use that.
Got it, good to know.
Quoted 119 lines
I'll resend the patch...
Thanks!!
steved.
Quoted 111 lines
Jianhong
尹剑虹
邮箱:[email protected]签名由 网易邮箱大师 <https://mail.163.com/dashi/dlpro.html?from=mail88> 定制
On 10/20/2018 01:36, Steve Dickson <mailto:[email protected]> wrote: On 10/19/18 4:03 AM, [email protected] wrote: > From: "Jianhong.Yin" <[email protected]> > > 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! Why should it fail? Two different mounts are being used and using -o sharecache which is the default the way... steved. > > 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 <[email protected]> > --- > 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)) >
----- 原始邮件 -----
Quoted 7 lines
发件人: "Jianhong Yin" <[email protected]>
收件人: "Steve Dickson" <[email protected]>
抄送: "尹剑虹" <[email protected]>, [email protected]
发送时间: 星期一, 2018年 10 月 22日 上午 10:56:31
主题: Re: [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true'
Quoted 20 lines
----- 原始邮件 -----
Quoted 19 lines
发件人: "Steve Dickson" <[email protected]>
收件人: "尹剑虹" <[email protected]>
抄送: [email protected], [email protected]
发送时间: 星期六, 2018年 10 月 20日 下午 10:35:48
主题: Re: [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true'Hello,
Quoted 5 lines · 尹剑虹
Hi Steved
The scenario is: these two mountings use different "context=" and sharecache option, in this case mount(2) return fail with EBUSY.
Fair enough.... I did miss the different contexts...
But we already have a routine that check mount points
is_mountpoint()used my mountd. I would rather use that.
Hi Sir
I reviewed function is_mountpoint(), seems it just check if the mountpoint is a root-fs, our goal is check if special dev has been mounted on specail path.
WDYT?
Quoted 124 lines
Got it, good to know.
Quoted 121 lines
I'll resend the patch...
Thanks!!
steved.
Quoted 113 lines
Jianhong
尹剑虹
邮箱:[email protected]签名由 网易邮箱大师 <https://mail.163.com/dashi/dlpro.html?from=mail88> 定制
On 10/20/2018 01:36, Steve Dickson <mailto:[email protected]> wrote: On 10/19/18 4:03 AM, [email protected] wrote: > From: "Jianhong.Yin" <[email protected]> > > 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! Why should it fail? Two different mounts are being used and using -o sharecache which is the default the way... steved. > > 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 <[email protected]> > --- > 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)) >
Quoted 27 lines · Jianhong Yin
----- 原始邮件 -----
Quoted 25 lines
发件人: "Jianhong Yin" <[email protected]>
收件人: "Steve Dickson" <[email protected]>
抄送: "尹剑虹" <[email protected]>, [email protected]
发送时间: 星期一, 2018年 10 月 22日 上午 10:56:31
主题: Re: [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true'----- 原始邮件 -----
Quoted 17 lines
发件人: "Steve Dickson" <[email protected]>
收件人: "尹剑虹" <[email protected]>
抄送: [email protected], [email protected]
发送时间: 星期六, 2018年 10 月 20日 下午 10:35:48
主题: Re: [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true'Hello,
Quoted 5 lines · 尹剑虹
Hi Steved
The scenario is: these two mountings use different "context=" and sharecache option, in this case mount(2) return fail with EBUSY.
Fair enough.... I did miss the different contexts...
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
But we already have a routine that check mount points
is_mountpoint()used my mountd. I would rather use that.Hi Sir
I reviewed function
is_mountpoint(), seems it just check if the mountpoint is a root-fs, our goal is check if special dev has been mounted on specail path.
No. It check to see if the directory above the path (aka /..) is on the same device (or filesystem) as path is. When the device numbers are the same, both paths are on the same filesystem. When they are not the same, the paths are on different filesystems
steved.
Quoted 127 lines
WDYT?
Quoted 124 lines
Got it, good to know.
Quoted 121 lines
I'll resend the patch...
Thanks!!
steved.
Quoted 113 lines
Jianhong
尹剑虹
邮箱:[email protected]签名由 网易邮箱大师 <https://mail.163.com/dashi/dlpro.html?from=mail88> 定制
On 10/20/2018 01:36, Steve Dickson <mailto:[email protected]> wrote: On 10/19/18 4:03 AM, [email protected] wrote: > From: "Jianhong.Yin" <[email protected]> > > 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! Why should it fail? Two different mounts are being used and using -o sharecache which is the default the way... steved. > > 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 <[email protected]> > --- > 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)) >
----- 原始邮件 -----
Quoted 42 lines
发件人: "Steve Dickson" <[email protected]>
收件人: "Jianhong Yin" <[email protected]>
抄送: "尹剑虹" <[email protected]>, [email protected]
发送时间: 星期一, 2018年 10 月 22日 下午 10:10:57
主题: Re: [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true'Quoted 33 lines · Jianhong Yin
----- 原始邮件 -----
Quoted 8 lines
发件人: "Jianhong Yin" <[email protected]>
收件人: "Steve Dickson" <[email protected]>
抄送: "尹剑虹" <[email protected]>, [email protected] 发送时间: 星期一, 2018年 10 月 22日 上午 10:56:31
主题: Re: [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true'Quoted 20 lines
----- 原始邮件 -----
Quoted 19 lines
发件人: "Steve Dickson" <[email protected]>
收件人: "尹剑虹" <[email protected]>
抄送: [email protected], [email protected]
发送时间: 星期六, 2018年 10 月 20日 下午 10:35:48
主题: Re: [PATCH] [nfs-utils] fix issue: mount -osharecache failure but return 'true'Hello,
Quoted 5 lines · 尹剑虹
Hi Steved
The scenario is: these two mountings use different "context=" and sharecache option, in this case mount(2) return fail with EBUSY.
Fair enough.... I did miss the different contexts...
But we already have a routine that check mount points
is_mountpoint()used my mountd. I would rather use that.Hi Sir
Quoted 7 lines
Quoted 3 lines
I reviewed function
is_mountpoint(), seems it just check if the mountpoint is a root-fs,
our goal is check if special dev has been mounted on specail path.No. It check to see if the directory above the path (aka /..) is on the same device (or filesystem) as path is. When the device numbers are the same, both paths are on the same filesystem. When they are not the same, the paths are on different filesystems
I know.. ah sorry I used wrong word root-fs(not top rootfs, just means mountpoint).
What I want to say is:
Two(or more) devices could be mounted on same mountpoint on Linux, only check "mi->node" is a mountpoint is not enough
we have to check if "mi->node" is a mountpoint *and* mounted on "mi->spec"
Jianhong
Quoted 132 lines
steved.
Quoted 129 lines
WDYT?
Quoted 126 lines
Got it, good to know.
Quoted 123 lines
I'll resend the patch...
Thanks!!
steved.
Quoted 115 lines
Jianhong
尹剑虹
邮箱:[email protected]签名由 网易邮箱大师 <https://mail.163.com/dashi/dlpro.html?from=mail88> 定制
On 10/20/2018 01:36, Steve Dickson <mailto:[email protected]> wrote: On 10/19/18 4:03 AM, [email protected] wrote: > From: "Jianhong.Yin" <[email protected]> > > 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! Why should it fail? Two different mounts are being used and using -o sharecache which is the default the way... steved. > > 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 <[email protected]> > --- > 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)) >