| Start/ | End/ | |||
| True | False | - | Line | Source |
| 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> | |||
| 13 | #include <linux/sunrpc/svc.h> | |||
| 14 | #include <linux/lockd/lockd.h> | |||
| 15 | #include <linux/lockd/sm_inter.h> | |||
| 16 | ||||
| 17 | ||||
| 18 | #define NLMDBG_FACILITY NLMDBG_MONITOR | |||
| 19 | ||||
| 20 | static struct rpc_clnt * nsm_create(void); | |||
| 21 | ||||
| 22 | static struct rpc_program nsm_program; | |||
| 23 | ||||
| 24 | /* | |||
| 25 | * Local NSM state | |||
| 26 | */ | |||
| 27 | u32 nsm_local_state; | |||
| 28 | ||||
| 29 | /* | |||
| 30 | * Common procedure for SM_MON/SM_UNMON calls | |||
| 31 | */ | |||
| 32 | static int | |||
| 0 | 0 | - | 33 | nsm_mon_unmon(struct nlm_host *host, u32 proc, struct nsm_res *res) |
| 34 | { | |||
| 35 | struct rpc_clnt *clnt; | |||
| 36 | int status; | |||
| 37 | struct nsm_args args; | |||
| 38 | ||||
| 39 | clnt = nsm_create(); | |||
| 0 | 0 | - | 40 | if (IS_ERR(clnt)) { |
| 41 | status = PTR_ERR(clnt); | |||
| 0 | - | 42 | goto out; | |
| 43 | } | |||
| 44 | ||||
| 45 | args.addr = host->h_addr.sin_addr.s_addr; | |||
| 46 | args.proto= (host->h_proto<<1) | host->h_server; | |||
| 47 | args.prog = NLM_PROGRAM; | |||
| 48 | args.vers = host->h_version; | |||
| 49 | args.proc = NLMPROC_NSM_NOTIFY; | |||
| 50 | memset(res, 0, sizeof(*res)); | |||
| 51 | ||||
| 52 | status = rpc_call(clnt, proc, &args, res, 0); | |||
| 0 | 0 | - | 53 | if (status < 0) |
| 54 | printk(KERN_DEBUG "nsm_mon_unmon: rpc failed, status=%d\n", | |||
| 55 | status); | |||
| 56 | else | |||
| 57 | status = 0; | |||
| 58 | out: | |||
| 0 | - | 59 | return status; | |
| 60 | } | |||
| 61 | ||||
| 62 | /* | |||
| 63 | * Set up monitoring of a remote host | |||
| 64 | */ | |||
| 65 | int | |||
| 0 | 0 | - | 66 | nsm_monitor(struct nlm_host *host) |
| 67 | { | |||
| 68 | struct nsm_res res; | |||
| 69 | int status; | |||
| 70 | ||||
| 71 | dprintk("lockd: nsm_monitor(%s)\n", host->h_name); | |||
| 0 | 0 | - | 71 | if (__builtin_expect ( ! ! ( nlm_debug & 0x0.. |
| 0 | 0 | - | 71 | do-while (0) |
| 72 | ||||
| 73 | status = nsm_mon_unmon(host, SM_MON, &res); | |||
| 74 | ||||
| 0 | 0 | - | 75 | if (status < 0 || res.status != 0) |
| 0 | - | 75 | T || _ | |
| 0 | - | 75 | F || T | |
| 0 | - | 75 | F || F | |
| 76 | printk(KERN_NOTICE "lockd: cannot monitor %s\n", host->h_name); | |||
| 77 | else | |||
| 78 | host->h_monitored = 1; | |||
| 0 | - | 79 | return status; | |
| 80 | } | |||
| 81 | ||||
| 82 | /* | |||
| 83 | * Cease to monitor remote host | |||
| 84 | */ | |||
| 85 | int | |||
| 0 | 0 | - | 86 | nsm_unmonitor(struct nlm_host *host) |
| 87 | { | |||
| 88 | struct nsm_res res; | |||
| 89 | int status; | |||
| 90 | ||||
| 91 | dprintk("lockd: nsm_unmonitor(%s)\n", host->h_name); | |||
| 0 | 0 | - | 91 | if (__builtin_expect ( ! ! ( nlm_debug & 0x0.. |
| 0 | 0 | - | 91 | do-while (0) |
| 92 | ||||
| 93 | status = nsm_mon_unmon(host, SM_UNMON, &res); | |||
| 0 | 0 | - | 94 | if (status < 0) |
| 95 | printk(KERN_NOTICE "lockd: cannot unmonitor %s\n", host->h_name); | |||
| 96 | else | |||
| 97 | host->h_monitored = 0; | |||
| 0 | - | 98 | return status; | |
| 99 | } | |||
| 100 | ||||
| 101 | /* | |||
| 102 | * Create NSM client for the local host | |||
| 103 | */ | |||
| 104 | static struct rpc_clnt * | |||
| 0 | 0 | - | 105 | nsm_create(void) |
| 106 | { | |||
| 107 | struct rpc_xprt *xprt; | |||
| 108 | struct rpc_clnt *clnt; | |||
| 109 | struct sockaddr_in sin; | |||
| 110 | ||||
| 111 | sin.sin_family = AF_INET; | |||
| 112 | sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | |||
| 0 | 0 | - | 112 | ternary-?: __builtin_constant_p ( ( __u32 ) ( .. |
| 113 | sin.sin_port = 0; | |||
| 114 | ||||
| 115 | xprt = xprt_create_proto(IPPROTO_UDP, &sin, NULL); | |||
| 0 | 0 | - | 116 | if (IS_ERR(xprt)) |
| 0 | - | 117 | return (struct rpc_clnt *)xprt; | |
| 118 | xprt->resvport = 1; /* NSM requires a reserved port */ | |||
| 119 | ||||
| 120 | clnt = rpc_create_client(xprt, "localhost", | |||
| 121 | &nsm_program, SM_VERSION, | |||
| 122 | RPC_AUTH_NULL); | |||
| 0 | 0 | - | 123 | if (IS_ERR(clnt)) |
| 0 | - | 124 | goto out_err; | |
| 125 | clnt->cl_softrtry = 1; | |||
| 126 | clnt->cl_oneshot = 1; | |||
| 0 | - | 127 | return clnt; | |
| 128 | ||||
| 129 | out_err: | |||
| 0 | - | 130 | return clnt; | |
| 131 | } | |||
| 132 | ||||
| 133 | /* | |||
| 134 | * XDR functions for NSM. | |||
| 135 | */ | |||
| 136 | ||||
| 137 | static u32 * | |||
| 0 | 0 | - | 138 | xdr_encode_common(struct rpc_rqst *rqstp, u32 *p, struct nsm_args *argp) |
| 139 | { | |||
| 140 | char buffer[20]; | |||
| 141 | ||||
| 142 | /* | |||
| 143 | * Use the dotted-quad IP address of the remote host as | |||
| 144 | * identifier. Linux statd always looks up the canonical | |||
| 145 | * hostname first for whatever remote hostname it receives, | |||
| 146 | * so this works alright. | |||
| 147 | */ | |||
| 148 | sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(argp->addr)); | |||
| 149 | if (!(p = xdr_encode_string(p, buffer)) | |||
| 0 | 0 | - | 150 | || !(p = xdr_encode_string(p, system_utsname.nodename))) |
| 0 | - | 150 | !(T) || !(F) | |
| 0 | - | 150 | !(F) || !(_) | |
| 0 | - | 150 | !(T) || !(T) | |
| 0 | - | 151 | return ERR_PTR(-EIO); | |
| 152 | *p++ = htonl(argp->prog); | |||
| 0 | 0 | - | 152 | ternary-?: __builtin_constant_p ( ( __u32 ) ( .. |
| 153 | *p++ = htonl(argp->vers); | |||
| 0 | 0 | - | 153 | ternary-?: __builtin_constant_p ( ( __u32 ) ( .. |
| 154 | *p++ = htonl(argp->proc); | |||
| 0 | 0 | - | 154 | ternary-?: __builtin_constant_p ( ( __u32 ) ( .. |
| 155 | ||||
| 0 | - | 156 | return p; | |
| 157 | } | |||
| 158 | ||||
| 159 | static int | |||
| 0 | 0 | - | 160 | xdr_encode_mon(struct rpc_rqst *rqstp, u32 *p, struct nsm_args *argp) |
| 161 | { | |||
| 162 | p = xdr_encode_common(rqstp, p, argp); | |||
| 0 | 0 | - | 163 | if (IS_ERR(p)) |
| 0 | - | 164 | return PTR_ERR(p); | |
| 165 | *p++ = argp->addr; | |||
| 166 | *p++ = argp->vers; | |||
| 167 | *p++ = argp->proto; | |||
| 168 | *p++ = 0; | |||
| 169 | rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p); | |||
| 0 | - | 170 | return 0; | |
| 171 | } | |||
| 172 | ||||
| 173 | static int | |||
| 0 | 0 | - | 174 | xdr_encode_unmon(struct rpc_rqst *rqstp, u32 *p, struct nsm_args *argp) |
| 175 | { | |||
| 176 | p = xdr_encode_common(rqstp, p, argp); | |||
| 0 | 0 | - | 177 | if (IS_ERR(p)) |
| 0 | - | 178 | return PTR_ERR(p); | |
| 179 | rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p); | |||
| 0 | - | 180 | return 0; | |
| 181 | } | |||
| 182 | ||||
| 183 | static int | |||
| 0 | 0 | - | 184 | xdr_decode_stat_res(struct rpc_rqst *rqstp, u32 *p, struct nsm_res *resp) |
| 185 | { | |||
| 186 | resp->status = ntohl(*p++); | |||
| 0 | 0 | - | 186 | ternary-?: __builtin_constant_p ( ( __u32 ) ( .. |
| 187 | resp->state = ntohl(*p++); | |||
| 0 | 0 | - | 187 | ternary-?: __builtin_constant_p ( ( __u32 ) ( .. |
| 188 | dprintk("nsm: xdr_decode_stat_res status %d state %d\n", | |||
| 0 | 0 | - | 188 | if (__builtin_expect ( ! ! ( nlm_debug & 0x0.. |
| 0 | 0 | - | 188 | do-while (0) |
| 189 | resp->status, resp->state); | |||
| 0 | - | 190 | return 0; | |
| 191 | } | |||
| 192 | ||||
| 193 | static int | |||
| 0 | 0 | - | 194 | xdr_decode_stat(struct rpc_rqst *rqstp, u32 *p, struct nsm_res *resp) |
| 195 | { | |||
| 196 | resp->state = ntohl(*p++); | |||
| 0 | 0 | - | 196 | ternary-?: __builtin_constant_p ( ( __u32 ) ( .. |
| 0 | - | 197 | return 0; | |
| 198 | } | |||
| 199 | ||||
| 200 | #define SM_my_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN)) | |||
| 201 | #define SM_my_id_sz (3+1+SM_my_name_sz) | |||
| 202 | #define SM_mon_id_sz (1+XDR_QUADLEN(20)+SM_my_id_sz) | |||
| 203 | #define SM_mon_sz (SM_mon_id_sz+4) | |||
| 204 | #define SM_monres_sz 2 | |||
| 205 | #define SM_unmonres_sz 1 | |||
| 206 | ||||
| 207 | #ifndef MAX | |||
| 208 | # define MAX(a, b) (((a) > (b))? (a) : (b)) | |||
| 209 | #endif | |||
| 210 | ||||
| 211 | static struct rpc_procinfo nsm_procedures[] = { | |||
| 212 | [SM_MON] = { | |||
| 213 | .p_proc = SM_MON, | |||
| 214 | .p_encode = (kxdrproc_t) xdr_encode_mon, | |||
| 215 | .p_decode = (kxdrproc_t) xdr_decode_stat_res, | |||
| 216 | .p_bufsiz = MAX(SM_mon_sz, SM_monres_sz) << 2, | |||
| 217 | }, | |||
| 218 | [SM_UNMON] = { | |||
| 219 | .p_proc = SM_UNMON, | |||
| 220 | .p_encode = (kxdrproc_t) xdr_encode_unmon, | |||
| 221 | .p_decode = (kxdrproc_t) xdr_decode_stat, | |||
| 222 | .p_bufsiz = MAX(SM_mon_id_sz, SM_unmonres_sz) << 2, | |||
| 223 | }, | |||
| 224 | }; | |||
| 225 | ||||
| 226 | static struct rpc_version nsm_version1 = { | |||
| 227 | .number = 1, | |||
| 228 | .nrprocs = sizeof(nsm_procedures)/sizeof(nsm_procedures[0]), | |||
| 229 | .procs = nsm_procedures | |||
| 230 | }; | |||
| 231 | ||||
| 232 | static struct rpc_version * nsm_version[] = { | |||
| 233 | [1] = &nsm_version1, | |||
| 234 | }; | |||
| 235 | ||||
| 236 | static struct rpc_stat nsm_stats; | |||
| 237 | ||||
| 238 | static struct rpc_program nsm_program = { | |||
| 239 | .name = "statd", | |||
| 240 | .number = SM_PROGRAM, | |||
| 241 | .nrvers = sizeof(nsm_version)/sizeof(nsm_version[0]), | |||
| 242 | .version = nsm_version, | |||
| 243 | .stats = &nsm_stats | |||
| 244 | }; | |||
| ***TER 0% (0/75) of SOURCE FILE mon.c | ||||