Skip to contentSkip to conversation

nfs: Enclose hostname in brackets when needed in nfs_do_root_mount

PATCH In review Jan Kara 3 participants 5 messages Sep 2, 2011 – Dec 20, 2011

Subsystems (2)
lore
Share & tools
lore

Jan Kara

author
#0 lore raw

PATCH 1/1 nfs: Enclose hostname in brackets when needed in nfs_do_root_mount

When hostname contains colon (e.g. when it is an IPv6 address) it needs to be enclosed in brackets to make parsing of NFS device string possible. Fix nfs_do_root_mount() to enclose hostname properly when needed. NFS code actually does not need this as it does not parse the string passed by nfs_do_root_mount() but the device string is exposed to userspace in /proc/mounts.

CC Josh Boyer <[email protected]>
CC Trond Myklebust <[email protected]>
---
 fs/nfs/super.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
fs/nfs/super.c +6 -2
index b961cea..42b74f8 100644
@@ -2694,11 +2694,15 @@ static struct vfsmount *nfs_do_root_mount(struct file_system_type *fs_type,
 	char *root_devname;
 	size_t len;
 
-	len = strlen(hostname) + 3;
+	len = strlen(hostname) + 5;
 	root_devname = kmalloc(len, GFP_KERNEL);
 	if (root_devname == NULL)
 		return ERR_PTR(-ENOMEM);
-	snprintf(root_devname, len, "%s:/", hostname);
+	/* Does hostname needs to be enclosed in brackets? */
+	if (strchr(hostname, ':'))
+		snprintf(root_devname, len, "[%s]:/", hostname);
+	else
+		snprintf(root_devname, len, "%s:/", hostname);
 	root_mnt = vfs_kern_mount(fs_type, flags, root_devname, data);
 	kfree(root_devname);
 	return root_mnt;
Signature · 1 line
1.7.1
#1 lore raw
Quoted 9 lines

-----Original Message-----
From: Jan Kara [mailto:[email protected]]
Sent: Friday, September 02, 2011 7:10 PM
To: Myklebust, Trond
Cc: [email protected]; Jan Kara; Josh Boyer; Myklebust, Trond
Subject: [PATCH] nfs: Enclose hostname in brackets when needed in nfs_do_root_mount

When hostname contains colon (e.g. when it is an IPv6 address) it

needs

Quoted 25 lines

to be enclosed in brackets to make parsing of NFS device string possible.
Fix nfs_do_root_mount() to enclose hostname properly when needed. NFS code
actually does not need this as it does not parse the string passed by nfs_do_root_mount() but the device string is exposed to userspace in /proc/mounts.

CC Josh Boyer <[email protected]>
CC Trond Myklebust <[email protected]>
---
 fs/nfs/super.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
fs/nfs/super.c +0 -1
index b961cea..42b74f8 100644
@@ -2694,11 +2694,15 @@ static struct vfsmount
 *nfs_do_root_mount(struct file_system_type *fs_type,
 	char *root_devname;
 	size_t len;
 
-	len = strlen(hostname) + 3;

fs/nfs/super.c static struct vfsmount · line 2706

Quoted 10 lines
fs/nfs/super.c +6 -1
+	len = strlen(hostname) + 5;
 	root_devname = kmalloc(len, GFP_KERNEL);
 	if (root_devname == NULL)
 		return ERR_PTR(-ENOMEM);
-	snprintf(root_devname, len, "%s:/", hostname);
+	/* Does hostname needs to be enclosed in brackets? */
+	if (strchr(hostname, ':'))
+		snprintf(root_devname, len, "[%s]:/", hostname);
+	else
+		snprintf(root_devname, len, "%s:/", hostname);

What if the hostname is already enclosed in brackets, as is usually the case if I enter an IPv6 address instead of a DNS name? Won't this cause it to be bracketed twice?

IOW: If I try to

	mount -t nfs [fe80::20c:29ff:fee9:83e6]:/export /mnt

won't the above end up returning a hostname of [[::20c:29ff:fee9:83e6]]?

Cheers
Trond

author
#2 lore raw
Quoted 50 lines · Trond
Quoted 9 lines

-----Original Message-----
From: Jan Kara [mailto:[email protected]]
Sent: Friday, September 02, 2011 7:10 PM
To: Myklebust, Trond
Cc: [email protected]; Jan Kara; Josh Boyer; Myklebust, Trond
Subject: [PATCH] nfs: Enclose hostname in brackets when needed in nfs_do_root_mount

When hostname contains colon (e.g. when it is an IPv6 address) it

needs

Quoted 25 lines

to be enclosed in brackets to make parsing of NFS device string possible.
Fix nfs_do_root_mount() to enclose hostname properly when needed. NFS code
actually does not need this as it does not parse the string passed by nfs_do_root_mount() but the device string is exposed to userspace in /proc/mounts.

CC Josh Boyer <[email protected]>
CC Trond Myklebust <[email protected]>
---
 fs/nfs/super.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
fs/nfs/super.c +0 -1
index b961cea..42b74f8 100644
@@ -2694,11 +2694,15 @@ static struct vfsmount
 *nfs_do_root_mount(struct file_system_type *fs_type,
 	char *root_devname;
 	size_t len;
 
-	len = strlen(hostname) + 3;

fs/nfs/super.c static struct vfsmount · line 2706

Quoted 10 lines
fs/nfs/super.c +6 -1
+	len = strlen(hostname) + 5;
 	root_devname = kmalloc(len, GFP_KERNEL);
 	if (root_devname == NULL)
 		return ERR_PTR(-ENOMEM);
-	snprintf(root_devname, len, "%s:/", hostname);
+	/* Does hostname needs to be enclosed in brackets? */
+	if (strchr(hostname, ':'))
+		snprintf(root_devname, len, "[%s]:/", hostname);
+	else
+		snprintf(root_devname, len, "%s:/", hostname);

What if the hostname is already enclosed in brackets, as is usually the case if I enter an IPv6 address instead of a DNS name? Won't this cause it to be bracketed twice?

Quoted 5 lines

IOW: If I try to

	mount -t nfs [fe80::20c:29ff:fee9:83e6]:/export /mnt

won't the above end up returning a hostname of [[::20c:29ff:fee9:83e6]]?

No it won't - I've actually verified my patch with experiment ;). The
hostname nfs_do_root_mount() gets is already without possible brackets (these have been removed when we first parsed the string passed from userspace by nfs_parse_devname() - yes, it took me some time to drill through the NFS call stack during mount to actually find out who removes the brackets from the passed hostname and who composes the device name back without them).

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
author
#3 lore raw
Quoted 55 lines · Jan Kara
Quoted 54 lines · Trond
Quoted 9 lines

-----Original Message-----
From: Jan Kara [mailto:[email protected]]
Sent: Friday, September 02, 2011 7:10 PM
To: Myklebust, Trond
Cc: [email protected]; Jan Kara; Josh Boyer; Myklebust, Trond
Subject: [PATCH] nfs: Enclose hostname in brackets when needed in nfs_do_root_mount

When hostname contains colon (e.g. when it is an IPv6 address) it

needs

Quoted 25 lines

to be enclosed in brackets to make parsing of NFS device string possible.
Fix nfs_do_root_mount() to enclose hostname properly when needed. NFS code
actually does not need this as it does not parse the string passed by nfs_do_root_mount() but the device string is exposed to userspace in /proc/mounts.

CC Josh Boyer <[email protected]>
CC Trond Myklebust <[email protected]>
---
 fs/nfs/super.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
fs/nfs/super.c +0 -1
index b961cea..42b74f8 100644
@@ -2694,11 +2694,15 @@ static struct vfsmount
 *nfs_do_root_mount(struct file_system_type *fs_type,
 	char *root_devname;
 	size_t len;
 
-	len = strlen(hostname) + 3;

fs/nfs/super.c static struct vfsmount · line 2706

Quoted 10 lines
fs/nfs/super.c +6 -1
+	len = strlen(hostname) + 5;
 	root_devname = kmalloc(len, GFP_KERNEL);
 	if (root_devname == NULL)
 		return ERR_PTR(-ENOMEM);
-	snprintf(root_devname, len, "%s:/", hostname);
+	/* Does hostname needs to be enclosed in brackets? */
+	if (strchr(hostname, ':'))
+		snprintf(root_devname, len, "[%s]:/", hostname);
+	else
+		snprintf(root_devname, len, "%s:/", hostname);

What if the hostname is already enclosed in brackets, as is usually the case if I enter an IPv6 address instead of a DNS name? Won't this cause it to be bracketed twice?

IOW: If I try to

	mount -t nfs [fe80::20c:29ff:fee9:83e6]:/export /mnt
Quoted 8 lines
Quoted 1 line

won't the above end up returning a hostname of [[::20c:29ff:fee9:83e6]]?

No it won't - I've actually verified my patch with experiment ;). The
hostname nfs_do_root_mount() gets is already without possible brackets (these have been removed when we first parsed the string passed from userspace by nfs_parse_devname() - yes, it took me some time to drill through the NFS call stack during mount to actually find out who removes the brackets from the passed hostname and who composes the device name back without them).

Ping? Trond, will you merge the patch please? I guess it got somehow
lost.

Honza

#4 lore raw
Quoted 64 lines · Jan Kara
Quoted 55 lines · Jan Kara
Quoted 54 lines · Trond
Quoted 9 lines

-----Original Message-----
From: Jan Kara [mailto:[email protected]]
Sent: Friday, September 02, 2011 7:10 PM
To: Myklebust, Trond
Cc: [email protected]; Jan Kara; Josh Boyer; Myklebust, Trond
Subject: [PATCH] nfs: Enclose hostname in brackets when needed in nfs_do_root_mount

When hostname contains colon (e.g. when it is an IPv6 address) it

needs

Quoted 25 lines

to be enclosed in brackets to make parsing of NFS device string possible.
Fix nfs_do_root_mount() to enclose hostname properly when needed. NFS code
actually does not need this as it does not parse the string passed by nfs_do_root_mount() but the device string is exposed to userspace in /proc/mounts.

CC Josh Boyer <[email protected]>
CC Trond Myklebust <[email protected]>
---
 fs/nfs/super.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
fs/nfs/super.c +0 -1
index b961cea..42b74f8 100644
@@ -2694,11 +2694,15 @@ static struct vfsmount
 *nfs_do_root_mount(struct file_system_type *fs_type,
 	char *root_devname;
 	size_t len;
 
-	len = strlen(hostname) + 3;

fs/nfs/super.c static struct vfsmount · line 2706

Quoted 10 lines
fs/nfs/super.c +6 -1
+	len = strlen(hostname) + 5;
 	root_devname = kmalloc(len, GFP_KERNEL);
 	if (root_devname == NULL)
 		return ERR_PTR(-ENOMEM);
-	snprintf(root_devname, len, "%s:/", hostname);
+	/* Does hostname needs to be enclosed in brackets? */
+	if (strchr(hostname, ':'))
+		snprintf(root_devname, len, "[%s]:/", hostname);
+	else
+		snprintf(root_devname, len, "%s:/", hostname);

What if the hostname is already enclosed in brackets, as is usually the case if I enter an IPv6 address instead of a DNS name? Won't this cause it to be bracketed twice?

IOW: If I try to

	mount -t nfs [fe80::20c:29ff:fee9:83e6]:/export /mnt
Quoted 8 lines
Quoted 1 line

won't the above end up returning a hostname of [[::20c:29ff:fee9:83e6]]?

No it won't - I've actually verified my patch with experiment ;). The
hostname nfs_do_root_mount() gets is already without possible brackets (these have been removed when we first parsed the string passed from userspace by nfs_parse_devname() - yes, it took me some time to drill through the NFS call stack during mount to actually find out who removes the brackets from the passed hostname and who composes the device name back without them).

Quoted 2 lines

Ping? Trond, will you merge the patch please? I guess it got somehow
lost.

Did this patch ever get queued up? I don't see it in Linus' tree or linux-next so I'm guessing no. Is there a reason why?

josh