2 * pNFS functions to call and manage layout drivers.
4 * Copyright (c) 2002 [year of first publication]
5 * The Regents of the University of Michigan
8 * Dean Hildebrand <dhildebz@umich.edu>
10 * Permission is granted to use, copy, create derivative works, and
11 * redistribute this software and such derivative works for any purpose,
12 * so long as the name of the University of Michigan is not used in
13 * any advertising or publicity pertaining to the use or distribution
14 * of this software without specific, written prior authorization. If
15 * the above copyright notice or any other identification of the
16 * University of Michigan is included in any copy of any portion of
17 * this software, then the disclaimer below must also be included.
19 * This software is provided as is, without representation or warranty
20 * of any kind either express or implied, including without limitation
21 * the implied warranties of merchantability, fitness for a particular
22 * purpose, or noninfringement. The Regents of the University of
23 * Michigan shall not be liable for any damages, including special,
24 * indirect, incidental, or consequential damages, with respect to any
25 * claim arising out of or in connection with the use of the software,
26 * even if it has been or is hereafter advised of the possibility of
30 #include <linux/nfs_fs.h>
31 #include <linux/nfs_page.h>
32 #include <linux/module.h>
36 #include "nfs4trace.h"
38 #define NFSDBG_FACILITY NFSDBG_PNFS
39 #define PNFS_LAYOUTGET_RETRY_TIMEOUT (120*HZ)
44 * protects pnfs_modules_tbl.
46 static DEFINE_SPINLOCK(pnfs_spinlock);
49 * pnfs_modules_tbl holds all pnfs modules
51 static LIST_HEAD(pnfs_modules_tbl);
54 pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, nfs4_stateid stateid,
55 enum pnfs_iomode iomode, bool sync);
57 /* Return the registered pnfs layout driver module matching given id */
58 static struct pnfs_layoutdriver_type *
59 find_pnfs_driver_locked(u32 id)
61 struct pnfs_layoutdriver_type *local;
63 list_for_each_entry(local, &pnfs_modules_tbl, pnfs_tblid)
68 dprintk("%s: Searching for id %u, found %p\n", __func__, id, local);
72 static struct pnfs_layoutdriver_type *
73 find_pnfs_driver(u32 id)
75 struct pnfs_layoutdriver_type *local;
77 spin_lock(&pnfs_spinlock);
78 local = find_pnfs_driver_locked(id);
79 if (local != NULL && !try_module_get(local->owner)) {
80 dprintk("%s: Could not grab reference on module\n", __func__);
83 spin_unlock(&pnfs_spinlock);
88 unset_pnfs_layoutdriver(struct nfs_server *nfss)
90 if (nfss->pnfs_curr_ld) {
91 if (nfss->pnfs_curr_ld->clear_layoutdriver)
92 nfss->pnfs_curr_ld->clear_layoutdriver(nfss);
93 /* Decrement the MDS count. Purge the deviceid cache if zero */
94 if (atomic_dec_and_test(&nfss->nfs_client->cl_mds_count))
95 nfs4_deviceid_purge_client(nfss->nfs_client);
96 module_put(nfss->pnfs_curr_ld->owner);
98 nfss->pnfs_curr_ld = NULL;
102 * Try to set the server's pnfs module to the pnfs layout type specified by id.
103 * Currently only one pNFS layout driver per filesystem is supported.
105 * @id layout type. Zero (illegal layout type) indicates pNFS not in use.
108 set_pnfs_layoutdriver(struct nfs_server *server, const struct nfs_fh *mntfh,
111 struct pnfs_layoutdriver_type *ld_type = NULL;
115 if (!(server->nfs_client->cl_exchange_flags &
116 (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) {
117 printk(KERN_ERR "NFS: %s: id %u cl_exchange_flags 0x%x\n",
118 __func__, id, server->nfs_client->cl_exchange_flags);
121 ld_type = find_pnfs_driver(id);
123 request_module("%s-%u", LAYOUT_NFSV4_1_MODULE_PREFIX, id);
124 ld_type = find_pnfs_driver(id);
126 dprintk("%s: No pNFS module found for %u.\n",
131 server->pnfs_curr_ld = ld_type;
132 if (ld_type->set_layoutdriver
133 && ld_type->set_layoutdriver(server, mntfh)) {
134 printk(KERN_ERR "NFS: %s: Error initializing pNFS layout "
135 "driver %u.\n", __func__, id);
136 module_put(ld_type->owner);
139 /* Bump the MDS count */
140 atomic_inc(&server->nfs_client->cl_mds_count);
142 dprintk("%s: pNFS module for %u set\n", __func__, id);
146 dprintk("%s: Using NFSv4 I/O\n", __func__);
147 server->pnfs_curr_ld = NULL;
151 pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
153 int status = -EINVAL;
154 struct pnfs_layoutdriver_type *tmp;
156 if (ld_type->id == 0) {
157 printk(KERN_ERR "NFS: %s id 0 is reserved\n", __func__);
160 if (!ld_type->alloc_lseg || !ld_type->free_lseg) {
161 printk(KERN_ERR "NFS: %s Layout driver must provide "
162 "alloc_lseg and free_lseg.\n", __func__);
166 spin_lock(&pnfs_spinlock);
167 tmp = find_pnfs_driver_locked(ld_type->id);
169 list_add(&ld_type->pnfs_tblid, &pnfs_modules_tbl);
171 dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id,
174 printk(KERN_ERR "NFS: %s Module with id %d already loaded!\n",
175 __func__, ld_type->id);
177 spin_unlock(&pnfs_spinlock);
181 EXPORT_SYMBOL_GPL(pnfs_register_layoutdriver);
184 pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
186 dprintk("%s Deregistering id:%u\n", __func__, ld_type->id);
187 spin_lock(&pnfs_spinlock);
188 list_del(&ld_type->pnfs_tblid);
189 spin_unlock(&pnfs_spinlock);
191 EXPORT_SYMBOL_GPL(pnfs_unregister_layoutdriver);
194 * pNFS client layout cache
197 /* Need to hold i_lock if caller does not already hold reference */
199 pnfs_get_layout_hdr(struct pnfs_layout_hdr *lo)
201 atomic_inc(&lo->plh_refcount);
204 static struct pnfs_layout_hdr *
205 pnfs_alloc_layout_hdr(struct inode *ino, gfp_t gfp_flags)
207 struct pnfs_layoutdriver_type *ld = NFS_SERVER(ino)->pnfs_curr_ld;
208 return ld->alloc_layout_hdr(ino, gfp_flags);
212 pnfs_free_layout_hdr(struct pnfs_layout_hdr *lo)
214 struct nfs_server *server = NFS_SERVER(lo->plh_inode);
215 struct pnfs_layoutdriver_type *ld = server->pnfs_curr_ld;
217 if (!list_empty(&lo->plh_layouts)) {
218 struct nfs_client *clp = server->nfs_client;
220 spin_lock(&clp->cl_lock);
221 list_del_init(&lo->plh_layouts);
222 spin_unlock(&clp->cl_lock);
224 put_rpccred(lo->plh_lc_cred);
225 return ld->free_layout_hdr(lo);
229 pnfs_detach_layout_hdr(struct pnfs_layout_hdr *lo)
231 struct nfs_inode *nfsi = NFS_I(lo->plh_inode);
232 dprintk("%s: freeing layout cache %p\n", __func__, lo);
234 /* Reset MDS Threshold I/O counters */
240 pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo)
242 struct inode *inode = lo->plh_inode;
244 if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) {
245 if (!list_empty(&lo->plh_segs))
246 WARN_ONCE(1, "NFS: BUG unfreed layout segments.\n");
247 pnfs_detach_layout_hdr(lo);
248 spin_unlock(&inode->i_lock);
249 pnfs_free_layout_hdr(lo);
254 pnfs_iomode_to_fail_bit(u32 iomode)
256 return iomode == IOMODE_RW ?
257 NFS_LAYOUT_RW_FAILED : NFS_LAYOUT_RO_FAILED;
261 pnfs_layout_set_fail_bit(struct pnfs_layout_hdr *lo, int fail_bit)
263 lo->plh_retry_timestamp = jiffies;
264 if (!test_and_set_bit(fail_bit, &lo->plh_flags))
265 atomic_inc(&lo->plh_refcount);
269 pnfs_layout_clear_fail_bit(struct pnfs_layout_hdr *lo, int fail_bit)
271 if (test_and_clear_bit(fail_bit, &lo->plh_flags))
272 atomic_dec(&lo->plh_refcount);
276 pnfs_layout_io_set_failed(struct pnfs_layout_hdr *lo, u32 iomode)
278 struct inode *inode = lo->plh_inode;
279 struct pnfs_layout_range range = {
282 .length = NFS4_MAX_UINT64,
286 spin_lock(&inode->i_lock);
287 pnfs_layout_set_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode));
288 pnfs_mark_matching_lsegs_invalid(lo, &head, &range);
289 spin_unlock(&inode->i_lock);
290 pnfs_free_lseg_list(&head);
291 dprintk("%s Setting layout IOMODE_%s fail bit\n", __func__,
292 iomode == IOMODE_RW ? "RW" : "READ");
296 pnfs_layout_io_test_failed(struct pnfs_layout_hdr *lo, u32 iomode)
298 unsigned long start, end;
299 int fail_bit = pnfs_iomode_to_fail_bit(iomode);
301 if (test_bit(fail_bit, &lo->plh_flags) == 0)
304 start = end - PNFS_LAYOUTGET_RETRY_TIMEOUT;
305 if (!time_in_range(lo->plh_retry_timestamp, start, end)) {
306 /* It is time to retry the failed layoutgets */
307 pnfs_layout_clear_fail_bit(lo, fail_bit);
314 init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg)
316 INIT_LIST_HEAD(&lseg->pls_list);
317 INIT_LIST_HEAD(&lseg->pls_lc_list);
318 atomic_set(&lseg->pls_refcount, 1);
320 set_bit(NFS_LSEG_VALID, &lseg->pls_flags);
321 lseg->pls_layout = lo;
324 static void pnfs_free_lseg(struct pnfs_layout_segment *lseg)
326 struct inode *ino = lseg->pls_layout->plh_inode;
328 NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
332 pnfs_layout_remove_lseg(struct pnfs_layout_hdr *lo,
333 struct pnfs_layout_segment *lseg)
335 struct inode *inode = lo->plh_inode;
337 WARN_ON(test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
338 list_del_init(&lseg->pls_list);
339 /* Matched by pnfs_get_layout_hdr in pnfs_layout_insert_lseg */
340 atomic_dec(&lo->plh_refcount);
341 if (list_empty(&lo->plh_segs))
342 clear_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags);
343 rpc_wake_up(&NFS_SERVER(inode)->roc_rpcwaitq);
346 /* Return true if layoutreturn is needed */
348 pnfs_layout_need_return(struct pnfs_layout_hdr *lo,
349 struct pnfs_layout_segment *lseg)
351 struct pnfs_layout_segment *s;
353 if (!test_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags))
356 list_for_each_entry(s, &lo->plh_segs, pls_list)
357 if (s != lseg && test_bit(NFS_LSEG_LAYOUTRETURN, &s->pls_flags))
363 static void pnfs_layoutreturn_free_lseg(struct work_struct *work)
365 struct pnfs_layout_segment *lseg;
366 struct pnfs_layout_hdr *lo;
369 lseg = container_of(work, struct pnfs_layout_segment, pls_work);
370 WARN_ON(atomic_read(&lseg->pls_refcount));
371 lo = lseg->pls_layout;
372 inode = lo->plh_inode;
374 spin_lock(&inode->i_lock);
375 if (pnfs_layout_need_return(lo, lseg)) {
376 nfs4_stateid stateid;
377 enum pnfs_iomode iomode;
379 stateid = lo->plh_stateid;
380 iomode = lo->plh_return_iomode;
381 /* decreased in pnfs_send_layoutreturn() */
382 lo->plh_block_lgets++;
383 lo->plh_return_iomode = 0;
384 spin_unlock(&inode->i_lock);
386 pnfs_send_layoutreturn(lo, stateid, iomode, true);
387 spin_lock(&inode->i_lock);
389 /* match pnfs_get_layout_hdr #2 in pnfs_put_lseg */
390 pnfs_put_layout_hdr(lo);
391 pnfs_layout_remove_lseg(lo, lseg);
392 spin_unlock(&inode->i_lock);
393 pnfs_free_lseg(lseg);
394 /* match pnfs_get_layout_hdr #1 in pnfs_put_lseg */
395 pnfs_put_layout_hdr(lo);
399 pnfs_layoutreturn_free_lseg_async(struct pnfs_layout_segment *lseg)
401 INIT_WORK(&lseg->pls_work, pnfs_layoutreturn_free_lseg);
402 queue_work(nfsiod_workqueue, &lseg->pls_work);
406 pnfs_put_lseg(struct pnfs_layout_segment *lseg)
408 struct pnfs_layout_hdr *lo;
414 dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg,
415 atomic_read(&lseg->pls_refcount),
416 test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
417 lo = lseg->pls_layout;
418 inode = lo->plh_inode;
419 if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) {
420 pnfs_get_layout_hdr(lo);
421 if (pnfs_layout_need_return(lo, lseg)) {
422 spin_unlock(&inode->i_lock);
423 /* hdr reference dropped in nfs4_layoutreturn_release */
424 pnfs_get_layout_hdr(lo);
425 pnfs_layoutreturn_free_lseg_async(lseg);
427 pnfs_layout_remove_lseg(lo, lseg);
428 spin_unlock(&inode->i_lock);
429 pnfs_free_lseg(lseg);
430 pnfs_put_layout_hdr(lo);
434 EXPORT_SYMBOL_GPL(pnfs_put_lseg);
436 static void pnfs_free_lseg_async_work(struct work_struct *work)
438 struct pnfs_layout_segment *lseg;
439 struct pnfs_layout_hdr *lo;
441 lseg = container_of(work, struct pnfs_layout_segment, pls_work);
442 lo = lseg->pls_layout;
444 pnfs_free_lseg(lseg);
445 pnfs_put_layout_hdr(lo);
448 static void pnfs_free_lseg_async(struct pnfs_layout_segment *lseg)
450 INIT_WORK(&lseg->pls_work, pnfs_free_lseg_async_work);
451 schedule_work(&lseg->pls_work);
455 pnfs_put_lseg_locked(struct pnfs_layout_segment *lseg)
460 assert_spin_locked(&lseg->pls_layout->plh_inode->i_lock);
462 dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg,
463 atomic_read(&lseg->pls_refcount),
464 test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
465 if (atomic_dec_and_test(&lseg->pls_refcount)) {
466 struct pnfs_layout_hdr *lo = lseg->pls_layout;
467 pnfs_get_layout_hdr(lo);
468 pnfs_layout_remove_lseg(lo, lseg);
469 pnfs_free_lseg_async(lseg);
472 EXPORT_SYMBOL_GPL(pnfs_put_lseg_locked);
475 end_offset(u64 start, u64 len)
480 return end >= start ? end : NFS4_MAX_UINT64;
484 * is l2 fully contained in l1?
486 * [----------------------------------)
491 pnfs_lseg_range_contained(const struct pnfs_layout_range *l1,
492 const struct pnfs_layout_range *l2)
494 u64 start1 = l1->offset;
495 u64 end1 = end_offset(start1, l1->length);
496 u64 start2 = l2->offset;
497 u64 end2 = end_offset(start2, l2->length);
499 return (start1 <= start2) && (end1 >= end2);
503 * is l1 and l2 intersecting?
505 * [----------------------------------)
510 pnfs_lseg_range_intersecting(const struct pnfs_layout_range *l1,
511 const struct pnfs_layout_range *l2)
513 u64 start1 = l1->offset;
514 u64 end1 = end_offset(start1, l1->length);
515 u64 start2 = l2->offset;
516 u64 end2 = end_offset(start2, l2->length);
518 return (end1 == NFS4_MAX_UINT64 || end1 > start2) &&
519 (end2 == NFS4_MAX_UINT64 || end2 > start1);
523 should_free_lseg(const struct pnfs_layout_range *lseg_range,
524 const struct pnfs_layout_range *recall_range)
526 return (recall_range->iomode == IOMODE_ANY ||
527 lseg_range->iomode == recall_range->iomode) &&
528 pnfs_lseg_range_intersecting(lseg_range, recall_range);
531 static bool pnfs_lseg_dec_and_remove_zero(struct pnfs_layout_segment *lseg,
532 struct list_head *tmp_list)
534 if (!atomic_dec_and_test(&lseg->pls_refcount))
536 pnfs_layout_remove_lseg(lseg->pls_layout, lseg);
537 list_add(&lseg->pls_list, tmp_list);
541 /* Returns 1 if lseg is removed from list, 0 otherwise */
542 static int mark_lseg_invalid(struct pnfs_layout_segment *lseg,
543 struct list_head *tmp_list)
547 if (test_and_clear_bit(NFS_LSEG_VALID, &lseg->pls_flags)) {
548 /* Remove the reference keeping the lseg in the
549 * list. It will now be removed when all
550 * outstanding io is finished.
552 dprintk("%s: lseg %p ref %d\n", __func__, lseg,
553 atomic_read(&lseg->pls_refcount));
554 if (pnfs_lseg_dec_and_remove_zero(lseg, tmp_list))
560 /* Returns count of number of matching invalid lsegs remaining in list
564 pnfs_mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo,
565 struct list_head *tmp_list,
566 struct pnfs_layout_range *recall_range)
568 struct pnfs_layout_segment *lseg, *next;
569 int invalid = 0, removed = 0;
571 dprintk("%s:Begin lo %p\n", __func__, lo);
573 if (list_empty(&lo->plh_segs))
575 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list)
577 should_free_lseg(&lseg->pls_range, recall_range)) {
578 dprintk("%s: freeing lseg %p iomode %d "
579 "offset %llu length %llu\n", __func__,
580 lseg, lseg->pls_range.iomode, lseg->pls_range.offset,
581 lseg->pls_range.length);
583 removed += mark_lseg_invalid(lseg, tmp_list);
585 dprintk("%s:Return %i\n", __func__, invalid - removed);
586 return invalid - removed;
589 /* note free_me must contain lsegs from a single layout_hdr */
591 pnfs_free_lseg_list(struct list_head *free_me)
593 struct pnfs_layout_segment *lseg, *tmp;
595 if (list_empty(free_me))
598 list_for_each_entry_safe(lseg, tmp, free_me, pls_list) {
599 list_del(&lseg->pls_list);
600 pnfs_free_lseg(lseg);
605 pnfs_destroy_layout(struct nfs_inode *nfsi)
607 struct pnfs_layout_hdr *lo;
610 spin_lock(&nfsi->vfs_inode.i_lock);
613 lo->plh_block_lgets++; /* permanently block new LAYOUTGETs */
614 pnfs_mark_matching_lsegs_invalid(lo, &tmp_list, NULL);
615 pnfs_get_layout_hdr(lo);
616 pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RO_FAILED);
617 pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RW_FAILED);
618 spin_unlock(&nfsi->vfs_inode.i_lock);
619 pnfs_free_lseg_list(&tmp_list);
620 pnfs_put_layout_hdr(lo);
622 spin_unlock(&nfsi->vfs_inode.i_lock);
624 EXPORT_SYMBOL_GPL(pnfs_destroy_layout);
627 pnfs_layout_add_bulk_destroy_list(struct inode *inode,
628 struct list_head *layout_list)
630 struct pnfs_layout_hdr *lo;
633 spin_lock(&inode->i_lock);
634 lo = NFS_I(inode)->layout;
635 if (lo != NULL && list_empty(&lo->plh_bulk_destroy)) {
636 pnfs_get_layout_hdr(lo);
637 list_add(&lo->plh_bulk_destroy, layout_list);
640 spin_unlock(&inode->i_lock);
644 /* Caller must hold rcu_read_lock and clp->cl_lock */
646 pnfs_layout_bulk_destroy_byserver_locked(struct nfs_client *clp,
647 struct nfs_server *server,
648 struct list_head *layout_list)
650 struct pnfs_layout_hdr *lo, *next;
653 list_for_each_entry_safe(lo, next, &server->layouts, plh_layouts) {
654 inode = igrab(lo->plh_inode);
657 list_del_init(&lo->plh_layouts);
658 if (pnfs_layout_add_bulk_destroy_list(inode, layout_list))
661 spin_unlock(&clp->cl_lock);
663 spin_lock(&clp->cl_lock);
671 pnfs_layout_free_bulk_destroy_list(struct list_head *layout_list,
674 struct pnfs_layout_hdr *lo;
676 struct pnfs_layout_range range = {
677 .iomode = IOMODE_ANY,
679 .length = NFS4_MAX_UINT64,
681 LIST_HEAD(lseg_list);
684 while (!list_empty(layout_list)) {
685 lo = list_entry(layout_list->next, struct pnfs_layout_hdr,
687 dprintk("%s freeing layout for inode %lu\n", __func__,
688 lo->plh_inode->i_ino);
689 inode = lo->plh_inode;
691 pnfs_layoutcommit_inode(inode, false);
693 spin_lock(&inode->i_lock);
694 list_del_init(&lo->plh_bulk_destroy);
695 lo->plh_block_lgets++; /* permanently block new LAYOUTGETs */
697 set_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags);
698 if (pnfs_mark_matching_lsegs_invalid(lo, &lseg_list, &range))
700 spin_unlock(&inode->i_lock);
701 pnfs_free_lseg_list(&lseg_list);
702 pnfs_put_layout_hdr(lo);
709 pnfs_destroy_layouts_byfsid(struct nfs_client *clp,
710 struct nfs_fsid *fsid,
713 struct nfs_server *server;
714 LIST_HEAD(layout_list);
716 spin_lock(&clp->cl_lock);
719 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
720 if (memcmp(&server->fsid, fsid, sizeof(*fsid)) != 0)
722 if (pnfs_layout_bulk_destroy_byserver_locked(clp,
728 spin_unlock(&clp->cl_lock);
730 if (list_empty(&layout_list))
732 return pnfs_layout_free_bulk_destroy_list(&layout_list, is_recall);
736 pnfs_destroy_layouts_byclid(struct nfs_client *clp,
739 struct nfs_server *server;
740 LIST_HEAD(layout_list);
742 spin_lock(&clp->cl_lock);
745 list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
746 if (pnfs_layout_bulk_destroy_byserver_locked(clp,
752 spin_unlock(&clp->cl_lock);
754 if (list_empty(&layout_list))
756 return pnfs_layout_free_bulk_destroy_list(&layout_list, is_recall);
760 * Called by the state manger to remove all layouts established under an
764 pnfs_destroy_all_layouts(struct nfs_client *clp)
766 nfs4_deviceid_mark_client_invalid(clp);
767 nfs4_deviceid_purge_client(clp);
769 pnfs_destroy_layouts_byclid(clp, false);
773 * Compare 2 layout stateid sequence ids, to see which is newer,
774 * taking into account wraparound issues.
776 static bool pnfs_seqid_is_newer(u32 s1, u32 s2)
778 return (s32)(s1 - s2) > 0;
781 /* update lo->plh_stateid with new if is more recent */
783 pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
786 u32 oldseq, newseq, new_barrier;
787 int empty = list_empty(&lo->plh_segs);
789 oldseq = be32_to_cpu(lo->plh_stateid.seqid);
790 newseq = be32_to_cpu(new->seqid);
791 if (empty || pnfs_seqid_is_newer(newseq, oldseq)) {
792 nfs4_stateid_copy(&lo->plh_stateid, new);
793 if (update_barrier) {
794 new_barrier = be32_to_cpu(new->seqid);
796 /* Because of wraparound, we want to keep the barrier
797 * "close" to the current seqids.
799 new_barrier = newseq - atomic_read(&lo->plh_outstanding);
801 if (empty || pnfs_seqid_is_newer(new_barrier, lo->plh_barrier))
802 lo->plh_barrier = new_barrier;
807 pnfs_layout_stateid_blocked(const struct pnfs_layout_hdr *lo,
808 const nfs4_stateid *stateid)
810 u32 seqid = be32_to_cpu(stateid->seqid);
812 return !pnfs_seqid_is_newer(seqid, lo->plh_barrier);
816 pnfs_layout_returning(const struct pnfs_layout_hdr *lo,
817 struct pnfs_layout_range *range)
819 return test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags) &&
820 (lo->plh_return_iomode == IOMODE_ANY ||
821 lo->plh_return_iomode == range->iomode);
824 /* lget is set to 1 if called from inside send_layoutget call chain */
826 pnfs_layoutgets_blocked(const struct pnfs_layout_hdr *lo,
827 struct pnfs_layout_range *range, int lget)
829 return lo->plh_block_lgets ||
830 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
831 (list_empty(&lo->plh_segs) &&
832 (atomic_read(&lo->plh_outstanding) > lget)) ||
833 pnfs_layout_returning(lo, range);
837 pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
838 struct pnfs_layout_range *range,
839 struct nfs4_state *open_state)
843 dprintk("--> %s\n", __func__);
844 spin_lock(&lo->plh_inode->i_lock);
845 if (pnfs_layoutgets_blocked(lo, range, 1)) {
847 } else if (!nfs4_valid_open_stateid(open_state)) {
849 } else if (list_empty(&lo->plh_segs) ||
850 test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags)) {
854 seq = read_seqbegin(&open_state->seqlock);
855 nfs4_stateid_copy(dst, &open_state->stateid);
856 } while (read_seqretry(&open_state->seqlock, seq));
858 nfs4_stateid_copy(dst, &lo->plh_stateid);
859 spin_unlock(&lo->plh_inode->i_lock);
860 dprintk("<-- %s\n", __func__);
865 * Get layout from server.
866 * for now, assume that whole file layouts are requested.
868 * arg->length: all ones
870 static struct pnfs_layout_segment *
871 send_layoutget(struct pnfs_layout_hdr *lo,
872 struct nfs_open_context *ctx,
873 struct pnfs_layout_range *range,
876 struct inode *ino = lo->plh_inode;
877 struct nfs_server *server = NFS_SERVER(ino);
878 struct nfs4_layoutget *lgp;
879 struct pnfs_layout_segment *lseg;
881 dprintk("--> %s\n", __func__);
883 lgp = kzalloc(sizeof(*lgp), gfp_flags);
887 lgp->args.minlength = PAGE_CACHE_SIZE;
888 if (lgp->args.minlength > range->length)
889 lgp->args.minlength = range->length;
890 lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE;
891 lgp->args.range = *range;
892 lgp->args.type = server->pnfs_curr_ld->id;
893 lgp->args.inode = ino;
894 lgp->args.ctx = get_nfs_open_context(ctx);
895 lgp->gfp_flags = gfp_flags;
896 lgp->cred = lo->plh_lc_cred;
898 /* Synchronously retrieve layout information from server and
901 lseg = nfs4_proc_layoutget(lgp, gfp_flags);
903 switch (PTR_ERR(lseg)) {
908 /* remember that LAYOUTGET failed and suspend trying */
909 pnfs_layout_io_set_failed(lo, range->iomode);
917 static void pnfs_clear_layoutcommit(struct inode *inode,
918 struct list_head *head)
920 struct nfs_inode *nfsi = NFS_I(inode);
921 struct pnfs_layout_segment *lseg, *tmp;
923 if (!test_and_clear_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags))
925 list_for_each_entry_safe(lseg, tmp, &nfsi->layout->plh_segs, pls_list) {
926 if (!test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, &lseg->pls_flags))
928 pnfs_lseg_dec_and_remove_zero(lseg, head);
933 pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, nfs4_stateid stateid,
934 enum pnfs_iomode iomode, bool sync)
936 struct inode *ino = lo->plh_inode;
937 struct nfs4_layoutreturn *lrp;
940 lrp = kzalloc(sizeof(*lrp), GFP_KERNEL);
941 if (unlikely(lrp == NULL)) {
943 spin_lock(&ino->i_lock);
944 lo->plh_block_lgets--;
945 rpc_wake_up(&NFS_SERVER(ino)->roc_rpcwaitq);
946 spin_unlock(&ino->i_lock);
947 pnfs_put_layout_hdr(lo);
951 lrp->args.stateid = stateid;
952 lrp->args.layout_type = NFS_SERVER(ino)->pnfs_curr_ld->id;
953 lrp->args.inode = ino;
954 lrp->args.range.iomode = iomode;
955 lrp->args.range.offset = 0;
956 lrp->args.range.length = NFS4_MAX_UINT64;
957 lrp->args.layout = lo;
958 lrp->clp = NFS_SERVER(ino)->nfs_client;
959 lrp->cred = lo->plh_lc_cred;
961 status = nfs4_proc_layoutreturn(lrp, sync);
963 dprintk("<-- %s status: %d\n", __func__, status);
968 * Initiates a LAYOUTRETURN(FILE), and removes the pnfs_layout_hdr
969 * when the layout segment list is empty.
971 * Note that a pnfs_layout_hdr can exist with an empty layout segment
972 * list when LAYOUTGET has failed, or when LAYOUTGET succeeded, but the
973 * deviceid is marked invalid.
976 _pnfs_return_layout(struct inode *ino)
978 struct pnfs_layout_hdr *lo = NULL;
979 struct nfs_inode *nfsi = NFS_I(ino);
981 nfs4_stateid stateid;
982 int status = 0, empty;
984 dprintk("NFS: %s for inode %lu\n", __func__, ino->i_ino);
986 spin_lock(&ino->i_lock);
989 spin_unlock(&ino->i_lock);
990 dprintk("NFS: %s no layout to return\n", __func__);
993 stateid = nfsi->layout->plh_stateid;
994 /* Reference matched in nfs4_layoutreturn_release */
995 pnfs_get_layout_hdr(lo);
996 empty = list_empty(&lo->plh_segs);
997 pnfs_clear_layoutcommit(ino, &tmp_list);
998 pnfs_mark_matching_lsegs_invalid(lo, &tmp_list, NULL);
1000 if (NFS_SERVER(ino)->pnfs_curr_ld->return_range) {
1001 struct pnfs_layout_range range = {
1002 .iomode = IOMODE_ANY,
1004 .length = NFS4_MAX_UINT64,
1006 NFS_SERVER(ino)->pnfs_curr_ld->return_range(lo, &range);
1009 /* Don't send a LAYOUTRETURN if list was initially empty */
1011 spin_unlock(&ino->i_lock);
1012 pnfs_put_layout_hdr(lo);
1013 dprintk("NFS: %s no layout segments to return\n", __func__);
1017 set_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags);
1018 lo->plh_block_lgets++;
1019 spin_unlock(&ino->i_lock);
1020 pnfs_free_lseg_list(&tmp_list);
1022 status = pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, true);
1024 dprintk("<-- %s status: %d\n", __func__, status);
1027 EXPORT_SYMBOL_GPL(_pnfs_return_layout);
1030 pnfs_commit_and_return_layout(struct inode *inode)
1032 struct pnfs_layout_hdr *lo;
1035 spin_lock(&inode->i_lock);
1036 lo = NFS_I(inode)->layout;
1038 spin_unlock(&inode->i_lock);
1041 pnfs_get_layout_hdr(lo);
1042 /* Block new layoutgets and read/write to ds */
1043 lo->plh_block_lgets++;
1044 spin_unlock(&inode->i_lock);
1045 filemap_fdatawait(inode->i_mapping);
1046 ret = pnfs_layoutcommit_inode(inode, true);
1048 ret = _pnfs_return_layout(inode);
1049 spin_lock(&inode->i_lock);
1050 lo->plh_block_lgets--;
1051 spin_unlock(&inode->i_lock);
1052 pnfs_put_layout_hdr(lo);
1056 bool pnfs_roc(struct inode *ino)
1058 struct pnfs_layout_hdr *lo;
1059 struct pnfs_layout_segment *lseg, *tmp;
1060 nfs4_stateid stateid;
1061 LIST_HEAD(tmp_list);
1062 bool found = false, layoutreturn = false;
1064 spin_lock(&ino->i_lock);
1065 lo = NFS_I(ino)->layout;
1066 if (!lo || !test_and_clear_bit(NFS_LAYOUT_ROC, &lo->plh_flags) ||
1067 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags))
1069 list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list)
1070 if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) {
1071 mark_lseg_invalid(lseg, &tmp_list);
1076 lo->plh_block_lgets++;
1077 pnfs_get_layout_hdr(lo); /* matched in pnfs_roc_release */
1078 spin_unlock(&ino->i_lock);
1079 pnfs_free_lseg_list(&tmp_list);
1084 stateid = lo->plh_stateid;
1086 test_and_clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE,
1089 lo->plh_block_lgets++;
1090 pnfs_get_layout_hdr(lo);
1093 spin_unlock(&ino->i_lock);
1095 pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, true);
1099 void pnfs_roc_release(struct inode *ino)
1101 struct pnfs_layout_hdr *lo;
1103 spin_lock(&ino->i_lock);
1104 lo = NFS_I(ino)->layout;
1105 lo->plh_block_lgets--;
1106 if (atomic_dec_and_test(&lo->plh_refcount)) {
1107 pnfs_detach_layout_hdr(lo);
1108 spin_unlock(&ino->i_lock);
1109 pnfs_free_layout_hdr(lo);
1111 spin_unlock(&ino->i_lock);
1114 void pnfs_roc_set_barrier(struct inode *ino, u32 barrier)
1116 struct pnfs_layout_hdr *lo;
1118 spin_lock(&ino->i_lock);
1119 lo = NFS_I(ino)->layout;
1120 if (pnfs_seqid_is_newer(barrier, lo->plh_barrier))
1121 lo->plh_barrier = barrier;
1122 spin_unlock(&ino->i_lock);
1125 bool pnfs_roc_drain(struct inode *ino, u32 *barrier, struct rpc_task *task)
1127 struct nfs_inode *nfsi = NFS_I(ino);
1128 struct pnfs_layout_hdr *lo;
1129 struct pnfs_layout_segment *lseg;
1130 nfs4_stateid stateid;
1132 bool found = false, layoutreturn = false;
1134 spin_lock(&ino->i_lock);
1135 list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list)
1136 if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) {
1137 rpc_sleep_on(&NFS_SERVER(ino)->roc_rpcwaitq, task, NULL);
1142 current_seqid = be32_to_cpu(lo->plh_stateid.seqid);
1144 /* Since close does not return a layout stateid for use as
1145 * a barrier, we choose the worst-case barrier.
1147 *barrier = current_seqid + atomic_read(&lo->plh_outstanding);
1150 stateid = lo->plh_stateid;
1152 test_and_clear_bit(NFS_LAYOUT_RETURN_BEFORE_CLOSE,
1155 lo->plh_block_lgets++;
1156 pnfs_get_layout_hdr(lo);
1159 spin_unlock(&ino->i_lock);
1161 rpc_sleep_on(&NFS_SERVER(ino)->roc_rpcwaitq, task, NULL);
1162 pnfs_send_layoutreturn(lo, stateid, IOMODE_ANY, false);
1168 * Compare two layout segments for sorting into layout cache.
1169 * We want to preferentially return RW over RO layouts, so ensure those
1173 pnfs_lseg_range_cmp(const struct pnfs_layout_range *l1,
1174 const struct pnfs_layout_range *l2)
1178 /* high offset > low offset */
1179 d = l1->offset - l2->offset;
1183 /* short length > long length */
1184 d = l2->length - l1->length;
1188 /* read > read/write */
1189 return (int)(l1->iomode == IOMODE_READ) - (int)(l2->iomode == IOMODE_READ);
1193 pnfs_layout_insert_lseg(struct pnfs_layout_hdr *lo,
1194 struct pnfs_layout_segment *lseg)
1196 struct pnfs_layout_segment *lp;
1198 dprintk("%s:Begin\n", __func__);
1200 list_for_each_entry(lp, &lo->plh_segs, pls_list) {
1201 if (pnfs_lseg_range_cmp(&lseg->pls_range, &lp->pls_range) > 0)
1203 list_add_tail(&lseg->pls_list, &lp->pls_list);
1204 dprintk("%s: inserted lseg %p "
1205 "iomode %d offset %llu length %llu before "
1206 "lp %p iomode %d offset %llu length %llu\n",
1207 __func__, lseg, lseg->pls_range.iomode,
1208 lseg->pls_range.offset, lseg->pls_range.length,
1209 lp, lp->pls_range.iomode, lp->pls_range.offset,
1210 lp->pls_range.length);
1213 list_add_tail(&lseg->pls_list, &lo->plh_segs);
1214 dprintk("%s: inserted lseg %p "
1215 "iomode %d offset %llu length %llu at tail\n",
1216 __func__, lseg, lseg->pls_range.iomode,
1217 lseg->pls_range.offset, lseg->pls_range.length);
1219 pnfs_get_layout_hdr(lo);
1221 dprintk("%s:Return\n", __func__);
1224 static struct pnfs_layout_hdr *
1225 alloc_init_layout_hdr(struct inode *ino,
1226 struct nfs_open_context *ctx,
1229 struct pnfs_layout_hdr *lo;
1231 lo = pnfs_alloc_layout_hdr(ino, gfp_flags);
1234 atomic_set(&lo->plh_refcount, 1);
1235 INIT_LIST_HEAD(&lo->plh_layouts);
1236 INIT_LIST_HEAD(&lo->plh_segs);
1237 INIT_LIST_HEAD(&lo->plh_bulk_destroy);
1238 lo->plh_inode = ino;
1239 lo->plh_lc_cred = get_rpccred(ctx->cred);
1243 static struct pnfs_layout_hdr *
1244 pnfs_find_alloc_layout(struct inode *ino,
1245 struct nfs_open_context *ctx,
1248 struct nfs_inode *nfsi = NFS_I(ino);
1249 struct pnfs_layout_hdr *new = NULL;
1251 dprintk("%s Begin ino=%p layout=%p\n", __func__, ino, nfsi->layout);
1253 if (nfsi->layout != NULL)
1255 spin_unlock(&ino->i_lock);
1256 new = alloc_init_layout_hdr(ino, ctx, gfp_flags);
1257 spin_lock(&ino->i_lock);
1259 if (likely(nfsi->layout == NULL)) { /* Won the race? */
1262 } else if (new != NULL)
1263 pnfs_free_layout_hdr(new);
1265 pnfs_get_layout_hdr(nfsi->layout);
1266 return nfsi->layout;
1270 * iomode matching rules:
1281 pnfs_lseg_range_match(const struct pnfs_layout_range *ls_range,
1282 const struct pnfs_layout_range *range)
1284 struct pnfs_layout_range range1;
1286 if ((range->iomode == IOMODE_RW &&
1287 ls_range->iomode != IOMODE_RW) ||
1288 !pnfs_lseg_range_intersecting(ls_range, range))
1291 /* range1 covers only the first byte in the range */
1294 return pnfs_lseg_range_contained(ls_range, &range1);
1298 * lookup range in layout
1300 static struct pnfs_layout_segment *
1301 pnfs_find_lseg(struct pnfs_layout_hdr *lo,
1302 struct pnfs_layout_range *range)
1304 struct pnfs_layout_segment *lseg, *ret = NULL;
1306 dprintk("%s:Begin\n", __func__);
1308 list_for_each_entry(lseg, &lo->plh_segs, pls_list) {
1309 if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) &&
1310 !test_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags) &&
1311 pnfs_lseg_range_match(&lseg->pls_range, range)) {
1312 ret = pnfs_get_lseg(lseg);
1315 if (lseg->pls_range.offset > range->offset)
1319 dprintk("%s:Return lseg %p ref %d\n",
1320 __func__, ret, ret ? atomic_read(&ret->pls_refcount) : 0);
1325 * Use mdsthreshold hints set at each OPEN to determine if I/O should go
1326 * to the MDS or over pNFS
1328 * The nfs_inode read_io and write_io fields are cumulative counters reset
1329 * when there are no layout segments. Note that in pnfs_update_layout iomode
1330 * is set to IOMODE_READ for a READ request, and set to IOMODE_RW for a
1333 * A return of true means use MDS I/O.
1336 * If a file's size is smaller than the file size threshold, data accesses
1337 * SHOULD be sent to the metadata server. If an I/O request has a length that
1338 * is below the I/O size threshold, the I/O SHOULD be sent to the metadata
1339 * server. If both file size and I/O size are provided, the client SHOULD
1340 * reach or exceed both thresholds before sending its read or write
1341 * requests to the data server.
1343 static bool pnfs_within_mdsthreshold(struct nfs_open_context *ctx,
1344 struct inode *ino, int iomode)
1346 struct nfs4_threshold *t = ctx->mdsthreshold;
1347 struct nfs_inode *nfsi = NFS_I(ino);
1348 loff_t fsize = i_size_read(ino);
1349 bool size = false, size_set = false, io = false, io_set = false, ret = false;
1354 dprintk("%s bm=0x%x rd_sz=%llu wr_sz=%llu rd_io=%llu wr_io=%llu\n",
1355 __func__, t->bm, t->rd_sz, t->wr_sz, t->rd_io_sz, t->wr_io_sz);
1359 if (t->bm & THRESHOLD_RD) {
1360 dprintk("%s fsize %llu\n", __func__, fsize);
1362 if (fsize < t->rd_sz)
1365 if (t->bm & THRESHOLD_RD_IO) {
1366 dprintk("%s nfsi->read_io %llu\n", __func__,
1369 if (nfsi->read_io < t->rd_io_sz)
1374 if (t->bm & THRESHOLD_WR) {
1375 dprintk("%s fsize %llu\n", __func__, fsize);
1377 if (fsize < t->wr_sz)
1380 if (t->bm & THRESHOLD_WR_IO) {
1381 dprintk("%s nfsi->write_io %llu\n", __func__,
1384 if (nfsi->write_io < t->wr_io_sz)
1389 if (size_set && io_set) {
1392 } else if (size || io)
1395 dprintk("<-- %s size %d io %d ret %d\n", __func__, size, io, ret);
1400 * Layout segment is retreived from the server if not cached.
1401 * The appropriate layout segment is referenced and returned to the caller.
1403 struct pnfs_layout_segment *
1404 pnfs_update_layout(struct inode *ino,
1405 struct nfs_open_context *ctx,
1408 enum pnfs_iomode iomode,
1411 struct pnfs_layout_range arg = {
1417 struct nfs_server *server = NFS_SERVER(ino);
1418 struct nfs_client *clp = server->nfs_client;
1419 struct pnfs_layout_hdr *lo;
1420 struct pnfs_layout_segment *lseg = NULL;
1423 if (!pnfs_enabled_sb(NFS_SERVER(ino)))
1426 if (pnfs_within_mdsthreshold(ctx, ino, iomode))
1431 spin_lock(&ino->i_lock);
1432 lo = pnfs_find_alloc_layout(ino, ctx, gfp_flags);
1434 spin_unlock(&ino->i_lock);
1438 /* Do we even need to bother with this? */
1439 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
1440 dprintk("%s matches recall, use MDS\n", __func__);
1444 /* if LAYOUTGET already failed once we don't try again */
1445 if (pnfs_layout_io_test_failed(lo, iomode))
1448 first = list_empty(&lo->plh_segs);
1450 /* The first layoutget for the file. Need to serialize per
1451 * RFC 5661 Errata 3208.
1453 if (test_and_set_bit(NFS_LAYOUT_FIRST_LAYOUTGET,
1455 spin_unlock(&ino->i_lock);
1456 wait_on_bit(&lo->plh_flags, NFS_LAYOUT_FIRST_LAYOUTGET,
1457 TASK_UNINTERRUPTIBLE);
1458 pnfs_put_layout_hdr(lo);
1462 /* Check to see if the layout for the given range
1465 lseg = pnfs_find_lseg(lo, &arg);
1470 if (pnfs_layoutgets_blocked(lo, &arg, 0))
1472 atomic_inc(&lo->plh_outstanding);
1473 spin_unlock(&ino->i_lock);
1475 if (list_empty(&lo->plh_layouts)) {
1476 /* The lo must be on the clp list if there is any
1477 * chance of a CB_LAYOUTRECALL(FILE) coming in.
1479 spin_lock(&clp->cl_lock);
1480 if (list_empty(&lo->plh_layouts))
1481 list_add_tail(&lo->plh_layouts, &server->layouts);
1482 spin_unlock(&clp->cl_lock);
1485 pg_offset = arg.offset & ~PAGE_CACHE_MASK;
1487 arg.offset -= pg_offset;
1488 arg.length += pg_offset;
1490 if (arg.length != NFS4_MAX_UINT64)
1491 arg.length = PAGE_CACHE_ALIGN(arg.length);
1493 lseg = send_layoutget(lo, ctx, &arg, gfp_flags);
1494 atomic_dec(&lo->plh_outstanding);
1497 unsigned long *bitlock = &lo->plh_flags;
1499 clear_bit_unlock(NFS_LAYOUT_FIRST_LAYOUTGET, bitlock);
1500 smp_mb__after_atomic();
1501 wake_up_bit(bitlock, NFS_LAYOUT_FIRST_LAYOUTGET);
1503 pnfs_put_layout_hdr(lo);
1505 dprintk("%s: inode %s/%llu pNFS layout segment %s for "
1506 "(%s, offset: %llu, length: %llu)\n",
1507 __func__, ino->i_sb->s_id,
1508 (unsigned long long)NFS_FILEID(ino),
1509 lseg == NULL ? "not found" : "found",
1510 iomode==IOMODE_RW ? "read/write" : "read-only",
1511 (unsigned long long)pos,
1512 (unsigned long long)count);
1515 spin_unlock(&ino->i_lock);
1516 goto out_put_layout_hdr;
1518 EXPORT_SYMBOL_GPL(pnfs_update_layout);
1520 struct pnfs_layout_segment *
1521 pnfs_layout_process(struct nfs4_layoutget *lgp)
1523 struct pnfs_layout_hdr *lo = NFS_I(lgp->args.inode)->layout;
1524 struct nfs4_layoutget_res *res = &lgp->res;
1525 struct pnfs_layout_segment *lseg;
1526 struct inode *ino = lo->plh_inode;
1530 /* Inject layout blob into I/O device driver */
1531 lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res, lgp->gfp_flags);
1532 if (!lseg || IS_ERR(lseg)) {
1536 status = PTR_ERR(lseg);
1537 dprintk("%s: Could not allocate layout: error %d\n",
1542 init_lseg(lo, lseg);
1543 lseg->pls_range = res->range;
1545 spin_lock(&ino->i_lock);
1546 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
1547 dprintk("%s forget reply due to recall\n", __func__);
1548 goto out_forget_reply;
1551 if (pnfs_layoutgets_blocked(lo, &lgp->args.range, 1)) {
1552 dprintk("%s forget reply due to state\n", __func__);
1553 goto out_forget_reply;
1556 if (nfs4_stateid_match_other(&lo->plh_stateid, &res->stateid)) {
1557 /* existing state ID, make sure the sequence number matches. */
1558 if (pnfs_layout_stateid_blocked(lo, &res->stateid)) {
1559 dprintk("%s forget reply due to sequence\n", __func__);
1560 goto out_forget_reply;
1562 pnfs_set_layout_stateid(lo, &res->stateid, false);
1565 * We got an entirely new state ID. Mark all segments for the
1566 * inode invalid, and don't bother validating the stateid
1569 pnfs_mark_matching_lsegs_invalid(lo, &free_me, NULL);
1571 nfs4_stateid_copy(&lo->plh_stateid, &res->stateid);
1572 lo->plh_barrier = be32_to_cpu(res->stateid.seqid);
1575 clear_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags);
1577 pnfs_get_lseg(lseg);
1578 pnfs_layout_insert_lseg(lo, lseg);
1580 if (res->return_on_close) {
1581 set_bit(NFS_LSEG_ROC, &lseg->pls_flags);
1582 set_bit(NFS_LAYOUT_ROC, &lo->plh_flags);
1585 spin_unlock(&ino->i_lock);
1586 pnfs_free_lseg_list(&free_me);
1589 return ERR_PTR(status);
1592 spin_unlock(&ino->i_lock);
1593 lseg->pls_layout = lo;
1594 NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
1599 pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo,
1600 struct list_head *tmp_list,
1601 struct pnfs_layout_range *return_range)
1603 struct pnfs_layout_segment *lseg, *next;
1605 dprintk("%s:Begin lo %p\n", __func__, lo);
1607 if (list_empty(&lo->plh_segs))
1610 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list)
1611 if (should_free_lseg(&lseg->pls_range, return_range)) {
1612 dprintk("%s: marking lseg %p iomode %d "
1613 "offset %llu length %llu\n", __func__,
1614 lseg, lseg->pls_range.iomode,
1615 lseg->pls_range.offset,
1616 lseg->pls_range.length);
1617 set_bit(NFS_LSEG_LAYOUTRETURN, &lseg->pls_flags);
1618 mark_lseg_invalid(lseg, tmp_list);
1622 void pnfs_error_mark_layout_for_return(struct inode *inode,
1623 struct pnfs_layout_segment *lseg)
1625 struct pnfs_layout_hdr *lo = NFS_I(inode)->layout;
1626 int iomode = pnfs_iomode_to_fail_bit(lseg->pls_range.iomode);
1627 struct pnfs_layout_range range = {
1628 .iomode = lseg->pls_range.iomode,
1630 .length = NFS4_MAX_UINT64,
1634 spin_lock(&inode->i_lock);
1635 /* set failure bit so that pnfs path will be retried later */
1636 pnfs_layout_set_fail_bit(lo, iomode);
1637 set_bit(NFS_LAYOUT_RETURN, &lo->plh_flags);
1638 if (lo->plh_return_iomode == 0)
1639 lo->plh_return_iomode = range.iomode;
1640 else if (lo->plh_return_iomode != range.iomode)
1641 lo->plh_return_iomode = IOMODE_ANY;
1643 * mark all matching lsegs so that we are sure to have no live
1644 * segments at hand when sending layoutreturn. See pnfs_put_lseg()
1647 pnfs_mark_matching_lsegs_return(lo, &free_me, &range);
1648 spin_unlock(&inode->i_lock);
1649 pnfs_free_lseg_list(&free_me);
1651 EXPORT_SYMBOL_GPL(pnfs_error_mark_layout_for_return);
1654 pnfs_generic_pg_init_read(struct nfs_pageio_descriptor *pgio, struct nfs_page *req)
1656 u64 rd_size = req->wb_bytes;
1658 WARN_ON_ONCE(pgio->pg_lseg != NULL);
1660 if (pgio->pg_dreq == NULL)
1661 rd_size = i_size_read(pgio->pg_inode) - req_offset(req);
1663 rd_size = nfs_dreq_bytes_left(pgio->pg_dreq);
1665 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
1671 /* If no lseg, fall back to read through mds */
1672 if (pgio->pg_lseg == NULL)
1673 nfs_pageio_reset_read_mds(pgio);
1676 EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_read);
1679 pnfs_generic_pg_init_write(struct nfs_pageio_descriptor *pgio,
1680 struct nfs_page *req, u64 wb_size)
1682 WARN_ON_ONCE(pgio->pg_lseg != NULL);
1684 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
1690 /* If no lseg, fall back to write through mds */
1691 if (pgio->pg_lseg == NULL)
1692 nfs_pageio_reset_write_mds(pgio);
1694 EXPORT_SYMBOL_GPL(pnfs_generic_pg_init_write);
1697 pnfs_generic_pg_cleanup(struct nfs_pageio_descriptor *desc)
1699 if (desc->pg_lseg) {
1700 pnfs_put_lseg(desc->pg_lseg);
1701 desc->pg_lseg = NULL;
1704 EXPORT_SYMBOL_GPL(pnfs_generic_pg_cleanup);
1707 * Return 0 if @req cannot be coalesced into @pgio, otherwise return the number
1708 * of bytes (maximum @req->wb_bytes) that can be coalesced.
1711 pnfs_generic_pg_test(struct nfs_pageio_descriptor *pgio,
1712 struct nfs_page *prev, struct nfs_page *req)
1715 u64 seg_end, req_start, seg_left;
1717 size = nfs_generic_pg_test(pgio, prev, req);
1722 * 'size' contains the number of bytes left in the current page (up
1723 * to the original size asked for in @req->wb_bytes).
1725 * Calculate how many bytes are left in the layout segment
1726 * and if there are less bytes than 'size', return that instead.
1728 * Please also note that 'end_offset' is actually the offset of the
1729 * first byte that lies outside the pnfs_layout_range. FIXME?
1732 if (pgio->pg_lseg) {
1733 seg_end = end_offset(pgio->pg_lseg->pls_range.offset,
1734 pgio->pg_lseg->pls_range.length);
1735 req_start = req_offset(req);
1736 WARN_ON_ONCE(req_start > seg_end);
1737 /* start of request is past the last byte of this segment */
1738 if (req_start >= seg_end)
1741 /* adjust 'size' iff there are fewer bytes left in the
1742 * segment than what nfs_generic_pg_test returned */
1743 seg_left = seg_end - req_start;
1744 if (seg_left < size)
1745 size = (unsigned int)seg_left;
1750 EXPORT_SYMBOL_GPL(pnfs_generic_pg_test);
1752 int pnfs_write_done_resend_to_mds(struct nfs_pgio_header *hdr)
1754 struct nfs_pageio_descriptor pgio;
1756 /* Resend all requests through the MDS */
1757 nfs_pageio_init_write(&pgio, hdr->inode, FLUSH_STABLE, true,
1758 hdr->completion_ops);
1759 return nfs_pageio_resend(&pgio, hdr);
1761 EXPORT_SYMBOL_GPL(pnfs_write_done_resend_to_mds);
1763 static void pnfs_ld_handle_write_error(struct nfs_pgio_header *hdr)
1766 dprintk("pnfs write error = %d\n", hdr->pnfs_error);
1767 if (NFS_SERVER(hdr->inode)->pnfs_curr_ld->flags &
1768 PNFS_LAYOUTRET_ON_ERROR) {
1769 pnfs_return_layout(hdr->inode);
1771 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags))
1772 hdr->task.tk_status = pnfs_write_done_resend_to_mds(hdr);
1776 * Called by non rpc-based layout drivers
1778 void pnfs_ld_write_done(struct nfs_pgio_header *hdr)
1780 trace_nfs4_pnfs_write(hdr, hdr->pnfs_error);
1781 if (!hdr->pnfs_error) {
1782 pnfs_set_layoutcommit(hdr);
1783 hdr->mds_ops->rpc_call_done(&hdr->task, hdr);
1785 pnfs_ld_handle_write_error(hdr);
1786 hdr->mds_ops->rpc_release(hdr);
1788 EXPORT_SYMBOL_GPL(pnfs_ld_write_done);
1791 pnfs_write_through_mds(struct nfs_pageio_descriptor *desc,
1792 struct nfs_pgio_header *hdr)
1794 struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc);
1796 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
1797 list_splice_tail_init(&hdr->pages, &mirror->pg_list);
1798 nfs_pageio_reset_write_mds(desc);
1799 mirror->pg_recoalesce = 1;
1801 nfs_pgio_data_destroy(hdr);
1804 static enum pnfs_try_status
1805 pnfs_try_to_write_data(struct nfs_pgio_header *hdr,
1806 const struct rpc_call_ops *call_ops,
1807 struct pnfs_layout_segment *lseg,
1810 struct inode *inode = hdr->inode;
1811 enum pnfs_try_status trypnfs;
1812 struct nfs_server *nfss = NFS_SERVER(inode);
1814 hdr->mds_ops = call_ops;
1816 dprintk("%s: Writing ino:%lu %u@%llu (how %d)\n", __func__,
1817 inode->i_ino, hdr->args.count, hdr->args.offset, how);
1818 trypnfs = nfss->pnfs_curr_ld->write_pagelist(hdr, how);
1819 if (trypnfs != PNFS_NOT_ATTEMPTED)
1820 nfs_inc_stats(inode, NFSIOS_PNFS_WRITE);
1821 dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs);
1826 pnfs_do_write(struct nfs_pageio_descriptor *desc,
1827 struct nfs_pgio_header *hdr, int how)
1829 const struct rpc_call_ops *call_ops = desc->pg_rpc_callops;
1830 struct pnfs_layout_segment *lseg = desc->pg_lseg;
1831 enum pnfs_try_status trypnfs;
1833 trypnfs = pnfs_try_to_write_data(hdr, call_ops, lseg, how);
1834 if (trypnfs == PNFS_NOT_ATTEMPTED)
1835 pnfs_write_through_mds(desc, hdr);
1838 static void pnfs_writehdr_free(struct nfs_pgio_header *hdr)
1840 pnfs_put_lseg(hdr->lseg);
1841 nfs_pgio_header_free(hdr);
1843 EXPORT_SYMBOL_GPL(pnfs_writehdr_free);
1846 pnfs_generic_pg_writepages(struct nfs_pageio_descriptor *desc)
1848 struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc);
1850 struct nfs_pgio_header *hdr;
1853 hdr = nfs_pgio_header_alloc(desc->pg_rw_ops);
1855 desc->pg_completion_ops->error_cleanup(&mirror->pg_list);
1858 nfs_pgheader_init(desc, hdr, pnfs_writehdr_free);
1860 hdr->lseg = pnfs_get_lseg(desc->pg_lseg);
1861 ret = nfs_generic_pgio(desc, hdr);
1863 pnfs_do_write(desc, hdr, desc->pg_ioflags);
1867 EXPORT_SYMBOL_GPL(pnfs_generic_pg_writepages);
1869 int pnfs_read_done_resend_to_mds(struct nfs_pgio_header *hdr)
1871 struct nfs_pageio_descriptor pgio;
1873 /* Resend all requests through the MDS */
1874 nfs_pageio_init_read(&pgio, hdr->inode, true, hdr->completion_ops);
1875 return nfs_pageio_resend(&pgio, hdr);
1877 EXPORT_SYMBOL_GPL(pnfs_read_done_resend_to_mds);
1879 static void pnfs_ld_handle_read_error(struct nfs_pgio_header *hdr)
1881 dprintk("pnfs read error = %d\n", hdr->pnfs_error);
1882 if (NFS_SERVER(hdr->inode)->pnfs_curr_ld->flags &
1883 PNFS_LAYOUTRET_ON_ERROR) {
1884 pnfs_return_layout(hdr->inode);
1886 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags))
1887 hdr->task.tk_status = pnfs_read_done_resend_to_mds(hdr);
1891 * Called by non rpc-based layout drivers
1893 void pnfs_ld_read_done(struct nfs_pgio_header *hdr)
1895 trace_nfs4_pnfs_read(hdr, hdr->pnfs_error);
1896 if (likely(!hdr->pnfs_error)) {
1897 __nfs4_read_done_cb(hdr);
1898 hdr->mds_ops->rpc_call_done(&hdr->task, hdr);
1900 pnfs_ld_handle_read_error(hdr);
1901 hdr->mds_ops->rpc_release(hdr);
1903 EXPORT_SYMBOL_GPL(pnfs_ld_read_done);
1906 pnfs_read_through_mds(struct nfs_pageio_descriptor *desc,
1907 struct nfs_pgio_header *hdr)
1909 struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc);
1911 if (!test_and_set_bit(NFS_IOHDR_REDO, &hdr->flags)) {
1912 list_splice_tail_init(&hdr->pages, &mirror->pg_list);
1913 nfs_pageio_reset_read_mds(desc);
1914 mirror->pg_recoalesce = 1;
1916 nfs_pgio_data_destroy(hdr);
1920 * Call the appropriate parallel I/O subsystem read function.
1922 static enum pnfs_try_status
1923 pnfs_try_to_read_data(struct nfs_pgio_header *hdr,
1924 const struct rpc_call_ops *call_ops,
1925 struct pnfs_layout_segment *lseg)
1927 struct inode *inode = hdr->inode;
1928 struct nfs_server *nfss = NFS_SERVER(inode);
1929 enum pnfs_try_status trypnfs;
1931 hdr->mds_ops = call_ops;
1933 dprintk("%s: Reading ino:%lu %u@%llu\n",
1934 __func__, inode->i_ino, hdr->args.count, hdr->args.offset);
1936 trypnfs = nfss->pnfs_curr_ld->read_pagelist(hdr);
1937 if (trypnfs != PNFS_NOT_ATTEMPTED)
1938 nfs_inc_stats(inode, NFSIOS_PNFS_READ);
1939 dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs);
1943 /* Resend all requests through pnfs. */
1944 int pnfs_read_resend_pnfs(struct nfs_pgio_header *hdr)
1946 struct nfs_pageio_descriptor pgio;
1948 nfs_pageio_init_read(&pgio, hdr->inode, false, hdr->completion_ops);
1949 return nfs_pageio_resend(&pgio, hdr);
1951 EXPORT_SYMBOL_GPL(pnfs_read_resend_pnfs);
1954 pnfs_do_read(struct nfs_pageio_descriptor *desc, struct nfs_pgio_header *hdr)
1956 const struct rpc_call_ops *call_ops = desc->pg_rpc_callops;
1957 struct pnfs_layout_segment *lseg = desc->pg_lseg;
1958 enum pnfs_try_status trypnfs;
1961 trypnfs = pnfs_try_to_read_data(hdr, call_ops, lseg);
1962 if (trypnfs == PNFS_TRY_AGAIN)
1963 err = pnfs_read_resend_pnfs(hdr);
1964 if (trypnfs == PNFS_NOT_ATTEMPTED || err)
1965 pnfs_read_through_mds(desc, hdr);
1968 static void pnfs_readhdr_free(struct nfs_pgio_header *hdr)
1970 pnfs_put_lseg(hdr->lseg);
1971 nfs_pgio_header_free(hdr);
1973 EXPORT_SYMBOL_GPL(pnfs_readhdr_free);
1976 pnfs_generic_pg_readpages(struct nfs_pageio_descriptor *desc)
1978 struct nfs_pgio_mirror *mirror = nfs_pgio_current_mirror(desc);
1980 struct nfs_pgio_header *hdr;
1983 hdr = nfs_pgio_header_alloc(desc->pg_rw_ops);
1985 desc->pg_completion_ops->error_cleanup(&mirror->pg_list);
1988 nfs_pgheader_init(desc, hdr, pnfs_readhdr_free);
1989 hdr->lseg = pnfs_get_lseg(desc->pg_lseg);
1990 ret = nfs_generic_pgio(desc, hdr);
1992 pnfs_do_read(desc, hdr);
1995 EXPORT_SYMBOL_GPL(pnfs_generic_pg_readpages);
1997 static void pnfs_clear_layoutcommitting(struct inode *inode)
1999 unsigned long *bitlock = &NFS_I(inode)->flags;
2001 clear_bit_unlock(NFS_INO_LAYOUTCOMMITTING, bitlock);
2002 smp_mb__after_atomic();
2003 wake_up_bit(bitlock, NFS_INO_LAYOUTCOMMITTING);
2007 * There can be multiple RW segments.
2009 static void pnfs_list_write_lseg(struct inode *inode, struct list_head *listp)
2011 struct pnfs_layout_segment *lseg;
2013 list_for_each_entry(lseg, &NFS_I(inode)->layout->plh_segs, pls_list) {
2014 if (lseg->pls_range.iomode == IOMODE_RW &&
2015 test_and_clear_bit(NFS_LSEG_LAYOUTCOMMIT, &lseg->pls_flags))
2016 list_add(&lseg->pls_lc_list, listp);
2020 static void pnfs_list_write_lseg_done(struct inode *inode, struct list_head *listp)
2022 struct pnfs_layout_segment *lseg, *tmp;
2024 /* Matched by references in pnfs_set_layoutcommit */
2025 list_for_each_entry_safe(lseg, tmp, listp, pls_lc_list) {
2026 list_del_init(&lseg->pls_lc_list);
2027 pnfs_put_lseg(lseg);
2030 pnfs_clear_layoutcommitting(inode);
2033 void pnfs_set_lo_fail(struct pnfs_layout_segment *lseg)
2035 pnfs_layout_io_set_failed(lseg->pls_layout, lseg->pls_range.iomode);
2037 EXPORT_SYMBOL_GPL(pnfs_set_lo_fail);
2040 pnfs_set_layoutcommit(struct nfs_pgio_header *hdr)
2042 struct inode *inode = hdr->inode;
2043 struct nfs_inode *nfsi = NFS_I(inode);
2044 loff_t end_pos = hdr->mds_offset + hdr->res.count;
2045 bool mark_as_dirty = false;
2047 spin_lock(&inode->i_lock);
2048 if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
2049 mark_as_dirty = true;
2050 dprintk("%s: Set layoutcommit for inode %lu ",
2051 __func__, inode->i_ino);
2053 if (!test_and_set_bit(NFS_LSEG_LAYOUTCOMMIT, &hdr->lseg->pls_flags)) {
2054 /* references matched in nfs4_layoutcommit_release */
2055 pnfs_get_lseg(hdr->lseg);
2057 if (end_pos > nfsi->layout->plh_lwb)
2058 nfsi->layout->plh_lwb = end_pos;
2059 spin_unlock(&inode->i_lock);
2060 dprintk("%s: lseg %p end_pos %llu\n",
2061 __func__, hdr->lseg, nfsi->layout->plh_lwb);
2063 /* if pnfs_layoutcommit_inode() runs between inode locks, the next one
2064 * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */
2066 mark_inode_dirty_sync(inode);
2068 EXPORT_SYMBOL_GPL(pnfs_set_layoutcommit);
2070 void pnfs_commit_set_layoutcommit(struct nfs_commit_data *data)
2072 struct inode *inode = data->inode;
2073 struct nfs_inode *nfsi = NFS_I(inode);
2074 bool mark_as_dirty = false;
2076 spin_lock(&inode->i_lock);
2077 if (!test_and_set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags)) {
2078 mark_as_dirty = true;
2079 dprintk("%s: Set layoutcommit for inode %lu ",
2080 __func__, inode->i_ino);
2082 if (!test_and_set_bit(NFS_LSEG_LAYOUTCOMMIT, &data->lseg->pls_flags)) {
2083 /* references matched in nfs4_layoutcommit_release */
2084 pnfs_get_lseg(data->lseg);
2086 if (data->lwb > nfsi->layout->plh_lwb)
2087 nfsi->layout->plh_lwb = data->lwb;
2088 spin_unlock(&inode->i_lock);
2089 dprintk("%s: lseg %p end_pos %llu\n",
2090 __func__, data->lseg, nfsi->layout->plh_lwb);
2092 /* if pnfs_layoutcommit_inode() runs between inode locks, the next one
2093 * will be a noop because NFS_INO_LAYOUTCOMMIT will not be set */
2095 mark_inode_dirty_sync(inode);
2097 EXPORT_SYMBOL_GPL(pnfs_commit_set_layoutcommit);
2099 void pnfs_cleanup_layoutcommit(struct nfs4_layoutcommit_data *data)
2101 struct nfs_server *nfss = NFS_SERVER(data->args.inode);
2103 if (nfss->pnfs_curr_ld->cleanup_layoutcommit)
2104 nfss->pnfs_curr_ld->cleanup_layoutcommit(data);
2105 pnfs_list_write_lseg_done(data->args.inode, &data->lseg_list);
2109 * For the LAYOUT4_NFSV4_1_FILES layout type, NFS_DATA_SYNC WRITEs and
2110 * NFS_UNSTABLE WRITEs with a COMMIT to data servers must store enough
2111 * data to disk to allow the server to recover the data if it crashes.
2112 * LAYOUTCOMMIT is only needed when the NFL4_UFLG_COMMIT_THRU_MDS flag
2113 * is off, and a COMMIT is sent to a data server, or
2114 * if WRITEs to a data server return NFS_DATA_SYNC.
2117 pnfs_layoutcommit_inode(struct inode *inode, bool sync)
2119 struct pnfs_layoutdriver_type *ld = NFS_SERVER(inode)->pnfs_curr_ld;
2120 struct nfs4_layoutcommit_data *data;
2121 struct nfs_inode *nfsi = NFS_I(inode);
2125 if (!pnfs_layoutcommit_outstanding(inode))
2128 dprintk("--> %s inode %lu\n", __func__, inode->i_ino);
2131 if (test_and_set_bit(NFS_INO_LAYOUTCOMMITTING, &nfsi->flags)) {
2134 status = wait_on_bit_lock_action(&nfsi->flags,
2135 NFS_INO_LAYOUTCOMMITTING,
2136 nfs_wait_bit_killable,
2143 /* Note kzalloc ensures data->res.seq_res.sr_slot == NULL */
2144 data = kzalloc(sizeof(*data), GFP_NOFS);
2146 goto clear_layoutcommitting;
2149 spin_lock(&inode->i_lock);
2150 if (!test_and_clear_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags))
2153 INIT_LIST_HEAD(&data->lseg_list);
2154 pnfs_list_write_lseg(inode, &data->lseg_list);
2156 end_pos = nfsi->layout->plh_lwb;
2157 nfsi->layout->plh_lwb = 0;
2159 nfs4_stateid_copy(&data->args.stateid, &nfsi->layout->plh_stateid);
2160 spin_unlock(&inode->i_lock);
2162 data->args.inode = inode;
2163 data->cred = get_rpccred(nfsi->layout->plh_lc_cred);
2164 nfs_fattr_init(&data->fattr);
2165 data->args.bitmask = NFS_SERVER(inode)->cache_consistency_bitmask;
2166 data->res.fattr = &data->fattr;
2167 data->args.lastbytewritten = end_pos - 1;
2168 data->res.server = NFS_SERVER(inode);
2170 if (ld->prepare_layoutcommit) {
2171 status = ld->prepare_layoutcommit(&data->args);
2173 spin_lock(&inode->i_lock);
2174 if (end_pos < nfsi->layout->plh_lwb)
2175 nfsi->layout->plh_lwb = end_pos;
2176 spin_unlock(&inode->i_lock);
2177 put_rpccred(data->cred);
2178 set_bit(NFS_INO_LAYOUTCOMMIT, &nfsi->flags);
2179 goto clear_layoutcommitting;
2184 status = nfs4_proc_layoutcommit(data, sync);
2187 mark_inode_dirty_sync(inode);
2188 dprintk("<-- %s status %d\n", __func__, status);
2191 spin_unlock(&inode->i_lock);
2193 clear_layoutcommitting:
2194 pnfs_clear_layoutcommitting(inode);
2197 EXPORT_SYMBOL_GPL(pnfs_layoutcommit_inode);
2199 struct nfs4_threshold *pnfs_mdsthreshold_alloc(void)
2201 struct nfs4_threshold *thp;
2203 thp = kzalloc(sizeof(*thp), GFP_NOFS);
2205 dprintk("%s mdsthreshold allocation failed\n", __func__);