* [PATCH] nfs: add $global.net.nfsport override
@ 2025-02-14 9:50 Ahmad Fatoum
2025-02-17 10:32 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-02-14 9:50 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] nfs: add $global.net.nfsport override
2025-02-14 9:50 [PATCH] nfs: add $global.net.nfsport override Ahmad Fatoum
@ 2025-02-17 10:32 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2025-02-17 10:32 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Fri, 14 Feb 2025 10:50:50 +0100, Ahmad Fatoum wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] nfs: add $global.net.nfsport override
https://git.pengutronix.de/cgit/barebox/commit/?id=a32e6ac4afd3 (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-17 10:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-14 9:50 [PATCH] nfs: add $global.net.nfsport override Ahmad Fatoum
2025-02-17 10:32 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox