Commit 9a28ac17 authored by Jeff Layton's avatar Jeff Layton Committed by Chuck Lever
Browse files

lockd: add netlink control interface

The legacy rpc.nfsd tool will set the nlm_grace_period if the NFSv4
grace period is set. nfsdctl is missing this functionality, so add a new
netlink control interface for lockd that it can use. For now, it only
allows setting the grace period, and the tcp and udp listener ports.

lockd currently uses module parameters and sysctls for configuration, so
all of its settings are global. With this change, lockd now tracks these
values on a per-net-ns basis. It will only fall back to using the global
values if any of them are 0.

Finally, as a backward compatibility measure, if updating the nlm
settings in the init_net namespace, also update the legacy global
values to match.

Link: https://issues.redhat.com/browse/RHEL-71698


Signed-off-by: default avatarJeff Layton <jlayton@kernel.org>
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
parent fc2a169c
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)

name: lockd
protocol: genetlink
uapi-header: linux/lockd_netlink.h

doc: lockd configuration over generic netlink

attribute-sets:
  -
    name: server
    attributes:
      -
        name: gracetime
        type: u32
      -
        name: tcp-port
        type: u16
      -
        name: udp-port
        type: u16

operations:
  list:
    -
      name: server-set
      doc: set the lockd server parameters
      attribute-set: server
      flags: [ admin-perm ]
      do:
        request:
          attributes:
            - gracetime
            - tcp-port
            - udp-port
    -
      name: server-get
      doc: get the lockd server parameters
      attribute-set: server
      do:
        reply:
          attributes:
            - gracetime
            - tcp-port
            - udp-port
+1 −1
Original line number Diff line number Diff line
@@ -8,6 +8,6 @@ ccflags-y += -I$(src) # needed for trace events
obj-$(CONFIG_LOCKD) += lockd.o

lockd-y := clntlock.o clntproc.o clntxdr.o host.o svc.o svclock.o \
	   svcshare.o svcproc.o svcsubs.o mon.o trace.o xdr.o
	   svcshare.o svcproc.o svcsubs.o mon.o trace.o xdr.o netlink.o
lockd-$(CONFIG_LOCKD_V4) += clnt4xdr.o xdr4.o svc4proc.o
lockd-$(CONFIG_PROC_FS) += procfs.o

fs/lockd/netlink.c

0 → 100644
+44 −0
Original line number Diff line number Diff line
// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause)
/* Do not edit directly, auto-generated from: */
/*	Documentation/netlink/specs/lockd.yaml */
/* YNL-GEN kernel source */

#include <net/netlink.h>
#include <net/genetlink.h>

#include "netlink.h"

#include <uapi/linux/lockd_netlink.h>

/* LOCKD_CMD_SERVER_SET - do */
static const struct nla_policy lockd_server_set_nl_policy[LOCKD_A_SERVER_UDP_PORT + 1] = {
	[LOCKD_A_SERVER_GRACETIME] = { .type = NLA_U32, },
	[LOCKD_A_SERVER_TCP_PORT] = { .type = NLA_U16, },
	[LOCKD_A_SERVER_UDP_PORT] = { .type = NLA_U16, },
};

/* Ops table for lockd */
static const struct genl_split_ops lockd_nl_ops[] = {
	{
		.cmd		= LOCKD_CMD_SERVER_SET,
		.doit		= lockd_nl_server_set_doit,
		.policy		= lockd_server_set_nl_policy,
		.maxattr	= LOCKD_A_SERVER_UDP_PORT,
		.flags		= GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
	},
	{
		.cmd	= LOCKD_CMD_SERVER_GET,
		.doit	= lockd_nl_server_get_doit,
		.flags	= GENL_CMD_CAP_DO,
	},
};

struct genl_family lockd_nl_family __ro_after_init = {
	.name		= LOCKD_FAMILY_NAME,
	.version	= LOCKD_FAMILY_VERSION,
	.netnsok	= true,
	.parallel_ops	= true,
	.module		= THIS_MODULE,
	.split_ops	= lockd_nl_ops,
	.n_split_ops	= ARRAY_SIZE(lockd_nl_ops),
};

fs/lockd/netlink.h

0 → 100644
+19 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
/* Do not edit directly, auto-generated from: */
/*	Documentation/netlink/specs/lockd.yaml */
/* YNL-GEN kernel header */

#ifndef _LINUX_LOCKD_GEN_H
#define _LINUX_LOCKD_GEN_H

#include <net/netlink.h>
#include <net/genetlink.h>

#include <uapi/linux/lockd_netlink.h>

int lockd_nl_server_set_doit(struct sk_buff *skb, struct genl_info *info);
int lockd_nl_server_get_doit(struct sk_buff *skb, struct genl_info *info);

extern struct genl_family lockd_nl_family;

#endif /* _LINUX_LOCKD_GEN_H */
+3 −0
Original line number Diff line number Diff line
@@ -10,6 +10,9 @@ struct lockd_net {
	unsigned int nlmsvc_users;
	unsigned long next_gc;
	unsigned long nrhosts;
	u32 gracetime;
	u16 tcp_port;
	u16 udp_port;

	struct delayed_work grace_period_end;
	struct lock_manager lockd_manager;
Loading