Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/callback.c |
| 3 | * |
| 4 | * Copyright (C) 2004 Trond Myklebust |
| 5 | * |
| 6 | * NFSv4 callback handling |
| 7 | */ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/completion.h> |
| 10 | #include <linux/ip.h> |
| 11 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/sunrpc/svc.h> |
| 13 | #include <linux/sunrpc/svcsock.h> |
| 14 | #include <linux/nfs_fs.h> |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 15 | #include <linux/mutex.h> |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 16 | #include <linux/freezer.h> |
Jeff Layton | a277e33 | 2008-02-20 08:55:30 -0500 | [diff] [blame] | 17 | #include <linux/kthread.h> |
Olga Kornievskaia | 945b34a | 2008-12-23 16:18:34 -0500 | [diff] [blame] | 18 | #include <linux/sunrpc/svcauth_gss.h> |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 19 | #include <linux/sunrpc/bc_xprt.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 20 | |
| 21 | #include <net/inet_sock.h> |
| 22 | |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 23 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include "callback.h" |
David Howells | 24c8dbb | 2006-08-22 20:06:10 -0400 | [diff] [blame] | 25 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #define NFSDBG_FACILITY NFSDBG_CALLBACK |
| 28 | |
| 29 | struct nfs_callback_data { |
| 30 | unsigned int users; |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 31 | struct svc_serv *serv; |
Jeff Layton | 5afc597 | 2008-06-11 10:03:11 -0400 | [diff] [blame] | 32 | struct svc_rqst *rqst; |
Jeff Layton | a277e33 | 2008-02-20 08:55:30 -0500 | [diff] [blame] | 33 | struct task_struct *task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Andy Adamson | e82dc22 | 2009-04-01 09:23:14 -0400 | [diff] [blame] | 36 | static struct nfs_callback_data nfs_callback_info[NFS4_MAX_MINOR_VERSION + 1]; |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 37 | static DEFINE_MUTEX(nfs_callback_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | static struct svc_program nfs4_callback_program; |
| 39 | |
Chuck Lever | f738f51 | 2009-03-18 20:48:06 -0400 | [diff] [blame] | 40 | unsigned short nfs_callback_tcpport6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | /* |
Andy Adamson | e82dc22 | 2009-04-01 09:23:14 -0400 | [diff] [blame] | 43 | * This is the NFSv4 callback kernel thread. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | */ |
Jeff Layton | a277e33 | 2008-02-20 08:55:30 -0500 | [diff] [blame] | 45 | static int |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 46 | nfs4_callback_svc(void *vrqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
Jeff Layton | 06e02d6 | 2008-04-08 15:40:07 -0400 | [diff] [blame] | 48 | int err, preverr = 0; |
Jeff Layton | a277e33 | 2008-02-20 08:55:30 -0500 | [diff] [blame] | 49 | struct svc_rqst *rqstp = vrqstp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
Rafael J. Wysocki | 8314418 | 2007-07-17 04:03:35 -0700 | [diff] [blame] | 51 | set_freezable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Jeff Layton | a277e33 | 2008-02-20 08:55:30 -0500 | [diff] [blame] | 53 | while (!kthread_should_stop()) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /* |
| 55 | * Listen for a request on the socket |
| 56 | */ |
NeilBrown | 6fb2b47 | 2006-10-02 02:17:50 -0700 | [diff] [blame] | 57 | err = svc_recv(rqstp, MAX_SCHEDULE_TIMEOUT); |
Jeff Layton | 06e02d6 | 2008-04-08 15:40:07 -0400 | [diff] [blame] | 58 | if (err == -EAGAIN || err == -EINTR) { |
| 59 | preverr = err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | } |
Jeff Layton | 06e02d6 | 2008-04-08 15:40:07 -0400 | [diff] [blame] | 62 | if (err < 0) { |
| 63 | if (err != preverr) { |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 64 | printk(KERN_WARNING "NFS: %s: unexpected error " |
Jeff Layton | 06e02d6 | 2008-04-08 15:40:07 -0400 | [diff] [blame] | 65 | "from svc_recv (%d)\n", __func__, err); |
| 66 | preverr = err; |
| 67 | } |
| 68 | schedule_timeout_uninterruptible(HZ); |
| 69 | continue; |
| 70 | } |
| 71 | preverr = err; |
NeilBrown | 6fb2b47 | 2006-10-02 02:17:50 -0700 | [diff] [blame] | 72 | svc_process(rqstp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | } |
Jeff Layton | a277e33 | 2008-02-20 08:55:30 -0500 | [diff] [blame] | 74 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /* |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 78 | * Prepare to bring up the NFSv4 callback service |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | */ |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 80 | static struct svc_rqst * |
Stanislav Kinsbursky | 7bb782c | 2012-01-10 16:13:03 +0400 | [diff] [blame] | 81 | nfs4_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 83 | int ret; |
Chuck Lever | 482fb94 | 2007-02-12 00:53:29 -0800 | [diff] [blame] | 84 | |
Stanislav Kinsbursky | 12918b1 | 2012-06-01 13:55:47 +0400 | [diff] [blame] | 85 | ret = svc_create_xprt(serv, "tcp", &init_net, PF_INET, |
Chuck Lever | 9652ada | 2009-03-18 20:46:21 -0400 | [diff] [blame] | 86 | nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS); |
Chuck Lever | 482fb94 | 2007-02-12 00:53:29 -0800 | [diff] [blame] | 87 | if (ret <= 0) |
Jeff Layton | 8e60029 | 2008-02-11 10:00:20 -0500 | [diff] [blame] | 88 | goto out_err; |
Chuck Lever | 482fb94 | 2007-02-12 00:53:29 -0800 | [diff] [blame] | 89 | nfs_callback_tcpport = ret; |
Chuck Lever | 18de973 | 2008-10-16 17:41:11 -0400 | [diff] [blame] | 90 | dprintk("NFS: Callback listener port = %u (af %u)\n", |
Chuck Lever | 26298ca | 2009-03-18 20:46:36 -0400 | [diff] [blame] | 91 | nfs_callback_tcpport, PF_INET); |
Chuck Lever | 482fb94 | 2007-02-12 00:53:29 -0800 | [diff] [blame] | 92 | |
Stanislav Kinsbursky | 12918b1 | 2012-06-01 13:55:47 +0400 | [diff] [blame] | 93 | ret = svc_create_xprt(serv, "tcp", &init_net, PF_INET6, |
Chuck Lever | f738f51 | 2009-03-18 20:48:06 -0400 | [diff] [blame] | 94 | nfs_callback_set_tcpport, SVC_SOCK_ANONYMOUS); |
| 95 | if (ret > 0) { |
| 96 | nfs_callback_tcpport6 = ret; |
| 97 | dprintk("NFS: Callback listener port = %u (af %u)\n", |
| 98 | nfs_callback_tcpport6, PF_INET6); |
Chuck Lever | 18fc316 | 2009-06-17 18:02:10 -0700 | [diff] [blame] | 99 | } else if (ret == -EAFNOSUPPORT) |
| 100 | ret = 0; |
| 101 | else |
Chuck Lever | f738f51 | 2009-03-18 20:48:06 -0400 | [diff] [blame] | 102 | goto out_err; |
Chuck Lever | f738f51 | 2009-03-18 20:48:06 -0400 | [diff] [blame] | 103 | |
Eric Dumazet | 11fd165 | 2011-07-28 20:04:09 +0200 | [diff] [blame] | 104 | return svc_prepare_thread(serv, &serv->sv_pools[0], NUMA_NO_NODE); |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 105 | |
| 106 | out_err: |
| 107 | if (ret == 0) |
| 108 | ret = -ENOMEM; |
| 109 | return ERR_PTR(ret); |
| 110 | } |
| 111 | |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 112 | #if defined(CONFIG_NFS_V4_1) |
| 113 | /* |
| 114 | * The callback service for NFSv4.1 callbacks |
| 115 | */ |
| 116 | static int |
| 117 | nfs41_callback_svc(void *vrqstp) |
| 118 | { |
| 119 | struct svc_rqst *rqstp = vrqstp; |
| 120 | struct svc_serv *serv = rqstp->rq_server; |
| 121 | struct rpc_rqst *req; |
| 122 | int error; |
| 123 | DEFINE_WAIT(wq); |
| 124 | |
| 125 | set_freezable(); |
| 126 | |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 127 | while (!kthread_should_stop()) { |
| 128 | prepare_to_wait(&serv->sv_cb_waitq, &wq, TASK_INTERRUPTIBLE); |
| 129 | spin_lock_bh(&serv->sv_cb_lock); |
| 130 | if (!list_empty(&serv->sv_cb_list)) { |
| 131 | req = list_first_entry(&serv->sv_cb_list, |
| 132 | struct rpc_rqst, rq_bc_list); |
| 133 | list_del(&req->rq_bc_list); |
| 134 | spin_unlock_bh(&serv->sv_cb_lock); |
| 135 | dprintk("Invoking bc_svc_process()\n"); |
| 136 | error = bc_svc_process(serv, req, rqstp); |
| 137 | dprintk("bc_svc_process() returned w/ error code= %d\n", |
| 138 | error); |
| 139 | } else { |
| 140 | spin_unlock_bh(&serv->sv_cb_lock); |
| 141 | schedule(); |
| 142 | } |
| 143 | finish_wait(&serv->sv_cb_waitq, &wq); |
| 144 | } |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Bring up the NFSv4.1 callback service |
| 150 | */ |
Trond Myklebust | 1728017 | 2012-03-11 13:11:00 -0400 | [diff] [blame] | 151 | static struct svc_rqst * |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 152 | nfs41_callback_up(struct svc_serv *serv, struct rpc_xprt *xprt) |
| 153 | { |
Andy Adamson | 01c9a0b | 2011-01-06 02:04:28 +0000 | [diff] [blame] | 154 | struct svc_rqst *rqstp; |
| 155 | int ret; |
Benny Halevy | 8f97524 | 2009-04-01 09:23:11 -0400 | [diff] [blame] | 156 | |
Andy Adamson | 01c9a0b | 2011-01-06 02:04:28 +0000 | [diff] [blame] | 157 | /* |
| 158 | * Create an svc_sock for the back channel service that shares the |
| 159 | * fore channel connection. |
| 160 | * Returns the input port (0) and sets the svc_serv bc_xprt on success |
| 161 | */ |
Stanislav Kinsbursky | 12918b1 | 2012-06-01 13:55:47 +0400 | [diff] [blame] | 162 | ret = svc_create_xprt(serv, "tcp-bc", &init_net, PF_INET, 0, |
Andy Adamson | 01c9a0b | 2011-01-06 02:04:28 +0000 | [diff] [blame] | 163 | SVC_SOCK_ANONYMOUS); |
| 164 | if (ret < 0) { |
| 165 | rqstp = ERR_PTR(ret); |
Benny Halevy | 8f97524 | 2009-04-01 09:23:11 -0400 | [diff] [blame] | 166 | goto out; |
Andy Adamson | 01c9a0b | 2011-01-06 02:04:28 +0000 | [diff] [blame] | 167 | } |
Benny Halevy | 8f97524 | 2009-04-01 09:23:11 -0400 | [diff] [blame] | 168 | |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 169 | /* |
| 170 | * Save the svc_serv in the transport so that it can |
| 171 | * be referenced when the session backchannel is initialized |
| 172 | */ |
| 173 | xprt->bc_serv = serv; |
| 174 | |
| 175 | INIT_LIST_HEAD(&serv->sv_cb_list); |
| 176 | spin_lock_init(&serv->sv_cb_lock); |
| 177 | init_waitqueue_head(&serv->sv_cb_waitq); |
Eric Dumazet | 11fd165 | 2011-07-28 20:04:09 +0200 | [diff] [blame] | 178 | rqstp = svc_prepare_thread(serv, &serv->sv_pools[0], NUMA_NO_NODE); |
Andy Adamson | 01c9a0b | 2011-01-06 02:04:28 +0000 | [diff] [blame] | 179 | if (IS_ERR(rqstp)) { |
Andy Adamson | 4a19de0 | 2011-01-06 02:04:35 +0000 | [diff] [blame] | 180 | svc_xprt_put(serv->sv_bc_xprt); |
| 181 | serv->sv_bc_xprt = NULL; |
Andy Adamson | 01c9a0b | 2011-01-06 02:04:28 +0000 | [diff] [blame] | 182 | } |
Benny Halevy | 8f97524 | 2009-04-01 09:23:11 -0400 | [diff] [blame] | 183 | out: |
Andy Adamson | 01c9a0b | 2011-01-06 02:04:28 +0000 | [diff] [blame] | 184 | dprintk("--> %s return %ld\n", __func__, |
| 185 | IS_ERR(rqstp) ? PTR_ERR(rqstp) : 0); |
Benny Halevy | 8f97524 | 2009-04-01 09:23:11 -0400 | [diff] [blame] | 186 | return rqstp; |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static inline int nfs_minorversion_callback_svc_setup(u32 minorversion, |
| 190 | struct svc_serv *serv, struct rpc_xprt *xprt, |
| 191 | struct svc_rqst **rqstpp, int (**callback_svc)(void *vrqstp)) |
| 192 | { |
| 193 | if (minorversion) { |
| 194 | *rqstpp = nfs41_callback_up(serv, xprt); |
| 195 | *callback_svc = nfs41_callback_svc; |
| 196 | } |
| 197 | return minorversion; |
| 198 | } |
| 199 | |
| 200 | static inline void nfs_callback_bc_serv(u32 minorversion, struct rpc_xprt *xprt, |
| 201 | struct nfs_callback_data *cb_info) |
| 202 | { |
| 203 | if (minorversion) |
| 204 | xprt->bc_serv = cb_info->serv; |
| 205 | } |
| 206 | #else |
| 207 | static inline int nfs_minorversion_callback_svc_setup(u32 minorversion, |
| 208 | struct svc_serv *serv, struct rpc_xprt *xprt, |
| 209 | struct svc_rqst **rqstpp, int (**callback_svc)(void *vrqstp)) |
| 210 | { |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | static inline void nfs_callback_bc_serv(u32 minorversion, struct rpc_xprt *xprt, |
| 215 | struct nfs_callback_data *cb_info) |
| 216 | { |
| 217 | } |
| 218 | #endif /* CONFIG_NFS_V4_1 */ |
| 219 | |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 220 | /* |
| 221 | * Bring up the callback thread if it is not already up. |
| 222 | */ |
| 223 | int nfs_callback_up(u32 minorversion, struct rpc_xprt *xprt) |
| 224 | { |
| 225 | struct svc_serv *serv = NULL; |
| 226 | struct svc_rqst *rqstp; |
| 227 | int (*callback_svc)(void *vrqstp); |
Andy Adamson | e82dc22 | 2009-04-01 09:23:14 -0400 | [diff] [blame] | 228 | struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion]; |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 229 | char svc_name[12]; |
| 230 | int ret = 0; |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 231 | int minorversion_setup; |
Stanislav Kinsbursky | 12918b1 | 2012-06-01 13:55:47 +0400 | [diff] [blame] | 232 | struct net *net = &init_net; |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 233 | |
| 234 | mutex_lock(&nfs_callback_mutex); |
Andy Adamson | e82dc22 | 2009-04-01 09:23:14 -0400 | [diff] [blame] | 235 | if (cb_info->users++ || cb_info->task != NULL) { |
| 236 | nfs_callback_bc_serv(minorversion, xprt, cb_info); |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 237 | goto out; |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 238 | } |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 239 | serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, NULL); |
| 240 | if (!serv) { |
| 241 | ret = -ENOMEM; |
| 242 | goto out_err; |
| 243 | } |
NeilBrown | b042414 | 2012-07-31 14:40:12 +1000 | [diff] [blame] | 244 | /* As there is only one thread we need to over-ride the |
| 245 | * default maximum of 80 connections |
| 246 | */ |
| 247 | serv->sv_maxconn = 1024; |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 248 | |
Stanislav Kinsbursky | 9793f7c | 2012-05-02 16:08:38 +0400 | [diff] [blame] | 249 | ret = svc_bind(serv, net); |
| 250 | if (ret < 0) { |
| 251 | printk(KERN_WARNING "NFS: bind callback service failed\n"); |
| 252 | goto out_err; |
| 253 | } |
| 254 | |
Ricardo Labiaga | a43cde9 | 2009-04-01 09:23:08 -0400 | [diff] [blame] | 255 | minorversion_setup = nfs_minorversion_callback_svc_setup(minorversion, |
| 256 | serv, xprt, &rqstp, &callback_svc); |
| 257 | if (!minorversion_setup) { |
| 258 | /* v4.0 callback setup */ |
Stanislav Kinsbursky | 7bb782c | 2012-01-10 16:13:03 +0400 | [diff] [blame] | 259 | rqstp = nfs4_callback_up(serv, xprt); |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 260 | callback_svc = nfs4_callback_svc; |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | if (IS_ERR(rqstp)) { |
| 264 | ret = PTR_ERR(rqstp); |
Jeff Layton | 8e60029 | 2008-02-11 10:00:20 -0500 | [diff] [blame] | 265 | goto out_err; |
Jeff Layton | a277e33 | 2008-02-20 08:55:30 -0500 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | svc_sock_update_bufs(serv); |
Jeff Layton | a277e33 | 2008-02-20 08:55:30 -0500 | [diff] [blame] | 269 | |
Benny Halevy | 7146851 | 2009-04-01 09:22:56 -0400 | [diff] [blame] | 270 | sprintf(svc_name, "nfsv4.%u-svc", minorversion); |
Andy Adamson | e82dc22 | 2009-04-01 09:23:14 -0400 | [diff] [blame] | 271 | cb_info->serv = serv; |
| 272 | cb_info->rqst = rqstp; |
| 273 | cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name); |
| 274 | if (IS_ERR(cb_info->task)) { |
| 275 | ret = PTR_ERR(cb_info->task); |
| 276 | svc_exit_thread(cb_info->rqst); |
| 277 | cb_info->rqst = NULL; |
| 278 | cb_info->task = NULL; |
Jeff Layton | a277e33 | 2008-02-20 08:55:30 -0500 | [diff] [blame] | 279 | goto out_err; |
| 280 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | out: |
Jeff Layton | 8e60029 | 2008-02-11 10:00:20 -0500 | [diff] [blame] | 282 | /* |
| 283 | * svc_create creates the svc_serv with sv_nrthreads == 1, and then |
Jeff Layton | a277e33 | 2008-02-20 08:55:30 -0500 | [diff] [blame] | 284 | * svc_prepare_thread increments that. So we need to call svc_destroy |
Jeff Layton | 8e60029 | 2008-02-11 10:00:20 -0500 | [diff] [blame] | 285 | * on both success and failure so that the refcount is 1 when the |
| 286 | * thread exits. |
| 287 | */ |
| 288 | if (serv) |
| 289 | svc_destroy(serv); |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 290 | mutex_unlock(&nfs_callback_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return ret; |
Jeff Layton | 8e60029 | 2008-02-11 10:00:20 -0500 | [diff] [blame] | 292 | out_err: |
Chuck Lever | 18de973 | 2008-10-16 17:41:11 -0400 | [diff] [blame] | 293 | dprintk("NFS: Couldn't create callback socket or server thread; " |
| 294 | "err = %d\n", ret); |
Andy Adamson | e82dc22 | 2009-04-01 09:23:14 -0400 | [diff] [blame] | 295 | cb_info->users--; |
Stanislav Kinsbursky | 786185b | 2012-05-04 12:49:41 +0400 | [diff] [blame] | 296 | if (serv) |
| 297 | svc_shutdown_net(serv, net); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | goto out; |
| 299 | } |
| 300 | |
| 301 | /* |
Jeff Layton | 5afc597 | 2008-06-11 10:03:11 -0400 | [diff] [blame] | 302 | * Kill the callback thread if it's no longer being used. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | */ |
Andy Adamson | e82dc22 | 2009-04-01 09:23:14 -0400 | [diff] [blame] | 304 | void nfs_callback_down(int minorversion) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
Andy Adamson | e82dc22 | 2009-04-01 09:23:14 -0400 | [diff] [blame] | 306 | struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion]; |
| 307 | |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 308 | mutex_lock(&nfs_callback_mutex); |
Andy Adamson | e82dc22 | 2009-04-01 09:23:14 -0400 | [diff] [blame] | 309 | cb_info->users--; |
| 310 | if (cb_info->users == 0 && cb_info->task != NULL) { |
| 311 | kthread_stop(cb_info->task); |
Stanislav Kinsbursky | 12918b1 | 2012-06-01 13:55:47 +0400 | [diff] [blame] | 312 | svc_shutdown_net(cb_info->serv, &init_net); |
Andy Adamson | e82dc22 | 2009-04-01 09:23:14 -0400 | [diff] [blame] | 313 | svc_exit_thread(cb_info->rqst); |
| 314 | cb_info->serv = NULL; |
| 315 | cb_info->rqst = NULL; |
| 316 | cb_info->task = NULL; |
Jeff Layton | 5afc597 | 2008-06-11 10:03:11 -0400 | [diff] [blame] | 317 | } |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 318 | mutex_unlock(&nfs_callback_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 321 | /* Boolean check of RPC_AUTH_GSS principal */ |
| 322 | int |
| 323 | check_gss_callback_principal(struct nfs_client *clp, struct svc_rqst *rqstp) |
Olga Kornievskaia | 945b34a | 2008-12-23 16:18:34 -0500 | [diff] [blame] | 324 | { |
J. Bruce Fields | 03a4e1f | 2012-05-14 19:55:22 -0400 | [diff] [blame] | 325 | char *p = rqstp->rq_cred.cr_principal; |
Olga Kornievskaia | 945b34a | 2008-12-23 16:18:34 -0500 | [diff] [blame] | 326 | |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 327 | if (rqstp->rq_authop->flavour != RPC_AUTH_GSS) |
| 328 | return 1; |
| 329 | |
Andy Adamson | ece0de6 | 2011-01-06 02:04:33 +0000 | [diff] [blame] | 330 | /* No RPC_AUTH_GSS on NFSv4.1 back channel yet */ |
| 331 | if (clp->cl_minorversion != 0) |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 332 | return 0; |
Olga Kornievskaia | 945b34a | 2008-12-23 16:18:34 -0500 | [diff] [blame] | 333 | /* |
| 334 | * It might just be a normal user principal, in which case |
| 335 | * userspace won't bother to tell us the name at all. |
| 336 | */ |
| 337 | if (p == NULL) |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 338 | return 0; |
Olga Kornievskaia | 945b34a | 2008-12-23 16:18:34 -0500 | [diff] [blame] | 339 | |
| 340 | /* Expect a GSS_C_NT_HOSTBASED_NAME like "nfs@serverhostname" */ |
| 341 | |
| 342 | if (memcmp(p, "nfs@", 4) != 0) |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 343 | return 0; |
Olga Kornievskaia | 945b34a | 2008-12-23 16:18:34 -0500 | [diff] [blame] | 344 | p += 4; |
Trond Myklebust | 4e0038b | 2012-03-01 17:01:05 -0500 | [diff] [blame] | 345 | if (strcmp(p, clp->cl_hostname) != 0) |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 346 | return 0; |
| 347 | return 1; |
Olga Kornievskaia | 945b34a | 2008-12-23 16:18:34 -0500 | [diff] [blame] | 348 | } |
| 349 | |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 350 | /* |
| 351 | * pg_authenticate method for nfsv4 callback threads. |
| 352 | * |
| 353 | * The authflavor has been negotiated, so an incorrect flavor is a server |
| 354 | * bug. Drop packets with incorrect authflavor. |
| 355 | * |
| 356 | * All other checking done after NFS decoding where the nfs_client can be |
| 357 | * found in nfs4_callback_compound |
| 358 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | static int nfs_callback_authenticate(struct svc_rqst *rqstp) |
| 360 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | switch (rqstp->rq_authop->flavour) { |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 362 | case RPC_AUTH_NULL: |
| 363 | if (rqstp->rq_proc != CB_NULL) |
| 364 | return SVC_DROP; |
| 365 | break; |
| 366 | case RPC_AUTH_GSS: |
| 367 | /* No RPC_AUTH_GSS support yet in NFSv4.1 */ |
| 368 | if (svc_is_backchannel(rqstp)) |
| 369 | return SVC_DROP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | } |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 371 | return SVC_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /* |
| 375 | * Define NFS4 callback program |
| 376 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | static struct svc_version *nfs4_callback_version[] = { |
| 378 | [1] = &nfs4_callback_version1, |
Alexandros Batsakis | 07bccc2 | 2009-12-05 13:19:01 -0500 | [diff] [blame] | 379 | [4] = &nfs4_callback_version4, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | }; |
| 381 | |
| 382 | static struct svc_stat nfs4_callback_stats; |
| 383 | |
| 384 | static struct svc_program nfs4_callback_program = { |
| 385 | .pg_prog = NFS4_CALLBACK, /* RPC service number */ |
| 386 | .pg_nvers = ARRAY_SIZE(nfs4_callback_version), /* Number of entries */ |
| 387 | .pg_vers = nfs4_callback_version, /* version table */ |
| 388 | .pg_name = "NFSv4 callback", /* service name */ |
| 389 | .pg_class = "nfs", /* authentication class */ |
| 390 | .pg_stats = &nfs4_callback_stats, |
| 391 | .pg_authenticate = nfs_callback_authenticate, |
| 392 | }; |