aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/callback_proc.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/callback_proc.c')
-rw-r--r--fs/nfs/callback_proc.c224
1 files changed, 198 insertions, 26 deletions
diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c
index b7da1f54da68..a08770a7e857 100644
--- a/fs/nfs/callback_proc.c
+++ b/fs/nfs/callback_proc.c
@@ -7,6 +7,7 @@
7 */ 7 */
8#include <linux/nfs4.h> 8#include <linux/nfs4.h>
9#include <linux/nfs_fs.h> 9#include <linux/nfs_fs.h>
10#include <linux/slab.h>
10#include "nfs4_fs.h" 11#include "nfs4_fs.h"
11#include "callback.h" 12#include "callback.h"
12#include "delegation.h" 13#include "delegation.h"
@@ -61,6 +62,16 @@ out:
61 return res->status; 62 return res->status;
62} 63}
63 64
65static int (*nfs_validate_delegation_stateid(struct nfs_client *clp))(struct nfs_delegation *, const nfs4_stateid *)
66{
67#if defined(CONFIG_NFS_V4_1)
68 if (clp->cl_minorversion > 0)
69 return nfs41_validate_delegation_stateid;
70#endif
71 return nfs4_validate_delegation_stateid;
72}
73
74
64__be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy) 75__be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy)
65{ 76{
66 struct nfs_client *clp; 77 struct nfs_client *clp;
@@ -81,7 +92,8 @@ __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy)
81 inode = nfs_delegation_find_inode(clp, &args->fh); 92 inode = nfs_delegation_find_inode(clp, &args->fh);
82 if (inode != NULL) { 93 if (inode != NULL) {
83 /* Set up a helper thread to actually return the delegation */ 94 /* Set up a helper thread to actually return the delegation */
84 switch(nfs_async_inode_return_delegation(inode, &args->stateid)) { 95 switch (nfs_async_inode_return_delegation(inode, &args->stateid,
96 nfs_validate_delegation_stateid(clp))) {
85 case 0: 97 case 0:
86 res = 0; 98 res = 0;
87 break; 99 break;
@@ -102,51 +114,79 @@ out:
102 return res; 114 return res;
103} 115}
104 116
117int nfs4_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
118{
119 if (delegation == NULL || memcmp(delegation->stateid.data, stateid->data,
120 sizeof(delegation->stateid.data)) != 0)
121 return 0;
122 return 1;
123}
124
105#if defined(CONFIG_NFS_V4_1) 125#if defined(CONFIG_NFS_V4_1)
106 126
127int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const nfs4_stateid *stateid)
128{
129 if (delegation == NULL)
130 return 0;
131
132 /* seqid is 4-bytes long */
133 if (((u32 *) &stateid->data)[0] != 0)
134 return 0;
135 if (memcmp(&delegation->stateid.data[4], &stateid->data[4],
136 sizeof(stateid->data)-4))
137 return 0;
138
139 return 1;
140}
141
107/* 142/*
108 * Validate the sequenceID sent by the server. 143 * Validate the sequenceID sent by the server.
109 * Return success if the sequenceID is one more than what we last saw on 144 * Return success if the sequenceID is one more than what we last saw on
110 * this slot, accounting for wraparound. Increments the slot's sequence. 145 * this slot, accounting for wraparound. Increments the slot's sequence.
111 * 146 *
112 * We don't yet implement a duplicate request cache, so at this time 147 * We don't yet implement a duplicate request cache, instead we set the
113 * we will log replays, and process them as if we had not seen them before, 148 * back channel ca_maxresponsesize_cached to zero. This is OK for now
114 * but we don't bump the sequence in the slot. Not too worried about it,
115 * since we only currently implement idempotent callbacks anyway. 149 * since we only currently implement idempotent callbacks anyway.
116 * 150 *
117 * We have a single slot backchannel at this time, so we don't bother 151 * We have a single slot backchannel at this time, so we don't bother
118 * checking the used_slots bit array on the table. The lower layer guarantees 152 * checking the used_slots bit array on the table. The lower layer guarantees
119 * a single outstanding callback request at a time. 153 * a single outstanding callback request at a time.
120 */ 154 */
121static int 155static __be32
122validate_seqid(struct nfs4_slot_table *tbl, u32 slotid, u32 seqid) 156validate_seqid(struct nfs4_slot_table *tbl, struct cb_sequenceargs * args)
123{ 157{
124 struct nfs4_slot *slot; 158 struct nfs4_slot *slot;
125 159
126 dprintk("%s enter. slotid %d seqid %d\n", 160 dprintk("%s enter. slotid %d seqid %d\n",
127 __func__, slotid, seqid); 161 __func__, args->csa_slotid, args->csa_sequenceid);
128 162
129 if (slotid > NFS41_BC_MAX_CALLBACKS) 163 if (args->csa_slotid > NFS41_BC_MAX_CALLBACKS)
130 return htonl(NFS4ERR_BADSLOT); 164 return htonl(NFS4ERR_BADSLOT);
131 165
132 slot = tbl->slots + slotid; 166 slot = tbl->slots + args->csa_slotid;
133 dprintk("%s slot table seqid: %d\n", __func__, slot->seq_nr); 167 dprintk("%s slot table seqid: %d\n", __func__, slot->seq_nr);
134 168
135 /* Normal */ 169 /* Normal */
136 if (likely(seqid == slot->seq_nr + 1)) { 170 if (likely(args->csa_sequenceid == slot->seq_nr + 1)) {
137 slot->seq_nr++; 171 slot->seq_nr++;
138 return htonl(NFS4_OK); 172 return htonl(NFS4_OK);
139 } 173 }
140 174
141 /* Replay */ 175 /* Replay */
142 if (seqid == slot->seq_nr) { 176 if (args->csa_sequenceid == slot->seq_nr) {
143 dprintk("%s seqid %d is a replay - no DRC available\n", 177 dprintk("%s seqid %d is a replay\n",
144 __func__, seqid); 178 __func__, args->csa_sequenceid);
145 return htonl(NFS4_OK); 179 /* Signal process_op to set this error on next op */
180 if (args->csa_cachethis == 0)
181 return htonl(NFS4ERR_RETRY_UNCACHED_REP);
182
183 /* The ca_maxresponsesize_cached is 0 with no DRC */
184 else if (args->csa_cachethis == 1)
185 return htonl(NFS4ERR_REP_TOO_BIG_TO_CACHE);
146 } 186 }
147 187
148 /* Wraparound */ 188 /* Wraparound */
149 if (seqid == 1 && (slot->seq_nr + 1) == 0) { 189 if (args->csa_sequenceid == 1 && (slot->seq_nr + 1) == 0) {
150 slot->seq_nr = 1; 190 slot->seq_nr = 1;
151 return htonl(NFS4_OK); 191 return htonl(NFS4_OK);
152 } 192 }
@@ -191,27 +231,87 @@ validate_seqid(struct nfs4_slot_table *tbl, u32 slotid, u32 seqid)
191 return NULL; 231 return NULL;
192} 232}
193 233
194/* FIXME: referring calls should be processed */ 234/*
195unsigned nfs4_callback_sequence(struct cb_sequenceargs *args, 235 * For each referring call triple, check the session's slot table for
236 * a match. If the slot is in use and the sequence numbers match, the
237 * client is still waiting for a response to the original request.
238 */
239static bool referring_call_exists(struct nfs_client *clp,
240 uint32_t nrclists,
241 struct referring_call_list *rclists)
242{
243 bool status = 0;
244 int i, j;
245 struct nfs4_session *session;
246 struct nfs4_slot_table *tbl;
247 struct referring_call_list *rclist;
248 struct referring_call *ref;
249
250 /*
251 * XXX When client trunking is implemented, this becomes
252 * a session lookup from within the loop
253 */
254 session = clp->cl_session;
255 tbl = &session->fc_slot_table;
256
257 for (i = 0; i < nrclists; i++) {
258 rclist = &rclists[i];
259 if (memcmp(session->sess_id.data,
260 rclist->rcl_sessionid.data,
261 NFS4_MAX_SESSIONID_LEN) != 0)
262 continue;
263
264 for (j = 0; j < rclist->rcl_nrefcalls; j++) {
265 ref = &rclist->rcl_refcalls[j];
266
267 dprintk("%s: sessionid %x:%x:%x:%x sequenceid %u "
268 "slotid %u\n", __func__,
269 ((u32 *)&rclist->rcl_sessionid.data)[0],
270 ((u32 *)&rclist->rcl_sessionid.data)[1],
271 ((u32 *)&rclist->rcl_sessionid.data)[2],
272 ((u32 *)&rclist->rcl_sessionid.data)[3],
273 ref->rc_sequenceid, ref->rc_slotid);
274
275 spin_lock(&tbl->slot_tbl_lock);
276 status = (test_bit(ref->rc_slotid, tbl->used_slots) &&
277 tbl->slots[ref->rc_slotid].seq_nr ==
278 ref->rc_sequenceid);
279 spin_unlock(&tbl->slot_tbl_lock);
280 if (status)
281 goto out;
282 }
283 }
284
285out:
286 return status;
287}
288
289__be32 nfs4_callback_sequence(struct cb_sequenceargs *args,
196 struct cb_sequenceres *res) 290 struct cb_sequenceres *res)
197{ 291{
198 struct nfs_client *clp; 292 struct nfs_client *clp;
199 int i, status; 293 int i;
200 294 __be32 status;
201 for (i = 0; i < args->csa_nrclists; i++)
202 kfree(args->csa_rclists[i].rcl_refcalls);
203 kfree(args->csa_rclists);
204 295
205 status = htonl(NFS4ERR_BADSESSION); 296 status = htonl(NFS4ERR_BADSESSION);
206 clp = find_client_with_session(args->csa_addr, 4, &args->csa_sessionid); 297 clp = find_client_with_session(args->csa_addr, 4, &args->csa_sessionid);
207 if (clp == NULL) 298 if (clp == NULL)
208 goto out; 299 goto out;
209 300
210 status = validate_seqid(&clp->cl_session->bc_slot_table, 301 status = validate_seqid(&clp->cl_session->bc_slot_table, args);
211 args->csa_slotid, args->csa_sequenceid);
212 if (status) 302 if (status)
213 goto out_putclient; 303 goto out_putclient;
214 304
305 /*
306 * Check for pending referring calls. If a match is found, a
307 * related callback was received before the response to the original
308 * call.
309 */
310 if (referring_call_exists(clp, args->csa_nrclists, args->csa_rclists)) {
311 status = htonl(NFS4ERR_DELAY);
312 goto out_putclient;
313 }
314
215 memcpy(&res->csr_sessionid, &args->csa_sessionid, 315 memcpy(&res->csr_sessionid, &args->csa_sessionid,
216 sizeof(res->csr_sessionid)); 316 sizeof(res->csr_sessionid));
217 res->csr_sequenceid = args->csa_sequenceid; 317 res->csr_sequenceid = args->csa_sequenceid;
@@ -222,9 +322,81 @@ unsigned nfs4_callback_sequence(struct cb_sequenceargs *args,
222out_putclient: 322out_putclient:
223 nfs_put_client(clp); 323 nfs_put_client(clp);
224out: 324out:
325 for (i = 0; i < args->csa_nrclists; i++)
326 kfree(args->csa_rclists[i].rcl_refcalls);
327 kfree(args->csa_rclists);
328
329 if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP))
330 res->csr_status = 0;
331 else
332 res->csr_status = status;
333 dprintk("%s: exit with status = %d res->csr_status %d\n", __func__,
334 ntohl(status), ntohl(res->csr_status));
335 return status;
336}
337
338__be32 nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy)
339{
340 struct nfs_client *clp;
341 __be32 status;
342 fmode_t flags = 0;
343
344 status = htonl(NFS4ERR_OP_NOT_IN_SESSION);
345 clp = nfs_find_client(args->craa_addr, 4);
346 if (clp == NULL)
347 goto out;
348
349 dprintk("NFS: RECALL_ANY callback request from %s\n",
350 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
351
352 if (test_bit(RCA4_TYPE_MASK_RDATA_DLG, (const unsigned long *)
353 &args->craa_type_mask))
354 flags = FMODE_READ;
355 if (test_bit(RCA4_TYPE_MASK_WDATA_DLG, (const unsigned long *)
356 &args->craa_type_mask))
357 flags |= FMODE_WRITE;
358
359 if (flags)
360 nfs_expire_all_delegation_types(clp, flags);
361 status = htonl(NFS4_OK);
362out:
225 dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); 363 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
226 res->csr_status = status; 364 return status;
227 return res->csr_status;
228} 365}
229 366
367/* Reduce the fore channel's max_slots to the target value */
368__be32 nfs4_callback_recallslot(struct cb_recallslotargs *args, void *dummy)
369{
370 struct nfs_client *clp;
371 struct nfs4_slot_table *fc_tbl;
372 __be32 status;
373
374 status = htonl(NFS4ERR_OP_NOT_IN_SESSION);
375 clp = nfs_find_client(args->crsa_addr, 4);
376 if (clp == NULL)
377 goto out;
378
379 dprintk("NFS: CB_RECALL_SLOT request from %s target max slots %d\n",
380 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR),
381 args->crsa_target_max_slots);
382
383 fc_tbl = &clp->cl_session->fc_slot_table;
384
385 status = htonl(NFS4ERR_BAD_HIGH_SLOT);
386 if (args->crsa_target_max_slots > fc_tbl->max_slots ||
387 args->crsa_target_max_slots < 1)
388 goto out_putclient;
389
390 status = htonl(NFS4_OK);
391 if (args->crsa_target_max_slots == fc_tbl->max_slots)
392 goto out_putclient;
393
394 fc_tbl->target_max_slots = args->crsa_target_max_slots;
395 nfs41_handle_recall_slot(clp);
396out_putclient:
397 nfs_put_client(clp); /* balance nfs_find_client */
398out:
399 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
400 return status;
401}
230#endif /* CONFIG_NFS_V4_1 */ 402#endif /* CONFIG_NFS_V4_1 */