From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] nfs: add $global.net.nfsport override
Date: Fri, 14 Feb 2025 10:50:50 +0100 [thread overview]
Message-ID: <20250214095050.2849460-1-a.fatoum@pengutronix.de> (raw)
Since commit 3ea30d9ce892 ("nfs: parse nfsport and mount port from file
system options"), it's possible to hard code the ports used for NFS,
which is especially useful when talking to a non-kernel NFS daemon
like unfsd.
Add a way to change the NFS port for the /mnt/nfs automount automount to
make this feature more accessible.
A simple one-time configuration can now look like this:
$ nv user=afa
$ nv net.server=mydevmachine
$ nv net.nfsport=2049
$ nv boot.default=/mnt/nfs
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/nfs.c | 55 ++++++++++++++++++++++++++++++++++++-------------------
1 file changed, 36 insertions(+), 19 deletions(-)
diff --git a/fs/nfs.c b/fs/nfs.c
index 9785a313d831..fb76c205db26 100644
--- a/fs/nfs.c
+++ b/fs/nfs.c
@@ -34,6 +34,7 @@
#include <byteorder.h>
#include <globalvar.h>
#include <parseopt.h>
+#include <magicvar.h>
#define SUNRPC_PORT 111
@@ -1390,6 +1391,7 @@ static const struct super_operations nfs_ops = {
};
static char *rootnfsopts;
+static int nfsport_default;
static void nfs_set_rootarg(struct nfs_priv *npriv, struct fs_device *fsdev)
{
@@ -1467,30 +1469,41 @@ static int nfs_probe(struct device *dev)
/* Need a priviliged source port */
net_udp_bind(npriv->con, 1000);
- 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;
+ if (nfsport_default == 0) {
+ 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;
+ } else {
+ npriv->manual_mount_port = 1;
}
- npriv->mount_port = ret;
- } else {
- npriv->manual_mount_port = 1;
- }
- 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;
+ 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;
+ } else {
+ npriv->manual_nfs_port = 1;
}
- npriv->nfs_port = ret;
} else {
- npriv->manual_nfs_port = 1;
+ if (nfsport_default > U16_MAX) {
+ printf("invalid NFS port: %d\n", nfsport_default);
+ return -EINVAL;
+ }
+
+ npriv->mount_port = npriv->nfs_port = nfsport_default;
+ npriv->manual_nfs_port = npriv->manual_mount_port = 1;
}
+
+ debug("mount port: %hu\n", npriv->mount_port);
debug("nfs port: %d\n", npriv->nfs_port);
ret = nfs_mount_req(npriv);
@@ -1555,7 +1568,11 @@ static int nfs_init(void)
rootnfsopts = xstrdup("v3,tcp");
globalvar_add_simple_string("linux.rootnfsopts", &rootnfsopts);
+ globalvar_add_simple_int("net.nfsport", &nfsport_default, "%d");
return register_fs_driver(&nfs_driver);
}
coredevice_initcall(nfs_init);
+
+BAREBOX_MAGICVAR(global.net.nfsport,
+ "Sets both NFS -o {port.mountport}= to the specified non-zero value");
--
2.39.5
next reply other threads:[~2025-02-14 9:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 9:50 Ahmad Fatoum [this message]
2025-02-17 10:32 ` 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=20250214095050.2849460-1-a.fatoum@pengutronix.de \
--to=a.fatoum@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