2 * linux/fs/nfs/delegation.c
4 * Copyright (C) 2004 Trond Myklebust
6 * NFS file delegation management
9 #include <linux/completion.h>
10 #include <linux/kthread.h>
11 #include <linux/module.h>
12 #include <linux/sched.h>
13 #include <linux/slab.h>
14 #include <linux/spinlock.h>
16 #include <linux/nfs4.h>
17 #include <linux/nfs_fs.h>
18 #include <linux/nfs_xdr.h>
21 #include "delegation.h"
23 #include "nfs4trace.h"
25 static void nfs_free_delegation(struct nfs_delegation *delegation)
27 if (delegation->cred) {
28 put_rpccred(delegation->cred);
29 delegation->cred = NULL;
31 kfree_rcu(delegation, rcu);
35 * nfs_mark_delegation_referenced - set delegation's REFERENCED flag
36 * @delegation: delegation to process
39 void nfs_mark_delegation_referenced(struct nfs_delegation *delegation)
41 set_bit(NFS_DELEGATION_REFERENCED, &delegation->flags);
45 nfs4_do_check_delegation(struct inode *inode, fmode_t flags, bool mark)
47 struct nfs_delegation *delegation;
50 flags &= FMODE_READ|FMODE_WRITE;
52 delegation = rcu_dereference(NFS_I(inode)->delegation);
53 if (delegation != NULL && (delegation->type & flags) == flags &&
54 !test_bit(NFS_DELEGATION_REVOKED, &delegation->flags) &&
55 !test_bit(NFS_DELEGATION_RETURNING, &delegation->flags)) {
57 nfs_mark_delegation_referenced(delegation);
64 * nfs_have_delegation - check if inode has a delegation, mark it
65 * NFS_DELEGATION_REFERENCED if there is one.
66 * @inode: inode to check
67 * @flags: delegation types to check for
69 * Returns one if inode has the indicated delegation, otherwise zero.
71 int nfs4_have_delegation(struct inode *inode, fmode_t flags)
73 return nfs4_do_check_delegation(inode, flags, true);
77 * nfs4_check_delegation - check if inode has a delegation, do not mark
78 * NFS_DELEGATION_REFERENCED if it has one.
80 int nfs4_check_delegation(struct inode *inode, fmode_t flags)
82 return nfs4_do_check_delegation(inode, flags, false);
85 static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
87 struct inode *inode = state->inode;
89 struct file_lock_context *flctx = inode->i_flctx;
90 struct list_head *list;
96 list = &flctx->flc_posix;
97 spin_lock(&flctx->flc_lock);
99 list_for_each_entry(fl, list, fl_list) {
100 if (nfs_file_open_context(fl->fl_file) != ctx)
102 spin_unlock(&flctx->flc_lock);
103 status = nfs4_lock_delegation_recall(fl, state, stateid);
106 spin_lock(&flctx->flc_lock);
108 if (list == &flctx->flc_posix) {
109 list = &flctx->flc_flock;
112 spin_unlock(&flctx->flc_lock);
117 static int nfs_delegation_claim_opens(struct inode *inode,
118 const nfs4_stateid *stateid, fmode_t type)
120 struct nfs_inode *nfsi = NFS_I(inode);
121 struct nfs_open_context *ctx;
122 struct nfs4_state_owner *sp;
123 struct nfs4_state *state;
128 spin_lock(&inode->i_lock);
129 list_for_each_entry(ctx, &nfsi->open_files, list) {
133 if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
135 if (!nfs4_valid_open_stateid(state))
137 if (!nfs4_stateid_match(&state->stateid, stateid))
139 get_nfs_open_context(ctx);
140 spin_unlock(&inode->i_lock);
142 /* Block nfs4_proc_unlck */
143 mutex_lock(&sp->so_delegreturn_mutex);
144 seq = raw_seqcount_begin(&sp->so_reclaim_seqcount);
145 err = nfs4_open_delegation_recall(ctx, state, stateid, type);
147 err = nfs_delegation_claim_locks(ctx, state, stateid);
148 if (!err && read_seqcount_retry(&sp->so_reclaim_seqcount, seq))
150 mutex_unlock(&sp->so_delegreturn_mutex);
151 put_nfs_open_context(ctx);
156 spin_unlock(&inode->i_lock);
161 * nfs_inode_reclaim_delegation - process a delegation reclaim request
162 * @inode: inode to process
163 * @cred: credential to use for request
164 * @res: new delegation state from server
167 void nfs_inode_reclaim_delegation(struct inode *inode, struct rpc_cred *cred,
168 struct nfs_openres *res)
170 struct nfs_delegation *delegation;
171 struct rpc_cred *oldcred = NULL;
174 delegation = rcu_dereference(NFS_I(inode)->delegation);
175 if (delegation != NULL) {
176 spin_lock(&delegation->lock);
177 if (delegation->inode != NULL) {
178 nfs4_stateid_copy(&delegation->stateid, &res->delegation);
179 delegation->type = res->delegation_type;
180 delegation->pagemod_limit = res->pagemod_limit;
181 oldcred = delegation->cred;
182 delegation->cred = get_rpccred(cred);
183 clear_bit(NFS_DELEGATION_NEED_RECLAIM,
185 spin_unlock(&delegation->lock);
187 put_rpccred(oldcred);
188 trace_nfs4_reclaim_delegation(inode, res->delegation_type);
190 /* We appear to have raced with a delegation return. */
191 spin_unlock(&delegation->lock);
193 nfs_inode_set_delegation(inode, cred, res);
200 static int nfs_do_return_delegation(struct inode *inode, struct nfs_delegation *delegation, int issync)
204 if (!test_bit(NFS_DELEGATION_REVOKED, &delegation->flags))
205 res = nfs4_proc_delegreturn(inode,
207 &delegation->stateid,
209 nfs_free_delegation(delegation);
213 static struct inode *nfs_delegation_grab_inode(struct nfs_delegation *delegation)
215 struct inode *inode = NULL;
217 spin_lock(&delegation->lock);
218 if (delegation->inode != NULL)
219 inode = igrab(delegation->inode);
220 spin_unlock(&delegation->lock);
224 static struct nfs_delegation *
225 nfs_start_delegation_return_locked(struct nfs_inode *nfsi)
227 struct nfs_delegation *ret = NULL;
228 struct nfs_delegation *delegation = rcu_dereference(nfsi->delegation);
230 if (delegation == NULL)
232 spin_lock(&delegation->lock);
233 if (!test_and_set_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
235 spin_unlock(&delegation->lock);
240 static struct nfs_delegation *
241 nfs_start_delegation_return(struct nfs_inode *nfsi)
243 struct nfs_delegation *delegation;
246 delegation = nfs_start_delegation_return_locked(nfsi);
252 nfs_abort_delegation_return(struct nfs_delegation *delegation,
253 struct nfs_client *clp)
256 spin_lock(&delegation->lock);
257 clear_bit(NFS_DELEGATION_RETURNING, &delegation->flags);
258 set_bit(NFS_DELEGATION_RETURN, &delegation->flags);
259 spin_unlock(&delegation->lock);
260 set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state);
263 static struct nfs_delegation *
264 nfs_detach_delegation_locked(struct nfs_inode *nfsi,
265 struct nfs_delegation *delegation,
266 struct nfs_client *clp)
268 struct nfs_delegation *deleg_cur =
269 rcu_dereference_protected(nfsi->delegation,
270 lockdep_is_held(&clp->cl_lock));
272 if (deleg_cur == NULL || delegation != deleg_cur)
275 spin_lock(&delegation->lock);
276 set_bit(NFS_DELEGATION_RETURNING, &delegation->flags);
277 list_del_rcu(&delegation->super_list);
278 delegation->inode = NULL;
279 rcu_assign_pointer(nfsi->delegation, NULL);
280 spin_unlock(&delegation->lock);
284 static struct nfs_delegation *nfs_detach_delegation(struct nfs_inode *nfsi,
285 struct nfs_delegation *delegation,
286 struct nfs_server *server)
288 struct nfs_client *clp = server->nfs_client;
290 spin_lock(&clp->cl_lock);
291 delegation = nfs_detach_delegation_locked(nfsi, delegation, clp);
292 spin_unlock(&clp->cl_lock);
296 static struct nfs_delegation *
297 nfs_inode_detach_delegation(struct inode *inode)
299 struct nfs_inode *nfsi = NFS_I(inode);
300 struct nfs_server *server = NFS_SERVER(inode);
301 struct nfs_delegation *delegation;
303 delegation = nfs_start_delegation_return(nfsi);
304 if (delegation == NULL)
306 return nfs_detach_delegation(nfsi, delegation, server);
310 nfs_update_inplace_delegation(struct nfs_delegation *delegation,
311 const struct nfs_delegation *update)
313 if (nfs4_stateid_is_newer(&update->stateid, &delegation->stateid)) {
314 delegation->stateid.seqid = update->stateid.seqid;
316 delegation->type = update->type;
321 * nfs_inode_set_delegation - set up a delegation on an inode
322 * @inode: inode to which delegation applies
323 * @cred: cred to use for subsequent delegation processing
324 * @res: new delegation state from server
326 * Returns zero on success, or a negative errno value.
328 int nfs_inode_set_delegation(struct inode *inode, struct rpc_cred *cred, struct nfs_openres *res)
330 struct nfs_server *server = NFS_SERVER(inode);
331 struct nfs_client *clp = server->nfs_client;
332 struct nfs_inode *nfsi = NFS_I(inode);
333 struct nfs_delegation *delegation, *old_delegation;
334 struct nfs_delegation *freeme = NULL;
337 delegation = kmalloc(sizeof(*delegation), GFP_NOFS);
338 if (delegation == NULL)
340 nfs4_stateid_copy(&delegation->stateid, &res->delegation);
341 delegation->type = res->delegation_type;
342 delegation->pagemod_limit = res->pagemod_limit;
343 delegation->change_attr = inode->i_version;
344 delegation->cred = get_rpccred(cred);
345 delegation->inode = inode;
346 delegation->flags = 1<<NFS_DELEGATION_REFERENCED;
347 spin_lock_init(&delegation->lock);
349 spin_lock(&clp->cl_lock);
350 old_delegation = rcu_dereference_protected(nfsi->delegation,
351 lockdep_is_held(&clp->cl_lock));
352 if (old_delegation != NULL) {
353 /* Is this an update of the existing delegation? */
354 if (nfs4_stateid_match_other(&old_delegation->stateid,
355 &delegation->stateid)) {
356 nfs_update_inplace_delegation(old_delegation,
361 * Deal with broken servers that hand out two
362 * delegations for the same file.
363 * Allow for upgrades to a WRITE delegation, but
366 dfprintk(FILE, "%s: server %s handed out "
367 "a duplicate delegation!\n",
368 __func__, clp->cl_hostname);
369 if (delegation->type == old_delegation->type ||
370 !(delegation->type & FMODE_WRITE)) {
375 if (test_and_set_bit(NFS_DELEGATION_RETURNING,
376 &old_delegation->flags))
378 freeme = nfs_detach_delegation_locked(nfsi,
379 old_delegation, clp);
383 list_add_tail_rcu(&delegation->super_list, &server->delegations);
384 rcu_assign_pointer(nfsi->delegation, delegation);
387 /* Ensure we revalidate the attributes and page cache! */
388 spin_lock(&inode->i_lock);
389 nfsi->cache_validity |= NFS_INO_REVAL_FORCED;
390 spin_unlock(&inode->i_lock);
391 trace_nfs4_set_delegation(inode, res->delegation_type);
394 spin_unlock(&clp->cl_lock);
395 if (delegation != NULL)
396 nfs_free_delegation(delegation);
398 nfs_do_return_delegation(inode, freeme, 0);
403 * Basic procedure for returning a delegation to the server
405 static int nfs_end_delegation_return(struct inode *inode, struct nfs_delegation *delegation, int issync)
407 struct nfs_client *clp = NFS_SERVER(inode)->nfs_client;
408 struct nfs_inode *nfsi = NFS_I(inode);
411 if (delegation == NULL)
414 if (test_bit(NFS_DELEGATION_REVOKED, &delegation->flags))
416 err = nfs_delegation_claim_opens(inode, &delegation->stateid,
418 if (!issync || err != -EAGAIN)
421 * Guard against state recovery
423 err = nfs4_wait_clnt_recover(clp);
427 nfs_abort_delegation_return(delegation, clp);
430 if (!nfs_detach_delegation(nfsi, delegation, NFS_SERVER(inode)))
433 err = nfs_do_return_delegation(inode, delegation, issync);
438 static bool nfs_delegation_need_return(struct nfs_delegation *delegation)
442 if (test_bit(NFS_DELEGATION_RETURNING, &delegation->flags))
444 if (test_and_clear_bit(NFS_DELEGATION_RETURN, &delegation->flags))
446 if (test_and_clear_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags) && !ret) {
449 spin_lock(&delegation->lock);
450 inode = delegation->inode;
451 if (inode && list_empty(&NFS_I(inode)->open_files))
453 spin_unlock(&delegation->lock);
460 * nfs_client_return_marked_delegations - return previously marked delegations
461 * @clp: nfs_client to process
463 * Note that this function is designed to be called by the state
464 * manager thread. For this reason, it cannot flush the dirty data,
465 * since that could deadlock in case of a state recovery error.
467 * Returns zero on success, or a negative errno value.
469 int nfs_client_return_marked_delegations(struct nfs_client *clp)
471 struct nfs_delegation *delegation;
472 struct nfs_server *server;
478 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
479 list_for_each_entry_rcu(delegation, &server->delegations,
481 if (!nfs_delegation_need_return(delegation))
483 if (!nfs_sb_active(server->super))
485 inode = nfs_delegation_grab_inode(delegation);
488 nfs_sb_deactive(server->super);
491 delegation = nfs_start_delegation_return_locked(NFS_I(inode));
494 err = nfs_end_delegation_return(inode, delegation, 0);
496 nfs_sb_deactive(server->super);
499 set_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state);
508 * nfs_inode_return_delegation_noreclaim - return delegation, don't reclaim opens
509 * @inode: inode to process
511 * Does not protect against delegation reclaims, therefore really only safe
512 * to be called from nfs4_clear_inode().
514 void nfs_inode_return_delegation_noreclaim(struct inode *inode)
516 struct nfs_delegation *delegation;
518 delegation = nfs_inode_detach_delegation(inode);
519 if (delegation != NULL)
520 nfs_do_return_delegation(inode, delegation, 1);
524 * nfs_inode_return_delegation - synchronously return a delegation
525 * @inode: inode to process
527 * This routine will always flush any dirty data to disk on the
528 * assumption that if we need to return the delegation, then
529 * we should stop caching.
531 * Returns zero on success, or a negative errno value.
533 int nfs4_inode_return_delegation(struct inode *inode)
535 struct nfs_inode *nfsi = NFS_I(inode);
536 struct nfs_delegation *delegation;
540 delegation = nfs_start_delegation_return(nfsi);
541 if (delegation != NULL)
542 err = nfs_end_delegation_return(inode, delegation, 1);
546 static void nfs_mark_return_if_closed_delegation(struct nfs_server *server,
547 struct nfs_delegation *delegation)
549 set_bit(NFS_DELEGATION_RETURN_IF_CLOSED, &delegation->flags);
550 set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state);
553 static void nfs_mark_return_delegation(struct nfs_server *server,
554 struct nfs_delegation *delegation)
556 set_bit(NFS_DELEGATION_RETURN, &delegation->flags);
557 set_bit(NFS4CLNT_DELEGRETURN, &server->nfs_client->cl_state);
560 static bool nfs_server_mark_return_all_delegations(struct nfs_server *server)
562 struct nfs_delegation *delegation;
565 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
566 nfs_mark_return_delegation(server, delegation);
572 static void nfs_client_mark_return_all_delegations(struct nfs_client *clp)
574 struct nfs_server *server;
577 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
578 nfs_server_mark_return_all_delegations(server);
582 static void nfs_delegation_run_state_manager(struct nfs_client *clp)
584 if (test_bit(NFS4CLNT_DELEGRETURN, &clp->cl_state))
585 nfs4_schedule_state_manager(clp);
589 * nfs_expire_all_delegations
590 * @clp: client to process
593 void nfs_expire_all_delegations(struct nfs_client *clp)
595 nfs_client_mark_return_all_delegations(clp);
596 nfs_delegation_run_state_manager(clp);
600 * nfs_super_return_all_delegations - return delegations for one superblock
604 void nfs_server_return_all_delegations(struct nfs_server *server)
606 struct nfs_client *clp = server->nfs_client;
613 need_wait = nfs_server_mark_return_all_delegations(server);
617 nfs4_schedule_state_manager(clp);
618 nfs4_wait_clnt_recover(clp);
622 static void nfs_mark_return_unused_delegation_types(struct nfs_server *server,
625 struct nfs_delegation *delegation;
627 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
628 if ((delegation->type == (FMODE_READ|FMODE_WRITE)) && !(flags & FMODE_WRITE))
630 if (delegation->type & flags)
631 nfs_mark_return_if_closed_delegation(server, delegation);
635 static void nfs_client_mark_return_unused_delegation_types(struct nfs_client *clp,
638 struct nfs_server *server;
641 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
642 nfs_mark_return_unused_delegation_types(server, flags);
646 static void nfs_revoke_delegation(struct inode *inode)
648 struct nfs_delegation *delegation;
650 delegation = rcu_dereference(NFS_I(inode)->delegation);
651 if (delegation != NULL) {
652 set_bit(NFS_DELEGATION_REVOKED, &delegation->flags);
653 nfs_mark_return_delegation(NFS_SERVER(inode), delegation);
658 void nfs_remove_bad_delegation(struct inode *inode)
660 struct nfs_delegation *delegation;
662 nfs_revoke_delegation(inode);
663 delegation = nfs_inode_detach_delegation(inode);
665 nfs_inode_find_state_and_recover(inode, &delegation->stateid);
666 nfs_free_delegation(delegation);
669 EXPORT_SYMBOL_GPL(nfs_remove_bad_delegation);
672 * nfs_expire_unused_delegation_types
673 * @clp: client to process
674 * @flags: delegation types to expire
677 void nfs_expire_unused_delegation_types(struct nfs_client *clp, fmode_t flags)
679 nfs_client_mark_return_unused_delegation_types(clp, flags);
680 nfs_delegation_run_state_manager(clp);
683 static void nfs_mark_return_unreferenced_delegations(struct nfs_server *server)
685 struct nfs_delegation *delegation;
687 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
688 if (test_and_clear_bit(NFS_DELEGATION_REFERENCED, &delegation->flags))
690 nfs_mark_return_if_closed_delegation(server, delegation);
695 * nfs_expire_unreferenced_delegations - Eliminate unused delegations
696 * @clp: nfs_client to process
699 void nfs_expire_unreferenced_delegations(struct nfs_client *clp)
701 struct nfs_server *server;
704 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
705 nfs_mark_return_unreferenced_delegations(server);
708 nfs_delegation_run_state_manager(clp);
712 * nfs_async_inode_return_delegation - asynchronously return a delegation
713 * @inode: inode to process
714 * @stateid: state ID information
716 * Returns zero on success, or a negative errno value.
718 int nfs_async_inode_return_delegation(struct inode *inode,
719 const nfs4_stateid *stateid)
721 struct nfs_server *server = NFS_SERVER(inode);
722 struct nfs_client *clp = server->nfs_client;
723 struct nfs_delegation *delegation;
726 delegation = rcu_dereference(NFS_I(inode)->delegation);
727 if (delegation == NULL)
729 if (stateid != NULL &&
730 !clp->cl_mvops->match_stateid(&delegation->stateid, stateid))
732 nfs_mark_return_delegation(server, delegation);
735 nfs_delegation_run_state_manager(clp);
742 static struct inode *
743 nfs_delegation_find_inode_server(struct nfs_server *server,
744 const struct nfs_fh *fhandle)
746 struct nfs_delegation *delegation;
747 struct inode *res = NULL;
749 list_for_each_entry_rcu(delegation, &server->delegations, super_list) {
750 spin_lock(&delegation->lock);
751 if (delegation->inode != NULL &&
752 nfs_compare_fh(fhandle, &NFS_I(delegation->inode)->fh) == 0) {
753 res = igrab(delegation->inode);
755 spin_unlock(&delegation->lock);
763 * nfs_delegation_find_inode - retrieve the inode associated with a delegation
764 * @clp: client state handle
765 * @fhandle: filehandle from a delegation recall
767 * Returns pointer to inode matching "fhandle," or NULL if a matching inode
770 struct inode *nfs_delegation_find_inode(struct nfs_client *clp,
771 const struct nfs_fh *fhandle)
773 struct nfs_server *server;
774 struct inode *res = NULL;
777 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
778 res = nfs_delegation_find_inode_server(server, fhandle);
786 static void nfs_delegation_mark_reclaim_server(struct nfs_server *server)
788 struct nfs_delegation *delegation;
790 list_for_each_entry_rcu(delegation, &server->delegations, super_list)
791 set_bit(NFS_DELEGATION_NEED_RECLAIM, &delegation->flags);
795 * nfs_delegation_mark_reclaim - mark all delegations as needing to be reclaimed
796 * @clp: nfs_client to process
799 void nfs_delegation_mark_reclaim(struct nfs_client *clp)
801 struct nfs_server *server;
804 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
805 nfs_delegation_mark_reclaim_server(server);
810 * nfs_delegation_reap_unclaimed - reap unclaimed delegations after reboot recovery is done
811 * @clp: nfs_client to process
814 void nfs_delegation_reap_unclaimed(struct nfs_client *clp)
816 struct nfs_delegation *delegation;
817 struct nfs_server *server;
822 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
823 list_for_each_entry_rcu(delegation, &server->delegations,
825 if (test_bit(NFS_DELEGATION_RETURNING,
828 if (test_bit(NFS_DELEGATION_NEED_RECLAIM,
829 &delegation->flags) == 0)
831 if (!nfs_sb_active(server->super))
833 inode = nfs_delegation_grab_inode(delegation);
836 nfs_sb_deactive(server->super);
839 delegation = nfs_start_delegation_return_locked(NFS_I(inode));
841 if (delegation != NULL) {
842 delegation = nfs_detach_delegation(NFS_I(inode),
844 if (delegation != NULL)
845 nfs_free_delegation(delegation);
848 nfs_sb_deactive(server->super);
856 * nfs_delegations_present - check for existence of delegations
857 * @clp: client state handle
859 * Returns one if there are any nfs_delegation structures attached
860 * to this nfs_client.
862 int nfs_delegations_present(struct nfs_client *clp)
864 struct nfs_server *server;
868 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link)
869 if (!list_empty(&server->delegations)) {
878 * nfs4_copy_delegation_stateid - Copy inode's state ID information
879 * @inode: inode to check
880 * @flags: delegation type requirement
881 * @dst: stateid data structure to fill in
882 * @cred: optional argument to retrieve credential
884 * Returns "true" and fills in "dst->data" * if inode had a delegation,
885 * otherwise "false" is returned.
887 bool nfs4_copy_delegation_stateid(struct inode *inode, fmode_t flags,
888 nfs4_stateid *dst, struct rpc_cred **cred)
890 struct nfs_inode *nfsi = NFS_I(inode);
891 struct nfs_delegation *delegation;
894 flags &= FMODE_READ|FMODE_WRITE;
896 delegation = rcu_dereference(nfsi->delegation);
897 ret = (delegation != NULL && (delegation->type & flags) == flags);
899 nfs4_stateid_copy(dst, &delegation->stateid);
900 nfs_mark_delegation_referenced(delegation);
902 *cred = get_rpccred(delegation->cred);
909 * nfs4_delegation_flush_on_close - Check if we must flush file on close
910 * @inode: inode to check
912 * This function checks the number of outstanding writes to the file
913 * against the delegation 'space_limit' field to see if
914 * the spec requires us to flush the file on close.
916 bool nfs4_delegation_flush_on_close(const struct inode *inode)
918 struct nfs_inode *nfsi = NFS_I(inode);
919 struct nfs_delegation *delegation;
923 delegation = rcu_dereference(nfsi->delegation);
924 if (delegation == NULL || !(delegation->type & FMODE_WRITE))
926 if (nfsi->nrequests < delegation->pagemod_limit)