linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Malahal Naineni <malahal@us.ibm.com>
To: Linux NFS Mailing list <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH 1/1] umount.nfs: normalize path names during umounts.
Date: Mon, 5 Mar 2012 15:20:15 -0600	[thread overview]
Message-ID: <20120305212015.GA21904@us.ibm.com> (raw)
In-Reply-To: <1330976165-19849-2-git-send-email-steved@redhat.com>

Steve Dickson [steved@redhat.com] wrote:
> So path names are found during umounts, normalize
> path names by removing any extra slashes and add
> a lead slash if one does not exist.
> 
> This normalization only has to occur when the mtab
> and /proc/mounts are not the same file.
> 
> Signed-off-by: Steve Dickson <steved@redhat.com>
> ---
>  utils/mount/nfsumount.c |   64 +++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 62 insertions(+), 2 deletions(-)
> 
> diff --git a/utils/mount/nfsumount.c b/utils/mount/nfsumount.c
> index 3538d88..0f77261 100644
> --- a/utils/mount/nfsumount.c
> +++ b/utils/mount/nfsumount.c
> @@ -140,6 +140,52 @@ static int del_mtab(const char *spec, const char *node)
>  }
> 
>  /*
> + * To ensure the path is found during unmounts, strip
> + * off the multiple '/' or add a '/' if one does not exist.
> + */
> +static inline char *
> +normalize_path(char *spec) 
> +{
> +	char *colen, *ptr, *str, *dev;
> +
> +	if ((colen = strchr(spec, ':')) == NULL)
> +		return NULL;
> +
> +	if (*(colen + 1) != '/') {
> +		dev = str = malloc(strlen(spec) + 2);
> +		if (dev == NULL) 
> +			return NULL;
> +
> +		ptr = spec;
> +		while (ptr <= colen)
> +			*(str++) = *(ptr++);
> +		*str++='/';
> +		while (*ptr)
> +			*(str++) = *(ptr++);
> +		*str='\0';
> +
> +		return dev;
> +	}
> +
> +	if (strstr(spec, "//") != NULL) {
> +		dev = strdup(spec);
> +		if (dev == NULL)
> +			return NULL;
> +
> +		colen = strchr(dev, ':');
> +		ptr = (colen +1);
> +		while (*ptr && *(ptr+1) == '/')
> +			ptr++;
> +		while (*ptr)
> +			*(++colen) = *(ptr++);
> +		*(colen+1) = '\0';
> +
> +		return dev;
> +	} 
> +	return NULL;
> +}
> +
> +/*
>   * Detect NFSv4 mounts.
>   *
>   * Consult /proc/mounts to determine if the mount point
> @@ -154,6 +200,7 @@ static int nfs_umount_is_vers4(const struct mntentchn *mc)
>  	struct mntentchn *pmc;
>  	struct mount_options *options;
>  	int retval;
> +	char *normpath=NULL;
> 
>  	retval = -1;
>  	pmc = getprocmntdirbackward(mc->m.mnt_dir, NULL);
> @@ -171,8 +218,20 @@ static int nfs_umount_is_vers4(const struct mntentchn *mc)
>  		 */
>  		while (pmc->m.mnt_fsname[nlen - 1] == '/')
>  			nlen--;
> -		if (strncmp(pmc->m.mnt_fsname, mc->m.mnt_fsname, nlen) != 0)
> -			continue;
> +		/*
> +		 * When the mtab and /proc/mounts are not the same
> +		 * file, normalize the path in the mtab if needed.
> +		 */
> +		if (mtab_is_writable())
> +			normpath = normalize_path(mc->m.mnt_fsname);
> +
> +		if (strncmp(pmc->m.mnt_fsname, mc->m.mnt_fsname, nlen) != 0) {
> +			/* Is there a normalized path, if so compare that one too */
> +			if (normpath == NULL)
> +				continue;
> +			if (strncmp(pmc->m.mnt_fsname, normpath, nlen) != 0)
> +				continue;

You need to free normpath here before the "continue".

Also, when you normalize, why not go the extra mile of doing it all the
way as the patch I posted? I wanted to cover specs like
"host:/server/../home/./blah". This patch only does partial
normalization. The original patch also normalizes /proc/mount entry's
pathname (this avoids dealing with trailing '/' hack that exists now).


  reply	other threads:[~2012-03-05 21:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-05 19:36 [PATCH 0/1] Normalized path names on umounts (take 2) Steve Dickson
2012-03-05 19:36 ` [PATCH 1/1] umount.nfs: normalize path names during umounts Steve Dickson
2012-03-05 21:20   ` Malahal Naineni [this message]
2012-03-05 21:30     ` Malahal Naineni
2012-03-06  0:28       ` Steve Dickson
2012-03-06  0:27     ` Steve Dickson
2012-03-06  0:31       ` Myklebust, Trond
2012-03-06  0:53         ` Steve Dickson
2012-03-06  1:04           ` Myklebust, Trond
2012-03-06  1:35             ` Steve Dickson
2012-03-06  1:52               ` Jim Rees
2012-03-06  2:25                 ` Malahal Naineni
2012-03-06  2:38                   ` Steve Dickson
2012-03-05 19:37 ` [PATCH 0/1] Normalized path names on umounts (take 2) Chuck Lever
2012-03-05 19:44   ` Steve Dickson

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=20120305212015.GA21904@us.ibm.com \
    --to=malahal@us.ibm.com \
    --cc=linux-nfs@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).