coredump: elf_fdpic_core_dump: use core_state->dumper list
[deliverable/linux.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;
5afc597c 30 struct svc_rqst *rqst;
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{
06e02d66 62 int err, preverr = 0;
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);
06e02d66
JL
77 if (err == -EAGAIN || err == -EINTR) {
78 preverr = err;
1da177e4 79 continue;
06e02d66 80 }
1da177e4 81 if (err < 0) {
06e02d66
JL
82 if (err != preverr) {
83 printk(KERN_WARNING "%s: unexpected error "
84 "from svc_recv (%d)\n", __func__, err);
85 preverr = err;
86 }
87 schedule_timeout_uninterruptible(HZ);
88 continue;
1da177e4 89 }
06e02d66 90 preverr = err;
6fb2b47f 91 svc_process(rqstp);
1da177e4 92 }
1da177e4 93 unlock_kernel();
a277e33c 94 return 0;
1da177e4
LT
95}
96
97/*
5afc597c 98 * Bring up the callback thread if it is not already up.
1da177e4
LT
99 */
100int nfs_callback_up(void)
101{
8e60029f 102 struct svc_serv *serv = NULL;
1da177e4
LT
103 int ret = 0;
104
353ab6e9 105 mutex_lock(&nfs_callback_mutex);
a277e33c 106 if (nfs_callback_info.users++ || nfs_callback_info.task != NULL)
1da177e4 107 goto out;
bc591ccf 108 serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, NULL);
1da177e4
LT
109 ret = -ENOMEM;
110 if (!serv)
111 goto out_err;
482fb94e 112
d7c9f1ed
TT
113 ret = svc_create_xprt(serv, "tcp", nfs_callback_set_tcpport,
114 SVC_SOCK_ANONYMOUS);
482fb94e 115 if (ret <= 0)
8e60029f 116 goto out_err;
482fb94e
CL
117 nfs_callback_tcpport = ret;
118 dprintk("Callback port = 0x%x\n", nfs_callback_tcpport);
119
5afc597c
JL
120 nfs_callback_info.rqst = svc_prepare_thread(serv, &serv->sv_pools[0]);
121 if (IS_ERR(nfs_callback_info.rqst)) {
122 ret = PTR_ERR(nfs_callback_info.rqst);
123 nfs_callback_info.rqst = NULL;
8e60029f 124 goto out_err;
a277e33c
JL
125 }
126
127 svc_sock_update_bufs(serv);
a277e33c 128
5afc597c
JL
129 nfs_callback_info.task = kthread_run(nfs_callback_svc,
130 nfs_callback_info.rqst,
a277e33c
JL
131 "nfsv4-svc");
132 if (IS_ERR(nfs_callback_info.task)) {
133 ret = PTR_ERR(nfs_callback_info.task);
5afc597c
JL
134 svc_exit_thread(nfs_callback_info.rqst);
135 nfs_callback_info.rqst = NULL;
a277e33c 136 nfs_callback_info.task = NULL;
a277e33c
JL
137 goto out_err;
138 }
1da177e4 139out:
8e60029f
JL
140 /*
141 * svc_create creates the svc_serv with sv_nrthreads == 1, and then
a277e33c 142 * svc_prepare_thread increments that. So we need to call svc_destroy
8e60029f
JL
143 * on both success and failure so that the refcount is 1 when the
144 * thread exits.
145 */
146 if (serv)
147 svc_destroy(serv);
353ab6e9 148 mutex_unlock(&nfs_callback_mutex);
1da177e4 149 return ret;
8e60029f 150out_err:
482fb94e
CL
151 dprintk("Couldn't create callback socket or server thread; err = %d\n",
152 ret);
1da177e4
LT
153 nfs_callback_info.users--;
154 goto out;
155}
156
157/*
5afc597c 158 * Kill the callback thread if it's no longer being used.
1da177e4 159 */
5ae1fbce 160void nfs_callback_down(void)
1da177e4 161{
353ab6e9 162 mutex_lock(&nfs_callback_mutex);
1dd761e9 163 nfs_callback_info.users--;
5afc597c 164 if (nfs_callback_info.users == 0 && nfs_callback_info.task != NULL) {
a277e33c 165 kthread_stop(nfs_callback_info.task);
5afc597c
JL
166 svc_exit_thread(nfs_callback_info.rqst);
167 nfs_callback_info.rqst = NULL;
168 nfs_callback_info.task = NULL;
169 }
353ab6e9 170 mutex_unlock(&nfs_callback_mutex);
1da177e4
LT
171}
172
173static int nfs_callback_authenticate(struct svc_rqst *rqstp)
174{
adfa6f98 175 struct nfs_client *clp;
5216a8e7 176 RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
1da177e4
LT
177
178 /* Don't talk to strangers */
ff052645 179 clp = nfs_find_client(svc_addr(rqstp), 4);
1da177e4
LT
180 if (clp == NULL)
181 return SVC_DROP;
ad06e4bd 182
3110ff80 183 dprintk("%s: %s NFSv4 callback!\n", __func__,
ad06e4bd 184 svc_print_addr(rqstp, buf, sizeof(buf)));
24c8dbbb 185 nfs_put_client(clp);
ad06e4bd 186
1da177e4
LT
187 switch (rqstp->rq_authop->flavour) {
188 case RPC_AUTH_NULL:
189 if (rqstp->rq_proc != CB_NULL)
190 return SVC_DENIED;
191 break;
192 case RPC_AUTH_UNIX:
193 break;
194 case RPC_AUTH_GSS:
195 /* FIXME: RPCSEC_GSS handling? */
196 default:
197 return SVC_DENIED;
198 }
199 return SVC_OK;
200}
201
202/*
203 * Define NFS4 callback program
204 */
1da177e4
LT
205static struct svc_version *nfs4_callback_version[] = {
206 [1] = &nfs4_callback_version1,
207};
208
209static struct svc_stat nfs4_callback_stats;
210
211static struct svc_program nfs4_callback_program = {
212 .pg_prog = NFS4_CALLBACK, /* RPC service number */
213 .pg_nvers = ARRAY_SIZE(nfs4_callback_version), /* Number of entries */
214 .pg_vers = nfs4_callback_version, /* version table */
215 .pg_name = "NFSv4 callback", /* service name */
216 .pg_class = "nfs", /* authentication class */
217 .pg_stats = &nfs4_callback_stats,
218 .pg_authenticate = nfs_callback_authenticate,
219};
This page took 1.153999 seconds and 5 git commands to generate.