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>
35 #define NFSDBG_FACILITY NFSDBG_PNFS
40 * protects pnfs_modules_tbl.
42 static DEFINE_SPINLOCK(pnfs_spinlock);
45 * pnfs_modules_tbl holds all pnfs modules
47 static LIST_HEAD(pnfs_modules_tbl);
49 /* Return the registered pnfs layout driver module matching given id */
50 static struct pnfs_layoutdriver_type *
51 find_pnfs_driver_locked(u32 id)
53 struct pnfs_layoutdriver_type *local;
55 list_for_each_entry(local, &pnfs_modules_tbl, pnfs_tblid)
60 dprintk("%s: Searching for id %u, found %p\n", __func__, id, local);
64 static struct pnfs_layoutdriver_type *
65 find_pnfs_driver(u32 id)
67 struct pnfs_layoutdriver_type *local;
69 spin_lock(&pnfs_spinlock);
70 local = find_pnfs_driver_locked(id);
71 spin_unlock(&pnfs_spinlock);
76 unset_pnfs_layoutdriver(struct nfs_server *nfss)
78 if (nfss->pnfs_curr_ld)
79 module_put(nfss->pnfs_curr_ld->owner);
80 nfss->pnfs_curr_ld = NULL;
84 * Try to set the server's pnfs module to the pnfs layout type specified by id.
85 * Currently only one pNFS layout driver per filesystem is supported.
87 * @id layout type. Zero (illegal layout type) indicates pNFS not in use.
90 set_pnfs_layoutdriver(struct nfs_server *server, u32 id)
92 struct pnfs_layoutdriver_type *ld_type = NULL;
96 if (!(server->nfs_client->cl_exchange_flags &
97 (EXCHGID4_FLAG_USE_NON_PNFS | EXCHGID4_FLAG_USE_PNFS_MDS))) {
98 printk(KERN_ERR "%s: id %u cl_exchange_flags 0x%x\n", __func__,
99 id, server->nfs_client->cl_exchange_flags);
102 ld_type = find_pnfs_driver(id);
104 request_module("%s-%u", LAYOUT_NFSV4_1_MODULE_PREFIX, id);
105 ld_type = find_pnfs_driver(id);
107 dprintk("%s: No pNFS module found for %u.\n",
112 if (!try_module_get(ld_type->owner)) {
113 dprintk("%s: Could not grab reference on module\n", __func__);
116 server->pnfs_curr_ld = ld_type;
118 dprintk("%s: pNFS module for %u set\n", __func__, id);
122 dprintk("%s: Using NFSv4 I/O\n", __func__);
123 server->pnfs_curr_ld = NULL;
127 pnfs_register_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
129 int status = -EINVAL;
130 struct pnfs_layoutdriver_type *tmp;
132 if (ld_type->id == 0) {
133 printk(KERN_ERR "%s id 0 is reserved\n", __func__);
136 if (!ld_type->alloc_lseg || !ld_type->free_lseg) {
137 printk(KERN_ERR "%s Layout driver must provide "
138 "alloc_lseg and free_lseg.\n", __func__);
142 spin_lock(&pnfs_spinlock);
143 tmp = find_pnfs_driver_locked(ld_type->id);
145 list_add(&ld_type->pnfs_tblid, &pnfs_modules_tbl);
147 dprintk("%s Registering id:%u name:%s\n", __func__, ld_type->id,
150 printk(KERN_ERR "%s Module with id %d already loaded!\n",
151 __func__, ld_type->id);
153 spin_unlock(&pnfs_spinlock);
157 EXPORT_SYMBOL_GPL(pnfs_register_layoutdriver);
160 pnfs_unregister_layoutdriver(struct pnfs_layoutdriver_type *ld_type)
162 dprintk("%s Deregistering id:%u\n", __func__, ld_type->id);
163 spin_lock(&pnfs_spinlock);
164 list_del(&ld_type->pnfs_tblid);
165 spin_unlock(&pnfs_spinlock);
167 EXPORT_SYMBOL_GPL(pnfs_unregister_layoutdriver);
170 * pNFS client layout cache
173 /* Need to hold i_lock if caller does not already hold reference */
175 get_layout_hdr(struct pnfs_layout_hdr *lo)
177 atomic_inc(&lo->plh_refcount);
181 destroy_layout_hdr(struct pnfs_layout_hdr *lo)
183 dprintk("%s: freeing layout cache %p\n", __func__, lo);
184 BUG_ON(!list_empty(&lo->plh_layouts));
185 NFS_I(lo->plh_inode)->layout = NULL;
190 put_layout_hdr_locked(struct pnfs_layout_hdr *lo)
192 if (atomic_dec_and_test(&lo->plh_refcount))
193 destroy_layout_hdr(lo);
197 put_layout_hdr(struct pnfs_layout_hdr *lo)
199 struct inode *inode = lo->plh_inode;
201 if (atomic_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) {
202 destroy_layout_hdr(lo);
203 spin_unlock(&inode->i_lock);
208 init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg)
210 INIT_LIST_HEAD(&lseg->pls_list);
211 atomic_set(&lseg->pls_refcount, 1);
213 set_bit(NFS_LSEG_VALID, &lseg->pls_flags);
214 lseg->pls_layout = lo;
217 static void free_lseg(struct pnfs_layout_segment *lseg)
219 struct inode *ino = lseg->pls_layout->plh_inode;
221 NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
222 /* Matched by get_layout_hdr in pnfs_insert_layout */
223 put_layout_hdr(NFS_I(ino)->layout);
227 put_lseg_common(struct pnfs_layout_segment *lseg)
229 struct inode *inode = lseg->pls_layout->plh_inode;
231 BUG_ON(test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
232 list_del_init(&lseg->pls_list);
233 if (list_empty(&lseg->pls_layout->plh_segs)) {
234 set_bit(NFS_LAYOUT_DESTROYED, &lseg->pls_layout->plh_flags);
235 /* Matched by initial refcount set in alloc_init_layout_hdr */
236 put_layout_hdr_locked(lseg->pls_layout);
238 rpc_wake_up(&NFS_SERVER(inode)->roc_rpcwaitq);
242 put_lseg(struct pnfs_layout_segment *lseg)
249 dprintk("%s: lseg %p ref %d valid %d\n", __func__, lseg,
250 atomic_read(&lseg->pls_refcount),
251 test_bit(NFS_LSEG_VALID, &lseg->pls_flags));
252 inode = lseg->pls_layout->plh_inode;
253 if (atomic_dec_and_lock(&lseg->pls_refcount, &inode->i_lock)) {
256 put_lseg_common(lseg);
257 list_add(&lseg->pls_list, &free_me);
258 spin_unlock(&inode->i_lock);
259 pnfs_free_lseg_list(&free_me);
262 EXPORT_SYMBOL_GPL(put_lseg);
265 should_free_lseg(u32 lseg_iomode, u32 recall_iomode)
267 return (recall_iomode == IOMODE_ANY ||
268 lseg_iomode == recall_iomode);
271 /* Returns 1 if lseg is removed from list, 0 otherwise */
272 static int mark_lseg_invalid(struct pnfs_layout_segment *lseg,
273 struct list_head *tmp_list)
277 if (test_and_clear_bit(NFS_LSEG_VALID, &lseg->pls_flags)) {
278 /* Remove the reference keeping the lseg in the
279 * list. It will now be removed when all
280 * outstanding io is finished.
282 dprintk("%s: lseg %p ref %d\n", __func__, lseg,
283 atomic_read(&lseg->pls_refcount));
284 if (atomic_dec_and_test(&lseg->pls_refcount)) {
285 put_lseg_common(lseg);
286 list_add(&lseg->pls_list, tmp_list);
293 /* Returns count of number of matching invalid lsegs remaining in list
297 mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo,
298 struct list_head *tmp_list,
301 struct pnfs_layout_segment *lseg, *next;
302 int invalid = 0, removed = 0;
304 dprintk("%s:Begin lo %p\n", __func__, lo);
306 if (list_empty(&lo->plh_segs)) {
307 if (!test_and_set_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags))
308 put_layout_hdr_locked(lo);
311 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list)
312 if (should_free_lseg(lseg->pls_range.iomode, iomode)) {
313 dprintk("%s: freeing lseg %p iomode %d "
314 "offset %llu length %llu\n", __func__,
315 lseg, lseg->pls_range.iomode, lseg->pls_range.offset,
316 lseg->pls_range.length);
318 removed += mark_lseg_invalid(lseg, tmp_list);
320 dprintk("%s:Return %i\n", __func__, invalid - removed);
321 return invalid - removed;
324 /* note free_me must contain lsegs from a single layout_hdr */
326 pnfs_free_lseg_list(struct list_head *free_me)
328 struct pnfs_layout_segment *lseg, *tmp;
329 struct pnfs_layout_hdr *lo;
331 if (list_empty(free_me))
334 lo = list_first_entry(free_me, struct pnfs_layout_segment,
335 pls_list)->pls_layout;
337 if (test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags)) {
338 struct nfs_client *clp;
340 clp = NFS_SERVER(lo->plh_inode)->nfs_client;
341 spin_lock(&clp->cl_lock);
342 list_del_init(&lo->plh_layouts);
343 spin_unlock(&clp->cl_lock);
345 list_for_each_entry_safe(lseg, tmp, free_me, pls_list) {
346 list_del(&lseg->pls_list);
352 pnfs_destroy_layout(struct nfs_inode *nfsi)
354 struct pnfs_layout_hdr *lo;
357 spin_lock(&nfsi->vfs_inode.i_lock);
360 lo->plh_block_lgets++; /* permanently block new LAYOUTGETs */
361 mark_matching_lsegs_invalid(lo, &tmp_list, IOMODE_ANY);
363 spin_unlock(&nfsi->vfs_inode.i_lock);
364 pnfs_free_lseg_list(&tmp_list);
368 * Called by the state manger to remove all layouts established under an
372 pnfs_destroy_all_layouts(struct nfs_client *clp)
374 struct pnfs_layout_hdr *lo;
377 spin_lock(&clp->cl_lock);
378 list_splice_init(&clp->cl_layouts, &tmp_list);
379 spin_unlock(&clp->cl_lock);
381 while (!list_empty(&tmp_list)) {
382 lo = list_entry(tmp_list.next, struct pnfs_layout_hdr,
384 dprintk("%s freeing layout for inode %lu\n", __func__,
385 lo->plh_inode->i_ino);
386 pnfs_destroy_layout(NFS_I(lo->plh_inode));
390 /* update lo->plh_stateid with new if is more recent */
392 pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new,
397 oldseq = be32_to_cpu(lo->plh_stateid.stateid.seqid);
398 newseq = be32_to_cpu(new->stateid.seqid);
399 if ((int)(newseq - oldseq) > 0) {
400 memcpy(&lo->plh_stateid, &new->stateid, sizeof(new->stateid));
401 if (update_barrier) {
402 u32 new_barrier = be32_to_cpu(new->stateid.seqid);
404 if ((int)(new_barrier - lo->plh_barrier))
405 lo->plh_barrier = new_barrier;
407 /* Because of wraparound, we want to keep the barrier
408 * "close" to the current seqids. It needs to be
409 * within 2**31 to count as "behind", so if it
410 * gets too near that limit, give us a litle leeway
411 * and bring it to within 2**30.
412 * NOTE - and yes, this is all unsigned arithmetic.
414 if (unlikely((newseq - lo->plh_barrier) > (3 << 29)))
415 lo->plh_barrier = newseq - (1 << 30);
420 /* lget is set to 1 if called from inside send_layoutget call chain */
422 pnfs_layoutgets_blocked(struct pnfs_layout_hdr *lo, nfs4_stateid *stateid,
426 (int)(lo->plh_barrier - be32_to_cpu(stateid->stateid.seqid)) >= 0)
428 return lo->plh_block_lgets ||
429 test_bit(NFS_LAYOUT_DESTROYED, &lo->plh_flags) ||
430 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags) ||
431 (list_empty(&lo->plh_segs) &&
432 (atomic_read(&lo->plh_outstanding) > lget));
436 pnfs_choose_layoutget_stateid(nfs4_stateid *dst, struct pnfs_layout_hdr *lo,
437 struct nfs4_state *open_state)
441 dprintk("--> %s\n", __func__);
442 spin_lock(&lo->plh_inode->i_lock);
443 if (pnfs_layoutgets_blocked(lo, NULL, 1)) {
445 } else if (list_empty(&lo->plh_segs)) {
449 seq = read_seqbegin(&open_state->seqlock);
450 memcpy(dst->data, open_state->stateid.data,
451 sizeof(open_state->stateid.data));
452 } while (read_seqretry(&open_state->seqlock, seq));
454 memcpy(dst->data, lo->plh_stateid.data, sizeof(lo->plh_stateid.data));
455 spin_unlock(&lo->plh_inode->i_lock);
456 dprintk("<-- %s\n", __func__);
461 * Get layout from server.
462 * for now, assume that whole file layouts are requested.
464 * arg->length: all ones
466 static struct pnfs_layout_segment *
467 send_layoutget(struct pnfs_layout_hdr *lo,
468 struct nfs_open_context *ctx,
471 struct inode *ino = lo->plh_inode;
472 struct nfs_server *server = NFS_SERVER(ino);
473 struct nfs4_layoutget *lgp;
474 struct pnfs_layout_segment *lseg = NULL;
476 dprintk("--> %s\n", __func__);
479 lgp = kzalloc(sizeof(*lgp), GFP_KERNEL);
482 lgp->args.minlength = NFS4_MAX_UINT64;
483 lgp->args.maxcount = PNFS_LAYOUT_MAXSIZE;
484 lgp->args.range.iomode = iomode;
485 lgp->args.range.offset = 0;
486 lgp->args.range.length = NFS4_MAX_UINT64;
487 lgp->args.type = server->pnfs_curr_ld->id;
488 lgp->args.inode = ino;
489 lgp->args.ctx = get_nfs_open_context(ctx);
492 /* Synchronously retrieve layout information from server and
495 nfs4_proc_layoutget(lgp);
497 /* remember that LAYOUTGET failed and suspend trying */
498 set_bit(lo_fail_bit(iomode), &lo->plh_flags);
503 bool pnfs_roc(struct inode *ino)
505 struct pnfs_layout_hdr *lo;
506 struct pnfs_layout_segment *lseg, *tmp;
510 spin_lock(&ino->i_lock);
511 lo = NFS_I(ino)->layout;
512 if (!lo || !test_and_clear_bit(NFS_LAYOUT_ROC, &lo->plh_flags) ||
513 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags))
515 list_for_each_entry_safe(lseg, tmp, &lo->plh_segs, pls_list)
516 if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) {
517 mark_lseg_invalid(lseg, &tmp_list);
522 lo->plh_block_lgets++;
523 get_layout_hdr(lo); /* matched in pnfs_roc_release */
524 spin_unlock(&ino->i_lock);
525 pnfs_free_lseg_list(&tmp_list);
529 spin_unlock(&ino->i_lock);
533 void pnfs_roc_release(struct inode *ino)
535 struct pnfs_layout_hdr *lo;
537 spin_lock(&ino->i_lock);
538 lo = NFS_I(ino)->layout;
539 lo->plh_block_lgets--;
540 put_layout_hdr_locked(lo);
541 spin_unlock(&ino->i_lock);
544 void pnfs_roc_set_barrier(struct inode *ino, u32 barrier)
546 struct pnfs_layout_hdr *lo;
548 spin_lock(&ino->i_lock);
549 lo = NFS_I(ino)->layout;
550 if ((int)(barrier - lo->plh_barrier) > 0)
551 lo->plh_barrier = barrier;
552 spin_unlock(&ino->i_lock);
555 bool pnfs_roc_drain(struct inode *ino, u32 *barrier)
557 struct nfs_inode *nfsi = NFS_I(ino);
558 struct pnfs_layout_segment *lseg;
561 spin_lock(&ino->i_lock);
562 list_for_each_entry(lseg, &nfsi->layout->plh_segs, pls_list)
563 if (test_bit(NFS_LSEG_ROC, &lseg->pls_flags)) {
568 struct pnfs_layout_hdr *lo = nfsi->layout;
569 u32 current_seqid = be32_to_cpu(lo->plh_stateid.stateid.seqid);
571 /* Since close does not return a layout stateid for use as
572 * a barrier, we choose the worst-case barrier.
574 *barrier = current_seqid + atomic_read(&lo->plh_outstanding);
576 spin_unlock(&ino->i_lock);
581 * Compare two layout segments for sorting into layout cache.
582 * We want to preferentially return RW over RO layouts, so ensure those
586 cmp_layout(u32 iomode1, u32 iomode2)
588 /* read > read/write */
589 return (int)(iomode2 == IOMODE_READ) - (int)(iomode1 == IOMODE_READ);
593 pnfs_insert_layout(struct pnfs_layout_hdr *lo,
594 struct pnfs_layout_segment *lseg)
596 struct pnfs_layout_segment *lp;
599 dprintk("%s:Begin\n", __func__);
601 assert_spin_locked(&lo->plh_inode->i_lock);
602 list_for_each_entry(lp, &lo->plh_segs, pls_list) {
603 if (cmp_layout(lp->pls_range.iomode, lseg->pls_range.iomode) > 0)
605 list_add_tail(&lseg->pls_list, &lp->pls_list);
606 dprintk("%s: inserted lseg %p "
607 "iomode %d offset %llu length %llu before "
608 "lp %p iomode %d offset %llu length %llu\n",
609 __func__, lseg, lseg->pls_range.iomode,
610 lseg->pls_range.offset, lseg->pls_range.length,
611 lp, lp->pls_range.iomode, lp->pls_range.offset,
612 lp->pls_range.length);
617 list_add_tail(&lseg->pls_list, &lo->plh_segs);
618 dprintk("%s: inserted lseg %p "
619 "iomode %d offset %llu length %llu at tail\n",
620 __func__, lseg, lseg->pls_range.iomode,
621 lseg->pls_range.offset, lseg->pls_range.length);
625 dprintk("%s:Return\n", __func__);
628 static struct pnfs_layout_hdr *
629 alloc_init_layout_hdr(struct inode *ino)
631 struct pnfs_layout_hdr *lo;
633 lo = kzalloc(sizeof(struct pnfs_layout_hdr), GFP_KERNEL);
636 atomic_set(&lo->plh_refcount, 1);
637 INIT_LIST_HEAD(&lo->plh_layouts);
638 INIT_LIST_HEAD(&lo->plh_segs);
639 INIT_LIST_HEAD(&lo->plh_bulk_recall);
644 static struct pnfs_layout_hdr *
645 pnfs_find_alloc_layout(struct inode *ino)
647 struct nfs_inode *nfsi = NFS_I(ino);
648 struct pnfs_layout_hdr *new = NULL;
650 dprintk("%s Begin ino=%p layout=%p\n", __func__, ino, nfsi->layout);
652 assert_spin_locked(&ino->i_lock);
654 if (test_bit(NFS_LAYOUT_DESTROYED, &nfsi->layout->plh_flags))
659 spin_unlock(&ino->i_lock);
660 new = alloc_init_layout_hdr(ino);
661 spin_lock(&ino->i_lock);
663 if (likely(nfsi->layout == NULL)) /* Won the race? */
671 * iomode matching rules:
682 is_matching_lseg(struct pnfs_layout_segment *lseg, u32 iomode)
684 return (iomode != IOMODE_RW || lseg->pls_range.iomode == IOMODE_RW);
688 * lookup range in layout
690 static struct pnfs_layout_segment *
691 pnfs_find_lseg(struct pnfs_layout_hdr *lo, u32 iomode)
693 struct pnfs_layout_segment *lseg, *ret = NULL;
695 dprintk("%s:Begin\n", __func__);
697 assert_spin_locked(&lo->plh_inode->i_lock);
698 list_for_each_entry(lseg, &lo->plh_segs, pls_list) {
699 if (test_bit(NFS_LSEG_VALID, &lseg->pls_flags) &&
700 is_matching_lseg(lseg, iomode)) {
701 ret = get_lseg(lseg);
704 if (cmp_layout(iomode, lseg->pls_range.iomode) > 0)
708 dprintk("%s:Return lseg %p ref %d\n",
709 __func__, ret, ret ? atomic_read(&ret->pls_refcount) : 0);
714 * Layout segment is retreived from the server if not cached.
715 * The appropriate layout segment is referenced and returned to the caller.
717 struct pnfs_layout_segment *
718 pnfs_update_layout(struct inode *ino,
719 struct nfs_open_context *ctx,
720 enum pnfs_iomode iomode)
722 struct nfs_inode *nfsi = NFS_I(ino);
723 struct nfs_client *clp = NFS_SERVER(ino)->nfs_client;
724 struct pnfs_layout_hdr *lo;
725 struct pnfs_layout_segment *lseg = NULL;
728 if (!pnfs_enabled_sb(NFS_SERVER(ino)))
730 spin_lock(&ino->i_lock);
731 lo = pnfs_find_alloc_layout(ino);
733 dprintk("%s ERROR: can't get pnfs_layout_hdr\n", __func__);
737 /* Do we even need to bother with this? */
738 if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) ||
739 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
740 dprintk("%s matches recall, use MDS\n", __func__);
744 /* if LAYOUTGET already failed once we don't try again */
745 if (test_bit(lo_fail_bit(iomode), &nfsi->layout->plh_flags))
748 /* Check to see if the layout for the given range already exists */
749 lseg = pnfs_find_lseg(lo, iomode);
753 if (pnfs_layoutgets_blocked(lo, NULL, 0))
755 atomic_inc(&lo->plh_outstanding);
758 if (list_empty(&lo->plh_segs))
760 spin_unlock(&ino->i_lock);
762 /* The lo must be on the clp list if there is any
763 * chance of a CB_LAYOUTRECALL(FILE) coming in.
765 spin_lock(&clp->cl_lock);
766 BUG_ON(!list_empty(&lo->plh_layouts));
767 list_add_tail(&lo->plh_layouts, &clp->cl_layouts);
768 spin_unlock(&clp->cl_lock);
771 lseg = send_layoutget(lo, ctx, iomode);
772 if (!lseg && first) {
773 spin_lock(&clp->cl_lock);
774 list_del_init(&lo->plh_layouts);
775 spin_unlock(&clp->cl_lock);
777 atomic_dec(&lo->plh_outstanding);
780 dprintk("%s end, state 0x%lx lseg %p\n", __func__,
781 nfsi->layout ? nfsi->layout->plh_flags : -1, lseg);
784 spin_unlock(&ino->i_lock);
789 pnfs_layout_process(struct nfs4_layoutget *lgp)
791 struct pnfs_layout_hdr *lo = NFS_I(lgp->args.inode)->layout;
792 struct nfs4_layoutget_res *res = &lgp->res;
793 struct pnfs_layout_segment *lseg;
794 struct inode *ino = lo->plh_inode;
795 struct nfs_client *clp = NFS_SERVER(ino)->nfs_client;
798 /* Verify we got what we asked for.
799 * Note that because the xdr parsing only accepts a single
800 * element array, this can fail even if the server is behaving
803 if (lgp->args.range.iomode > res->range.iomode ||
804 res->range.offset != 0 ||
805 res->range.length != NFS4_MAX_UINT64) {
809 /* Inject layout blob into I/O device driver */
810 lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res);
811 if (!lseg || IS_ERR(lseg)) {
815 status = PTR_ERR(lseg);
816 dprintk("%s: Could not allocate layout: error %d\n",
821 spin_lock(&ino->i_lock);
822 if (test_bit(NFS4CLNT_LAYOUTRECALL, &clp->cl_state) ||
823 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) {
824 dprintk("%s forget reply due to recall\n", __func__);
825 goto out_forget_reply;
828 if (pnfs_layoutgets_blocked(lo, &res->stateid, 1)) {
829 dprintk("%s forget reply due to state\n", __func__);
830 goto out_forget_reply;
833 lseg->pls_range = res->range;
834 *lgp->lsegpp = get_lseg(lseg);
835 pnfs_insert_layout(lo, lseg);
837 if (res->return_on_close) {
838 set_bit(NFS_LSEG_ROC, &lseg->pls_flags);
839 set_bit(NFS_LAYOUT_ROC, &lo->plh_flags);
842 /* Done processing layoutget. Set the layout stateid */
843 pnfs_set_layout_stateid(lo, &res->stateid, false);
844 spin_unlock(&ino->i_lock);
849 spin_unlock(&ino->i_lock);
850 lseg->pls_layout = lo;
851 NFS_SERVER(ino)->pnfs_curr_ld->free_lseg(lseg);
855 static int pnfs_read_pg_test(struct nfs_pageio_descriptor *pgio,
856 struct nfs_page *prev,
857 struct nfs_page *req)
859 if (pgio->pg_count == prev->wb_bytes) {
860 /* This is first coelesce call for a series of nfs_pages */
861 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
865 return NFS_SERVER(pgio->pg_inode)->pnfs_curr_ld->pg_test(pgio, prev, req);
869 pnfs_pageio_init_read(struct nfs_pageio_descriptor *pgio, struct inode *inode)
871 struct pnfs_layoutdriver_type *ld;
873 ld = NFS_SERVER(inode)->pnfs_curr_ld;
874 pgio->pg_test = (ld && ld->pg_test) ? pnfs_read_pg_test : NULL;
877 static int pnfs_write_pg_test(struct nfs_pageio_descriptor *pgio,
878 struct nfs_page *prev,
879 struct nfs_page *req)
881 if (pgio->pg_count == prev->wb_bytes) {
882 /* This is first coelesce call for a series of nfs_pages */
883 pgio->pg_lseg = pnfs_update_layout(pgio->pg_inode,
887 return NFS_SERVER(pgio->pg_inode)->pnfs_curr_ld->pg_test(pgio, prev, req);
891 pnfs_pageio_init_write(struct nfs_pageio_descriptor *pgio, struct inode *inode)
893 struct pnfs_layoutdriver_type *ld;
895 ld = NFS_SERVER(inode)->pnfs_curr_ld;
896 pgio->pg_test = (ld && ld->pg_test) ? pnfs_write_pg_test : NULL;
900 pnfs_try_to_write_data(struct nfs_write_data *wdata,
901 const struct rpc_call_ops *call_ops, int how)
903 struct inode *inode = wdata->inode;
904 enum pnfs_try_status trypnfs;
905 struct nfs_server *nfss = NFS_SERVER(inode);
907 wdata->mds_ops = call_ops;
909 dprintk("%s: Writing ino:%lu %u@%llu (how %d)\n", __func__,
910 inode->i_ino, wdata->args.count, wdata->args.offset, how);
912 trypnfs = nfss->pnfs_curr_ld->write_pagelist(wdata, how);
913 if (trypnfs == PNFS_NOT_ATTEMPTED) {
914 put_lseg(wdata->lseg);
917 nfs_inc_stats(inode, NFSIOS_PNFS_WRITE);
919 dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs);
924 * Call the appropriate parallel I/O subsystem read function.
927 pnfs_try_to_read_data(struct nfs_read_data *rdata,
928 const struct rpc_call_ops *call_ops)
930 struct inode *inode = rdata->inode;
931 struct nfs_server *nfss = NFS_SERVER(inode);
932 enum pnfs_try_status trypnfs;
934 rdata->mds_ops = call_ops;
936 dprintk("%s: Reading ino:%lu %u@%llu\n",
937 __func__, inode->i_ino, rdata->args.count, rdata->args.offset);
939 trypnfs = nfss->pnfs_curr_ld->read_pagelist(rdata);
940 if (trypnfs == PNFS_NOT_ATTEMPTED) {
941 put_lseg(rdata->lseg);
944 nfs_inc_stats(inode, NFSIOS_PNFS_READ);
946 dprintk("%s End (trypnfs:%d)\n", __func__, trypnfs);