From: Rob Landley This is not a complete fix, but this lets you mount an NFSv3 server via UDP from a container. So, I set up duplicate 10.0.2.15 addresses, the first is eth0 on the KVM system, the second is an alias for loopback on the host. This means that only the container can see the host's 10.0.2.15, the host gets its local interface for that address. On the host I did: unfsd -d -s -p -e $(pwd)/export -l 10.0.2.15 -m 9999 -n 9999 In the container I did: mkdir nfsdir mount -t nfs -o ro,port=9999,mountport=9999,nolock,nfsvers=3,udp \ 10.0.2.15:/home/landley/nfs/unfs3-0.9.22/doc nfsdir ls -l nfsdir umount nfsdir And it mounted and listed the directory contents. Note: if you try to mount from the same server in both the host and the container, the darn superblock merging in the cache screws stuff up, I still need to fix that. It gets cached for several minutes before timing out. I'm working to confirm that get_sb() is never called from anything other than mount's process context (NO OTHER FILESYSTEM EVER USES THIS HOOK!), but the rpc code is already doing the get_net() and put_net() reference counting for lifetimes. (Except for the bits where I still have to fix the cacheing.) Signed-off-by: Rob Landley --- fs/nfs/client.c | 3 ++- fs/nfs/mount_clnt.c | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 192f2f8..4fb94e9 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -619,7 +620,7 @@ static int nfs_create_rpc_client(struct nfs_client *clp, { struct rpc_clnt *clnt = NULL; struct rpc_create_args args = { - .net = &init_net, + .net = current->nsproxy->net_ns, .protocol = clp->cl_proto, .address = (struct sockaddr *)&clp->cl_addr, .addrsize = clp->cl_addrlen, diff --git a/fs/nfs/mount_clnt.c b/fs/nfs/mount_clnt.c index d4c2d6b..5564f64 100644 --- a/fs/nfs/mount_clnt.c +++ b/fs/nfs/mount_clnt.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "internal.h" #ifdef RPC_DEBUG @@ -140,6 +141,8 @@ struct mnt_fhstatus { * @info: pointer to mount request arguments * * Uses default timeout parameters specified by underlying transport. + * + * This is always called from process context. */ int nfs_mount(struct nfs_mount_request *info) { @@ -153,7 +156,7 @@ int nfs_mount(struct nfs_mount_request *info) .rpc_resp = &result, }; struct rpc_create_args args = { - .net = &init_net, + .net = current->nsproxy->net_ns, .protocol = info->protocol, .address = info->sap, .addrsize = info->salen, @@ -225,7 +228,7 @@ void nfs_umount(const struct nfs_mount_request *info) .to_retries = 2, }; struct rpc_create_args args = { - .net = &init_net, + .net = current->nsproxy->net_ns, .protocol = IPPROTO_UDP, .address = info->sap, .addrsize = info->salen,