~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/nfs/callback_proc.c

Version: ~ [ linux-5.9-rc6 ] ~ [ linux-5.8.10 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.66 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.146 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.198 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.236 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.236 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 /*
  3  * linux/fs/nfs/callback_proc.c
  4  *
  5  * Copyright (C) 2004 Trond Myklebust
  6  *
  7  * NFSv4 callback procedures
  8  */
  9 #include <linux/nfs4.h>
 10 #include <linux/nfs_fs.h>
 11 #include <linux/slab.h>
 12 #include <linux/rcupdate.h>
 13 #include "nfs4_fs.h"
 14 #include "callback.h"
 15 #include "delegation.h"
 16 #include "internal.h"
 17 #include "pnfs.h"
 18 #include "nfs4session.h"
 19 #include "nfs4trace.h"
 20 
 21 #define NFSDBG_FACILITY NFSDBG_CALLBACK
 22 
 23 __be32 nfs4_callback_getattr(void *argp, void *resp,
 24                              struct cb_process_state *cps)
 25 {
 26         struct cb_getattrargs *args = argp;
 27         struct cb_getattrres *res = resp;
 28         struct nfs_delegation *delegation;
 29         struct nfs_inode *nfsi;
 30         struct inode *inode;
 31 
 32         res->status = htonl(NFS4ERR_OP_NOT_IN_SESSION);
 33         if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
 34                 goto out;
 35 
 36         res->bitmap[0] = res->bitmap[1] = 0;
 37         res->status = htonl(NFS4ERR_BADHANDLE);
 38 
 39         dprintk_rcu("NFS: GETATTR callback request from %s\n",
 40                 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
 41 
 42         inode = nfs_delegation_find_inode(cps->clp, &args->fh);
 43         if (IS_ERR(inode)) {
 44                 if (inode == ERR_PTR(-EAGAIN))
 45                         res->status = htonl(NFS4ERR_DELAY);
 46                 trace_nfs4_cb_getattr(cps->clp, &args->fh, NULL,
 47                                 -ntohl(res->status));
 48                 goto out;
 49         }
 50         nfsi = NFS_I(inode);
 51         rcu_read_lock();
 52         delegation = rcu_dereference(nfsi->delegation);
 53         if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0)
 54                 goto out_iput;
 55         res->size = i_size_read(inode);
 56         res->change_attr = delegation->change_attr;
 57         if (nfs_have_writebacks(inode))
 58                 res->change_attr++;
 59         res->ctime = timespec64_to_timespec(inode->i_ctime);
 60         res->mtime = timespec64_to_timespec(inode->i_mtime);
 61         res->bitmap[0] = (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) &
 62                 args->bitmap[0];
 63         res->bitmap[1] = (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) &
 64                 args->bitmap[1];
 65         res->status = 0;
 66 out_iput:
 67         rcu_read_unlock();
 68         trace_nfs4_cb_getattr(cps->clp, &args->fh, inode, -ntohl(res->status));
 69         iput(inode);
 70 out:
 71         dprintk("%s: exit with status = %d\n", __func__, ntohl(res->status));
 72         return res->status;
 73 }
 74 
 75 __be32 nfs4_callback_recall(void *argp, void *resp,
 76                             struct cb_process_state *cps)
 77 {
 78         struct cb_recallargs *args = argp;
 79         struct inode *inode;
 80         __be32 res;
 81         
 82         res = htonl(NFS4ERR_OP_NOT_IN_SESSION);
 83         if (!cps->clp) /* Always set for v4.0. Set in cb_sequence for v4.1 */
 84                 goto out;
 85 
 86         dprintk_rcu("NFS: RECALL callback request from %s\n",
 87                 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
 88 
 89         res = htonl(NFS4ERR_BADHANDLE);
 90         inode = nfs_delegation_find_inode(cps->clp, &args->fh);
 91         if (IS_ERR(inode)) {
 92                 if (inode == ERR_PTR(-EAGAIN))
 93                         res = htonl(NFS4ERR_DELAY);
 94                 trace_nfs4_cb_recall(cps->clp, &args->fh, NULL,
 95                                 &args->stateid, -ntohl(res));
 96                 goto out;
 97         }
 98         /* Set up a helper thread to actually return the delegation */
 99         switch (nfs_async_inode_return_delegation(inode, &args->stateid)) {
100         case 0:
101                 res = 0;
102                 break;
103         case -ENOENT:
104                 res = htonl(NFS4ERR_BAD_STATEID);
105                 break;
106         default:
107                 res = htonl(NFS4ERR_RESOURCE);
108         }
109         trace_nfs4_cb_recall(cps->clp, &args->fh, inode,
110                         &args->stateid, -ntohl(res));
111         iput(inode);
112 out:
113         dprintk("%s: exit with status = %d\n", __func__, ntohl(res));
114         return res;
115 }
116 
117 #if defined(CONFIG_NFS_V4_1)
118 
119 /*
120  * Lookup a layout inode by stateid
121  *
122  * Note: returns a refcount on the inode and superblock
123  */
124 static struct inode *nfs_layout_find_inode_by_stateid(struct nfs_client *clp,
125                 const nfs4_stateid *stateid)
126 {
127         struct nfs_server *server;
128         struct inode *inode;
129         struct pnfs_layout_hdr *lo;
130 
131         list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
132                 list_for_each_entry(lo, &server->layouts, plh_layouts) {
133                         if (stateid != NULL &&
134                             !nfs4_stateid_match_other(stateid, &lo->plh_stateid))
135                                 continue;
136                         inode = igrab(lo->plh_inode);
137                         if (!inode)
138                                 return ERR_PTR(-EAGAIN);
139                         if (!nfs_sb_active(inode->i_sb)) {
140                                 rcu_read_unlock();
141                                 spin_unlock(&clp->cl_lock);
142                                 iput(inode);
143                                 spin_lock(&clp->cl_lock);
144                                 rcu_read_lock();
145                                 return ERR_PTR(-EAGAIN);
146                         }
147                         return inode;
148                 }
149         }
150 
151         return ERR_PTR(-ENOENT);
152 }
153 
154 /*
155  * Lookup a layout inode by filehandle.
156  *
157  * Note: returns a refcount on the inode and superblock
158  *
159  */
160 static struct inode *nfs_layout_find_inode_by_fh(struct nfs_client *clp,
161                 const struct nfs_fh *fh)
162 {
163         struct nfs_server *server;
164         struct nfs_inode *nfsi;
165         struct inode *inode;
166         struct pnfs_layout_hdr *lo;
167 
168         list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
169                 list_for_each_entry(lo, &server->layouts, plh_layouts) {
170                         nfsi = NFS_I(lo->plh_inode);
171                         if (nfs_compare_fh(fh, &nfsi->fh))
172                                 continue;
173                         if (nfsi->layout != lo)
174                                 continue;
175                         inode = igrab(lo->plh_inode);
176                         if (!inode)
177                                 return ERR_PTR(-EAGAIN);
178                         if (!nfs_sb_active(inode->i_sb)) {
179                                 rcu_read_unlock();
180                                 spin_unlock(&clp->cl_lock);
181                                 iput(inode);
182                                 spin_lock(&clp->cl_lock);
183                                 rcu_read_lock();
184                                 return ERR_PTR(-EAGAIN);
185                         }
186                         return inode;
187                 }
188         }
189 
190         return ERR_PTR(-ENOENT);
191 }
192 
193 static struct inode *nfs_layout_find_inode(struct nfs_client *clp,
194                 const struct nfs_fh *fh,
195                 const nfs4_stateid *stateid)
196 {
197         struct inode *inode;
198 
199         spin_lock(&clp->cl_lock);
200         rcu_read_lock();
201         inode = nfs_layout_find_inode_by_stateid(clp, stateid);
202         if (inode == ERR_PTR(-ENOENT))
203                 inode = nfs_layout_find_inode_by_fh(clp, fh);
204         rcu_read_unlock();
205         spin_unlock(&clp->cl_lock);
206 
207         return inode;
208 }
209 
210 /*
211  * Enforce RFC5661 section 12.5.5.2.1. (Layout Recall and Return Sequencing)
212  */
213 static u32 pnfs_check_callback_stateid(struct pnfs_layout_hdr *lo,
214                                         const nfs4_stateid *new)
215 {
216         u32 oldseq, newseq;
217 
218         /* Is the stateid not initialised? */
219         if (!pnfs_layout_is_valid(lo))
220                 return NFS4ERR_NOMATCHING_LAYOUT;
221 
222         /* Mismatched stateid? */
223         if (!nfs4_stateid_match_other(&lo->plh_stateid, new))
224                 return NFS4ERR_BAD_STATEID;
225 
226         newseq = be32_to_cpu(new->seqid);
227         /* Are we already in a layout recall situation? */
228         if (test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags) &&
229             lo->plh_return_seq != 0) {
230                 if (newseq < lo->plh_return_seq)
231                         return NFS4ERR_OLD_STATEID;
232                 if (newseq > lo->plh_return_seq)
233                         return NFS4ERR_DELAY;
234                 goto out;
235         }
236 
237         /* Check that the stateid matches what we think it should be. */
238         oldseq = be32_to_cpu(lo->plh_stateid.seqid);
239         if (newseq > oldseq + 1)
240                 return NFS4ERR_DELAY;
241         /* Crazy server! */
242         if (newseq <= oldseq)
243                 return NFS4ERR_OLD_STATEID;
244 out:
245         return NFS_OK;
246 }
247 
248 static u32 initiate_file_draining(struct nfs_client *clp,
249                                   struct cb_layoutrecallargs *args)
250 {
251         struct inode *ino;
252         struct pnfs_layout_hdr *lo;
253         u32 rv = NFS4ERR_NOMATCHING_LAYOUT;
254         LIST_HEAD(free_me_list);
255 
256         ino = nfs_layout_find_inode(clp, &args->cbl_fh, &args->cbl_stateid);
257         if (IS_ERR(ino)) {
258                 if (ino == ERR_PTR(-EAGAIN))
259                         rv = NFS4ERR_DELAY;
260                 goto out_noput;
261         }
262 
263         pnfs_layoutcommit_inode(ino, false);
264 
265 
266         spin_lock(&ino->i_lock);
267         lo = NFS_I(ino)->layout;
268         if (!lo) {
269                 spin_unlock(&ino->i_lock);
270                 goto out;
271         }
272         pnfs_get_layout_hdr(lo);
273         rv = pnfs_check_callback_stateid(lo, &args->cbl_stateid);
274         if (rv != NFS_OK)
275                 goto unlock;
276         pnfs_set_layout_stateid(lo, &args->cbl_stateid, true);
277 
278         /*
279          * Enforce RFC5661 Section 12.5.5.2.1.5 (Bulk Recall and Return)
280          */
281         if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
282                 rv = NFS4ERR_DELAY;
283                 goto unlock;
284         }
285 
286         if (pnfs_mark_matching_lsegs_return(lo, &free_me_list,
287                                 &args->cbl_range,
288                                 be32_to_cpu(args->cbl_stateid.seqid))) {
289                 rv = NFS4_OK;
290                 goto unlock;
291         }
292 
293         /* Embrace your forgetfulness! */
294         rv = NFS4ERR_NOMATCHING_LAYOUT;
295 
296         if (NFS_SERVER(ino)->pnfs_curr_ld->return_range) {
297                 NFS_SERVER(ino)->pnfs_curr_ld->return_range(lo,
298                         &args->cbl_range);
299         }
300 unlock:
301         spin_unlock(&ino->i_lock);
302         pnfs_free_lseg_list(&free_me_list);
303         /* Free all lsegs that are attached to commit buckets */
304         nfs_commit_inode(ino, 0);
305         pnfs_put_layout_hdr(lo);
306 out:
307         nfs_iput_and_deactive(ino);
308 out_noput:
309         trace_nfs4_cb_layoutrecall_file(clp, &args->cbl_fh, ino,
310                         &args->cbl_stateid, -rv);
311         return rv;
312 }
313 
314 static u32 initiate_bulk_draining(struct nfs_client *clp,
315                                   struct cb_layoutrecallargs *args)
316 {
317         int stat;
318 
319         if (args->cbl_recall_type == RETURN_FSID)
320                 stat = pnfs_destroy_layouts_byfsid(clp, &args->cbl_fsid, true);
321         else
322                 stat = pnfs_destroy_layouts_byclid(clp, true);
323         if (stat != 0)
324                 return NFS4ERR_DELAY;
325         return NFS4ERR_NOMATCHING_LAYOUT;
326 }
327 
328 static u32 do_callback_layoutrecall(struct nfs_client *clp,
329                                     struct cb_layoutrecallargs *args)
330 {
331         write_seqcount_begin(&clp->cl_callback_count);
332         write_seqcount_end(&clp->cl_callback_count);
333         if (args->cbl_recall_type == RETURN_FILE)
334                 return initiate_file_draining(clp, args);
335         return initiate_bulk_draining(clp, args);
336 }
337 
338 __be32 nfs4_callback_layoutrecall(void *argp, void *resp,
339                                   struct cb_process_state *cps)
340 {
341         struct cb_layoutrecallargs *args = argp;
342         u32 res = NFS4ERR_OP_NOT_IN_SESSION;
343 
344         if (cps->clp)
345                 res = do_callback_layoutrecall(cps->clp, args);
346         return cpu_to_be32(res);
347 }
348 
349 static void pnfs_recall_all_layouts(struct nfs_client *clp)
350 {
351         struct cb_layoutrecallargs args;
352 
353         /* Pretend we got a CB_LAYOUTRECALL(ALL) */
354         memset(&args, 0, sizeof(args));
355         args.cbl_recall_type = RETURN_ALL;
356         /* FIXME we ignore errors, what should we do? */
357         do_callback_layoutrecall(clp, &args);
358 }
359 
360 __be32 nfs4_callback_devicenotify(void *argp, void *resp,
361                                   struct cb_process_state *cps)
362 {
363         struct cb_devicenotifyargs *args = argp;
364         int i;
365         __be32 res = 0;
366         struct nfs_client *clp = cps->clp;
367         struct nfs_server *server = NULL;
368 
369         if (!clp) {
370                 res = cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION);
371                 goto out;
372         }
373 
374         for (i = 0; i < args->ndevs; i++) {
375                 struct cb_devicenotifyitem *dev = &args->devs[i];
376 
377                 if (!server ||
378                     server->pnfs_curr_ld->id != dev->cbd_layout_type) {
379                         rcu_read_lock();
380                         list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
381                                 if (server->pnfs_curr_ld &&
382                                     server->pnfs_curr_ld->id == dev->cbd_layout_type) {
383                                         rcu_read_unlock();
384                                         goto found;
385                                 }
386                         rcu_read_unlock();
387                         continue;
388                 }
389 
390         found:
391                 nfs4_delete_deviceid(server->pnfs_curr_ld, clp, &dev->cbd_dev_id);
392         }
393 
394 out:
395         kfree(args->devs);
396         return res;
397 }
398 
399 /*
400  * Validate the sequenceID sent by the server.
401  * Return success if the sequenceID is one more than what we last saw on
402  * this slot, accounting for wraparound.  Increments the slot's sequence.
403  *
404  * We don't yet implement a duplicate request cache, instead we set the
405  * back channel ca_maxresponsesize_cached to zero. This is OK for now
406  * since we only currently implement idempotent callbacks anyway.
407  *
408  * We have a single slot backchannel at this time, so we don't bother
409  * checking the used_slots bit array on the table.  The lower layer guarantees
410  * a single outstanding callback request at a time.
411  */
412 static __be32
413 validate_seqid(const struct nfs4_slot_table *tbl, const struct nfs4_slot *slot,
414                 const struct cb_sequenceargs * args)
415 {
416         if (args->csa_slotid > tbl->server_highest_slotid)
417                 return htonl(NFS4ERR_BADSLOT);
418 
419         /* Replay */
420         if (args->csa_sequenceid == slot->seq_nr) {
421                 if (nfs4_test_locked_slot(tbl, slot->slot_nr))
422                         return htonl(NFS4ERR_DELAY);
423                 /* Signal process_op to set this error on next op */
424                 if (args->csa_cachethis == 0)
425                         return htonl(NFS4ERR_RETRY_UNCACHED_REP);
426 
427                 /* Liar! We never allowed you to set csa_cachethis != 0 */
428                 return htonl(NFS4ERR_SEQ_FALSE_RETRY);
429         }
430 
431         /* Note: wraparound relies on seq_nr being of type u32 */
432         if (likely(args->csa_sequenceid == slot->seq_nr + 1))
433                 return htonl(NFS4_OK);
434 
435         /* Misordered request */
436         return htonl(NFS4ERR_SEQ_MISORDERED);
437 }
438 
439 /*
440  * For each referring call triple, check the session's slot table for
441  * a match.  If the slot is in use and the sequence numbers match, the
442  * client is still waiting for a response to the original request.
443  */
444 static int referring_call_exists(struct nfs_client *clp,
445                                   uint32_t nrclists,
446                                   struct referring_call_list *rclists,
447                                   spinlock_t *lock)
448         __releases(lock)
449         __acquires(lock)
450 {
451         int status = 0;
452         int i, j;
453         struct nfs4_session *session;
454         struct nfs4_slot_table *tbl;
455         struct referring_call_list *rclist;
456         struct referring_call *ref;
457 
458         /*
459          * XXX When client trunking is implemented, this becomes
460          * a session lookup from within the loop
461          */
462         session = clp->cl_session;
463         tbl = &session->fc_slot_table;
464 
465         for (i = 0; i < nrclists; i++) {
466                 rclist = &rclists[i];
467                 if (memcmp(session->sess_id.data,
468                            rclist->rcl_sessionid.data,
469                            NFS4_MAX_SESSIONID_LEN) != 0)
470                         continue;
471 
472                 for (j = 0; j < rclist->rcl_nrefcalls; j++) {
473                         ref = &rclist->rcl_refcalls[j];
474                         spin_unlock(lock);
475                         status = nfs4_slot_wait_on_seqid(tbl, ref->rc_slotid,
476                                         ref->rc_sequenceid, HZ >> 1) < 0;
477                         spin_lock(lock);
478                         if (status)
479                                 goto out;
480                 }
481         }
482 
483 out:
484         return status;
485 }
486 
487 __be32 nfs4_callback_sequence(void *argp, void *resp,
488                               struct cb_process_state *cps)
489 {
490         struct cb_sequenceargs *args = argp;
491         struct cb_sequenceres *res = resp;
492         struct nfs4_slot_table *tbl;
493         struct nfs4_slot *slot;
494         struct nfs_client *clp;
495         int i;
496         __be32 status = htonl(NFS4ERR_BADSESSION);
497 
498         clp = nfs4_find_client_sessionid(cps->net, args->csa_addr,
499                                          &args->csa_sessionid, cps->minorversion);
500         if (clp == NULL)
501                 goto out;
502 
503         if (!(clp->cl_session->flags & SESSION4_BACK_CHAN))
504                 goto out;
505 
506         tbl = &clp->cl_session->bc_slot_table;
507 
508         /* Set up res before grabbing the spinlock */
509         memcpy(&res->csr_sessionid, &args->csa_sessionid,
510                sizeof(res->csr_sessionid));
511         res->csr_sequenceid = args->csa_sequenceid;
512         res->csr_slotid = args->csa_slotid;
513 
514         spin_lock(&tbl->slot_tbl_lock);
515         /* state manager is resetting the session */
516         if (test_bit(NFS4_SLOT_TBL_DRAINING, &tbl->slot_tbl_state)) {
517                 status = htonl(NFS4ERR_DELAY);
518                 /* Return NFS4ERR_BADSESSION if we're draining the session
519                  * in order to reset it.
520                  */
521                 if (test_bit(NFS4CLNT_SESSION_RESET, &clp->cl_state))
522                         status = htonl(NFS4ERR_BADSESSION);
523                 goto out_unlock;
524         }
525 
526         status = htonl(NFS4ERR_BADSLOT);
527         slot = nfs4_lookup_slot(tbl, args->csa_slotid);
528         if (IS_ERR(slot))
529                 goto out_unlock;
530 
531         res->csr_highestslotid = tbl->server_highest_slotid;
532         res->csr_target_highestslotid = tbl->target_highest_slotid;
533 
534         status = validate_seqid(tbl, slot, args);
535         if (status)
536                 goto out_unlock;
537         if (!nfs4_try_to_lock_slot(tbl, slot)) {
538                 status = htonl(NFS4ERR_DELAY);
539                 goto out_unlock;
540         }
541         cps->slot = slot;
542 
543         /* The ca_maxresponsesize_cached is 0 with no DRC */
544         if (args->csa_cachethis != 0) {
545                 status = htonl(NFS4ERR_REP_TOO_BIG_TO_CACHE);
546                 goto out_unlock;
547         }
548 
549         /*
550          * Check for pending referring calls.  If a match is found, a
551          * related callback was received before the response to the original
552          * call.
553          */
554         if (referring_call_exists(clp, args->csa_nrclists, args->csa_rclists,
555                                 &tbl->slot_tbl_lock) < 0) {
556                 status = htonl(NFS4ERR_DELAY);
557                 goto out_unlock;
558         }
559 
560         /*
561          * RFC5661 20.9.3
562          * If CB_SEQUENCE returns an error, then the state of the slot
563          * (sequence ID, cached reply) MUST NOT change.
564          */
565         slot->seq_nr = args->csa_sequenceid;
566 out_unlock:
567         spin_unlock(&tbl->slot_tbl_lock);
568 
569 out:
570         cps->clp = clp; /* put in nfs4_callback_compound */
571         for (i = 0; i < args->csa_nrclists; i++)
572                 kfree(args->csa_rclists[i].rcl_refcalls);
573         kfree(args->csa_rclists);
574 
575         if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) {
576                 cps->drc_status = status;
577                 status = 0;
578         } else
579                 res->csr_status = status;
580 
581         trace_nfs4_cb_sequence(args, res, status);
582         return status;
583 }
584 
585 static bool
586 validate_bitmap_values(unsigned int mask)
587 {
588         return (mask & ~RCA4_TYPE_MASK_ALL) == 0;
589 }
590 
591 __be32 nfs4_callback_recallany(void *argp, void *resp,
592                                struct cb_process_state *cps)
593 {
594         struct cb_recallanyargs *args = argp;
595         __be32 status;
596         fmode_t flags = 0;
597 
598         status = cpu_to_be32(NFS4ERR_OP_NOT_IN_SESSION);
599         if (!cps->clp) /* set in cb_sequence */
600                 goto out;
601 
602         dprintk_rcu("NFS: RECALL_ANY callback request from %s\n",
603                 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
604 
605         status = cpu_to_be32(NFS4ERR_INVAL);
606         if (!validate_bitmap_values(args->craa_type_mask))
607                 goto out;
608 
609         status = cpu_to_be32(NFS4_OK);
610         if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_RDATA_DLG))
611                 flags = FMODE_READ;
612         if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_WDATA_DLG))
613                 flags |= FMODE_WRITE;
614         if (flags)
615                 nfs_expire_unused_delegation_types(cps->clp, flags);
616 
617         if (args->craa_type_mask & BIT(RCA4_TYPE_MASK_FILE_LAYOUT))
618                 pnfs_recall_all_layouts(cps->clp);
619 out:
620         dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
621         return status;
622 }
623 
624 /* Reduce the fore channel's max_slots to the target value */
625 __be32 nfs4_callback_recallslot(void *argp, void *resp,
626                                 struct cb_process_state *cps)
627 {
628         struct cb_recallslotargs *args = argp;
629         struct nfs4_slot_table *fc_tbl;
630         __be32 status;
631 
632         status = htonl(NFS4ERR_OP_NOT_IN_SESSION);
633         if (!cps->clp) /* set in cb_sequence */
634                 goto out;
635 
636         dprintk_rcu("NFS: CB_RECALL_SLOT request from %s target highest slotid %u\n",
637                 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR),
638                 args->crsa_target_highest_slotid);
639 
640         fc_tbl = &cps->clp->cl_session->fc_slot_table;
641 
642         status = htonl(NFS4_OK);
643 
644         nfs41_set_target_slotid(fc_tbl, args->crsa_target_highest_slotid);
645         nfs41_notify_server(cps->clp);
646 out:
647         dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
648         return status;
649 }
650 
651 __be32 nfs4_callback_notify_lock(void *argp, void *resp,
652                                  struct cb_process_state *cps)
653 {
654         struct cb_notify_lock_args *args = argp;
655 
656         if (!cps->clp) /* set in cb_sequence */
657                 return htonl(NFS4ERR_OP_NOT_IN_SESSION);
658 
659         dprintk_rcu("NFS: CB_NOTIFY_LOCK request from %s\n",
660                 rpc_peeraddr2str(cps->clp->cl_rpcclient, RPC_DISPLAY_ADDR));
661 
662         /* Don't wake anybody if the string looked bogus */
663         if (args->cbnl_valid)
664                 __wake_up(&cps->clp->cl_lock_waitq, TASK_NORMAL, 0, args);
665 
666         return htonl(NFS4_OK);
667 }
668 #endif /* CONFIG_NFS_V4_1 */
669 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp