Merge tag 'libnvdimm-for-4.18' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdim...
[linux-2.6-microblaze.git] / fs / xfs / xfs_trans_priv.h
1 /*
2  * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 #ifndef __XFS_TRANS_PRIV_H__
19 #define __XFS_TRANS_PRIV_H__
20
21 struct xfs_log_item;
22 struct xfs_mount;
23 struct xfs_trans;
24 struct xfs_ail;
25 struct xfs_log_vec;
26
27
28 void    xfs_trans_init(struct xfs_mount *);
29 void    xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *);
30 void    xfs_trans_del_item(struct xfs_log_item *);
31 void    xfs_trans_free_items(struct xfs_trans *tp, xfs_lsn_t commit_lsn,
32                                 bool abort);
33 void    xfs_trans_unreserve_and_mod_sb(struct xfs_trans *tp);
34
35 void    xfs_trans_committed_bulk(struct xfs_ail *ailp, struct xfs_log_vec *lv,
36                                 xfs_lsn_t commit_lsn, int aborted);
37 /*
38  * AIL traversal cursor.
39  *
40  * Rather than using a generation number for detecting changes in the ail, use
41  * a cursor that is protected by the ail lock. The aild cursor exists in the
42  * struct xfs_ail, but other traversals can declare it on the stack and link it
43  * to the ail list.
44  *
45  * When an object is deleted from or moved int the AIL, the cursor list is
46  * searched to see if the object is a designated cursor item. If it is, it is
47  * deleted from the cursor so that the next time the cursor is used traversal
48  * will return to the start.
49  *
50  * This means a traversal colliding with a removal will cause a restart of the
51  * list scan, rather than any insertion or deletion anywhere in the list. The
52  * low bit of the item pointer is set if the cursor has been invalidated so
53  * that we can tell the difference between invalidation and reaching the end
54  * of the list to trigger traversal restarts.
55  */
56 struct xfs_ail_cursor {
57         struct list_head        list;
58         struct xfs_log_item     *item;
59 };
60
61 /*
62  * Private AIL structures.
63  *
64  * Eventually we need to drive the locking in here as well.
65  */
66 struct xfs_ail {
67         struct xfs_mount        *ail_mount;
68         struct task_struct      *ail_task;
69         struct list_head        ail_head;
70         xfs_lsn_t               ail_target;
71         xfs_lsn_t               ail_target_prev;
72         struct list_head        ail_cursors;
73         spinlock_t              ail_lock;
74         xfs_lsn_t               ail_last_pushed_lsn;
75         int                     ail_log_flush;
76         struct list_head        ail_buf_list;
77         wait_queue_head_t       ail_empty;
78 };
79
80 /*
81  * From xfs_trans_ail.c
82  */
83 void    xfs_trans_ail_update_bulk(struct xfs_ail *ailp,
84                                 struct xfs_ail_cursor *cur,
85                                 struct xfs_log_item **log_items, int nr_items,
86                                 xfs_lsn_t lsn) __releases(ailp->ail_lock);
87 /*
88  * Return a pointer to the first item in the AIL.  If the AIL is empty, then
89  * return NULL.
90  */
91 static inline struct xfs_log_item *
92 xfs_ail_min(
93         struct xfs_ail  *ailp)
94 {
95         return list_first_entry_or_null(&ailp->ail_head, struct xfs_log_item,
96                                         li_ail);
97 }
98
99 static inline void
100 xfs_trans_ail_update(
101         struct xfs_ail          *ailp,
102         struct xfs_log_item     *lip,
103         xfs_lsn_t               lsn) __releases(ailp->ail_lock)
104 {
105         xfs_trans_ail_update_bulk(ailp, NULL, &lip, 1, lsn);
106 }
107
108 bool xfs_ail_delete_one(struct xfs_ail *ailp, struct xfs_log_item *lip);
109 void xfs_trans_ail_delete(struct xfs_ail *ailp, struct xfs_log_item *lip,
110                 int shutdown_type) __releases(ailp->ail_lock);
111
112 static inline void
113 xfs_trans_ail_remove(
114         struct xfs_log_item     *lip,
115         int                     shutdown_type)
116 {
117         struct xfs_ail          *ailp = lip->li_ailp;
118
119         spin_lock(&ailp->ail_lock);
120         /* xfs_trans_ail_delete() drops the AIL lock */
121         if (test_bit(XFS_LI_IN_AIL, &lip->li_flags))
122                 xfs_trans_ail_delete(ailp, lip, shutdown_type);
123         else
124                 spin_unlock(&ailp->ail_lock);
125 }
126
127 void                    xfs_ail_push(struct xfs_ail *, xfs_lsn_t);
128 void                    xfs_ail_push_all(struct xfs_ail *);
129 void                    xfs_ail_push_all_sync(struct xfs_ail *);
130 struct xfs_log_item     *xfs_ail_min(struct xfs_ail  *ailp);
131 xfs_lsn_t               xfs_ail_min_lsn(struct xfs_ail *ailp);
132
133 struct xfs_log_item *   xfs_trans_ail_cursor_first(struct xfs_ail *ailp,
134                                         struct xfs_ail_cursor *cur,
135                                         xfs_lsn_t lsn);
136 struct xfs_log_item *   xfs_trans_ail_cursor_last(struct xfs_ail *ailp,
137                                         struct xfs_ail_cursor *cur,
138                                         xfs_lsn_t lsn);
139 struct xfs_log_item *   xfs_trans_ail_cursor_next(struct xfs_ail *ailp,
140                                         struct xfs_ail_cursor *cur);
141 void                    xfs_trans_ail_cursor_done(struct xfs_ail_cursor *cur);
142
143 #if BITS_PER_LONG != 64
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); /* don't lock if it shrinks */
151         spin_lock(&ailp->ail_lock);
152         *dst = *src;
153         spin_unlock(&ailp->ail_lock);
154 }
155 #else
156 static inline void
157 xfs_trans_ail_copy_lsn(
158         struct xfs_ail  *ailp,
159         xfs_lsn_t       *dst,
160         xfs_lsn_t       *src)
161 {
162         ASSERT(sizeof(xfs_lsn_t) == 8);
163         *dst = *src;
164 }
165 #endif
166
167 static inline void
168 xfs_clear_li_failed(
169         struct xfs_log_item     *lip)
170 {
171         struct xfs_buf  *bp = lip->li_buf;
172
173         ASSERT(test_bit(XFS_LI_IN_AIL, &lip->li_flags));
174         lockdep_assert_held(&lip->li_ailp->ail_lock);
175
176         if (test_and_clear_bit(XFS_LI_FAILED, &lip->li_flags)) {
177                 lip->li_buf = NULL;
178                 xfs_buf_rele(bp);
179         }
180 }
181
182 static inline void
183 xfs_set_li_failed(
184         struct xfs_log_item     *lip,
185         struct xfs_buf          *bp)
186 {
187         lockdep_assert_held(&lip->li_ailp->ail_lock);
188
189         if (!test_and_set_bit(XFS_LI_FAILED, &lip->li_flags)) {
190                 xfs_buf_hold(bp);
191                 lip->li_buf = bp;
192         }
193 }
194
195 #endif  /* __XFS_TRANS_PRIV_H__ */