Skip to contentSkip to conversation

lockd: allow setting ports without setting gracetime

PATCH In review Jeff Layton 2 participants 4 messages Sep 23

Subsystems (3)
lore
Share & tools
lore

Jeff Layton

author maintainer
#0 lore raw

v2 cover lockd: allow setting ports without setting gracetime

This version fixes some selftest coverage gaps that Sashiko pointed out. The actual bugfix is unchanged.

This patchset fixes a rather silly bug that Scott pointed out to me in a meeting recently. You currently can't set the ports in lockd via the netlink interface unless you also set the gracetime. This patch makes them all properly optional.

---
Changes in v2:
- selftests: split put_ports() into put_tcp_port()/put_udp_port() helpers
- selftests: attributes_are_set_independently now also covers a UDP-only SERVER_SET
- selftests: empty_set_is_a_noop and settings_are_per_netns now set and check gracetime too
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Jeff Layton (2):
lockd: allow SERVER_SET without a gracetime attribute selftests/nfsd: add lockd netlink configuration tests

 fs/lockd/svc.c                                    |  50 ++--
 tools/testing/selftests/nfsd/.gitignore           |   1 +
 tools/testing/selftests/nfsd/Makefile             |   1 +
 tools/testing/selftests/nfsd/nfsd_lockd_netlink.c | 268 ++++++++++++++++++++++
 tools/testing/selftests/nfsd/nfsd_netlink.h       |  90 ++++++--
 5 files changed, 367 insertions(+), 43 deletions(-)

---
base-commit: cab95e6be3ba82bcf4c8be27c2eb20e55238aa41
change-id: 20260922-nfsd-testing-00c12335047d

Best regards,

Signature · 1 line
Jeff Layton <[email protected]>
author maintainer
#1 lore raw

PATCH v2 1/2 lockd: allow SERVER_SET without a gracetime attribute

lockd_nl_server_set_doit() required LOCKD_A_SERVER_GRACETIME via GENL_REQ_ATTR_CHECK(), but all three attributes are optional in lockd.yaml and each is applied independently below. The effect was that the tcp and udp ports could not be set on their own.

nfsdctl hits this: with a [lockd] section that sets "port" but no "grace-time", it sends SERVER_SET with only the two port attributes, and "nfsdctl autostart" aborts with EINVAL before configuring anything.

Drop the check, along with the now-redundant outer test for "any attribute present". The gracetime range check is unaffected.

Fixes 9a28ac1762a7 ("lockd: add netlink control interface")
Assisted-by LLM
---
 fs/lockd/svc.c | 50 ++++++++++++++++++++++----------------------------
 1 file changed, 22 insertions(+), 28 deletions(-)
fs/lockd/svc.c +22 -28
index f0e1a58c9106..8e1b1735acaf 100644
@@ -704,7 +704,8 @@ static struct svc_program	nlmsvc_program = {
  * @info: netlink metadata and command arguments
  *
  * This updates the per-net values. When updating the values in the init_net
- * namespace, also update the "legacy" global values.
+ * namespace, also update the "legacy" global values. Every attribute is
+ * optional; only the ones present in @info are changed.
  *
  * Return 0 on success or a negative errno.
  */
@@ -714,38 +715,31 @@ int lockd_nl_server_set_doit(struct sk_buff *skb, struct genl_info *info)
 	struct lockd_net *ln = net_generic(net, lockd_net_id);
 	const struct nlattr *attr;
 
-	if (GENL_REQ_ATTR_CHECK(info, LOCKD_A_SERVER_GRACETIME))
-		return -EINVAL;
+	attr = info->attrs[LOCKD_A_SERVER_GRACETIME];
+	if (attr) {
+		u32 gracetime = nla_get_u32(attr);
 
-	if (info->attrs[LOCKD_A_SERVER_GRACETIME] ||
-	    info->attrs[LOCKD_A_SERVER_TCP_PORT] ||
-	    info->attrs[LOCKD_A_SERVER_UDP_PORT]) {
-		attr = info->attrs[LOCKD_A_SERVER_GRACETIME];
-		if (attr) {
-			u32 gracetime = nla_get_u32(attr);
+		if (gracetime > nlm_grace_period_max)
+			return -EINVAL;
 
-			if (gracetime > nlm_grace_period_max)
-				return -EINVAL;
+		ln->gracetime = gracetime;
 
-			ln->gracetime = gracetime;
-
-			if (net == &init_net)
-				nlm_grace_period = gracetime;
-		}
+		if (net == &init_net)
+			nlm_grace_period = gracetime;
+	}
 
-		attr = info->attrs[LOCKD_A_SERVER_TCP_PORT];
-		if (attr) {
-			ln->tcp_port = nla_get_u16(attr);
-			if (net == &init_net)
-				nlm_tcpport = ln->tcp_port;
-		}
+	attr = info->attrs[LOCKD_A_SERVER_TCP_PORT];
+	if (attr) {
+		ln->tcp_port = nla_get_u16(attr);
+		if (net == &init_net)
+			nlm_tcpport = ln->tcp_port;
+	}
 
-		attr = info->attrs[LOCKD_A_SERVER_UDP_PORT];
-		if (attr) {
-			ln->udp_port = nla_get_u16(attr);
-			if (net == &init_net)
-				nlm_udpport = ln->udp_port;
-		}
+	attr = info->attrs[LOCKD_A_SERVER_UDP_PORT];
+	if (attr) {
+		ln->udp_port = nla_get_u16(attr);
+		if (net == &init_net)
+			nlm_udpport = ln->udp_port;
 	}
 	return 0;
 }
Signature · 1 line
2.55.0
author maintainer
#2 lore raw

PATCH v2 2/2 selftests/nfsd: add lockd netlink configuration tests

In reply to Jeff Layton

Cover LOCKD_CMD_SERVER_SET / SERVER_GET, in particular that each of the three attributes can be set on its own. Without the preceding fix, four of the eight tests fail with EINVAL -- every one that omits the grace time, which is what nfsdctl sends for a [lockd] port with no grace-time.

Also pinned down here:
- an empty SERVER_SET is a no-op, not an error
- a gracetime over nlm_grace_period_max is still rejected, and the rejected request applies none of the ports it came with
- the settings are per-netns

Everything runs under unshare(CLONE_NEWNET): the values are per-netns, and a SERVER_SET in init_net would overwrite the host's module-wide nlm_grace_period/nlm_tcpport/nlm_udpport.

nfsd_netlink.h grows genl_resolve() and *_to() request helpers that take a family id, so the plumbing can drive the lockd family too; genl_resolve_nfsd() and the existing helpers are thin wrappers and the other tests are unchanged.

Assisted-by LLM
---
 tools/testing/selftests/nfsd/.gitignore           |   1 +
 tools/testing/selftests/nfsd/Makefile             |   1 +
 tools/testing/selftests/nfsd/nfsd_lockd_netlink.c | 268 ++++++++++++++++++++++
 tools/testing/selftests/nfsd/nfsd_netlink.h       |  90 ++++++--
 4 files changed, 345 insertions(+), 15 deletions(-)
tools/testing/selftests/nfsd/.gitignore +1 -0
index 2347491c634d..7ac844d0fd57 100644
@@ -1,3 +1,4 @@
+nfsd_lockd_netlink
 nfsd_netlink_listener
 nfsd_netns_isolation
 nfsd_netns_stress
tools/testing/selftests/nfsd/Makefile +1 -0
index b29bf642c0ad..e74bb3424d45 100644
@@ -2,6 +2,7 @@
 CFLAGS += $(KHDR_INCLUDES) -Wall
 
 TEST_GEN_PROGS := nfsd_netlink_listener
+TEST_GEN_PROGS += nfsd_lockd_netlink
 TEST_GEN_PROGS += nfsd_netns_isolation
 TEST_GEN_PROGS += nfsd_netns_stress
 
tools/testing/selftests/nfsd/nfsd_lockd_netlink.c new file +268 -0

268 lines not on this page · raw message

tools/testing/selftests/nfsd/nfsd_netlink.h +75 -15

151 lines not on this page · raw message

Signature · 1 line
2.55.0
maintainer
#3 lore raw
In reply to Jeff Layton
Quoted 9 lines · Jeff Layton

This version fixes some selftest coverage gaps that Sashiko pointed out. The actual bugfix is unchanged.

This patchset fixes a rather silly bug that Scott pointed out to me in a meeting recently. You currently can't set the ports in lockd via the netlink interface unless you also set the gracetime. This patch makes them all properly optional.

[...]

Applied to nfsd-testing, thanks!

[1/2] lockd: allow SERVER_SET without a gracetime attribute

      commit: 06ed8fb285705890e83b7e199141a9f488286bb9
[2/2] selftests/nfsd: add lockd netlink configuration tests
      commit: 12dbf3be3c58e190c4173471d79ba0b19178447c

--
Chuck Lever