]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/nfs/callback.c
Use a zero sized array for raw field in struct fid
[net-next-2.6.git] / fs / nfs / callback.c
CommitLineData
1da177e4
LT
1/*
2 * linux/fs/nfs/callback.c
3 *
4 * Copyright (C) 2004 Trond Myklebust
5 *
6 * NFSv4 callback handling
7 */
8
1da177e4
LT
9#include <linux/completion.h>
10#include <linux/ip.h>
11#include <linux/module.h>
12#include <linux/smp_lock.h>
13#include <linux/sunrpc/svc.h>
14#include <linux/sunrpc/svcsock.h>
15#include <linux/nfs_fs.h>
353ab6e9 16#include <linux/mutex.h>
83144186 17#include <linux/freezer.h>
a277e33c 18#include <linux/kthread.h>
14c85021
ACM
19
20#include <net/inet_sock.h>
21
4ce79717 22#include "nfs4_fs.h"
1da177e4 23#include "callback.h"
24c8dbbb 24#include "internal.h"
1da177e4
LT
25
26#define NFSDBG_FACILITY NFSDBG_CALLBACK
27
28struct nfs_callback_data {
29 unsigned int users;
30 struct svc_serv *serv;
a277e33c 31 struct task_struct *task;
1da177e4
LT
32};
33
34static struct nfs_callback_data nfs_callback_info;
353ab6e9 35static DEFINE_MUTEX(nfs_callback_mutex);
1da177e4
LT
36static struct svc_program nfs4_callback_program;
37
a72b4422 38unsigned int nfs_callback_set_tcpport;
1da177e4 39unsigned short nfs_callback_tcpport;
7d4e2747
DH
40static const int nfs_set_port_min = 0;
41static const int nfs_set_port_max = 65535;
42
43static int param_set_port(const char *val, struct kernel_param *kp)
44{
45 char *endp;
46 int num = simple_strtol(val, &endp, 0);
47 if (endp == val || *endp || num < nfs_set_port_min || num > nfs_set_port_max)
48 return -EINVAL;
49 *((int *)kp->arg) = num;
50 return 0;
51}
52
53module_param_call(callback_tcpport, param_set_port, param_get_int,
54 &nfs_callback_set_tcpport, 0644);
1da177e4
LT
55
56/*
57 * This is the callback kernel thread.
58 */
a277e33c
JL
59static int
60nfs_callback_svc(void *vrqstp)
1da177e4 61{
1da177e4 62 int err;
a277e33c 63 struct svc_rqst *rqstp = vrqstp;
1da177e4 64
83144186 65 set_freezable();
1da177e4 66
a277e33c
JL
67 /*
68 * FIXME: do we really need to run this under the BKL? If so, please
69 * add a comment about what it's intended to protect.
70 */
71 lock_kernel();
72 while (!kthread_should_stop()) {
1da177e4
LT
73 /*
74 * Listen for a request on the socket
75 */
6fb2b47f 76 err = svc_recv(rqstp, MAX_SCHEDULE_TIMEOUT);
1da177e4
LT
77 if (err == -EAGAIN || err == -EINTR)
78 continue;
79 if (err < 0) {
80 printk(KERN_WARNING
81 "%s: terminating on error %d\n",
82 __FUNCTION__, -err);
83 break;
84 }
6fb2b47f 85 svc_process(rqstp);
1da177e4 86 }
1da177e4 87 unlock_kernel();
a277e33c
JL
88 nfs_callback_info.task = NULL;
89 svc_exit_thread(rqstp);
90 return 0;
1da177e4
LT
91}
92
93/*
94 * Bring up the server process if it is not already up.
95 */
96int nfs_callback_up(void)
97{
8e60029f 98 struct svc_serv *serv = NULL;
a277e33c 99 struct svc_rqst *rqstp;
1da177e4
LT
100 int ret = 0;
101
102 lock_kernel();
353ab6e9 103 mutex_lock(&nfs_callback_mutex);
a277e33c 104 if (nfs_callback_info.users++ || nfs_callback_info.task != NULL)
1da177e4 105 goto out;
bc591ccf 106 serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, NULL);
1da177e4
LT
107 ret = -ENOMEM;
108 if (!serv)
109 goto out_err;
482fb94e 110
d7c9f1ed
TT
111 ret = svc_create_xprt(serv, "tcp", nfs_callback_set_tcpport,
112 SVC_SOCK_ANONYMOUS);
482fb94e 113 if (ret <= 0)
8e60029f 114 goto out_err;
482fb94e
CL
115 nfs_callback_tcpport = ret;
116 dprintk("Callback port = 0x%x\n", nfs_callback_tcpport);
117
a277e33c
JL
118 rqstp = svc_prepare_thread(serv, &serv->sv_pools[0]);
119 if (IS_ERR(rqstp)) {
120 ret = PTR_ERR(rqstp);
8e60029f 121 goto out_err;
a277e33c
JL
122 }
123
124 svc_sock_update_bufs(serv);
1da177e4 125 nfs_callback_info.serv = serv;
a277e33c
JL
126
127 nfs_callback_info.task = kthread_run(nfs_callback_svc, rqstp,
128 "nfsv4-svc");
129 if (IS_ERR(nfs_callback_info.task)) {
130 ret = PTR_ERR(nfs_callback_info.task);
131 nfs_callback_info.serv = NULL;
132 nfs_callback_info.task = NULL;
133 svc_exit_thread(rqstp);
134 goto out_err;
135 }
1da177e4 136out:
8e60029f
JL
137 /*
138 * svc_create creates the svc_serv with sv_nrthreads == 1, and then
a277e33c 139 * svc_prepare_thread increments that. So we need to call svc_destroy
8e60029f
JL
140 * on both success and failure so that the refcount is 1 when the
141 * thread exits.
142 */
143 if (serv)
144 svc_destroy(serv);
353ab6e9 145 mutex_unlock(&nfs_callback_mutex);
1da177e4
LT
146 unlock_kernel();
147 return ret;
8e60029f 148out_err:
482fb94e
CL
149 dprintk("Couldn't create callback socket or server thread; err = %d\n",
150 ret);
1da177e4
LT
151 nfs_callback_info.users--;
152 goto out;
153}
154
155/*
e1ba1ab7 156 * Kill the server process if it is not already down.
1da177e4 157 */
5ae1fbce 158void nfs_callback_down(void)
1da177e4 159{
1da177e4 160 lock_kernel();
353ab6e9 161 mutex_lock(&nfs_callback_mutex);
1dd761e9 162 nfs_callback_info.users--;
a277e33c
JL
163 if (nfs_callback_info.users == 0 && nfs_callback_info.task != NULL)
164 kthread_stop(nfs_callback_info.task);
353ab6e9 165 mutex_unlock(&nfs_callback_mutex);
1da177e4 166 unlock_kernel();
1da177e4
LT
167}
168
169static int nfs_callback_authenticate(struct svc_rqst *rqstp)
170{
adfa6f98 171 struct nfs_client *clp;
5216a8e7 172 RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
1da177e4
LT
173
174 /* Don't talk to strangers */
ff052645 175 clp = nfs_find_client(svc_addr(rqstp), 4);
1da177e4
LT
176 if (clp == NULL)
177 return SVC_DROP;
ad06e4bd
CL
178
179 dprintk("%s: %s NFSv4 callback!\n", __FUNCTION__,
180 svc_print_addr(rqstp, buf, sizeof(buf)));
24c8dbbb 181 nfs_put_client(clp);
ad06e4bd 182
1da177e4
LT
183 switch (rqstp->rq_authop->flavour) {
184 case RPC_AUTH_NULL:
185 if (rqstp->rq_proc != CB_NULL)
186 return SVC_DENIED;
187 break;
188 case RPC_AUTH_UNIX:
189 break;
190 case RPC_AUTH_GSS:
191 /* FIXME: RPCSEC_GSS handling? */
192 default:
193 return SVC_DENIED;
194 }
195 return SVC_OK;
196}
197
198/*
199 * Define NFS4 callback program
200 */
1da177e4
LT
201static struct svc_version *nfs4_callback_version[] = {
202 [1] = &nfs4_callback_version1,
203};
204
205static struct svc_stat nfs4_callback_stats;
206
207static struct svc_program nfs4_callback_program = {
208 .pg_prog = NFS4_CALLBACK, /* RPC service number */
209 .pg_nvers = ARRAY_SIZE(nfs4_callback_version), /* Number of entries */
210 .pg_vers = nfs4_callback_version, /* version table */
211 .pg_name = "NFSv4 callback", /* service name */
212 .pg_class = "nfs", /* authentication class */
213 .pg_stats = &nfs4_callback_stats,
214 .pg_authenticate = nfs_callback_authenticate,
215};