Lines Matching full:lo

57 static void pnfs_layoutreturn_before_put_layout_hdr(struct pnfs_layout_hdr *lo);
58 static void pnfs_free_returned_lsegs(struct pnfs_layout_hdr *lo,
64 static int pnfs_layout_return_on_reboot(struct pnfs_layout_hdr *lo);
265 pnfs_get_layout_hdr(struct pnfs_layout_hdr *lo) in pnfs_get_layout_hdr() argument
267 refcount_inc(&lo->plh_refcount); in pnfs_get_layout_hdr()
278 pnfs_free_layout_hdr(struct pnfs_layout_hdr *lo) in pnfs_free_layout_hdr() argument
280 struct nfs_server *server = NFS_SERVER(lo->plh_inode); in pnfs_free_layout_hdr()
283 if (test_and_clear_bit(NFS_LAYOUT_HASHED, &lo->plh_flags)) { in pnfs_free_layout_hdr()
287 list_del_rcu(&lo->plh_layouts); in pnfs_free_layout_hdr()
290 put_cred(lo->plh_lc_cred); in pnfs_free_layout_hdr()
291 return ld->free_layout_hdr(lo); in pnfs_free_layout_hdr()
295 pnfs_detach_layout_hdr(struct pnfs_layout_hdr *lo) in pnfs_detach_layout_hdr() argument
297 struct nfs_inode *nfsi = NFS_I(lo->plh_inode); in pnfs_detach_layout_hdr()
298 dprintk("%s: freeing layout cache %p\n", __func__, lo); in pnfs_detach_layout_hdr()
306 pnfs_put_layout_hdr(struct pnfs_layout_hdr *lo) in pnfs_put_layout_hdr() argument
311 if (!lo) in pnfs_put_layout_hdr()
313 inode = lo->plh_inode; in pnfs_put_layout_hdr()
314 pnfs_layoutreturn_before_put_layout_hdr(lo); in pnfs_put_layout_hdr()
316 if (refcount_dec_and_lock(&lo->plh_refcount, &inode->i_lock)) { in pnfs_put_layout_hdr()
317 if (!list_empty(&lo->plh_segs)) in pnfs_put_layout_hdr()
319 pnfs_detach_layout_hdr(lo); in pnfs_put_layout_hdr()
322 pnfs_free_layout_hdr(lo); in pnfs_put_layout_hdr()
325 wake_up_var(lo); in pnfs_put_layout_hdr()
330 pnfs_grab_inode_layout_hdr(struct pnfs_layout_hdr *lo) in pnfs_grab_inode_layout_hdr() argument
332 struct inode *inode = igrab(lo->plh_inode); in pnfs_grab_inode_layout_hdr()
335 set_bit(NFS_LAYOUT_INODE_FREEING, &lo->plh_flags); in pnfs_grab_inode_layout_hdr()
348 static void pnfs_barrier_update(struct pnfs_layout_hdr *lo, u32 newseq) in pnfs_barrier_update() argument
350 if (pnfs_seqid_is_newer(newseq, lo->plh_barrier) || !lo->plh_barrier) in pnfs_barrier_update()
351 lo->plh_barrier = newseq; in pnfs_barrier_update()
355 pnfs_set_plh_return_info(struct pnfs_layout_hdr *lo, enum pnfs_iomode iomode, in pnfs_set_plh_return_info() argument
358 if (lo->plh_return_iomode != 0 && lo->plh_return_iomode != iomode) in pnfs_set_plh_return_info()
360 lo->plh_return_iomode = iomode; in pnfs_set_plh_return_info()
361 set_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags); in pnfs_set_plh_return_info()
363 * We must set lo->plh_return_seq to avoid livelocks with in pnfs_set_plh_return_info()
367 seq = be32_to_cpu(lo->plh_stateid.seqid); in pnfs_set_plh_return_info()
368 if (!lo->plh_return_seq || pnfs_seqid_is_newer(seq, lo->plh_return_seq)) in pnfs_set_plh_return_info()
369 lo->plh_return_seq = seq; in pnfs_set_plh_return_info()
370 pnfs_barrier_update(lo, seq); in pnfs_set_plh_return_info()
374 pnfs_clear_layoutreturn_info(struct pnfs_layout_hdr *lo) in pnfs_clear_layoutreturn_info() argument
377 lo->plh_return_iomode = 0; in pnfs_clear_layoutreturn_info()
378 lo->plh_return_seq = 0; in pnfs_clear_layoutreturn_info()
379 clear_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags); in pnfs_clear_layoutreturn_info()
380 list_for_each_entry(lseg, &lo->plh_segs, pls_list) { in pnfs_clear_layoutreturn_info()
383 pnfs_set_plh_return_info(lo, lseg->pls_range.iomode, 0); in pnfs_clear_layoutreturn_info()
387 static void pnfs_clear_layoutreturn_waitbit(struct pnfs_layout_hdr *lo) in pnfs_clear_layoutreturn_waitbit() argument
389 clear_bit_unlock(NFS_LAYOUT_RETURN, &lo->plh_flags); in pnfs_clear_layoutreturn_waitbit()
390 clear_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags); in pnfs_clear_layoutreturn_waitbit()
392 wake_up_bit(&lo->plh_flags, NFS_LAYOUT_RETURN); in pnfs_clear_layoutreturn_waitbit()
393 rpc_wake_up(&NFS_SERVER(lo->plh_inode)->roc_rpcwaitq); in pnfs_clear_layoutreturn_waitbit()
416 struct pnfs_layout_hdr *lo; in nfs4_layout_refresh_old_stateid() local
427 lo = NFS_I(inode)->layout; in nfs4_layout_refresh_old_stateid()
428 if (lo && pnfs_layout_is_valid(lo) && in nfs4_layout_refresh_old_stateid()
429 nfs4_stateid_match_other(dst, &lo->plh_stateid)) { in nfs4_layout_refresh_old_stateid()
431 if (!nfs4_stateid_is_newer(&lo->plh_stateid, dst)) { in nfs4_layout_refresh_old_stateid()
437 err = pnfs_mark_matching_lsegs_return(lo, &head, &range, 0); in nfs4_layout_refresh_old_stateid()
439 dst->seqid = lo->plh_stateid.seqid; in nfs4_layout_refresh_old_stateid()
458 pnfs_mark_layout_stateid_invalid(struct pnfs_layout_hdr *lo, in pnfs_mark_layout_stateid_invalid() argument
468 set_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags); in pnfs_mark_layout_stateid_invalid()
469 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) in pnfs_mark_layout_stateid_invalid()
471 pnfs_clear_layoutreturn_info(lo); in pnfs_mark_layout_stateid_invalid()
472 pnfs_free_returned_lsegs(lo, lseg_list, &range, 0); in pnfs_mark_layout_stateid_invalid()
473 set_bit(NFS_LAYOUT_DRAIN, &lo->plh_flags); in pnfs_mark_layout_stateid_invalid()
474 if (test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags) && in pnfs_mark_layout_stateid_invalid()
475 !test_and_set_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags)) in pnfs_mark_layout_stateid_invalid()
476 pnfs_clear_layoutreturn_waitbit(lo); in pnfs_mark_layout_stateid_invalid()
477 return !list_empty(&lo->plh_segs); in pnfs_mark_layout_stateid_invalid()
480 static int pnfs_mark_layout_stateid_return(struct pnfs_layout_hdr *lo, in pnfs_mark_layout_stateid_return() argument
489 return pnfs_mark_matching_lsegs_return(lo, lseg_list, &range, seq); in pnfs_mark_layout_stateid_return()
500 pnfs_layout_set_fail_bit(struct pnfs_layout_hdr *lo, int fail_bit) in pnfs_layout_set_fail_bit() argument
502 lo->plh_retry_timestamp = jiffies; in pnfs_layout_set_fail_bit()
503 if (!test_and_set_bit(fail_bit, &lo->plh_flags)) in pnfs_layout_set_fail_bit()
504 refcount_inc(&lo->plh_refcount); in pnfs_layout_set_fail_bit()
508 pnfs_layout_clear_fail_bit(struct pnfs_layout_hdr *lo, int fail_bit) in pnfs_layout_clear_fail_bit() argument
510 if (test_and_clear_bit(fail_bit, &lo->plh_flags)) in pnfs_layout_clear_fail_bit()
511 refcount_dec(&lo->plh_refcount); in pnfs_layout_clear_fail_bit()
515 pnfs_layout_io_set_failed(struct pnfs_layout_hdr *lo, u32 iomode) in pnfs_layout_io_set_failed() argument
517 struct inode *inode = lo->plh_inode; in pnfs_layout_io_set_failed()
526 pnfs_layout_set_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode)); in pnfs_layout_io_set_failed()
527 pnfs_mark_matching_lsegs_return(lo, &head, &range, 0); in pnfs_layout_io_set_failed()
535 pnfs_layout_io_test_failed(struct pnfs_layout_hdr *lo, u32 iomode) in pnfs_layout_io_test_failed() argument
540 if (test_bit(fail_bit, &lo->plh_flags) == 0) in pnfs_layout_io_test_failed()
544 if (!time_in_range(lo->plh_retry_timestamp, start, end)) { in pnfs_layout_io_test_failed()
546 pnfs_layout_clear_fail_bit(lo, fail_bit); in pnfs_layout_io_test_failed()
553 pnfs_init_lseg(struct pnfs_layout_hdr *lo, struct pnfs_layout_segment *lseg, in pnfs_init_lseg() argument
562 lseg->pls_layout = lo; in pnfs_init_lseg()
576 pnfs_layout_remove_lseg(struct pnfs_layout_hdr *lo, in pnfs_layout_remove_lseg() argument
582 refcount_dec(&lo->plh_refcount); in pnfs_layout_remove_lseg()
585 if (list_empty(&lo->plh_segs) && in pnfs_layout_remove_lseg()
586 !test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags) && in pnfs_layout_remove_lseg()
587 !test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) { in pnfs_layout_remove_lseg()
588 if (atomic_read(&lo->plh_outstanding) == 0) in pnfs_layout_remove_lseg()
589 set_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags); in pnfs_layout_remove_lseg()
590 clear_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags); in pnfs_layout_remove_lseg()
595 pnfs_cache_lseg_for_layoutreturn(struct pnfs_layout_hdr *lo, in pnfs_cache_lseg_for_layoutreturn() argument
599 pnfs_layout_is_valid(lo)) { in pnfs_cache_lseg_for_layoutreturn()
600 pnfs_set_plh_return_info(lo, lseg->pls_range.iomode, 0); in pnfs_cache_lseg_for_layoutreturn()
601 list_move_tail(&lseg->pls_list, &lo->plh_return_segs); in pnfs_cache_lseg_for_layoutreturn()
610 struct pnfs_layout_hdr *lo; in pnfs_put_lseg() local
620 lo = lseg->pls_layout; in pnfs_put_lseg()
621 inode = lo->plh_inode; in pnfs_put_lseg()
624 pnfs_get_layout_hdr(lo); in pnfs_put_lseg()
625 pnfs_layout_remove_lseg(lo, lseg); in pnfs_put_lseg()
626 if (pnfs_cache_lseg_for_layoutreturn(lo, lseg)) in pnfs_put_lseg()
630 pnfs_put_layout_hdr(lo); in pnfs_put_lseg()
706 * @lo: layout header containing the lsegs
720 pnfs_mark_matching_lsegs_invalid(struct pnfs_layout_hdr *lo, in pnfs_mark_matching_lsegs_invalid() argument
726 struct nfs_server *server = NFS_SERVER(lo->plh_inode); in pnfs_mark_matching_lsegs_invalid()
729 dprintk("%s:Begin lo %p\n", __func__, lo); in pnfs_mark_matching_lsegs_invalid()
731 if (list_empty(&lo->plh_segs)) in pnfs_mark_matching_lsegs_invalid()
733 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) in pnfs_mark_matching_lsegs_invalid()
749 pnfs_free_returned_lsegs(struct pnfs_layout_hdr *lo, in pnfs_free_returned_lsegs() argument
756 list_for_each_entry_safe(lseg, next, &lo->plh_return_segs, pls_list) { in pnfs_free_returned_lsegs()
779 struct pnfs_layout_hdr *lo; in __pnfs_destroy_layout() local
783 lo = nfsi->layout; in __pnfs_destroy_layout()
784 if (lo) { in __pnfs_destroy_layout()
785 pnfs_get_layout_hdr(lo); in __pnfs_destroy_layout()
786 pnfs_mark_layout_stateid_invalid(lo, &tmp_list); in __pnfs_destroy_layout()
787 pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RO_FAILED); in __pnfs_destroy_layout()
788 pnfs_layout_clear_fail_bit(lo, NFS_LAYOUT_RW_FAILED); in __pnfs_destroy_layout()
792 pnfs_put_layout_hdr(lo); in __pnfs_destroy_layout()
795 return lo; in __pnfs_destroy_layout()
805 struct pnfs_layout_hdr *lo) in pnfs_layout_removed() argument
810 ret = nfsi->layout != lo; in pnfs_layout_removed()
817 struct pnfs_layout_hdr *lo = __pnfs_destroy_layout(nfsi); in pnfs_destroy_layout_final() local
819 if (lo) in pnfs_destroy_layout_final()
820 wait_var_event(lo, pnfs_layout_removed(nfsi, lo)); in pnfs_destroy_layout_final()
827 struct pnfs_layout_hdr *lo; in pnfs_layout_add_bulk_destroy_list() local
831 lo = NFS_I(inode)->layout; in pnfs_layout_add_bulk_destroy_list()
832 if (lo != NULL && list_empty(&lo->plh_bulk_destroy)) { in pnfs_layout_add_bulk_destroy_list()
833 pnfs_get_layout_hdr(lo); in pnfs_layout_add_bulk_destroy_list()
834 list_add(&lo->plh_bulk_destroy, layout_list); in pnfs_layout_add_bulk_destroy_list()
849 struct pnfs_layout_hdr *lo, *next; in pnfs_layout_bulk_destroy_byserver_locked() local
852 list_for_each_entry_safe(lo, next, &server->layouts, plh_layouts) { in pnfs_layout_bulk_destroy_byserver_locked()
853 if (test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags) || in pnfs_layout_bulk_destroy_byserver_locked()
854 test_bit(NFS_LAYOUT_INODE_FREEING, &lo->plh_flags) || in pnfs_layout_bulk_destroy_byserver_locked()
855 !list_empty(&lo->plh_bulk_destroy)) in pnfs_layout_bulk_destroy_byserver_locked()
860 inode = pnfs_grab_inode_layout_hdr(lo); in pnfs_layout_bulk_destroy_byserver_locked()
884 struct pnfs_layout_hdr *lo; in pnfs_layout_free_bulk_destroy_list() local
890 lo = list_entry(layout_list->next, struct pnfs_layout_hdr, in pnfs_layout_free_bulk_destroy_list()
893 lo->plh_inode->i_ino); in pnfs_layout_free_bulk_destroy_list()
894 inode = lo->plh_inode; in pnfs_layout_free_bulk_destroy_list()
899 list_del_init(&lo->plh_bulk_destroy); in pnfs_layout_free_bulk_destroy_list()
901 pnfs_mark_layout_stateid_return(lo, &lseg_list, in pnfs_layout_free_bulk_destroy_list()
903 } else if (pnfs_mark_layout_stateid_invalid(lo, &lseg_list)) { in pnfs_layout_free_bulk_destroy_list()
905 set_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags); in pnfs_layout_free_bulk_destroy_list()
912 pnfs_put_layout_hdr(lo); in pnfs_layout_free_bulk_destroy_list()
1008 struct pnfs_layout_hdr *lo; in pnfs_layout_bulk_list_reboot() local
1012 list_for_each_entry(lo, list, plh_bulk_destroy) { in pnfs_layout_bulk_list_reboot()
1013 server = NFS_SERVER(lo->plh_inode); in pnfs_layout_bulk_list_reboot()
1014 ret = pnfs_layout_return_on_reboot(lo); in pnfs_layout_bulk_list_reboot()
1049 pnfs_set_layout_cred(struct pnfs_layout_hdr *lo, const struct cred *cred) in pnfs_set_layout_cred() argument
1053 if (cred && cred_fscmp(lo->plh_lc_cred, cred) != 0) { in pnfs_set_layout_cred()
1054 old = xchg(&lo->plh_lc_cred, get_cred(cred)); in pnfs_set_layout_cred()
1059 /* update lo->plh_stateid with new if is more recent */
1061 pnfs_set_layout_stateid(struct pnfs_layout_hdr *lo, const nfs4_stateid *new, in pnfs_set_layout_stateid() argument
1064 u32 oldseq = be32_to_cpu(lo->plh_stateid.seqid); in pnfs_set_layout_stateid()
1067 if (!pnfs_layout_is_valid(lo)) { in pnfs_set_layout_stateid()
1068 pnfs_set_layout_cred(lo, cred); in pnfs_set_layout_stateid()
1069 nfs4_stateid_copy(&lo->plh_stateid, new); in pnfs_set_layout_stateid()
1070 lo->plh_barrier = newseq; in pnfs_set_layout_stateid()
1071 pnfs_clear_layoutreturn_info(lo); in pnfs_set_layout_stateid()
1072 clear_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags); in pnfs_set_layout_stateid()
1077 nfs4_stateid_copy(&lo->plh_stateid, new); in pnfs_set_layout_stateid()
1080 pnfs_barrier_update(lo, newseq); in pnfs_set_layout_stateid()
1088 if (atomic_read(&lo->plh_outstanding) == 1) in pnfs_set_layout_stateid()
1089 pnfs_barrier_update(lo, be32_to_cpu(lo->plh_stateid.seqid)); in pnfs_set_layout_stateid()
1093 pnfs_layout_stateid_blocked(const struct pnfs_layout_hdr *lo, in pnfs_layout_stateid_blocked() argument
1098 return lo->plh_barrier && pnfs_seqid_is_newer(lo->plh_barrier, seqid); in pnfs_layout_stateid_blocked()
1103 pnfs_layoutgets_blocked(const struct pnfs_layout_hdr *lo) in pnfs_layoutgets_blocked() argument
1105 return lo->plh_block_lgets || in pnfs_layoutgets_blocked()
1106 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags); in pnfs_layoutgets_blocked()
1226 pnfs_put_layout_hdr(lgp->lo); in pnfs_layoutget_free()
1247 pnfs_layoutreturn_retry_later_locked(struct pnfs_layout_hdr *lo, in pnfs_layoutreturn_retry_later_locked() argument
1254 if (pnfs_layout_is_valid(lo) && in pnfs_layoutreturn_retry_later_locked()
1255 nfs4_stateid_match_other(&lo->plh_stateid, arg_stateid)) { in pnfs_layoutreturn_retry_later_locked()
1256 list_for_each_entry(lseg, &lo->plh_return_segs, pls_list) { in pnfs_layoutreturn_retry_later_locked()
1260 pnfs_set_plh_return_info(lo, range->iomode, seq); in pnfs_layoutreturn_retry_later_locked()
1266 void pnfs_layoutreturn_retry_later(struct pnfs_layout_hdr *lo, in pnfs_layoutreturn_retry_later() argument
1270 struct inode *inode = lo->plh_inode; in pnfs_layoutreturn_retry_later()
1273 pnfs_layoutreturn_retry_later_locked(lo, arg_stateid, range); in pnfs_layoutreturn_retry_later()
1274 pnfs_clear_layoutreturn_waitbit(lo); in pnfs_layoutreturn_retry_later()
1278 void pnfs_layoutreturn_free_lsegs(struct pnfs_layout_hdr *lo, in pnfs_layoutreturn_free_lsegs() argument
1283 struct inode *inode = lo->plh_inode; in pnfs_layoutreturn_free_lsegs()
1287 if (!nfs4_stateid_match_other(&lo->plh_stateid, arg_stateid)) in pnfs_layoutreturn_free_lsegs()
1289 if (stateid && pnfs_layout_is_valid(lo)) { in pnfs_layoutreturn_free_lsegs()
1292 pnfs_mark_matching_lsegs_invalid(lo, &freeme, range, seq); in pnfs_layoutreturn_free_lsegs()
1293 pnfs_free_returned_lsegs(lo, &freeme, range, seq); in pnfs_layoutreturn_free_lsegs()
1294 pnfs_set_layout_stateid(lo, stateid, NULL, true); in pnfs_layoutreturn_free_lsegs()
1296 pnfs_mark_layout_stateid_invalid(lo, &freeme); in pnfs_layoutreturn_free_lsegs()
1298 pnfs_clear_layoutreturn_waitbit(lo); in pnfs_layoutreturn_free_lsegs()
1305 pnfs_prepare_layoutreturn(struct pnfs_layout_hdr *lo, in pnfs_prepare_layoutreturn() argument
1311 if (atomic_read(&lo->plh_outstanding) != 0) in pnfs_prepare_layoutreturn()
1313 if (test_and_set_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags)) in pnfs_prepare_layoutreturn()
1315 set_bit(NFS_LAYOUT_RETURN, &lo->plh_flags); in pnfs_prepare_layoutreturn()
1316 pnfs_get_layout_hdr(lo); in pnfs_prepare_layoutreturn()
1317 nfs4_stateid_copy(stateid, &lo->plh_stateid); in pnfs_prepare_layoutreturn()
1318 *cred = get_cred(lo->plh_lc_cred); in pnfs_prepare_layoutreturn()
1319 if (test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) { in pnfs_prepare_layoutreturn()
1320 if (lo->plh_return_seq != 0) in pnfs_prepare_layoutreturn()
1321 stateid->seqid = cpu_to_be32(lo->plh_return_seq); in pnfs_prepare_layoutreturn()
1323 *iomode = lo->plh_return_iomode; in pnfs_prepare_layoutreturn()
1324 pnfs_clear_layoutreturn_info(lo); in pnfs_prepare_layoutreturn()
1327 pnfs_barrier_update(lo, be32_to_cpu(stateid->seqid)); in pnfs_prepare_layoutreturn()
1333 struct pnfs_layout_hdr *lo, in pnfs_init_layoutreturn_args() argument
1337 struct inode *inode = lo->plh_inode; in pnfs_init_layoutreturn_args()
1344 args->layout = lo; in pnfs_init_layoutreturn_args()
1349 pnfs_send_layoutreturn(struct pnfs_layout_hdr *lo, in pnfs_send_layoutreturn() argument
1355 struct inode *ino = lo->plh_inode; in pnfs_send_layoutreturn()
1366 pnfs_clear_layoutreturn_waitbit(lo); in pnfs_send_layoutreturn()
1369 pnfs_put_layout_hdr(lo); in pnfs_send_layoutreturn()
1373 pnfs_init_layoutreturn_args(&lrp->args, lo, stateid, iomode); in pnfs_send_layoutreturn()
1388 pnfs_layout_need_return(struct pnfs_layout_hdr *lo) in pnfs_layout_need_return() argument
1390 if (!test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) in pnfs_layout_need_return()
1392 return pnfs_mark_layout_stateid_return(lo, &lo->plh_return_segs, in pnfs_layout_need_return()
1393 lo->plh_return_iomode, in pnfs_layout_need_return()
1394 lo->plh_return_seq) != EBUSY; in pnfs_layout_need_return()
1397 static void pnfs_layoutreturn_before_put_layout_hdr(struct pnfs_layout_hdr *lo) in pnfs_layoutreturn_before_put_layout_hdr() argument
1399 struct inode *inode= lo->plh_inode; in pnfs_layoutreturn_before_put_layout_hdr()
1401 if (!test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) in pnfs_layoutreturn_before_put_layout_hdr()
1404 if (pnfs_layout_need_return(lo)) { in pnfs_layoutreturn_before_put_layout_hdr()
1410 send = pnfs_prepare_layoutreturn(lo, &stateid, &cred, &iomode); in pnfs_layoutreturn_before_put_layout_hdr()
1414 pnfs_send_layoutreturn(lo, &stateid, &cred, iomode, in pnfs_layoutreturn_before_put_layout_hdr()
1432 struct pnfs_layout_hdr *lo = NULL; in _pnfs_return_layout() local
1448 lo = nfsi->layout; in _pnfs_return_layout()
1449 if (!lo) { in _pnfs_return_layout()
1455 pnfs_get_layout_hdr(lo); in _pnfs_return_layout()
1457 if (test_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags)) { in _pnfs_return_layout()
1459 if (wait_on_bit(&lo->plh_flags, NFS_LAYOUT_RETURN, in _pnfs_return_layout()
1464 valid_layout = pnfs_layout_is_valid(lo); in _pnfs_return_layout()
1466 pnfs_mark_matching_lsegs_return(lo, &tmp_list, &range, 0); in _pnfs_return_layout()
1469 NFS_SERVER(ino)->pnfs_curr_ld->return_range(lo, &range); in _pnfs_return_layout()
1472 if (!test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags) || in _pnfs_return_layout()
1479 send = pnfs_prepare_layoutreturn(lo, &stateid, &cred, NULL); in _pnfs_return_layout()
1482 status = pnfs_send_layoutreturn(lo, &stateid, &cred, IOMODE_ANY, in _pnfs_return_layout()
1485 wait_on_bit(&lo->plh_flags, NFS_LAYOUT_RETURN, TASK_UNINTERRUPTIBLE); in _pnfs_return_layout()
1488 pnfs_put_layout_hdr(lo); in _pnfs_return_layout()
1497 struct pnfs_layout_hdr *lo; in pnfs_commit_and_return_layout() local
1501 lo = NFS_I(inode)->layout; in pnfs_commit_and_return_layout()
1502 if (lo == NULL) { in pnfs_commit_and_return_layout()
1506 pnfs_get_layout_hdr(lo); in pnfs_commit_and_return_layout()
1508 lo->plh_block_lgets++; in pnfs_commit_and_return_layout()
1515 lo->plh_block_lgets--; in pnfs_commit_and_return_layout()
1517 pnfs_put_layout_hdr(lo); in pnfs_commit_and_return_layout()
1521 static int pnfs_layout_return_on_reboot(struct pnfs_layout_hdr *lo) in pnfs_layout_return_on_reboot() argument
1523 struct inode *inode = lo->plh_inode; in pnfs_layout_return_on_reboot()
1527 if (!pnfs_layout_is_valid(lo)) { in pnfs_layout_return_on_reboot()
1531 cred = get_cred(lo->plh_lc_cred); in pnfs_layout_return_on_reboot()
1532 pnfs_get_layout_hdr(lo); in pnfs_layout_return_on_reboot()
1535 return pnfs_send_layoutreturn(lo, &zero_stateid, &cred, IOMODE_ANY, in pnfs_layout_return_on_reboot()
1547 struct pnfs_layout_hdr *lo; in pnfs_roc() local
1560 lo = nfsi->layout; in pnfs_roc()
1561 if (!lo || !pnfs_layout_is_valid(lo) || in pnfs_roc()
1562 test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) { in pnfs_roc()
1563 lo = NULL; in pnfs_roc()
1566 pnfs_get_layout_hdr(lo); in pnfs_roc()
1567 if (test_bit(NFS_LAYOUT_RETURN_LOCK, &lo->plh_flags)) { in pnfs_roc()
1570 wait_on_bit(&lo->plh_flags, NFS_LAYOUT_RETURN, in pnfs_roc()
1572 pnfs_put_layout_hdr(lo); in pnfs_roc()
1595 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) { in pnfs_roc()
1606 if (!mark_lseg_invalid(lseg, &lo->plh_return_segs)) in pnfs_roc()
1608 pnfs_set_plh_return_info(lo, lseg->pls_range.iomode, 0); in pnfs_roc()
1611 if (!test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) in pnfs_roc()
1618 /* lo ref dropped in pnfs_roc_release() */ in pnfs_roc()
1619 layoutreturn = pnfs_prepare_layoutreturn(lo, &stateid, &lc_cred, &iomode); in pnfs_roc()
1625 pnfs_init_layoutreturn_args(args, lo, &stateid, iomode); in pnfs_roc()
1638 pnfs_put_layout_hdr(lo); in pnfs_roc()
1642 pnfs_send_layoutreturn(lo, &stateid, &lc_cred, iomode, 0); in pnfs_roc()
1643 pnfs_put_layout_hdr(lo); in pnfs_roc()
1694 struct pnfs_layout_hdr *lo = args->layout; in pnfs_roc_release() local
1705 pnfs_layoutreturn_retry_later_locked(lo, &args->stateid, in pnfs_roc_release()
1707 pnfs_clear_layoutreturn_waitbit(lo); in pnfs_roc_release()
1715 pnfs_layoutreturn_free_lsegs(lo, &args->stateid, &args->range, in pnfs_roc_release()
1721 pnfs_put_layout_hdr(lo); in pnfs_roc_release()
1727 struct pnfs_layout_hdr *lo; in pnfs_wait_on_layoutreturn() local
1730 /* we might not have grabbed lo reference. so need to check under in pnfs_wait_on_layoutreturn()
1733 lo = nfsi->layout; in pnfs_wait_on_layoutreturn()
1734 if (lo && test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) { in pnfs_wait_on_layoutreturn()
1782 pnfs_generic_layout_insert_lseg(struct pnfs_layout_hdr *lo, in pnfs_generic_layout_insert_lseg() argument
1794 list_for_each_entry_safe(lp, tmp, &lo->plh_segs, pls_list) { in pnfs_generic_layout_insert_lseg()
1813 list_add_tail(&lseg->pls_list, &lo->plh_segs); in pnfs_generic_layout_insert_lseg()
1819 pnfs_get_layout_hdr(lo); in pnfs_generic_layout_insert_lseg()
1826 pnfs_layout_insert_lseg(struct pnfs_layout_hdr *lo, in pnfs_layout_insert_lseg() argument
1830 struct inode *inode = lo->plh_inode; in pnfs_layout_insert_lseg()
1834 ld->add_lseg(lo, lseg, free_me); in pnfs_layout_insert_lseg()
1836 pnfs_generic_layout_insert_lseg(lo, lseg, in pnfs_layout_insert_lseg()
1847 struct pnfs_layout_hdr *lo; in alloc_init_layout_hdr() local
1849 lo = pnfs_alloc_layout_hdr(ino, gfp_flags); in alloc_init_layout_hdr()
1850 if (!lo) in alloc_init_layout_hdr()
1852 refcount_set(&lo->plh_refcount, 1); in alloc_init_layout_hdr()
1853 INIT_LIST_HEAD(&lo->plh_layouts); in alloc_init_layout_hdr()
1854 INIT_LIST_HEAD(&lo->plh_segs); in alloc_init_layout_hdr()
1855 INIT_LIST_HEAD(&lo->plh_return_segs); in alloc_init_layout_hdr()
1856 INIT_LIST_HEAD(&lo->plh_bulk_destroy); in alloc_init_layout_hdr()
1857 lo->plh_inode = ino; in alloc_init_layout_hdr()
1858 lo->plh_lc_cred = get_cred(ctx->cred); in alloc_init_layout_hdr()
1859 lo->plh_flags |= 1 << NFS_LAYOUT_INVALID_STID; in alloc_init_layout_hdr()
1860 return lo; in alloc_init_layout_hdr()
1928 pnfs_find_lseg(struct pnfs_layout_hdr *lo, in pnfs_find_lseg() argument
1936 list_for_each_entry(lseg, &lo->plh_segs, pls_list) { in pnfs_find_lseg()
2025 static int pnfs_prepare_to_retry_layoutget(struct pnfs_layout_hdr *lo) in pnfs_prepare_to_retry_layoutget() argument
2031 pnfs_layoutcommit_inode(lo->plh_inode, false); in pnfs_prepare_to_retry_layoutget()
2032 return wait_on_bit_action(&lo->plh_flags, NFS_LAYOUT_RETURN, in pnfs_prepare_to_retry_layoutget()
2037 static void nfs_layoutget_begin(struct pnfs_layout_hdr *lo) in nfs_layoutget_begin() argument
2039 atomic_inc(&lo->plh_outstanding); in nfs_layoutget_begin()
2042 static void nfs_layoutget_end(struct pnfs_layout_hdr *lo) in nfs_layoutget_end() argument
2044 if (atomic_dec_and_test(&lo->plh_outstanding) && in nfs_layoutget_end()
2045 test_and_clear_bit(NFS_LAYOUT_DRAIN, &lo->plh_flags)) in nfs_layoutget_end()
2046 wake_up_bit(&lo->plh_flags, NFS_LAYOUT_DRAIN); in nfs_layoutget_end()
2049 static bool pnfs_is_first_layoutget(struct pnfs_layout_hdr *lo) in pnfs_is_first_layoutget() argument
2051 return test_bit(NFS_LAYOUT_FIRST_LAYOUTGET, &lo->plh_flags); in pnfs_is_first_layoutget()
2054 static void pnfs_clear_first_layoutget(struct pnfs_layout_hdr *lo) in pnfs_clear_first_layoutget() argument
2056 unsigned long *bitlock = &lo->plh_flags; in pnfs_clear_first_layoutget()
2063 static void _add_to_server_list(struct pnfs_layout_hdr *lo, in _add_to_server_list() argument
2066 if (!test_and_set_bit(NFS_LAYOUT_HASHED, &lo->plh_flags)) { in _add_to_server_list()
2069 /* The lo must be on the clp list if there is any in _add_to_server_list()
2073 list_add_tail_rcu(&lo->plh_layouts, &server->layouts); in _add_to_server_list()
2099 struct pnfs_layout_hdr *lo = NULL; in pnfs_update_layout() local
2110 trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, in pnfs_update_layout()
2116 trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, in pnfs_update_layout()
2124 iomode, lo, lseg, in pnfs_update_layout()
2135 lo = pnfs_find_alloc_layout(ino, ctx, gfp_flags); in pnfs_update_layout()
2136 if (lo == NULL) { in pnfs_update_layout()
2139 trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, in pnfs_update_layout()
2145 if (test_bit(NFS_LAYOUT_BULK_RECALL, &lo->plh_flags)) { in pnfs_update_layout()
2146 trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, in pnfs_update_layout()
2153 if (pnfs_layout_io_test_failed(lo, iomode)) { in pnfs_update_layout()
2154 trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, in pnfs_update_layout()
2163 if (test_bit(NFS_LAYOUT_DRAIN, &lo->plh_flags) && in pnfs_update_layout()
2164 atomic_read(&lo->plh_outstanding) != 0) { in pnfs_update_layout()
2166 lseg = ERR_PTR(wait_on_bit(&lo->plh_flags, NFS_LAYOUT_DRAIN, in pnfs_update_layout()
2170 pnfs_put_layout_hdr(lo); in pnfs_update_layout()
2178 if (test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) { in pnfs_update_layout()
2181 lseg = ERR_PTR(pnfs_prepare_to_retry_layoutget(lo)); in pnfs_update_layout()
2183 pnfs_put_layout_hdr(lo); in pnfs_update_layout()
2185 trace_pnfs_update_layout(ino, pos, count, iomode, lo, in pnfs_update_layout()
2190 trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, in pnfs_update_layout()
2195 lseg = pnfs_find_lseg(lo, &arg, strict_iomode); in pnfs_update_layout()
2197 trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, in pnfs_update_layout()
2207 if (test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags)) { in pnfs_update_layout()
2215 &lo->plh_flags)) { in pnfs_update_layout()
2217 lseg = ERR_PTR(wait_on_bit(&lo->plh_flags, in pnfs_update_layout()
2222 pnfs_put_layout_hdr(lo); in pnfs_update_layout()
2235 iomode, lo, lseg, in pnfs_update_layout()
2238 pnfs_clear_first_layoutget(lo); in pnfs_update_layout()
2239 pnfs_put_layout_hdr(lo); in pnfs_update_layout()
2244 nfs4_stateid_copy(&stateid, &lo->plh_stateid); in pnfs_update_layout()
2247 if (pnfs_layoutgets_blocked(lo)) { in pnfs_update_layout()
2248 trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, in pnfs_update_layout()
2252 nfs_layoutget_begin(lo); in pnfs_update_layout()
2255 _add_to_server_list(lo, server); in pnfs_update_layout()
2268 trace_pnfs_update_layout(ino, pos, count, iomode, lo, NULL, in pnfs_update_layout()
2270 nfs_layoutget_end(lo); in pnfs_update_layout()
2274 lgp->lo = lo; in pnfs_update_layout()
2275 pnfs_get_layout_hdr(lo); in pnfs_update_layout()
2278 trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, in pnfs_update_layout()
2280 nfs_layoutget_end(lo); in pnfs_update_layout()
2293 lo, pnfs_iomode_to_fail_bit(iomode)); in pnfs_update_layout()
2298 pnfs_layout_clear_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode)); in pnfs_update_layout()
2307 pnfs_clear_first_layoutget(lo); in pnfs_update_layout()
2309 iomode, lo, lseg, PNFS_UPDATE_LAYOUT_RETRY); in pnfs_update_layout()
2310 pnfs_put_layout_hdr(lo); in pnfs_update_layout()
2314 pnfs_layout_clear_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode)); in pnfs_update_layout()
2319 pnfs_clear_first_layoutget(lo); in pnfs_update_layout()
2320 trace_pnfs_update_layout(ino, pos, count, iomode, lo, lseg, in pnfs_update_layout()
2322 pnfs_put_layout_hdr(lo); in pnfs_update_layout()
2362 struct pnfs_layout_hdr *lo; in _pnfs_grab_empty_layout() local
2365 lo = pnfs_find_alloc_layout(ino, ctx, nfs_io_gfp_mask()); in _pnfs_grab_empty_layout()
2366 if (!lo) in _pnfs_grab_empty_layout()
2368 if (!test_bit(NFS_LAYOUT_INVALID_STID, &lo->plh_flags)) in _pnfs_grab_empty_layout()
2370 if (test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags)) in _pnfs_grab_empty_layout()
2372 if (pnfs_layoutgets_blocked(lo)) in _pnfs_grab_empty_layout()
2374 if (test_and_set_bit(NFS_LAYOUT_FIRST_LAYOUTGET, &lo->plh_flags)) in _pnfs_grab_empty_layout()
2376 nfs_layoutget_begin(lo); in _pnfs_grab_empty_layout()
2378 _add_to_server_list(lo, NFS_SERVER(ino)); in _pnfs_grab_empty_layout()
2379 return lo; in _pnfs_grab_empty_layout()
2383 pnfs_put_layout_hdr(lo); in _pnfs_grab_empty_layout()
2398 struct pnfs_layout_hdr *lo; in _lgopen_prepare_attached() local
2405 lo = _pnfs_grab_empty_layout(ino, ctx); in _lgopen_prepare_attached()
2406 if (!lo) in _lgopen_prepare_attached()
2411 pnfs_clear_first_layoutget(lo); in _lgopen_prepare_attached()
2412 nfs_layoutget_end(lo); in _lgopen_prepare_attached()
2413 pnfs_put_layout_hdr(lo); in _lgopen_prepare_attached()
2416 lgp->lo = lo; in _lgopen_prepare_attached()
2465 struct pnfs_layout_hdr *lo; in pnfs_parse_lgopen() local
2495 if (!lgp->lo) { in pnfs_parse_lgopen()
2496 lo = _pnfs_grab_empty_layout(ino, ctx); in pnfs_parse_lgopen()
2497 if (!lo) in pnfs_parse_lgopen()
2499 lgp->lo = lo; in pnfs_parse_lgopen()
2501 lo = lgp->lo; in pnfs_parse_lgopen()
2506 pnfs_layout_clear_fail_bit(lo, pnfs_iomode_to_fail_bit(iomode)); in pnfs_parse_lgopen()
2514 if (lgp->lo) { in nfs4_lgopen_release()
2515 pnfs_clear_first_layoutget(lgp->lo); in nfs4_lgopen_release()
2516 nfs_layoutget_end(lgp->lo); in nfs4_lgopen_release()
2525 struct pnfs_layout_hdr *lo = lgp->lo; in pnfs_layout_process() local
2528 struct inode *ino = lo->plh_inode; in pnfs_layout_process()
2535 lseg = NFS_SERVER(ino)->pnfs_curr_ld->alloc_lseg(lo, res, lgp->gfp_flags); in pnfs_layout_process()
2545 pnfs_init_lseg(lo, lseg, &res->range, &res->stateid); in pnfs_layout_process()
2548 if (pnfs_layoutgets_blocked(lo)) { in pnfs_layout_process()
2553 if (test_bit(NFS_LAYOUT_DRAIN, &lo->plh_flags) && in pnfs_layout_process()
2554 !pnfs_is_first_layoutget(lo)) in pnfs_layout_process()
2557 if (nfs4_stateid_match_other(&lo->plh_stateid, &res->stateid)) { in pnfs_layout_process()
2559 if (pnfs_layout_stateid_blocked(lo, &res->stateid)) { in pnfs_layout_process()
2560 if (!pnfs_layout_is_valid(lo)) in pnfs_layout_process()
2561 lo->plh_barrier = 0; in pnfs_layout_process()
2565 pnfs_set_layout_stateid(lo, &res->stateid, lgp->cred, false); in pnfs_layout_process()
2566 } else if (pnfs_layout_is_valid(lo)) { in pnfs_layout_process()
2575 pnfs_mark_matching_lsegs_return(lo, &free_me, &range, 0); in pnfs_layout_process()
2579 pnfs_set_layout_stateid(lo, &res->stateid, lgp->cred, true); in pnfs_layout_process()
2583 pnfs_layout_insert_lseg(lo, lseg, &free_me); in pnfs_layout_process()
2595 lseg->pls_layout = lo; in pnfs_layout_process()
2602 * @lo: pointer to layout header
2617 pnfs_mark_matching_lsegs_return(struct pnfs_layout_hdr *lo, in pnfs_mark_matching_lsegs_return() argument
2623 struct nfs_server *server = NFS_SERVER(lo->plh_inode); in pnfs_mark_matching_lsegs_return()
2626 dprintk("%s:Begin lo %p\n", __func__, lo); in pnfs_mark_matching_lsegs_return()
2628 assert_spin_locked(&lo->plh_inode->i_lock); in pnfs_mark_matching_lsegs_return()
2630 if (test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) in pnfs_mark_matching_lsegs_return()
2631 tmp_list = &lo->plh_return_segs; in pnfs_mark_matching_lsegs_return()
2633 list_for_each_entry_safe(lseg, next, &lo->plh_segs, pls_list) in pnfs_mark_matching_lsegs_return()
2641 tmp_list = &lo->plh_return_segs; in pnfs_mark_matching_lsegs_return()
2650 pnfs_set_plh_return_info(lo, return_range->iomode, seq); in pnfs_mark_matching_lsegs_return()
2654 if (!list_empty(&lo->plh_return_segs)) { in pnfs_mark_matching_lsegs_return()
2655 pnfs_set_plh_return_info(lo, return_range->iomode, seq); in pnfs_mark_matching_lsegs_return()
2666 struct pnfs_layout_hdr *lo; in pnfs_mark_layout_for_return() local
2670 lo = NFS_I(inode)->layout; in pnfs_mark_layout_for_return()
2671 if (!pnfs_layout_is_valid(lo)) { in pnfs_mark_layout_for_return()
2675 pnfs_set_plh_return_info(lo, range->iomode, 0); in pnfs_mark_layout_for_return()
2681 if (pnfs_mark_matching_lsegs_return(lo, &lo->plh_return_segs, range, 0) != -EBUSY) { in pnfs_mark_layout_for_return()
2686 return_now = pnfs_prepare_layoutreturn(lo, &stateid, &cred, &iomode); in pnfs_mark_layout_for_return()
2689 pnfs_send_layoutreturn(lo, &stateid, &cred, iomode, in pnfs_mark_layout_for_return()
2711 pnfs_layout_can_be_returned(struct pnfs_layout_hdr *lo) in pnfs_layout_can_be_returned() argument
2713 return pnfs_layout_is_valid(lo) && in pnfs_layout_can_be_returned()
2714 !test_bit(NFS_LAYOUT_INODE_FREEING, &lo->plh_flags) && in pnfs_layout_can_be_returned()
2715 !test_bit(NFS_LAYOUT_RETURN, &lo->plh_flags); in pnfs_layout_can_be_returned()
2719 pnfs_find_first_lseg(struct pnfs_layout_hdr *lo, in pnfs_find_first_lseg() argument
2725 list_for_each_entry(lseg, &lo->plh_segs, pls_list) { in pnfs_find_first_lseg()
2740 pnfs_should_return_unused_layout(struct pnfs_layout_hdr *lo, in pnfs_should_return_unused_layout() argument
2747 if (!pnfs_layout_can_be_returned(lo) || in pnfs_should_return_unused_layout()
2748 !pnfs_find_first_lseg(lo, range, range->iomode)) in pnfs_should_return_unused_layout()
2751 head = &NFS_I(lo->plh_inode)->open_files; in pnfs_should_return_unused_layout()
2764 if (pnfs_find_first_lseg(lo, range, IOMODE_READ)) in pnfs_should_return_unused_layout()
2775 struct pnfs_layout_hdr *lo; in pnfs_layout_return_unused_byserver() local
2782 list_for_each_entry_rcu(lo, &server->layouts, plh_layouts) { in pnfs_layout_return_unused_byserver()
2783 inode = lo->plh_inode; in pnfs_layout_return_unused_byserver()
2784 if (!inode || !pnfs_layout_can_be_returned(lo) || in pnfs_layout_return_unused_byserver()
2785 test_bit(NFS_LAYOUT_RETURN_REQUESTED, &lo->plh_flags)) in pnfs_layout_return_unused_byserver()
2788 if (!lo->plh_inode || in pnfs_layout_return_unused_byserver()
2789 !pnfs_should_return_unused_layout(lo, range)) { in pnfs_layout_return_unused_byserver()
2793 pnfs_get_layout_hdr(lo); in pnfs_layout_return_unused_byserver()
2794 pnfs_set_plh_return_info(lo, range->iomode, 0); in pnfs_layout_return_unused_byserver()
2795 if (pnfs_mark_matching_lsegs_return(lo, &lo->plh_return_segs, in pnfs_layout_return_unused_byserver()
2797 !pnfs_prepare_layoutreturn(lo, &stateid, &cred, &iomode)) { in pnfs_layout_return_unused_byserver()
2800 pnfs_put_layout_hdr(lo); in pnfs_layout_return_unused_byserver()
2806 pnfs_send_layoutreturn(lo, &stateid, &cred, iomode, in pnfs_layout_return_unused_byserver()
2808 pnfs_put_layout_hdr(lo); in pnfs_layout_return_unused_byserver()