nfsd/sunrpc: add support for netlink upcalls for mountd/exportd
Subsystems (6)
Jeff Layton
maintainerv2 cover nfsd/sunrpc: add support for netlink upcalls for mountd/exportd
This version should address most of Chuck's review comments. The userland patch series is unchanged. I've added the netdev folks this time too in order to get more experienced eyes on the netlink bits.
Original cover letter follows:
mountd/exportd use the sunrpc cache mechanism for some of its internal caches that are populated by userland. These currently use some very antiquated interfaces in /proc to handle upcalls and downcalls. While it has worked well for decades and is relatively stable, it has some problems.
Most notably, it's very difficult to extend to add support for new export options. There is also the matter of requiring /proc which is not always desirable in a container.
This patchset adds new netlink-based interfaces for handling the sunrpc cache upcalls. The basic idea is to add a new "cache_notify" operation to struct cache_detail. That causes the kernel to send a notification to userland which then fetches any outstanding cache_requests and then responds to them via netlink.
There is also a companion patchset for nfs-utils that adds the necessary support for these interfaces to mountd/exportd and exportfs.
---
Changes in v2:
- Reword comment above cache_do_upcall()
- Delay adding include of genetlink.h until needed
- Implement proper netlink dump continuation support in all downcalls
- Only ->cache_notify if request is still PENDING
- Add comments to svc_export netlink flag enums
- Shrink size passed to genlmsg_new for notify requests to sizeof(u32)
- move nfsd_cache_notify() out of autogenerated file
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Jeff Layton (13):
nfsd: move struct nfsd_genl_rqstp to nfsctl.c
sunrpc: rename sunrpc_cache_pipe_upcall() to sunrpc_cache_upcall()
sunrpc: rename sunrpc_cache_pipe_upcall_timeout()
sunrpc: rename cache_pipe_upcall() to cache_do_upcall()
sunrpc: add a cache_notify callback
sunrpc: add helpers to count and snapshot pending cache requests
sunrpc: add a generic netlink family for cache upcalls
sunrpc: add netlink upcall for the auth.unix.ip cache
sunrpc: add netlink upcall for the auth.unix.gid cache
nfsd: add netlink upcall for the svc_export cache
nfsd: add netlink upcall for the nfsd.fh cache
sunrpc: add SUNRPC_CMD_CACHE_FLUSH netlink command
nfsd: add NFSD_CMD_CACHE_FLUSH netlink command
Documentation/netlink/specs/nfsd.yaml | 241 +++++++++ Documentation/netlink/specs/sunrpc_cache.yaml | 149 ++++++ fs/nfs/dns_resolve.c | 2 +- fs/nfsd/export.c | 713 +++++++++++++++++++++++++- fs/nfsd/netlink.c | 107 ++++ fs/nfsd/netlink.h | 18 + fs/nfsd/nfs4idmap.c | 4 +- fs/nfsd/nfsctl.c | 79 +++ fs/nfsd/nfsd.h | 17 +- include/linux/sunrpc/cache.h | 15 +- include/uapi/linux/nfsd_netlink.h | 141 +++++ include/uapi/linux/sunrpc_netlink.h | 84 +++ net/sunrpc/Makefile | 2 +- net/sunrpc/auth_gss/svcauth_gss.c | 2 +- net/sunrpc/cache.c | 127 ++++- net/sunrpc/netlink.c | 111 ++++ net/sunrpc/netlink.h | 35 ++ net/sunrpc/sunrpc_syms.c | 10 + net/sunrpc/svcauth_unix.c | 516 ++++++++++++++++++- 19 files changed, 2332 insertions(+), 41 deletions(-)
---
base-commit: e111174758bddc84136446ae283c741d855c7f8f
change-id: 20260316-exportd-netlink-1c9fb52536e3
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerPATCH v2 1/13 nfsd: move struct nfsd_genl_rqstp to nfsctl.c
It's not used outside of that file.
--- fs/nfsd/nfsctl.c | 15 +++++++++++++++ fs/nfsd/nfsd.h | 15 --------------- 2 files changed, 15 insertions(+), 15 deletions(-)
fs/nfsd/nfsctl.c +15 -0
@@ -1412,6 +1412,21 @@ static int create_proc_exports_entry(void)unsigned int nfsd_net_id; +struct nfsd_genl_rqstp { +struct sockaddr rq_daddr; +struct sockaddr rq_saddr; +unsigned long rq_flags; +ktime_t rq_stime; +__be32 rq_xid; +u32 rq_vers; +u32 rq_prog; +u32 rq_proc; + +/* NFSv4 compound */ +u32 rq_opcnt; +u32 rq_opnum[16 ]; +}; +static int nfsd_genl_rpc_status_compose_msg (struct sk_buff *skb,struct netlink_callback *cb,struct nfsd_genl_rqstp *genl_rqstp)
fs/nfsd/nfsd.h +0 -15
@@ -60,21 +60,6 @@ struct readdir_cd {/* Maximum number of operations per session compound */ #define NFSD_MAX_OPS_PER_COMPOUND 200 -struct nfsd_genl_rqstp { -struct sockaddr rq_daddr; -struct sockaddr rq_saddr; -unsigned long rq_flags; -ktime_t rq_stime; -__be32 rq_xid; -u32 rq_vers; -u32 rq_prog; -u32 rq_proc; - -/* NFSv4 compound */ -u32 rq_opcnt; -u32 rq_opnum[16 ]; -}; -extern struct svc_program nfsd_programs[];extern const struct svc_version nfsd_version2, nfsd_version3, nfsd_version4;extern struct mutex nfsd_mutex;
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 2/13 sunrpc: rename sunrpc_cache_pipe_upcall() to sunrpc_cache_upcall()
In reply to Jeff LaytonSince it will soon also send an upcall via netlink, if configured.
--- fs/nfsd/export.c | 4 ++-- include/linux/sunrpc/cache.h | 2 +- net/sunrpc/cache.c | 6 +++--- net/sunrpc/svcauth_unix.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)
fs/nfsd/export.c +2 -2
@@ -64,7 +64,7 @@ static void expkey_put(struct kref *ref)static int expkey_upcall (struct cache_detail *cd,struct cache_head *h) { -return sunrpc_cache_pipe_upcall (cd, h); +return sunrpc_cache_upcall (cd, h); } static void expkey_request(struct cache_detail *cd,
@@ -388,7 +388,7 @@ static void svc_export_put(struct kref *ref)static int svc_export_upcall (struct cache_detail *cd,struct cache_head *h) { -return sunrpc_cache_pipe_upcall (cd, h); +return sunrpc_cache_upcall (cd, h); } static void svc_export_request(struct cache_detail *cd,
include/linux/sunrpc/cache.h +1 -1
@@ -189,7 +189,7 @@ sunrpc_cache_update(struct cache_detail *detail, struct cache_head *new, struct cache_head *old, int hash);extern int -sunrpc_cache_pipe_upcall (struct cache_detail *detail,struct cache_head *h); +sunrpc_cache_upcall (struct cache_detail *detail,struct cache_head *h);extern int sunrpc_cache_pipe_upcall_timeout (struct cache_detail *detail,struct cache_head *h);
net/sunrpc/cache.c +3 -3
@@ -1241,13 +1241,13 @@ static int cache_pipe_upcall(struct cache_detail *detail, struct cache_head *h)return ret; } -int sunrpc_cache_pipe_upcall (struct cache_detail *detail,struct cache_head *h) +int sunrpc_cache_upcall (struct cache_detail *detail,struct cache_head *h) {if (test_and_set_bit (CACHE_PENDING , &h->flags))return 0 ;return cache_pipe_upcall (detail, h); } -EXPORT_SYMBOL_GPL (sunrpc_cache_pipe_upcall); +EXPORT_SYMBOL_GPL (sunrpc_cache_upcall);int sunrpc_cache_pipe_upcall_timeout (struct cache_detail *detail,struct cache_head *h)
@@ -1257,7 +1257,7 @@ int sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail,trace_cache_entry_no_listener (detail, h);return -EINVAL ; } -return sunrpc_cache_pipe_upcall (detail, h); +return sunrpc_cache_upcall (detail, h); }EXPORT_SYMBOL_GPL (sunrpc_cache_pipe_upcall_timeout);
net/sunrpc/svcauth_unix.c +1 -1
@@ -152,7 +152,7 @@ static struct cache_head *ip_map_alloc(void)static int ip_map_upcall (struct cache_detail *cd,struct cache_head *h) { -return sunrpc_cache_pipe_upcall (cd, h); +return sunrpc_cache_upcall (cd, h); } static void ip_map_request(struct cache_detail *cd,
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 3/13 sunrpc: rename sunrpc_cache_pipe_upcall_timeout()
In reply to Jeff LaytonThis function doesn't have anything to do with a timeout. The only difference is that it warns if there are no listeners. Rename it to sunrpc_cache_upcall_warn().
--- fs/nfs/dns_resolve.c | 2 +- fs/nfsd/nfs4idmap.c | 4 ++-- include/linux/sunrpc/cache.h | 2 +- net/sunrpc/auth_gss/svcauth_gss.c | 2 +- net/sunrpc/cache.c | 6 +++--- net/sunrpc/svcauth_unix.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-)
fs/nfs/dns_resolve.c +1 -1
@@ -156,7 +156,7 @@ static int nfs_dns_upcall(struct cache_detail *cd,if (!nfs_cache_upcall (cd, key->hostname))return 0 ;clear_bit (CACHE_PENDING , &ch->flags); -return sunrpc_cache_pipe_upcall_timeout (cd, ch); +return sunrpc_cache_upcall_warn (cd, ch); } static int nfs_dns_match(struct cache_head *ca,
fs/nfsd/nfs4idmap.c +2 -2
@@ -126,7 +126,7 @@ idtoname_hash(struct ent *ent)static int idtoname_upcall (struct cache_detail *cd,struct cache_head *h) { -return sunrpc_cache_pipe_upcall_timeout (cd, h); +return sunrpc_cache_upcall_warn (cd, h); } static void
@@ -306,7 +306,7 @@ nametoid_hash(struct ent *ent)static int nametoid_upcall (struct cache_detail *cd,struct cache_head *h) { -return sunrpc_cache_pipe_upcall_timeout (cd, h); +return sunrpc_cache_upcall_warn (cd, h); } static void
include/linux/sunrpc/cache.h +1 -1
@@ -191,7 +191,7 @@ sunrpc_cache_update(struct cache_detail *detail,extern int sunrpc_cache_upcall (struct cache_detail *detail,struct cache_head *h);extern int -sunrpc_cache_pipe_upcall_timeout (struct cache_detail *detail, +sunrpc_cache_upcall_warn (struct cache_detail *detail,struct cache_head *h);
net/sunrpc/auth_gss/svcauth_gss.c +1 -1
@@ -206,7 +206,7 @@ static struct cache_head *rsi_alloc(void)static int rsi_upcall (struct cache_detail *cd,struct cache_head *h) { -return sunrpc_cache_pipe_upcall_timeout (cd, h); +return sunrpc_cache_upcall_warn (cd, h); } static void rsi_request(struct cache_detail *cd,
net/sunrpc/cache.c +3 -3
@@ -1249,8 +1249,8 @@ int sunrpc_cache_upcall(struct cache_detail *detail, struct cache_head *h) }EXPORT_SYMBOL_GPL (sunrpc_cache_upcall); -int sunrpc_cache_pipe_upcall_timeout (struct cache_detail *detail, -struct cache_head *h) +int sunrpc_cache_upcall_warn (struct cache_detail *detail, +struct cache_head *h) {if (!cache_listeners_exist (detail)) {warn_no_listener (detail);
@@ -1259,7 +1259,7 @@ int sunrpc_cache_pipe_upcall_timeout(struct cache_detail *detail, }return sunrpc_cache_upcall (detail, h); } -EXPORT_SYMBOL_GPL (sunrpc_cache_pipe_upcall_timeout); +EXPORT_SYMBOL_GPL (sunrpc_cache_upcall_warn);/* * parse a message from user-space and pass it
net/sunrpc/svcauth_unix.c +1 -1
@@ -467,7 +467,7 @@ static struct cache_head *unix_gid_alloc(void)static int unix_gid_upcall (struct cache_detail *cd,struct cache_head *h) { -return sunrpc_cache_pipe_upcall_timeout (cd, h); +return sunrpc_cache_upcall_warn (cd, h); } static void unix_gid_request(struct cache_detail *cd,
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 4/13 sunrpc: rename cache_pipe_upcall() to cache_do_upcall()
In reply to Jeff LaytonRename cache_pipe_upcall() to cache_do_upcall() in anticipation of the addition of a netlink-based upcall mechanism.
--- net/sunrpc/cache.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/sunrpc/cache.c +4 -4
@@ -1195,12 +1195,12 @@ static bool cache_listeners_exist(struct cache_detail *detail) }/* -* register an upcall request to user-space and queue it up for read() by the -* upcall daemon. +* register an upcall request to user-space and queue it up to be fetched by +* the upcall daemon. * * Each request is at most one page long. */ -static int cache_pipe_upcall (struct cache_detail *detail,struct cache_head *h) +static int cache_do_upcall (struct cache_detail *detail,struct cache_head *h) {char *buf;struct cache_request *crq;
@@ -1245,7 +1245,7 @@ int sunrpc_cache_upcall(struct cache_detail *detail, struct cache_head *h) {if (test_and_set_bit (CACHE_PENDING , &h->flags))return 0 ; -return cache_pipe_upcall (detail, h); +return cache_do_upcall (detail, h); }EXPORT_SYMBOL_GPL (sunrpc_cache_upcall);
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 5/13 sunrpc: add a cache_notify callback
In reply to Jeff LaytonA later patch will be changing the kernel to send a netlink notification when there is a pending cache_request. Add a new cache_notify operation to struct cache_detail for this purpose.
--- include/linux/sunrpc/cache.h | 3 +++ net/sunrpc/cache.c | 2 ++ 2 files changed, 5 insertions(+)
include/linux/sunrpc/cache.h +3 -0
@@ -80,6 +80,9 @@ struct cache_detail {int (*cache_upcall)(struct cache_detail *,struct cache_head *); +int (*cache_notify)(struct cache_detail *cd, +struct cache_head *h); +void (*cache_request)(struct cache_detail *cd,struct cache_head *ch,char **bpp,int *blen);
net/sunrpc/cache.c +2 -0
@@ -1233,6 +1233,8 @@ static int cache_do_upcall(struct cache_detail *detail, struct cache_head *h)/* Lost a race, no longer PENDING, so don't enqueue */ ret = -EAGAIN ;spin_unlock (&detail->queue_lock); +if (ret != -EAGAIN && detail->cache_notify) + detail->cache_notify (detail, h);wake_up (&detail->queue_wait);if (ret == -EAGAIN ) {kfree (buf);
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 6/13 sunrpc: add helpers to count and snapshot pending cache requests
In reply to Jeff LaytonAdd sunrpc_cache_requests_count() and sunrpc_cache_requests_snapshot() to allow callers to count and snapshot the pending upcall request list without exposing struct cache_request outside of cache.c.
Both functions skip entries that no longer have CACHE_PENDING set.
The snapshot function takes a cache_get() reference on each item so the caller can safely use them after the queue_lock is released.
These will be used by the nfsd generic netlink dumpit handler for svc_export upcall requests.
--- include/linux/sunrpc/cache.h | 6 +++++ net/sunrpc/cache.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+)
include/linux/sunrpc/cache.h +6 -0
@@ -251,6 +251,12 @@ extern int sunrpc_cache_register_pipefs(struct dentry *parent, const char *,extern void sunrpc_cache_unregister_pipefs (struct cache_detail *);extern void sunrpc_cache_unhash (struct cache_detail *,struct cache_head *); +int sunrpc_cache_requests_count (struct cache_detail *cd); +int sunrpc_cache_requests_snapshot (struct cache_detail *cd, +struct cache_head **items, +u64 *seqnos,int max, +u64 min_seqno); +/* Must store cache_detail in seq_file->private if using next three functions */ extern void *cache_seq_start_rcu (struct seq_file *file,loff_t *pos);extern void *cache_seq_next_rcu (struct seq_file *file,void *p,loff_t *pos);
net/sunrpc/cache.c +61 -0
64 lines not on this page · raw message
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 7/13 sunrpc: add a generic netlink family for cache upcalls
In reply to Jeff LaytonThe auth.unix.ip and auth.unix.gid caches live in the sunrpc module, so they cannot use the nfsd generic netlink family. Create a new "sunrpc" generic netlink family with its own "exportd" multicast group to support cache upcall notifications for sunrpc-resident caches.
Define a YAML spec (sunrpc_cache.yaml) with a cache-type enum (ip_map, unix_gid), a cache-notify multicast event, and the corresponding uapi header.
Implement sunrpc_cache_notify() in cache.c, which checks for listeners on the exportd multicast group, builds and sends a SUNRPC_CMD_CACHE_NOTIFY message with the cache-type attribute.
Register/unregister the sunrpc_nl_family in init_sunrpc() and cleanup_sunrpc().
--- Documentation/netlink/specs/sunrpc_cache.yaml | 40 ++++++++++++++++++++++++ include/linux/sunrpc/cache.h | 2 ++ include/uapi/linux/sunrpc_netlink.h | 35 +++++++++++++++++++++ net/sunrpc/Makefile | 2 +- net/sunrpc/cache.c | 44 +++++++++++++++++++++++++++ net/sunrpc/netlink.c | 34 +++++++++++++++++++++ net/sunrpc/netlink.h | 22 ++++++++++++++ net/sunrpc/sunrpc_syms.c | 10 ++++++ 8 files changed, 188 insertions(+), 1 deletion(-)
Documentation/netlink/specs/sunrpc_cache.yaml new file +40 -0
@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +--- +name: sunrpc +protocol: genetlink +uapi-header: linux/sunrpc_netlink.h + +doc: SUNRPC cache upcall support over generic netlink. + +definitions: + - + type: flags + name: cache-type + entries: [ip_map, unix_gid] + +attribute-sets: + - + name: cache-notify + attributes: + - + name: cache-type + type: u32 + enum: cache-type + +operations: + list: + - + name: cache-notify + doc: Notification that there are cache requests that need servicing + attribute-set: cache-notify + mcgrp: exportd + event: + attributes: + - cache-type + +mcast-groups: + list: + - + name: none + - + name: exportd
include/linux/sunrpc/cache.h +2 -0
@@ -256,6 +256,8 @@ int sunrpc_cache_requests_snapshot(struct cache_detail *cd,struct cache_head **items, u64 *seqnos, int max, u64 min_seqno); +int sunrpc_cache_notify (struct cache_detail *cd,struct cache_head *h, +u32 cache_type);/* Must store cache_detail in seq_file->private if using next three functions */ extern void *cache_seq_start_rcu (struct seq_file *file,loff_t *pos);
include/uapi/linux/sunrpc_netlink.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/sunrpc_cache.yaml */ +/* YNL-GEN uapi header */ +/* To regenerate run: tools/net/ynl/ynl-regen.sh */ + +#ifndef _UAPI_LINUX_SUNRPC_NETLINK_H +#define _UAPI_LINUX_SUNRPC_NETLINK_H + +#define SUNRPC_FAMILY_NAME "sunrpc" +#define SUNRPC_FAMILY_VERSION 1 + +enum sunrpc_cache_type { +SUNRPC_CACHE_TYPE_IP_MAP =1 , +SUNRPC_CACHE_TYPE_UNIX_GID =2 , +}; + +enum { +SUNRPC_A_CACHE_NOTIFY_CACHE_TYPE =1 , + + __SUNRPC_A_CACHE_NOTIFY_MAX, +SUNRPC_A_CACHE_NOTIFY_MAX = (__SUNRPC_A_CACHE_NOTIFY_MAX -1 ) +}; + +enum { +SUNRPC_CMD_CACHE_NOTIFY =1 , + + __SUNRPC_CMD_MAX, +SUNRPC_CMD_MAX = (__SUNRPC_CMD_MAX -1 ) +}; + +#define SUNRPC_MCGRP_NONE "none" +#define SUNRPC_MCGRP_EXPORTD "exportd" + +#endif /* _UAPI_LINUX_SUNRPC_NETLINK_H */
net/sunrpc/Makefile +1 -1
@@ -14,7 +14,7 @@ sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \ addr.o rpcb_clnt.o timer.o xdr.o \ sunrpc_syms.o cache.o rpc_pipe.o sysfs.o \ svc_xprt.o \ - xprtmultipath.o + xprtmultipath.o netlink.o sunrpc-$(CONFIG_SUNRPC_DEBUG) += debugfs.o sunrpc-$(CONFIG_SUNRPC_BACKCHANNEL) += backchannel_rqst.o sunrpc-$(CONFIG_PROC_FS) += stats.o
net/sunrpc/cache.c +44 -0
56 lines not on this page · raw message
net/sunrpc/netlink.c new file +34 -0
@@ -0,0 +1,34 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/sunrpc_cache.yaml */ +/* YNL-GEN kernel source */ +/* To regenerate run: tools/net/ynl/ynl-regen.sh */ + +#include <net/netlink.h> +#include <net/genetlink.h> +#include <linux/sunrpc/cache.h> + +#include "netlink.h" + +#include <uapi/linux/sunrpc_netlink.h> + +/* Ops table for sunrpc */ +static const struct genl_split_ops sunrpc_nl_ops[] = { +}; + +static const struct genl_multicast_group sunrpc_nl_mcgrps[] = { + [SUNRPC_NLGRP_NONE ] = {"none" , }, + [SUNRPC_NLGRP_EXPORTD ] = {"exportd" , }, +}; + +struct genl_family sunrpc_nl_family__ro_after_init = { + .name =SUNRPC_FAMILY_NAME , + .version =SUNRPC_FAMILY_VERSION , + .netnsok = true, + .parallel_ops = true, + .module =THIS_MODULE , + .split_ops = sunrpc_nl_ops, + .n_split_ops =ARRAY_SIZE (sunrpc_nl_ops), + .mcgrps = sunrpc_nl_mcgrps, + .n_mcgrps =ARRAY_SIZE (sunrpc_nl_mcgrps), +};
net/sunrpc/netlink.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/sunrpc_cache.yaml */ +/* YNL-GEN kernel header */ +/* To regenerate run: tools/net/ynl/ynl-regen.sh */ + +#ifndef _LINUX_SUNRPC_GEN_H +#define _LINUX_SUNRPC_GEN_H + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include <uapi/linux/sunrpc_netlink.h> + +enum { +SUNRPC_NLGRP_NONE , +SUNRPC_NLGRP_EXPORTD , +}; + +extern struct genl_family sunrpc_nl_family; + +#endif /* _LINUX_SUNRPC_GEN_H */
net/sunrpc/sunrpc_syms.c +10 -0
@@ -23,9 +23,12 @@#include <linux/sunrpc/rpc_pipe_fs.h> #include <linux/sunrpc/xprtsock.h> +#include <net/genetlink.h> +#include "sunrpc.h" #include "sysfs.h" #include "netns.h" +#include "netlink.h" unsigned int sunrpc_net_id;EXPORT_SYMBOL_GPL (sunrpc_net_id);
@@ -108,6 +111,10 @@ init_sunrpc(void)if (err) goto out5; + err =genl_register_family (&sunrpc_nl_family); +if (err) + goto out6; +sunrpc_debugfs_init ();#if IS_ENABLED (CONFIG_SUNRPC_DEBUG )rpc_register_sysctl ();
@@ -116,6 +123,8 @@ init_sunrpc(void)init_socket_xprt ();/* clnt sock transport */ return 0 ; +out6: +rpc_sysfs_exit (); out5:unregister_rpc_pipefs (); out4:
@@ -131,6 +140,7 @@ init_sunrpc(void) static void __exitcleanup_sunrpc (void ) { +genl_unregister_family (&sunrpc_nl_family);rpc_sysfs_exit ();rpc_cleanup_clids ();xprt_cleanup_ids ();
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 8/13 sunrpc: add netlink upcall for the auth.unix.ip cache
In reply to Jeff LaytonAdd netlink-based cache upcall support for the ip_map (auth.unix.ip) cache, using the sunrpc generic netlink family.
Add ip-map attribute-set (seqno, class, addr, domain, negative, expiry), ip-map-reqs wrapper, and ip-map-get-reqs / ip-map-set-reqs operations to the sunrpc_cache YAML spec and generated headers.
Implement sunrpc_nl_ip_map_get_reqs_dumpit() which snapshots pending ip_map cache requests and sends each entry's seqno, class name, and IP address over netlink.
Implement sunrpc_nl_ip_map_set_reqs_doit() which parses ip_map cache responses from userspace (class, addr, expiry, and domain name or negative flag) and updates the cache via __ip_map_lookup() / __ip_map_update().
Wire up ip_map_notify() callback in ip_map_cache_template so cache misses trigger SUNRPC_CMD_CACHE_NOTIFY multicast events with SUNRPC_CACHE_TYPE_IP_MAP.
--- Documentation/netlink/specs/sunrpc_cache.yaml | 47 +++++ include/uapi/linux/sunrpc_netlink.h | 21 +++ net/sunrpc/netlink.c | 34 ++++ net/sunrpc/netlink.h | 8 + net/sunrpc/svcauth_unix.c | 246 ++++++++++++++++++++++++++ 5 files changed, 356 insertions(+)
Documentation/netlink/specs/sunrpc_cache.yaml +47 -0
@@ -20,6 +20,35 @@ attribute-sets: name: cache-type type: u32 enum: cache-type + - + name: ip-map + attributes: + - + name: seqno + type: u64 + - + name: class + type: string + - + name: addr + type: string + - + name: domain + type: string + - + name: negative + type: flag + - + name: expiry + type: u64 + - + name: ip-map-reqs + attributes: + - + name: requests + type: nest + nested-attributes: ip-map + multi-attr: true operations: list:
@@ -31,6 +60,24 @@ operations: event: attributes: - cache-type + - + name: ip-map-get-reqs + doc: Dump all pending ip_map requests + attribute-set: ip-map-reqs + flags: [admin-perm] + dump: + request: + attributes: + - requests + - + name: ip-map-set-reqs + doc: Respond to one or more ip_map requests + attribute-set: ip-map-reqs + flags: [admin-perm] + do: + request: + attributes: + - requests mcast-groups: list:
include/uapi/linux/sunrpc_netlink.h +21 -0
@@ -22,8 +22,29 @@ enum {SUNRPC_A_CACHE_NOTIFY_MAX = (__SUNRPC_A_CACHE_NOTIFY_MAX -1 ) }; +enum { +SUNRPC_A_IP_MAP_SEQNO =1 , +SUNRPC_A_IP_MAP_CLASS , +SUNRPC_A_IP_MAP_ADDR , +SUNRPC_A_IP_MAP_DOMAIN , +SUNRPC_A_IP_MAP_NEGATIVE , +SUNRPC_A_IP_MAP_EXPIRY , + + __SUNRPC_A_IP_MAP_MAX, +SUNRPC_A_IP_MAP_MAX = (__SUNRPC_A_IP_MAP_MAX -1 ) +}; + +enum { +SUNRPC_A_IP_MAP_REQS_REQUESTS =1 , + + __SUNRPC_A_IP_MAP_REQS_MAX, +SUNRPC_A_IP_MAP_REQS_MAX = (__SUNRPC_A_IP_MAP_REQS_MAX -1 ) +}; +enum {SUNRPC_CMD_CACHE_NOTIFY =1 , +SUNRPC_CMD_IP_MAP_GET_REQS , +SUNRPC_CMD_IP_MAP_SET_REQS , __SUNRPC_CMD_MAX,SUNRPC_CMD_MAX = (__SUNRPC_CMD_MAX -1 )
net/sunrpc/netlink.c +34 -0
@@ -12,8 +12,42 @@#include <uapi/linux/sunrpc_netlink.h> +/* Common nested types */ +const struct nla_policy sunrpc_ip_map_nl_policy[SUNRPC_A_IP_MAP_EXPIRY +1 ] = { + [SUNRPC_A_IP_MAP_SEQNO ] = { .type =NLA_U64 , }, + [SUNRPC_A_IP_MAP_CLASS ] = { .type =NLA_NUL_STRING , }, + [SUNRPC_A_IP_MAP_ADDR ] = { .type =NLA_NUL_STRING , }, + [SUNRPC_A_IP_MAP_DOMAIN ] = { .type =NLA_NUL_STRING , }, + [SUNRPC_A_IP_MAP_NEGATIVE ] = { .type =NLA_FLAG , }, + [SUNRPC_A_IP_MAP_EXPIRY ] = { .type =NLA_U64 , }, +}; + +/* SUNRPC_CMD_IP_MAP_GET_REQS - dump */ +static const struct nla_policy sunrpc_ip_map_get_reqs_nl_policy[SUNRPC_A_IP_MAP_REQS_REQUESTS +1 ] = { + [SUNRPC_A_IP_MAP_REQS_REQUESTS ] =NLA_POLICY_NESTED (sunrpc_ip_map_nl_policy), +}; + +/* SUNRPC_CMD_IP_MAP_SET_REQS - do */ +static const struct nla_policy sunrpc_ip_map_set_reqs_nl_policy[SUNRPC_A_IP_MAP_REQS_REQUESTS +1 ] = { + [SUNRPC_A_IP_MAP_REQS_REQUESTS ] =NLA_POLICY_NESTED (sunrpc_ip_map_nl_policy), +}; +/* Ops table for sunrpc */ static const struct genl_split_ops sunrpc_nl_ops[] = { + { + .cmd =SUNRPC_CMD_IP_MAP_GET_REQS , + .dumpit = sunrpc_nl_ip_map_get_reqs_dumpit, + .policy = sunrpc_ip_map_get_reqs_nl_policy, + .maxattr =SUNRPC_A_IP_MAP_REQS_REQUESTS , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DUMP , + }, + { + .cmd =SUNRPC_CMD_IP_MAP_SET_REQS , + .doit = sunrpc_nl_ip_map_set_reqs_doit, + .policy = sunrpc_ip_map_set_reqs_nl_policy, + .maxattr =SUNRPC_A_IP_MAP_REQS_REQUESTS , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, };static const struct genl_multicast_group sunrpc_nl_mcgrps[] = {
net/sunrpc/netlink.h +8 -0
@@ -12,6 +12,14 @@#include <uapi/linux/sunrpc_netlink.h> +/* Common nested types */ +extern const struct nla_policy sunrpc_ip_map_nl_policy[SUNRPC_A_IP_MAP_EXPIRY +1 ]; + +int sunrpc_nl_ip_map_get_reqs_dumpit (struct sk_buff *skb, +struct netlink_callback *cb); +int sunrpc_nl_ip_map_set_reqs_doit (struct sk_buff *skb, +struct genl_info *info); +enum {SUNRPC_NLGRP_NONE ,SUNRPC_NLGRP_EXPORTD ,
net/sunrpc/svcauth_unix.c +246 -0
269 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH v2 08/13] sunrpc: add netlink upcall for the auth.unix.ip cache
Quoted 10 lines · Jeff Layton
Add netlink-based cache upcall support for the
ip_map(auth.unix.ip) cache, using the sunrpc generic netlink family.Add ip-map attribute-set (seqno, class, addr, domain, negative, expiry), ip-map-reqs wrapper, and ip-map-get-reqs / ip-map-set-reqs operations to the
sunrpc_cacheYAML spec and generated headers.Implement
sunrpc_nl_ip_map_get_reqs_dumpit()which snapshots pendingip_mapcache requests and sends each entry's seqno, class name, and IP address over netlink.
This afaics showed up in -next today and seems to have broken compiling tools/net/ynl for me:
"""
CC nl80211-user.o
CC nlctrl-user.o
CC ovpn-user.o
CC ovs_datapath-user.o
In file included from nfsd-user.c:9:
nfsd-user.h:746:45: error: field ‘obj’ has incomplete type
746 | struct nfsd_svc_export_get_reqs_rsp obj
__attribute__((aligned(8)));
| ^~~
nfsd-user.h:826:41: error: field ‘obj’ has incomplete type
826 | struct nfsd_expkey_get_reqs_rsp obj
__attribute__((aligned(8)));
| ^~~nfsd-user.c: In function ‘nfsd_svc_export_get_reqs_dump’:
nfsd-user.c:1181:18: error: ‘nfsd_svc_export_get_reqs_rsp_parse’ undeclared (first use in this function); did you mean ‘nfsd_svc_export_get_reqs_req_free’?
1181 | yds.cb = nfsd_svc_export_get_reqs_rsp_parse;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| nfsd_svc_export_get_reqs_req_freenfsd-user.c:1181:18: note: each undeclared identifier is reported only once for each function it appears in
nfsd-user.c:1195:19: error: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
1195 | return yds.first;
| ~~~^~~~~~nfsd-user.c:1199:16: error: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
1199 | return NULL;
| ^~~~nfsd-user.c: In function ‘nfsd_expkey_get_reqs_dump’:
nfsd-user.c:1273:18: error: ‘nfsd_expkey_get_reqs_rsp_parse’ undeclared (first use in this function); did you mean ‘nfsd_expkey_get_reqs_req_free’?
1273 | yds.cb = nfsd_expkey_get_reqs_rsp_parse;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| nfsd_expkey_get_reqs_req_free CC ovs_vport-user.o
CC ovs_flow-user.o
nfsd-user.c:1287:19: error: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
1287 | return yds.first;
| ~~~^~~~~~nfsd-user.c:1291:16: error: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
1291 | return NULL;
| ^~~~
CC psp-user.o
make[1]: *** [Makefile:52: nfsd-user.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:28: generated] Error 2
"""
Full log:
https://download.copr.fedorainfracloud.org/results/@kernel-vanilla/next/fedora-rawhide-x86_64/10360309-next-next-all/builder-live.log.gz
(similar errors for aarch64 and ppc64)
Reverting the following changes made things compile again for me:
257dc1227d07be ("nfsd: add NFSD_CMD_CACHE_FLUSH netlink command") 22f99c05b145e7 ("sunrpc: add SUNRPC_CMD_CACHE_FLUSH netlink command") 97fa24739b5566 ("nfsd: add netlink upcall for the nfsd.fh cache") dd8015e766e639 ("nfsd: add netlink upcall for the svc_export cache") d1b8115657acdf ("sunrpc: add netlink upcall for the auth.unix.gid cache") 1045ccf519ce30 ("sunrpc: add netlink upcall for the auth.unix.ip cache")
I reverted all patches that modified Documentation/netlink/specs/ in reverse order, so maybe all except the last one in the list above are fine.
Ciao, Thorsten
Quoted 459 lines
Implement
sunrpc_nl_ip_map_set_reqs_doit()which parsesip_mapcache responses from userspace (class, addr, expiry, and domain name or negative flag) and updates the cache via__ip_map_lookup()/__ip_map_update().Wire up
ip_map_notify()callback inip_map_cache_templateso cache misses triggerSUNRPC_CMD_CACHE_NOTIFYmulticast events withSUNRPC_CACHE_TYPE_IP_MAP.Signed-off-by Jeff Layton <[email protected]>--- Documentation/netlink/specs/sunrpc_cache.yaml | 47 +++++ include/uapi/linux/sunrpc_netlink.h | 21 +++ net/sunrpc/netlink.c | 34 ++++ net/sunrpc/netlink.h | 8 + net/sunrpc/svcauth_unix.c | 246 ++++++++++++++++++++++++++ 5 files changed, 356 insertions(+)Documentation/netlink/specs/sunrpc_cache.yaml +47
-0@@ -20,6 +20,35 @@ attribute-sets: name: cache-type type: u32 enum: cache-type + - + name: ip-map + attributes: + - + name: seqno + type: u64 + - + name: class + type: string + - + name: addr + type: string + - + name: domain + type: string + - + name: negative + type: flag + - + name: expiry + type: u64 + - + name: ip-map-reqs + attributes: + - + name: requests + type: nest + nested-attributes: ip-map + multi-attr: true operations: list:@@ -31,6 +60,24 @@ operations: event: attributes: - cache-type + - + name: ip-map-get-reqs + doc: Dump all pending ip_map requests + attribute-set: ip-map-reqs + flags: [admin-perm] + dump: + request: + attributes: + - requests + - + name: ip-map-set-reqs + doc: Respond to one or more ip_map requests + attribute-set: ip-map-reqs + flags: [admin-perm] + do: + request: + attributes: + - requests mcast-groups: list:include/uapi/linux/sunrpc_netlink.h +21
-0@@ -22,8 +22,29 @@ enum {SUNRPC_A_CACHE_NOTIFY_MAX = (__SUNRPC_A_CACHE_NOTIFY_MAX -1 ) }; +enum { +SUNRPC_A_IP_MAP_SEQNO =1 , +SUNRPC_A_IP_MAP_CLASS , +SUNRPC_A_IP_MAP_ADDR , +SUNRPC_A_IP_MAP_DOMAIN , +SUNRPC_A_IP_MAP_NEGATIVE , +SUNRPC_A_IP_MAP_EXPIRY , + + __SUNRPC_A_IP_MAP_MAX, +SUNRPC_A_IP_MAP_MAX = (__SUNRPC_A_IP_MAP_MAX -1 ) +}; + +enum { +SUNRPC_A_IP_MAP_REQS_REQUESTS =1 , + + __SUNRPC_A_IP_MAP_REQS_MAX, +SUNRPC_A_IP_MAP_REQS_MAX = (__SUNRPC_A_IP_MAP_REQS_MAX -1 ) +}; +enum {SUNRPC_CMD_CACHE_NOTIFY =1 , +SUNRPC_CMD_IP_MAP_GET_REQS , +SUNRPC_CMD_IP_MAP_SET_REQS , __SUNRPC_CMD_MAX,SUNRPC_CMD_MAX = (__SUNRPC_CMD_MAX -1 )net/sunrpc/netlink.c +34
-0@@ -12,8 +12,42 @@#include <uapi/linux/sunrpc_netlink.h> +/* Common nested types */ +const struct nla_policy sunrpc_ip_map_nl_policy[SUNRPC_A_IP_MAP_EXPIRY +1 ] = { + [SUNRPC_A_IP_MAP_SEQNO ] = { .type =NLA_U64 , }, + [SUNRPC_A_IP_MAP_CLASS ] = { .type =NLA_NUL_STRING , }, + [SUNRPC_A_IP_MAP_ADDR ] = { .type =NLA_NUL_STRING , }, + [SUNRPC_A_IP_MAP_DOMAIN ] = { .type =NLA_NUL_STRING , }, + [SUNRPC_A_IP_MAP_NEGATIVE ] = { .type =NLA_FLAG , }, + [SUNRPC_A_IP_MAP_EXPIRY ] = { .type =NLA_U64 , }, +}; + +/* SUNRPC_CMD_IP_MAP_GET_REQS - dump */ +static const struct nla_policy sunrpc_ip_map_get_reqs_nl_policy[SUNRPC_A_IP_MAP_REQS_REQUESTS +1 ] = { + [SUNRPC_A_IP_MAP_REQS_REQUESTS ] =NLA_POLICY_NESTED (sunrpc_ip_map_nl_policy), +}; + +/* SUNRPC_CMD_IP_MAP_SET_REQS - do */ +static const struct nla_policy sunrpc_ip_map_set_reqs_nl_policy[SUNRPC_A_IP_MAP_REQS_REQUESTS +1 ] = { + [SUNRPC_A_IP_MAP_REQS_REQUESTS ] =NLA_POLICY_NESTED (sunrpc_ip_map_nl_policy), +}; +/* Ops table for sunrpc */ static const struct genl_split_ops sunrpc_nl_ops[] = { + { + .cmd =SUNRPC_CMD_IP_MAP_GET_REQS , + .dumpit = sunrpc_nl_ip_map_get_reqs_dumpit, + .policy = sunrpc_ip_map_get_reqs_nl_policy, + .maxattr =SUNRPC_A_IP_MAP_REQS_REQUESTS , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DUMP , + }, + { + .cmd =SUNRPC_CMD_IP_MAP_SET_REQS , + .doit = sunrpc_nl_ip_map_set_reqs_doit, + .policy = sunrpc_ip_map_set_reqs_nl_policy, + .maxattr =SUNRPC_A_IP_MAP_REQS_REQUESTS , + .flags =GENL_ADMIN_PERM |GENL_CMD_CAP_DO , + }, };static const struct genl_multicast_group sunrpc_nl_mcgrps[] = {net/sunrpc/netlink.h +8
-0@@ -12,6 +12,14 @@#include <uapi/linux/sunrpc_netlink.h> +/* Common nested types */ +extern const struct nla_policy sunrpc_ip_map_nl_policy[SUNRPC_A_IP_MAP_EXPIRY +1 ]; + +int sunrpc_nl_ip_map_get_reqs_dumpit (struct sk_buff *skb, +struct netlink_callback *cb); +int sunrpc_nl_ip_map_set_reqs_doit (struct sk_buff *skb, +struct genl_info *info); +enum {SUNRPC_NLGRP_NONE ,SUNRPC_NLGRP_EXPORTD ,net/sunrpc/svcauth_unix.c +246
-0@@ -17,11 +17,14 @@#include <net/ipv6.h> #include <linux/kernel.h> #include <linux/user_namespace.h> +#include <net/genetlink.h> +#include <uapi/linux/sunrpc_netlink.h> #include <trace/events/sunrpc.h> #define RPCDBG_FACILITY RPCDBG_AUTH#include "netns.h" +#include "netlink.h" /* * AUTHUNIX and AUTHNULL credentials are both handled here. @@ -1017,12 +1020,255 @@ struct auth_ops svcauth_unix = { .set_client = svcauth_unix_set_client, }; +static int ip_map_notify (struct cache_detail *cd,struct cache_head *h) +{ +return sunrpc_cache_notify (cd, h,SUNRPC_CACHE_TYPE_IP_MAP ); +} + +/** +* sunrpc_nl_ip_map_get_reqs_dumpit - dump pending ip_map requests +* @skb: reply buffer +* @cb: netlink metadata and command arguments +* +* Walk the ip_map cache's pending request list and create a netlink +* message with a nested entry for each cache_request, containing the +* seqno, class and addr. +* +* Uses cb->args[0] as a seqno cursor for dump continuation across +* multiple netlink messages. +* +* Returns the size of the reply or a negative errno. +*/ +int sunrpc_nl_ip_map_get_reqs_dumpit (struct sk_buff *skb, +struct netlink_callback *cb) +{ +struct sunrpc_net *sn; +struct cache_detail *cd; +struct cache_head **items; +u64 *seqnos; +int cnt, i, emitted; +void *hdr; +int ret; + + sn =net_generic (sock_net (skb->sk), sunrpc_net_id); + + cd = sn->ip_map_cache; +if (!cd) +return -ENODEV ; + + cnt =sunrpc_cache_requests_count (cd); +if (!cnt) +return 0 ; + + items =kcalloc (cnt,sizeof (*items),GFP_KERNEL ); + seqnos =kcalloc (cnt,sizeof (*seqnos),GFP_KERNEL ); +if (!items || !seqnos) { + ret = -ENOMEM ; + goto out_alloc; + } + + cnt =sunrpc_cache_requests_snapshot (cd, items, seqnos, cnt, + cb->args[0 ]); +if (!cnt) { + ret =0 ; + goto out_alloc; + } + + hdr =genlmsg_put (skb,NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq, &sunrpc_nl_family, +NLM_F_MULTI ,SUNRPC_CMD_IP_MAP_GET_REQS ); +if (!hdr) { + ret = -ENOBUFS ; + goto out_put; + } + + emitted =0 ; +for (i =0 ; i < cnt; i++) { +struct ip_map *im; +struct nlattr *nest; +char text_addr[40 ]; + + im = container_of(items[i], struct ip_map, h); + +if (ipv6_addr_v4mapped (&im->m_addr)) +snprintf (text_addr,20 ,"%pI4" , + &im->m_addr.s6_addr32[3 ]); +else +snprintf (text_addr,40 ,"%pI6" , &im->m_addr); + + nest =nla_nest_start (skb,SUNRPC_A_IP_MAP_REQS_REQUESTS ); +if (!nest) +break ; + +if (nla_put_u64_64bit (skb,SUNRPC_A_IP_MAP_SEQNO , + seqnos[i],0 ) || +nla_put_string (skb,SUNRPC_A_IP_MAP_CLASS , + im->m_class) || +nla_put_string (skb,SUNRPC_A_IP_MAP_ADDR , text_addr)) { +nla_nest_cancel (skb, nest); +break ; + } + +nla_nest_end (skb, nest); + cb->args[0 ] = seqnos[i]; + emitted++; + } + +if (!emitted) { +genlmsg_cancel (skb, hdr); + ret = -EMSGSIZE ; + goto out_put; + } + +genlmsg_end (skb, hdr); + ret = skb->len; +out_put: +for (i =0 ; i < cnt; i++) +cache_put (items[i], cd); +out_alloc: +kfree (seqnos); +kfree (items); +return ret; +} + +/** +* sunrpc_nl_parse_one_ip_map - parse one ip_map entry from netlink +* @cd: cache_detail for the ip_map cache +* @attr: nested attribute containing ip_map fields +* +* Parses one ip_map entry from a netlink message and updates the +* cache. Mirrors the logic in ip_map_parse(). +* +* Returns 0 on success or a negative errno. +*/ +static int sunrpc_nl_parse_one_ip_map (struct cache_detail *cd, +struct nlattr *attr) +{ +struct nlattr *tb[SUNRPC_A_IP_MAP_EXPIRY +1 ]; +union { +struct sockaddr sa; +struct sockaddr_in s4; +struct sockaddr_in6 s6; + } address; +struct sockaddr_in6 sin6; +struct ip_map *ipmp; +struct auth_domain *dom =NULL ; +struct unix_domain *udom =NULL ; +struct timespec64 boot; +time64_t expiry; +char class[8 ]; +int err; +int len; + + err =nla_parse_nested (tb,SUNRPC_A_IP_MAP_EXPIRY , attr, + sunrpc_ip_map_nl_policy,NULL ); +if (err) +return err; + +/* class (required) */ +if (!tb[SUNRPC_A_IP_MAP_CLASS ]) +return -EINVAL ; + len =nla_len (tb[SUNRPC_A_IP_MAP_CLASS ]); +if (len <=0 || len >sizeof (class)) +return -EINVAL ; +nla_strscpy (class, tb[SUNRPC_A_IP_MAP_CLASS ],sizeof (class)); + +/* addr (required) */ +if (!tb[SUNRPC_A_IP_MAP_ADDR ]) +return -EINVAL ; +if (rpc_pton (cd->net,nla_data (tb[SUNRPC_A_IP_MAP_ADDR ]), +nla_len (tb[SUNRPC_A_IP_MAP_ADDR ]) -1 , + &address.sa,sizeof (address)) ==0 ) +return -EINVAL ; + +switch (address.sa.sa_family) { +case AF_INET : + sin6.sin6_family =AF_INET6 ; +ipv6_addr_set_v4mapped (address.s4.sin_addr.s_addr, + &sin6.sin6_addr); +break ; +#if IS_ENABLED (CONFIG_IPV6 ) +case AF_INET6 : +memcpy (&sin6, &address.s6,sizeof (sin6)); +break ; +#endif +default : +return -EINVAL ; + } + +/* expiry (required, wallclock seconds) */ +if (!tb[SUNRPC_A_IP_MAP_EXPIRY ]) +return -EINVAL ; +getboottime64 (&boot); + expiry =nla_get_u64 (tb[SUNRPC_A_IP_MAP_EXPIRY ]) - boot.tv_sec; + +/* domain name or negative */ +if (tb[SUNRPC_A_IP_MAP_NEGATIVE ]) { + udom =NULL ; + }else if (tb[SUNRPC_A_IP_MAP_DOMAIN ]) { + dom =unix_domain_find (nla_data (tb[SUNRPC_A_IP_MAP_DOMAIN ])); +if (!dom) +return -ENOENT ; + udom = container_of(dom, struct unix_domain, h); + }else { +return -EINVAL ; + } + + ipmp =__ip_map_lookup (cd, class, &sin6.sin6_addr); +if (ipmp) + err =__ip_map_update (cd, ipmp, udom, expiry); +else + err = -ENOMEM ; + +if (dom) +auth_domain_put (dom); + +cache_flush (); +return err; +} + +/** +* sunrpc_nl_ip_map_set_reqs_doit - respond to ip_map requests +* @skb: reply buffer +* @info: netlink metadata and command arguments +* +* Parse one or more ip_map cache responses from userspace and +* update the ip_map cache accordingly. +* +* Returns 0 on success or a negative errno. +*/ +int sunrpc_nl_ip_map_set_reqs_doit (struct sk_buff *skb, +struct genl_info *info) +{ +struct sunrpc_net *sn; +struct cache_detail *cd; +const struct nlattr *attr; +int rem, ret =0 ; + + sn =net_generic (genl_info_net (info), sunrpc_net_id); + + cd = sn->ip_map_cache; +if (!cd) +return -ENODEV ; + +nlmsg_for_each_attr_type (attr,SUNRPC_A_IP_MAP_REQS_REQUESTS , + info->nlhdr,GENL_HDRLEN , rem) { + ret =sunrpc_nl_parse_one_ip_map (cd, + (struct nlattr *)attr); +if (ret) +break ; + } + +return ret; +} +static const struct cache_detail ip_map_cache_template = { .owner =THIS_MODULE , .hash_size =IP_HASHMAX , .name ="auth.unix.ip" , .cache_put = ip_map_put, .cache_upcall = ip_map_upcall, + .cache_notify = ip_map_notify, .cache_request = ip_map_request, .cache_parse = ip_map_parse, .cache_show = ip_map_show,
Jeff Layton
maintainerPATCH v2 9/13 sunrpc: add netlink upcall for the auth.unix.gid cache
In reply to Jeff LaytonAdd netlink-based cache upcall support for the unix_gid (auth.unix.gid) cache, using the sunrpc generic netlink family.
Add unix-gid attribute-set (seqno, uid, gids multi-attr, negative, expiry), unix-gid-reqs wrapper, and unix-gid-get-reqs / unix-gid-set-reqs operations to the sunrpc_cache YAML spec and generated headers.
Implement sunrpc_nl_unix_gid_get_reqs_dumpit() which snapshots pending unix_gid cache requests and sends each entry's seqno and uid over netlink.
Implement sunrpc_nl_unix_gid_set_reqs_doit() which parses unix_gid cache responses from userspace (uid, expiry, gids as u32 multi-attr or negative flag) and updates the cache via unix_gid_lookup() / sunrpc_cache_update().
Wire up unix_gid_notify() callback in unix_gid_cache_template so cache misses trigger SUNRPC_CMD_CACHE_NOTIFY multicast events with SUNRPC_CACHE_TYPE_UNIX_GID.
--- Documentation/netlink/specs/sunrpc_cache.yaml | 45 +++++ include/uapi/linux/sunrpc_netlink.h | 20 +++ net/sunrpc/netlink.c | 32 ++++ net/sunrpc/netlink.h | 5 + net/sunrpc/svcauth_unix.c | 234 ++++++++++++++++++++++++++ 5 files changed, 336 insertions(+)
Documentation/netlink/specs/sunrpc_cache.yaml +45 -0
@@ -49,6 +49,33 @@ attribute-sets: type: nest nested-attributes: ip-map multi-attr: true + - + name: unix-gid + attributes: + - + name: seqno + type: u64 + - + name: uid + type: u32 + - + name: gids + type: u32 + multi-attr: true + - + name: negative + type: flag + - + name: expiry + type: u64 + - + name: unix-gid-reqs + attributes: + - + name: requests + type: nest + nested-attributes: unix-gid + multi-attr: true operations: list:
@@ -78,6 +105,24 @@ operations: request: attributes: - requests + - + name: unix-gid-get-reqs + doc: Dump all pending unix_gid requests + attribute-set: unix-gid-reqs + flags: [admin-perm] + dump: + request: + attributes: + - requests + - + name: unix-gid-set-reqs + doc: Respond to one or more unix_gid requests + attribute-set: unix-gid-reqs + flags: [admin-perm] + do: + request: + attributes: + - requests mcast-groups: list:
include/uapi/linux/sunrpc_netlink.h +20 -0
@@ -41,10 +41,30 @@ enum {SUNRPC_A_IP_MAP_REQS_MAX = (__SUNRPC_A_IP_MAP_REQS_MAX -1 ) }; +enum { +SUNRPC_A_UNIX_GID_SEQNO =1 , +SUNRPC_A_UNIX_GID_UID , +SUNRPC_A_UNIX_GID_GIDS , +SUNRPC_A_UNIX_GID_NEGATIVE , +SUNRPC_A_UNIX_GID_EXPIRY , + + __SUNRPC_A_UNIX_GID_MAX, +SUNRPC_A_UNIX_GID_MAX = (__SUNRPC_A_UNIX_GID_MAX -1 ) +}; + +enum { +SUNRPC_A_UNIX_GID_REQS_REQUESTS =1 , + + __SUNRPC_A_UNIX_GID_REQS_MAX, +SUNRPC_A_UNIX_GID_REQS_MAX = (__SUNRPC_A_UNIX_GID_REQS_MAX -1 ) +}; +enum {SUNRPC_CMD_CACHE_NOTIFY =1 ,SUNRPC_CMD_IP_MAP_GET_REQS ,SUNRPC_CMD_IP_MAP_SET_REQS , +SUNRPC_CMD_UNIX_GID_GET_REQS , +SUNRPC_CMD_UNIX_GID_SET_REQS , __SUNRPC_CMD_MAX,SUNRPC_CMD_MAX = (__SUNRPC_CMD_MAX -1 )
net/sunrpc/netlink.c +32 -0
@@ -32,6 +32,24 @@ static const struct nla_policy sunrpc_ip_map_set_reqs_nl_policy[SUNRPC_A_IP_MAP_ [SUNRPC_A_IP_MAP_REQS_REQUESTS] = NLA_POLICY_NESTED(sunrpc_ip_map_nl_policy), }; +const struct nla_policy sunrpc_unix_gid_nl_policy[SUNRPC_A_UNIX_GID_EXPIRY +1 ] = { + [SUNRPC_A_UNIX_GID_SEQNO ] = { .type =NLA_U64 , }, + [SUNRPC_A_UNIX_GID_UID ] = { .type =NLA_U32 , }, + [SUNRPC_A_UNIX_GID_GIDS ] = { .type =NLA_U32 , }, + [SUNRPC_A_UNIX_GID_NEGATIVE ] = { .type =NLA_FLAG , }, + [SUNRPC_A_UNIX_GID_EXPIRY ] = { .type =NLA_U64 , }, +}; + +/* SUNRPC_CMD_UNIX_GID_GET_REQS - dump */ +static const struct nla_policy sunrpc_unix_gid_get_reqs_nl_policy[SUNRPC_A_UNIX_GID_REQS_REQUESTS +1 ] = { + [SUNRPC_A_UNIX_GID_REQS_REQUESTS ] =NLA_POLICY_NESTED (sunrpc_unix_gid_nl_policy), +}; + +/* SUNRPC_CMD_UNIX_GID_SET_REQS - do */ +static const struct nla_policy sunrpc_unix_gid_set_reqs_nl_policy[SUNRPC_A_UNIX_GID_REQS_REQUESTS +1 ] = { + [SUNRPC_A_UNIX_GID_REQS_REQUESTS ] =NLA_POLICY_NESTED (sunrpc_unix_gid_nl_policy), +}; +/* Ops table for sunrpc */ static const struct genl_split_ops sunrpc_nl_ops[] = { {
@@ -48,6 +66,20 @@ static const struct genl_split_ops sunrpc_nl_ops[] = { .maxattr = SUNRPC_A_IP_MAP_REQS_REQUESTS, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, + { + .cmd = SUNRPC_CMD_UNIX_GID_GET_REQS, + .dumpit = sunrpc_nl_unix_gid_get_reqs_dumpit, + .policy = sunrpc_unix_gid_get_reqs_nl_policy, + .maxattr = SUNRPC_A_UNIX_GID_REQS_REQUESTS, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP, + }, + { + .cmd = SUNRPC_CMD_UNIX_GID_SET_REQS, + .doit = sunrpc_nl_unix_gid_set_reqs_doit, + .policy = sunrpc_unix_gid_set_reqs_nl_policy, + .maxattr = SUNRPC_A_UNIX_GID_REQS_REQUESTS, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, }; static const struct genl_multicast_group sunrpc_nl_mcgrps[] = {
net/sunrpc/netlink.h +5 -0
@@ -14,11 +14,16 @@/* Common nested types */ extern const struct nla_policy sunrpc_ip_map_nl_policy[SUNRPC_A_IP_MAP_EXPIRY +1 ]; +extern const struct nla_policy sunrpc_unix_gid_nl_policy[SUNRPC_A_UNIX_GID_EXPIRY +1 ];int sunrpc_nl_ip_map_get_reqs_dumpit (struct sk_buff *skb,struct netlink_callback *cb);int sunrpc_nl_ip_map_set_reqs_doit (struct sk_buff *skb,struct genl_info *info); +int sunrpc_nl_unix_gid_get_reqs_dumpit (struct sk_buff *skb, +struct netlink_callback *cb); +int sunrpc_nl_unix_gid_set_reqs_doit (struct sk_buff *skb, +struct genl_info *info);enum {SUNRPC_NLGRP_NONE ,
net/sunrpc/svcauth_unix.c +234 -0
246 lines not on this page · raw message
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 10/13 nfsd: add netlink upcall for the svc_export cache
In reply to Jeff LaytonAdd netlink-based cache upcall support for the svc_export (nfsd.export) cache to Documentation/netlink/specs/nfsd.yaml and regenerate the resulting files.
Implement nfsd_cache_notify() which sends a NFSD_CMD_CACHE_NOTIFY multicast event to the "exportd" group, carrying the cache type so userspace knows which cache has pending requests.
Implement nfsd_nl_svc_export_get_reqs_dumpit() which snapshots pending svc_export cache requests and sends each entry's seqno, client name, and path over netlink.
Implement nfsd_nl_svc_export_set_reqs_doit() which parses svc_export cache responses from userspace (client, path, expiry, flags, anon uid/gid, fslocations, uuid, secinfo, xprtsec, fsid, or negative flag) and updates the cache via svc_export_lookup() / svc_export_update().
Wire up the svc_export_notify() callback in svc_export_cache_template so cache misses trigger NFSD_CMD_CACHE_NOTIFY multicast events with NFSD_CACHE_TYPE_SVC_EXPORT.
Note that the export-flags and xprtsec-mode enums are organized to match their counterparts in include/uapi/linux/nfsd/export.h. The intent is that future export options will only be added to the netlink headers, which should eliminate the need to keep so much in sync.
--- Documentation/netlink/specs/nfsd.yaml | 174 +++++++++++++ fs/nfsd/export.c | 443 +++++++++++++++++++++++++++++++++- fs/nfsd/netlink.c | 61 +++++ fs/nfsd/netlink.h | 13 + fs/nfsd/nfsctl.c | 28 +++ fs/nfsd/nfsd.h | 2 +- include/uapi/linux/nfsd_netlink.h | 110 +++++++++ net/sunrpc/netlink.c | 17 +- net/sunrpc/netlink.h | 3 +- 9 files changed, 835 insertions(+), 16 deletions(-)
Documentation/netlink/specs/nfsd.yaml +174 -0
@@ -6,7 +6,51 @@ uapi-header: linux/nfsd_netlink.h doc: NFSD configuration over generic netlink. +definitions: + - + type: flags + name: cache-type + entries: [svc_export] + - + type: flags + name: export-flags + doc: These flags are ordered to match the NFSEXP_* flags in include/linux/nfsd/export.h + entries: + - readonly + - insecure-port + - rootsquash + - allsquash + - async + - gathered-writes + - noreaddirplus + - security-label + - sign-fh + - nohide + - nosubtreecheck + - noauthnlm + - msnfs + - fsid + - crossmount + - noacl + - v4root + - pnfs + - + type: flags + name: xprtsec-mode + doc: These flags are ordered to match the NFSEXP_XPRTSEC_* flags in include/linux/nfsd/export.h + entries: + - none + - tls + - mtls + attribute-sets: + - + name: cache-notify + attributes: + - + name: cache-type + type: u32 + enum: cache-type - name: rpc-status attributes:
@@ -132,6 +176,103 @@ attribute-sets: - name: npools type: u32 + - + name: fslocation + attributes: + - + name: host + type: string + - + name: path + type: string + - + name: fslocations + attributes: + - + name: location + type: nest + nested-attributes: fslocation + multi-attr: true + - + name: auth-flavor + attributes: + - + name: pseudoflavor + type: u32 + - + name: flags + type: u32 + enum: export-flags + enum-as-flags: true + - + name: svc-export-req + attributes: + - + name: seqno + type: u64 + - + name: client + type: string + - + name: path + type: string + - + name: svc-export + attributes: + - + name: seqno + type: u64 + - + name: client + type: string + - + name: path + type: string + - + name: negative + type: flag + - + name: expiry + type: u64 + - + name: anon-uid + type: u32 + - + name: anon-gid + type: u32 + - + name: fslocations + type: nest + nested-attributes: fslocations + - + name: uuid + type: binary + - + name: secinfo + type: nest + nested-attributes: auth-flavor + multi-attr: true + - + name: xprtsec + type: u32 + enum: xprtsec-mode + multi-attr: true + - + name: flags + type: u32 + enum: export-flags + enum-as-flags: true + - + name: fsid + type: s32 + - + name: svc-export-reqs + attributes: + - + name: requests + type: nest + nested-attributes: svc-export + multi-attr: true operations: list:
@@ -233,3 +374,36 @@ operations: attributes: - mode - npools + - + name: cache-notify + doc: Notification that there are cache requests that need servicing + attribute-set: cache-notify + mcgrp: exportd + event: + attributes: + - cache-type + - + name: svc-export-get-reqs + doc: Dump all pending svc_export requests + attribute-set: svc-export-reqs + flags: [admin-perm] + dump: + request: + attributes: + - requests + - + name: svc-export-set-reqs + doc: Respond to one or more svc_export requests + attribute-set: svc-export-reqs + flags: [admin-perm] + do: + request: + attributes: + - requests + +mcast-groups: + list: + - + name: none + - + name: exportd
fs/nfsd/export.c +439 -4
478 lines not on this page · raw message
fs/nfsd/netlink.c +61 -0
88 lines not on this page · raw message
fs/nfsd/netlink.h +13 -0
@@ -13,7 +13,11 @@#include <uapi/linux/nfsd_netlink.h> /* Common nested types */ +extern const struct nla_policy nfsd_auth_flavor_nl_policy[NFSD_A_AUTH_FLAVOR_FLAGS +1 ]; +extern const struct nla_policy nfsd_fslocation_nl_policy[NFSD_A_FSLOCATION_PATH +1 ]; +extern const struct nla_policy nfsd_fslocations_nl_policy[NFSD_A_FSLOCATIONS_LOCATION +1 ];extern const struct nla_policy nfsd_sock_nl_policy[NFSD_A_SOCK_TRANSPORT_NAME +1 ]; +extern const struct nla_policy nfsd_svc_export_nl_policy[NFSD_A_SVC_EXPORT_FSID +1 ];extern const struct nla_policy nfsd_version_nl_policy[NFSD_A_VERSION_ENABLED +1 ]; int nfsd_nl_rpc_status_get_dumpit(struct sk_buff *skb,
@@ -26,6 +30,15 @@ int nfsd_nl_listener_set_doit(struct sk_buff *skb, struct genl_info *info);int nfsd_nl_listener_get_doit (struct sk_buff *skb,struct genl_info *info);int nfsd_nl_pool_mode_set_doit (struct sk_buff *skb,struct genl_info *info);int nfsd_nl_pool_mode_get_doit (struct sk_buff *skb,struct genl_info *info); +int nfsd_nl_svc_export_get_reqs_dumpit (struct sk_buff *skb, +struct netlink_callback *cb); +int nfsd_nl_svc_export_set_reqs_doit (struct sk_buff *skb, +struct genl_info *info); + +enum { +NFSD_NLGRP_NONE , +NFSD_NLGRP_EXPORTD , +};extern struct genl_family nfsd_nl_family;
fs/nfsd/nfsctl.c +28 -0
@@ -2215,6 +2215,34 @@ int nfsd_nl_pool_mode_get_doit(struct sk_buff *skb, struct genl_info *info)return err; } +int nfsd_cache_notify (struct cache_detail *cd,struct cache_head *h,u32 cache_type) +{ +struct genlmsghdr *hdr; +struct sk_buff *msg; + +if (!genl_has_listeners (&nfsd_nl_family, cd->net,NFSD_NLGRP_EXPORTD )) +return -ENOLINK ; + + msg =genlmsg_new (nla_total_size (sizeof (u32)),GFP_KERNEL ); +if (!msg) +return -ENOMEM ; + + hdr =genlmsg_put (msg,0 ,0 , &nfsd_nl_family,0 ,NFSD_CMD_CACHE_NOTIFY ); +if (!hdr) { +nlmsg_free (msg); +return -ENOMEM ; + } + +if (nla_put_u32 (msg,NFSD_A_CACHE_NOTIFY_CACHE_TYPE , cache_type)) { +nlmsg_free (msg); +return -ENOMEM ; + } + +genlmsg_end (msg, hdr); +return genlmsg_multicast_netns (&nfsd_nl_family, cd->net, msg,0 , +NFSD_NLGRP_EXPORTD ,GFP_KERNEL ); +} +/** * nfsd_net_init - Prepare the nfsd_net portion of a new net namespace * @net: a freshly-created network namespace
fs/nfsd/nfsd.h +1 -1
@@ -108,7 +108,7 @@ struct dentry *nfsd_client_mkdir(struct nfsd_net *nn, const struct tree_descr *, struct dentry **fdentries);void nfsd_client_rmdir (struct dentry *dentry); - +int nfsd_cache_notify (struct cache_detail *cd,struct cache_head *h,u32 cache_type);#if defined(CONFIG_NFSD_V2_ACL ) || defined(CONFIG_NFSD_V3_ACL )#ifdef CONFIG_NFSD_V2_ACL
include/uapi/linux/nfsd_netlink.h +110 -0
131 lines not on this page · raw message
net/sunrpc/netlink.c +8 -9
@@ -6,7 +6,6 @@#include <net/netlink.h> #include <net/genetlink.h> -#include <linux/sunrpc/cache.h> #include "netlink.h"
@@ -22,6 +21,14 @@ const struct nla_policy sunrpc_ip_map_nl_policy[SUNRPC_A_IP_MAP_EXPIRY + 1] = { [SUNRPC_A_IP_MAP_EXPIRY] = { .type = NLA_U64, }, }; +const struct nla_policy sunrpc_unix_gid_nl_policy[SUNRPC_A_UNIX_GID_EXPIRY +1 ] = { + [SUNRPC_A_UNIX_GID_SEQNO ] = { .type =NLA_U64 , }, + [SUNRPC_A_UNIX_GID_UID ] = { .type =NLA_U32 , }, + [SUNRPC_A_UNIX_GID_GIDS ] = { .type =NLA_U32 , }, + [SUNRPC_A_UNIX_GID_NEGATIVE ] = { .type =NLA_FLAG , }, + [SUNRPC_A_UNIX_GID_EXPIRY ] = { .type =NLA_U64 , }, +}; +/* SUNRPC_CMD_IP_MAP_GET_REQS - dump */ static const struct nla_policy sunrpc_ip_map_get_reqs_nl_policy[SUNRPC_A_IP_MAP_REQS_REQUESTS +1 ] = { [SUNRPC_A_IP_MAP_REQS_REQUESTS ] =NLA_POLICY_NESTED (sunrpc_ip_map_nl_policy),
@@ -32,14 +39,6 @@ static const struct nla_policy sunrpc_ip_map_set_reqs_nl_policy[SUNRPC_A_IP_MAP_ [SUNRPC_A_IP_MAP_REQS_REQUESTS] = NLA_POLICY_NESTED(sunrpc_ip_map_nl_policy), }; -const struct nla_policy sunrpc_unix_gid_nl_policy[SUNRPC_A_UNIX_GID_EXPIRY +1 ] = { - [SUNRPC_A_UNIX_GID_SEQNO ] = { .type =NLA_U64 , }, - [SUNRPC_A_UNIX_GID_UID ] = { .type =NLA_U32 , }, - [SUNRPC_A_UNIX_GID_GIDS ] = { .type =NLA_U32 , }, - [SUNRPC_A_UNIX_GID_NEGATIVE ] = { .type =NLA_FLAG , }, - [SUNRPC_A_UNIX_GID_EXPIRY ] = { .type =NLA_U64 , }, -}; -/* SUNRPC_CMD_UNIX_GID_GET_REQS - dump */ static const struct nla_policy sunrpc_unix_gid_get_reqs_nl_policy[SUNRPC_A_UNIX_GID_REQS_REQUESTS +1 ] = { [SUNRPC_A_UNIX_GID_REQS_REQUESTS ] =NLA_POLICY_NESTED (sunrpc_unix_gid_nl_policy),
net/sunrpc/netlink.h +1 -2
@@ -18,8 +18,7 @@ extern const struct nla_policy sunrpc_unix_gid_nl_policy[SUNRPC_A_UNIX_GID_EXPIRint sunrpc_nl_ip_map_get_reqs_dumpit (struct sk_buff *skb,struct netlink_callback *cb); -int sunrpc_nl_ip_map_set_reqs_doit (struct sk_buff *skb, -struct genl_info *info); +int sunrpc_nl_ip_map_set_reqs_doit (struct sk_buff *skb,struct genl_info *info);int sunrpc_nl_unix_gid_get_reqs_dumpit (struct sk_buff *skb,struct netlink_callback *cb); int sunrpc_nl_unix_gid_set_reqs_doit(struct sk_buff *skb,
Signature · 1 line
2.53.0
Chuck Lever
maintainerRe: [PATCH v2 10/13] nfsd: add netlink upcall for the svc_export cache
Quoted 99 lines · Jeff Layton
Add netlink-based cache upcall support for the
svc_export(nfsd.export) cache toDocumentation/netlink/specs/nfsd.yamland regenerate the resulting files.Documentation/netlink/specs/nfsd.yaml +0
-0
8ab43c8253b2e83bcc178c3f4fe8c41c2997d153..709751502f8b56bd4b68462fa15337df5e3e035e100644Documentation/netlink/specs/nfsd.yaml +9
-0@@ -6,7 +6,51 @@ uapi-header: linux/nfsd_netlink.h doc: NFSD configuration over generic netlink. +definitions: + - + type: flags + name: cache-type + entries: [svc_export] + - + type: flags + name: export-flags + doc: These flags are ordered to match the NFSEXP_* flags in
include/linux/nfsd/export.hDocumentation/netlink/specs/nfsd.yaml +23
-0+ entries: + - readonly + - insecure-port + - rootsquash + - allsquash + - async + - gathered-writes + - noreaddirplus + - security-label + - sign-fh + - nohide + - nosubtreecheck + - noauthnlm + - msnfs + - fsid + - crossmount + - noacl + - v4root + - pnfs + - + type: flags + name: xprtsec-mode + doc: These flags are ordered to match the NFSEXP_XPRTSEC_* flagsin
include/linux/nfsd/export.hDocumentation/netlink/specs/nfsd.yaml +42
-0+ entries: + - none + - tls + - mtls + attribute-sets: + - + name: cache-notify + attributes: + - + name: cache-type + type: u32 + enum: cache-type - name: rpc-status attributes:@@ -132,6 +176,103 @@ attribute-sets: - name: npools type: u32 + - + name: fslocation + attributes: + - + name: host + type: string + - + name: path + type: string + - + name: fslocations + attributes: + - + name: location + type: nest + nested-attributes: fslocation + multi-attr: true + - + name: auth-flavor + attributes: + - + name: pseudoflavor + type: u32 + - + name: flags + type: u32 + enum: export-flags + enum-as-flags: true + - + name: svc-export-req
Documentation/netlink/specs/nfsd.yaml attribute-sets: · line 218
Quoted 10 lines
Documentation/netlink/specs/nfsd.yaml +10
-0+ attributes: + - + name: seqno + type: u64 + - + name: client + type: string + - + name: path + type: string
Is the svc-export-req attribute set used for anything?
Quoted 98 lines
Documentation/netlink/specs/nfsd.yaml +60
-0+ - + name: svc-export + attributes: + - + name: seqno + type: u64 + - + name: client + type: string + - + name: path + type: string + - + name: negative + type: flag + - + name: expiry + type: u64 + - + name: anon-uid + type: u32 + - + name: anon-gid + type: u32 + - + name: fslocations + type: nest + nested-attributes: fslocations + - + name: uuid + type: binary + - + name: secinfo + type: nest + nested-attributes: auth-flavor + multi-attr: true + - + name: xprtsec + type: u32 + enum: xprtsec-mode + multi-attr: true + - + name: flags + type: u32 + enum: export-flags + enum-as-flags: true + - + name: fsid + type: s32 + - + name: svc-export-reqs + attributes: + - + name: requests + type: nest + nested-attributes: svc-export + multi-attr: true operations: list:@@ -233,3 +374,36 @@ operations: attributes: - mode - npools + - + name: cache-notify + doc: Notification that there are cache requests that needservicing
Documentation/netlink/specs/nfsd.yaml +30
-0+ attribute-set: cache-notify + mcgrp: exportd + event: + attributes: + - cache-type + - + name: svc-export-get-reqs + doc: Dump all pending svc_export requests + attribute-set: svc-export-reqs + flags: [admin-perm] + dump: + request: + attributes: + - requests + - + name: svc-export-set-reqs + doc: Respond to one or more svc_export requests + attribute-set: svc-export-reqs + flags: [admin-perm] + do: + request: + attributes: + - requests + +mcast-groups: + list: + - + name: none + - + name: exportd
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerRe: [PATCH v2 10/13] nfsd: add netlink upcall for the svc_export cache
Quoted 14 lines · Chuck Lever
Documentation/netlink/specs/nfsd.yaml attribute-sets: · line 218
Quoted 13 lines
Documentation/netlink/specs/nfsd.yaml +12
-0+ - + name: svc-export-req + attributes: + - + name: seqno + type: u64 + - + name: client + type: string + - + name: path + type: string
Quoted 3 lines
Is the svc-export-req attribute set used for anything?
No, good catch.
That's a holdover from an earlier version that had a separate attribute set for the up and downcalls. It's not needed in the latest version.
It should be fine to remove it and regenerate the headers. The result builds fine without it. I've pushed a fixed patch to the 'exportd-nl' branch in my tree. You can fix it up or I can resend if you prefer.
Thanks,
Signature · 1 line
Jeff Layton <[email protected]>
Chuck Lever
maintainerRe: [PATCH v2 10/13] nfsd: add netlink upcall for the svc_export cache
Quoted 19 lines · Jeff Layton
Quoted 14 lines · Chuck Lever
Documentation/netlink/specs/nfsd.yaml attribute-sets: · line 218
Quoted 13 lines
Documentation/netlink/specs/nfsd.yaml +12
-0+ - + name: svc-export-req + attributes: + - + name: seqno + type: u64 + - + name: client + type: string + - + name: path + type: stringQuoted 3 lines
Is the svc-export-req attribute set used for anything?
Quoted 8 lines
No, good catch.
That's a holdover from an earlier version that had a separate attribute set for the up and downcalls. It's not needed in the latest version.
It should be fine to remove it and regenerate the headers. The result builds fine without it. I've pushed a fixed patch to the 'exportd-nl' branch in my tree. You can fix it up or I can resend if you prefer.
Thanks for jumping on that. Let's wait to see if there are other review comments.
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerPATCH v2 11/13 nfsd: add netlink upcall for the nfsd.fh cache
In reply to Jeff LaytonAdd netlink-based cache upcall support for the expkey (nfsd.fh) cache, following the same pattern as the existing svc_export netlink support.
Add expkey to the cache-type enum, a new expkey attribute-set with client, fsidtype, fsid, negative, expiry, and path fields, and the expkey-get-reqs / expkey-set-reqs operations to the nfsd YAML spec and generated headers.
Implement nfsd_nl_expkey_get_reqs_dumpit() which snapshots pending expkey cache requests and sends each entry's seqno, client name, fsidtype, and fsid over netlink.
Implement nfsd_nl_expkey_set_reqs_doit() which parses expkey cache responses from userspace (client, fsidtype, fsid, expiry, and path or negative flag) and updates the cache via svc_expkey_lookup() / svc_expkey_update().
Wire up the expkey_notify() callback in svc_expkey_cache_template so cache misses trigger NFSD_CMD_CACHE_NOTIFY multicast events with NFSD_CACHE_TYPE_EXPKEY.
--- Documentation/netlink/specs/nfsd.yaml | 52 ++++++- fs/nfsd/export.c | 266 ++++++++++++++++++++++++++++++++++ fs/nfsd/netlink.c | 34 +++++ fs/nfsd/netlink.h | 4 + include/uapi/linux/nfsd_netlink.h | 23 +++ 5 files changed, 378 insertions(+), 1 deletion(-)
Documentation/netlink/specs/nfsd.yaml +51 -1
@@ -10,7 +10,7 @@ definitions: - type: flags name: cache-type - entries: [svc_export] + entries: [svc_export, expkey] - type: flags name: export-flags
@@ -273,6 +273,38 @@ attribute-sets: type: nest nested-attributes: svc-export multi-attr: true + - + name: expkey + attributes: + - + name: seqno + type: u64 + - + name: client + type: string + - + name: fsidtype + type: u8 + - + name: fsid + type: binary + - + name: negative + type: flag + - + name: expiry + type: u64 + - + name: path + type: string + - + name: expkey-reqs + attributes: + - + name: requests + type: nest + nested-attributes: expkey + multi-attr: true operations: list:
@@ -400,6 +432,24 @@ operations: request: attributes: - requests + - + name: expkey-get-reqs + doc: Dump all pending expkey requests + attribute-set: expkey-reqs + flags: [admin-perm] + dump: + request: + attributes: + - requests + - + name: expkey-set-reqs + doc: Respond to one or more expkey requests + attribute-set: expkey-reqs + flags: [admin-perm] + do: + request: + attributes: + - requests mcast-groups: list:
fs/nfsd/export.c +266 -0
284 lines not on this page · raw message
fs/nfsd/netlink.c +34 -0
@@ -17,6 +17,16 @@ const struct nla_policy nfsd_auth_flavor_nl_policy[NFSD_A_AUTH_FLAVOR_FLAGS + 1] [NFSD_A_AUTH_FLAVOR_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0x3ffff), }; +const struct nla_policy nfsd_expkey_nl_policy[NFSD_A_EXPKEY_PATH +1 ] = { + [NFSD_A_EXPKEY_SEQNO ] = { .type =NLA_U64 , }, + [NFSD_A_EXPKEY_CLIENT ] = { .type =NLA_NUL_STRING , }, + [NFSD_A_EXPKEY_FSIDTYPE ] = { .type =NLA_U8 , }, + [NFSD_A_EXPKEY_FSID ] = { .type =NLA_BINARY , }, + [NFSD_A_EXPKEY_NEGATIVE ] = { .type =NLA_FLAG , }, + [NFSD_A_EXPKEY_EXPIRY ] = { .type =NLA_U64 , }, + [NFSD_A_EXPKEY_PATH ] = { .type =NLA_NUL_STRING , }, +}; +const struct nla_policy nfsd_fslocation_nl_policy[NFSD_A_FSLOCATION_PATH +1 ] = { [NFSD_A_FSLOCATION_HOST ] = { .type =NLA_NUL_STRING , }, [NFSD_A_FSLOCATION_PATH ] = { .type =NLA_NUL_STRING , },
@@ -88,6 +98,16 @@ static const struct nla_policy nfsd_svc_export_set_reqs_nl_policy[NFSD_A_SVC_EXP [NFSD_A_SVC_EXPORT_REQS_REQUESTS] = NLA_POLICY_NESTED(nfsd_svc_export_nl_policy), }; +/* NFSD_CMD_EXPKEY_GET_REQS - dump */ +static const struct nla_policy nfsd_expkey_get_reqs_nl_policy[NFSD_A_EXPKEY_REQS_REQUESTS +1 ] = { + [NFSD_A_EXPKEY_REQS_REQUESTS ] =NLA_POLICY_NESTED (nfsd_expkey_nl_policy), +}; + +/* NFSD_CMD_EXPKEY_SET_REQS - do */ +static const struct nla_policy nfsd_expkey_set_reqs_nl_policy[NFSD_A_EXPKEY_REQS_REQUESTS +1 ] = { + [NFSD_A_EXPKEY_REQS_REQUESTS ] =NLA_POLICY_NESTED (nfsd_expkey_nl_policy), +}; +/* Ops table for nfsd */ static const struct genl_split_ops nfsd_nl_ops[] = { {
@@ -157,6 +177,20 @@ static const struct genl_split_ops nfsd_nl_ops[] = { .maxattr = NFSD_A_SVC_EXPORT_REQS_REQUESTS, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, + { + .cmd = NFSD_CMD_EXPKEY_GET_REQS, + .dumpit = nfsd_nl_expkey_get_reqs_dumpit, + .policy = nfsd_expkey_get_reqs_nl_policy, + .maxattr = NFSD_A_EXPKEY_REQS_REQUESTS, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP, + }, + { + .cmd = NFSD_CMD_EXPKEY_SET_REQS, + .doit = nfsd_nl_expkey_set_reqs_doit, + .policy = nfsd_expkey_set_reqs_nl_policy, + .maxattr = NFSD_A_EXPKEY_REQS_REQUESTS, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, }; static const struct genl_multicast_group nfsd_nl_mcgrps[] = {
fs/nfsd/netlink.h +4 -0
@@ -14,6 +14,7 @@/* Common nested types */ extern const struct nla_policy nfsd_auth_flavor_nl_policy[NFSD_A_AUTH_FLAVOR_FLAGS +1 ]; +extern const struct nla_policy nfsd_expkey_nl_policy[NFSD_A_EXPKEY_PATH +1 ];extern const struct nla_policy nfsd_fslocation_nl_policy[NFSD_A_FSLOCATION_PATH +1 ];extern const struct nla_policy nfsd_fslocations_nl_policy[NFSD_A_FSLOCATIONS_LOCATION +1 ];extern const struct nla_policy nfsd_sock_nl_policy[NFSD_A_SOCK_TRANSPORT_NAME +1 ];
@@ -34,6 +35,9 @@ int nfsd_nl_svc_export_get_reqs_dumpit(struct sk_buff *skb, struct netlink_callback *cb);int nfsd_nl_svc_export_set_reqs_doit (struct sk_buff *skb,struct genl_info *info); +int nfsd_nl_expkey_get_reqs_dumpit (struct sk_buff *skb, +struct netlink_callback *cb); +int nfsd_nl_expkey_set_reqs_doit (struct sk_buff *skb,struct genl_info *info);enum {NFSD_NLGRP_NONE ,
include/uapi/linux/nfsd_netlink.h +23 -0
@@ -12,6 +12,7 @@enum nfsd_cache_type {NFSD_CACHE_TYPE_SVC_EXPORT =1 , +NFSD_CACHE_TYPE_EXPKEY =2 , };/*
@@ -185,6 +186,26 @@ enum {NFSD_A_SVC_EXPORT_REQS_MAX = (__NFSD_A_SVC_EXPORT_REQS_MAX -1 ) }; +enum { +NFSD_A_EXPKEY_SEQNO =1 , +NFSD_A_EXPKEY_CLIENT , +NFSD_A_EXPKEY_FSIDTYPE , +NFSD_A_EXPKEY_FSID , +NFSD_A_EXPKEY_NEGATIVE , +NFSD_A_EXPKEY_EXPIRY , +NFSD_A_EXPKEY_PATH , + + __NFSD_A_EXPKEY_MAX, +NFSD_A_EXPKEY_MAX = (__NFSD_A_EXPKEY_MAX -1 ) +}; + +enum { +NFSD_A_EXPKEY_REQS_REQUESTS =1 , + + __NFSD_A_EXPKEY_REQS_MAX, +NFSD_A_EXPKEY_REQS_MAX = (__NFSD_A_EXPKEY_REQS_MAX -1 ) +}; +enum {NFSD_CMD_RPC_STATUS_GET =1 ,NFSD_CMD_THREADS_SET ,
@@ -198,6 +219,8 @@ enum {NFSD_CMD_CACHE_NOTIFY ,NFSD_CMD_SVC_EXPORT_GET_REQS ,NFSD_CMD_SVC_EXPORT_SET_REQS , +NFSD_CMD_EXPKEY_GET_REQS , +NFSD_CMD_EXPKEY_SET_REQS , __NFSD_CMD_MAX,NFSD_CMD_MAX = (__NFSD_CMD_MAX -1 )
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 12/13 sunrpc: add SUNRPC_CMD_CACHE_FLUSH netlink command
In reply to Jeff LaytonAdd a new SUNRPC_CMD_CACHE_FLUSH generic netlink command that allows userspace to flush the sunrpc auth caches (ip_map and unix_gid) without writing to /proc/net/rpc/*/flush.
An optional SUNRPC_A_CACHE_FLUSH_MASK u32 attribute selects which caches to flush (bit 1 = ip_map, bit 2 = unix_gid). If the attribute is omitted, all sunrpc caches are flushed.
This is used by exportfs to replace its /proc-based cache_flush() with a netlink equivalent, with /proc fallback for older kernels.
--- Documentation/netlink/specs/sunrpc_cache.yaml | 17 ++++++++++++++ include/uapi/linux/sunrpc_netlink.h | 8 +++++++ net/sunrpc/netlink.c | 12 ++++++++++ net/sunrpc/netlink.h | 1 + net/sunrpc/svcauth_unix.c | 32 +++++++++++++++++++++++++++ 5 files changed, 70 insertions(+)
Documentation/netlink/specs/sunrpc_cache.yaml +17 -0
@@ -76,6 +76,14 @@ attribute-sets: type: nest nested-attributes: unix-gid multi-attr: true + - + name: cache-flush + attributes: + - + name: mask + type: u32 + enum: cache-type + enum-as-flags: true operations: list:
@@ -123,6 +131,15 @@ operations: request: attributes: - requests + - + name: cache-flush + doc: Flush sunrpc caches (ip_map and/or unix_gid) + attribute-set: cache-flush + flags: [admin-perm] + do: + request: + attributes: + - mask mcast-groups: list:
include/uapi/linux/sunrpc_netlink.h +8 -0
@@ -59,12 +59,20 @@ enum {SUNRPC_A_UNIX_GID_REQS_MAX = (__SUNRPC_A_UNIX_GID_REQS_MAX -1 ) }; +enum { +SUNRPC_A_CACHE_FLUSH_MASK =1 , + + __SUNRPC_A_CACHE_FLUSH_MAX, +SUNRPC_A_CACHE_FLUSH_MAX = (__SUNRPC_A_CACHE_FLUSH_MAX -1 ) +}; +enum {SUNRPC_CMD_CACHE_NOTIFY =1 ,SUNRPC_CMD_IP_MAP_GET_REQS ,SUNRPC_CMD_IP_MAP_SET_REQS ,SUNRPC_CMD_UNIX_GID_GET_REQS ,SUNRPC_CMD_UNIX_GID_SET_REQS , +SUNRPC_CMD_CACHE_FLUSH , __SUNRPC_CMD_MAX,SUNRPC_CMD_MAX = (__SUNRPC_CMD_MAX -1 )
net/sunrpc/netlink.c +12 -0
@@ -49,6 +49,11 @@ static const struct nla_policy sunrpc_unix_gid_set_reqs_nl_policy[SUNRPC_A_UNIX_ [SUNRPC_A_UNIX_GID_REQS_REQUESTS] = NLA_POLICY_NESTED(sunrpc_unix_gid_nl_policy), }; +/* SUNRPC_CMD_CACHE_FLUSH - do */ +static const struct nla_policy sunrpc_cache_flush_nl_policy[SUNRPC_A_CACHE_FLUSH_MASK +1 ] = { + [SUNRPC_A_CACHE_FLUSH_MASK ] =NLA_POLICY_MASK (NLA_U32 ,0x3 ), +}; +/* Ops table for sunrpc */ static const struct genl_split_ops sunrpc_nl_ops[] = { {
@@ -79,6 +84,13 @@ static const struct genl_split_ops sunrpc_nl_ops[] = { .maxattr = SUNRPC_A_UNIX_GID_REQS_REQUESTS, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, + { + .cmd = SUNRPC_CMD_CACHE_FLUSH, + .doit = sunrpc_nl_cache_flush_doit, + .policy = sunrpc_cache_flush_nl_policy, + .maxattr = SUNRPC_A_CACHE_FLUSH_MASK, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, };static const struct genl_multicast_group sunrpc_nl_mcgrps[] = {
net/sunrpc/netlink.h +1 -0
@@ -23,6 +23,7 @@ int sunrpc_nl_unix_gid_get_reqs_dumpit(struct sk_buff *skb, struct netlink_callback *cb);int sunrpc_nl_unix_gid_set_reqs_doit (struct sk_buff *skb,struct genl_info *info); +int sunrpc_nl_cache_flush_doit (struct sk_buff *skb,struct genl_info *info);enum {SUNRPC_NLGRP_NONE ,
net/sunrpc/svcauth_unix.c +32 -0
@@ -818,6 +818,38 @@ int sunrpc_nl_unix_gid_set_reqs_doit(struct sk_buff *skb,return ret; } +/** +* sunrpc_nl_cache_flush_doit - flush sunrpc caches via netlink +* @skb: reply buffer +* @info: netlink metadata and command arguments +* +* Flush the ip_map and/or unix_gid caches. If SUNRPC_A_CACHE_FLUSH_MASK +* is provided, only flush the caches indicated by the bitmask (bit 1 = +* ip_map, bit 2 = unix_gid). If omitted, flush both. +* +* Return 0 on success or a negative errno. +*/ +int sunrpc_nl_cache_flush_doit (struct sk_buff *skb,struct genl_info *info) +{ +struct sunrpc_net *sn; +u32 mask = ~0U ; + + sn =net_generic (genl_info_net (info), sunrpc_net_id); + +if (info->attrs[SUNRPC_A_CACHE_FLUSH_MASK ]) + mask =nla_get_u32 (info->attrs[SUNRPC_A_CACHE_FLUSH_MASK ]); + +if ((mask &SUNRPC_CACHE_TYPE_IP_MAP ) && + sn->ip_map_cache) +cache_purge (sn->ip_map_cache); + +if ((mask &SUNRPC_CACHE_TYPE_UNIX_GID ) && + sn->unix_gid_cache) +cache_purge (sn->unix_gid_cache); + +return 0 ; +} +static const struct cache_detail unix_gid_cache_template = { .owner =THIS_MODULE , .hash_size =GID_HASHMAX ,
Signature · 1 line
2.53.0
Jeff Layton
maintainerPATCH v2 13/13 nfsd: add NFSD_CMD_CACHE_FLUSH netlink command
In reply to Jeff LaytonAdd a new NFSD_CMD_CACHE_FLUSH generic netlink command that allows userspace to flush the nfsd export caches (svc_export and expkey) without writing to /proc/net/rpc/*/flush.
An optional NFSD_A_CACHE_FLUSH_MASK u32 attribute selects which caches to flush (bit 1 = svc_export, bit 2 = expkey). If the attribute is omitted, all nfsd caches are flushed.
This is used by exportfs to replace its /proc-based cache_flush() with a netlink equivalent, with /proc fallback for older kernels.
--- Documentation/netlink/specs/nfsd.yaml | 17 +++++++++++++++++ fs/nfsd/netlink.c | 12 ++++++++++++ fs/nfsd/netlink.h | 1 + fs/nfsd/nfsctl.c | 36 +++++++++++++++++++++++++++++++++++ include/uapi/linux/nfsd_netlink.h | 8 ++++++++ 5 files changed, 74 insertions(+)
Documentation/netlink/specs/nfsd.yaml +17 -0
@@ -305,6 +305,14 @@ attribute-sets: type: nest nested-attributes: expkey multi-attr: true + - + name: cache-flush + attributes: + - + name: mask + type: u32 + enum: cache-type + enum-as-flags: true operations: list:
@@ -450,6 +458,15 @@ operations: request: attributes: - requests + - + name: cache-flush + doc: Flush nfsd caches (svc_export and/or expkey) + attribute-set: cache-flush + flags: [admin-perm] + do: + request: + attributes: + - mask mcast-groups: list:
fs/nfsd/netlink.c +12 -0
@@ -108,6 +108,11 @@ static const struct nla_policy nfsd_expkey_set_reqs_nl_policy[NFSD_A_EXPKEY_REQS [NFSD_A_EXPKEY_REQS_REQUESTS] = NLA_POLICY_NESTED(nfsd_expkey_nl_policy), }; +/* NFSD_CMD_CACHE_FLUSH - do */ +static const struct nla_policy nfsd_cache_flush_nl_policy[NFSD_A_CACHE_FLUSH_MASK +1 ] = { + [NFSD_A_CACHE_FLUSH_MASK ] =NLA_POLICY_MASK (NLA_U32 ,0x3 ), +}; +/* Ops table for nfsd */ static const struct genl_split_ops nfsd_nl_ops[] = { {
@@ -191,6 +196,13 @@ static const struct genl_split_ops nfsd_nl_ops[] = { .maxattr = NFSD_A_EXPKEY_REQS_REQUESTS, .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, }, + { + .cmd = NFSD_CMD_CACHE_FLUSH, + .doit = nfsd_nl_cache_flush_doit, + .policy = nfsd_cache_flush_nl_policy, + .maxattr = NFSD_A_CACHE_FLUSH_MASK, + .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, + }, };static const struct genl_multicast_group nfsd_nl_mcgrps[] = {
fs/nfsd/netlink.h +1 -0
@@ -38,6 +38,7 @@ int nfsd_nl_svc_export_set_reqs_doit(struct sk_buff *skb,int nfsd_nl_expkey_get_reqs_dumpit (struct sk_buff *skb,struct netlink_callback *cb);int nfsd_nl_expkey_set_reqs_doit (struct sk_buff *skb,struct genl_info *info); +int nfsd_nl_cache_flush_doit (struct sk_buff *skb,struct genl_info *info);enum {NFSD_NLGRP_NONE ,
fs/nfsd/nfsctl.c +36 -0
@@ -10,6 +10,7 @@#include <linux/ctype.h> #include <linux/fs_context.h> +#include <linux/sunrpc/cache.h> #include <linux/sunrpc/svcsock.h> #include <linux/lockd/bind.h> #include <linux/sunrpc/addr.h>
@@ -2215,6 +2216,41 @@ int nfsd_nl_pool_mode_get_doit(struct sk_buff *skb, struct genl_info *info)return err; } +/** +* nfsd_nl_cache_flush_doit - flush nfsd caches via netlink +* @skb: reply buffer +* @info: netlink metadata and command arguments +* +* Flush the svc_export and/or expkey caches. If NFSD_A_CACHE_FLUSH_MASK +* is provided, only flush the caches indicated by the bitmask (bit 0 = +* svc_export, bit 1 = expkey). If omitted, flush both. +* +* Return 0 on success or a negative errno. +*/ +int nfsd_nl_cache_flush_doit (struct sk_buff *skb,struct genl_info *info) +{ +struct net *net =genl_info_net (info); +struct nfsd_net *nn =net_generic (net, nfsd_net_id); +u32 mask = ~0U ; + +if (info->attrs[NFSD_A_CACHE_FLUSH_MASK ]) + mask =nla_get_u32 (info->attrs[NFSD_A_CACHE_FLUSH_MASK ]); + +mutex_lock (&nfsd_mutex); + +if ((mask &NFSD_CACHE_TYPE_SVC_EXPORT ) && + nn->svc_export_cache) +cache_purge (nn->svc_export_cache); + +if ((mask &NFSD_CACHE_TYPE_EXPKEY ) && + nn->svc_expkey_cache) +cache_purge (nn->svc_expkey_cache); + +mutex_unlock (&nfsd_mutex); + +return 0 ; +} +int nfsd_cache_notify (struct cache_detail *cd,struct cache_head *h,u32 cache_type) {struct genlmsghdr *hdr;
include/uapi/linux/nfsd_netlink.h +8 -0
@@ -206,6 +206,13 @@ enum {NFSD_A_EXPKEY_REQS_MAX = (__NFSD_A_EXPKEY_REQS_MAX -1 ) }; +enum { +NFSD_A_CACHE_FLUSH_MASK =1 , + + __NFSD_A_CACHE_FLUSH_MAX, +NFSD_A_CACHE_FLUSH_MAX = (__NFSD_A_CACHE_FLUSH_MAX -1 ) +}; +enum {NFSD_CMD_RPC_STATUS_GET =1 ,NFSD_CMD_THREADS_SET ,
@@ -221,6 +228,7 @@ enum {NFSD_CMD_SVC_EXPORT_SET_REQS ,NFSD_CMD_EXPKEY_GET_REQS ,NFSD_CMD_EXPKEY_SET_REQS , +NFSD_CMD_CACHE_FLUSH , __NFSD_CMD_MAX,NFSD_CMD_MAX = (__NFSD_CMD_MAX -1 )
Signature · 1 line
2.53.0
Chuck Lever
maintainerFrom: Chuck Lever <[email protected]>
Quoted 6 lines · Jeff Layton
This version should address most of Chuck's review comments. The userland patch series is unchanged. I've added the netdev folks this time too in order to get more experienced eyes on the netlink bits.
Original cover letter follows:
Quoted 7 lines
mountd/exportd use the sunrpc cache mechanism for some of its internal caches that are populated by userland. These currently use some very antiquated interfaces in /proc to handle upcalls and downcalls. While it has worked well for decades and is relatively stable, it has some problems.
[...]
Applied to nfsd-testing, thanks!
[01/13] nfsd: move struct nfsd_genl_rqstp to nfsctl.c
commit: 9255d64c38df86b504fd9928c4599f506e0e9a5f
[02/13] sunrpc: rename sunrpc_cache_pipe_upcall() to sunrpc_cache_upcall()
commit: 296a9a594de51e5d4f875a56ece878dab3a4afd0
[03/13] sunrpc: rename sunrpc_cache_pipe_upcall_timeout()
commit: 4695f0a549afde54672311ff3b70e4a8c9f67ee4
[04/13] sunrpc: rename cache_pipe_upcall() to cache_do_upcall()
commit: 9699085b61700e040ddb500828cf5430e0a9f7f3
[05/13] sunrpc: add a cache_notify callback
commit: 0f2e29eb49430fba0ddcc9f0a8fb10334751e9f8
[06/13] sunrpc: add helpers to count and snapshot pending cache requests
commit: d5d861c2a0340a70c869b5688c57741564956875
[07/13] sunrpc: add a generic netlink family for cache upcalls
commit: 44139e2b768b1bfd9fcc8fbefdcc5a425ef448cf
[08/13] sunrpc: add netlink upcall for the auth.unix.ip cache
commit: 8f056ebed4272238de8f003925d91bdb4e6726ae
[09/13] sunrpc: add netlink upcall for the auth.unix.gid cache
commit: 6bfbaa6d611bcde1d62435982a2d8895ca0082e8
[10/13] nfsd: add netlink upcall for the svc_export cache
commit: cfefcaec25438cc82344ac3ea22c474798e05531
[11/13] nfsd: add netlink upcall for the nfsd.fh cache
commit: dbd292f2d787b7ae0d471da9783996eb8eea759e
[12/13] sunrpc: add SUNRPC_CMD_CACHE_FLUSH netlink command
commit: e91b082fdae41cdeb73772aeeee2f61937d14c65
[13/13] nfsd: add NFSD_CMD_CACHE_FLUSH netlink command
commit: 895a916e2c31d86a11b867c16ac0e4e167298e5e--
Chuck Lever