All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [nfs-utils] fix method to check if mounted already
@ 2018-10-25  4:15 Jianhong.Yin
  2018-10-25 15:38 ` Steve Dickson
  0 siblings, 1 reply; 3+ messages in thread
From: Jianhong.Yin @ 2018-10-25  4:15 UTC (permalink / raw)
  To: steved; +Cc: linux-nfs, Jianhong.Yin

reproducer:
'''
mkdir /expdir /mnt/nfsmp /mnt/tmpfs
echo "/expdir *(rw,no_root_squash)" >/etc/exports
service nfs restart
mount -t tmpfs tmpfs /mnt/tmpfs
mount -osharecache localhost:/expdir /mnt/nfsmp #success
mount -osharecache localhost:/expdir /mnt/nfsmp #mounted already, return 0(pass)
mount -osharecache localhost:/expdir /mnt/tmpfs #success
mount -osharecache localhost:/expdir /mnt/tmpfs #mounted already, return 0(pass)
umount /mnt/nfsmp
umount /mnt/tmpfs

mount -ocontext=system_u:object_r:xferlog_t:s0,sharecache localhost:/expdir /mnt/nfsmp
mount -ocontext=system_u:object_r:user_home_dir_t:s0,sharecache localhost:/expdir /mnt/tmpfs
[[ $? = 0 ]] && echo "***test fail: hasn't mounted, should return fail ***"
'''

Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
---
 support/include/misc.h    |  1 +
 support/misc/mountpoint.c | 26 +++++++++++++++++++++++++-
 utils/mount/stropts.c     |  4 +---
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/support/include/misc.h b/support/include/misc.h
index 06e2a0c..6a146e4 100644
--- a/support/include/misc.h
+++ b/support/include/misc.h
@@ -19,6 +19,7 @@ char *generic_make_pathname(const char *, const char *);
 _Bool generic_setup_basedir(const char *, const char *, char *, const size_t);
 
 extern int is_mountpoint(char *path);
+extern int is_mounted_already(const char *fsname, const char *dir);
 
 /* size of the file pointer buffers for rpc procfs files */
 #define RPC_CHAN_BUF_SIZE 32768
diff --git a/support/misc/mountpoint.c b/support/misc/mountpoint.c
index 9f9ce44..e21d529 100644
--- a/support/misc/mountpoint.c
+++ b/support/misc/mountpoint.c
@@ -4,8 +4,10 @@
  */
 
 #include <string.h>
-#include "xcommon.h"
 #include <sys/stat.h>
+#include <stdio.h>
+#include <mntent.h>
+#include "xcommon.h"
 #include "misc.h"
 
 int
@@ -38,3 +40,25 @@ is_mountpoint(char *path)
 	free(dotdot);
 	return rv;
 }
+
+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;
+}
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
index eed0356..0ee13bc 100644
--- a/utils/mount/stropts.c
+++ b/utils/mount/stropts.c
@@ -1079,9 +1079,7 @@ static int nfsmount_fg(struct nfsmount_info *mi)
 		if (nfs_try_mount(mi))
 			return EX_SUCCESS;
 
-#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
-		if (errno == EBUSY && is_mountpoint(mi->node))
-#pragma GCC diagnostic warning "-Wdiscarded-qualifiers"
+		if (errno == EBUSY && is_mounted_already(mi->spec, mi->node))
 			/*
 			 * EBUSY can happen when mounting a filesystem that
 			 * is already mounted or when the context= are
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] [nfs-utils] fix method to check if mounted already
  2018-10-25  4:15 [PATCH] [nfs-utils] fix method to check if mounted already Jianhong.Yin
@ 2018-10-25 15:38 ` Steve Dickson
       [not found]   ` <252a171e.6801.166ae43c6af.Coremail.yin-jianhong@163.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Steve Dickson @ 2018-10-25 15:38 UTC (permalink / raw)
  To: Jianhong.Yin; +Cc: linux-nfs

Hello,

On 10/25/18 12:15 AM, Jianhong.Yin wrote:
> reproducer:
> '''
> mkdir /expdir /mnt/nfsmp /mnt/tmpfs
> echo "/expdir *(rw,no_root_squash)" >/etc/exports
> service nfs restart
> mount -t tmpfs tmpfs /mnt/tmpfs
> mount -osharecache localhost:/expdir /mnt/nfsmp #success
> mount -osharecache localhost:/expdir /mnt/nfsmp #mounted already, return 0(pass)
> mount -osharecache localhost:/expdir /mnt/tmpfs #success
> mount -osharecache localhost:/expdir /mnt/tmpfs #mounted already, return 0(pass)
> umount /mnt/nfsmp
> umount /mnt/tmpfs
> 
> mount -ocontext=system_u:object_r:xferlog_t:s0,sharecache localhost:/expdir /mnt/nfsmp
> mount -ocontext=system_u:object_r:user_home_dir_t:s0,sharecache localhost:/expdir /mnt/tmpfs
> [[ $? = 0 ]] && echo "***test fail: hasn't mounted, should return fail ***"
> '''
> 
> Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> ---
>  support/include/misc.h    |  1 +
>  support/misc/mountpoint.c | 26 +++++++++++++++++++++++++-
>  utils/mount/stropts.c     |  4 +---
>  3 files changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/support/include/misc.h b/support/include/misc.h
> index 06e2a0c..6a146e4 100644
> --- a/support/include/misc.h
> +++ b/support/include/misc.h
> @@ -19,6 +19,7 @@ char *generic_make_pathname(const char *, const char *);
>  _Bool generic_setup_basedir(const char *, const char *, char *, const size_t);
>  
>  extern int is_mountpoint(char *path);
> +extern int is_mounted_already(const char *fsname, const char *dir);
>  
>  /* size of the file pointer buffers for rpc procfs files */
>  #define RPC_CHAN_BUF_SIZE 32768
> diff --git a/support/misc/mountpoint.c b/support/misc/mountpoint.c
> index 9f9ce44..e21d529 100644
> --- a/support/misc/mountpoint.c
> +++ b/support/misc/mountpoint.c
> @@ -4,8 +4,10 @@
>   */
>  
>  #include <string.h>
> -#include "xcommon.h"
>  #include <sys/stat.h>
> +#include <stdio.h>
> +#include <mntent.h>
> +#include "xcommon.h"
>  #include "misc.h"
>  
>  int
> @@ -38,3 +40,25 @@ is_mountpoint(char *path)
>  	free(dotdot);
>  	return rv;
>  }
> +
> +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;
> +}
This does not scale on a large machines, especially when all that
is needed is two stat()s... one on the directory and one on the 
parent directory.

> diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
> index eed0356..0ee13bc 100644
> --- a/utils/mount/stropts.c
> +++ b/utils/mount/stropts.c
> @@ -1079,9 +1079,7 @@ static int nfsmount_fg(struct nfsmount_info *mi)
>  		if (nfs_try_mount(mi))
>  			return EX_SUCCESS;
>  
> -#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
> -		if (errno == EBUSY && is_mountpoint(mi->node))
> -#pragma GCC diagnostic warning "-Wdiscarded-qualifiers"
> +		if (errno == EBUSY && is_mounted_already(mi->spec, mi->node))
>  			/*
>  			 * EBUSY can happen when mounting a filesystem that
>  			 * is already mounted or when the context= are
> 
This has been fixed with commit 2e5533976c76c1

steved.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [nfs-utils] fix method to check if mounted already
       [not found]   ` <252a171e.6801.166ae43c6af.Coremail.yin-jianhong@163.com>
@ 2018-10-26 12:07     ` Steve Dickson
  0 siblings, 0 replies; 3+ messages in thread
From: Steve Dickson @ 2018-10-26 12:07 UTC (permalink / raw)
  To: 尹剑虹; +Cc: linux-nfs



On 10/25/18 10:46 PM, 尹剑虹 wrote:
> Hi
> 
> commit 2e5533976c76c1 still test fail
> please see the reproducer.
It works for me... 

# mount -ocontext=system_u:object_r:xferlog_t:s0,sharecache localhost:/tmp /mnt/nfsmp
# mount -ocontext=system_u:object_r:user_home_dir_t:s0,sharecache localhost:/tmp /mnt/tmpfs
mount.nfs: /mnt/tmpfs is busy or already mounted

steved.
> 
> 
> 	
> 尹剑虹
> 邮箱:yin-jianhong@163.com
> 
> <https://maas.mail.163.com/dashi-web-extend/html/proSignature.html?iconUrl=https%3A%2F%2Fmail-online.nosdn.127.net%2Fqiyelogo%2FdefaultAvatar.png&name=%E5%B0%B9%E5%89%91%E8%99%B9&uid=yin-jianhong%40163.com&ftlId=1&items=%5B%22%E9%82%AE%E7%AE%B1%EF%BC%9Ayin-jianhong%40163.com%22%5D>
> 
> 签名由 网易邮箱大师 <https://mail.163.com/dashi/dlpro.html?from=mail88> 定制
> 
>         On 10/25/2018 23:38, Steve Dickson <mailto:SteveD@RedHat.com> wrote:
>         Hello,
> 
>         On 10/25/18 12:15 AM, Jianhong.Yin wrote:
>         > reproducer:
>         > '''
>         > mkdir /expdir /mnt/nfsmp /mnt/tmpfs
>         > echo "/expdir *(rw,no_root_squash)" >/etc/exports
>         > service nfs restart
>         > mount -t tmpfs tmpfs /mnt/tmpfs
>         > mount -osharecache localhost:/expdir /mnt/nfsmp #success
>         > mount -osharecache localhost:/expdir /mnt/nfsmp #mounted already, return 0(pass)
>         > mount -osharecache localhost:/expdir /mnt/tmpfs #success
>         > mount -osharecache localhost:/expdir /mnt/tmpfs #mounted already, return 0(pass)
>         > umount /mnt/nfsmp
>         > umount /mnt/tmpfs
>         >
>         > mount -ocontext=system_u:object_r:xferlog_t:s0,sharecache localhost:/expdir /mnt/nfsmp
>         > mount -ocontext=system_u:object_r:user_home_dir_t:s0,sharecache localhost:/expdir /mnt/tmpfs
>         > [[ $? = 0 ]] && echo "***test fail: hasn't mounted, should return fail ***"
>         > '''
>         >
>         > Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
>         > ---
>         >  support/include/misc.h    |  1 +
>         >  support/misc/mountpoint.c | 26 +++++++++++++++++++++++++-
>         >  utils/mount/stropts.c     |  4 +---
>         >  3 files changed, 27 insertions(+), 4 deletions(-)
>         >
>         > diff --git a/support/include/misc.h b/support/include/misc.h
>         > index 06e2a0c..6a146e4 100644
>         > --- a/support/include/misc.h
>         > +++ b/support/include/misc.h
>         > @@ -19,6 +19,7 @@ char *generic_make_pathname(const char *, const char *);
>         >  _Bool generic_setup_basedir(const char *, const char *, char *, const size_t);
>         >  
>         >  extern int is_mountpoint(char *path);
>         > +extern int is_mounted_already(const char *fsname, const char *dir);
>         >  
>         >  /* size of the file pointer buffers for rpc procfs files */
>         >  #define RPC_CHAN_BUF_SIZE 32768
>         > diff --git a/support/misc/mountpoint.c b/support/misc/mountpoint.c
>         > index 9f9ce44..e21d529 100644
>         > --- a/support/misc/mountpoint.c
>         > +++ b/support/misc/mountpoint.c
>         > @@ -4,8 +4,10 @@
>         >   */
>         >  
>         >  #include <string.h>
>         > -#include "xcommon.h"
>         >  #include <sys/stat.h>
>         > +#include <stdio.h>
>         > +#include <mntent.h>
>         > +#include "xcommon.h"
>         >  #include "misc.h"
>         >  
>         >  int
>         > @@ -38,3 +40,25 @@ is_mountpoint(char *path)
>         >       free(dotdot);
>         >       return rv;
>         >  }
>         > +
>         > +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;
>         > +}
>         This does not scale on a large machines, especially when all that
>         is needed is two stat()s... one on the directory and one on the
>         parent directory.
> 
>         > diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
>         > index eed0356..0ee13bc 100644
>         > --- a/utils/mount/stropts.c
>         > +++ b/utils/mount/stropts.c
>         > @@ -1079,9 +1079,7 @@ static int nfsmount_fg(struct nfsmount_info *mi)
>         >            if (nfs_try_mount(mi))
>         >                 return EX_SUCCESS;
>         >  
>         > -#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
>         > -          if (errno == EBUSY && is_mountpoint(mi->node))
>         > -#pragma GCC diagnostic warning "-Wdiscarded-qualifiers"
>         > +          if (errno == EBUSY && is_mounted_already(mi->spec, mi->node))
>         >                 /*
>         >                  * EBUSY can happen when mounting a filesystem that
>         >                  * is already mounted or when the context= are
>         >
>         This has been fixed with commit 2e5533976c76c1
> 
>         steved.
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-10-26 12:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-25  4:15 [PATCH] [nfs-utils] fix method to check if mounted already Jianhong.Yin
2018-10-25 15:38 ` Steve Dickson
     [not found]   ` <252a171e.6801.166ae43c6af.Coremail.yin-jianhong@163.com>
2018-10-26 12:07     ` Steve Dickson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.