mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Chuck Lever <cel@kernel.org>, NeilBrown <neil@brown.name>,
	 Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <Dai.Ngo@oracle.com>,  Tom Talpey <tom@talpey.com>,
	Shuah Khan <shuah@kernel.org>
Cc: linux-nfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-kselftest@vger.kernel.org,
	Jeff Layton <jlayton@kernel.org>
Subject: [PATCH 2/8] nfsd: make max_blksize a per-namespace setting
Date: Mon, 21 Sep 2026 12:31:41 -0400	[thread overview]
Message-ID: <20260921-nfsd-per-net-mutex-v1-2-4a7287f6504c@kernel.org> (raw)
In-Reply-To: <20260921-nfsd-per-net-mutex-v1-0-4a7287f6504c@kernel.org>

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 <jlayton@kernel.org>
---
 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


  parent reply	other threads:[~2026-09-21 16:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 16:31 [PATCH 0/8] nfsd: reduce the scope of the nfsd_mutex Jeff Layton
2026-09-21 16:31 ` [PATCH 1/8] nfsd: clear NFSD_NET_UP before dropping the generic resource reference Jeff Layton
2026-09-21 16:31 ` Jeff Layton [this message]
2026-09-21 16:31 ` [PATCH 3/8] nfsd: move the control plane to a per-namespace mutex Jeff Layton
2026-09-21 16:31 ` [PATCH 4/8] nfsd: rename nfsd_mutex to nfsd_global_mutex Jeff Layton
2026-09-21 16:31 ` [PATCH 5/8] nfsd: give the open file cache its own mutex Jeff Layton
2026-09-22  6:37   ` NeilBrown
2026-09-22 10:18     ` Jeff Layton
2026-09-21 16:31 ` [PATCH 6/8] selftests/nfsd: factor the netlink plumbing into a shared header Jeff Layton
2026-09-21 16:31 ` [PATCH 7/8] selftests/nfsd: add cross-namespace isolation tests Jeff Layton
2026-09-21 16:31 ` [PATCH 8/8] selftests/nfsd: add a cross-namespace control-plane soak Jeff Layton
2026-09-21 18:20   ` Chuck Lever
2026-09-21 19:09     ` Jeff Layton
2026-09-22  6:39 ` [PATCH 0/8] nfsd: reduce the scope of the nfsd_mutex NeilBrown

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=20260921-nfsd-per-net-mutex-v1-2-4a7287f6504c@kernel.org \
    --to=jlayton@kernel.org \
    --cc=Dai.Ngo@oracle.com \
    --cc=cel@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=shuah@kernel.org \
    --cc=tom@talpey.com \
    /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

all inboxes | Powered by JetHome®