All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steve Dickson <SteveD@redhat.com>
To: linux-nfs@vger.kernel.org
Subject: Re: [PATCH] Get normalized paths for comparing NFS export paths
Date: Sat, 03 Mar 2012 12:39:13 -0500	[thread overview]
Message-ID: <4F525741.2060404@RedHat.com> (raw)
In-Reply-To: <20120302220108.GA17119@us.ibm.com>



On 03/02/2012 05:01 PM, Malahal Naineni wrote:
> Steve Dickson [SteveD@redhat.com] wrote:
>> So what my patch does is "normalizes" the device name early
>> on in main, so the correct name used used through the mount
>> and when its written the mtab. Plus, for better or worses, 
>> since the new device name will always be shorter, I just 
>> reuse/rewrite the memory allocated for the argv vector.. 
>> Meaning there is no allocation... 
> 
> My problem is a bit different.
> 
> "mount -t nfs4 server:export /mnt" works but umount fails.
> 
> Notice that there is no '/' in the path!
> 
> Normalizing or just stripping leading '/'s early won't help with the
> above problem and since there is already a hack to strip the
> __trailing__ '/' that kernel adds to /proc/mounts file, I just made the
> existing hack it a bit better by normalizing.
>
How about something like this... It takes on both case early on...

Author: Steve Dickson <steved@redhat.com>
Date:   Sat Mar 3 12:31:23 2012 -0500

    mount.nfs: Validate device name syntax
    
    To ensure the device name is found at unmount time strip
    off the multiple '/' or add a '/' if one does not exist.
    
    Signed-off-by: Steve Dickson <steved@redhat.com>

diff --git a/utils/mount/mount.c b/utils/mount/mount.c
index eea00af..7b9ba8b 100644
--- a/utils/mount/mount.c
+++ b/utils/mount/mount.c
@@ -344,6 +344,52 @@ static void parse_opts(const char *options, int *flags, char **extra_opts)
 	}
 }
 
+/*
+ * To ensure the device is found at unmount time strip
+ * off the multiple '/' or add a '/' if one does not exist.
+ */
+static char *
+chk_devicename(char *spec) {
+
+	char *colen, *slash;
+
+	if (strstr(spec, "//") != NULL) {
+		if ((colen = strchr(spec, ':')) == NULL)
+			return NULL;
+
+		slash = (colen + 1);
+		while (*slash && *(slash+1) == '/')
+			slash++;
+		while (*slash)
+			*(++colen) = *(slash++);
+		*(colen+1) = '\0';
+
+		return spec;
+	} 
+
+	if (strchr(spec, '/') == NULL) {
+		char *colen, *ptr, *str, *dev;
+		
+		if ((colen = strchr(spec, ':')) == NULL)
+			return NULL;
+
+		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';
+		spec = dev;
+	}
+
+	return spec;
+}
+
 static int try_mount(char *spec, char *mount_point, int flags,
 			char *fs_type, char **extra_opts, char *mount_opts,
 			int fake, int bg)
@@ -445,6 +491,15 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	/*
+	 * Validate the device name syntax
+	 */
+	if ((spec = chk_devicename(argv[1])) == NULL) {
+		nfs_error(_("%s: %s - Invalid device name syntax"),
+			progname, argv[1]);
+		goto out_usage;
+	}
+
 	if (strcmp(progname, "mount.nfs4") == 0)
 		fs_type = "nfs4";
 

  reply	other threads:[~2012-03-03 17:39 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-03  1:42 [PATCH] Check for beginning '/' in the mount path Malahal Naineni
2012-02-03 11:15 ` Boaz Harrosh
2012-02-03 12:16   ` NeilBrown
2012-02-03 14:29     ` Malahal Naineni
2012-02-05 11:03       ` Boaz Harrosh
2012-02-06 18:11         ` Malahal Naineni
2012-02-07 20:44         ` [PATCH] Get normalized paths for comparing NFS export paths Malahal Naineni
2012-02-16 18:09           ` Malahal Naineni
2012-03-02 19:10           ` Steve Dickson
2012-03-02 19:27             ` Malahal Naineni
2012-03-02 20:57               ` Steve Dickson
2012-03-02 22:01                 ` Malahal Naineni
2012-03-03 17:39                   ` Steve Dickson [this message]
2012-03-03 19:12                     ` Myklebust, Trond
2012-03-04 22:31                       ` Steve Dickson
2012-03-04 22:46                         ` Myklebust, Trond
2012-03-04 23:08                           ` Steve Dickson
2012-03-05  4:46                           ` Malahal Naineni
2012-03-05 12:03                             ` Steve Dickson
2012-03-04 22:58                         ` Steve Dickson
2012-03-04 23:26                           ` Myklebust, Trond
2012-03-05  0:03                             ` Steve Dickson
2012-03-05  2:04                               ` Myklebust, Trond
2012-03-05  4:53                                 ` Malahal Naineni
2012-03-05 11:55                                 ` Steve Dickson
2012-03-05 14:47                                   ` Malahal Naineni
2012-03-05 15:03                                     ` 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=4F525741.2060404@RedHat.com \
    --to=steved@redhat.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 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.