Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | #ifndef __XFS_TRANS_PRIV_H__ |
| 7 | #define __XFS_TRANS_PRIV_H__ |
| 8 | |
| 9 | struct xfs_log_item; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | struct xfs_mount; |
| 11 | struct xfs_trans; |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 12 | struct xfs_ail; |
| 13 | struct xfs_log_vec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
Dave Chinner | d386b32 | 2013-08-12 20:49:31 +1000 | [diff] [blame] | 15 | |
| 16 | void xfs_trans_init(struct xfs_mount *); |
Christoph Hellwig | e98c414 | 2010-06-23 18:11:15 +1000 | [diff] [blame] | 17 | void xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *); |
| 18 | void xfs_trans_del_item(struct xfs_log_item *); |
Dave Chinner | d17c701 | 2010-08-24 11:42:52 +1000 | [diff] [blame] | 19 | void xfs_trans_free_items(struct xfs_trans *tp, xfs_lsn_t commit_lsn, |
Christoph Hellwig | eacb24e | 2015-06-04 13:47:43 +1000 | [diff] [blame] | 20 | bool abort); |
Dave Chinner | 71e330b | 2010-05-21 14:37:18 +1000 | [diff] [blame] | 21 | void xfs_trans_unreserve_and_mod_sb(struct xfs_trans *tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Dave Chinner | 0e57f6a | 2010-12-20 12:02:19 +1100 | [diff] [blame] | 23 | void xfs_trans_committed_bulk(struct xfs_ail *ailp, struct xfs_log_vec *lv, |
| 24 | xfs_lsn_t commit_lsn, int aborted); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | /* |
David Chinner | 27d8d5f | 2008-10-30 17:38:39 +1100 | [diff] [blame] | 26 | * AIL traversal cursor. |
| 27 | * |
| 28 | * Rather than using a generation number for detecting changes in the ail, use |
| 29 | * a cursor that is protected by the ail lock. The aild cursor exists in the |
| 30 | * struct xfs_ail, but other traversals can declare it on the stack and link it |
| 31 | * to the ail list. |
| 32 | * |
| 33 | * When an object is deleted from or moved int the AIL, the cursor list is |
| 34 | * searched to see if the object is a designated cursor item. If it is, it is |
| 35 | * deleted from the cursor so that the next time the cursor is used traversal |
| 36 | * will return to the start. |
| 37 | * |
| 38 | * This means a traversal colliding with a removal will cause a restart of the |
| 39 | * list scan, rather than any insertion or deletion anywhere in the list. The |
| 40 | * low bit of the item pointer is set if the cursor has been invalidated so |
| 41 | * that we can tell the difference between invalidation and reaching the end |
| 42 | * of the list to trigger traversal restarts. |
| 43 | */ |
| 44 | struct xfs_ail_cursor { |
Dave Chinner | af3e402 | 2011-07-18 03:40:18 +0000 | [diff] [blame] | 45 | struct list_head list; |
David Chinner | 27d8d5f | 2008-10-30 17:38:39 +1100 | [diff] [blame] | 46 | struct xfs_log_item *item; |
| 47 | }; |
| 48 | |
| 49 | /* |
| 50 | * Private AIL structures. |
| 51 | * |
| 52 | * Eventually we need to drive the locking in here as well. |
| 53 | */ |
| 54 | struct xfs_ail { |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 55 | struct xfs_mount *ail_mount; |
| 56 | struct task_struct *ail_task; |
| 57 | struct list_head ail_head; |
| 58 | xfs_lsn_t ail_target; |
| 59 | xfs_lsn_t ail_target_prev; |
| 60 | struct list_head ail_cursors; |
| 61 | spinlock_t ail_lock; |
| 62 | xfs_lsn_t ail_last_pushed_lsn; |
| 63 | int ail_log_flush; |
| 64 | struct list_head ail_buf_list; |
| 65 | wait_queue_head_t ail_empty; |
David Chinner | 27d8d5f | 2008-10-30 17:38:39 +1100 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | * From xfs_trans_ail.c |
| 70 | */ |
Dave Chinner | e605994 | 2010-12-20 12:34:26 +1100 | [diff] [blame] | 71 | void xfs_trans_ail_update_bulk(struct xfs_ail *ailp, |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 72 | struct xfs_ail_cursor *cur, |
Dave Chinner | e605994 | 2010-12-20 12:34:26 +1100 | [diff] [blame] | 73 | struct xfs_log_item **log_items, int nr_items, |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 74 | xfs_lsn_t lsn) __releases(ailp->ail_lock); |
Jie Liu | 8d1d408 | 2013-08-15 13:08:35 +0800 | [diff] [blame] | 75 | /* |
| 76 | * Return a pointer to the first item in the AIL. If the AIL is empty, then |
| 77 | * return NULL. |
| 78 | */ |
| 79 | static inline struct xfs_log_item * |
| 80 | xfs_ail_min( |
| 81 | struct xfs_ail *ailp) |
| 82 | { |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 83 | return list_first_entry_or_null(&ailp->ail_head, struct xfs_log_item, |
Jie Liu | 8d1d408 | 2013-08-15 13:08:35 +0800 | [diff] [blame] | 84 | li_ail); |
| 85 | } |
| 86 | |
Dave Chinner | e605994 | 2010-12-20 12:34:26 +1100 | [diff] [blame] | 87 | static inline void |
| 88 | xfs_trans_ail_update( |
| 89 | struct xfs_ail *ailp, |
| 90 | struct xfs_log_item *lip, |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 91 | xfs_lsn_t lsn) __releases(ailp->ail_lock) |
Dave Chinner | e605994 | 2010-12-20 12:34:26 +1100 | [diff] [blame] | 92 | { |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 93 | xfs_trans_ail_update_bulk(ailp, NULL, &lip, 1, lsn); |
Dave Chinner | e605994 | 2010-12-20 12:34:26 +1100 | [diff] [blame] | 94 | } |
| 95 | |
Christoph Hellwig | 27af1bb | 2017-04-21 11:24:42 -0700 | [diff] [blame] | 96 | bool xfs_ail_delete_one(struct xfs_ail *ailp, struct xfs_log_item *lip); |
| 97 | void xfs_trans_ail_delete(struct xfs_ail *ailp, struct xfs_log_item *lip, |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 98 | int shutdown_type) __releases(ailp->ail_lock); |
Dave Chinner | 9552e7f | 2010-12-20 12:36:15 +1100 | [diff] [blame] | 99 | |
Brian Foster | 146e54b | 2015-08-19 10:01:08 +1000 | [diff] [blame] | 100 | static inline void |
| 101 | xfs_trans_ail_remove( |
| 102 | struct xfs_log_item *lip, |
| 103 | int shutdown_type) |
| 104 | { |
| 105 | struct xfs_ail *ailp = lip->li_ailp; |
| 106 | |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 107 | spin_lock(&ailp->ail_lock); |
Brian Foster | 146e54b | 2015-08-19 10:01:08 +1000 | [diff] [blame] | 108 | /* xfs_trans_ail_delete() drops the AIL lock */ |
Dave Chinner | 22525c1 | 2018-05-09 07:47:34 -0700 | [diff] [blame] | 109 | if (test_bit(XFS_LI_IN_AIL, &lip->li_flags)) |
Brian Foster | 146e54b | 2015-08-19 10:01:08 +1000 | [diff] [blame] | 110 | xfs_trans_ail_delete(ailp, lip, shutdown_type); |
| 111 | else |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 112 | spin_unlock(&ailp->ail_lock); |
Brian Foster | 146e54b | 2015-08-19 10:01:08 +1000 | [diff] [blame] | 113 | } |
| 114 | |
Dave Chinner | fd07484 | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 115 | void xfs_ail_push(struct xfs_ail *, xfs_lsn_t); |
| 116 | void xfs_ail_push_all(struct xfs_ail *); |
Christoph Hellwig | 211e4d4 | 2012-04-23 15:58:34 +1000 | [diff] [blame] | 117 | void xfs_ail_push_all_sync(struct xfs_ail *); |
Christoph Hellwig | 1c30462 | 2012-04-23 15:58:33 +1000 | [diff] [blame] | 118 | struct xfs_log_item *xfs_ail_min(struct xfs_ail *ailp); |
Dave Chinner | fd07484 | 2011-04-08 12:45:07 +1000 | [diff] [blame] | 119 | xfs_lsn_t xfs_ail_min_lsn(struct xfs_ail *ailp); |
| 120 | |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 121 | struct xfs_log_item * xfs_trans_ail_cursor_first(struct xfs_ail *ailp, |
David Chinner | 5b00f14 | 2008-10-30 17:39:00 +1100 | [diff] [blame] | 122 | struct xfs_ail_cursor *cur, |
| 123 | xfs_lsn_t lsn); |
Dave Chinner | 1d8c95a | 2011-07-18 03:40:16 +0000 | [diff] [blame] | 124 | struct xfs_log_item * xfs_trans_ail_cursor_last(struct xfs_ail *ailp, |
| 125 | struct xfs_ail_cursor *cur, |
| 126 | xfs_lsn_t lsn); |
| 127 | struct xfs_log_item * xfs_trans_ail_cursor_next(struct xfs_ail *ailp, |
David Chinner | 27d8d5f | 2008-10-30 17:38:39 +1100 | [diff] [blame] | 128 | struct xfs_ail_cursor *cur); |
Eric Sandeen | e4a1e29 | 2014-04-14 19:06:05 +1000 | [diff] [blame] | 129 | void xfs_trans_ail_cursor_done(struct xfs_ail_cursor *cur); |
David Chinner | 82fa901 | 2008-10-30 17:38:26 +1100 | [diff] [blame] | 130 | |
David Chinner | 7b2e2a3 | 2008-10-30 17:39:12 +1100 | [diff] [blame] | 131 | #if BITS_PER_LONG != 64 |
| 132 | static inline void |
| 133 | xfs_trans_ail_copy_lsn( |
| 134 | struct xfs_ail *ailp, |
| 135 | xfs_lsn_t *dst, |
| 136 | xfs_lsn_t *src) |
| 137 | { |
| 138 | ASSERT(sizeof(xfs_lsn_t) == 8); /* don't lock if it shrinks */ |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 139 | spin_lock(&ailp->ail_lock); |
David Chinner | 7b2e2a3 | 2008-10-30 17:39:12 +1100 | [diff] [blame] | 140 | *dst = *src; |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 141 | spin_unlock(&ailp->ail_lock); |
David Chinner | 7b2e2a3 | 2008-10-30 17:39:12 +1100 | [diff] [blame] | 142 | } |
| 143 | #else |
| 144 | static inline void |
| 145 | xfs_trans_ail_copy_lsn( |
| 146 | struct xfs_ail *ailp, |
| 147 | xfs_lsn_t *dst, |
| 148 | xfs_lsn_t *src) |
| 149 | { |
| 150 | ASSERT(sizeof(xfs_lsn_t) == 8); |
| 151 | *dst = *src; |
| 152 | } |
| 153 | #endif |
Carlos Maiolino | d3a304b | 2017-08-08 18:21:50 -0700 | [diff] [blame] | 154 | |
| 155 | static inline void |
| 156 | xfs_clear_li_failed( |
| 157 | struct xfs_log_item *lip) |
| 158 | { |
| 159 | struct xfs_buf *bp = lip->li_buf; |
| 160 | |
Dave Chinner | 22525c1 | 2018-05-09 07:47:34 -0700 | [diff] [blame] | 161 | ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags)); |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 162 | lockdep_assert_held(&lip->li_ailp->ail_lock); |
Carlos Maiolino | d3a304b | 2017-08-08 18:21:50 -0700 | [diff] [blame] | 163 | |
Dave Chinner | 22525c1 | 2018-05-09 07:47:34 -0700 | [diff] [blame] | 164 | if (test_and_clear_bit(XFS_LI_FAILED, &lip->li_flags)) { |
Carlos Maiolino | d3a304b | 2017-08-08 18:21:50 -0700 | [diff] [blame] | 165 | lip->li_buf = NULL; |
| 166 | xfs_buf_rele(bp); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | static inline void |
| 171 | xfs_set_li_failed( |
| 172 | struct xfs_log_item *lip, |
| 173 | struct xfs_buf *bp) |
| 174 | { |
Matthew Wilcox | 57e8095 | 2018-03-07 14:59:39 -0800 | [diff] [blame] | 175 | lockdep_assert_held(&lip->li_ailp->ail_lock); |
Carlos Maiolino | d3a304b | 2017-08-08 18:21:50 -0700 | [diff] [blame] | 176 | |
Dave Chinner | 22525c1 | 2018-05-09 07:47:34 -0700 | [diff] [blame] | 177 | if (!test_and_set_bit(XFS_LI_FAILED, &lip->li_flags)) { |
Carlos Maiolino | d3a304b | 2017-08-08 18:21:50 -0700 | [diff] [blame] | 178 | xfs_buf_hold(bp); |
Carlos Maiolino | d3a304b | 2017-08-08 18:21:50 -0700 | [diff] [blame] | 179 | lip->li_buf = bp; |
| 180 | } |
| 181 | } |
| 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | #endif /* __XFS_TRANS_PRIV_H__ */ |