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