Skip to contentSkip to conversation

text-based mount.nfs: Fix mounthost= processing

PATCH New Chuck Lever 1 participant 1 message Sep 11, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/19 text-based mount.nfs: Fix mounthost= processing

The nfs(5) man page shows that the mounthost= option takes a name, not an address. The kernel's text-based mount option parsing logic expects an IPv4 address.

Resolve the hostname and pass in a new mount option, 'mountaddr=', to the kernel. This is necessary because the kernel cannot itself resolve hostnames to addresses.

This will require changes in the kernel to recognize the new option.

---

 utils/mount/stropts.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
utils/mount/stropts.c +25 -0
index 3d20d39..da9c14a 100644
@@ -225,6 +225,28 @@ static int append_clientaddr_option(struct sockaddr_in *saddr,
 }
 
 /*
+ * Called to resolve the 'mounthost=' hostname and append a new
+ * option using an IPv4 address.
+ */
+static int fix_up_mounthost_opt(struct mount_options *options)
+{
+	struct sockaddr_in maddr;
+	char *mounthost, new_option[32];
+
+	mounthost = po_get(options, "mounthost");
+	if (!mounthost)
+		return 1;
+
+	if (!fill_ipv4_sockaddr(mounthost, &maddr))
+		return 0;
+
+	snprintf(new_option, sizeof(new_option) - 1,
+			"mountaddr=%s", inet_ntoa(maddr.sin_addr));
+
+	return po_append(options, new_option);
+}
+
+/*
  * nfsmount_s - Mount an NFSv2 or v3 file system using C string options
  *
  * @spec:	C string hostname:path specifying remoteshare to mount
@@ -261,6 +283,9 @@ int nfsmount_s(const char *spec, const char *node, int flags,
 	if (!append_addr_option(&saddr, options, child))
 		goto out;
 
+	if (!fix_up_mounthost_opt(options))
+		goto out;
+
 	*extra_opts = po_join(options);
 	if (!*extra_opts) {
 		nfs_error(_("%s: internal option parsing error"), progname);

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs