11da177e4SLinus Torvalds /* 27b718769SNathan Scott * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. 3c7e8f268SDavid Chinner * Copyright (c) 2008 Dave Chinner 47b718769SNathan Scott * All Rights Reserved. 51da177e4SLinus Torvalds * 67b718769SNathan Scott * This program is free software; you can redistribute it and/or 77b718769SNathan Scott * modify it under the terms of the GNU General Public License as 81da177e4SLinus Torvalds * published by the Free Software Foundation. 91da177e4SLinus Torvalds * 107b718769SNathan Scott * This program is distributed in the hope that it would be useful, 117b718769SNathan Scott * but WITHOUT ANY WARRANTY; without even the implied warranty of 127b718769SNathan Scott * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 137b718769SNathan Scott * GNU General Public License for more details. 141da177e4SLinus Torvalds * 157b718769SNathan Scott * You should have received a copy of the GNU General Public License 167b718769SNathan Scott * along with this program; if not, write the Free Software Foundation, 177b718769SNathan Scott * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 181da177e4SLinus Torvalds */ 191da177e4SLinus Torvalds #include "xfs.h" 20a844f451SNathan Scott #include "xfs_fs.h" 211da177e4SLinus Torvalds #include "xfs_types.h" 221da177e4SLinus Torvalds #include "xfs_log.h" 23a844f451SNathan Scott #include "xfs_inum.h" 241da177e4SLinus Torvalds #include "xfs_trans.h" 251da177e4SLinus Torvalds #include "xfs_sb.h" 26da353b0dSDavid Chinner #include "xfs_ag.h" 271da177e4SLinus Torvalds #include "xfs_mount.h" 281da177e4SLinus Torvalds #include "xfs_trans_priv.h" 291da177e4SLinus Torvalds #include "xfs_error.h" 301da177e4SLinus Torvalds 310bf6a5bdSDave Chinner struct workqueue_struct *xfs_ail_wq; /* AIL workqueue */ 320bf6a5bdSDave Chinner 331da177e4SLinus Torvalds #ifdef DEBUG 34*cd4a3c50SDave Chinner /* 35*cd4a3c50SDave Chinner * Check that the list is sorted as it should be. 36*cd4a3c50SDave Chinner */ 37*cd4a3c50SDave Chinner STATIC void 38*cd4a3c50SDave Chinner xfs_ail_check( 39*cd4a3c50SDave Chinner struct xfs_ail *ailp, 40*cd4a3c50SDave Chinner xfs_log_item_t *lip) 41*cd4a3c50SDave Chinner { 42*cd4a3c50SDave Chinner xfs_log_item_t *prev_lip; 43*cd4a3c50SDave Chinner 44*cd4a3c50SDave Chinner if (list_empty(&ailp->xa_ail)) 45*cd4a3c50SDave Chinner return; 46*cd4a3c50SDave Chinner 47*cd4a3c50SDave Chinner /* 48*cd4a3c50SDave Chinner * Check the next and previous entries are valid. 49*cd4a3c50SDave Chinner */ 50*cd4a3c50SDave Chinner ASSERT((lip->li_flags & XFS_LI_IN_AIL) != 0); 51*cd4a3c50SDave Chinner prev_lip = list_entry(lip->li_ail.prev, xfs_log_item_t, li_ail); 52*cd4a3c50SDave Chinner if (&prev_lip->li_ail != &ailp->xa_ail) 53*cd4a3c50SDave Chinner ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) <= 0); 54*cd4a3c50SDave Chinner 55*cd4a3c50SDave Chinner prev_lip = list_entry(lip->li_ail.next, xfs_log_item_t, li_ail); 56*cd4a3c50SDave Chinner if (&prev_lip->li_ail != &ailp->xa_ail) 57*cd4a3c50SDave Chinner ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) >= 0); 58*cd4a3c50SDave Chinner 59*cd4a3c50SDave Chinner 60*cd4a3c50SDave Chinner #ifdef XFS_TRANS_DEBUG 61*cd4a3c50SDave Chinner /* 62*cd4a3c50SDave Chinner * Walk the list checking lsn ordering, and that every entry has the 63*cd4a3c50SDave Chinner * XFS_LI_IN_AIL flag set. This is really expensive, so only do it 64*cd4a3c50SDave Chinner * when specifically debugging the transaction subsystem. 65*cd4a3c50SDave Chinner */ 66*cd4a3c50SDave Chinner prev_lip = list_entry(&ailp->xa_ail, xfs_log_item_t, li_ail); 67*cd4a3c50SDave Chinner list_for_each_entry(lip, &ailp->xa_ail, li_ail) { 68*cd4a3c50SDave Chinner if (&prev_lip->li_ail != &ailp->xa_ail) 69*cd4a3c50SDave Chinner ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) <= 0); 70*cd4a3c50SDave Chinner ASSERT((lip->li_flags & XFS_LI_IN_AIL) != 0); 71*cd4a3c50SDave Chinner prev_lip = lip; 72*cd4a3c50SDave Chinner } 73*cd4a3c50SDave Chinner #endif /* XFS_TRANS_DEBUG */ 74*cd4a3c50SDave Chinner } 75*cd4a3c50SDave Chinner #else /* !DEBUG */ 76de08dbc1SDavid Chinner #define xfs_ail_check(a,l) 771da177e4SLinus Torvalds #endif /* DEBUG */ 781da177e4SLinus Torvalds 79*cd4a3c50SDave Chinner /* 80*cd4a3c50SDave Chinner * Return a pointer to the first item in the AIL. If the AIL is empty, then 81*cd4a3c50SDave Chinner * return NULL. 82*cd4a3c50SDave Chinner */ 83*cd4a3c50SDave Chinner static xfs_log_item_t * 84*cd4a3c50SDave Chinner xfs_ail_min( 85*cd4a3c50SDave Chinner struct xfs_ail *ailp) 86*cd4a3c50SDave Chinner { 87*cd4a3c50SDave Chinner if (list_empty(&ailp->xa_ail)) 88*cd4a3c50SDave Chinner return NULL; 89*cd4a3c50SDave Chinner 90*cd4a3c50SDave Chinner return list_first_entry(&ailp->xa_ail, xfs_log_item_t, li_ail); 91*cd4a3c50SDave Chinner } 921da177e4SLinus Torvalds 931da177e4SLinus Torvalds /* 94*cd4a3c50SDave Chinner * Return a pointer to the item which follows the given item in the AIL. If 95*cd4a3c50SDave Chinner * the given item is the last item in the list, then return NULL. 96*cd4a3c50SDave Chinner */ 97*cd4a3c50SDave Chinner static xfs_log_item_t * 98*cd4a3c50SDave Chinner xfs_ail_next( 99*cd4a3c50SDave Chinner struct xfs_ail *ailp, 100*cd4a3c50SDave Chinner xfs_log_item_t *lip) 101*cd4a3c50SDave Chinner { 102*cd4a3c50SDave Chinner if (lip->li_ail.next == &ailp->xa_ail) 103*cd4a3c50SDave Chinner return NULL; 104*cd4a3c50SDave Chinner 105*cd4a3c50SDave Chinner return list_first_entry(&lip->li_ail, xfs_log_item_t, li_ail); 106*cd4a3c50SDave Chinner } 107*cd4a3c50SDave Chinner 108*cd4a3c50SDave Chinner /* 109*cd4a3c50SDave Chinner * This is called by the log manager code to determine the LSN of the tail of 110*cd4a3c50SDave Chinner * the log. This is exactly the LSN of the first item in the AIL. If the AIL 111*cd4a3c50SDave Chinner * is empty, then this function returns 0. 1121da177e4SLinus Torvalds * 113*cd4a3c50SDave Chinner * We need the AIL lock in order to get a coherent read of the lsn of the last 114*cd4a3c50SDave Chinner * item in the AIL. 1151da177e4SLinus Torvalds */ 1161da177e4SLinus Torvalds xfs_lsn_t 1175b00f14fSDavid Chinner xfs_trans_ail_tail( 1185b00f14fSDavid Chinner struct xfs_ail *ailp) 1191da177e4SLinus Torvalds { 120*cd4a3c50SDave Chinner xfs_lsn_t lsn = 0; 1211da177e4SLinus Torvalds xfs_log_item_t *lip; 1221da177e4SLinus Torvalds 123c7e8f268SDavid Chinner spin_lock(&ailp->xa_lock); 1245b00f14fSDavid Chinner lip = xfs_ail_min(ailp); 125*cd4a3c50SDave Chinner if (lip) 1261da177e4SLinus Torvalds lsn = lip->li_lsn; 127c7e8f268SDavid Chinner spin_unlock(&ailp->xa_lock); 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds return lsn; 1301da177e4SLinus Torvalds } 1311da177e4SLinus Torvalds 1321da177e4SLinus Torvalds /* 13327d8d5feSDavid Chinner * AIL traversal cursor initialisation. 13427d8d5feSDavid Chinner * 13527d8d5feSDavid Chinner * The cursor keeps track of where our current traversal is up 13627d8d5feSDavid Chinner * to by tracking the next ƣtem in the list for us. However, for 13727d8d5feSDavid Chinner * this to be safe, removing an object from the AIL needs to invalidate 13827d8d5feSDavid Chinner * any cursor that points to it. hence the traversal cursor needs to 13927d8d5feSDavid Chinner * be linked to the struct xfs_ail so that deletion can search all the 14027d8d5feSDavid Chinner * active cursors for invalidation. 14127d8d5feSDavid Chinner * 14227d8d5feSDavid Chinner * We don't link the push cursor because it is embedded in the struct 14327d8d5feSDavid Chinner * xfs_ail and hence easily findable. 14427d8d5feSDavid Chinner */ 1455b00f14fSDavid Chinner STATIC void 14627d8d5feSDavid Chinner xfs_trans_ail_cursor_init( 14727d8d5feSDavid Chinner struct xfs_ail *ailp, 14827d8d5feSDavid Chinner struct xfs_ail_cursor *cur) 14927d8d5feSDavid Chinner { 15027d8d5feSDavid Chinner cur->item = NULL; 15127d8d5feSDavid Chinner if (cur == &ailp->xa_cursors) 15227d8d5feSDavid Chinner return; 15327d8d5feSDavid Chinner 15427d8d5feSDavid Chinner cur->next = ailp->xa_cursors.next; 15527d8d5feSDavid Chinner ailp->xa_cursors.next = cur; 15627d8d5feSDavid Chinner } 15727d8d5feSDavid Chinner 15827d8d5feSDavid Chinner /* 15927d8d5feSDavid Chinner * Set the cursor to the next item, because when we look 16027d8d5feSDavid Chinner * up the cursor the current item may have been freed. 16127d8d5feSDavid Chinner */ 16227d8d5feSDavid Chinner STATIC void 16327d8d5feSDavid Chinner xfs_trans_ail_cursor_set( 16427d8d5feSDavid Chinner struct xfs_ail *ailp, 16527d8d5feSDavid Chinner struct xfs_ail_cursor *cur, 16627d8d5feSDavid Chinner struct xfs_log_item *lip) 16727d8d5feSDavid Chinner { 16827d8d5feSDavid Chinner if (lip) 16927d8d5feSDavid Chinner cur->item = xfs_ail_next(ailp, lip); 17027d8d5feSDavid Chinner } 17127d8d5feSDavid Chinner 17227d8d5feSDavid Chinner /* 17327d8d5feSDavid Chinner * Get the next item in the traversal and advance the cursor. 17427d8d5feSDavid Chinner * If the cursor was invalidated (inidicated by a lip of 1), 17527d8d5feSDavid Chinner * restart the traversal. 17627d8d5feSDavid Chinner */ 1775b00f14fSDavid Chinner struct xfs_log_item * 17827d8d5feSDavid Chinner xfs_trans_ail_cursor_next( 17927d8d5feSDavid Chinner struct xfs_ail *ailp, 18027d8d5feSDavid Chinner struct xfs_ail_cursor *cur) 18127d8d5feSDavid Chinner { 18227d8d5feSDavid Chinner struct xfs_log_item *lip = cur->item; 18327d8d5feSDavid Chinner 18427d8d5feSDavid Chinner if ((__psint_t)lip & 1) 18527d8d5feSDavid Chinner lip = xfs_ail_min(ailp); 18627d8d5feSDavid Chinner xfs_trans_ail_cursor_set(ailp, cur, lip); 18727d8d5feSDavid Chinner return lip; 18827d8d5feSDavid Chinner } 18927d8d5feSDavid Chinner 19027d8d5feSDavid Chinner /* 19127d8d5feSDavid Chinner * Now that the traversal is complete, we need to remove the cursor 19227d8d5feSDavid Chinner * from the list of traversing cursors. Avoid removing the embedded 1939da096fdSMalcolm Parsons * push cursor, but use the fact it is always present to make the 19427d8d5feSDavid Chinner * list deletion simple. 19527d8d5feSDavid Chinner */ 19627d8d5feSDavid Chinner void 19727d8d5feSDavid Chinner xfs_trans_ail_cursor_done( 19827d8d5feSDavid Chinner struct xfs_ail *ailp, 19927d8d5feSDavid Chinner struct xfs_ail_cursor *done) 20027d8d5feSDavid Chinner { 20127d8d5feSDavid Chinner struct xfs_ail_cursor *prev = NULL; 20227d8d5feSDavid Chinner struct xfs_ail_cursor *cur; 20327d8d5feSDavid Chinner 20427d8d5feSDavid Chinner done->item = NULL; 20527d8d5feSDavid Chinner if (done == &ailp->xa_cursors) 20627d8d5feSDavid Chinner return; 20727d8d5feSDavid Chinner prev = &ailp->xa_cursors; 20827d8d5feSDavid Chinner for (cur = prev->next; cur; prev = cur, cur = prev->next) { 20927d8d5feSDavid Chinner if (cur == done) { 21027d8d5feSDavid Chinner prev->next = cur->next; 21127d8d5feSDavid Chinner break; 21227d8d5feSDavid Chinner } 21327d8d5feSDavid Chinner } 21427d8d5feSDavid Chinner ASSERT(cur); 21527d8d5feSDavid Chinner } 21627d8d5feSDavid Chinner 21727d8d5feSDavid Chinner /* 2185b00f14fSDavid Chinner * Invalidate any cursor that is pointing to this item. This is 2195b00f14fSDavid Chinner * called when an item is removed from the AIL. Any cursor pointing 2205b00f14fSDavid Chinner * to this object is now invalid and the traversal needs to be 2215b00f14fSDavid Chinner * terminated so it doesn't reference a freed object. We set the 2225b00f14fSDavid Chinner * cursor item to a value of 1 so we can distinguish between an 2235b00f14fSDavid Chinner * invalidation and the end of the list when getting the next item 2245b00f14fSDavid Chinner * from the cursor. 2255b00f14fSDavid Chinner */ 2265b00f14fSDavid Chinner STATIC void 2275b00f14fSDavid Chinner xfs_trans_ail_cursor_clear( 2285b00f14fSDavid Chinner struct xfs_ail *ailp, 2295b00f14fSDavid Chinner struct xfs_log_item *lip) 2305b00f14fSDavid Chinner { 2315b00f14fSDavid Chinner struct xfs_ail_cursor *cur; 2325b00f14fSDavid Chinner 2335b00f14fSDavid Chinner /* need to search all cursors */ 2345b00f14fSDavid Chinner for (cur = &ailp->xa_cursors; cur; cur = cur->next) { 2355b00f14fSDavid Chinner if (cur->item == lip) 2365b00f14fSDavid Chinner cur->item = (struct xfs_log_item *) 2375b00f14fSDavid Chinner ((__psint_t)cur->item | 1); 2385b00f14fSDavid Chinner } 2395b00f14fSDavid Chinner } 2405b00f14fSDavid Chinner 2415b00f14fSDavid Chinner /* 242249a8c11SDavid Chinner * Return the item in the AIL with the current lsn. 243249a8c11SDavid Chinner * Return the current tree generation number for use 244249a8c11SDavid Chinner * in calls to xfs_trans_next_ail(). 245249a8c11SDavid Chinner */ 2465b00f14fSDavid Chinner xfs_log_item_t * 2475b00f14fSDavid Chinner xfs_trans_ail_cursor_first( 24827d8d5feSDavid Chinner struct xfs_ail *ailp, 24927d8d5feSDavid Chinner struct xfs_ail_cursor *cur, 250249a8c11SDavid Chinner xfs_lsn_t lsn) 251249a8c11SDavid Chinner { 252249a8c11SDavid Chinner xfs_log_item_t *lip; 253249a8c11SDavid Chinner 2545b00f14fSDavid Chinner xfs_trans_ail_cursor_init(ailp, cur); 25527d8d5feSDavid Chinner lip = xfs_ail_min(ailp); 256249a8c11SDavid Chinner if (lsn == 0) 2575b00f14fSDavid Chinner goto out; 258249a8c11SDavid Chinner 25927d8d5feSDavid Chinner list_for_each_entry(lip, &ailp->xa_ail, li_ail) { 2605b00f14fSDavid Chinner if (XFS_LSN_CMP(lip->li_lsn, lsn) >= 0) 2617ee49acfSDavid Chinner goto out; 2625b00f14fSDavid Chinner } 2635b00f14fSDavid Chinner lip = NULL; 2645b00f14fSDavid Chinner out: 26527d8d5feSDavid Chinner xfs_trans_ail_cursor_set(ailp, cur, lip); 266249a8c11SDavid Chinner return lip; 267249a8c11SDavid Chinner } 268535f6b37SJosef 'Jeff' Sipek 269249a8c11SDavid Chinner /* 270*cd4a3c50SDave Chinner * splice the log item list into the AIL at the given LSN. 271*cd4a3c50SDave Chinner */ 272*cd4a3c50SDave Chinner static void 273*cd4a3c50SDave Chinner xfs_ail_splice( 274*cd4a3c50SDave Chinner struct xfs_ail *ailp, 275*cd4a3c50SDave Chinner struct list_head *list, 276*cd4a3c50SDave Chinner xfs_lsn_t lsn) 277*cd4a3c50SDave Chinner { 278*cd4a3c50SDave Chinner xfs_log_item_t *next_lip; 279*cd4a3c50SDave Chinner 280*cd4a3c50SDave Chinner /* If the list is empty, just insert the item. */ 281*cd4a3c50SDave Chinner if (list_empty(&ailp->xa_ail)) { 282*cd4a3c50SDave Chinner list_splice(list, &ailp->xa_ail); 283*cd4a3c50SDave Chinner return; 284*cd4a3c50SDave Chinner } 285*cd4a3c50SDave Chinner 286*cd4a3c50SDave Chinner list_for_each_entry_reverse(next_lip, &ailp->xa_ail, li_ail) { 287*cd4a3c50SDave Chinner if (XFS_LSN_CMP(next_lip->li_lsn, lsn) <= 0) 288*cd4a3c50SDave Chinner break; 289*cd4a3c50SDave Chinner } 290*cd4a3c50SDave Chinner 291*cd4a3c50SDave Chinner ASSERT(&next_lip->li_ail == &ailp->xa_ail || 292*cd4a3c50SDave Chinner XFS_LSN_CMP(next_lip->li_lsn, lsn) <= 0); 293*cd4a3c50SDave Chinner 294*cd4a3c50SDave Chinner list_splice_init(list, &next_lip->li_ail); 295*cd4a3c50SDave Chinner } 296*cd4a3c50SDave Chinner 297*cd4a3c50SDave Chinner /* 298*cd4a3c50SDave Chinner * Delete the given item from the AIL. Return a pointer to the item. 299*cd4a3c50SDave Chinner */ 300*cd4a3c50SDave Chinner static void 301*cd4a3c50SDave Chinner xfs_ail_delete( 302*cd4a3c50SDave Chinner struct xfs_ail *ailp, 303*cd4a3c50SDave Chinner xfs_log_item_t *lip) 304*cd4a3c50SDave Chinner { 305*cd4a3c50SDave Chinner xfs_ail_check(ailp, lip); 306*cd4a3c50SDave Chinner list_del(&lip->li_ail); 307*cd4a3c50SDave Chinner xfs_trans_ail_cursor_clear(ailp, lip); 308*cd4a3c50SDave Chinner } 309*cd4a3c50SDave Chinner 310*cd4a3c50SDave Chinner /* 3110bf6a5bdSDave Chinner * xfs_ail_worker does the work of pushing on the AIL. It will requeue itself 3120bf6a5bdSDave Chinner * to run at a later time if there is more work to do to complete the push. 313249a8c11SDavid Chinner */ 3140bf6a5bdSDave Chinner STATIC void 3150bf6a5bdSDave Chinner xfs_ail_worker( 3160bf6a5bdSDave Chinner struct work_struct *work) 317249a8c11SDavid Chinner { 3180bf6a5bdSDave Chinner struct xfs_ail *ailp = container_of(to_delayed_work(work), 3190bf6a5bdSDave Chinner struct xfs_ail, xa_work); 3200bf6a5bdSDave Chinner long tout; 32182fa9012SDavid Chinner xfs_lsn_t target = ailp->xa_target; 3221da177e4SLinus Torvalds xfs_lsn_t lsn; 3231da177e4SLinus Torvalds xfs_log_item_t *lip; 324249a8c11SDavid Chinner int flush_log, count, stuck; 32582fa9012SDavid Chinner xfs_mount_t *mp = ailp->xa_mount; 32627d8d5feSDavid Chinner struct xfs_ail_cursor *cur = &ailp->xa_cursors; 327d808f617SDave Chinner int push_xfsbufd = 0; 3281da177e4SLinus Torvalds 329c7e8f268SDavid Chinner spin_lock(&ailp->xa_lock); 33027d8d5feSDavid Chinner xfs_trans_ail_cursor_init(ailp, cur); 3310bf6a5bdSDave Chinner lip = xfs_trans_ail_cursor_first(ailp, cur, ailp->xa_last_pushed_lsn); 332249a8c11SDavid Chinner if (!lip || XFS_FORCED_SHUTDOWN(mp)) { 3331da177e4SLinus Torvalds /* 334249a8c11SDavid Chinner * AIL is empty or our push has reached the end. 3351da177e4SLinus Torvalds */ 33627d8d5feSDavid Chinner xfs_trans_ail_cursor_done(ailp, cur); 337c7e8f268SDavid Chinner spin_unlock(&ailp->xa_lock); 3380bf6a5bdSDave Chinner ailp->xa_last_pushed_lsn = 0; 3390bf6a5bdSDave Chinner return; 3401da177e4SLinus Torvalds } 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds XFS_STATS_INC(xs_push_ail); 3431da177e4SLinus Torvalds 3441da177e4SLinus Torvalds /* 3451da177e4SLinus Torvalds * While the item we are looking at is below the given threshold 346249a8c11SDavid Chinner * try to flush it out. We'd like not to stop until we've at least 3471da177e4SLinus Torvalds * tried to push on everything in the AIL with an LSN less than 348249a8c11SDavid Chinner * the given threshold. 3491da177e4SLinus Torvalds * 350249a8c11SDavid Chinner * However, we will stop after a certain number of pushes and wait 351249a8c11SDavid Chinner * for a reduced timeout to fire before pushing further. This 352249a8c11SDavid Chinner * prevents use from spinning when we can't do anything or there is 353249a8c11SDavid Chinner * lots of contention on the AIL lists. 354249a8c11SDavid Chinner */ 355249a8c11SDavid Chinner lsn = lip->li_lsn; 35627d8d5feSDavid Chinner flush_log = stuck = count = 0; 357249a8c11SDavid Chinner while ((XFS_LSN_CMP(lip->li_lsn, target) < 0)) { 358249a8c11SDavid Chinner int lock_result; 359249a8c11SDavid Chinner /* 360249a8c11SDavid Chinner * If we can lock the item without sleeping, unlock the AIL 361249a8c11SDavid Chinner * lock and flush the item. Then re-grab the AIL lock so we 362249a8c11SDavid Chinner * can look for the next item on the AIL. List changes are 363249a8c11SDavid Chinner * handled by the AIL lookup functions internally 364249a8c11SDavid Chinner * 365249a8c11SDavid Chinner * If we can't lock the item, either its holder will flush it 366249a8c11SDavid Chinner * or it is already being flushed or it is being relogged. In 367249a8c11SDavid Chinner * any of these case it is being taken care of and we can just 368249a8c11SDavid Chinner * skip to the next item in the list. 3691da177e4SLinus Torvalds */ 3701da177e4SLinus Torvalds lock_result = IOP_TRYLOCK(lip); 371c7e8f268SDavid Chinner spin_unlock(&ailp->xa_lock); 3721da177e4SLinus Torvalds switch (lock_result) { 3731da177e4SLinus Torvalds case XFS_ITEM_SUCCESS: 3741da177e4SLinus Torvalds XFS_STATS_INC(xs_push_ail_success); 3751da177e4SLinus Torvalds IOP_PUSH(lip); 3760bf6a5bdSDave Chinner ailp->xa_last_pushed_lsn = lsn; 3771da177e4SLinus Torvalds break; 3781da177e4SLinus Torvalds 3791da177e4SLinus Torvalds case XFS_ITEM_PUSHBUF: 3801da177e4SLinus Torvalds XFS_STATS_INC(xs_push_ail_pushbuf); 3811da177e4SLinus Torvalds IOP_PUSHBUF(lip); 3820bf6a5bdSDave Chinner ailp->xa_last_pushed_lsn = lsn; 383d808f617SDave Chinner push_xfsbufd = 1; 3841da177e4SLinus Torvalds break; 3851da177e4SLinus Torvalds 3861da177e4SLinus Torvalds case XFS_ITEM_PINNED: 3871da177e4SLinus Torvalds XFS_STATS_INC(xs_push_ail_pinned); 388249a8c11SDavid Chinner stuck++; 3891da177e4SLinus Torvalds flush_log = 1; 3901da177e4SLinus Torvalds break; 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvalds case XFS_ITEM_LOCKED: 3931da177e4SLinus Torvalds XFS_STATS_INC(xs_push_ail_locked); 3940bf6a5bdSDave Chinner ailp->xa_last_pushed_lsn = lsn; 395249a8c11SDavid Chinner stuck++; 3961da177e4SLinus Torvalds break; 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds default: 3991da177e4SLinus Torvalds ASSERT(0); 4001da177e4SLinus Torvalds break; 4011da177e4SLinus Torvalds } 4021da177e4SLinus Torvalds 403c7e8f268SDavid Chinner spin_lock(&ailp->xa_lock); 404249a8c11SDavid Chinner /* should we bother continuing? */ 405249a8c11SDavid Chinner if (XFS_FORCED_SHUTDOWN(mp)) 4061da177e4SLinus Torvalds break; 407249a8c11SDavid Chinner ASSERT(mp->m_log); 4081da177e4SLinus Torvalds 409249a8c11SDavid Chinner count++; 410249a8c11SDavid Chinner 411249a8c11SDavid Chinner /* 412249a8c11SDavid Chinner * Are there too many items we can't do anything with? 413249a8c11SDavid Chinner * If we we are skipping too many items because we can't flush 414249a8c11SDavid Chinner * them or they are already being flushed, we back off and 415249a8c11SDavid Chinner * given them time to complete whatever operation is being 416249a8c11SDavid Chinner * done. i.e. remove pressure from the AIL while we can't make 417249a8c11SDavid Chinner * progress so traversals don't slow down further inserts and 418249a8c11SDavid Chinner * removals to/from the AIL. 419249a8c11SDavid Chinner * 420249a8c11SDavid Chinner * The value of 100 is an arbitrary magic number based on 421249a8c11SDavid Chinner * observation. 422249a8c11SDavid Chinner */ 423249a8c11SDavid Chinner if (stuck > 100) 424249a8c11SDavid Chinner break; 425249a8c11SDavid Chinner 42627d8d5feSDavid Chinner lip = xfs_trans_ail_cursor_next(ailp, cur); 427249a8c11SDavid Chinner if (lip == NULL) 428249a8c11SDavid Chinner break; 429249a8c11SDavid Chinner lsn = lip->li_lsn; 4301da177e4SLinus Torvalds } 43127d8d5feSDavid Chinner xfs_trans_ail_cursor_done(ailp, cur); 432c7e8f268SDavid Chinner spin_unlock(&ailp->xa_lock); 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvalds if (flush_log) { 4351da177e4SLinus Torvalds /* 4361da177e4SLinus Torvalds * If something we need to push out was pinned, then 4371da177e4SLinus Torvalds * push out the log so it will become unpinned and 4381da177e4SLinus Torvalds * move forward in the AIL. 4391da177e4SLinus Torvalds */ 4401da177e4SLinus Torvalds XFS_STATS_INC(xs_push_ail_flush); 441a14a348bSChristoph Hellwig xfs_log_force(mp, 0); 4421da177e4SLinus Torvalds } 4431da177e4SLinus Torvalds 444d808f617SDave Chinner if (push_xfsbufd) { 445d808f617SDave Chinner /* we've got delayed write buffers to flush */ 446d808f617SDave Chinner wake_up_process(mp->m_ddev_targp->bt_task); 447d808f617SDave Chinner } 448d808f617SDave Chinner 4490bf6a5bdSDave Chinner /* assume we have more work to do in a short while */ 4500bf6a5bdSDave Chinner tout = 10; 45192d9cd10SDavid Chinner if (!count) { 45292d9cd10SDavid Chinner /* We're past our target or empty, so idle */ 4530bf6a5bdSDave Chinner ailp->xa_last_pushed_lsn = 0; 4540bf6a5bdSDave Chinner 4550bf6a5bdSDave Chinner /* 4560bf6a5bdSDave Chinner * Check for an updated push target before clearing the 4570bf6a5bdSDave Chinner * XFS_AIL_PUSHING_BIT. If the target changed, we've got more 4580bf6a5bdSDave Chinner * work to do. Wait a bit longer before starting that work. 4590bf6a5bdSDave Chinner */ 4600bf6a5bdSDave Chinner smp_rmb(); 4610bf6a5bdSDave Chinner if (ailp->xa_target == target) { 4620bf6a5bdSDave Chinner clear_bit(XFS_AIL_PUSHING_BIT, &ailp->xa_flags); 4630bf6a5bdSDave Chinner return; 4640bf6a5bdSDave Chinner } 4650bf6a5bdSDave Chinner tout = 50; 46692d9cd10SDavid Chinner } else if (XFS_LSN_CMP(lsn, target) >= 0) { 467249a8c11SDavid Chinner /* 46892d9cd10SDavid Chinner * We reached the target so wait a bit longer for I/O to 46992d9cd10SDavid Chinner * complete and remove pushed items from the AIL before we 47092d9cd10SDavid Chinner * start the next scan from the start of the AIL. 471249a8c11SDavid Chinner */ 472453eac8aSDave Chinner tout = 50; 4730bf6a5bdSDave Chinner ailp->xa_last_pushed_lsn = 0; 47427d8d5feSDavid Chinner } else if ((stuck * 100) / count > 90) { 475249a8c11SDavid Chinner /* 476249a8c11SDavid Chinner * Either there is a lot of contention on the AIL or we 477249a8c11SDavid Chinner * are stuck due to operations in progress. "Stuck" in this 478249a8c11SDavid Chinner * case is defined as >90% of the items we tried to push 479249a8c11SDavid Chinner * were stuck. 480249a8c11SDavid Chinner * 481249a8c11SDavid Chinner * Backoff a bit more to allow some I/O to complete before 482249a8c11SDavid Chinner * continuing from where we were. 483249a8c11SDavid Chinner */ 484453eac8aSDave Chinner tout = 20; 485453eac8aSDave Chinner } 4861da177e4SLinus Torvalds 4870bf6a5bdSDave Chinner /* There is more to do, requeue us. */ 4880bf6a5bdSDave Chinner queue_delayed_work(xfs_syncd_wq, &ailp->xa_work, 4890bf6a5bdSDave Chinner msecs_to_jiffies(tout)); 4900bf6a5bdSDave Chinner } 4910bf6a5bdSDave Chinner 4920bf6a5bdSDave Chinner /* 4930bf6a5bdSDave Chinner * This routine is called to move the tail of the AIL forward. It does this by 4940bf6a5bdSDave Chinner * trying to flush items in the AIL whose lsns are below the given 4950bf6a5bdSDave Chinner * threshold_lsn. 4960bf6a5bdSDave Chinner * 4970bf6a5bdSDave Chinner * The push is run asynchronously in a workqueue, which means the caller needs 4980bf6a5bdSDave Chinner * to handle waiting on the async flush for space to become available. 4990bf6a5bdSDave Chinner * We don't want to interrupt any push that is in progress, hence we only queue 5000bf6a5bdSDave Chinner * work if we set the pushing bit approriately. 5010bf6a5bdSDave Chinner * 5020bf6a5bdSDave Chinner * We do this unlocked - we only need to know whether there is anything in the 5030bf6a5bdSDave Chinner * AIL at the time we are called. We don't need to access the contents of 5040bf6a5bdSDave Chinner * any of the objects, so the lock is not needed. 5050bf6a5bdSDave Chinner */ 5060bf6a5bdSDave Chinner void 5070bf6a5bdSDave Chinner xfs_trans_ail_push( 5080bf6a5bdSDave Chinner struct xfs_ail *ailp, 5090bf6a5bdSDave Chinner xfs_lsn_t threshold_lsn) 5100bf6a5bdSDave Chinner { 5110bf6a5bdSDave Chinner xfs_log_item_t *lip; 5120bf6a5bdSDave Chinner 5130bf6a5bdSDave Chinner lip = xfs_ail_min(ailp); 5140bf6a5bdSDave Chinner if (!lip || XFS_FORCED_SHUTDOWN(ailp->xa_mount) || 5150bf6a5bdSDave Chinner XFS_LSN_CMP(threshold_lsn, ailp->xa_target) <= 0) 5160bf6a5bdSDave Chinner return; 5170bf6a5bdSDave Chinner 5180bf6a5bdSDave Chinner /* 5190bf6a5bdSDave Chinner * Ensure that the new target is noticed in push code before it clears 5200bf6a5bdSDave Chinner * the XFS_AIL_PUSHING_BIT. 5210bf6a5bdSDave Chinner */ 5220bf6a5bdSDave Chinner smp_wmb(); 5230bf6a5bdSDave Chinner ailp->xa_target = threshold_lsn; 5240bf6a5bdSDave Chinner if (!test_and_set_bit(XFS_AIL_PUSHING_BIT, &ailp->xa_flags)) 5250bf6a5bdSDave Chinner queue_delayed_work(xfs_syncd_wq, &ailp->xa_work, 0); 5260bf6a5bdSDave Chinner } 5271da177e4SLinus Torvalds 5281da177e4SLinus Torvalds /* 5291da177e4SLinus Torvalds * This is to be called when an item is unlocked that may have 5301da177e4SLinus Torvalds * been in the AIL. It will wake up the first member of the AIL 5311da177e4SLinus Torvalds * wait list if this item's unlocking might allow it to progress. 5321da177e4SLinus Torvalds * If the item is in the AIL, then we need to get the AIL lock 5331da177e4SLinus Torvalds * while doing our checking so we don't race with someone going 5341da177e4SLinus Torvalds * to sleep waiting for this event in xfs_trans_push_ail(). 5351da177e4SLinus Torvalds */ 5361da177e4SLinus Torvalds void 5371da177e4SLinus Torvalds xfs_trans_unlocked_item( 538783a2f65SDavid Chinner struct xfs_ail *ailp, 5391da177e4SLinus Torvalds xfs_log_item_t *lip) 5401da177e4SLinus Torvalds { 5411da177e4SLinus Torvalds xfs_log_item_t *min_lip; 5421da177e4SLinus Torvalds 5431da177e4SLinus Torvalds /* 5441da177e4SLinus Torvalds * If we're forcibly shutting down, we may have 5451da177e4SLinus Torvalds * unlocked log items arbitrarily. The last thing 5461da177e4SLinus Torvalds * we want to do is to move the tail of the log 5471da177e4SLinus Torvalds * over some potentially valid data. 5481da177e4SLinus Torvalds */ 5491da177e4SLinus Torvalds if (!(lip->li_flags & XFS_LI_IN_AIL) || 550783a2f65SDavid Chinner XFS_FORCED_SHUTDOWN(ailp->xa_mount)) { 5511da177e4SLinus Torvalds return; 5521da177e4SLinus Torvalds } 5531da177e4SLinus Torvalds 5541da177e4SLinus Torvalds /* 5551da177e4SLinus Torvalds * This is the one case where we can call into xfs_ail_min() 5561da177e4SLinus Torvalds * without holding the AIL lock because we only care about the 5571da177e4SLinus Torvalds * case where we are at the tail of the AIL. If the object isn't 5581da177e4SLinus Torvalds * at the tail, it doesn't matter what result we get back. This 5591da177e4SLinus Torvalds * is slightly racy because since we were just unlocked, we could 5601da177e4SLinus Torvalds * go to sleep between the call to xfs_ail_min and the call to 5611da177e4SLinus Torvalds * xfs_log_move_tail, have someone else lock us, commit to us disk, 5621da177e4SLinus Torvalds * move us out of the tail of the AIL, and then we wake up. However, 5631da177e4SLinus Torvalds * the call to xfs_log_move_tail() doesn't do anything if there's 5641da177e4SLinus Torvalds * not enough free space to wake people up so we're safe calling it. 5651da177e4SLinus Torvalds */ 566783a2f65SDavid Chinner min_lip = xfs_ail_min(ailp); 5671da177e4SLinus Torvalds 5681da177e4SLinus Torvalds if (min_lip == lip) 569783a2f65SDavid Chinner xfs_log_move_tail(ailp->xa_mount, 1); 5701da177e4SLinus Torvalds } /* xfs_trans_unlocked_item */ 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds /* 5730e57f6a3SDave Chinner * xfs_trans_ail_update - bulk AIL insertion operation. 5740e57f6a3SDave Chinner * 5750e57f6a3SDave Chinner * @xfs_trans_ail_update takes an array of log items that all need to be 5760e57f6a3SDave Chinner * positioned at the same LSN in the AIL. If an item is not in the AIL, it will 5770e57f6a3SDave Chinner * be added. Otherwise, it will be repositioned by removing it and re-adding 5780e57f6a3SDave Chinner * it to the AIL. If we move the first item in the AIL, update the log tail to 5790e57f6a3SDave Chinner * match the new minimum LSN in the AIL. 5800e57f6a3SDave Chinner * 5810e57f6a3SDave Chinner * This function takes the AIL lock once to execute the update operations on 5820e57f6a3SDave Chinner * all the items in the array, and as such should not be called with the AIL 5830e57f6a3SDave Chinner * lock held. As a result, once we have the AIL lock, we need to check each log 5840e57f6a3SDave Chinner * item LSN to confirm it needs to be moved forward in the AIL. 5850e57f6a3SDave Chinner * 5860e57f6a3SDave Chinner * To optimise the insert operation, we delete all the items from the AIL in 5870e57f6a3SDave Chinner * the first pass, moving them into a temporary list, then splice the temporary 5880e57f6a3SDave Chinner * list into the correct position in the AIL. This avoids needing to do an 5890e57f6a3SDave Chinner * insert operation on every item. 5900e57f6a3SDave Chinner * 5910e57f6a3SDave Chinner * This function must be called with the AIL lock held. The lock is dropped 5920e57f6a3SDave Chinner * before returning. 5930e57f6a3SDave Chinner */ 5940e57f6a3SDave Chinner void 5950e57f6a3SDave Chinner xfs_trans_ail_update_bulk( 5960e57f6a3SDave Chinner struct xfs_ail *ailp, 5970e57f6a3SDave Chinner struct xfs_log_item **log_items, 5980e57f6a3SDave Chinner int nr_items, 5990e57f6a3SDave Chinner xfs_lsn_t lsn) __releases(ailp->xa_lock) 6000e57f6a3SDave Chinner { 6010e57f6a3SDave Chinner xfs_log_item_t *mlip; 6020e57f6a3SDave Chinner xfs_lsn_t tail_lsn; 6030e57f6a3SDave Chinner int mlip_changed = 0; 6040e57f6a3SDave Chinner int i; 6050e57f6a3SDave Chinner LIST_HEAD(tmp); 6060e57f6a3SDave Chinner 6070e57f6a3SDave Chinner mlip = xfs_ail_min(ailp); 6080e57f6a3SDave Chinner 6090e57f6a3SDave Chinner for (i = 0; i < nr_items; i++) { 6100e57f6a3SDave Chinner struct xfs_log_item *lip = log_items[i]; 6110e57f6a3SDave Chinner if (lip->li_flags & XFS_LI_IN_AIL) { 6120e57f6a3SDave Chinner /* check if we really need to move the item */ 6130e57f6a3SDave Chinner if (XFS_LSN_CMP(lsn, lip->li_lsn) <= 0) 6140e57f6a3SDave Chinner continue; 6150e57f6a3SDave Chinner 6160e57f6a3SDave Chinner xfs_ail_delete(ailp, lip); 6170e57f6a3SDave Chinner if (mlip == lip) 6180e57f6a3SDave Chinner mlip_changed = 1; 6190e57f6a3SDave Chinner } else { 6200e57f6a3SDave Chinner lip->li_flags |= XFS_LI_IN_AIL; 6210e57f6a3SDave Chinner } 6220e57f6a3SDave Chinner lip->li_lsn = lsn; 6230e57f6a3SDave Chinner list_add(&lip->li_ail, &tmp); 6240e57f6a3SDave Chinner } 6250e57f6a3SDave Chinner 6260e57f6a3SDave Chinner xfs_ail_splice(ailp, &tmp, lsn); 6270e57f6a3SDave Chinner 6280e57f6a3SDave Chinner if (!mlip_changed) { 6290e57f6a3SDave Chinner spin_unlock(&ailp->xa_lock); 6300e57f6a3SDave Chinner return; 6310e57f6a3SDave Chinner } 6320e57f6a3SDave Chinner 6330e57f6a3SDave Chinner /* 6340e57f6a3SDave Chinner * It is not safe to access mlip after the AIL lock is dropped, so we 6350e57f6a3SDave Chinner * must get a copy of li_lsn before we do so. This is especially 6360e57f6a3SDave Chinner * important on 32-bit platforms where accessing and updating 64-bit 6370e57f6a3SDave Chinner * values like li_lsn is not atomic. 6380e57f6a3SDave Chinner */ 6390e57f6a3SDave Chinner mlip = xfs_ail_min(ailp); 6400e57f6a3SDave Chinner tail_lsn = mlip->li_lsn; 6410e57f6a3SDave Chinner spin_unlock(&ailp->xa_lock); 6420e57f6a3SDave Chinner xfs_log_move_tail(ailp->xa_mount, tail_lsn); 6430e57f6a3SDave Chinner } 6440e57f6a3SDave Chinner 6450e57f6a3SDave Chinner /* 64630136832SDave Chinner * xfs_trans_ail_delete_bulk - remove multiple log items from the AIL 64730136832SDave Chinner * 64830136832SDave Chinner * @xfs_trans_ail_delete_bulk takes an array of log items that all need to 64930136832SDave Chinner * removed from the AIL. The caller is already holding the AIL lock, and done 65030136832SDave Chinner * all the checks necessary to ensure the items passed in via @log_items are 65130136832SDave Chinner * ready for deletion. This includes checking that the items are in the AIL. 65230136832SDave Chinner * 65330136832SDave Chinner * For each log item to be removed, unlink it from the AIL, clear the IN_AIL 65430136832SDave Chinner * flag from the item and reset the item's lsn to 0. If we remove the first 65530136832SDave Chinner * item in the AIL, update the log tail to match the new minimum LSN in the 65630136832SDave Chinner * AIL. 65730136832SDave Chinner * 65830136832SDave Chinner * This function will not drop the AIL lock until all items are removed from 65930136832SDave Chinner * the AIL to minimise the amount of lock traffic on the AIL. This does not 66030136832SDave Chinner * greatly increase the AIL hold time, but does significantly reduce the amount 66130136832SDave Chinner * of traffic on the lock, especially during IO completion. 66230136832SDave Chinner * 66330136832SDave Chinner * This function must be called with the AIL lock held. The lock is dropped 66430136832SDave Chinner * before returning. 66530136832SDave Chinner */ 66630136832SDave Chinner void 66730136832SDave Chinner xfs_trans_ail_delete_bulk( 66830136832SDave Chinner struct xfs_ail *ailp, 66930136832SDave Chinner struct xfs_log_item **log_items, 67030136832SDave Chinner int nr_items) __releases(ailp->xa_lock) 67130136832SDave Chinner { 67230136832SDave Chinner xfs_log_item_t *mlip; 67330136832SDave Chinner xfs_lsn_t tail_lsn; 67430136832SDave Chinner int mlip_changed = 0; 67530136832SDave Chinner int i; 67630136832SDave Chinner 67730136832SDave Chinner mlip = xfs_ail_min(ailp); 67830136832SDave Chinner 67930136832SDave Chinner for (i = 0; i < nr_items; i++) { 68030136832SDave Chinner struct xfs_log_item *lip = log_items[i]; 68130136832SDave Chinner if (!(lip->li_flags & XFS_LI_IN_AIL)) { 68230136832SDave Chinner struct xfs_mount *mp = ailp->xa_mount; 68330136832SDave Chinner 68430136832SDave Chinner spin_unlock(&ailp->xa_lock); 68530136832SDave Chinner if (!XFS_FORCED_SHUTDOWN(mp)) { 6866a19d939SDave Chinner xfs_alert_tag(mp, XFS_PTAG_AILDELETE, 68730136832SDave Chinner "%s: attempting to delete a log item that is not in the AIL", 68830136832SDave Chinner __func__); 68930136832SDave Chinner xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); 69030136832SDave Chinner } 69130136832SDave Chinner return; 69230136832SDave Chinner } 69330136832SDave Chinner 69430136832SDave Chinner xfs_ail_delete(ailp, lip); 69530136832SDave Chinner lip->li_flags &= ~XFS_LI_IN_AIL; 69630136832SDave Chinner lip->li_lsn = 0; 69730136832SDave Chinner if (mlip == lip) 69830136832SDave Chinner mlip_changed = 1; 69930136832SDave Chinner } 70030136832SDave Chinner 70130136832SDave Chinner if (!mlip_changed) { 70230136832SDave Chinner spin_unlock(&ailp->xa_lock); 70330136832SDave Chinner return; 70430136832SDave Chinner } 70530136832SDave Chinner 70630136832SDave Chinner /* 70730136832SDave Chinner * It is not safe to access mlip after the AIL lock is dropped, so we 70830136832SDave Chinner * must get a copy of li_lsn before we do so. This is especially 70930136832SDave Chinner * important on 32-bit platforms where accessing and updating 64-bit 71030136832SDave Chinner * values like li_lsn is not atomic. It is possible we've emptied the 71130136832SDave Chinner * AIL here, so if that is the case, pass an LSN of 0 to the tail move. 71230136832SDave Chinner */ 71330136832SDave Chinner mlip = xfs_ail_min(ailp); 71430136832SDave Chinner tail_lsn = mlip ? mlip->li_lsn : 0; 71530136832SDave Chinner spin_unlock(&ailp->xa_lock); 71630136832SDave Chinner xfs_log_move_tail(ailp->xa_mount, tail_lsn); 71730136832SDave Chinner } 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds /* 7201da177e4SLinus Torvalds * The active item list (AIL) is a doubly linked list of log 7211da177e4SLinus Torvalds * items sorted by ascending lsn. The base of the list is 7221da177e4SLinus Torvalds * a forw/back pointer pair embedded in the xfs mount structure. 7231da177e4SLinus Torvalds * The base is initialized with both pointers pointing to the 7241da177e4SLinus Torvalds * base. This case always needs to be distinguished, because 7251da177e4SLinus Torvalds * the base has no lsn to look at. We almost always insert 7261da177e4SLinus Torvalds * at the end of the list, so on inserts we search from the 7271da177e4SLinus Torvalds * end of the list to find where the new item belongs. 7281da177e4SLinus Torvalds */ 7291da177e4SLinus Torvalds 7301da177e4SLinus Torvalds /* 7311da177e4SLinus Torvalds * Initialize the doubly linked list to point only to itself. 7321da177e4SLinus Torvalds */ 733249a8c11SDavid Chinner int 7341da177e4SLinus Torvalds xfs_trans_ail_init( 7351da177e4SLinus Torvalds xfs_mount_t *mp) 7361da177e4SLinus Torvalds { 73782fa9012SDavid Chinner struct xfs_ail *ailp; 73882fa9012SDavid Chinner 73982fa9012SDavid Chinner ailp = kmem_zalloc(sizeof(struct xfs_ail), KM_MAYFAIL); 74082fa9012SDavid Chinner if (!ailp) 74182fa9012SDavid Chinner return ENOMEM; 74282fa9012SDavid Chinner 74382fa9012SDavid Chinner ailp->xa_mount = mp; 74482fa9012SDavid Chinner INIT_LIST_HEAD(&ailp->xa_ail); 745c7e8f268SDavid Chinner spin_lock_init(&ailp->xa_lock); 7460bf6a5bdSDave Chinner INIT_DELAYED_WORK(&ailp->xa_work, xfs_ail_worker); 74727d8d5feSDavid Chinner mp->m_ail = ailp; 74827d8d5feSDavid Chinner return 0; 749249a8c11SDavid Chinner } 750249a8c11SDavid Chinner 751249a8c11SDavid Chinner void 752249a8c11SDavid Chinner xfs_trans_ail_destroy( 753249a8c11SDavid Chinner xfs_mount_t *mp) 754249a8c11SDavid Chinner { 75582fa9012SDavid Chinner struct xfs_ail *ailp = mp->m_ail; 75682fa9012SDavid Chinner 7570bf6a5bdSDave Chinner cancel_delayed_work_sync(&ailp->xa_work); 75882fa9012SDavid Chinner kmem_free(ailp); 7591da177e4SLinus Torvalds } 760