nfsd_max_blksize is module-scope, but /proc/fs/nfsd/max_block_size is a
per-netns file. A container writing it therefore changes the payload size
that every other namespace's next server start will use.
Move it into struct nfsd_net as ->max_blksize. The lazy
nfsd_get_default_max_blksize() fill-in now happens per namespace on first
nfsd_create_serv().
User-visible change: max_block_size no longer leaks across namespaces.
Fixes: 11f779421a39 ("nfsd: containerize NFSd filesystem")
Assisted-by: LLM
Signed-off-by: Jeff Layton <[email protected]>
---
fs/nfsd/netns.h | 6 ++++++
fs/nfsd/nfsctl.c | 8 +++-----
fs/nfsd/nfsd.h | 2 --
fs/nfsd/nfssvc.c | 6 +++---
4 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/fs/nfsd/netns.h b/fs/nfsd/netns.h
index 0ce7da20aba3..374ce83e2ba0 100644
--- a/fs/nfsd/netns.h
+++ b/fs/nfsd/netns.h
@@ -154,6 +154,12 @@ struct nfsd_net {
*/
unsigned int min_threads;
+ /*
+ * Maximum size of an NFS READ or WRITE payload. Zero until the
+ * first server start in this namespace picks a default.
+ */
+ unsigned int max_blksize;
+
u32 clientid_base;
u32 clientid_counter;
u32 clverifier_counter;
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index f32311f2d7cf..330d0f12e199 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -885,8 +885,6 @@ static ssize_t write_ports(struct file *file, char *buf,
size_t size)
}
-int nfsd_max_blksize;
-
/*
* write_maxblksize - Set or report the current NFS blksize
*
@@ -931,12 +929,12 @@ static ssize_t write_maxblksize(struct file *file, char
*buf, size_t size)
mutex_unlock(&nfsd_mutex);
return -EBUSY;
}
- nfsd_max_blksize = bsize;
+ nn->max_blksize = bsize;
mutex_unlock(&nfsd_mutex);
}
- return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%d\n",
- nfsd_max_blksize);
+ return scnprintf(buf, SIMPLE_TRANSACTION_LIMIT, "%u\n",
+ nn->max_blksize);
}
#ifdef CONFIG_NFSD_V4
diff --git a/fs/nfsd/nfsd.h b/fs/nfsd/nfsd.h
index d1e413d21e76..0864d6d564e2 100644
--- a/fs/nfsd/nfsd.h
+++ b/fs/nfsd/nfsd.h
@@ -143,8 +143,6 @@ enum {
extern u64 nfsd_io_cache_read __read_mostly;
extern u64 nfsd_io_cache_write __read_mostly;
-extern int nfsd_max_blksize;
-
bool nfsd_v4client(struct svc_rqst *rqstp);
/*
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index d75fe1523436..77e1e6ba686d 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -630,12 +630,12 @@ int nfsd_create_serv(struct net *net, bool no_rpcbind)
init_completion(&nn->nfsd_net_free_done);
init_completion(&nn->nfsd_net_confirm_done);
- if (nfsd_max_blksize == 0)
- nfsd_max_blksize = nfsd_get_default_max_blksize();
+ if (nn->max_blksize == 0)
+ nn->max_blksize = nfsd_get_default_max_blksize();
nfsd_reset_versions(nn);
serv = svc_create_pooled(nfsd_programs, ARRAY_SIZE(nfsd_programs),
&nn->nfsd_svcstats,
- nfsd_max_blksize, nfsd);
+ nn->max_blksize, nfsd);
if (serv == NULL) {
percpu_ref_exit(&nn->nfsd_net_ref);
return -ENOMEM;
--
2.55.0