xfs_inode.c (0ea8a56de21be24cb79abb03dee79aabcd60a316) | xfs_inode.c (664ffb8a429a800c51964b94c15c6a92c8d8334c) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (c) 2000-2006 Silicon Graphics, Inc. 4 * All Rights Reserved. 5 */ 6#include <linux/iversion.h> 7 8#include "xfs.h" --- 584 unchanged lines hidden (view full) --- 593 delay(1); /* Don't just spin the CPU */ 594 goto again; 595 } 596 } else { 597 xfs_ilock(ip1, xfs_lock_inumorder(ip1_mode, 1)); 598 } 599} 600 | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Copyright (c) 2000-2006 Silicon Graphics, Inc. 4 * All Rights Reserved. 5 */ 6#include <linux/iversion.h> 7 8#include "xfs.h" --- 584 unchanged lines hidden (view full) --- 593 delay(1); /* Don't just spin the CPU */ 594 goto again; 595 } 596 } else { 597 xfs_ilock(ip1, xfs_lock_inumorder(ip1_mode, 1)); 598 } 599} 600 |
601void 602__xfs_iflock( 603 struct xfs_inode *ip) 604{ 605 wait_queue_head_t *wq = bit_waitqueue(&ip->i_flags, __XFS_IFLOCK_BIT); 606 DEFINE_WAIT_BIT(wait, &ip->i_flags, __XFS_IFLOCK_BIT); 607 608 do { 609 prepare_to_wait_exclusive(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); 610 if (xfs_isiflocked(ip)) 611 io_schedule(); 612 } while (!xfs_iflock_nowait(ip)); 613 614 finish_wait(wq, &wait.wq_entry); 615} 616 | |
617STATIC uint 618_xfs_dic2xflags( 619 uint16_t di_flags, 620 uint64_t di_flags2, 621 bool has_attr) 622{ 623 uint flags = 0; 624 --- 1901 unchanged lines hidden (view full) --- 2526 2527 /* 2528 * because this is an RCU protected lookup, we could find a recently 2529 * freed or even reallocated inode during the lookup. We need to check 2530 * under the i_flags_lock for a valid inode here. Skip it if it is not 2531 * valid, the wrong inode or stale. 2532 */ 2533 spin_lock(&ip->i_flags_lock); | 601STATIC uint 602_xfs_dic2xflags( 603 uint16_t di_flags, 604 uint64_t di_flags2, 605 bool has_attr) 606{ 607 uint flags = 0; 608 --- 1901 unchanged lines hidden (view full) --- 2510 2511 /* 2512 * because this is an RCU protected lookup, we could find a recently 2513 * freed or even reallocated inode during the lookup. We need to check 2514 * under the i_flags_lock for a valid inode here. Skip it if it is not 2515 * valid, the wrong inode or stale. 2516 */ 2517 spin_lock(&ip->i_flags_lock); |
2534 if (ip->i_ino != inum || __xfs_iflags_test(ip, XFS_ISTALE)) { 2535 spin_unlock(&ip->i_flags_lock); 2536 rcu_read_unlock(); 2537 return; 2538 } | 2518 if (ip->i_ino != inum || __xfs_iflags_test(ip, XFS_ISTALE)) 2519 goto out_iflags_unlock; |
2539 2540 /* 2541 * Don't try to lock/unlock the current inode, but we _cannot_ skip the 2542 * other inodes that we did not find in the list attached to the buffer 2543 * and are not already marked stale. If we can't lock it, back off and 2544 * retry. 2545 */ 2546 if (ip != free_ip) { 2547 if (!xfs_ilock_nowait(ip, XFS_ILOCK_EXCL)) { 2548 spin_unlock(&ip->i_flags_lock); 2549 rcu_read_unlock(); 2550 delay(1); 2551 goto retry; 2552 } 2553 } 2554 ip->i_flags |= XFS_ISTALE; | 2520 2521 /* 2522 * Don't try to lock/unlock the current inode, but we _cannot_ skip the 2523 * other inodes that we did not find in the list attached to the buffer 2524 * and are not already marked stale. If we can't lock it, back off and 2525 * retry. 2526 */ 2527 if (ip != free_ip) { 2528 if (!xfs_ilock_nowait(ip, XFS_ILOCK_EXCL)) { 2529 spin_unlock(&ip->i_flags_lock); 2530 rcu_read_unlock(); 2531 delay(1); 2532 goto retry; 2533 } 2534 } 2535 ip->i_flags |= XFS_ISTALE; |
2555 spin_unlock(&ip->i_flags_lock); 2556 rcu_read_unlock(); | |
2557 2558 /* | 2536 2537 /* |
2559 * If we can't get the flush lock, the inode is already attached. All | 2538 * If the inode is flushing, it is already attached to the buffer. All |
2560 * we needed to do here is mark the inode stale so buffer IO completion 2561 * will remove it from the AIL. 2562 */ 2563 iip = ip->i_itemp; | 2539 * we needed to do here is mark the inode stale so buffer IO completion 2540 * will remove it from the AIL. 2541 */ 2542 iip = ip->i_itemp; |
2564 if (!xfs_iflock_nowait(ip)) { | 2543 if (__xfs_iflags_test(ip, XFS_IFLUSHING)) { |
2565 ASSERT(!list_empty(&iip->ili_item.li_bio_list)); 2566 ASSERT(iip->ili_last_fields); 2567 goto out_iunlock; 2568 } 2569 2570 /* 2571 * Inodes not attached to the buffer can be released immediately. 2572 * Everything else has to go through xfs_iflush_abort() on journal 2573 * commit as the flock synchronises removal of the inode from the 2574 * cluster buffer against inode reclaim. 2575 */ | 2544 ASSERT(!list_empty(&iip->ili_item.li_bio_list)); 2545 ASSERT(iip->ili_last_fields); 2546 goto out_iunlock; 2547 } 2548 2549 /* 2550 * Inodes not attached to the buffer can be released immediately. 2551 * Everything else has to go through xfs_iflush_abort() on journal 2552 * commit as the flock synchronises removal of the inode from the 2553 * cluster buffer against inode reclaim. 2554 */ |
2576 if (!iip || list_empty(&iip->ili_item.li_bio_list)) { 2577 xfs_ifunlock(ip); | 2555 if (!iip || list_empty(&iip->ili_item.li_bio_list)) |
2578 goto out_iunlock; | 2556 goto out_iunlock; |
2579 } | |
2580 | 2557 |
2558 __xfs_iflags_set(ip, XFS_IFLUSHING); 2559 spin_unlock(&ip->i_flags_lock); 2560 rcu_read_unlock(); 2561 |
|
2581 /* we have a dirty inode in memory that has not yet been flushed. */ 2582 spin_lock(&iip->ili_lock); 2583 iip->ili_last_fields = iip->ili_fields; 2584 iip->ili_fields = 0; 2585 iip->ili_fsync_fields = 0; 2586 spin_unlock(&iip->ili_lock); 2587 ASSERT(iip->ili_last_fields); 2588 | 2562 /* we have a dirty inode in memory that has not yet been flushed. */ 2563 spin_lock(&iip->ili_lock); 2564 iip->ili_last_fields = iip->ili_fields; 2565 iip->ili_fields = 0; 2566 iip->ili_fsync_fields = 0; 2567 spin_unlock(&iip->ili_lock); 2568 ASSERT(iip->ili_last_fields); 2569 |
2570 if (ip != free_ip) 2571 xfs_iunlock(ip, XFS_ILOCK_EXCL); 2572 return; 2573 |
|
2589out_iunlock: 2590 if (ip != free_ip) 2591 xfs_iunlock(ip, XFS_ILOCK_EXCL); | 2574out_iunlock: 2575 if (ip != free_ip) 2576 xfs_iunlock(ip, XFS_ILOCK_EXCL); |
2577out_iflags_unlock: 2578 spin_unlock(&ip->i_flags_lock); 2579 rcu_read_unlock(); |
|
2592} 2593 2594/* 2595 * A big issue when freeing the inode cluster is that we _cannot_ skip any 2596 * inodes that are in memory - they all must be marked stale and attached to 2597 * the cluster buffer. 2598 */ 2599STATIC int --- 26 unchanged lines hidden (view full) --- 2626 continue; 2627 } 2628 2629 blkno = XFS_AGB_TO_DADDR(mp, XFS_INO_TO_AGNO(mp, inum), 2630 XFS_INO_TO_AGBNO(mp, inum)); 2631 2632 /* 2633 * We obtain and lock the backing buffer first in the process | 2580} 2581 2582/* 2583 * A big issue when freeing the inode cluster is that we _cannot_ skip any 2584 * inodes that are in memory - they all must be marked stale and attached to 2585 * the cluster buffer. 2586 */ 2587STATIC int --- 26 unchanged lines hidden (view full) --- 2614 continue; 2615 } 2616 2617 blkno = XFS_AGB_TO_DADDR(mp, XFS_INO_TO_AGNO(mp, inum), 2618 XFS_INO_TO_AGBNO(mp, inum)); 2619 2620 /* 2621 * We obtain and lock the backing buffer first in the process |
2634 * here, as we have to ensure that any dirty inode that we 2635 * can't get the flush lock on is attached to the buffer. | 2622 * here to ensure dirty inodes attached to the buffer remain in 2623 * the flushing state while we mark them stale. 2624 * |
2636 * If we scan the in-memory inodes first, then buffer IO can 2637 * complete before we get a lock on it, and hence we may fail 2638 * to mark all the active inodes on the buffer stale. 2639 */ 2640 error = xfs_trans_get_buf(tp, mp->m_ddev_targp, blkno, 2641 mp->m_bsize * igeo->blocks_per_cluster, 2642 XBF_UNMAPPED, &bp); 2643 if (error) --- 794 unchanged lines hidden (view full) --- 3438 struct xfs_buf *bp) 3439{ 3440 struct xfs_inode_log_item *iip = ip->i_itemp; 3441 struct xfs_dinode *dip; 3442 struct xfs_mount *mp = ip->i_mount; 3443 int error; 3444 3445 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)); | 2625 * If we scan the in-memory inodes first, then buffer IO can 2626 * complete before we get a lock on it, and hence we may fail 2627 * to mark all the active inodes on the buffer stale. 2628 */ 2629 error = xfs_trans_get_buf(tp, mp->m_ddev_targp, blkno, 2630 mp->m_bsize * igeo->blocks_per_cluster, 2631 XBF_UNMAPPED, &bp); 2632 if (error) --- 794 unchanged lines hidden (view full) --- 3427 struct xfs_buf *bp) 3428{ 3429 struct xfs_inode_log_item *iip = ip->i_itemp; 3430 struct xfs_dinode *dip; 3431 struct xfs_mount *mp = ip->i_mount; 3432 int error; 3433 3434 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_ILOCK_SHARED)); |
3446 ASSERT(xfs_isiflocked(ip)); | 3435 ASSERT(xfs_iflags_test(ip, XFS_IFLUSHING)); |
3447 ASSERT(ip->i_df.if_format != XFS_DINODE_FMT_BTREE || 3448 ip->i_df.if_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)); 3449 ASSERT(iip->ili_item.li_buf == bp); 3450 3451 dip = xfs_buf_offset(bp, ip->i_imap.im_boffset); 3452 3453 /* 3454 * We don't flush the inode if any of the following checks fail, but we --- 93 unchanged lines hidden (view full) --- 3548 * However, we can't stop logging all this information until the data 3549 * we've copied into the disk buffer is written to disk. If we did we 3550 * might overwrite the copy of the inode in the log with all the data 3551 * after re-logging only part of it, and in the face of a crash we 3552 * wouldn't have all the data we need to recover. 3553 * 3554 * What we do is move the bits to the ili_last_fields field. When 3555 * logging the inode, these bits are moved back to the ili_fields field. | 3436 ASSERT(ip->i_df.if_format != XFS_DINODE_FMT_BTREE || 3437 ip->i_df.if_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)); 3438 ASSERT(iip->ili_item.li_buf == bp); 3439 3440 dip = xfs_buf_offset(bp, ip->i_imap.im_boffset); 3441 3442 /* 3443 * We don't flush the inode if any of the following checks fail, but we --- 93 unchanged lines hidden (view full) --- 3537 * However, we can't stop logging all this information until the data 3538 * we've copied into the disk buffer is written to disk. If we did we 3539 * might overwrite the copy of the inode in the log with all the data 3540 * after re-logging only part of it, and in the face of a crash we 3541 * wouldn't have all the data we need to recover. 3542 * 3543 * What we do is move the bits to the ili_last_fields field. When 3544 * logging the inode, these bits are moved back to the ili_fields field. |
3556 * In the xfs_iflush_done() routine we clear ili_last_fields, since we 3557 * know that the information those bits represent is permanently on | 3545 * In the xfs_buf_inode_iodone() routine we clear ili_last_fields, since 3546 * we know that the information those bits represent is permanently on |
3558 * disk. As long as the flush completes before the inode is logged 3559 * again, then both ili_fields and ili_last_fields will be cleared. 3560 */ 3561 error = 0; 3562flush_out: 3563 spin_lock(&iip->ili_lock); 3564 iip->ili_last_fields = iip->ili_fields; 3565 iip->ili_fields = 0; 3566 iip->ili_fsync_fields = 0; 3567 spin_unlock(&iip->ili_lock); 3568 3569 /* 3570 * Store the current LSN of the inode so that we can tell whether the | 3547 * disk. As long as the flush completes before the inode is logged 3548 * again, then both ili_fields and ili_last_fields will be cleared. 3549 */ 3550 error = 0; 3551flush_out: 3552 spin_lock(&iip->ili_lock); 3553 iip->ili_last_fields = iip->ili_fields; 3554 iip->ili_fields = 0; 3555 iip->ili_fsync_fields = 0; 3556 spin_unlock(&iip->ili_lock); 3557 3558 /* 3559 * Store the current LSN of the inode so that we can tell whether the |
3571 * item has moved in the AIL from xfs_iflush_done(). | 3560 * item has moved in the AIL from xfs_buf_inode_iodone(). |
3572 */ 3573 xfs_trans_ail_copy_lsn(mp->m_ail, &iip->ili_flush_lsn, 3574 &iip->ili_item.li_lsn); 3575 3576 /* generate the checksum. */ 3577 xfs_dinode_calc_crc(mp, dip); 3578 return error; 3579} --- 28 unchanged lines hidden (view full) --- 3608 */ 3609 list_for_each_entry_safe(lip, n, &bp->b_li_list, li_bio_list) { 3610 iip = (struct xfs_inode_log_item *)lip; 3611 ip = iip->ili_inode; 3612 3613 /* 3614 * Quick and dirty check to avoid locks if possible. 3615 */ | 3561 */ 3562 xfs_trans_ail_copy_lsn(mp->m_ail, &iip->ili_flush_lsn, 3563 &iip->ili_item.li_lsn); 3564 3565 /* generate the checksum. */ 3566 xfs_dinode_calc_crc(mp, dip); 3567 return error; 3568} --- 28 unchanged lines hidden (view full) --- 3597 */ 3598 list_for_each_entry_safe(lip, n, &bp->b_li_list, li_bio_list) { 3599 iip = (struct xfs_inode_log_item *)lip; 3600 ip = iip->ili_inode; 3601 3602 /* 3603 * Quick and dirty check to avoid locks if possible. 3604 */ |
3616 if (__xfs_iflags_test(ip, XFS_IRECLAIM | XFS_IFLOCK)) | 3605 if (__xfs_iflags_test(ip, XFS_IRECLAIM | XFS_IFLUSHING)) |
3617 continue; 3618 if (xfs_ipincount(ip)) 3619 continue; 3620 3621 /* 3622 * The inode is still attached to the buffer, which means it is 3623 * dirty but reclaim might try to grab it. Check carefully for 3624 * that, and grab the ilock while still holding the i_flags_lock 3625 * to guarantee reclaim will not be able to reclaim this inode 3626 * once we drop the i_flags_lock. 3627 */ 3628 spin_lock(&ip->i_flags_lock); 3629 ASSERT(!__xfs_iflags_test(ip, XFS_ISTALE)); | 3606 continue; 3607 if (xfs_ipincount(ip)) 3608 continue; 3609 3610 /* 3611 * The inode is still attached to the buffer, which means it is 3612 * dirty but reclaim might try to grab it. Check carefully for 3613 * that, and grab the ilock while still holding the i_flags_lock 3614 * to guarantee reclaim will not be able to reclaim this inode 3615 * once we drop the i_flags_lock. 3616 */ 3617 spin_lock(&ip->i_flags_lock); 3618 ASSERT(!__xfs_iflags_test(ip, XFS_ISTALE)); |
3630 if (__xfs_iflags_test(ip, XFS_IRECLAIM | XFS_IFLOCK)) { | 3619 if (__xfs_iflags_test(ip, XFS_IRECLAIM | XFS_IFLUSHING)) { |
3631 spin_unlock(&ip->i_flags_lock); 3632 continue; 3633 } 3634 3635 /* 3636 * ILOCK will pin the inode against reclaim and prevent 3637 * concurrent transactions modifying the inode while we are | 3620 spin_unlock(&ip->i_flags_lock); 3621 continue; 3622 } 3623 3624 /* 3625 * ILOCK will pin the inode against reclaim and prevent 3626 * concurrent transactions modifying the inode while we are |
3638 * flushing the inode. | 3627 * flushing the inode. If we get the lock, set the flushing 3628 * state before we drop the i_flags_lock. |
3639 */ 3640 if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) { 3641 spin_unlock(&ip->i_flags_lock); 3642 continue; 3643 } | 3629 */ 3630 if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) { 3631 spin_unlock(&ip->i_flags_lock); 3632 continue; 3633 } |
3634 __xfs_iflags_set(ip, XFS_IFLUSHING); |
|
3644 spin_unlock(&ip->i_flags_lock); 3645 3646 /* | 3635 spin_unlock(&ip->i_flags_lock); 3636 3637 /* |
3647 * Skip inodes that are already flush locked as they have 3648 * already been written to the buffer. 3649 */ 3650 if (!xfs_iflock_nowait(ip)) { 3651 xfs_iunlock(ip, XFS_ILOCK_SHARED); 3652 continue; 3653 } 3654 3655 /* | |
3656 * Abort flushing this inode if we are shut down because the 3657 * inode may not currently be in the AIL. This can occur when 3658 * log I/O failure unpins the inode without inserting into the 3659 * AIL, leaving a dirty/unpinned inode attached to the buffer 3660 * that otherwise looks like it should be flushed. 3661 */ 3662 if (XFS_FORCED_SHUTDOWN(mp)) { 3663 xfs_iunpin_wait(ip); | 3638 * Abort flushing this inode if we are shut down because the 3639 * inode may not currently be in the AIL. This can occur when 3640 * log I/O failure unpins the inode without inserting into the 3641 * AIL, leaving a dirty/unpinned inode attached to the buffer 3642 * that otherwise looks like it should be flushed. 3643 */ 3644 if (XFS_FORCED_SHUTDOWN(mp)) { 3645 xfs_iunpin_wait(ip); |
3664 /* xfs_iflush_abort() drops the flush lock */ | |
3665 xfs_iflush_abort(ip); 3666 xfs_iunlock(ip, XFS_ILOCK_SHARED); 3667 error = -EIO; 3668 continue; 3669 } 3670 3671 /* don't block waiting on a log force to unpin dirty inodes */ 3672 if (xfs_ipincount(ip)) { | 3646 xfs_iflush_abort(ip); 3647 xfs_iunlock(ip, XFS_ILOCK_SHARED); 3648 error = -EIO; 3649 continue; 3650 } 3651 3652 /* don't block waiting on a log force to unpin dirty inodes */ 3653 if (xfs_ipincount(ip)) { |
3673 xfs_ifunlock(ip); | 3654 xfs_iflags_clear(ip, XFS_IFLUSHING); |
3674 xfs_iunlock(ip, XFS_ILOCK_SHARED); 3675 continue; 3676 } 3677 3678 if (!xfs_inode_clean(ip)) 3679 error = xfs_iflush(ip, bp); 3680 else | 3655 xfs_iunlock(ip, XFS_ILOCK_SHARED); 3656 continue; 3657 } 3658 3659 if (!xfs_inode_clean(ip)) 3660 error = xfs_iflush(ip, bp); 3661 else |
3681 xfs_ifunlock(ip); | 3662 xfs_iflags_clear(ip, XFS_IFLUSHING); |
3682 xfs_iunlock(ip, XFS_ILOCK_SHARED); 3683 if (error) 3684 break; 3685 clcount++; 3686 } 3687 3688 if (error) { 3689 bp->b_flags |= XBF_ASYNC; --- 134 unchanged lines hidden --- | 3663 xfs_iunlock(ip, XFS_ILOCK_SHARED); 3664 if (error) 3665 break; 3666 clcount++; 3667 } 3668 3669 if (error) { 3670 bp->b_flags |= XBF_ASYNC; --- 134 unchanged lines hidden --- |