17336d0e6SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 2b3b94faaSDavid Teigland /* 3b3b94faaSDavid Teigland * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 4da6dd40dSBob Peterson * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. 5b3b94faaSDavid Teigland */ 6b3b94faaSDavid Teigland 7b3b94faaSDavid Teigland #include <linux/sched.h> 8b3b94faaSDavid Teigland #include <linux/slab.h> 9b3b94faaSDavid Teigland #include <linux/spinlock.h> 10b3b94faaSDavid Teigland #include <linux/completion.h> 11b3b94faaSDavid Teigland #include <linux/buffer_head.h> 125c676f6dSSteven Whitehouse #include <linux/gfs2_ondisk.h> 1371b86f56SSteven Whitehouse #include <linux/crc32.h> 14c1696fb8SBob Peterson #include <linux/crc32c.h> 15a25311c8SSteven Whitehouse #include <linux/delay.h> 16ec69b188SSteven Whitehouse #include <linux/kthread.h> 17ec69b188SSteven Whitehouse #include <linux/freezer.h> 18254db57fSSteven Whitehouse #include <linux/bio.h> 19885bcecaSSteven Whitehouse #include <linux/blkdev.h> 204667a0ecSSteven Whitehouse #include <linux/writeback.h> 214a36d08dSBob Peterson #include <linux/list_sort.h> 22b3b94faaSDavid Teigland 23b3b94faaSDavid Teigland #include "gfs2.h" 245c676f6dSSteven Whitehouse #include "incore.h" 25b3b94faaSDavid Teigland #include "bmap.h" 26b3b94faaSDavid Teigland #include "glock.h" 27b3b94faaSDavid Teigland #include "log.h" 28b3b94faaSDavid Teigland #include "lops.h" 29b3b94faaSDavid Teigland #include "meta_io.h" 305c676f6dSSteven Whitehouse #include "util.h" 3171b86f56SSteven Whitehouse #include "dir.h" 3263997775SSteven Whitehouse #include "trace_gfs2.h" 33b839dadaSBob Peterson #include "trans.h" 34b3b94faaSDavid Teigland 35feed98a8SBob Peterson static void gfs2_log_shutdown(struct gfs2_sbd *sdp); 36feed98a8SBob Peterson 37b3b94faaSDavid Teigland /** 38b3b94faaSDavid Teigland * gfs2_struct2blk - compute stuff 39b3b94faaSDavid Teigland * @sdp: the filesystem 40b3b94faaSDavid Teigland * @nstruct: the number of structures 41b3b94faaSDavid Teigland * 42b3b94faaSDavid Teigland * Compute the number of log descriptor blocks needed to hold a certain number 43b3b94faaSDavid Teigland * of structures of a certain size. 44b3b94faaSDavid Teigland * 45b3b94faaSDavid Teigland * Returns: the number of blocks needed (minimum is always 1) 46b3b94faaSDavid Teigland */ 47b3b94faaSDavid Teigland 482e9eeaa1SBob Peterson unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct) 49b3b94faaSDavid Teigland { 50b3b94faaSDavid Teigland unsigned int blks; 51b3b94faaSDavid Teigland unsigned int first, second; 52b3b94faaSDavid Teigland 536188e877SAndreas Gruenbacher /* The initial struct gfs2_log_descriptor block */ 54b3b94faaSDavid Teigland blks = 1; 552e9eeaa1SBob Peterson first = sdp->sd_ldptrs; 56b3b94faaSDavid Teigland 57b3b94faaSDavid Teigland if (nstruct > first) { 586188e877SAndreas Gruenbacher /* Subsequent struct gfs2_meta_header blocks */ 592e9eeaa1SBob Peterson second = sdp->sd_inptrs; 605c676f6dSSteven Whitehouse blks += DIV_ROUND_UP(nstruct - first, second); 61b3b94faaSDavid Teigland } 62b3b94faaSDavid Teigland 63b3b94faaSDavid Teigland return blks; 64b3b94faaSDavid Teigland } 65b3b94faaSDavid Teigland 66ddacfaf7SSteven Whitehouse /** 671e1a3d03SSteven Whitehouse * gfs2_remove_from_ail - Remove an entry from the ail lists, updating counters 681e1a3d03SSteven Whitehouse * @bd: The gfs2_bufdata to remove 691e1a3d03SSteven Whitehouse * 70c618e87aSSteven Whitehouse * The ail lock _must_ be held when calling this function 711e1a3d03SSteven Whitehouse * 721e1a3d03SSteven Whitehouse */ 731e1a3d03SSteven Whitehouse 7468942870SBob Peterson void gfs2_remove_from_ail(struct gfs2_bufdata *bd) 751e1a3d03SSteven Whitehouse { 7616ca9412SBenjamin Marzinski bd->bd_tr = NULL; 771ad38c43SSteven Whitehouse list_del_init(&bd->bd_ail_st_list); 781ad38c43SSteven Whitehouse list_del_init(&bd->bd_ail_gl_list); 791e1a3d03SSteven Whitehouse atomic_dec(&bd->bd_gl->gl_ail_count); 801e1a3d03SSteven Whitehouse brelse(bd->bd_bh); 811e1a3d03SSteven Whitehouse } 821e1a3d03SSteven Whitehouse 831e1a3d03SSteven Whitehouse /** 84c551f66cSLee Jones * gfs2_ail1_start_one - Start I/O on a transaction 85c551f66cSLee Jones * @sdp: The superblock 864667a0ecSSteven Whitehouse * @wbc: The writeback control structure 87c551f66cSLee Jones * @tr: The transaction to start I/O on 88c551f66cSLee Jones * @plug: The block plug currently active 89ddacfaf7SSteven Whitehouse */ 90ddacfaf7SSteven Whitehouse 914f1de018SSteven Whitehouse static int gfs2_ail1_start_one(struct gfs2_sbd *sdp, 924667a0ecSSteven Whitehouse struct writeback_control *wbc, 9317d77684SBob Peterson struct gfs2_trans *tr, struct blk_plug *plug) 94d6a079e8SDave Chinner __releases(&sdp->sd_ail_lock) 95d6a079e8SDave Chinner __acquires(&sdp->sd_ail_lock) 96ddacfaf7SSteven Whitehouse { 975ac048bbSSteven Whitehouse struct gfs2_glock *gl = NULL; 984667a0ecSSteven Whitehouse struct address_space *mapping; 99ddacfaf7SSteven Whitehouse struct gfs2_bufdata *bd, *s; 100ddacfaf7SSteven Whitehouse struct buffer_head *bh; 101b1676cbbSBob Peterson int ret = 0; 102ddacfaf7SSteven Whitehouse 10316ca9412SBenjamin Marzinski list_for_each_entry_safe_reverse(bd, s, &tr->tr_ail1_list, bd_ail_st_list) { 104ddacfaf7SSteven Whitehouse bh = bd->bd_bh; 105ddacfaf7SSteven Whitehouse 10616ca9412SBenjamin Marzinski gfs2_assert(sdp, bd->bd_tr == tr); 107ddacfaf7SSteven Whitehouse 108ddacfaf7SSteven Whitehouse if (!buffer_busy(bh)) { 10930fe70a8SBob Peterson if (buffer_uptodate(bh)) { 11030fe70a8SBob Peterson list_move(&bd->bd_ail_st_list, 11130fe70a8SBob Peterson &tr->tr_ail2_list); 11230fe70a8SBob Peterson continue; 11330fe70a8SBob Peterson } 114036330c9SBob Peterson if (!cmpxchg(&sdp->sd_log_error, 0, -EIO)) { 115ddacfaf7SSteven Whitehouse gfs2_io_error_bh(sdp, bh); 11669511080SBob Peterson gfs2_withdraw_delayed(sdp); 1179e1a9ecdSAndreas Gruenbacher } 118ddacfaf7SSteven Whitehouse } 119ddacfaf7SSteven Whitehouse 12030fe70a8SBob Peterson if (gfs2_withdrawn(sdp)) { 12130fe70a8SBob Peterson gfs2_remove_from_ail(bd); 12230fe70a8SBob Peterson continue; 12330fe70a8SBob Peterson } 124ddacfaf7SSteven Whitehouse if (!buffer_dirty(bh)) 125ddacfaf7SSteven Whitehouse continue; 1265ac048bbSSteven Whitehouse if (gl == bd->bd_gl) 1275ac048bbSSteven Whitehouse continue; 1285ac048bbSSteven Whitehouse gl = bd->bd_gl; 12916ca9412SBenjamin Marzinski list_move(&bd->bd_ail_st_list, &tr->tr_ail1_list); 1304667a0ecSSteven Whitehouse mapping = bh->b_page->mapping; 1314f1de018SSteven Whitehouse if (!mapping) 1324f1de018SSteven Whitehouse continue; 133d6a079e8SDave Chinner spin_unlock(&sdp->sd_ail_lock); 134*b2b0a5e9SChristoph Hellwig ret = filemap_fdatawrite_wbc(mapping, wbc); 13517d77684SBob Peterson if (need_resched()) { 13617d77684SBob Peterson blk_finish_plug(plug); 13717d77684SBob Peterson cond_resched(); 13817d77684SBob Peterson blk_start_plug(plug); 13917d77684SBob Peterson } 140d6a079e8SDave Chinner spin_lock(&sdp->sd_ail_lock); 1414e79e3f0SBob Peterson if (ret == -ENODATA) /* if a jdata write into a new hole */ 1424e79e3f0SBob Peterson ret = 0; /* ignore it */ 143b1676cbbSBob Peterson if (ret || wbc->nr_to_write <= 0) 144ddacfaf7SSteven Whitehouse break; 145b1676cbbSBob Peterson return -EBUSY; 146ddacfaf7SSteven Whitehouse } 1474f1de018SSteven Whitehouse 148b1676cbbSBob Peterson return ret; 1494667a0ecSSteven Whitehouse } 1504667a0ecSSteven Whitehouse 1519592ea80SBob Peterson static void dump_ail_list(struct gfs2_sbd *sdp) 1529592ea80SBob Peterson { 1539592ea80SBob Peterson struct gfs2_trans *tr; 1549592ea80SBob Peterson struct gfs2_bufdata *bd; 1559592ea80SBob Peterson struct buffer_head *bh; 1569592ea80SBob Peterson 1579592ea80SBob Peterson list_for_each_entry_reverse(tr, &sdp->sd_ail1_list, tr_list) { 1589592ea80SBob Peterson list_for_each_entry_reverse(bd, &tr->tr_ail1_list, 1599592ea80SBob Peterson bd_ail_st_list) { 1609592ea80SBob Peterson bh = bd->bd_bh; 1619592ea80SBob Peterson fs_err(sdp, "bd %p: blk:0x%llx bh=%p ", bd, 1629592ea80SBob Peterson (unsigned long long)bd->bd_blkno, bh); 1639592ea80SBob Peterson if (!bh) { 1649592ea80SBob Peterson fs_err(sdp, "\n"); 1659592ea80SBob Peterson continue; 1669592ea80SBob Peterson } 1679592ea80SBob Peterson fs_err(sdp, "0x%llx up2:%d dirt:%d lkd:%d req:%d " 1689592ea80SBob Peterson "map:%d new:%d ar:%d aw:%d delay:%d " 1699592ea80SBob Peterson "io err:%d unwritten:%d dfr:%d pin:%d esc:%d\n", 1709592ea80SBob Peterson (unsigned long long)bh->b_blocknr, 1719592ea80SBob Peterson buffer_uptodate(bh), buffer_dirty(bh), 1729592ea80SBob Peterson buffer_locked(bh), buffer_req(bh), 1739592ea80SBob Peterson buffer_mapped(bh), buffer_new(bh), 1749592ea80SBob Peterson buffer_async_read(bh), buffer_async_write(bh), 1759592ea80SBob Peterson buffer_delay(bh), buffer_write_io_error(bh), 1769592ea80SBob Peterson buffer_unwritten(bh), 1779592ea80SBob Peterson buffer_defer_completion(bh), 1789592ea80SBob Peterson buffer_pinned(bh), buffer_escaped(bh)); 1799592ea80SBob Peterson } 1809592ea80SBob Peterson } 1819592ea80SBob Peterson } 1824667a0ecSSteven Whitehouse 1834667a0ecSSteven Whitehouse /** 1844667a0ecSSteven Whitehouse * gfs2_ail1_flush - start writeback of some ail1 entries 1854667a0ecSSteven Whitehouse * @sdp: The super block 1864667a0ecSSteven Whitehouse * @wbc: The writeback control structure 1874667a0ecSSteven Whitehouse * 1884667a0ecSSteven Whitehouse * Writes back some ail1 entries, according to the limits in the 1894667a0ecSSteven Whitehouse * writeback control structure 1904667a0ecSSteven Whitehouse */ 1914667a0ecSSteven Whitehouse 1924667a0ecSSteven Whitehouse void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc) 1934667a0ecSSteven Whitehouse { 1944667a0ecSSteven Whitehouse struct list_head *head = &sdp->sd_ail1_list; 19516ca9412SBenjamin Marzinski struct gfs2_trans *tr; 196885bcecaSSteven Whitehouse struct blk_plug plug; 19775b46c43SBob Peterson int ret; 1989592ea80SBob Peterson unsigned long flush_start = jiffies; 1994667a0ecSSteven Whitehouse 200c83ae9caSSteven Whitehouse trace_gfs2_ail_flush(sdp, wbc, 1); 201885bcecaSSteven Whitehouse blk_start_plug(&plug); 2024667a0ecSSteven Whitehouse spin_lock(&sdp->sd_ail_lock); 2034f1de018SSteven Whitehouse restart: 20475b46c43SBob Peterson ret = 0; 2059592ea80SBob Peterson if (time_after(jiffies, flush_start + (HZ * 600))) { 206d5dc3d96SBob Peterson fs_err(sdp, "Error: In %s for ten minutes! t=%d\n", 207d5dc3d96SBob Peterson __func__, current->journal_info ? 1 : 0); 2089592ea80SBob Peterson dump_ail_list(sdp); 2099592ea80SBob Peterson goto out; 2109592ea80SBob Peterson } 21116ca9412SBenjamin Marzinski list_for_each_entry_reverse(tr, head, tr_list) { 2124667a0ecSSteven Whitehouse if (wbc->nr_to_write <= 0) 2134667a0ecSSteven Whitehouse break; 21417d77684SBob Peterson ret = gfs2_ail1_start_one(sdp, wbc, tr, &plug); 215b1676cbbSBob Peterson if (ret) { 216b1676cbbSBob Peterson if (ret == -EBUSY) 2174f1de018SSteven Whitehouse goto restart; 218b1676cbbSBob Peterson break; 219b1676cbbSBob Peterson } 2204667a0ecSSteven Whitehouse } 2219592ea80SBob Peterson out: 2224667a0ecSSteven Whitehouse spin_unlock(&sdp->sd_ail_lock); 223885bcecaSSteven Whitehouse blk_finish_plug(&plug); 22449003128SBob Peterson if (ret) { 225*b2b0a5e9SChristoph Hellwig gfs2_lm(sdp, "gfs2_ail1_start_one returned: %d\n", ret); 226badb55ecSAndreas Gruenbacher gfs2_withdraw(sdp); 22749003128SBob Peterson } 228c83ae9caSSteven Whitehouse trace_gfs2_ail_flush(sdp, wbc, 0); 2294667a0ecSSteven Whitehouse } 2304667a0ecSSteven Whitehouse 2314667a0ecSSteven Whitehouse /** 2324667a0ecSSteven Whitehouse * gfs2_ail1_start - start writeback of all ail1 entries 2334667a0ecSSteven Whitehouse * @sdp: The superblock 2344667a0ecSSteven Whitehouse */ 2354667a0ecSSteven Whitehouse 2364667a0ecSSteven Whitehouse static void gfs2_ail1_start(struct gfs2_sbd *sdp) 2374667a0ecSSteven Whitehouse { 2384667a0ecSSteven Whitehouse struct writeback_control wbc = { 2394667a0ecSSteven Whitehouse .sync_mode = WB_SYNC_NONE, 2404667a0ecSSteven Whitehouse .nr_to_write = LONG_MAX, 2414667a0ecSSteven Whitehouse .range_start = 0, 2424667a0ecSSteven Whitehouse .range_end = LLONG_MAX, 2434667a0ecSSteven Whitehouse }; 2444667a0ecSSteven Whitehouse 2454667a0ecSSteven Whitehouse return gfs2_ail1_flush(sdp, &wbc); 246ddacfaf7SSteven Whitehouse } 247ddacfaf7SSteven Whitehouse 2485cb738b5SAndreas Gruenbacher static void gfs2_log_update_flush_tail(struct gfs2_sbd *sdp) 2495cb738b5SAndreas Gruenbacher { 2505cb738b5SAndreas Gruenbacher unsigned int new_flush_tail = sdp->sd_log_head; 2515cb738b5SAndreas Gruenbacher struct gfs2_trans *tr; 2525cb738b5SAndreas Gruenbacher 2535cb738b5SAndreas Gruenbacher if (!list_empty(&sdp->sd_ail1_list)) { 2545cb738b5SAndreas Gruenbacher tr = list_last_entry(&sdp->sd_ail1_list, 2555cb738b5SAndreas Gruenbacher struct gfs2_trans, tr_list); 2565cb738b5SAndreas Gruenbacher new_flush_tail = tr->tr_first; 2575cb738b5SAndreas Gruenbacher } 2585cb738b5SAndreas Gruenbacher sdp->sd_log_flush_tail = new_flush_tail; 2595cb738b5SAndreas Gruenbacher } 2605cb738b5SAndreas Gruenbacher 2615cb738b5SAndreas Gruenbacher static void gfs2_log_update_head(struct gfs2_sbd *sdp) 2625cb738b5SAndreas Gruenbacher { 2635cb738b5SAndreas Gruenbacher unsigned int new_head = sdp->sd_log_flush_head; 2645cb738b5SAndreas Gruenbacher 2655cb738b5SAndreas Gruenbacher if (sdp->sd_log_flush_tail == sdp->sd_log_head) 2665cb738b5SAndreas Gruenbacher sdp->sd_log_flush_tail = new_head; 2675cb738b5SAndreas Gruenbacher sdp->sd_log_head = new_head; 2685cb738b5SAndreas Gruenbacher } 2695cb738b5SAndreas Gruenbacher 270c551f66cSLee Jones /* 27176fce654SAndreas Gruenbacher * gfs2_ail_empty_tr - empty one of the ail lists of a transaction 27276fce654SAndreas Gruenbacher */ 27376fce654SAndreas Gruenbacher 27476fce654SAndreas Gruenbacher static void gfs2_ail_empty_tr(struct gfs2_sbd *sdp, struct gfs2_trans *tr, 27576fce654SAndreas Gruenbacher struct list_head *head) 27676fce654SAndreas Gruenbacher { 27776fce654SAndreas Gruenbacher struct gfs2_bufdata *bd; 27876fce654SAndreas Gruenbacher 27976fce654SAndreas Gruenbacher while (!list_empty(head)) { 28076fce654SAndreas Gruenbacher bd = list_first_entry(head, struct gfs2_bufdata, 28176fce654SAndreas Gruenbacher bd_ail_st_list); 28276fce654SAndreas Gruenbacher gfs2_assert(sdp, bd->bd_tr == tr); 28376fce654SAndreas Gruenbacher gfs2_remove_from_ail(bd); 28476fce654SAndreas Gruenbacher } 28576fce654SAndreas Gruenbacher } 28676fce654SAndreas Gruenbacher 287ddacfaf7SSteven Whitehouse /** 288ddacfaf7SSteven Whitehouse * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced 289ddacfaf7SSteven Whitehouse * @sdp: the filesystem 2905e4c7632SBob Peterson * @tr: the transaction 2915e4c7632SBob Peterson * @max_revokes: If nonzero, issue revokes for the bd items for written buffers 292ddacfaf7SSteven Whitehouse * 29336c78309SBob Peterson * returns: the transaction's count of remaining active items 294ddacfaf7SSteven Whitehouse */ 295ddacfaf7SSteven Whitehouse 29636c78309SBob Peterson static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr, 2975e4c7632SBob Peterson int *max_revokes) 298ddacfaf7SSteven Whitehouse { 299ddacfaf7SSteven Whitehouse struct gfs2_bufdata *bd, *s; 300ddacfaf7SSteven Whitehouse struct buffer_head *bh; 30136c78309SBob Peterson int active_count = 0; 302ddacfaf7SSteven Whitehouse 30316ca9412SBenjamin Marzinski list_for_each_entry_safe_reverse(bd, s, &tr->tr_ail1_list, 304ddacfaf7SSteven Whitehouse bd_ail_st_list) { 305ddacfaf7SSteven Whitehouse bh = bd->bd_bh; 30616ca9412SBenjamin Marzinski gfs2_assert(sdp, bd->bd_tr == tr); 307036330c9SBob Peterson /* 308036330c9SBob Peterson * If another process flagged an io error, e.g. writing to the 309036330c9SBob Peterson * journal, error all other bhs and move them off the ail1 to 310036330c9SBob Peterson * prevent a tight loop when unmount tries to flush ail1, 311036330c9SBob Peterson * regardless of whether they're still busy. If no outside 312036330c9SBob Peterson * errors were found and the buffer is busy, move to the next. 313036330c9SBob Peterson * If the ail buffer is not busy and caught an error, flag it 314036330c9SBob Peterson * for others. 315036330c9SBob Peterson */ 31636c78309SBob Peterson if (!sdp->sd_log_error && buffer_busy(bh)) { 31736c78309SBob Peterson active_count++; 318ddacfaf7SSteven Whitehouse continue; 31936c78309SBob Peterson } 320b524abccSBob Peterson if (!buffer_uptodate(bh) && 321036330c9SBob Peterson !cmpxchg(&sdp->sd_log_error, 0, -EIO)) { 322ddacfaf7SSteven Whitehouse gfs2_io_error_bh(sdp, bh); 32369511080SBob Peterson gfs2_withdraw_delayed(sdp); 3249e1a9ecdSAndreas Gruenbacher } 3255e4c7632SBob Peterson /* 3265e4c7632SBob Peterson * If we have space for revokes and the bd is no longer on any 3275e4c7632SBob Peterson * buf list, we can just add a revoke for it immediately and 3285e4c7632SBob Peterson * avoid having to put it on the ail2 list, where it would need 3295e4c7632SBob Peterson * to be revoked later. 3305e4c7632SBob Peterson */ 3315e4c7632SBob Peterson if (*max_revokes && list_empty(&bd->bd_list)) { 3325e4c7632SBob Peterson gfs2_add_revoke(sdp, bd); 3335e4c7632SBob Peterson (*max_revokes)--; 3345e4c7632SBob Peterson continue; 3355e4c7632SBob Peterson } 33616ca9412SBenjamin Marzinski list_move(&bd->bd_ail_st_list, &tr->tr_ail2_list); 337ddacfaf7SSteven Whitehouse } 33836c78309SBob Peterson return active_count; 339ddacfaf7SSteven Whitehouse } 340ddacfaf7SSteven Whitehouse 3414667a0ecSSteven Whitehouse /** 3424667a0ecSSteven Whitehouse * gfs2_ail1_empty - Try to empty the ail1 lists 3434667a0ecSSteven Whitehouse * @sdp: The superblock 3445e4c7632SBob Peterson * @max_revokes: If non-zero, add revokes where appropriate 3454667a0ecSSteven Whitehouse * 3464667a0ecSSteven Whitehouse * Tries to empty the ail1 lists, starting with the oldest first 3474667a0ecSSteven Whitehouse */ 348b3b94faaSDavid Teigland 3495e4c7632SBob Peterson static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int max_revokes) 350b3b94faaSDavid Teigland { 35116ca9412SBenjamin Marzinski struct gfs2_trans *tr, *s; 3525d054964SBenjamin Marzinski int oldest_tr = 1; 353b3b94faaSDavid Teigland int ret; 354b3b94faaSDavid Teigland 355d6a079e8SDave Chinner spin_lock(&sdp->sd_ail_lock); 35616ca9412SBenjamin Marzinski list_for_each_entry_safe_reverse(tr, s, &sdp->sd_ail1_list, tr_list) { 35736c78309SBob Peterson if (!gfs2_ail1_empty_one(sdp, tr, &max_revokes) && oldest_tr) 35816ca9412SBenjamin Marzinski list_move(&tr->tr_list, &sdp->sd_ail2_list); 3594667a0ecSSteven Whitehouse else 3605d054964SBenjamin Marzinski oldest_tr = 0; 361b3b94faaSDavid Teigland } 3625cb738b5SAndreas Gruenbacher gfs2_log_update_flush_tail(sdp); 363b3b94faaSDavid Teigland ret = list_empty(&sdp->sd_ail1_list); 364d6a079e8SDave Chinner spin_unlock(&sdp->sd_ail_lock); 365b3b94faaSDavid Teigland 36669511080SBob Peterson if (test_bit(SDF_WITHDRAWING, &sdp->sd_flags)) { 367badb55ecSAndreas Gruenbacher gfs2_lm(sdp, "fatal: I/O error(s)\n"); 368badb55ecSAndreas Gruenbacher gfs2_withdraw(sdp); 369badb55ecSAndreas Gruenbacher } 3709e1a9ecdSAndreas Gruenbacher 371b3b94faaSDavid Teigland return ret; 372b3b94faaSDavid Teigland } 373b3b94faaSDavid Teigland 37426b06a69SSteven Whitehouse static void gfs2_ail1_wait(struct gfs2_sbd *sdp) 37526b06a69SSteven Whitehouse { 37616ca9412SBenjamin Marzinski struct gfs2_trans *tr; 37726b06a69SSteven Whitehouse struct gfs2_bufdata *bd; 37826b06a69SSteven Whitehouse struct buffer_head *bh; 37926b06a69SSteven Whitehouse 38026b06a69SSteven Whitehouse spin_lock(&sdp->sd_ail_lock); 38116ca9412SBenjamin Marzinski list_for_each_entry_reverse(tr, &sdp->sd_ail1_list, tr_list) { 38216ca9412SBenjamin Marzinski list_for_each_entry(bd, &tr->tr_ail1_list, bd_ail_st_list) { 38326b06a69SSteven Whitehouse bh = bd->bd_bh; 38426b06a69SSteven Whitehouse if (!buffer_locked(bh)) 38526b06a69SSteven Whitehouse continue; 38626b06a69SSteven Whitehouse get_bh(bh); 38726b06a69SSteven Whitehouse spin_unlock(&sdp->sd_ail_lock); 38826b06a69SSteven Whitehouse wait_on_buffer(bh); 38926b06a69SSteven Whitehouse brelse(bh); 39026b06a69SSteven Whitehouse return; 39126b06a69SSteven Whitehouse } 39226b06a69SSteven Whitehouse } 39326b06a69SSteven Whitehouse spin_unlock(&sdp->sd_ail_lock); 39426b06a69SSteven Whitehouse } 395ddacfaf7SSteven Whitehouse 3966e80674aSAndreas Gruenbacher static void __ail2_empty(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 397ddacfaf7SSteven Whitehouse { 3982ca0c2fbSBob Peterson gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail2_list); 39916ca9412SBenjamin Marzinski list_del(&tr->tr_list); 40016ca9412SBenjamin Marzinski gfs2_assert_warn(sdp, list_empty(&tr->tr_ail1_list)); 40116ca9412SBenjamin Marzinski gfs2_assert_warn(sdp, list_empty(&tr->tr_ail2_list)); 402b839dadaSBob Peterson gfs2_trans_free(sdp, tr); 403b3b94faaSDavid Teigland } 404b3b94faaSDavid Teigland 4056e80674aSAndreas Gruenbacher static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) 4066e80674aSAndreas Gruenbacher { 4076e80674aSAndreas Gruenbacher struct list_head *ail2_list = &sdp->sd_ail2_list; 4086e80674aSAndreas Gruenbacher unsigned int old_tail = sdp->sd_log_tail; 4096e80674aSAndreas Gruenbacher struct gfs2_trans *tr, *safe; 4106e80674aSAndreas Gruenbacher 4116e80674aSAndreas Gruenbacher spin_lock(&sdp->sd_ail_lock); 4126e80674aSAndreas Gruenbacher if (old_tail <= new_tail) { 4136e80674aSAndreas Gruenbacher list_for_each_entry_safe(tr, safe, ail2_list, tr_list) { 4146e80674aSAndreas Gruenbacher if (old_tail <= tr->tr_first && tr->tr_first < new_tail) 4156e80674aSAndreas Gruenbacher __ail2_empty(sdp, tr); 4166e80674aSAndreas Gruenbacher } 4176e80674aSAndreas Gruenbacher } else { 4186e80674aSAndreas Gruenbacher list_for_each_entry_safe(tr, safe, ail2_list, tr_list) { 4196e80674aSAndreas Gruenbacher if (old_tail <= tr->tr_first || tr->tr_first < new_tail) 4206e80674aSAndreas Gruenbacher __ail2_empty(sdp, tr); 4216e80674aSAndreas Gruenbacher } 4226e80674aSAndreas Gruenbacher } 423d6a079e8SDave Chinner spin_unlock(&sdp->sd_ail_lock); 424b3b94faaSDavid Teigland } 425b3b94faaSDavid Teigland 426b3b94faaSDavid Teigland /** 427f3708fb5SAndreas Gruenbacher * gfs2_log_is_empty - Check if the log is empty 428f3708fb5SAndreas Gruenbacher * @sdp: The GFS2 superblock 429f3708fb5SAndreas Gruenbacher */ 430f3708fb5SAndreas Gruenbacher 431f3708fb5SAndreas Gruenbacher bool gfs2_log_is_empty(struct gfs2_sbd *sdp) { 432f3708fb5SAndreas Gruenbacher return atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks; 433f3708fb5SAndreas Gruenbacher } 434f3708fb5SAndreas Gruenbacher 4352129b428SAndreas Gruenbacher static bool __gfs2_log_try_reserve_revokes(struct gfs2_sbd *sdp, unsigned int revokes) 4362129b428SAndreas Gruenbacher { 4372129b428SAndreas Gruenbacher unsigned int available; 4382129b428SAndreas Gruenbacher 4392129b428SAndreas Gruenbacher available = atomic_read(&sdp->sd_log_revokes_available); 4402129b428SAndreas Gruenbacher while (available >= revokes) { 4412129b428SAndreas Gruenbacher if (atomic_try_cmpxchg(&sdp->sd_log_revokes_available, 4422129b428SAndreas Gruenbacher &available, available - revokes)) 4432129b428SAndreas Gruenbacher return true; 4442129b428SAndreas Gruenbacher } 4452129b428SAndreas Gruenbacher return false; 4462129b428SAndreas Gruenbacher } 4472129b428SAndreas Gruenbacher 4482129b428SAndreas Gruenbacher /** 4492129b428SAndreas Gruenbacher * gfs2_log_release_revokes - Release a given number of revokes 4502129b428SAndreas Gruenbacher * @sdp: The GFS2 superblock 4512129b428SAndreas Gruenbacher * @revokes: The number of revokes to release 4522129b428SAndreas Gruenbacher * 4532129b428SAndreas Gruenbacher * sdp->sd_log_flush_lock must be held. 4542129b428SAndreas Gruenbacher */ 4552129b428SAndreas Gruenbacher void gfs2_log_release_revokes(struct gfs2_sbd *sdp, unsigned int revokes) 4562129b428SAndreas Gruenbacher { 4572129b428SAndreas Gruenbacher if (revokes) 4582129b428SAndreas Gruenbacher atomic_add(revokes, &sdp->sd_log_revokes_available); 4592129b428SAndreas Gruenbacher } 4602129b428SAndreas Gruenbacher 461f3708fb5SAndreas Gruenbacher /** 46224972557SBenjamin Marzinski * gfs2_log_release - Release a given number of log blocks 46324972557SBenjamin Marzinski * @sdp: The GFS2 superblock 46424972557SBenjamin Marzinski * @blks: The number of blocks 46524972557SBenjamin Marzinski * 46624972557SBenjamin Marzinski */ 46724972557SBenjamin Marzinski 46824972557SBenjamin Marzinski void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) 46924972557SBenjamin Marzinski { 47024972557SBenjamin Marzinski atomic_add(blks, &sdp->sd_log_blks_free); 47124972557SBenjamin Marzinski trace_gfs2_log_blocks(sdp, blks); 47224972557SBenjamin Marzinski gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= 47324972557SBenjamin Marzinski sdp->sd_jdesc->jd_blocks); 4745ae8fff8SAndreas Gruenbacher if (atomic_read(&sdp->sd_log_blks_needed)) 4755ae8fff8SAndreas Gruenbacher wake_up(&sdp->sd_log_waitq); 47624972557SBenjamin Marzinski } 47724972557SBenjamin Marzinski 47824972557SBenjamin Marzinski /** 479fe3e3976SAndreas Gruenbacher * __gfs2_log_try_reserve - Try to make a log reservation 480b3b94faaSDavid Teigland * @sdp: The GFS2 superblock 481b3b94faaSDavid Teigland * @blks: The number of blocks to reserve 482fe3e3976SAndreas Gruenbacher * @taboo_blks: The number of blocks to leave free 483b3b94faaSDavid Teigland * 484fe3e3976SAndreas Gruenbacher * Try to do the same as __gfs2_log_reserve(), but fail if no more log 485fe3e3976SAndreas Gruenbacher * space is immediately available. 486fe3e3976SAndreas Gruenbacher */ 487fe3e3976SAndreas Gruenbacher static bool __gfs2_log_try_reserve(struct gfs2_sbd *sdp, unsigned int blks, 488fe3e3976SAndreas Gruenbacher unsigned int taboo_blks) 489fe3e3976SAndreas Gruenbacher { 490fe3e3976SAndreas Gruenbacher unsigned wanted = blks + taboo_blks; 491fe3e3976SAndreas Gruenbacher unsigned int free_blocks; 492fe3e3976SAndreas Gruenbacher 493fe3e3976SAndreas Gruenbacher free_blocks = atomic_read(&sdp->sd_log_blks_free); 494fe3e3976SAndreas Gruenbacher while (free_blocks >= wanted) { 495fe3e3976SAndreas Gruenbacher if (atomic_try_cmpxchg(&sdp->sd_log_blks_free, &free_blocks, 496fe3e3976SAndreas Gruenbacher free_blocks - blks)) { 497fe3e3976SAndreas Gruenbacher trace_gfs2_log_blocks(sdp, -blks); 498fe3e3976SAndreas Gruenbacher return true; 499fe3e3976SAndreas Gruenbacher } 500fe3e3976SAndreas Gruenbacher } 501fe3e3976SAndreas Gruenbacher return false; 502fe3e3976SAndreas Gruenbacher } 503fe3e3976SAndreas Gruenbacher 504fe3e3976SAndreas Gruenbacher /** 505fe3e3976SAndreas Gruenbacher * __gfs2_log_reserve - Make a log reservation 506fe3e3976SAndreas Gruenbacher * @sdp: The GFS2 superblock 507fe3e3976SAndreas Gruenbacher * @blks: The number of blocks to reserve 508fe3e3976SAndreas Gruenbacher * @taboo_blks: The number of blocks to leave free 509fe3e3976SAndreas Gruenbacher * 510fe3e3976SAndreas Gruenbacher * @taboo_blks is set to 0 for logd, and to GFS2_LOG_FLUSH_MIN_BLOCKS 511fe3e3976SAndreas Gruenbacher * for all other processes. This ensures that when the log is almost full, 512fe3e3976SAndreas Gruenbacher * logd will still be able to call gfs2_log_flush one more time without 513fe3e3976SAndreas Gruenbacher * blocking, which will advance the tail and make some more log space 514fe3e3976SAndreas Gruenbacher * available. 515b004157aSSteven Whitehouse * 5165e687eacSBenjamin Marzinski * We no longer flush the log here, instead we wake up logd to do that 5175e687eacSBenjamin Marzinski * for us. To avoid the thundering herd and to ensure that we deal fairly 5185e687eacSBenjamin Marzinski * with queued waiters, we use an exclusive wait. This means that when we 5195e687eacSBenjamin Marzinski * get woken with enough journal space to get our reservation, we need to 5205e687eacSBenjamin Marzinski * wake the next waiter on the list. 521b3b94faaSDavid Teigland */ 522b3b94faaSDavid Teigland 523fe3e3976SAndreas Gruenbacher static void __gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks, 524fe3e3976SAndreas Gruenbacher unsigned int taboo_blks) 525b3b94faaSDavid Teigland { 526fe3e3976SAndreas Gruenbacher unsigned wanted = blks + taboo_blks; 5275e687eacSBenjamin Marzinski unsigned int free_blocks; 528b3b94faaSDavid Teigland 529f07b3520SBob Peterson atomic_add(blks, &sdp->sd_log_blks_needed); 5305ae8fff8SAndreas Gruenbacher for (;;) { 5315ae8fff8SAndreas Gruenbacher if (current != sdp->sd_logd_process) 5325e687eacSBenjamin Marzinski wake_up(&sdp->sd_logd_waitq); 5335ae8fff8SAndreas Gruenbacher io_wait_event(sdp->sd_log_waitq, 5345ae8fff8SAndreas Gruenbacher (free_blocks = atomic_read(&sdp->sd_log_blks_free), 5355ae8fff8SAndreas Gruenbacher free_blocks >= wanted)); 5365ae8fff8SAndreas Gruenbacher do { 5375ae8fff8SAndreas Gruenbacher if (atomic_try_cmpxchg(&sdp->sd_log_blks_free, 5385ae8fff8SAndreas Gruenbacher &free_blocks, 5395ae8fff8SAndreas Gruenbacher free_blocks - blks)) 5405ae8fff8SAndreas Gruenbacher goto reserved; 5415ae8fff8SAndreas Gruenbacher } while (free_blocks >= wanted); 542b3b94faaSDavid Teigland } 5435ae8fff8SAndreas Gruenbacher 5445ae8fff8SAndreas Gruenbacher reserved: 54563997775SSteven Whitehouse trace_gfs2_log_blocks(sdp, -blks); 5465ae8fff8SAndreas Gruenbacher if (atomic_sub_return(blks, &sdp->sd_log_blks_needed)) 5475e687eacSBenjamin Marzinski wake_up(&sdp->sd_log_waitq); 54824972557SBenjamin Marzinski } 549b3b94faaSDavid Teigland 550b3b94faaSDavid Teigland /** 5512129b428SAndreas Gruenbacher * gfs2_log_try_reserve - Try to make a log reservation 552fe3e3976SAndreas Gruenbacher * @sdp: The GFS2 superblock 5532129b428SAndreas Gruenbacher * @tr: The transaction 5542129b428SAndreas Gruenbacher * @extra_revokes: The number of additional revokes reserved (output) 5552129b428SAndreas Gruenbacher * 5562129b428SAndreas Gruenbacher * This is similar to gfs2_log_reserve, but sdp->sd_log_flush_lock must be 5572129b428SAndreas Gruenbacher * held for correct revoke accounting. 558fe3e3976SAndreas Gruenbacher */ 559fe3e3976SAndreas Gruenbacher 5602129b428SAndreas Gruenbacher bool gfs2_log_try_reserve(struct gfs2_sbd *sdp, struct gfs2_trans *tr, 5612129b428SAndreas Gruenbacher unsigned int *extra_revokes) 562fe3e3976SAndreas Gruenbacher { 5632129b428SAndreas Gruenbacher unsigned int blks = tr->tr_reserved; 5642129b428SAndreas Gruenbacher unsigned int revokes = tr->tr_revokes; 5652129b428SAndreas Gruenbacher unsigned int revoke_blks = 0; 5662129b428SAndreas Gruenbacher 5672129b428SAndreas Gruenbacher *extra_revokes = 0; 5682129b428SAndreas Gruenbacher if (revokes && !__gfs2_log_try_reserve_revokes(sdp, revokes)) { 5692129b428SAndreas Gruenbacher revoke_blks = DIV_ROUND_UP(revokes, sdp->sd_inptrs); 5702129b428SAndreas Gruenbacher *extra_revokes = revoke_blks * sdp->sd_inptrs - revokes; 5712129b428SAndreas Gruenbacher blks += revoke_blks; 5722129b428SAndreas Gruenbacher } 5732129b428SAndreas Gruenbacher if (!blks) 5742129b428SAndreas Gruenbacher return true; 575fe3e3976SAndreas Gruenbacher if (__gfs2_log_try_reserve(sdp, blks, GFS2_LOG_FLUSH_MIN_BLOCKS)) 5762129b428SAndreas Gruenbacher return true; 5772129b428SAndreas Gruenbacher if (!revoke_blks) 5782129b428SAndreas Gruenbacher gfs2_log_release_revokes(sdp, revokes); 5792129b428SAndreas Gruenbacher return false; 5802129b428SAndreas Gruenbacher } 5812129b428SAndreas Gruenbacher 5822129b428SAndreas Gruenbacher /** 5832129b428SAndreas Gruenbacher * gfs2_log_reserve - Make a log reservation 5842129b428SAndreas Gruenbacher * @sdp: The GFS2 superblock 5852129b428SAndreas Gruenbacher * @tr: The transaction 5862129b428SAndreas Gruenbacher * @extra_revokes: The number of additional revokes reserved (output) 5872129b428SAndreas Gruenbacher * 5882129b428SAndreas Gruenbacher * sdp->sd_log_flush_lock must not be held. 5892129b428SAndreas Gruenbacher */ 5902129b428SAndreas Gruenbacher 5912129b428SAndreas Gruenbacher void gfs2_log_reserve(struct gfs2_sbd *sdp, struct gfs2_trans *tr, 5922129b428SAndreas Gruenbacher unsigned int *extra_revokes) 5932129b428SAndreas Gruenbacher { 5942129b428SAndreas Gruenbacher unsigned int blks = tr->tr_reserved; 5952129b428SAndreas Gruenbacher unsigned int revokes = tr->tr_revokes; 596dc7674edSBob Peterson unsigned int revoke_blks; 5972129b428SAndreas Gruenbacher 5982129b428SAndreas Gruenbacher *extra_revokes = 0; 5992129b428SAndreas Gruenbacher if (revokes) { 6002129b428SAndreas Gruenbacher revoke_blks = DIV_ROUND_UP(revokes, sdp->sd_inptrs); 6012129b428SAndreas Gruenbacher *extra_revokes = revoke_blks * sdp->sd_inptrs - revokes; 6022129b428SAndreas Gruenbacher blks += revoke_blks; 6032129b428SAndreas Gruenbacher } 604fe3e3976SAndreas Gruenbacher __gfs2_log_reserve(sdp, blks, GFS2_LOG_FLUSH_MIN_BLOCKS); 605b3b94faaSDavid Teigland } 606b3b94faaSDavid Teigland 607b3b94faaSDavid Teigland /** 608b3b94faaSDavid Teigland * log_distance - Compute distance between two journal blocks 609b3b94faaSDavid Teigland * @sdp: The GFS2 superblock 610b3b94faaSDavid Teigland * @newer: The most recent journal block of the pair 611b3b94faaSDavid Teigland * @older: The older journal block of the pair 612b3b94faaSDavid Teigland * 613b3b94faaSDavid Teigland * Compute the distance (in the journal direction) between two 614b3b94faaSDavid Teigland * blocks in the journal 615b3b94faaSDavid Teigland * 616b3b94faaSDavid Teigland * Returns: the distance in blocks 617b3b94faaSDavid Teigland */ 618b3b94faaSDavid Teigland 619faa31ce8SSteven Whitehouse static inline unsigned int log_distance(struct gfs2_sbd *sdp, unsigned int newer, 620b3b94faaSDavid Teigland unsigned int older) 621b3b94faaSDavid Teigland { 622b3b94faaSDavid Teigland int dist; 623b3b94faaSDavid Teigland 624b3b94faaSDavid Teigland dist = newer - older; 625b3b94faaSDavid Teigland if (dist < 0) 626b3b94faaSDavid Teigland dist += sdp->sd_jdesc->jd_blocks; 627b3b94faaSDavid Teigland 628b3b94faaSDavid Teigland return dist; 629b3b94faaSDavid Teigland } 630b3b94faaSDavid Teigland 6312332c443SRobert Peterson /** 6326188e877SAndreas Gruenbacher * calc_reserved - Calculate the number of blocks to keep reserved 6332332c443SRobert Peterson * @sdp: The GFS2 superblock 6342332c443SRobert Peterson * 6352332c443SRobert Peterson * This is complex. We need to reserve room for all our currently used 6366188e877SAndreas Gruenbacher * metadata blocks (e.g. normal file I/O rewriting file time stamps) and 6376188e877SAndreas Gruenbacher * all our journaled data blocks for journaled files (e.g. files in the 6382332c443SRobert Peterson * meta_fs like rindex, or files for which chattr +j was done.) 6396188e877SAndreas Gruenbacher * If we don't reserve enough space, corruption will follow. 6402332c443SRobert Peterson * 6416188e877SAndreas Gruenbacher * We can have metadata blocks and jdata blocks in the same journal. Each 6426188e877SAndreas Gruenbacher * type gets its own log descriptor, for which we need to reserve a block. 6436188e877SAndreas Gruenbacher * In fact, each type has the potential for needing more than one log descriptor 6446188e877SAndreas Gruenbacher * in cases where we have more blocks than will fit in a log descriptor. 6452332c443SRobert Peterson * Metadata journal entries take up half the space of journaled buffer entries. 6462332c443SRobert Peterson * 6472332c443SRobert Peterson * Also, we need to reserve blocks for revoke journal entries and one for an 6482332c443SRobert Peterson * overall header for the lot. 6492332c443SRobert Peterson * 6502332c443SRobert Peterson * Returns: the number of blocks reserved 6512332c443SRobert Peterson */ 6522332c443SRobert Peterson static unsigned int calc_reserved(struct gfs2_sbd *sdp) 6532332c443SRobert Peterson { 654fe3e3976SAndreas Gruenbacher unsigned int reserved = GFS2_LOG_FLUSH_MIN_BLOCKS; 65571b219f4SAndreas Gruenbacher unsigned int blocks; 656022ef4feSSteven Whitehouse struct gfs2_trans *tr = sdp->sd_log_tr; 6572332c443SRobert Peterson 658022ef4feSSteven Whitehouse if (tr) { 65971b219f4SAndreas Gruenbacher blocks = tr->tr_num_buf_new - tr->tr_num_buf_rm; 66071b219f4SAndreas Gruenbacher reserved += blocks + DIV_ROUND_UP(blocks, buf_limit(sdp)); 66171b219f4SAndreas Gruenbacher blocks = tr->tr_num_databuf_new - tr->tr_num_databuf_rm; 66271b219f4SAndreas Gruenbacher reserved += blocks + DIV_ROUND_UP(blocks, databuf_limit(sdp)); 663022ef4feSSteven Whitehouse } 6642332c443SRobert Peterson return reserved; 6652332c443SRobert Peterson } 6662332c443SRobert Peterson 6675cb738b5SAndreas Gruenbacher static void log_pull_tail(struct gfs2_sbd *sdp) 668b3b94faaSDavid Teigland { 6695cb738b5SAndreas Gruenbacher unsigned int new_tail = sdp->sd_log_flush_tail; 6705cb738b5SAndreas Gruenbacher unsigned int dist; 671b3b94faaSDavid Teigland 6725cb738b5SAndreas Gruenbacher if (new_tail == sdp->sd_log_tail) 6735cb738b5SAndreas Gruenbacher return; 6745cb738b5SAndreas Gruenbacher dist = log_distance(sdp, new_tail, sdp->sd_log_tail); 675b3b94faaSDavid Teigland ail2_empty(sdp, new_tail); 676c1eba1b0SAndreas Gruenbacher gfs2_log_release(sdp, dist); 677b3b94faaSDavid Teigland sdp->sd_log_tail = new_tail; 678b3b94faaSDavid Teigland } 679b3b94faaSDavid Teigland 680b3b94faaSDavid Teigland 6819ff78289SBob Peterson void log_flush_wait(struct gfs2_sbd *sdp) 682b3b94faaSDavid Teigland { 68316615be1SSteven Whitehouse DEFINE_WAIT(wait); 684b3b94faaSDavid Teigland 68516615be1SSteven Whitehouse if (atomic_read(&sdp->sd_log_in_flight)) { 68616615be1SSteven Whitehouse do { 68716615be1SSteven Whitehouse prepare_to_wait(&sdp->sd_log_flush_wait, &wait, 68816615be1SSteven Whitehouse TASK_UNINTERRUPTIBLE); 68916615be1SSteven Whitehouse if (atomic_read(&sdp->sd_log_in_flight)) 69016615be1SSteven Whitehouse io_schedule(); 69116615be1SSteven Whitehouse } while(atomic_read(&sdp->sd_log_in_flight)); 69216615be1SSteven Whitehouse finish_wait(&sdp->sd_log_flush_wait, &wait); 693b3b94faaSDavid Teigland } 694b3b94faaSDavid Teigland } 695b3b94faaSDavid Teigland 6964f0f586bSSami Tolvanen static int ip_cmp(void *priv, const struct list_head *a, const struct list_head *b) 6974a36d08dSBob Peterson { 69845138990SSteven Whitehouse struct gfs2_inode *ipa, *ipb; 6994a36d08dSBob Peterson 70045138990SSteven Whitehouse ipa = list_entry(a, struct gfs2_inode, i_ordered); 70145138990SSteven Whitehouse ipb = list_entry(b, struct gfs2_inode, i_ordered); 7024a36d08dSBob Peterson 70345138990SSteven Whitehouse if (ipa->i_no_addr < ipb->i_no_addr) 7044a36d08dSBob Peterson return -1; 70545138990SSteven Whitehouse if (ipa->i_no_addr > ipb->i_no_addr) 7064a36d08dSBob Peterson return 1; 7074a36d08dSBob Peterson return 0; 7084a36d08dSBob Peterson } 7094a36d08dSBob Peterson 7107542486bSBob Peterson static void __ordered_del_inode(struct gfs2_inode *ip) 7117542486bSBob Peterson { 7127542486bSBob Peterson if (!list_empty(&ip->i_ordered)) 7137542486bSBob Peterson list_del_init(&ip->i_ordered); 7147542486bSBob Peterson } 7157542486bSBob Peterson 716d7b616e2SSteven Whitehouse static void gfs2_ordered_write(struct gfs2_sbd *sdp) 717d7b616e2SSteven Whitehouse { 71845138990SSteven Whitehouse struct gfs2_inode *ip; 719d7b616e2SSteven Whitehouse LIST_HEAD(written); 720d7b616e2SSteven Whitehouse 72145138990SSteven Whitehouse spin_lock(&sdp->sd_ordered_lock); 722a5b1d3fcSAndreas Gruenbacher list_sort(NULL, &sdp->sd_log_ordered, &ip_cmp); 723a5b1d3fcSAndreas Gruenbacher while (!list_empty(&sdp->sd_log_ordered)) { 724969183bcSAndreas Gruenbacher ip = list_first_entry(&sdp->sd_log_ordered, struct gfs2_inode, i_ordered); 7251f23bc78SAbhi Das if (ip->i_inode.i_mapping->nrpages == 0) { 7267542486bSBob Peterson __ordered_del_inode(ip); 727d7b616e2SSteven Whitehouse continue; 7281f23bc78SAbhi Das } 7291f23bc78SAbhi Das list_move(&ip->i_ordered, &written); 73045138990SSteven Whitehouse spin_unlock(&sdp->sd_ordered_lock); 73145138990SSteven Whitehouse filemap_fdatawrite(ip->i_inode.i_mapping); 73245138990SSteven Whitehouse spin_lock(&sdp->sd_ordered_lock); 733d7b616e2SSteven Whitehouse } 734a5b1d3fcSAndreas Gruenbacher list_splice(&written, &sdp->sd_log_ordered); 73545138990SSteven Whitehouse spin_unlock(&sdp->sd_ordered_lock); 736d7b616e2SSteven Whitehouse } 737d7b616e2SSteven Whitehouse 738d7b616e2SSteven Whitehouse static void gfs2_ordered_wait(struct gfs2_sbd *sdp) 739d7b616e2SSteven Whitehouse { 74045138990SSteven Whitehouse struct gfs2_inode *ip; 741d7b616e2SSteven Whitehouse 74245138990SSteven Whitehouse spin_lock(&sdp->sd_ordered_lock); 743a5b1d3fcSAndreas Gruenbacher while (!list_empty(&sdp->sd_log_ordered)) { 744969183bcSAndreas Gruenbacher ip = list_first_entry(&sdp->sd_log_ordered, struct gfs2_inode, i_ordered); 7457542486bSBob Peterson __ordered_del_inode(ip); 74645138990SSteven Whitehouse if (ip->i_inode.i_mapping->nrpages == 0) 747d7b616e2SSteven Whitehouse continue; 74845138990SSteven Whitehouse spin_unlock(&sdp->sd_ordered_lock); 74945138990SSteven Whitehouse filemap_fdatawait(ip->i_inode.i_mapping); 75045138990SSteven Whitehouse spin_lock(&sdp->sd_ordered_lock); 751d7b616e2SSteven Whitehouse } 75245138990SSteven Whitehouse spin_unlock(&sdp->sd_ordered_lock); 753d7b616e2SSteven Whitehouse } 75445138990SSteven Whitehouse 75545138990SSteven Whitehouse void gfs2_ordered_del_inode(struct gfs2_inode *ip) 75645138990SSteven Whitehouse { 75745138990SSteven Whitehouse struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 75845138990SSteven Whitehouse 75945138990SSteven Whitehouse spin_lock(&sdp->sd_ordered_lock); 7607542486bSBob Peterson __ordered_del_inode(ip); 76145138990SSteven Whitehouse spin_unlock(&sdp->sd_ordered_lock); 762d7b616e2SSteven Whitehouse } 763d7b616e2SSteven Whitehouse 7645d054964SBenjamin Marzinski void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd) 7655d054964SBenjamin Marzinski { 7665d054964SBenjamin Marzinski struct buffer_head *bh = bd->bd_bh; 7675d054964SBenjamin Marzinski struct gfs2_glock *gl = bd->bd_gl; 7685d054964SBenjamin Marzinski 769f4e2f5e1SAndreas Gruenbacher sdp->sd_log_num_revoke++; 770f4e2f5e1SAndreas Gruenbacher if (atomic_inc_return(&gl->gl_revokes) == 1) 771f4e2f5e1SAndreas Gruenbacher gfs2_glock_hold(gl); 7725d054964SBenjamin Marzinski bh->b_private = NULL; 7735d054964SBenjamin Marzinski bd->bd_blkno = bh->b_blocknr; 7749290a9a7SBob Peterson gfs2_remove_from_ail(bd); /* drops ref on bh */ 7759290a9a7SBob Peterson bd->bd_bh = NULL; 7765d054964SBenjamin Marzinski set_bit(GLF_LFLUSH, &gl->gl_flags); 777a5b1d3fcSAndreas Gruenbacher list_add(&bd->bd_list, &sdp->sd_log_revokes); 7785d054964SBenjamin Marzinski } 7795d054964SBenjamin Marzinski 780fe5e7ba1SBob Peterson void gfs2_glock_remove_revoke(struct gfs2_glock *gl) 781fe5e7ba1SBob Peterson { 782fe5e7ba1SBob Peterson if (atomic_dec_return(&gl->gl_revokes) == 0) { 783fe5e7ba1SBob Peterson clear_bit(GLF_LFLUSH, &gl->gl_flags); 784fe5e7ba1SBob Peterson gfs2_glock_queue_put(gl); 785fe5e7ba1SBob Peterson } 786fe5e7ba1SBob Peterson } 787fe5e7ba1SBob Peterson 7885e4c7632SBob Peterson /** 789e7501bf8SAndreas Gruenbacher * gfs2_flush_revokes - Add as many revokes to the system transaction as we can 7905e4c7632SBob Peterson * @sdp: The GFS2 superblock 7915e4c7632SBob Peterson * 7925e4c7632SBob Peterson * Our usual strategy is to defer writing revokes as much as we can in the hope 7935e4c7632SBob Peterson * that we'll eventually overwrite the journal, which will make those revokes 7945e4c7632SBob Peterson * go away. This changes when we flush the log: at that point, there will 7955e4c7632SBob Peterson * likely be some left-over space in the last revoke block of that transaction. 7965e4c7632SBob Peterson * We can fill that space with additional revokes for blocks that have already 7975e4c7632SBob Peterson * been written back. This will basically come at no cost now, and will save 7985e4c7632SBob Peterson * us from having to keep track of those blocks on the AIL2 list later. 7995e4c7632SBob Peterson */ 800e7501bf8SAndreas Gruenbacher void gfs2_flush_revokes(struct gfs2_sbd *sdp) 8015d054964SBenjamin Marzinski { 8025e4c7632SBob Peterson /* number of revokes we still have room for */ 8032129b428SAndreas Gruenbacher unsigned int max_revokes = atomic_read(&sdp->sd_log_revokes_available); 8045d054964SBenjamin Marzinski 8055e4c7632SBob Peterson gfs2_log_lock(sdp); 8065e4c7632SBob Peterson gfs2_ail1_empty(sdp, max_revokes); 8075d054964SBenjamin Marzinski gfs2_log_unlock(sdp); 8085d054964SBenjamin Marzinski } 8095d054964SBenjamin Marzinski 810b3b94faaSDavid Teigland /** 8117c70b896SBob Peterson * gfs2_write_log_header - Write a journal log header buffer at lblock 812588bff95SBob Peterson * @sdp: The GFS2 superblock 813c1696fb8SBob Peterson * @jd: journal descriptor of the journal to which we are writing 814588bff95SBob Peterson * @seq: sequence number 815588bff95SBob Peterson * @tail: tail of the log 8167c70b896SBob Peterson * @lblock: value for lh_blkno (block number relative to start of journal) 817c1696fb8SBob Peterson * @flags: log header flags GFS2_LOG_HEAD_* 818588bff95SBob Peterson * @op_flags: flags to pass to the bio 819588bff95SBob Peterson * 820588bff95SBob Peterson * Returns: the initialized log buffer descriptor 821588bff95SBob Peterson */ 822588bff95SBob Peterson 823c1696fb8SBob Peterson void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, 8247c70b896SBob Peterson u64 seq, u32 tail, u32 lblock, u32 flags, 8257c70b896SBob Peterson int op_flags) 826588bff95SBob Peterson { 827588bff95SBob Peterson struct gfs2_log_header *lh; 828c1696fb8SBob Peterson u32 hash, crc; 829ade48088SBob Peterson struct page *page; 830c1696fb8SBob Peterson struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; 831c1696fb8SBob Peterson struct timespec64 tv; 832c1696fb8SBob Peterson struct super_block *sb = sdp->sd_vfs; 8337c70b896SBob Peterson u64 dblock; 834588bff95SBob Peterson 835ade48088SBob Peterson if (gfs2_withdrawn(sdp)) 8364a3d049dSAndreas Gruenbacher return; 837ade48088SBob Peterson 838ade48088SBob Peterson page = mempool_alloc(gfs2_page_pool, GFP_NOIO); 839588bff95SBob Peterson lh = page_address(page); 840588bff95SBob Peterson clear_page(lh); 841588bff95SBob Peterson 842588bff95SBob Peterson lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); 843588bff95SBob Peterson lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH); 844588bff95SBob Peterson lh->lh_header.__pad0 = cpu_to_be64(0); 845588bff95SBob Peterson lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH); 846588bff95SBob Peterson lh->lh_header.mh_jid = cpu_to_be32(sdp->sd_jdesc->jd_jid); 847588bff95SBob Peterson lh->lh_sequence = cpu_to_be64(seq); 848588bff95SBob Peterson lh->lh_flags = cpu_to_be32(flags); 849588bff95SBob Peterson lh->lh_tail = cpu_to_be32(tail); 8507c70b896SBob Peterson lh->lh_blkno = cpu_to_be32(lblock); 851c1696fb8SBob Peterson hash = ~crc32(~0, lh, LH_V1_SIZE); 852588bff95SBob Peterson lh->lh_hash = cpu_to_be32(hash); 853588bff95SBob Peterson 854ee9c7f9aSArnd Bergmann ktime_get_coarse_real_ts64(&tv); 855c1696fb8SBob Peterson lh->lh_nsec = cpu_to_be32(tv.tv_nsec); 856c1696fb8SBob Peterson lh->lh_sec = cpu_to_be64(tv.tv_sec); 8577c70b896SBob Peterson if (!list_empty(&jd->extent_list)) 85819ebc050SAndreas Gruenbacher dblock = gfs2_log_bmap(jd, lblock); 8597c70b896SBob Peterson else { 860152f58c9SAndreas Gruenbacher unsigned int extlen; 861152f58c9SAndreas Gruenbacher int ret; 862152f58c9SAndreas Gruenbacher 863152f58c9SAndreas Gruenbacher extlen = 1; 864152f58c9SAndreas Gruenbacher ret = gfs2_get_extent(jd->jd_inode, lblock, &dblock, &extlen); 8657c70b896SBob Peterson if (gfs2_assert_withdraw(sdp, ret == 0)) 8667c70b896SBob Peterson return; 8677c70b896SBob Peterson } 8687c70b896SBob Peterson lh->lh_addr = cpu_to_be64(dblock); 869c1696fb8SBob Peterson lh->lh_jinode = cpu_to_be64(GFS2_I(jd->jd_inode)->i_no_addr); 870c1696fb8SBob Peterson 871c1696fb8SBob Peterson /* We may only write local statfs, quota, etc., when writing to our 872c1696fb8SBob Peterson own journal. The values are left 0 when recovering a journal 873c1696fb8SBob Peterson different from our own. */ 874c1696fb8SBob Peterson if (!(flags & GFS2_LOG_HEAD_RECOVERY)) { 875c1696fb8SBob Peterson lh->lh_statfs_addr = 876c1696fb8SBob Peterson cpu_to_be64(GFS2_I(sdp->sd_sc_inode)->i_no_addr); 877c1696fb8SBob Peterson lh->lh_quota_addr = 878c1696fb8SBob Peterson cpu_to_be64(GFS2_I(sdp->sd_qc_inode)->i_no_addr); 879c1696fb8SBob Peterson 880c1696fb8SBob Peterson spin_lock(&sdp->sd_statfs_spin); 881c1696fb8SBob Peterson lh->lh_local_total = cpu_to_be64(l_sc->sc_total); 882c1696fb8SBob Peterson lh->lh_local_free = cpu_to_be64(l_sc->sc_free); 883c1696fb8SBob Peterson lh->lh_local_dinodes = cpu_to_be64(l_sc->sc_dinodes); 884c1696fb8SBob Peterson spin_unlock(&sdp->sd_statfs_spin); 885c1696fb8SBob Peterson } 886c1696fb8SBob Peterson 887c1696fb8SBob Peterson BUILD_BUG_ON(offsetof(struct gfs2_log_header, lh_crc) != LH_V1_SIZE); 888c1696fb8SBob Peterson 889c1696fb8SBob Peterson crc = crc32c(~0, (void *)lh + LH_V1_SIZE + 4, 890c1696fb8SBob Peterson sb->s_blocksize - LH_V1_SIZE - 4); 891c1696fb8SBob Peterson lh->lh_crc = cpu_to_be32(crc); 892c1696fb8SBob Peterson 89382218943SBob Peterson gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock); 89482218943SBob Peterson gfs2_log_submit_bio(&jd->jd_log_bio, REQ_OP_WRITE | op_flags); 895588bff95SBob Peterson } 896588bff95SBob Peterson 897588bff95SBob Peterson /** 89834cc1781SSteven Whitehouse * log_write_header - Get and initialize a journal header buffer 89934cc1781SSteven Whitehouse * @sdp: The GFS2 superblock 900c1696fb8SBob Peterson * @flags: The log header flags, including log header origin 90134cc1781SSteven Whitehouse * 90234cc1781SSteven Whitehouse * Returns: the initialized log buffer descriptor 90334cc1781SSteven Whitehouse */ 90434cc1781SSteven Whitehouse 905fdb76a42SSteven Whitehouse static void log_write_header(struct gfs2_sbd *sdp, u32 flags) 90634cc1781SSteven Whitehouse { 9070f0b9b63SJan Kara int op_flags = REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC; 9082e60d768SBenjamin Marzinski enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state); 90934cc1781SSteven Whitehouse 9102e60d768SBenjamin Marzinski gfs2_assert_withdraw(sdp, (state != SFS_FROZEN)); 91134cc1781SSteven Whitehouse 91234cc1781SSteven Whitehouse if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) { 91334cc1781SSteven Whitehouse gfs2_ordered_wait(sdp); 91434cc1781SSteven Whitehouse log_flush_wait(sdp); 91570fd7614SChristoph Hellwig op_flags = REQ_SYNC | REQ_META | REQ_PRIO; 91634cc1781SSteven Whitehouse } 9175cb738b5SAndreas Gruenbacher sdp->sd_log_idle = (sdp->sd_log_flush_tail == sdp->sd_log_flush_head); 9185cb738b5SAndreas Gruenbacher gfs2_write_log_header(sdp, sdp->sd_jdesc, sdp->sd_log_sequence++, 9195cb738b5SAndreas Gruenbacher sdp->sd_log_flush_tail, sdp->sd_log_flush_head, 9205cb738b5SAndreas Gruenbacher flags, op_flags); 92119ebc050SAndreas Gruenbacher gfs2_log_incr_head(sdp); 9224a3d049dSAndreas Gruenbacher log_flush_wait(sdp); 9235cb738b5SAndreas Gruenbacher log_pull_tail(sdp); 924fe3e3976SAndreas Gruenbacher gfs2_log_update_head(sdp); 92534cc1781SSteven Whitehouse } 92634cc1781SSteven Whitehouse 92734cc1781SSteven Whitehouse /** 928f5456b5dSBob Peterson * gfs2_ail_drain - drain the ail lists after a withdraw 9292ca0c2fbSBob Peterson * @sdp: Pointer to GFS2 superblock 9302ca0c2fbSBob Peterson */ 931f5456b5dSBob Peterson void gfs2_ail_drain(struct gfs2_sbd *sdp) 9322ca0c2fbSBob Peterson { 9332ca0c2fbSBob Peterson struct gfs2_trans *tr; 9342ca0c2fbSBob Peterson 9352ca0c2fbSBob Peterson spin_lock(&sdp->sd_ail_lock); 9362ca0c2fbSBob Peterson /* 9372ca0c2fbSBob Peterson * For transactions on the sd_ail1_list we need to drain both the 9382ca0c2fbSBob Peterson * ail1 and ail2 lists. That's because function gfs2_ail1_start_one 9392ca0c2fbSBob Peterson * (temporarily) moves items from its tr_ail1 list to tr_ail2 list 9402ca0c2fbSBob Peterson * before revokes are sent for that block. Items on the sd_ail2_list 9412ca0c2fbSBob Peterson * should have already gotten beyond that point, so no need. 9422ca0c2fbSBob Peterson */ 9432ca0c2fbSBob Peterson while (!list_empty(&sdp->sd_ail1_list)) { 9442ca0c2fbSBob Peterson tr = list_first_entry(&sdp->sd_ail1_list, struct gfs2_trans, 9452ca0c2fbSBob Peterson tr_list); 9462ca0c2fbSBob Peterson gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail1_list); 9472ca0c2fbSBob Peterson gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail2_list); 9482ca0c2fbSBob Peterson list_del(&tr->tr_list); 949b839dadaSBob Peterson gfs2_trans_free(sdp, tr); 9502ca0c2fbSBob Peterson } 9512ca0c2fbSBob Peterson while (!list_empty(&sdp->sd_ail2_list)) { 9522ca0c2fbSBob Peterson tr = list_first_entry(&sdp->sd_ail2_list, struct gfs2_trans, 9532ca0c2fbSBob Peterson tr_list); 9542ca0c2fbSBob Peterson gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail2_list); 9552ca0c2fbSBob Peterson list_del(&tr->tr_list); 956b839dadaSBob Peterson gfs2_trans_free(sdp, tr); 9572ca0c2fbSBob Peterson } 958f5456b5dSBob Peterson gfs2_drain_revokes(sdp); 9592ca0c2fbSBob Peterson spin_unlock(&sdp->sd_ail_lock); 9602ca0c2fbSBob Peterson } 9612ca0c2fbSBob Peterson 9622ca0c2fbSBob Peterson /** 963d5dc3d96SBob Peterson * empty_ail1_list - try to start IO and empty the ail1 list 964d5dc3d96SBob Peterson * @sdp: Pointer to GFS2 superblock 965d5dc3d96SBob Peterson */ 966d5dc3d96SBob Peterson static void empty_ail1_list(struct gfs2_sbd *sdp) 967d5dc3d96SBob Peterson { 968d5dc3d96SBob Peterson unsigned long start = jiffies; 969d5dc3d96SBob Peterson 970d5dc3d96SBob Peterson for (;;) { 971d5dc3d96SBob Peterson if (time_after(jiffies, start + (HZ * 600))) { 972d5dc3d96SBob Peterson fs_err(sdp, "Error: In %s for 10 minutes! t=%d\n", 973d5dc3d96SBob Peterson __func__, current->journal_info ? 1 : 0); 974d5dc3d96SBob Peterson dump_ail_list(sdp); 975d5dc3d96SBob Peterson return; 976d5dc3d96SBob Peterson } 977d5dc3d96SBob Peterson gfs2_ail1_start(sdp); 978d5dc3d96SBob Peterson gfs2_ail1_wait(sdp); 979d5dc3d96SBob Peterson if (gfs2_ail1_empty(sdp, 0)) 980d5dc3d96SBob Peterson return; 981d5dc3d96SBob Peterson } 982d5dc3d96SBob Peterson } 983d5dc3d96SBob Peterson 984d5dc3d96SBob Peterson /** 985521031faSBob Peterson * trans_drain - drain the buf and databuf queue for a failed transaction 986462582b9SBob Peterson * @tr: the transaction to drain 987462582b9SBob Peterson * 988462582b9SBob Peterson * When this is called, we're taking an error exit for a log write that failed 989462582b9SBob Peterson * but since we bypassed the after_commit functions, we need to remove the 990462582b9SBob Peterson * items from the buf and databuf queue. 991462582b9SBob Peterson */ 992462582b9SBob Peterson static void trans_drain(struct gfs2_trans *tr) 993462582b9SBob Peterson { 994462582b9SBob Peterson struct gfs2_bufdata *bd; 995462582b9SBob Peterson struct list_head *head; 996462582b9SBob Peterson 997462582b9SBob Peterson if (!tr) 998462582b9SBob Peterson return; 999462582b9SBob Peterson 1000462582b9SBob Peterson head = &tr->tr_buf; 1001462582b9SBob Peterson while (!list_empty(head)) { 1002462582b9SBob Peterson bd = list_first_entry(head, struct gfs2_bufdata, bd_list); 1003462582b9SBob Peterson list_del_init(&bd->bd_list); 10041a5a2cfdSBob Peterson if (!list_empty(&bd->bd_ail_st_list)) 10051a5a2cfdSBob Peterson gfs2_remove_from_ail(bd); 1006462582b9SBob Peterson kmem_cache_free(gfs2_bufdata_cachep, bd); 1007462582b9SBob Peterson } 1008462582b9SBob Peterson head = &tr->tr_databuf; 1009462582b9SBob Peterson while (!list_empty(head)) { 1010462582b9SBob Peterson bd = list_first_entry(head, struct gfs2_bufdata, bd_list); 1011462582b9SBob Peterson list_del_init(&bd->bd_list); 10121a5a2cfdSBob Peterson if (!list_empty(&bd->bd_ail_st_list)) 10131a5a2cfdSBob Peterson gfs2_remove_from_ail(bd); 1014462582b9SBob Peterson kmem_cache_free(gfs2_bufdata_cachep, bd); 1015462582b9SBob Peterson } 1016462582b9SBob Peterson } 1017462582b9SBob Peterson 1018462582b9SBob Peterson /** 1019b09e593dSSteven Whitehouse * gfs2_log_flush - flush incore transaction(s) 1020c551f66cSLee Jones * @sdp: The filesystem 1021b3b94faaSDavid Teigland * @gl: The glock structure to flush. If NULL, flush the whole incore log 1022805c0907SBob Peterson * @flags: The log header flags: GFS2_LOG_HEAD_FLUSH_* and debug flags 1023b3b94faaSDavid Teigland * 1024b3b94faaSDavid Teigland */ 1025b3b94faaSDavid Teigland 1026c1696fb8SBob Peterson void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags) 1027b3b94faaSDavid Teigland { 10282ca0c2fbSBob Peterson struct gfs2_trans *tr = NULL; 1029fe3e3976SAndreas Gruenbacher unsigned int reserved_blocks = 0, used_blocks = 0; 10302e60d768SBenjamin Marzinski enum gfs2_freeze_state state = atomic_read(&sdp->sd_freeze_state); 1031fe3e3976SAndreas Gruenbacher unsigned int first_log_head; 10322129b428SAndreas Gruenbacher unsigned int reserved_revokes = 0; 1033b3b94faaSDavid Teigland 1034484adff8SSteven Whitehouse down_write(&sdp->sd_log_flush_lock); 1035fe3e3976SAndreas Gruenbacher trace_gfs2_log_flush(sdp, 1, flags); 1036f55ab26aSSteven Whitehouse 1037fe3e3976SAndreas Gruenbacher repeat: 10382ca0c2fbSBob Peterson /* 10392ca0c2fbSBob Peterson * Do this check while holding the log_flush_lock to prevent new 10402ca0c2fbSBob Peterson * buffers from being added to the ail via gfs2_pin() 10412ca0c2fbSBob Peterson */ 10420efc4976SBob Peterson if (gfs2_withdrawn(sdp) || !test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) 10432ca0c2fbSBob Peterson goto out; 10442ca0c2fbSBob Peterson 10452bcd610dSSteven Whitehouse /* Log might have been flushed while we waited for the flush lock */ 10465a61ae14SAndreas Gruenbacher if (gl && !test_bit(GLF_LFLUSH, &gl->gl_flags)) 10475a61ae14SAndreas Gruenbacher goto out; 1048f55ab26aSSteven Whitehouse 1049fe3e3976SAndreas Gruenbacher first_log_head = sdp->sd_log_head; 1050fe3e3976SAndreas Gruenbacher sdp->sd_log_flush_head = first_log_head; 1051400ac52eSBenjamin Marzinski 105216ca9412SBenjamin Marzinski tr = sdp->sd_log_tr; 1053fe3e3976SAndreas Gruenbacher if (tr || sdp->sd_log_num_revoke) { 1054fe3e3976SAndreas Gruenbacher if (reserved_blocks) 1055fe3e3976SAndreas Gruenbacher gfs2_log_release(sdp, reserved_blocks); 1056fe3e3976SAndreas Gruenbacher reserved_blocks = sdp->sd_log_blks_reserved; 10572129b428SAndreas Gruenbacher reserved_revokes = sdp->sd_log_num_revoke; 105816ca9412SBenjamin Marzinski if (tr) { 105916ca9412SBenjamin Marzinski sdp->sd_log_tr = NULL; 1060fe3e3976SAndreas Gruenbacher tr->tr_first = first_log_head; 10612129b428SAndreas Gruenbacher if (unlikely (state == SFS_FROZEN)) { 1062ca399c96SBob Peterson if (gfs2_assert_withdraw_delayed(sdp, 1063ca399c96SBob Peterson !tr->tr_num_buf_new && !tr->tr_num_databuf_new)) 10645a61ae14SAndreas Gruenbacher goto out_withdraw; 106516ca9412SBenjamin Marzinski } 10662129b428SAndreas Gruenbacher } 1067fe3e3976SAndreas Gruenbacher } else if (!reserved_blocks) { 1068fe3e3976SAndreas Gruenbacher unsigned int taboo_blocks = GFS2_LOG_FLUSH_MIN_BLOCKS; 1069fe3e3976SAndreas Gruenbacher 1070fe3e3976SAndreas Gruenbacher reserved_blocks = GFS2_LOG_FLUSH_MIN_BLOCKS; 1071fe3e3976SAndreas Gruenbacher if (current == sdp->sd_logd_process) 1072fe3e3976SAndreas Gruenbacher taboo_blocks = 0; 1073fe3e3976SAndreas Gruenbacher 1074fe3e3976SAndreas Gruenbacher if (!__gfs2_log_try_reserve(sdp, reserved_blocks, taboo_blocks)) { 1075fe3e3976SAndreas Gruenbacher up_write(&sdp->sd_log_flush_lock); 1076fe3e3976SAndreas Gruenbacher __gfs2_log_reserve(sdp, reserved_blocks, taboo_blocks); 1077fe3e3976SAndreas Gruenbacher down_write(&sdp->sd_log_flush_lock); 1078fe3e3976SAndreas Gruenbacher goto repeat; 1079fe3e3976SAndreas Gruenbacher } 10802129b428SAndreas Gruenbacher BUG_ON(sdp->sd_log_num_revoke); 1081fe3e3976SAndreas Gruenbacher } 1082fe3e3976SAndreas Gruenbacher 1083fe3e3976SAndreas Gruenbacher if (flags & GFS2_LOG_HEAD_FLUSH_SHUTDOWN) 1084fe3e3976SAndreas Gruenbacher clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); 1085b3b94faaSDavid Teigland 10862e60d768SBenjamin Marzinski if (unlikely(state == SFS_FROZEN)) 10872129b428SAndreas Gruenbacher if (gfs2_assert_withdraw_delayed(sdp, !reserved_revokes)) 10885a61ae14SAndreas Gruenbacher goto out_withdraw; 1089b3b94faaSDavid Teigland 1090d7b616e2SSteven Whitehouse gfs2_ordered_write(sdp); 10912ca0c2fbSBob Peterson if (gfs2_withdrawn(sdp)) 10925a61ae14SAndreas Gruenbacher goto out_withdraw; 1093d69a3c65SSteven Whitehouse lops_before_commit(sdp, tr); 10942ca0c2fbSBob Peterson if (gfs2_withdrawn(sdp)) 10955a61ae14SAndreas Gruenbacher goto out_withdraw; 109682218943SBob Peterson gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE); 10972ca0c2fbSBob Peterson if (gfs2_withdrawn(sdp)) 10985a61ae14SAndreas Gruenbacher goto out_withdraw; 1099d7b616e2SSteven Whitehouse 110034cc1781SSteven Whitehouse if (sdp->sd_log_head != sdp->sd_log_flush_head) { 1101c1696fb8SBob Peterson log_write_header(sdp, flags); 11025cb738b5SAndreas Gruenbacher } else if (sdp->sd_log_tail != sdp->sd_log_flush_tail && !sdp->sd_log_idle) { 1103c1696fb8SBob Peterson log_write_header(sdp, flags); 11042332c443SRobert Peterson } 11052ca0c2fbSBob Peterson if (gfs2_withdrawn(sdp)) 11065a61ae14SAndreas Gruenbacher goto out_withdraw; 110716ca9412SBenjamin Marzinski lops_after_commit(sdp, tr); 1108fe1a698fSSteven Whitehouse 1109fe1a698fSSteven Whitehouse gfs2_log_lock(sdp); 1110faa31ce8SSteven Whitehouse sdp->sd_log_blks_reserved = 0; 1111b3b94faaSDavid Teigland 1112d6a079e8SDave Chinner spin_lock(&sdp->sd_ail_lock); 111316ca9412SBenjamin Marzinski if (tr && !list_empty(&tr->tr_ail1_list)) { 111416ca9412SBenjamin Marzinski list_add(&tr->tr_list, &sdp->sd_ail1_list); 111516ca9412SBenjamin Marzinski tr = NULL; 1116b3b94faaSDavid Teigland } 1117d6a079e8SDave Chinner spin_unlock(&sdp->sd_ail_lock); 1118b3b94faaSDavid Teigland gfs2_log_unlock(sdp); 111924972557SBenjamin Marzinski 1120c1696fb8SBob Peterson if (!(flags & GFS2_LOG_HEAD_FLUSH_NORMAL)) { 112124972557SBenjamin Marzinski if (!sdp->sd_log_idle) { 1122d5dc3d96SBob Peterson empty_ail1_list(sdp); 112330fe70a8SBob Peterson if (gfs2_withdrawn(sdp)) 11245a61ae14SAndreas Gruenbacher goto out_withdraw; 1125c1696fb8SBob Peterson log_write_header(sdp, flags); 112624972557SBenjamin Marzinski } 1127c1696fb8SBob Peterson if (flags & (GFS2_LOG_HEAD_FLUSH_SHUTDOWN | 1128c1696fb8SBob Peterson GFS2_LOG_HEAD_FLUSH_FREEZE)) 112924972557SBenjamin Marzinski gfs2_log_shutdown(sdp); 1130c1696fb8SBob Peterson if (flags & GFS2_LOG_HEAD_FLUSH_FREEZE) 11312e60d768SBenjamin Marzinski atomic_set(&sdp->sd_freeze_state, SFS_FROZEN); 113224972557SBenjamin Marzinski } 113324972557SBenjamin Marzinski 11345a61ae14SAndreas Gruenbacher out_end: 1135fe3e3976SAndreas Gruenbacher used_blocks = log_distance(sdp, sdp->sd_log_flush_head, first_log_head); 11362129b428SAndreas Gruenbacher reserved_revokes += atomic_read(&sdp->sd_log_revokes_available); 11372129b428SAndreas Gruenbacher atomic_set(&sdp->sd_log_revokes_available, sdp->sd_ldptrs); 11382129b428SAndreas Gruenbacher gfs2_assert_withdraw(sdp, reserved_revokes % sdp->sd_inptrs == sdp->sd_ldptrs); 11392129b428SAndreas Gruenbacher if (reserved_revokes > sdp->sd_ldptrs) 11402129b428SAndreas Gruenbacher reserved_blocks += (reserved_revokes - sdp->sd_ldptrs) / sdp->sd_inptrs; 114130fe70a8SBob Peterson out: 11422129b428SAndreas Gruenbacher if (used_blocks != reserved_blocks) { 11432129b428SAndreas Gruenbacher gfs2_assert_withdraw_delayed(sdp, used_blocks < reserved_blocks); 1144fe3e3976SAndreas Gruenbacher gfs2_log_release(sdp, reserved_blocks - used_blocks); 11452129b428SAndreas Gruenbacher } 11465a61ae14SAndreas Gruenbacher up_write(&sdp->sd_log_flush_lock); 11475a61ae14SAndreas Gruenbacher gfs2_trans_free(sdp, tr); 11485a61ae14SAndreas Gruenbacher if (gfs2_withdrawing(sdp)) 11495a61ae14SAndreas Gruenbacher gfs2_withdraw(sdp); 1150fe3e3976SAndreas Gruenbacher trace_gfs2_log_flush(sdp, 0, flags); 11515a61ae14SAndreas Gruenbacher return; 11525a61ae14SAndreas Gruenbacher 11535a61ae14SAndreas Gruenbacher out_withdraw: 1154462582b9SBob Peterson trans_drain(tr); 115558e08e8dSBob Peterson /** 115658e08e8dSBob Peterson * If the tr_list is empty, we're withdrawing during a log 115758e08e8dSBob Peterson * flush that targets a transaction, but the transaction was 115858e08e8dSBob Peterson * never queued onto any of the ail lists. Here we add it to 115958e08e8dSBob Peterson * ail1 just so that ail_drain() will find and free it. 116058e08e8dSBob Peterson */ 116158e08e8dSBob Peterson spin_lock(&sdp->sd_ail_lock); 116258e08e8dSBob Peterson if (tr && list_empty(&tr->tr_list)) 116358e08e8dSBob Peterson list_add(&tr->tr_list, &sdp->sd_ail1_list); 116458e08e8dSBob Peterson spin_unlock(&sdp->sd_ail_lock); 11652ca0c2fbSBob Peterson tr = NULL; 11665a61ae14SAndreas Gruenbacher goto out_end; 1167b3b94faaSDavid Teigland } 1168b3b94faaSDavid Teigland 1169d69a3c65SSteven Whitehouse /** 1170d69a3c65SSteven Whitehouse * gfs2_merge_trans - Merge a new transaction into a cached transaction 1171c551f66cSLee Jones * @sdp: the filesystem 1172d69a3c65SSteven Whitehouse * @new: New transaction to be merged 1173d69a3c65SSteven Whitehouse */ 1174d69a3c65SSteven Whitehouse 117583d060caSBob Peterson static void gfs2_merge_trans(struct gfs2_sbd *sdp, struct gfs2_trans *new) 1176d69a3c65SSteven Whitehouse { 117783d060caSBob Peterson struct gfs2_trans *old = sdp->sd_log_tr; 117883d060caSBob Peterson 11799862ca05SBob Peterson WARN_ON_ONCE(!test_bit(TR_ATTACHED, &old->tr_flags)); 1180d69a3c65SSteven Whitehouse 1181d69a3c65SSteven Whitehouse old->tr_num_buf_new += new->tr_num_buf_new; 1182d69a3c65SSteven Whitehouse old->tr_num_databuf_new += new->tr_num_databuf_new; 1183d69a3c65SSteven Whitehouse old->tr_num_buf_rm += new->tr_num_buf_rm; 1184d69a3c65SSteven Whitehouse old->tr_num_databuf_rm += new->tr_num_databuf_rm; 11852129b428SAndreas Gruenbacher old->tr_revokes += new->tr_revokes; 1186d69a3c65SSteven Whitehouse old->tr_num_revoke += new->tr_num_revoke; 1187d69a3c65SSteven Whitehouse 1188d69a3c65SSteven Whitehouse list_splice_tail_init(&new->tr_databuf, &old->tr_databuf); 1189d69a3c65SSteven Whitehouse list_splice_tail_init(&new->tr_buf, &old->tr_buf); 119083d060caSBob Peterson 119183d060caSBob Peterson spin_lock(&sdp->sd_ail_lock); 119283d060caSBob Peterson list_splice_tail_init(&new->tr_ail1_list, &old->tr_ail1_list); 119383d060caSBob Peterson list_splice_tail_init(&new->tr_ail2_list, &old->tr_ail2_list); 119483d060caSBob Peterson spin_unlock(&sdp->sd_ail_lock); 1195d69a3c65SSteven Whitehouse } 1196d69a3c65SSteven Whitehouse 1197b3b94faaSDavid Teigland static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 1198b3b94faaSDavid Teigland { 11992332c443SRobert Peterson unsigned int reserved; 1200ac39aaddSSteven Whitehouse unsigned int unused; 1201022ef4feSSteven Whitehouse unsigned int maxres; 1202b3b94faaSDavid Teigland 1203b3b94faaSDavid Teigland gfs2_log_lock(sdp); 1204b3b94faaSDavid Teigland 1205d69a3c65SSteven Whitehouse if (sdp->sd_log_tr) { 120683d060caSBob Peterson gfs2_merge_trans(sdp, tr); 1207d69a3c65SSteven Whitehouse } else if (tr->tr_num_buf_new || tr->tr_num_databuf_new) { 1208c968f578SAndreas Gruenbacher gfs2_assert_withdraw(sdp, !test_bit(TR_ONSTACK, &tr->tr_flags)); 120916ca9412SBenjamin Marzinski sdp->sd_log_tr = tr; 12109862ca05SBob Peterson set_bit(TR_ATTACHED, &tr->tr_flags); 121116ca9412SBenjamin Marzinski } 1212022ef4feSSteven Whitehouse 1213022ef4feSSteven Whitehouse reserved = calc_reserved(sdp); 1214022ef4feSSteven Whitehouse maxres = sdp->sd_log_blks_reserved + tr->tr_reserved; 1215022ef4feSSteven Whitehouse gfs2_assert_withdraw(sdp, maxres >= reserved); 1216022ef4feSSteven Whitehouse unused = maxres - reserved; 12175ae8fff8SAndreas Gruenbacher if (unused) 1218c1eba1b0SAndreas Gruenbacher gfs2_log_release(sdp, unused); 1219022ef4feSSteven Whitehouse sdp->sd_log_blks_reserved = reserved; 1220022ef4feSSteven Whitehouse 1221b3b94faaSDavid Teigland gfs2_log_unlock(sdp); 1222b3b94faaSDavid Teigland } 1223b3b94faaSDavid Teigland 1224b3b94faaSDavid Teigland /** 1225b3b94faaSDavid Teigland * gfs2_log_commit - Commit a transaction to the log 1226b3b94faaSDavid Teigland * @sdp: the filesystem 1227b3b94faaSDavid Teigland * @tr: the transaction 1228b3b94faaSDavid Teigland * 12295e687eacSBenjamin Marzinski * We wake up gfs2_logd if the number of pinned blocks exceed thresh1 12305e687eacSBenjamin Marzinski * or the total number of used blocks (pinned blocks plus AIL blocks) 12315e687eacSBenjamin Marzinski * is greater than thresh2. 12325e687eacSBenjamin Marzinski * 1233b57bc0fbSBob Peterson * At mount time thresh1 is 2/5ths of journal size, thresh2 is 4/5ths of 12345e687eacSBenjamin Marzinski * journal size. 12355e687eacSBenjamin Marzinski * 1236b3b94faaSDavid Teigland * Returns: errno 1237b3b94faaSDavid Teigland */ 1238b3b94faaSDavid Teigland 1239b3b94faaSDavid Teigland void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 1240b3b94faaSDavid Teigland { 1241b3b94faaSDavid Teigland log_refund(sdp, tr); 1242b3b94faaSDavid Teigland 12435e687eacSBenjamin Marzinski if (atomic_read(&sdp->sd_log_pinned) > atomic_read(&sdp->sd_log_thresh1) || 12445e687eacSBenjamin Marzinski ((sdp->sd_jdesc->jd_blocks - atomic_read(&sdp->sd_log_blks_free)) > 12455e687eacSBenjamin Marzinski atomic_read(&sdp->sd_log_thresh2))) 12465e687eacSBenjamin Marzinski wake_up(&sdp->sd_logd_waitq); 1247faa31ce8SSteven Whitehouse } 1248b3b94faaSDavid Teigland 1249b3b94faaSDavid Teigland /** 1250b3b94faaSDavid Teigland * gfs2_log_shutdown - write a shutdown header into a journal 1251b3b94faaSDavid Teigland * @sdp: the filesystem 1252b3b94faaSDavid Teigland * 1253b3b94faaSDavid Teigland */ 1254b3b94faaSDavid Teigland 1255feed98a8SBob Peterson static void gfs2_log_shutdown(struct gfs2_sbd *sdp) 1256b3b94faaSDavid Teigland { 1257b3b94faaSDavid Teigland gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); 1258b3b94faaSDavid Teigland gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); 1259b3b94faaSDavid Teigland gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list)); 1260b3b94faaSDavid Teigland 1261805c0907SBob Peterson log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT | GFS2_LFC_SHUTDOWN); 1262fe3e3976SAndreas Gruenbacher log_pull_tail(sdp); 1263b3b94faaSDavid Teigland 1264a74604beSSteven Whitehouse gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail); 1265a74604beSSteven Whitehouse gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list)); 1266a25311c8SSteven Whitehouse } 1267a25311c8SSteven Whitehouse 12685e687eacSBenjamin Marzinski static inline int gfs2_jrnl_flush_reqd(struct gfs2_sbd *sdp) 12695e687eacSBenjamin Marzinski { 1270f07b3520SBob Peterson return (atomic_read(&sdp->sd_log_pinned) + 1271f07b3520SBob Peterson atomic_read(&sdp->sd_log_blks_needed) >= 1272f07b3520SBob Peterson atomic_read(&sdp->sd_log_thresh1)); 12735e687eacSBenjamin Marzinski } 12745e687eacSBenjamin Marzinski 12755e687eacSBenjamin Marzinski static inline int gfs2_ail_flush_reqd(struct gfs2_sbd *sdp) 12765e687eacSBenjamin Marzinski { 12775e687eacSBenjamin Marzinski unsigned int used_blocks = sdp->sd_jdesc->jd_blocks - atomic_read(&sdp->sd_log_blks_free); 1278b066a4eeSAbhi Das 1279b066a4eeSAbhi Das if (test_and_clear_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags)) 1280b066a4eeSAbhi Das return 1; 1281b066a4eeSAbhi Das 1282f07b3520SBob Peterson return used_blocks + atomic_read(&sdp->sd_log_blks_needed) >= 1283f07b3520SBob Peterson atomic_read(&sdp->sd_log_thresh2); 12845e687eacSBenjamin Marzinski } 1285ec69b188SSteven Whitehouse 1286ec69b188SSteven Whitehouse /** 1287ec69b188SSteven Whitehouse * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks 1288c551f66cSLee Jones * @data: Pointer to GFS2 superblock 1289ec69b188SSteven Whitehouse * 1290ec69b188SSteven Whitehouse * Also, periodically check to make sure that we're using the most recent 1291ec69b188SSteven Whitehouse * journal index. 1292ec69b188SSteven Whitehouse */ 1293ec69b188SSteven Whitehouse 1294ec69b188SSteven Whitehouse int gfs2_logd(void *data) 1295ec69b188SSteven Whitehouse { 1296ec69b188SSteven Whitehouse struct gfs2_sbd *sdp = data; 12975e687eacSBenjamin Marzinski unsigned long t = 1; 12985e687eacSBenjamin Marzinski DEFINE_WAIT(wait); 1299ec69b188SSteven Whitehouse 1300ec69b188SSteven Whitehouse while (!kthread_should_stop()) { 1301ec69b188SSteven Whitehouse 1302d22f69a0SBob Peterson if (gfs2_withdrawn(sdp)) { 1303d22f69a0SBob Peterson msleep_interruptible(HZ); 1304d22f69a0SBob Peterson continue; 1305d22f69a0SBob Peterson } 1306942b0cddSBob Peterson /* Check for errors writing to the journal */ 1307942b0cddSBob Peterson if (sdp->sd_log_error) { 1308badb55ecSAndreas Gruenbacher gfs2_lm(sdp, 1309942b0cddSBob Peterson "GFS2: fsid=%s: error %d: " 1310942b0cddSBob Peterson "withdrawing the file system to " 1311942b0cddSBob Peterson "prevent further damage.\n", 1312942b0cddSBob Peterson sdp->sd_fsname, sdp->sd_log_error); 1313badb55ecSAndreas Gruenbacher gfs2_withdraw(sdp); 1314d22f69a0SBob Peterson continue; 1315942b0cddSBob Peterson } 1316942b0cddSBob Peterson 13175e687eacSBenjamin Marzinski if (gfs2_jrnl_flush_reqd(sdp) || t == 0) { 13185e4c7632SBob Peterson gfs2_ail1_empty(sdp, 0); 1319805c0907SBob Peterson gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL | 1320805c0907SBob Peterson GFS2_LFC_LOGD_JFLUSH_REQD); 1321ec69b188SSteven Whitehouse } 1322ec69b188SSteven Whitehouse 13235e687eacSBenjamin Marzinski if (gfs2_ail_flush_reqd(sdp)) { 13245e687eacSBenjamin Marzinski gfs2_ail1_start(sdp); 132526b06a69SSteven Whitehouse gfs2_ail1_wait(sdp); 13265e4c7632SBob Peterson gfs2_ail1_empty(sdp, 0); 1327805c0907SBob Peterson gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL | 1328805c0907SBob Peterson GFS2_LFC_LOGD_AIL_FLUSH_REQD); 13295e687eacSBenjamin Marzinski } 13305e687eacSBenjamin Marzinski 1331ec69b188SSteven Whitehouse t = gfs2_tune_get(sdp, gt_logd_secs) * HZ; 1332a0acae0eSTejun Heo 1333a0acae0eSTejun Heo try_to_freeze(); 13345e687eacSBenjamin Marzinski 13355e687eacSBenjamin Marzinski do { 13365e687eacSBenjamin Marzinski prepare_to_wait(&sdp->sd_logd_waitq, &wait, 13375f487490SSteven Whitehouse TASK_INTERRUPTIBLE); 13385e687eacSBenjamin Marzinski if (!gfs2_ail_flush_reqd(sdp) && 13395e687eacSBenjamin Marzinski !gfs2_jrnl_flush_reqd(sdp) && 13405e687eacSBenjamin Marzinski !kthread_should_stop()) 13415e687eacSBenjamin Marzinski t = schedule_timeout(t); 13425e687eacSBenjamin Marzinski } while(t && !gfs2_ail_flush_reqd(sdp) && 13435e687eacSBenjamin Marzinski !gfs2_jrnl_flush_reqd(sdp) && 13445e687eacSBenjamin Marzinski !kthread_should_stop()); 13455e687eacSBenjamin Marzinski finish_wait(&sdp->sd_logd_waitq, &wait); 1346ec69b188SSteven Whitehouse } 1347ec69b188SSteven Whitehouse 1348ec69b188SSteven Whitehouse return 0; 1349ec69b188SSteven Whitehouse } 1350ec69b188SSteven Whitehouse 1351