USB: drivers/usb/misc/sisusbvga/sisusb.c: kill two unused variables
[linux-2.6/next.git] / fs / lockd / mon.c
blob3353ed8421a7af49e69e98758860d7d7754f7185
1 /*
2 * linux/fs/lockd/mon.c
4 * The kernel statd client.
6 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
7 */
9 #include <linux/types.h>
10 #include <linux/utsname.h>
11 #include <linux/kernel.h>
12 #include <linux/sunrpc/clnt.h>
13 #include <linux/sunrpc/svc.h>
14 #include <linux/lockd/lockd.h>
15 #include <linux/lockd/sm_inter.h>
18 #define NLMDBG_FACILITY NLMDBG_MONITOR
20 static struct rpc_clnt * nsm_create(void);
22 static struct rpc_program nsm_program;
25 * Local NSM state
27 int nsm_local_state;
30 * Common procedure for SM_MON/SM_UNMON calls
32 static int
33 nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res)
35 struct rpc_clnt *clnt;
36 int status;
37 struct nsm_args args;
38 struct rpc_message msg = {
39 .rpc_argp = &args,
40 .rpc_resp = res,
43 clnt = nsm_create();
44 if (IS_ERR(clnt)) {
45 status = PTR_ERR(clnt);
46 goto out;
49 memset(&args, 0, sizeof(args));
50 args.mon_name = nsm->sm_name;
51 args.addr = nsm->sm_addr.sin_addr.s_addr;
52 args.prog = NLM_PROGRAM;
53 args.vers = 3;
54 args.proc = NLMPROC_NSM_NOTIFY;
55 memset(res, 0, sizeof(*res));
57 msg.rpc_proc = &clnt->cl_procinfo[proc];
58 status = rpc_call_sync(clnt, &msg, 0);
59 if (status < 0)
60 printk(KERN_DEBUG "nsm_mon_unmon: rpc failed, status=%d\n",
61 status);
62 else
63 status = 0;
64 rpc_shutdown_client(clnt);
65 out:
66 return status;
70 * Set up monitoring of a remote host
72 int
73 nsm_monitor(struct nlm_host *host)
75 struct nsm_handle *nsm = host->h_nsmhandle;
76 struct nsm_res res;
77 int status;
79 dprintk("lockd: nsm_monitor(%s)\n", host->h_name);
80 BUG_ON(nsm == NULL);
82 if (nsm->sm_monitored)
83 return 0;
85 status = nsm_mon_unmon(nsm, SM_MON, &res);
87 if (status < 0 || res.status != 0)
88 printk(KERN_NOTICE "lockd: cannot monitor %s\n", host->h_name);
89 else
90 nsm->sm_monitored = 1;
91 return status;
95 * Cease to monitor remote host
97 int
98 nsm_unmonitor(struct nlm_host *host)
100 struct nsm_handle *nsm = host->h_nsmhandle;
101 struct nsm_res res;
102 int status = 0;
104 if (nsm == NULL)
105 return 0;
106 host->h_nsmhandle = NULL;
108 if (atomic_read(&nsm->sm_count) == 1
109 && nsm->sm_monitored && !nsm->sm_sticky) {
110 dprintk("lockd: nsm_unmonitor(%s)\n", host->h_name);
112 status = nsm_mon_unmon(nsm, SM_UNMON, &res);
113 if (status < 0)
114 printk(KERN_NOTICE "lockd: cannot unmonitor %s\n",
115 host->h_name);
116 else
117 nsm->sm_monitored = 0;
119 nsm_release(nsm);
120 return status;
124 * Create NSM client for the local host
126 static struct rpc_clnt *
127 nsm_create(void)
129 struct sockaddr_in sin = {
130 .sin_family = AF_INET,
131 .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
132 .sin_port = 0,
134 struct rpc_create_args args = {
135 .protocol = IPPROTO_UDP,
136 .address = (struct sockaddr *)&sin,
137 .addrsize = sizeof(sin),
138 .servername = "localhost",
139 .program = &nsm_program,
140 .version = SM_VERSION,
141 .authflavor = RPC_AUTH_NULL,
144 return rpc_create(&args);
148 * XDR functions for NSM.
151 static __be32 *
152 xdr_encode_common(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp)
154 char buffer[20], *name;
157 * Use the dotted-quad IP address of the remote host as
158 * identifier. Linux statd always looks up the canonical
159 * hostname first for whatever remote hostname it receives,
160 * so this works alright.
162 if (nsm_use_hostnames) {
163 name = argp->mon_name;
164 } else {
165 sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(argp->addr));
166 name = buffer;
168 if (!(p = xdr_encode_string(p, name))
169 || !(p = xdr_encode_string(p, utsname()->nodename)))
170 return ERR_PTR(-EIO);
171 *p++ = htonl(argp->prog);
172 *p++ = htonl(argp->vers);
173 *p++ = htonl(argp->proc);
175 return p;
178 static int
179 xdr_encode_mon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp)
181 p = xdr_encode_common(rqstp, p, argp);
182 if (IS_ERR(p))
183 return PTR_ERR(p);
185 /* Surprise - there may even be room for an IPv6 address now */
186 *p++ = argp->addr;
187 *p++ = 0;
188 *p++ = 0;
189 *p++ = 0;
190 rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p);
191 return 0;
194 static int
195 xdr_encode_unmon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp)
197 p = xdr_encode_common(rqstp, p, argp);
198 if (IS_ERR(p))
199 return PTR_ERR(p);
200 rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p);
201 return 0;
204 static int
205 xdr_decode_stat_res(struct rpc_rqst *rqstp, __be32 *p, struct nsm_res *resp)
207 resp->status = ntohl(*p++);
208 resp->state = ntohl(*p++);
209 dprintk("nsm: xdr_decode_stat_res status %d state %d\n",
210 resp->status, resp->state);
211 return 0;
214 static int
215 xdr_decode_stat(struct rpc_rqst *rqstp, __be32 *p, struct nsm_res *resp)
217 resp->state = ntohl(*p++);
218 return 0;
221 #define SM_my_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN))
222 #define SM_my_id_sz (3+1+SM_my_name_sz)
223 #define SM_mon_id_sz (1+XDR_QUADLEN(20)+SM_my_id_sz)
224 #define SM_mon_sz (SM_mon_id_sz+4)
225 #define SM_monres_sz 2
226 #define SM_unmonres_sz 1
228 static struct rpc_procinfo nsm_procedures[] = {
229 [SM_MON] = {
230 .p_proc = SM_MON,
231 .p_encode = (kxdrproc_t) xdr_encode_mon,
232 .p_decode = (kxdrproc_t) xdr_decode_stat_res,
233 .p_arglen = SM_mon_sz,
234 .p_replen = SM_monres_sz,
235 .p_statidx = SM_MON,
236 .p_name = "MONITOR",
238 [SM_UNMON] = {
239 .p_proc = SM_UNMON,
240 .p_encode = (kxdrproc_t) xdr_encode_unmon,
241 .p_decode = (kxdrproc_t) xdr_decode_stat,
242 .p_arglen = SM_mon_id_sz,
243 .p_replen = SM_unmonres_sz,
244 .p_statidx = SM_UNMON,
245 .p_name = "UNMONITOR",
249 static struct rpc_version nsm_version1 = {
250 .number = 1,
251 .nrprocs = ARRAY_SIZE(nsm_procedures),
252 .procs = nsm_procedures
255 static struct rpc_version * nsm_version[] = {
256 [1] = &nsm_version1,
259 static struct rpc_stat nsm_stats;
261 static struct rpc_program nsm_program = {
262 .name = "statd",
263 .number = SM_PROGRAM,
264 .nrvers = ARRAY_SIZE(nsm_version),
265 .version = nsm_version,
266 .stats = &nsm_stats