Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/lockd/mon.c |
| 3 | * |
| 4 | * The kernel statd client. |
| 5 | * |
| 6 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> |
| 7 | */ |
| 8 | |
| 9 | #include <linux/types.h> |
| 10 | #include <linux/utsname.h> |
| 11 | #include <linux/kernel.h> |
| 12 | #include <linux/sunrpc/clnt.h> |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 13 | #include <linux/sunrpc/xprtsock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/sunrpc/svc.h> |
| 15 | #include <linux/lockd/lockd.h> |
| 16 | #include <linux/lockd/sm_inter.h> |
| 17 | |
| 18 | |
| 19 | #define NLMDBG_FACILITY NLMDBG_MONITOR |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 20 | #define NSM_PROGRAM 100024 |
| 21 | #define NSM_VERSION 1 |
| 22 | |
| 23 | enum { |
| 24 | NSMPROC_NULL, |
| 25 | NSMPROC_STAT, |
| 26 | NSMPROC_MON, |
| 27 | NSMPROC_UNMON, |
| 28 | NSMPROC_UNMON_ALL, |
| 29 | NSMPROC_SIMU_CRASH, |
| 30 | NSMPROC_NOTIFY, |
| 31 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Chuck Lever | 9c1bfd0 | 2008-12-05 19:01:59 -0500 | [diff] [blame] | 33 | struct nsm_args { |
| 34 | __be32 addr; /* remote address */ |
| 35 | u32 prog; /* RPC callback info */ |
| 36 | u32 vers; |
| 37 | u32 proc; |
| 38 | |
| 39 | char *mon_name; |
| 40 | }; |
| 41 | |
| 42 | struct nsm_res { |
| 43 | u32 status; |
| 44 | u32 state; |
| 45 | }; |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | static struct rpc_clnt * nsm_create(void); |
| 48 | |
| 49 | static struct rpc_program nsm_program; |
| 50 | |
| 51 | /* |
| 52 | * Local NSM state |
| 53 | */ |
Olaf Kirch | 460f5ca | 2006-10-04 02:16:03 -0700 | [diff] [blame] | 54 | int nsm_local_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | /* |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 57 | * Common procedure for NSMPROC_MON/NSMPROC_UNMON calls |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | */ |
| 59 | static int |
Olaf Kirch | 9502c52 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 60 | nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
| 62 | struct rpc_clnt *clnt; |
| 63 | int status; |
Chuck Lever | a484675 | 2008-12-04 14:20:23 -0500 | [diff] [blame] | 64 | struct nsm_args args = { |
| 65 | .addr = nsm_addr_in(nsm)->sin_addr.s_addr, |
| 66 | .prog = NLM_PROGRAM, |
| 67 | .vers = 3, |
| 68 | .proc = NLMPROC_NSM_NOTIFY, |
Chuck Lever | 29ed140 | 2008-12-04 14:20:46 -0500 | [diff] [blame] | 69 | .mon_name = nsm->sm_mon_name, |
Chuck Lever | a484675 | 2008-12-04 14:20:23 -0500 | [diff] [blame] | 70 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 71 | struct rpc_message msg = { |
| 72 | .rpc_argp = &args, |
| 73 | .rpc_resp = res, |
| 74 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | clnt = nsm_create(); |
| 77 | if (IS_ERR(clnt)) { |
| 78 | status = PTR_ERR(clnt); |
Chuck Lever | 5acf431 | 2008-12-04 14:20:31 -0500 | [diff] [blame] | 79 | dprintk("lockd: failed to create NSM upcall transport, " |
| 80 | "status=%d\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | goto out; |
| 82 | } |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | memset(res, 0, sizeof(*res)); |
| 85 | |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 86 | msg.rpc_proc = &clnt->cl_procinfo[proc]; |
| 87 | status = rpc_call_sync(clnt, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | if (status < 0) |
Chuck Lever | 5acf431 | 2008-12-04 14:20:31 -0500 | [diff] [blame] | 89 | dprintk("lockd: NSM upcall RPC failed, status=%d\n", |
| 90 | status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | else |
| 92 | status = 0; |
Trond Myklebust | 90c5755 | 2007-06-09 19:49:36 -0400 | [diff] [blame] | 93 | rpc_shutdown_client(clnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | out: |
| 95 | return status; |
| 96 | } |
| 97 | |
Chuck Lever | 1e49323 | 2008-12-04 14:21:24 -0500 | [diff] [blame] | 98 | /** |
| 99 | * nsm_monitor - Notify a peer in case we reboot |
| 100 | * @host: pointer to nlm_host of peer to notify |
| 101 | * |
| 102 | * If this peer is not already monitored, this function sends an |
| 103 | * upcall to the local rpc.statd to record the name/address of |
| 104 | * the peer to notify in case we reboot. |
| 105 | * |
| 106 | * Returns zero if the peer is monitored by the local rpc.statd; |
| 107 | * otherwise a negative errno value is returned. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | */ |
Chuck Lever | 1e49323 | 2008-12-04 14:21:24 -0500 | [diff] [blame] | 109 | int nsm_monitor(const struct nlm_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
Olaf Kirch | 8dead0d | 2006-10-04 02:15:53 -0700 | [diff] [blame] | 111 | struct nsm_handle *nsm = host->h_nsmhandle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | struct nsm_res res; |
| 113 | int status; |
| 114 | |
Chuck Lever | 9fee490 | 2008-12-04 14:20:53 -0500 | [diff] [blame] | 115 | dprintk("lockd: nsm_monitor(%s)\n", nsm->sm_name); |
Olaf Kirch | 8dead0d | 2006-10-04 02:15:53 -0700 | [diff] [blame] | 116 | |
| 117 | if (nsm->sm_monitored) |
Olaf Kirch | 977faf3 | 2006-10-04 02:15:51 -0700 | [diff] [blame] | 118 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Chuck Lever | 29ed140 | 2008-12-04 14:20:46 -0500 | [diff] [blame] | 120 | /* |
| 121 | * Choose whether to record the caller_name or IP address of |
| 122 | * this peer in the local rpc.statd's database. |
| 123 | */ |
| 124 | nsm->sm_mon_name = nsm_use_hostnames ? nsm->sm_name : nsm->sm_addrbuf; |
| 125 | |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 126 | status = nsm_mon_unmon(nsm, NSMPROC_MON, &res); |
Chuck Lever | 5d254b1 | 2008-12-04 14:21:15 -0500 | [diff] [blame] | 127 | if (res.status != 0) |
| 128 | status = -EIO; |
| 129 | if (status < 0) |
Chuck Lever | 9fee490 | 2008-12-04 14:20:53 -0500 | [diff] [blame] | 130 | printk(KERN_NOTICE "lockd: cannot monitor %s\n", nsm->sm_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | else |
Olaf Kirch | 8dead0d | 2006-10-04 02:15:53 -0700 | [diff] [blame] | 132 | nsm->sm_monitored = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return status; |
| 134 | } |
| 135 | |
Chuck Lever | 356c3eb | 2008-12-04 14:21:38 -0500 | [diff] [blame] | 136 | /** |
| 137 | * nsm_unmonitor - Unregister peer notification |
| 138 | * @host: pointer to nlm_host of peer to stop monitoring |
| 139 | * |
| 140 | * If this peer is monitored, this function sends an upcall to |
| 141 | * tell the local rpc.statd not to send this peer a notification |
| 142 | * when we reboot. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | */ |
Chuck Lever | 356c3eb | 2008-12-04 14:21:38 -0500 | [diff] [blame] | 144 | void nsm_unmonitor(const struct nlm_host *host) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
Olaf Kirch | 8dead0d | 2006-10-04 02:15:53 -0700 | [diff] [blame] | 146 | struct nsm_handle *nsm = host->h_nsmhandle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | struct nsm_res res; |
Chuck Lever | 356c3eb | 2008-12-04 14:21:38 -0500 | [diff] [blame] | 148 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Olaf Kirch | 9502c52 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 150 | if (atomic_read(&nsm->sm_count) == 1 |
| 151 | && nsm->sm_monitored && !nsm->sm_sticky) { |
Chuck Lever | 9fee490 | 2008-12-04 14:20:53 -0500 | [diff] [blame] | 152 | dprintk("lockd: nsm_unmonitor(%s)\n", nsm->sm_name); |
Olaf Kirch | 9502c52 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 153 | |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 154 | status = nsm_mon_unmon(nsm, NSMPROC_UNMON, &res); |
Chuck Lever | 0c7aef4 | 2008-12-04 14:21:46 -0500 | [diff] [blame] | 155 | if (res.status != 0) |
| 156 | status = -EIO; |
Olaf Kirch | 977faf3 | 2006-10-04 02:15:51 -0700 | [diff] [blame] | 157 | if (status < 0) |
Olaf Kirch | 9502c52 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 158 | printk(KERN_NOTICE "lockd: cannot unmonitor %s\n", |
Chuck Lever | 9fee490 | 2008-12-04 14:20:53 -0500 | [diff] [blame] | 159 | nsm->sm_name); |
Olaf Kirch | 9502c52 | 2006-10-04 02:15:56 -0700 | [diff] [blame] | 160 | else |
| 161 | nsm->sm_monitored = 0; |
Olaf Kirch | 977faf3 | 2006-10-04 02:15:51 -0700 | [diff] [blame] | 162 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* |
| 166 | * Create NSM client for the local host |
| 167 | */ |
| 168 | static struct rpc_clnt * |
| 169 | nsm_create(void) |
| 170 | { |
Chuck Lever | e1ec789 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 171 | struct sockaddr_in sin = { |
| 172 | .sin_family = AF_INET, |
| 173 | .sin_addr.s_addr = htonl(INADDR_LOOPBACK), |
| 174 | .sin_port = 0, |
| 175 | }; |
| 176 | struct rpc_create_args args = { |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 177 | .protocol = XPRT_TRANSPORT_UDP, |
Chuck Lever | e1ec789 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 178 | .address = (struct sockaddr *)&sin, |
| 179 | .addrsize = sizeof(sin), |
| 180 | .servername = "localhost", |
| 181 | .program = &nsm_program, |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 182 | .version = NSM_VERSION, |
Chuck Lever | e1ec789 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 183 | .authflavor = RPC_AUTH_NULL, |
Chuck Lever | e1ec789 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 184 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Chuck Lever | e1ec789 | 2006-08-22 20:06:20 -0400 | [diff] [blame] | 186 | return rpc_create(&args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /* |
| 190 | * XDR functions for NSM. |
Chuck Lever | 2ca7754 | 2008-03-14 14:26:01 -0400 | [diff] [blame] | 191 | * |
| 192 | * See http://www.opengroup.org/ for details on the Network |
| 193 | * Status Monitor wire protocol. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | */ |
| 195 | |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 196 | static int encode_nsm_string(struct xdr_stream *xdr, const char *string) |
Chuck Lever | 099bd05 | 2008-03-14 14:25:32 -0400 | [diff] [blame] | 197 | { |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 198 | const u32 len = strlen(string); |
| 199 | __be32 *p; |
Chuck Lever | 099bd05 | 2008-03-14 14:25:32 -0400 | [diff] [blame] | 200 | |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 201 | if (unlikely(len > SM_MAXSTRLEN)) |
| 202 | return -EIO; |
| 203 | p = xdr_reserve_space(xdr, sizeof(u32) + len); |
| 204 | if (unlikely(p == NULL)) |
| 205 | return -EIO; |
| 206 | xdr_encode_opaque(p, string, len); |
| 207 | return 0; |
Chuck Lever | 099bd05 | 2008-03-14 14:25:32 -0400 | [diff] [blame] | 208 | } |
| 209 | |
Chuck Lever | 4969517 | 2008-03-14 14:25:39 -0400 | [diff] [blame] | 210 | /* |
| 211 | * "mon_name" specifies the host to be monitored. |
Chuck Lever | 4969517 | 2008-03-14 14:25:39 -0400 | [diff] [blame] | 212 | */ |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 213 | static int encode_mon_name(struct xdr_stream *xdr, const struct nsm_args *argp) |
Chuck Lever | 4969517 | 2008-03-14 14:25:39 -0400 | [diff] [blame] | 214 | { |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 215 | return encode_nsm_string(xdr, argp->mon_name); |
Chuck Lever | 4969517 | 2008-03-14 14:25:39 -0400 | [diff] [blame] | 216 | } |
| 217 | |
Chuck Lever | 850c95f | 2008-03-14 14:25:46 -0400 | [diff] [blame] | 218 | /* |
| 219 | * The "my_id" argument specifies the hostname and RPC procedure |
| 220 | * to be called when the status manager receives notification |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 221 | * (via the NLMPROC_SM_NOTIFY call) that the state of host "mon_name" |
Chuck Lever | 850c95f | 2008-03-14 14:25:46 -0400 | [diff] [blame] | 222 | * has changed. |
| 223 | */ |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 224 | static int encode_my_id(struct xdr_stream *xdr, const struct nsm_args *argp) |
Chuck Lever | 850c95f | 2008-03-14 14:25:46 -0400 | [diff] [blame] | 225 | { |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 226 | int status; |
| 227 | __be32 *p; |
Chuck Lever | 850c95f | 2008-03-14 14:25:46 -0400 | [diff] [blame] | 228 | |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 229 | status = encode_nsm_string(xdr, utsname()->nodename); |
| 230 | if (unlikely(status != 0)) |
| 231 | return status; |
| 232 | p = xdr_reserve_space(xdr, 3 * sizeof(u32)); |
| 233 | if (unlikely(p == NULL)) |
| 234 | return -EIO; |
Chuck Lever | 850c95f | 2008-03-14 14:25:46 -0400 | [diff] [blame] | 235 | *p++ = htonl(argp->prog); |
| 236 | *p++ = htonl(argp->vers); |
| 237 | *p++ = htonl(argp->proc); |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 238 | return 0; |
Chuck Lever | 850c95f | 2008-03-14 14:25:46 -0400 | [diff] [blame] | 239 | } |
| 240 | |
Chuck Lever | ea72a7f | 2008-03-14 14:25:53 -0400 | [diff] [blame] | 241 | /* |
| 242 | * The "mon_id" argument specifies the non-private arguments |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 243 | * of an NSMPROC_MON or NSMPROC_UNMON call. |
Chuck Lever | ea72a7f | 2008-03-14 14:25:53 -0400 | [diff] [blame] | 244 | */ |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 245 | static int encode_mon_id(struct xdr_stream *xdr, const struct nsm_args *argp) |
Chuck Lever | ea72a7f | 2008-03-14 14:25:53 -0400 | [diff] [blame] | 246 | { |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 247 | int status; |
Chuck Lever | ea72a7f | 2008-03-14 14:25:53 -0400 | [diff] [blame] | 248 | |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 249 | status = encode_mon_name(xdr, argp); |
| 250 | if (unlikely(status != 0)) |
| 251 | return status; |
| 252 | return encode_my_id(xdr, argp); |
Chuck Lever | ea72a7f | 2008-03-14 14:25:53 -0400 | [diff] [blame] | 253 | } |
| 254 | |
Chuck Lever | 0490a54 | 2008-03-14 14:26:08 -0400 | [diff] [blame] | 255 | /* |
| 256 | * The "priv" argument may contain private information required |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 257 | * by the NSMPROC_MON call. This information will be supplied in the |
| 258 | * NLMPROC_SM_NOTIFY call. |
Chuck Lever | 0490a54 | 2008-03-14 14:26:08 -0400 | [diff] [blame] | 259 | * |
| 260 | * Linux provides the raw IP address of the monitored host, |
| 261 | * left in network byte order. |
| 262 | */ |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 263 | static int encode_priv(struct xdr_stream *xdr, const struct nsm_args *argp) |
Chuck Lever | 0490a54 | 2008-03-14 14:26:08 -0400 | [diff] [blame] | 264 | { |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 265 | __be32 *p; |
| 266 | |
| 267 | p = xdr_reserve_space(xdr, SM_PRIV_SIZE); |
| 268 | if (unlikely(p == NULL)) |
| 269 | return -EIO; |
Chuck Lever | 0490a54 | 2008-03-14 14:26:08 -0400 | [diff] [blame] | 270 | *p++ = argp->addr; |
| 271 | *p++ = 0; |
| 272 | *p++ = 0; |
| 273 | *p++ = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 277 | static int xdr_enc_mon(struct rpc_rqst *req, __be32 *p, |
| 278 | const struct nsm_args *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | { |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 280 | struct xdr_stream xdr; |
| 281 | int status; |
| 282 | |
| 283 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 284 | status = encode_mon_id(&xdr, argp); |
| 285 | if (unlikely(status)) |
| 286 | return status; |
| 287 | return encode_priv(&xdr, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | } |
| 289 | |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 290 | static int xdr_enc_unmon(struct rpc_rqst *req, __be32 *p, |
| 291 | const struct nsm_args *argp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 293 | struct xdr_stream xdr; |
| 294 | |
| 295 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 296 | return encode_mon_id(&xdr, argp); |
| 297 | } |
| 298 | |
| 299 | static int xdr_dec_stat_res(struct rpc_rqst *rqstp, __be32 *p, |
| 300 | struct nsm_res *resp) |
| 301 | { |
| 302 | struct xdr_stream xdr; |
| 303 | |
| 304 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 305 | p = xdr_inline_decode(&xdr, 2 * sizeof(u32)); |
| 306 | if (unlikely(p == NULL)) |
| 307 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | resp->status = ntohl(*p++); |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 309 | resp->state = ntohl(*p); |
| 310 | |
| 311 | dprintk("lockd: xdr_dec_stat_res status %d state %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | resp->status, resp->state); |
| 313 | return 0; |
| 314 | } |
| 315 | |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 316 | static int xdr_dec_stat(struct rpc_rqst *rqstp, __be32 *p, |
| 317 | struct nsm_res *resp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 319 | struct xdr_stream xdr; |
| 320 | |
| 321 | xdr_init_decode(&xdr, &rqstp->rq_rcv_buf, p); |
| 322 | p = xdr_inline_decode(&xdr, sizeof(u32)); |
| 323 | if (unlikely(p == NULL)) |
| 324 | return -EIO; |
| 325 | resp->state = ntohl(*p); |
| 326 | |
| 327 | dprintk("lockd: xdr_dec_stat state %d\n", resp->state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | #define SM_my_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN)) |
Chuck Lever | 2ca7754 | 2008-03-14 14:26:01 -0400 | [diff] [blame] | 332 | #define SM_my_id_sz (SM_my_name_sz+3) |
| 333 | #define SM_mon_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN)) |
| 334 | #define SM_mon_id_sz (SM_mon_name_sz+SM_my_id_sz) |
Chuck Lever | 0490a54 | 2008-03-14 14:26:08 -0400 | [diff] [blame] | 335 | #define SM_priv_sz (XDR_QUADLEN(SM_PRIV_SIZE)) |
| 336 | #define SM_mon_sz (SM_mon_id_sz+SM_priv_sz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | #define SM_monres_sz 2 |
| 338 | #define SM_unmonres_sz 1 |
| 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | static struct rpc_procinfo nsm_procedures[] = { |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 341 | [NSMPROC_MON] = { |
| 342 | .p_proc = NSMPROC_MON, |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 343 | .p_encode = (kxdrproc_t)xdr_enc_mon, |
| 344 | .p_decode = (kxdrproc_t)xdr_dec_stat_res, |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 345 | .p_arglen = SM_mon_sz, |
| 346 | .p_replen = SM_monres_sz, |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 347 | .p_statidx = NSMPROC_MON, |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 348 | .p_name = "MONITOR", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | }, |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 350 | [NSMPROC_UNMON] = { |
| 351 | .p_proc = NSMPROC_UNMON, |
Chuck Lever | 03eb1dc | 2008-12-05 19:02:15 -0500 | [diff] [blame^] | 352 | .p_encode = (kxdrproc_t)xdr_enc_unmon, |
| 353 | .p_decode = (kxdrproc_t)xdr_dec_stat, |
Chuck Lever | 2bea90d | 2007-03-29 16:47:53 -0400 | [diff] [blame] | 354 | .p_arglen = SM_mon_id_sz, |
| 355 | .p_replen = SM_unmonres_sz, |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 356 | .p_statidx = NSMPROC_UNMON, |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 357 | .p_name = "UNMONITOR", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | }, |
| 359 | }; |
| 360 | |
| 361 | static struct rpc_version nsm_version1 = { |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 362 | .number = 1, |
| 363 | .nrprocs = ARRAY_SIZE(nsm_procedures), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | .procs = nsm_procedures |
| 365 | }; |
| 366 | |
| 367 | static struct rpc_version * nsm_version[] = { |
| 368 | [1] = &nsm_version1, |
| 369 | }; |
| 370 | |
| 371 | static struct rpc_stat nsm_stats; |
| 372 | |
| 373 | static struct rpc_program nsm_program = { |
| 374 | .name = "statd", |
Chuck Lever | 36e8e66 | 2008-12-05 19:02:07 -0500 | [diff] [blame] | 375 | .number = NSM_PROGRAM, |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 376 | .nrvers = ARRAY_SIZE(nsm_version), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | .version = nsm_version, |
| 378 | .stats = &nsm_stats |
| 379 | }; |