mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH v2 11/11] nfs: parse nfsport and mount port from file system options
Date: Fri,  7 Feb 2014 22:28:13 +0100	[thread overview]
Message-ID: <1391808493-27328-11-git-send-email-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <1391808493-27328-1-git-send-email-u.kleine-koenig@pengutronix.de>

This allows to use unfs3 on the server side which doesn't integrate into
portmap/rpcbind which results in the port not being impossible to lookup
via rpc calls to the portmap program.

Use it like:

	mount -t nfs -o port=2703,mountport=2703 192.168.77.157:/root /mnt/nfs

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---

Notes:
    move parseopt_hu into a seperate file. For now compile it depending on
    CONFIG_FS_NFS.

 fs/Makefile   |  2 +-
 fs/nfs.c      | 32 +++++++++++++++++++++-----------
 fs/parseopt.c | 34 ++++++++++++++++++++++++++++++++++
 fs/parseopt.h |  1 +
 4 files changed, 57 insertions(+), 12 deletions(-)
 create mode 100644 fs/parseopt.c
 create mode 100644 fs/parseopt.h

diff --git a/fs/Makefile b/fs/Makefile
index e8347bd6705f..d3465edfa595 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -8,6 +8,6 @@ obj-y	+= fs.o
 obj-$(CONFIG_FS_UBIFS)	+= ubifs/
 obj-$(CONFIG_FS_TFTP)	+= tftp.o
 obj-$(CONFIG_FS_OMAP4_USBBOOT)	+= omap4_usbbootfs.o
-obj-$(CONFIG_FS_NFS)	+= nfs.o
+obj-$(CONFIG_FS_NFS)	+= nfs.o parseopt.o
 obj-$(CONFIG_FS_BPKFS) += bpkfs.o
 obj-$(CONFIG_FS_UIMAGEFS)	+= uimagefs.o
diff --git a/fs/nfs.c b/fs/nfs.c
index ab33c91ef0a9..046cd4d76c9a 100644
--- a/fs/nfs.c
+++ b/fs/nfs.c
@@ -36,6 +36,8 @@
 #include <sizes.h>
 #include <byteorder.h>
 
+#include "parseopt.h"
+
 #define SUNRPC_PORT     111
 
 #define PROG_PORTMAP    100000
@@ -1339,19 +1341,27 @@ static int nfs_probe(struct device_d *dev)
 	/* Need a priviliged source port */
 	net_udp_bind(npriv->con, 1000);
 
-	ret = rpc_lookup_req(npriv, PROG_MOUNT, 3);
-	if (ret < 0) {
-		printf("lookup mount port failed with %d\n", ret);
-		goto err2;
+	parseopt_hu(fsdev->options, "mountport", &npriv->mount_port);
+	if (!npriv->mount_port) {
+		ret = rpc_lookup_req(npriv, PROG_MOUNT, 3);
+		if (ret < 0) {
+			printf("lookup mount port failed with %d\n", ret);
+			goto err2;
+		}
+		npriv->mount_port = ret;
 	}
-	npriv->mount_port = ret;
-
-	ret = rpc_lookup_req(npriv, PROG_NFS, 3);
-	if (ret < 0) {
-		printf("lookup nfs port failed with %d\n", ret);
-		goto err2;
+	debug("mount port: %hu\n", npriv->mount_port);
+
+	parseopt_hu(fsdev->options, "port", &npriv->nfs_port);
+	if (!npriv->nfs_port) {
+		ret = rpc_lookup_req(npriv, PROG_NFS, 3);
+		if (ret < 0) {
+			printf("lookup nfs port failed with %d\n", ret);
+			goto err2;
+		}
+		npriv->nfs_port = ret;
 	}
-	npriv->nfs_port = ret;
+	debug("nfs port: %d\n", npriv->nfs_port);
 
 	ret = nfs_mount_req(npriv);
 	if (ret) {
diff --git a/fs/parseopt.c b/fs/parseopt.c
new file mode 100644
index 000000000000..fbe53cfb02c4
--- /dev/null
+++ b/fs/parseopt.c
@@ -0,0 +1,34 @@
+#include <common.h>
+
+#include "parseopt.h"
+
+void parseopt_hu(const char *options, const char *opt, unsigned short *val)
+{
+	const char *start;
+	size_t optlen = strlen(opt);
+	ulong v;
+	char *endp;
+
+again:
+	start = strstr(options, opt);
+
+	if (!start)
+		return;
+
+	if (start > options && start[-1] != ',') {
+		options = start;
+		goto again;
+	}
+
+	if (start[optlen] != '=') {
+		options = start;
+		goto again;
+	}
+
+	v = simple_strtoul(start + optlen + 1, &endp, 0);
+	if (v > USHORT_MAX)
+		return;
+
+	if (*endp == ',' || *endp == '\0')
+		*val = v;
+}
diff --git a/fs/parseopt.h b/fs/parseopt.h
new file mode 100644
index 000000000000..a8523b6a10ae
--- /dev/null
+++ b/fs/parseopt.h
@@ -0,0 +1 @@
+void parseopt_hu(const char *options, const char *opt, unsigned short *val);
-- 
1.8.5.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2014-02-07 21:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-07 21:28 [PATCH v2 01/11] net: net_read_uint32: assert that only 32 bit are read Uwe Kleine-König
2014-02-07 21:28 ` [PATCH v2 02/11] nfs: fix mount prog version in portmap lookup Uwe Kleine-König
2014-02-07 21:28 ` [PATCH v2 03/11] nfs: skip over stale rpc packets Uwe Kleine-König
2014-02-07 21:28 ` [PATCH v2 04/11] nfs: shorten and simplify rpc_add_credentials a bit Uwe Kleine-König
2014-02-08  6:51   ` Jean-Christophe PLAGNIOL-VILLARD
2014-02-08 15:11     ` Uwe Kleine-König
2014-02-07 21:28 ` [PATCH v2 05/11] nfs: simplify rpc_lookup_req Uwe Kleine-König
2014-02-07 21:28 ` [PATCH v2 06/11] nfs: drop an unneeded variable from nfs_do_open() Uwe Kleine-König
2014-02-07 21:28 ` [PATCH v2 07/11] net: new function net_read_uint64 Uwe Kleine-König
2014-02-07 21:28 ` [PATCH v2 08/11] net: provide alternatives to {ntoh, hton}[sl] funtions with cleaner semantics Uwe Kleine-König
2014-02-07 21:28 ` [PATCH v2 09/11] nfs: switch to nfs3 Uwe Kleine-König
2014-02-07 21:28 ` [PATCH v2 10/11] mount: support filesystem options passed via -o Uwe Kleine-König
2014-02-07 21:28 ` Uwe Kleine-König [this message]
2014-02-10  8:02 ` [PATCH v2 01/11] net: net_read_uint32: assert that only 32 bit are read Sascha Hauer

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=1391808493-27328-11-git-send-email-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@lists.infradead.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