blob: 0e6e63f55db4ae9eaa503883ccae4feb3d2a5df6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/nfs/callback_proc.c
3 *
4 * Copyright (C) 2004 Trond Myklebust
5 *
6 * NFSv4 callback procedures
7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/nfs4.h>
9#include <linux/nfs_fs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/slab.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000011#include "nfs4_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "callback.h"
13#include "delegation.h"
David Howells24c8dbb2006-08-22 20:06:10 -040014#include "internal.h"
Fred Isaman43f1b3d2011-01-06 11:36:30 +000015#include "pnfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Chuck Lever1d98fe62007-12-10 14:57:23 -050017#ifdef NFS_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#define NFSDBG_FACILITY NFSDBG_CALLBACK
Chuck Lever1d98fe62007-12-10 14:57:23 -050019#endif
Andy Adamsonc36fca52011-01-06 02:04:32 +000020
21__be32 nfs4_callback_getattr(struct cb_getattrargs *args,
22 struct cb_getattrres *res,
23 struct cb_process_state *cps)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 struct nfs_delegation *delegation;
26 struct nfs_inode *nfsi;
27 struct inode *inode;
Chuck Lever1d98fe62007-12-10 14:57:23 -050028
Andy Adamsonc36fca52011-01-06 02:04:32 +000029 res->status = htonl(NFS4ERR_OP_NOT_IN_SESSION);
30 if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 goto out;
Chuck Lever1d98fe62007-12-10 14:57:23 -050032
Andy Adamsonc36fca52011-01-06 02:04:32 +000033 res->bitmap[0] = res->bitmap[1] = 0;
34 res->status = htonl(NFS4ERR_BADHANDLE);
Chuck Lever1d98fe62007-12-10 14:57:23 -050035
Andy Adamsonc36fca52011-01-06 02:04:32 +000036 dprintk("NFS: GETATTR callback request from %s\n",
37 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
38
39 inode = nfs_delegation_find_inode(cps->clp, &args->fh);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 if (inode == NULL)
Andy Adamsonc36fca52011-01-06 02:04:32 +000041 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 nfsi = NFS_I(inode);
Trond Myklebust761fe932010-08-04 09:29:52 -040043 rcu_read_lock();
44 delegation = rcu_dereference(nfsi->delegation);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0)
46 goto out_iput;
47 res->size = i_size_read(inode);
Trond Myklebustbeb2a5e2006-01-03 09:55:37 +010048 res->change_attr = delegation->change_attr;
49 if (nfsi->npages != 0)
50 res->change_attr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 res->ctime = inode->i_ctime;
52 res->mtime = inode->i_mtime;
53 res->bitmap[0] = (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) &
54 args->bitmap[0];
55 res->bitmap[1] = (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) &
56 args->bitmap[1];
57 res->status = 0;
58out_iput:
Trond Myklebust761fe932010-08-04 09:29:52 -040059 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061out:
Harvey Harrison3110ff82008-05-02 13:42:44 -070062 dprintk("%s: exit with status = %d\n", __func__, ntohl(res->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 return res->status;
64}
65
Andy Adamsonc36fca52011-01-06 02:04:32 +000066__be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy,
67 struct cb_process_state *cps)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 struct inode *inode;
Al Viroe6f684f2006-10-19 23:28:50 -070070 __be32 res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Andy Adamsonc36fca52011-01-06 02:04:32 +000072 res = htonl(NFS4ERR_OP_NOT_IN_SESSION);
73 if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 goto out;
Chuck Lever1d98fe62007-12-10 14:57:23 -050075
76 dprintk("NFS: RECALL callback request from %s\n",
Andy Adamsonc36fca52011-01-06 02:04:32 +000077 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
Chuck Lever1d98fe62007-12-10 14:57:23 -050078
Andy Adamsonc36fca52011-01-06 02:04:32 +000079 res = htonl(NFS4ERR_BADHANDLE);
80 inode = nfs_delegation_find_inode(cps->clp, &args->fh);
81 if (inode == NULL)
82 goto out;
83 /* Set up a helper thread to actually return the delegation */
84 switch (nfs_async_inode_return_delegation(inode, &args->stateid)) {
85 case 0:
86 res = 0;
87 break;
88 case -ENOENT:
89 if (res != 0)
90 res = htonl(NFS4ERR_BAD_STATEID);
91 break;
92 default:
93 res = htonl(NFS4ERR_RESOURCE);
94 }
95 iput(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096out:
Harvey Harrison3110ff82008-05-02 13:42:44 -070097 dprintk("%s: exit with status = %d\n", __func__, ntohl(res));
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return res;
99}
Benny Halevyd49433e2009-04-01 09:23:25 -0400100
Alexandros Batsakis25976412009-12-05 13:48:55 -0500101int nfs4_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
102{
103 if (delegation == NULL || memcmp(delegation->stateid.data, stateid->data,
104 sizeof(delegation->stateid.data)) != 0)
105 return 0;
106 return 1;
107}
108
Benny Halevyd49433e2009-04-01 09:23:25 -0400109#if defined(CONFIG_NFS_V4_1)
110
Benny Halevyd36b7cf2012-01-22 16:03:39 +0200111/*
112 * Lookup a layout by filehandle.
113 *
114 * Note: gets a refcount on the layout hdr and on its respective inode.
115 * Caller must put the layout hdr and the inode.
116 *
117 * TODO: keep track of all layouts (and delegations) in a hash table
118 * hashed by filehandle.
119 */
120static struct pnfs_layout_hdr * get_layout_by_fh_locked(struct nfs_client *clp, struct nfs_fh *fh)
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000121{
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400122 struct nfs_server *server;
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000123 struct inode *ino;
Benny Halevyd36b7cf2012-01-22 16:03:39 +0200124 struct pnfs_layout_hdr *lo;
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000125
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400126 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
127 list_for_each_entry(lo, &server->layouts, plh_layouts) {
Benny Halevyd36b7cf2012-01-22 16:03:39 +0200128 if (nfs_compare_fh(fh, &NFS_I(lo->plh_inode)->fh))
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400129 continue;
130 ino = igrab(lo->plh_inode);
131 if (!ino)
132 continue;
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400133 get_layout_hdr(lo);
Benny Halevyd36b7cf2012-01-22 16:03:39 +0200134 return lo;
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400135 }
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000136 }
Benny Halevyd36b7cf2012-01-22 16:03:39 +0200137
138 return NULL;
139}
140
141static struct pnfs_layout_hdr * get_layout_by_fh(struct nfs_client *clp, struct nfs_fh *fh)
142{
143 struct pnfs_layout_hdr *lo;
144
145 spin_lock(&clp->cl_lock);
146 rcu_read_lock();
147 lo = get_layout_by_fh_locked(clp, fh);
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400148 rcu_read_unlock();
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000149 spin_unlock(&clp->cl_lock);
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400150
Benny Halevyd36b7cf2012-01-22 16:03:39 +0200151 return lo;
152}
153
154static u32 initiate_file_draining(struct nfs_client *clp,
155 struct cb_layoutrecallargs *args)
156{
157 struct inode *ino;
158 struct pnfs_layout_hdr *lo;
159 u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
160 LIST_HEAD(free_me_list);
161
162 lo = get_layout_by_fh(clp, &args->cbl_fh);
163 if (!lo)
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000164 return NFS4ERR_NOMATCHING_LAYOUT;
165
Benny Halevyd36b7cf2012-01-22 16:03:39 +0200166 ino = lo->plh_inode;
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000167 spin_lock(&ino->i_lock);
168 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
169 mark_matching_lsegs_invalid(lo, &free_me_list,
Benny Halevy778b5502011-05-22 19:48:02 +0300170 &args->cbl_range))
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000171 rv = NFS4ERR_DELAY;
172 else
173 rv = NFS4ERR_NOMATCHING_LAYOUT;
174 pnfs_set_layout_stateid(lo, &args->cbl_stateid, true);
175 spin_unlock(&ino->i_lock);
176 pnfs_free_lseg_list(&free_me_list);
177 put_layout_hdr(lo);
178 iput(ino);
179 return rv;
180}
181
182static u32 initiate_bulk_draining(struct nfs_client *clp,
183 struct cb_layoutrecallargs *args)
184{
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400185 struct nfs_server *server;
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000186 struct pnfs_layout_hdr *lo;
187 struct inode *ino;
188 u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
189 struct pnfs_layout_hdr *tmp;
190 LIST_HEAD(recall_list);
191 LIST_HEAD(free_me_list);
192 struct pnfs_layout_range range = {
193 .iomode = IOMODE_ANY,
194 .offset = 0,
195 .length = NFS4_MAX_UINT64,
196 };
197
198 spin_lock(&clp->cl_lock);
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400199 rcu_read_lock();
200 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000201 if ((args->cbl_recall_type == RETURN_FSID) &&
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400202 memcmp(&server->fsid, &args->cbl_fsid,
203 sizeof(struct nfs_fsid)))
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000204 continue;
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400205
206 list_for_each_entry(lo, &server->layouts, plh_layouts) {
207 if (!igrab(lo->plh_inode))
208 continue;
209 get_layout_hdr(lo);
210 BUG_ON(!list_empty(&lo->plh_bulk_recall));
211 list_add(&lo->plh_bulk_recall, &recall_list);
212 }
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000213 }
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400214 rcu_read_unlock();
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000215 spin_unlock(&clp->cl_lock);
Weston Andros Adamson6382a442011-06-01 16:44:44 -0400216
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000217 list_for_each_entry_safe(lo, tmp,
218 &recall_list, plh_bulk_recall) {
219 ino = lo->plh_inode;
220 spin_lock(&ino->i_lock);
221 set_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags);
Benny Halevy778b5502011-05-22 19:48:02 +0300222 if (mark_matching_lsegs_invalid(lo, &free_me_list, &range))
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000223 rv = NFS4ERR_DELAY;
224 list_del_init(&lo->plh_bulk_recall);
225 spin_unlock(&ino->i_lock);
Fred Isamanf49f9ba2011-02-03 18:28:52 +0000226 pnfs_free_lseg_list(&free_me_list);
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000227 put_layout_hdr(lo);
228 iput(ino);
229 }
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000230 return rv;
231}
232
233static u32 do_callback_layoutrecall(struct nfs_client *clp,
234 struct cb_layoutrecallargs *args)
235{
236 u32 res = NFS4ERR_DELAY;
237
238 dprintk("%s enter, type=%i\n", __func__, args->cbl_recall_type);
239 if (test_and_set_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state))
240 goto out;
241 if (args->cbl_recall_type == RETURN_FILE)
242 res = initiate_file_draining(clp, args);
243 else
244 res = initiate_bulk_draining(clp, args);
245 clear_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state);
246out:
247 dprintk("%s returning %i\n", __func__, res);
248 return res;
249
250}
251
Fred Isamanf2a62562011-01-06 11:36:29 +0000252__be32 nfs4_callback_layoutrecall(struct cb_layoutrecallargs *args,
253 void *dummy, struct cb_process_state *cps)
254{
Fred Isaman43f1b3d2011-01-06 11:36:30 +0000255 u32 res;
256
257 dprintk("%s: -->\n", __func__);
258
259 if (cps->clp)
260 res = do_callback_layoutrecall(cps->clp, args);
261 else
262 res = NFS4ERR_OP_NOT_IN_SESSION;
263
264 dprintk("%s: exit with status = %d\n", __func__, res);
265 return cpu_to_be32(res);
Fred Isamanf2a62562011-01-06 11:36:29 +0000266}
267
Alexandros Batsakis36840372011-01-06 11:36:31 +0000268static void pnfs_recall_all_layouts(struct nfs_client *clp)
269{
270 struct cb_layoutrecallargs args;
271
272 /* Pretend we got a CB_LAYOUTRECALL(ALL) */
273 memset(&args, 0, sizeof(args));
274 args.cbl_recall_type = RETURN_ALL;
275 /* FIXME we ignore errors, what should we do? */
276 do_callback_layoutrecall(clp, &args);
277}
278
Marc Eshel1be56832011-05-22 19:47:09 +0300279__be32 nfs4_callback_devicenotify(struct cb_devicenotifyargs *args,
280 void *dummy, struct cb_process_state *cps)
281{
282 int i;
283 __be32 res = 0;
284 struct nfs_client *clp = cps->clp;
285 struct nfs_server *server = NULL;
286
287 dprintk("%s: -->\n", __func__);
288
289 if (!clp) {
290 res = cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION);
291 goto out;
292 }
293
294 for (i = 0; i < args->ndevs; i++) {
295 struct cb_devicenotifyitem *dev = &args->devs[i];
296
297 if (!server ||
298 server->pnfs_curr_ld->id != dev->cbd_layout_type) {
299 rcu_read_lock();
300 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
301 if (server->pnfs_curr_ld &&
302 server->pnfs_curr_ld->id == dev->cbd_layout_type) {
303 rcu_read_unlock();
304 goto found;
305 }
306 rcu_read_unlock();
307 dprintk("%s: layout type %u not found\n",
308 __func__, dev->cbd_layout_type);
309 continue;
310 }
311
312 found:
313 if (dev->cbd_notify_type == NOTIFY_DEVICEID4_CHANGE)
314 dprintk("%s: NOTIFY_DEVICEID4_CHANGE not supported, "
315 "deleting instead\n", __func__);
Benny Halevy35c8bb52011-05-24 18:04:02 +0300316 nfs4_delete_deviceid(server->pnfs_curr_ld, clp, &dev->cbd_dev_id);
Marc Eshel1be56832011-05-22 19:47:09 +0300317 }
318
319out:
320 kfree(args->devs);
321 dprintk("%s: exit with status = %u\n",
322 __func__, be32_to_cpu(res));
323 return res;
324}
325
Alexandros Batsakis25976412009-12-05 13:48:55 -0500326int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
327{
328 if (delegation == NULL)
329 return 0;
330
Alexandros Batsakis94499252010-10-20 00:17:56 -0400331 if (stateid->stateid.seqid != 0)
Alexandros Batsakis25976412009-12-05 13:48:55 -0500332 return 0;
Alexandros Batsakis94499252010-10-20 00:17:56 -0400333 if (memcmp(&delegation->stateid.stateid.other,
334 &stateid->stateid.other,
335 NFS4_STATEID_OTHER_SIZE))
Alexandros Batsakis25976412009-12-05 13:48:55 -0500336 return 0;
337
338 return 1;
339}
340
Ricardo Labiaga963891a2009-04-01 09:23:34 -0400341/*
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400342 * Validate the sequenceID sent by the server.
343 * Return success if the sequenceID is one more than what we last saw on
344 * this slot, accounting for wraparound. Increments the slot's sequence.
345 *
Andy Adamson49110962010-01-14 17:45:08 -0500346 * We don't yet implement a duplicate request cache, instead we set the
347 * back channel ca_maxresponsesize_cached to zero. This is OK for now
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400348 * since we only currently implement idempotent callbacks anyway.
349 *
350 * We have a single slot backchannel at this time, so we don't bother
351 * checking the used_slots bit array on the table. The lower layer guarantees
352 * a single outstanding callback request at a time.
353 */
Andy Adamson9733f0d2010-01-22 12:03:08 -0500354static __be32
Andy Adamsonb2f28bd2010-01-14 17:45:07 -0500355validate_seqid(struct nfs4_slot_table *tbl, struct cb_sequenceargs * args)
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400356{
357 struct nfs4_slot *slot;
358
359 dprintk("%s enter. slotid %d seqid %d\n",
Andy Adamsonb2f28bd2010-01-14 17:45:07 -0500360 __func__, args->csa_slotid, args->csa_sequenceid);
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400361
Andy Adamson61f2e512011-11-09 13:58:20 -0500362 if (args->csa_slotid >= NFS41_BC_MAX_CALLBACKS)
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400363 return htonl(NFS4ERR_BADSLOT);
364
Andy Adamsonb2f28bd2010-01-14 17:45:07 -0500365 slot = tbl->slots + args->csa_slotid;
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400366 dprintk("%s slot table seqid: %d\n", __func__, slot->seq_nr);
367
368 /* Normal */
Andy Adamsonb2f28bd2010-01-14 17:45:07 -0500369 if (likely(args->csa_sequenceid == slot->seq_nr + 1)) {
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400370 slot->seq_nr++;
Trond Myklebust55a67392011-08-02 14:46:29 -0400371 goto out_ok;
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400372 }
373
374 /* Replay */
Andy Adamsonb2f28bd2010-01-14 17:45:07 -0500375 if (args->csa_sequenceid == slot->seq_nr) {
Andy Adamson49110962010-01-14 17:45:08 -0500376 dprintk("%s seqid %d is a replay\n",
Andy Adamsonb2f28bd2010-01-14 17:45:07 -0500377 __func__, args->csa_sequenceid);
Andy Adamson49110962010-01-14 17:45:08 -0500378 /* Signal process_op to set this error on next op */
379 if (args->csa_cachethis == 0)
380 return htonl(NFS4ERR_RETRY_UNCACHED_REP);
381
382 /* The ca_maxresponsesize_cached is 0 with no DRC */
383 else if (args->csa_cachethis == 1)
384 return htonl(NFS4ERR_REP_TOO_BIG_TO_CACHE);
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400385 }
386
387 /* Wraparound */
Andy Adamsonb2f28bd2010-01-14 17:45:07 -0500388 if (args->csa_sequenceid == 1 && (slot->seq_nr + 1) == 0) {
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400389 slot->seq_nr = 1;
Trond Myklebust55a67392011-08-02 14:46:29 -0400390 goto out_ok;
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400391 }
392
393 /* Misordered request */
394 return htonl(NFS4ERR_SEQ_MISORDERED);
Trond Myklebust55a67392011-08-02 14:46:29 -0400395out_ok:
396 tbl->highest_used_slotid = args->csa_slotid;
397 return htonl(NFS4_OK);
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400398}
399
400/*
Mike Sagera7989c32010-01-19 12:54:40 -0500401 * For each referring call triple, check the session's slot table for
402 * a match. If the slot is in use and the sequence numbers match, the
403 * client is still waiting for a response to the original request.
404 */
405static bool referring_call_exists(struct nfs_client *clp,
406 uint32_t nrclists,
407 struct referring_call_list *rclists)
408{
409 bool status = 0;
410 int i, j;
411 struct nfs4_session *session;
412 struct nfs4_slot_table *tbl;
413 struct referring_call_list *rclist;
414 struct referring_call *ref;
415
416 /*
417 * XXX When client trunking is implemented, this becomes
418 * a session lookup from within the loop
419 */
420 session = clp->cl_session;
421 tbl = &session->fc_slot_table;
422
423 for (i = 0; i < nrclists; i++) {
424 rclist = &rclists[i];
425 if (memcmp(session->sess_id.data,
426 rclist->rcl_sessionid.data,
427 NFS4_MAX_SESSIONID_LEN) != 0)
428 continue;
429
430 for (j = 0; j < rclist->rcl_nrefcalls; j++) {
431 ref = &rclist->rcl_refcalls[j];
432
433 dprintk("%s: sessionid %x:%x:%x:%x sequenceid %u "
434 "slotid %u\n", __func__,
435 ((u32 *)&rclist->rcl_sessionid.data)[0],
436 ((u32 *)&rclist->rcl_sessionid.data)[1],
437 ((u32 *)&rclist->rcl_sessionid.data)[2],
438 ((u32 *)&rclist->rcl_sessionid.data)[3],
439 ref->rc_sequenceid, ref->rc_slotid);
440
441 spin_lock(&tbl->slot_tbl_lock);
442 status = (test_bit(ref->rc_slotid, tbl->used_slots) &&
443 tbl->slots[ref->rc_slotid].seq_nr ==
444 ref->rc_sequenceid);
445 spin_unlock(&tbl->slot_tbl_lock);
446 if (status)
447 goto out;
448 }
449 }
450
451out:
452 return status;
453}
454
Andy Adamson9733f0d2010-01-22 12:03:08 -0500455__be32 nfs4_callback_sequence(struct cb_sequenceargs *args,
Andy Adamsonc36fca52011-01-06 02:04:32 +0000456 struct cb_sequenceres *res,
457 struct cb_process_state *cps)
Benny Halevyd49433e2009-04-01 09:23:25 -0400458{
Trond Myklebust55a67392011-08-02 14:46:29 -0400459 struct nfs4_slot_table *tbl;
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400460 struct nfs_client *clp;
Andy Adamson9733f0d2010-01-22 12:03:08 -0500461 int i;
Andy Adamson778be232011-01-25 15:38:01 +0000462 __be32 status = htonl(NFS4ERR_BADSESSION);
Benny Halevyd49433e2009-04-01 09:23:25 -0400463
Andy Adamson778be232011-01-25 15:38:01 +0000464 clp = nfs4_find_client_sessionid(args->csa_addr, &args->csa_sessionid);
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400465 if (clp == NULL)
466 goto out;
467
Trond Myklebust55a67392011-08-02 14:46:29 -0400468 tbl = &clp->cl_session->bc_slot_table;
469
470 spin_lock(&tbl->slot_tbl_lock);
Andy Adamson42acd022011-01-06 02:04:34 +0000471 /* state manager is resetting the session */
472 if (test_bit(NFS4_SESSION_DRAINING, &clp->cl_session->session_state)) {
Trond Myklebust55a67392011-08-02 14:46:29 -0400473 spin_unlock(&tbl->slot_tbl_lock);
474 status = htonl(NFS4ERR_DELAY);
Trond Myklebust910ac682011-08-02 14:46:52 -0400475 /* Return NFS4ERR_BADSESSION if we're draining the session
476 * in order to reset it.
477 */
478 if (test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state))
479 status = htonl(NFS4ERR_BADSESSION);
Andy Adamson42acd022011-01-06 02:04:34 +0000480 goto out;
481 }
482
Andy Adamsonb2f28bd2010-01-14 17:45:07 -0500483 status = validate_seqid(&clp->cl_session->bc_slot_table, args);
Trond Myklebust55a67392011-08-02 14:46:29 -0400484 spin_unlock(&tbl->slot_tbl_lock);
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400485 if (status)
Andy Adamsonc36fca52011-01-06 02:04:32 +0000486 goto out;
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400487
Trond Myklebust55a67392011-08-02 14:46:29 -0400488 cps->slotid = args->csa_slotid;
489
Mike Sager72ce2b32010-01-19 12:54:41 -0500490 /*
491 * Check for pending referring calls. If a match is found, a
492 * related callback was received before the response to the original
493 * call.
494 */
495 if (referring_call_exists(clp, args->csa_nrclists, args->csa_rclists)) {
496 status = htonl(NFS4ERR_DELAY);
Andy Adamsonc36fca52011-01-06 02:04:32 +0000497 goto out;
Mike Sager72ce2b32010-01-19 12:54:41 -0500498 }
499
Benny Halevyd49433e2009-04-01 09:23:25 -0400500 memcpy(&res->csr_sessionid, &args->csa_sessionid,
501 sizeof(res->csr_sessionid));
502 res->csr_sequenceid = args->csa_sequenceid;
503 res->csr_slotid = args->csa_slotid;
504 res->csr_highestslotid = NFS41_BC_MAX_CALLBACKS - 1;
505 res->csr_target_highestslotid = NFS41_BC_MAX_CALLBACKS - 1;
506
Ricardo Labiaga68f3f902009-04-01 09:23:35 -0400507out:
Andy Adamson2c4cdf82011-01-25 15:38:02 +0000508 cps->clp = clp; /* put in nfs4_callback_compound */
Mike Sager72ce2b32010-01-19 12:54:41 -0500509 for (i = 0; i < args->csa_nrclists; i++)
510 kfree(args->csa_rclists[i].rcl_refcalls);
511 kfree(args->csa_rclists);
512
Andy Adamsonc36fca52011-01-06 02:04:32 +0000513 if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) {
514 cps->drc_status = status;
515 status = 0;
516 } else
Andy Adamson49110962010-01-14 17:45:08 -0500517 res->csr_status = status;
Andy Adamsonc36fca52011-01-06 02:04:32 +0000518
Andy Adamson49110962010-01-14 17:45:08 -0500519 dprintk("%s: exit with status = %d res->csr_status %d\n", __func__,
520 ntohl(status), ntohl(res->csr_status));
521 return status;
Benny Halevyd49433e2009-04-01 09:23:25 -0400522}
523
Alexandros Batsakis36840372011-01-06 11:36:31 +0000524static bool
525validate_bitmap_values(unsigned long mask)
526{
527 return (mask & ~RCA4_TYPE_MASK_ALL) == 0;
528}
529
Andy Adamsonc36fca52011-01-06 02:04:32 +0000530__be32 nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy,
531 struct cb_process_state *cps)
Alexandros Batsakis31f09602009-12-05 13:27:02 -0500532{
Andy Adamson9733f0d2010-01-22 12:03:08 -0500533 __be32 status;
Alexandros Batsakis31f09602009-12-05 13:27:02 -0500534 fmode_t flags = 0;
535
Alexandros Batsakis36840372011-01-06 11:36:31 +0000536 status = cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION);
Andy Adamsonc36fca52011-01-06 02:04:32 +0000537 if (!cps->clp) /* set in cb_sequence */
Alexandros Batsakis31f09602009-12-05 13:27:02 -0500538 goto out;
539
540 dprintk("NFS: RECALL_ANY callback request from %s\n",
Andy Adamsonc36fca52011-01-06 02:04:32 +0000541 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
Alexandros Batsakis31f09602009-12-05 13:27:02 -0500542
Alexandros Batsakis36840372011-01-06 11:36:31 +0000543 status = cpu_to_be32(NFS4ERR_INVAL);
544 if (!validate_bitmap_values(args->craa_type_mask))
545 goto out;
546
547 status = cpu_to_be32(NFS4_OK);
Alexandros Batsakis31f09602009-12-05 13:27:02 -0500548 if (test_bit(RCA4_TYPE_MASK_RDATA_DLG, (const unsigned long *)
549 &args->craa_type_mask))
550 flags = FMODE_READ;
551 if (test_bit(RCA4_TYPE_MASK_WDATA_DLG, (const unsigned long *)
552 &args->craa_type_mask))
553 flags |= FMODE_WRITE;
Alexandros Batsakis36840372011-01-06 11:36:31 +0000554 if (test_bit(RCA4_TYPE_MASK_FILE_LAYOUT, (const unsigned long *)
555 &args->craa_type_mask))
556 pnfs_recall_all_layouts(cps->clp);
Alexandros Batsakis31f09602009-12-05 13:27:02 -0500557 if (flags)
Andy Adamsonc36fca52011-01-06 02:04:32 +0000558 nfs_expire_all_delegation_types(cps->clp, flags);
Alexandros Batsakis31f09602009-12-05 13:27:02 -0500559out:
560 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
561 return status;
562}
Andy Adamsonb9efa1b2010-01-20 16:06:27 -0500563
564/* Reduce the fore channel's max_slots to the target value */
Andy Adamsonc36fca52011-01-06 02:04:32 +0000565__be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, void *dummy,
566 struct cb_process_state *cps)
Andy Adamsonb9efa1b2010-01-20 16:06:27 -0500567{
Andy Adamsonb9efa1b2010-01-20 16:06:27 -0500568 struct nfs4_slot_table *fc_tbl;
Andy Adamson9733f0d2010-01-22 12:03:08 -0500569 __be32 status;
Andy Adamsonb9efa1b2010-01-20 16:06:27 -0500570
571 status = htonl(NFS4ERR_OP_NOT_IN_SESSION);
Andy Adamsonc36fca52011-01-06 02:04:32 +0000572 if (!cps->clp) /* set in cb_sequence */
Andy Adamsonb9efa1b2010-01-20 16:06:27 -0500573 goto out;
574
575 dprintk("NFS: CB_RECALL_SLOT request from %s target max slots %d\n",
Andy Adamsonc36fca52011-01-06 02:04:32 +0000576 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR),
Andy Adamsonb9efa1b2010-01-20 16:06:27 -0500577 args->crsa_target_max_slots);
578
Andy Adamsonc36fca52011-01-06 02:04:32 +0000579 fc_tbl = &cps->clp->cl_session->fc_slot_table;
Andy Adamsonb9efa1b2010-01-20 16:06:27 -0500580
581 status = htonl(NFS4ERR_BAD_HIGH_SLOT);
Andy Adamsonbae0ac02010-01-21 14:19:16 -0500582 if (args->crsa_target_max_slots > fc_tbl->max_slots ||
Andy Adamsonb9efa1b2010-01-20 16:06:27 -0500583 args->crsa_target_max_slots < 1)
Andy Adamsonc36fca52011-01-06 02:04:32 +0000584 goto out;
Andy Adamsonbae0ac02010-01-21 14:19:16 -0500585
586 status = htonl(NFS4_OK);
587 if (args->crsa_target_max_slots == fc_tbl->max_slots)
Andy Adamsonc36fca52011-01-06 02:04:32 +0000588 goto out;
Andy Adamsonb9efa1b2010-01-20 16:06:27 -0500589
590 fc_tbl->target_max_slots = args->crsa_target_max_slots;
Andy Adamsonc36fca52011-01-06 02:04:32 +0000591 nfs41_handle_recall_slot(cps->clp);
Andy Adamsonb9efa1b2010-01-20 16:06:27 -0500592out:
593 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
594 return status;
595}
Benny Halevyd49433e2009-04-01 09:23:25 -0400596#endif /* CONFIG_NFS_V4_1 */