|
33 | 33 | #include <linux/sunrpc/cache.h> |
34 | 34 | #include <linux/sunrpc/stats.h> |
35 | 35 | #include <linux/sunrpc/rpc_pipe_fs.h> |
| 36 | +#include <net/genetlink.h> |
36 | 37 | #include <trace/events/sunrpc.h> |
37 | 38 |
|
38 | 39 | #include "netns.h" |
| 40 | +#include "netlink.h" |
39 | 41 | #include "fail.h" |
40 | 42 |
|
41 | 43 | #define RPCDBG_FACILITY RPCDBG_CACHE |
@@ -1963,3 +1965,45 @@ int sunrpc_cache_requests_snapshot(struct cache_detail *cd, |
1963 | 1965 | return i; |
1964 | 1966 | } |
1965 | 1967 | EXPORT_SYMBOL_GPL(sunrpc_cache_requests_snapshot); |
| 1968 | + |
| 1969 | +/** |
| 1970 | + * sunrpc_cache_notify - send a netlink notification for a cache event |
| 1971 | + * @cd: cache_detail for the cache |
| 1972 | + * @h: cache_head entry (unused, reserved for future use) |
| 1973 | + * @cache_type: cache type identifier (e.g. SUNRPC_CACHE_TYPE_UNIX_GID) |
| 1974 | + * |
| 1975 | + * Sends a SUNRPC_CMD_CACHE_NOTIFY multicast message on the "exportd" |
| 1976 | + * group if any listeners are present. Returns 0 on success or a |
| 1977 | + * negative errno. |
| 1978 | + */ |
| 1979 | +int sunrpc_cache_notify(struct cache_detail *cd, struct cache_head *h, |
| 1980 | + u32 cache_type) |
| 1981 | +{ |
| 1982 | + struct genlmsghdr *hdr; |
| 1983 | + struct sk_buff *msg; |
| 1984 | + |
| 1985 | + if (!genl_has_listeners(&sunrpc_nl_family, cd->net, |
| 1986 | + SUNRPC_NLGRP_EXPORTD)) |
| 1987 | + return -ENOLINK; |
| 1988 | + |
| 1989 | + msg = genlmsg_new(nla_total_size(sizeof(u32)), GFP_KERNEL); |
| 1990 | + if (!msg) |
| 1991 | + return -ENOMEM; |
| 1992 | + |
| 1993 | + hdr = genlmsg_put(msg, 0, 0, &sunrpc_nl_family, 0, |
| 1994 | + SUNRPC_CMD_CACHE_NOTIFY); |
| 1995 | + if (!hdr) { |
| 1996 | + nlmsg_free(msg); |
| 1997 | + return -ENOMEM; |
| 1998 | + } |
| 1999 | + |
| 2000 | + if (nla_put_u32(msg, SUNRPC_A_CACHE_NOTIFY_CACHE_TYPE, cache_type)) { |
| 2001 | + nlmsg_free(msg); |
| 2002 | + return -ENOMEM; |
| 2003 | + } |
| 2004 | + |
| 2005 | + genlmsg_end(msg, hdr); |
| 2006 | + return genlmsg_multicast_netns(&sunrpc_nl_family, cd->net, msg, 0, |
| 2007 | + SUNRPC_NLGRP_EXPORTD, GFP_KERNEL); |
| 2008 | +} |
| 2009 | +EXPORT_SYMBOL_GPL(sunrpc_cache_notify); |
0 commit comments