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 833822a7c4SLinus Torvalds static int __gfs2_writepage(struct folio *folio, struct writeback_control *wbc, 8495ecbd0fSAndreas Gruenbacher void *data) 8595ecbd0fSAndreas Gruenbacher { 8695ecbd0fSAndreas Gruenbacher struct address_space *mapping = data; 873822a7c4SLinus Torvalds int ret = mapping->a_ops->writepage(&folio->page, wbc); 8895ecbd0fSAndreas Gruenbacher mapping_set_error(mapping, ret); 8995ecbd0fSAndreas Gruenbacher return ret; 9095ecbd0fSAndreas Gruenbacher } 9195ecbd0fSAndreas Gruenbacher 921e1a3d03SSteven Whitehouse /** 93c551f66cSLee Jones * gfs2_ail1_start_one - Start I/O on a transaction 94c551f66cSLee Jones * @sdp: The superblock 954667a0ecSSteven Whitehouse * @wbc: The writeback control structure 96c551f66cSLee Jones * @tr: The transaction to start I/O on 97c551f66cSLee Jones * @plug: The block plug currently active 98ddacfaf7SSteven Whitehouse */ 99ddacfaf7SSteven Whitehouse 1004f1de018SSteven Whitehouse static int gfs2_ail1_start_one(struct gfs2_sbd *sdp, 1014667a0ecSSteven Whitehouse struct writeback_control *wbc, 10217d77684SBob Peterson struct gfs2_trans *tr, struct blk_plug *plug) 103d6a079e8SDave Chinner __releases(&sdp->sd_ail_lock) 104d6a079e8SDave Chinner __acquires(&sdp->sd_ail_lock) 105ddacfaf7SSteven Whitehouse { 1065ac048bbSSteven Whitehouse struct gfs2_glock *gl = NULL; 1074667a0ecSSteven Whitehouse struct address_space *mapping; 108ddacfaf7SSteven Whitehouse struct gfs2_bufdata *bd, *s; 109ddacfaf7SSteven Whitehouse struct buffer_head *bh; 110b1676cbbSBob Peterson int ret = 0; 111ddacfaf7SSteven Whitehouse 11216ca9412SBenjamin Marzinski list_for_each_entry_safe_reverse(bd, s, &tr->tr_ail1_list, bd_ail_st_list) { 113ddacfaf7SSteven Whitehouse bh = bd->bd_bh; 114ddacfaf7SSteven Whitehouse 11516ca9412SBenjamin Marzinski gfs2_assert(sdp, bd->bd_tr == tr); 116ddacfaf7SSteven Whitehouse 117ddacfaf7SSteven Whitehouse if (!buffer_busy(bh)) { 11830fe70a8SBob Peterson if (buffer_uptodate(bh)) { 11930fe70a8SBob Peterson list_move(&bd->bd_ail_st_list, 12030fe70a8SBob Peterson &tr->tr_ail2_list); 12130fe70a8SBob Peterson continue; 12230fe70a8SBob Peterson } 123036330c9SBob Peterson if (!cmpxchg(&sdp->sd_log_error, 0, -EIO)) { 124ddacfaf7SSteven Whitehouse gfs2_io_error_bh(sdp, bh); 12569511080SBob Peterson gfs2_withdraw_delayed(sdp); 1269e1a9ecdSAndreas Gruenbacher } 127ddacfaf7SSteven Whitehouse } 128ddacfaf7SSteven Whitehouse 12930fe70a8SBob Peterson if (gfs2_withdrawn(sdp)) { 13030fe70a8SBob Peterson gfs2_remove_from_ail(bd); 13130fe70a8SBob Peterson continue; 13230fe70a8SBob Peterson } 133ddacfaf7SSteven Whitehouse if (!buffer_dirty(bh)) 134ddacfaf7SSteven Whitehouse continue; 1355ac048bbSSteven Whitehouse if (gl == bd->bd_gl) 1365ac048bbSSteven Whitehouse continue; 1375ac048bbSSteven Whitehouse gl = bd->bd_gl; 13816ca9412SBenjamin Marzinski list_move(&bd->bd_ail_st_list, &tr->tr_ail1_list); 13911551cf1SMatthew Wilcox (Oracle) mapping = bh->b_folio->mapping; 1404f1de018SSteven Whitehouse if (!mapping) 1414f1de018SSteven Whitehouse continue; 142d6a079e8SDave Chinner spin_unlock(&sdp->sd_ail_lock); 14395ecbd0fSAndreas Gruenbacher ret = write_cache_pages(mapping, wbc, __gfs2_writepage, mapping); 14417d77684SBob Peterson if (need_resched()) { 14517d77684SBob Peterson blk_finish_plug(plug); 14617d77684SBob Peterson cond_resched(); 14717d77684SBob Peterson blk_start_plug(plug); 14817d77684SBob Peterson } 149d6a079e8SDave Chinner spin_lock(&sdp->sd_ail_lock); 1504e79e3f0SBob Peterson if (ret == -ENODATA) /* if a jdata write into a new hole */ 1514e79e3f0SBob Peterson ret = 0; /* ignore it */ 152b1676cbbSBob Peterson if (ret || wbc->nr_to_write <= 0) 153ddacfaf7SSteven Whitehouse break; 154b1676cbbSBob Peterson return -EBUSY; 155ddacfaf7SSteven Whitehouse } 1564f1de018SSteven Whitehouse 157b1676cbbSBob Peterson return ret; 1584667a0ecSSteven Whitehouse } 1594667a0ecSSteven Whitehouse 1609592ea80SBob Peterson static void dump_ail_list(struct gfs2_sbd *sdp) 1619592ea80SBob Peterson { 1629592ea80SBob Peterson struct gfs2_trans *tr; 1639592ea80SBob Peterson struct gfs2_bufdata *bd; 1649592ea80SBob Peterson struct buffer_head *bh; 1659592ea80SBob Peterson 1669592ea80SBob Peterson list_for_each_entry_reverse(tr, &sdp->sd_ail1_list, tr_list) { 1679592ea80SBob Peterson list_for_each_entry_reverse(bd, &tr->tr_ail1_list, 1689592ea80SBob Peterson bd_ail_st_list) { 1699592ea80SBob Peterson bh = bd->bd_bh; 1709592ea80SBob Peterson fs_err(sdp, "bd %p: blk:0x%llx bh=%p ", bd, 1719592ea80SBob Peterson (unsigned long long)bd->bd_blkno, bh); 1729592ea80SBob Peterson if (!bh) { 1739592ea80SBob Peterson fs_err(sdp, "\n"); 1749592ea80SBob Peterson continue; 1759592ea80SBob Peterson } 1769592ea80SBob Peterson fs_err(sdp, "0x%llx up2:%d dirt:%d lkd:%d req:%d " 1779592ea80SBob Peterson "map:%d new:%d ar:%d aw:%d delay:%d " 1789592ea80SBob Peterson "io err:%d unwritten:%d dfr:%d pin:%d esc:%d\n", 1799592ea80SBob Peterson (unsigned long long)bh->b_blocknr, 1809592ea80SBob Peterson buffer_uptodate(bh), buffer_dirty(bh), 1819592ea80SBob Peterson buffer_locked(bh), buffer_req(bh), 1829592ea80SBob Peterson buffer_mapped(bh), buffer_new(bh), 1839592ea80SBob Peterson buffer_async_read(bh), buffer_async_write(bh), 1849592ea80SBob Peterson buffer_delay(bh), buffer_write_io_error(bh), 1859592ea80SBob Peterson buffer_unwritten(bh), 1869592ea80SBob Peterson buffer_defer_completion(bh), 1879592ea80SBob Peterson buffer_pinned(bh), buffer_escaped(bh)); 1889592ea80SBob Peterson } 1899592ea80SBob Peterson } 1909592ea80SBob Peterson } 1914667a0ecSSteven Whitehouse 1924667a0ecSSteven Whitehouse /** 1934667a0ecSSteven Whitehouse * gfs2_ail1_flush - start writeback of some ail1 entries 1944667a0ecSSteven Whitehouse * @sdp: The super block 1954667a0ecSSteven Whitehouse * @wbc: The writeback control structure 1964667a0ecSSteven Whitehouse * 1974667a0ecSSteven Whitehouse * Writes back some ail1 entries, according to the limits in the 1984667a0ecSSteven Whitehouse * writeback control structure 1994667a0ecSSteven Whitehouse */ 2004667a0ecSSteven Whitehouse 2014667a0ecSSteven Whitehouse void gfs2_ail1_flush(struct gfs2_sbd *sdp, struct writeback_control *wbc) 2024667a0ecSSteven Whitehouse { 2034667a0ecSSteven Whitehouse struct list_head *head = &sdp->sd_ail1_list; 20416ca9412SBenjamin Marzinski struct gfs2_trans *tr; 205885bcecaSSteven Whitehouse struct blk_plug plug; 20675b46c43SBob Peterson int ret; 2079592ea80SBob Peterson unsigned long flush_start = jiffies; 2084667a0ecSSteven Whitehouse 209c83ae9caSSteven Whitehouse trace_gfs2_ail_flush(sdp, wbc, 1); 210885bcecaSSteven Whitehouse blk_start_plug(&plug); 2114667a0ecSSteven Whitehouse spin_lock(&sdp->sd_ail_lock); 2124f1de018SSteven Whitehouse restart: 21375b46c43SBob Peterson ret = 0; 2149592ea80SBob Peterson if (time_after(jiffies, flush_start + (HZ * 600))) { 215d5dc3d96SBob Peterson fs_err(sdp, "Error: In %s for ten minutes! t=%d\n", 216d5dc3d96SBob Peterson __func__, current->journal_info ? 1 : 0); 2179592ea80SBob Peterson dump_ail_list(sdp); 2189592ea80SBob Peterson goto out; 2199592ea80SBob Peterson } 22016ca9412SBenjamin Marzinski list_for_each_entry_reverse(tr, head, tr_list) { 2214667a0ecSSteven Whitehouse if (wbc->nr_to_write <= 0) 2224667a0ecSSteven Whitehouse break; 22317d77684SBob Peterson ret = gfs2_ail1_start_one(sdp, wbc, tr, &plug); 224b1676cbbSBob Peterson if (ret) { 225b1676cbbSBob Peterson if (ret == -EBUSY) 2264f1de018SSteven Whitehouse goto restart; 227b1676cbbSBob Peterson break; 228b1676cbbSBob Peterson } 2294667a0ecSSteven Whitehouse } 2309592ea80SBob Peterson out: 2314667a0ecSSteven Whitehouse spin_unlock(&sdp->sd_ail_lock); 232885bcecaSSteven Whitehouse blk_finish_plug(&plug); 23349003128SBob Peterson if (ret) { 234b2b0a5e9SChristoph Hellwig gfs2_lm(sdp, "gfs2_ail1_start_one returned: %d\n", ret); 235badb55ecSAndreas Gruenbacher gfs2_withdraw(sdp); 23649003128SBob Peterson } 237c83ae9caSSteven Whitehouse trace_gfs2_ail_flush(sdp, wbc, 0); 2384667a0ecSSteven Whitehouse } 2394667a0ecSSteven Whitehouse 2404667a0ecSSteven Whitehouse /** 2414667a0ecSSteven Whitehouse * gfs2_ail1_start - start writeback of all ail1 entries 2424667a0ecSSteven Whitehouse * @sdp: The superblock 2434667a0ecSSteven Whitehouse */ 2444667a0ecSSteven Whitehouse 2454667a0ecSSteven Whitehouse static void gfs2_ail1_start(struct gfs2_sbd *sdp) 2464667a0ecSSteven Whitehouse { 2474667a0ecSSteven Whitehouse struct writeback_control wbc = { 2484667a0ecSSteven Whitehouse .sync_mode = WB_SYNC_NONE, 2494667a0ecSSteven Whitehouse .nr_to_write = LONG_MAX, 2504667a0ecSSteven Whitehouse .range_start = 0, 2514667a0ecSSteven Whitehouse .range_end = LLONG_MAX, 2524667a0ecSSteven Whitehouse }; 2534667a0ecSSteven Whitehouse 2544667a0ecSSteven Whitehouse return gfs2_ail1_flush(sdp, &wbc); 255ddacfaf7SSteven Whitehouse } 256ddacfaf7SSteven Whitehouse 2575cb738b5SAndreas Gruenbacher static void gfs2_log_update_flush_tail(struct gfs2_sbd *sdp) 2585cb738b5SAndreas Gruenbacher { 2595cb738b5SAndreas Gruenbacher unsigned int new_flush_tail = sdp->sd_log_head; 2605cb738b5SAndreas Gruenbacher struct gfs2_trans *tr; 2615cb738b5SAndreas Gruenbacher 2625cb738b5SAndreas Gruenbacher if (!list_empty(&sdp->sd_ail1_list)) { 2635cb738b5SAndreas Gruenbacher tr = list_last_entry(&sdp->sd_ail1_list, 2645cb738b5SAndreas Gruenbacher struct gfs2_trans, tr_list); 2655cb738b5SAndreas Gruenbacher new_flush_tail = tr->tr_first; 2665cb738b5SAndreas Gruenbacher } 2675cb738b5SAndreas Gruenbacher sdp->sd_log_flush_tail = new_flush_tail; 2685cb738b5SAndreas Gruenbacher } 2695cb738b5SAndreas Gruenbacher 2705cb738b5SAndreas Gruenbacher static void gfs2_log_update_head(struct gfs2_sbd *sdp) 2715cb738b5SAndreas Gruenbacher { 2725cb738b5SAndreas Gruenbacher unsigned int new_head = sdp->sd_log_flush_head; 2735cb738b5SAndreas Gruenbacher 2745cb738b5SAndreas Gruenbacher if (sdp->sd_log_flush_tail == sdp->sd_log_head) 2755cb738b5SAndreas Gruenbacher sdp->sd_log_flush_tail = new_head; 2765cb738b5SAndreas Gruenbacher sdp->sd_log_head = new_head; 2775cb738b5SAndreas Gruenbacher } 2785cb738b5SAndreas Gruenbacher 279c551f66cSLee Jones /* 28076fce654SAndreas Gruenbacher * gfs2_ail_empty_tr - empty one of the ail lists of a transaction 28176fce654SAndreas Gruenbacher */ 28276fce654SAndreas Gruenbacher 28376fce654SAndreas Gruenbacher static void gfs2_ail_empty_tr(struct gfs2_sbd *sdp, struct gfs2_trans *tr, 28476fce654SAndreas Gruenbacher struct list_head *head) 28576fce654SAndreas Gruenbacher { 28676fce654SAndreas Gruenbacher struct gfs2_bufdata *bd; 28776fce654SAndreas Gruenbacher 28876fce654SAndreas Gruenbacher while (!list_empty(head)) { 28976fce654SAndreas Gruenbacher bd = list_first_entry(head, struct gfs2_bufdata, 29076fce654SAndreas Gruenbacher bd_ail_st_list); 29176fce654SAndreas Gruenbacher gfs2_assert(sdp, bd->bd_tr == tr); 29276fce654SAndreas Gruenbacher gfs2_remove_from_ail(bd); 29376fce654SAndreas Gruenbacher } 29476fce654SAndreas Gruenbacher } 29576fce654SAndreas Gruenbacher 296ddacfaf7SSteven Whitehouse /** 297ddacfaf7SSteven Whitehouse * gfs2_ail1_empty_one - Check whether or not a trans in the AIL has been synced 298ddacfaf7SSteven Whitehouse * @sdp: the filesystem 2995e4c7632SBob Peterson * @tr: the transaction 3005e4c7632SBob Peterson * @max_revokes: If nonzero, issue revokes for the bd items for written buffers 301ddacfaf7SSteven Whitehouse * 30236c78309SBob Peterson * returns: the transaction's count of remaining active items 303ddacfaf7SSteven Whitehouse */ 304ddacfaf7SSteven Whitehouse 30536c78309SBob Peterson static int gfs2_ail1_empty_one(struct gfs2_sbd *sdp, struct gfs2_trans *tr, 3065e4c7632SBob Peterson int *max_revokes) 307ddacfaf7SSteven Whitehouse { 308ddacfaf7SSteven Whitehouse struct gfs2_bufdata *bd, *s; 309ddacfaf7SSteven Whitehouse struct buffer_head *bh; 31036c78309SBob Peterson int active_count = 0; 311ddacfaf7SSteven Whitehouse 31216ca9412SBenjamin Marzinski list_for_each_entry_safe_reverse(bd, s, &tr->tr_ail1_list, 313ddacfaf7SSteven Whitehouse bd_ail_st_list) { 314ddacfaf7SSteven Whitehouse bh = bd->bd_bh; 31516ca9412SBenjamin Marzinski gfs2_assert(sdp, bd->bd_tr == tr); 316036330c9SBob Peterson /* 317036330c9SBob Peterson * If another process flagged an io error, e.g. writing to the 318036330c9SBob Peterson * journal, error all other bhs and move them off the ail1 to 319036330c9SBob Peterson * prevent a tight loop when unmount tries to flush ail1, 320036330c9SBob Peterson * regardless of whether they're still busy. If no outside 321036330c9SBob Peterson * errors were found and the buffer is busy, move to the next. 322036330c9SBob Peterson * If the ail buffer is not busy and caught an error, flag it 323036330c9SBob Peterson * for others. 324036330c9SBob Peterson */ 32536c78309SBob Peterson if (!sdp->sd_log_error && buffer_busy(bh)) { 32636c78309SBob Peterson active_count++; 327ddacfaf7SSteven Whitehouse continue; 32836c78309SBob Peterson } 329b524abccSBob Peterson if (!buffer_uptodate(bh) && 330036330c9SBob Peterson !cmpxchg(&sdp->sd_log_error, 0, -EIO)) { 331ddacfaf7SSteven Whitehouse gfs2_io_error_bh(sdp, bh); 33269511080SBob Peterson gfs2_withdraw_delayed(sdp); 3339e1a9ecdSAndreas Gruenbacher } 3345e4c7632SBob Peterson /* 3355e4c7632SBob Peterson * If we have space for revokes and the bd is no longer on any 3365e4c7632SBob Peterson * buf list, we can just add a revoke for it immediately and 3375e4c7632SBob Peterson * avoid having to put it on the ail2 list, where it would need 3385e4c7632SBob Peterson * to be revoked later. 3395e4c7632SBob Peterson */ 3405e4c7632SBob Peterson if (*max_revokes && list_empty(&bd->bd_list)) { 3415e4c7632SBob Peterson gfs2_add_revoke(sdp, bd); 3425e4c7632SBob Peterson (*max_revokes)--; 3435e4c7632SBob Peterson continue; 3445e4c7632SBob Peterson } 34516ca9412SBenjamin Marzinski list_move(&bd->bd_ail_st_list, &tr->tr_ail2_list); 346ddacfaf7SSteven Whitehouse } 34736c78309SBob Peterson return active_count; 348ddacfaf7SSteven Whitehouse } 349ddacfaf7SSteven Whitehouse 3504667a0ecSSteven Whitehouse /** 3514667a0ecSSteven Whitehouse * gfs2_ail1_empty - Try to empty the ail1 lists 3524667a0ecSSteven Whitehouse * @sdp: The superblock 3535e4c7632SBob Peterson * @max_revokes: If non-zero, add revokes where appropriate 3544667a0ecSSteven Whitehouse * 3554667a0ecSSteven Whitehouse * Tries to empty the ail1 lists, starting with the oldest first 3564667a0ecSSteven Whitehouse */ 357b3b94faaSDavid Teigland 3585e4c7632SBob Peterson static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int max_revokes) 359b3b94faaSDavid Teigland { 36016ca9412SBenjamin Marzinski struct gfs2_trans *tr, *s; 3615d054964SBenjamin Marzinski int oldest_tr = 1; 362b3b94faaSDavid Teigland int ret; 363b3b94faaSDavid Teigland 364d6a079e8SDave Chinner spin_lock(&sdp->sd_ail_lock); 36516ca9412SBenjamin Marzinski list_for_each_entry_safe_reverse(tr, s, &sdp->sd_ail1_list, tr_list) { 36636c78309SBob Peterson if (!gfs2_ail1_empty_one(sdp, tr, &max_revokes) && oldest_tr) 36716ca9412SBenjamin Marzinski list_move(&tr->tr_list, &sdp->sd_ail2_list); 3684667a0ecSSteven Whitehouse else 3695d054964SBenjamin Marzinski oldest_tr = 0; 370b3b94faaSDavid Teigland } 3715cb738b5SAndreas Gruenbacher gfs2_log_update_flush_tail(sdp); 372b3b94faaSDavid Teigland ret = list_empty(&sdp->sd_ail1_list); 373d6a079e8SDave Chinner spin_unlock(&sdp->sd_ail_lock); 374b3b94faaSDavid Teigland 37569511080SBob Peterson if (test_bit(SDF_WITHDRAWING, &sdp->sd_flags)) { 376badb55ecSAndreas Gruenbacher gfs2_lm(sdp, "fatal: I/O error(s)\n"); 377badb55ecSAndreas Gruenbacher gfs2_withdraw(sdp); 378badb55ecSAndreas Gruenbacher } 3799e1a9ecdSAndreas Gruenbacher 380b3b94faaSDavid Teigland return ret; 381b3b94faaSDavid Teigland } 382b3b94faaSDavid Teigland 38326b06a69SSteven Whitehouse static void gfs2_ail1_wait(struct gfs2_sbd *sdp) 38426b06a69SSteven Whitehouse { 38516ca9412SBenjamin Marzinski struct gfs2_trans *tr; 38626b06a69SSteven Whitehouse struct gfs2_bufdata *bd; 38726b06a69SSteven Whitehouse struct buffer_head *bh; 38826b06a69SSteven Whitehouse 38926b06a69SSteven Whitehouse spin_lock(&sdp->sd_ail_lock); 39016ca9412SBenjamin Marzinski list_for_each_entry_reverse(tr, &sdp->sd_ail1_list, tr_list) { 39116ca9412SBenjamin Marzinski list_for_each_entry(bd, &tr->tr_ail1_list, bd_ail_st_list) { 39226b06a69SSteven Whitehouse bh = bd->bd_bh; 39326b06a69SSteven Whitehouse if (!buffer_locked(bh)) 39426b06a69SSteven Whitehouse continue; 39526b06a69SSteven Whitehouse get_bh(bh); 39626b06a69SSteven Whitehouse spin_unlock(&sdp->sd_ail_lock); 39726b06a69SSteven Whitehouse wait_on_buffer(bh); 39826b06a69SSteven Whitehouse brelse(bh); 39926b06a69SSteven Whitehouse return; 40026b06a69SSteven Whitehouse } 40126b06a69SSteven Whitehouse } 40226b06a69SSteven Whitehouse spin_unlock(&sdp->sd_ail_lock); 40326b06a69SSteven Whitehouse } 404ddacfaf7SSteven Whitehouse 4056e80674aSAndreas Gruenbacher static void __ail2_empty(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 406ddacfaf7SSteven Whitehouse { 4072ca0c2fbSBob Peterson gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail2_list); 40816ca9412SBenjamin Marzinski list_del(&tr->tr_list); 40916ca9412SBenjamin Marzinski gfs2_assert_warn(sdp, list_empty(&tr->tr_ail1_list)); 41016ca9412SBenjamin Marzinski gfs2_assert_warn(sdp, list_empty(&tr->tr_ail2_list)); 411b839dadaSBob Peterson gfs2_trans_free(sdp, tr); 412b3b94faaSDavid Teigland } 413b3b94faaSDavid Teigland 4146e80674aSAndreas Gruenbacher static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) 4156e80674aSAndreas Gruenbacher { 4166e80674aSAndreas Gruenbacher struct list_head *ail2_list = &sdp->sd_ail2_list; 4176e80674aSAndreas Gruenbacher unsigned int old_tail = sdp->sd_log_tail; 4186e80674aSAndreas Gruenbacher struct gfs2_trans *tr, *safe; 4196e80674aSAndreas Gruenbacher 4206e80674aSAndreas Gruenbacher spin_lock(&sdp->sd_ail_lock); 4216e80674aSAndreas Gruenbacher if (old_tail <= new_tail) { 4226e80674aSAndreas Gruenbacher list_for_each_entry_safe(tr, safe, ail2_list, tr_list) { 4236e80674aSAndreas Gruenbacher if (old_tail <= tr->tr_first && tr->tr_first < new_tail) 4246e80674aSAndreas Gruenbacher __ail2_empty(sdp, tr); 4256e80674aSAndreas Gruenbacher } 4266e80674aSAndreas Gruenbacher } else { 4276e80674aSAndreas Gruenbacher list_for_each_entry_safe(tr, safe, ail2_list, tr_list) { 4286e80674aSAndreas Gruenbacher if (old_tail <= tr->tr_first || tr->tr_first < new_tail) 4296e80674aSAndreas Gruenbacher __ail2_empty(sdp, tr); 4306e80674aSAndreas Gruenbacher } 4316e80674aSAndreas Gruenbacher } 432d6a079e8SDave Chinner spin_unlock(&sdp->sd_ail_lock); 433b3b94faaSDavid Teigland } 434b3b94faaSDavid Teigland 435b3b94faaSDavid Teigland /** 436f3708fb5SAndreas Gruenbacher * gfs2_log_is_empty - Check if the log is empty 437f3708fb5SAndreas Gruenbacher * @sdp: The GFS2 superblock 438f3708fb5SAndreas Gruenbacher */ 439f3708fb5SAndreas Gruenbacher 440f3708fb5SAndreas Gruenbacher bool gfs2_log_is_empty(struct gfs2_sbd *sdp) { 441f3708fb5SAndreas Gruenbacher return atomic_read(&sdp->sd_log_blks_free) == sdp->sd_jdesc->jd_blocks; 442f3708fb5SAndreas Gruenbacher } 443f3708fb5SAndreas Gruenbacher 4442129b428SAndreas Gruenbacher static bool __gfs2_log_try_reserve_revokes(struct gfs2_sbd *sdp, unsigned int revokes) 4452129b428SAndreas Gruenbacher { 4462129b428SAndreas Gruenbacher unsigned int available; 4472129b428SAndreas Gruenbacher 4482129b428SAndreas Gruenbacher available = atomic_read(&sdp->sd_log_revokes_available); 4492129b428SAndreas Gruenbacher while (available >= revokes) { 4502129b428SAndreas Gruenbacher if (atomic_try_cmpxchg(&sdp->sd_log_revokes_available, 4512129b428SAndreas Gruenbacher &available, available - revokes)) 4522129b428SAndreas Gruenbacher return true; 4532129b428SAndreas Gruenbacher } 4542129b428SAndreas Gruenbacher return false; 4552129b428SAndreas Gruenbacher } 4562129b428SAndreas Gruenbacher 4572129b428SAndreas Gruenbacher /** 4582129b428SAndreas Gruenbacher * gfs2_log_release_revokes - Release a given number of revokes 4592129b428SAndreas Gruenbacher * @sdp: The GFS2 superblock 4602129b428SAndreas Gruenbacher * @revokes: The number of revokes to release 4612129b428SAndreas Gruenbacher * 4622129b428SAndreas Gruenbacher * sdp->sd_log_flush_lock must be held. 4632129b428SAndreas Gruenbacher */ 4642129b428SAndreas Gruenbacher void gfs2_log_release_revokes(struct gfs2_sbd *sdp, unsigned int revokes) 4652129b428SAndreas Gruenbacher { 4662129b428SAndreas Gruenbacher if (revokes) 4672129b428SAndreas Gruenbacher atomic_add(revokes, &sdp->sd_log_revokes_available); 4682129b428SAndreas Gruenbacher } 4692129b428SAndreas Gruenbacher 470f3708fb5SAndreas Gruenbacher /** 47124972557SBenjamin Marzinski * gfs2_log_release - Release a given number of log blocks 47224972557SBenjamin Marzinski * @sdp: The GFS2 superblock 47324972557SBenjamin Marzinski * @blks: The number of blocks 47424972557SBenjamin Marzinski * 47524972557SBenjamin Marzinski */ 47624972557SBenjamin Marzinski 47724972557SBenjamin Marzinski void gfs2_log_release(struct gfs2_sbd *sdp, unsigned int blks) 47824972557SBenjamin Marzinski { 47924972557SBenjamin Marzinski atomic_add(blks, &sdp->sd_log_blks_free); 48024972557SBenjamin Marzinski trace_gfs2_log_blocks(sdp, blks); 48124972557SBenjamin Marzinski gfs2_assert_withdraw(sdp, atomic_read(&sdp->sd_log_blks_free) <= 48224972557SBenjamin Marzinski sdp->sd_jdesc->jd_blocks); 4835ae8fff8SAndreas Gruenbacher if (atomic_read(&sdp->sd_log_blks_needed)) 4845ae8fff8SAndreas Gruenbacher wake_up(&sdp->sd_log_waitq); 48524972557SBenjamin Marzinski } 48624972557SBenjamin Marzinski 48724972557SBenjamin Marzinski /** 488fe3e3976SAndreas Gruenbacher * __gfs2_log_try_reserve - Try to make a log reservation 489b3b94faaSDavid Teigland * @sdp: The GFS2 superblock 490b3b94faaSDavid Teigland * @blks: The number of blocks to reserve 491fe3e3976SAndreas Gruenbacher * @taboo_blks: The number of blocks to leave free 492b3b94faaSDavid Teigland * 493fe3e3976SAndreas Gruenbacher * Try to do the same as __gfs2_log_reserve(), but fail if no more log 494fe3e3976SAndreas Gruenbacher * space is immediately available. 495fe3e3976SAndreas Gruenbacher */ 496fe3e3976SAndreas Gruenbacher static bool __gfs2_log_try_reserve(struct gfs2_sbd *sdp, unsigned int blks, 497fe3e3976SAndreas Gruenbacher unsigned int taboo_blks) 498fe3e3976SAndreas Gruenbacher { 499fe3e3976SAndreas Gruenbacher unsigned wanted = blks + taboo_blks; 500fe3e3976SAndreas Gruenbacher unsigned int free_blocks; 501fe3e3976SAndreas Gruenbacher 502fe3e3976SAndreas Gruenbacher free_blocks = atomic_read(&sdp->sd_log_blks_free); 503fe3e3976SAndreas Gruenbacher while (free_blocks >= wanted) { 504fe3e3976SAndreas Gruenbacher if (atomic_try_cmpxchg(&sdp->sd_log_blks_free, &free_blocks, 505fe3e3976SAndreas Gruenbacher free_blocks - blks)) { 506fe3e3976SAndreas Gruenbacher trace_gfs2_log_blocks(sdp, -blks); 507fe3e3976SAndreas Gruenbacher return true; 508fe3e3976SAndreas Gruenbacher } 509fe3e3976SAndreas Gruenbacher } 510fe3e3976SAndreas Gruenbacher return false; 511fe3e3976SAndreas Gruenbacher } 512fe3e3976SAndreas Gruenbacher 513fe3e3976SAndreas Gruenbacher /** 514fe3e3976SAndreas Gruenbacher * __gfs2_log_reserve - Make a log reservation 515fe3e3976SAndreas Gruenbacher * @sdp: The GFS2 superblock 516fe3e3976SAndreas Gruenbacher * @blks: The number of blocks to reserve 517fe3e3976SAndreas Gruenbacher * @taboo_blks: The number of blocks to leave free 518fe3e3976SAndreas Gruenbacher * 519fe3e3976SAndreas Gruenbacher * @taboo_blks is set to 0 for logd, and to GFS2_LOG_FLUSH_MIN_BLOCKS 520fe3e3976SAndreas Gruenbacher * for all other processes. This ensures that when the log is almost full, 521fe3e3976SAndreas Gruenbacher * logd will still be able to call gfs2_log_flush one more time without 522fe3e3976SAndreas Gruenbacher * blocking, which will advance the tail and make some more log space 523fe3e3976SAndreas Gruenbacher * available. 524b004157aSSteven Whitehouse * 5255e687eacSBenjamin Marzinski * We no longer flush the log here, instead we wake up logd to do that 5265e687eacSBenjamin Marzinski * for us. To avoid the thundering herd and to ensure that we deal fairly 5275e687eacSBenjamin Marzinski * with queued waiters, we use an exclusive wait. This means that when we 5285e687eacSBenjamin Marzinski * get woken with enough journal space to get our reservation, we need to 5295e687eacSBenjamin Marzinski * wake the next waiter on the list. 530b3b94faaSDavid Teigland */ 531b3b94faaSDavid Teigland 532fe3e3976SAndreas Gruenbacher static void __gfs2_log_reserve(struct gfs2_sbd *sdp, unsigned int blks, 533fe3e3976SAndreas Gruenbacher unsigned int taboo_blks) 534b3b94faaSDavid Teigland { 535fe3e3976SAndreas Gruenbacher unsigned wanted = blks + taboo_blks; 5365e687eacSBenjamin Marzinski unsigned int free_blocks; 537b3b94faaSDavid Teigland 538f07b3520SBob Peterson atomic_add(blks, &sdp->sd_log_blks_needed); 5395ae8fff8SAndreas Gruenbacher for (;;) { 5405ae8fff8SAndreas Gruenbacher if (current != sdp->sd_logd_process) 5415e687eacSBenjamin Marzinski wake_up(&sdp->sd_logd_waitq); 5425ae8fff8SAndreas Gruenbacher io_wait_event(sdp->sd_log_waitq, 5435ae8fff8SAndreas Gruenbacher (free_blocks = atomic_read(&sdp->sd_log_blks_free), 5445ae8fff8SAndreas Gruenbacher free_blocks >= wanted)); 5455ae8fff8SAndreas Gruenbacher do { 5465ae8fff8SAndreas Gruenbacher if (atomic_try_cmpxchg(&sdp->sd_log_blks_free, 5475ae8fff8SAndreas Gruenbacher &free_blocks, 5485ae8fff8SAndreas Gruenbacher free_blocks - blks)) 5495ae8fff8SAndreas Gruenbacher goto reserved; 5505ae8fff8SAndreas Gruenbacher } while (free_blocks >= wanted); 551b3b94faaSDavid Teigland } 5525ae8fff8SAndreas Gruenbacher 5535ae8fff8SAndreas Gruenbacher reserved: 55463997775SSteven Whitehouse trace_gfs2_log_blocks(sdp, -blks); 5555ae8fff8SAndreas Gruenbacher if (atomic_sub_return(blks, &sdp->sd_log_blks_needed)) 5565e687eacSBenjamin Marzinski wake_up(&sdp->sd_log_waitq); 55724972557SBenjamin Marzinski } 558b3b94faaSDavid Teigland 559b3b94faaSDavid Teigland /** 5602129b428SAndreas Gruenbacher * gfs2_log_try_reserve - Try to make a log reservation 561fe3e3976SAndreas Gruenbacher * @sdp: The GFS2 superblock 5622129b428SAndreas Gruenbacher * @tr: The transaction 5632129b428SAndreas Gruenbacher * @extra_revokes: The number of additional revokes reserved (output) 5642129b428SAndreas Gruenbacher * 5652129b428SAndreas Gruenbacher * This is similar to gfs2_log_reserve, but sdp->sd_log_flush_lock must be 5662129b428SAndreas Gruenbacher * held for correct revoke accounting. 567fe3e3976SAndreas Gruenbacher */ 568fe3e3976SAndreas Gruenbacher 5692129b428SAndreas Gruenbacher bool gfs2_log_try_reserve(struct gfs2_sbd *sdp, struct gfs2_trans *tr, 5702129b428SAndreas Gruenbacher unsigned int *extra_revokes) 571fe3e3976SAndreas Gruenbacher { 5722129b428SAndreas Gruenbacher unsigned int blks = tr->tr_reserved; 5732129b428SAndreas Gruenbacher unsigned int revokes = tr->tr_revokes; 5742129b428SAndreas Gruenbacher unsigned int revoke_blks = 0; 5752129b428SAndreas Gruenbacher 5762129b428SAndreas Gruenbacher *extra_revokes = 0; 5772129b428SAndreas Gruenbacher if (revokes && !__gfs2_log_try_reserve_revokes(sdp, revokes)) { 5782129b428SAndreas Gruenbacher revoke_blks = DIV_ROUND_UP(revokes, sdp->sd_inptrs); 5792129b428SAndreas Gruenbacher *extra_revokes = revoke_blks * sdp->sd_inptrs - revokes; 5802129b428SAndreas Gruenbacher blks += revoke_blks; 5812129b428SAndreas Gruenbacher } 5822129b428SAndreas Gruenbacher if (!blks) 5832129b428SAndreas Gruenbacher return true; 584fe3e3976SAndreas Gruenbacher if (__gfs2_log_try_reserve(sdp, blks, GFS2_LOG_FLUSH_MIN_BLOCKS)) 5852129b428SAndreas Gruenbacher return true; 5862129b428SAndreas Gruenbacher if (!revoke_blks) 5872129b428SAndreas Gruenbacher gfs2_log_release_revokes(sdp, revokes); 5882129b428SAndreas Gruenbacher return false; 5892129b428SAndreas Gruenbacher } 5902129b428SAndreas Gruenbacher 5912129b428SAndreas Gruenbacher /** 5922129b428SAndreas Gruenbacher * gfs2_log_reserve - Make a log reservation 5932129b428SAndreas Gruenbacher * @sdp: The GFS2 superblock 5942129b428SAndreas Gruenbacher * @tr: The transaction 5952129b428SAndreas Gruenbacher * @extra_revokes: The number of additional revokes reserved (output) 5962129b428SAndreas Gruenbacher * 5972129b428SAndreas Gruenbacher * sdp->sd_log_flush_lock must not be held. 5982129b428SAndreas Gruenbacher */ 5992129b428SAndreas Gruenbacher 6002129b428SAndreas Gruenbacher void gfs2_log_reserve(struct gfs2_sbd *sdp, struct gfs2_trans *tr, 6012129b428SAndreas Gruenbacher unsigned int *extra_revokes) 6022129b428SAndreas Gruenbacher { 6032129b428SAndreas Gruenbacher unsigned int blks = tr->tr_reserved; 6042129b428SAndreas Gruenbacher unsigned int revokes = tr->tr_revokes; 605dc7674edSBob Peterson unsigned int revoke_blks; 6062129b428SAndreas Gruenbacher 6072129b428SAndreas Gruenbacher *extra_revokes = 0; 6082129b428SAndreas Gruenbacher if (revokes) { 6092129b428SAndreas Gruenbacher revoke_blks = DIV_ROUND_UP(revokes, sdp->sd_inptrs); 6102129b428SAndreas Gruenbacher *extra_revokes = revoke_blks * sdp->sd_inptrs - revokes; 6112129b428SAndreas Gruenbacher blks += revoke_blks; 6122129b428SAndreas Gruenbacher } 613fe3e3976SAndreas Gruenbacher __gfs2_log_reserve(sdp, blks, GFS2_LOG_FLUSH_MIN_BLOCKS); 614b3b94faaSDavid Teigland } 615b3b94faaSDavid Teigland 616b3b94faaSDavid Teigland /** 617b3b94faaSDavid Teigland * log_distance - Compute distance between two journal blocks 618b3b94faaSDavid Teigland * @sdp: The GFS2 superblock 619b3b94faaSDavid Teigland * @newer: The most recent journal block of the pair 620b3b94faaSDavid Teigland * @older: The older journal block of the pair 621b3b94faaSDavid Teigland * 622b3b94faaSDavid Teigland * Compute the distance (in the journal direction) between two 623b3b94faaSDavid Teigland * blocks in the journal 624b3b94faaSDavid Teigland * 625b3b94faaSDavid Teigland * Returns: the distance in blocks 626b3b94faaSDavid Teigland */ 627b3b94faaSDavid Teigland 628faa31ce8SSteven Whitehouse static inline unsigned int log_distance(struct gfs2_sbd *sdp, unsigned int newer, 629b3b94faaSDavid Teigland unsigned int older) 630b3b94faaSDavid Teigland { 631b3b94faaSDavid Teigland int dist; 632b3b94faaSDavid Teigland 633b3b94faaSDavid Teigland dist = newer - older; 634b3b94faaSDavid Teigland if (dist < 0) 635b3b94faaSDavid Teigland dist += sdp->sd_jdesc->jd_blocks; 636b3b94faaSDavid Teigland 637b3b94faaSDavid Teigland return dist; 638b3b94faaSDavid Teigland } 639b3b94faaSDavid Teigland 6402332c443SRobert Peterson /** 6416188e877SAndreas Gruenbacher * calc_reserved - Calculate the number of blocks to keep reserved 6422332c443SRobert Peterson * @sdp: The GFS2 superblock 6432332c443SRobert Peterson * 6442332c443SRobert Peterson * This is complex. We need to reserve room for all our currently used 6456188e877SAndreas Gruenbacher * metadata blocks (e.g. normal file I/O rewriting file time stamps) and 6466188e877SAndreas Gruenbacher * all our journaled data blocks for journaled files (e.g. files in the 6472332c443SRobert Peterson * meta_fs like rindex, or files for which chattr +j was done.) 6486188e877SAndreas Gruenbacher * If we don't reserve enough space, corruption will follow. 6492332c443SRobert Peterson * 6506188e877SAndreas Gruenbacher * We can have metadata blocks and jdata blocks in the same journal. Each 6516188e877SAndreas Gruenbacher * type gets its own log descriptor, for which we need to reserve a block. 6526188e877SAndreas Gruenbacher * In fact, each type has the potential for needing more than one log descriptor 6536188e877SAndreas Gruenbacher * in cases where we have more blocks than will fit in a log descriptor. 6542332c443SRobert Peterson * Metadata journal entries take up half the space of journaled buffer entries. 6552332c443SRobert Peterson * 6562332c443SRobert Peterson * Also, we need to reserve blocks for revoke journal entries and one for an 6572332c443SRobert Peterson * overall header for the lot. 6582332c443SRobert Peterson * 6592332c443SRobert Peterson * Returns: the number of blocks reserved 6602332c443SRobert Peterson */ 6612332c443SRobert Peterson static unsigned int calc_reserved(struct gfs2_sbd *sdp) 6622332c443SRobert Peterson { 663fe3e3976SAndreas Gruenbacher unsigned int reserved = GFS2_LOG_FLUSH_MIN_BLOCKS; 66471b219f4SAndreas Gruenbacher unsigned int blocks; 665022ef4feSSteven Whitehouse struct gfs2_trans *tr = sdp->sd_log_tr; 6662332c443SRobert Peterson 667022ef4feSSteven Whitehouse if (tr) { 66871b219f4SAndreas Gruenbacher blocks = tr->tr_num_buf_new - tr->tr_num_buf_rm; 66971b219f4SAndreas Gruenbacher reserved += blocks + DIV_ROUND_UP(blocks, buf_limit(sdp)); 67071b219f4SAndreas Gruenbacher blocks = tr->tr_num_databuf_new - tr->tr_num_databuf_rm; 67171b219f4SAndreas Gruenbacher reserved += blocks + DIV_ROUND_UP(blocks, databuf_limit(sdp)); 672022ef4feSSteven Whitehouse } 6732332c443SRobert Peterson return reserved; 6742332c443SRobert Peterson } 6752332c443SRobert Peterson 6765cb738b5SAndreas Gruenbacher static void log_pull_tail(struct gfs2_sbd *sdp) 677b3b94faaSDavid Teigland { 6785cb738b5SAndreas Gruenbacher unsigned int new_tail = sdp->sd_log_flush_tail; 6795cb738b5SAndreas Gruenbacher unsigned int dist; 680b3b94faaSDavid Teigland 6815cb738b5SAndreas Gruenbacher if (new_tail == sdp->sd_log_tail) 6825cb738b5SAndreas Gruenbacher return; 6835cb738b5SAndreas Gruenbacher dist = log_distance(sdp, new_tail, sdp->sd_log_tail); 684b3b94faaSDavid Teigland ail2_empty(sdp, new_tail); 685c1eba1b0SAndreas Gruenbacher gfs2_log_release(sdp, dist); 686b3b94faaSDavid Teigland sdp->sd_log_tail = new_tail; 687b3b94faaSDavid Teigland } 688b3b94faaSDavid Teigland 689b3b94faaSDavid Teigland 6909ff78289SBob Peterson void log_flush_wait(struct gfs2_sbd *sdp) 691b3b94faaSDavid Teigland { 69216615be1SSteven Whitehouse DEFINE_WAIT(wait); 693b3b94faaSDavid Teigland 69416615be1SSteven Whitehouse if (atomic_read(&sdp->sd_log_in_flight)) { 69516615be1SSteven Whitehouse do { 69616615be1SSteven Whitehouse prepare_to_wait(&sdp->sd_log_flush_wait, &wait, 69716615be1SSteven Whitehouse TASK_UNINTERRUPTIBLE); 69816615be1SSteven Whitehouse if (atomic_read(&sdp->sd_log_in_flight)) 69916615be1SSteven Whitehouse io_schedule(); 70016615be1SSteven Whitehouse } while(atomic_read(&sdp->sd_log_in_flight)); 70116615be1SSteven Whitehouse finish_wait(&sdp->sd_log_flush_wait, &wait); 702b3b94faaSDavid Teigland } 703b3b94faaSDavid Teigland } 704b3b94faaSDavid Teigland 7054f0f586bSSami Tolvanen static int ip_cmp(void *priv, const struct list_head *a, const struct list_head *b) 7064a36d08dSBob Peterson { 70745138990SSteven Whitehouse struct gfs2_inode *ipa, *ipb; 7084a36d08dSBob Peterson 70945138990SSteven Whitehouse ipa = list_entry(a, struct gfs2_inode, i_ordered); 71045138990SSteven Whitehouse ipb = list_entry(b, struct gfs2_inode, i_ordered); 7114a36d08dSBob Peterson 71245138990SSteven Whitehouse if (ipa->i_no_addr < ipb->i_no_addr) 7134a36d08dSBob Peterson return -1; 71445138990SSteven Whitehouse if (ipa->i_no_addr > ipb->i_no_addr) 7154a36d08dSBob Peterson return 1; 7164a36d08dSBob Peterson return 0; 7174a36d08dSBob Peterson } 7184a36d08dSBob Peterson 7197542486bSBob Peterson static void __ordered_del_inode(struct gfs2_inode *ip) 7207542486bSBob Peterson { 7217542486bSBob Peterson if (!list_empty(&ip->i_ordered)) 7227542486bSBob Peterson list_del_init(&ip->i_ordered); 7237542486bSBob Peterson } 7247542486bSBob Peterson 725d7b616e2SSteven Whitehouse static void gfs2_ordered_write(struct gfs2_sbd *sdp) 726d7b616e2SSteven Whitehouse { 72745138990SSteven Whitehouse struct gfs2_inode *ip; 728d7b616e2SSteven Whitehouse LIST_HEAD(written); 729d7b616e2SSteven Whitehouse 73045138990SSteven Whitehouse spin_lock(&sdp->sd_ordered_lock); 731a5b1d3fcSAndreas Gruenbacher list_sort(NULL, &sdp->sd_log_ordered, &ip_cmp); 732a5b1d3fcSAndreas Gruenbacher while (!list_empty(&sdp->sd_log_ordered)) { 733969183bcSAndreas Gruenbacher ip = list_first_entry(&sdp->sd_log_ordered, struct gfs2_inode, i_ordered); 7341f23bc78SAbhi Das if (ip->i_inode.i_mapping->nrpages == 0) { 7357542486bSBob Peterson __ordered_del_inode(ip); 736d7b616e2SSteven Whitehouse continue; 7371f23bc78SAbhi Das } 7381f23bc78SAbhi Das list_move(&ip->i_ordered, &written); 73945138990SSteven Whitehouse spin_unlock(&sdp->sd_ordered_lock); 74045138990SSteven Whitehouse filemap_fdatawrite(ip->i_inode.i_mapping); 74145138990SSteven Whitehouse spin_lock(&sdp->sd_ordered_lock); 742d7b616e2SSteven Whitehouse } 743a5b1d3fcSAndreas Gruenbacher list_splice(&written, &sdp->sd_log_ordered); 74445138990SSteven Whitehouse spin_unlock(&sdp->sd_ordered_lock); 745d7b616e2SSteven Whitehouse } 746d7b616e2SSteven Whitehouse 747d7b616e2SSteven Whitehouse static void gfs2_ordered_wait(struct gfs2_sbd *sdp) 748d7b616e2SSteven Whitehouse { 74945138990SSteven Whitehouse struct gfs2_inode *ip; 750d7b616e2SSteven Whitehouse 75145138990SSteven Whitehouse spin_lock(&sdp->sd_ordered_lock); 752a5b1d3fcSAndreas Gruenbacher while (!list_empty(&sdp->sd_log_ordered)) { 753969183bcSAndreas Gruenbacher ip = list_first_entry(&sdp->sd_log_ordered, struct gfs2_inode, i_ordered); 7547542486bSBob Peterson __ordered_del_inode(ip); 75545138990SSteven Whitehouse if (ip->i_inode.i_mapping->nrpages == 0) 756d7b616e2SSteven Whitehouse continue; 75745138990SSteven Whitehouse spin_unlock(&sdp->sd_ordered_lock); 75845138990SSteven Whitehouse filemap_fdatawait(ip->i_inode.i_mapping); 75945138990SSteven Whitehouse spin_lock(&sdp->sd_ordered_lock); 760d7b616e2SSteven Whitehouse } 76145138990SSteven Whitehouse spin_unlock(&sdp->sd_ordered_lock); 762d7b616e2SSteven Whitehouse } 76345138990SSteven Whitehouse 76445138990SSteven Whitehouse void gfs2_ordered_del_inode(struct gfs2_inode *ip) 76545138990SSteven Whitehouse { 76645138990SSteven Whitehouse struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); 76745138990SSteven Whitehouse 76845138990SSteven Whitehouse spin_lock(&sdp->sd_ordered_lock); 7697542486bSBob Peterson __ordered_del_inode(ip); 77045138990SSteven Whitehouse spin_unlock(&sdp->sd_ordered_lock); 771d7b616e2SSteven Whitehouse } 772d7b616e2SSteven Whitehouse 7735d054964SBenjamin Marzinski void gfs2_add_revoke(struct gfs2_sbd *sdp, struct gfs2_bufdata *bd) 7745d054964SBenjamin Marzinski { 7755d054964SBenjamin Marzinski struct buffer_head *bh = bd->bd_bh; 7765d054964SBenjamin Marzinski struct gfs2_glock *gl = bd->bd_gl; 7775d054964SBenjamin Marzinski 778f4e2f5e1SAndreas Gruenbacher sdp->sd_log_num_revoke++; 779f4e2f5e1SAndreas Gruenbacher if (atomic_inc_return(&gl->gl_revokes) == 1) 780f4e2f5e1SAndreas Gruenbacher gfs2_glock_hold(gl); 7815d054964SBenjamin Marzinski bh->b_private = NULL; 7825d054964SBenjamin Marzinski bd->bd_blkno = bh->b_blocknr; 7839290a9a7SBob Peterson gfs2_remove_from_ail(bd); /* drops ref on bh */ 7849290a9a7SBob Peterson bd->bd_bh = NULL; 7855d054964SBenjamin Marzinski set_bit(GLF_LFLUSH, &gl->gl_flags); 786a5b1d3fcSAndreas Gruenbacher list_add(&bd->bd_list, &sdp->sd_log_revokes); 7875d054964SBenjamin Marzinski } 7885d054964SBenjamin Marzinski 789fe5e7ba1SBob Peterson void gfs2_glock_remove_revoke(struct gfs2_glock *gl) 790fe5e7ba1SBob Peterson { 791fe5e7ba1SBob Peterson if (atomic_dec_return(&gl->gl_revokes) == 0) { 792fe5e7ba1SBob Peterson clear_bit(GLF_LFLUSH, &gl->gl_flags); 793fe5e7ba1SBob Peterson gfs2_glock_queue_put(gl); 794fe5e7ba1SBob Peterson } 795fe5e7ba1SBob Peterson } 796fe5e7ba1SBob Peterson 7975e4c7632SBob Peterson /** 798e7501bf8SAndreas Gruenbacher * gfs2_flush_revokes - Add as many revokes to the system transaction as we can 7995e4c7632SBob Peterson * @sdp: The GFS2 superblock 8005e4c7632SBob Peterson * 8015e4c7632SBob Peterson * Our usual strategy is to defer writing revokes as much as we can in the hope 8025e4c7632SBob Peterson * that we'll eventually overwrite the journal, which will make those revokes 8035e4c7632SBob Peterson * go away. This changes when we flush the log: at that point, there will 8045e4c7632SBob Peterson * likely be some left-over space in the last revoke block of that transaction. 8055e4c7632SBob Peterson * We can fill that space with additional revokes for blocks that have already 8065e4c7632SBob Peterson * been written back. This will basically come at no cost now, and will save 8075e4c7632SBob Peterson * us from having to keep track of those blocks on the AIL2 list later. 8085e4c7632SBob Peterson */ 809e7501bf8SAndreas Gruenbacher void gfs2_flush_revokes(struct gfs2_sbd *sdp) 8105d054964SBenjamin Marzinski { 8115e4c7632SBob Peterson /* number of revokes we still have room for */ 8122129b428SAndreas Gruenbacher unsigned int max_revokes = atomic_read(&sdp->sd_log_revokes_available); 8135d054964SBenjamin Marzinski 8145e4c7632SBob Peterson gfs2_log_lock(sdp); 8155e4c7632SBob Peterson gfs2_ail1_empty(sdp, max_revokes); 8165d054964SBenjamin Marzinski gfs2_log_unlock(sdp); 8175d054964SBenjamin Marzinski } 8185d054964SBenjamin Marzinski 819b3b94faaSDavid Teigland /** 8207c70b896SBob Peterson * gfs2_write_log_header - Write a journal log header buffer at lblock 821588bff95SBob Peterson * @sdp: The GFS2 superblock 822c1696fb8SBob Peterson * @jd: journal descriptor of the journal to which we are writing 823588bff95SBob Peterson * @seq: sequence number 824588bff95SBob Peterson * @tail: tail of the log 8257c70b896SBob Peterson * @lblock: value for lh_blkno (block number relative to start of journal) 826c1696fb8SBob Peterson * @flags: log header flags GFS2_LOG_HEAD_* 827588bff95SBob Peterson * @op_flags: flags to pass to the bio 828588bff95SBob Peterson * 829588bff95SBob Peterson * Returns: the initialized log buffer descriptor 830588bff95SBob Peterson */ 831588bff95SBob Peterson 832c1696fb8SBob Peterson void gfs2_write_log_header(struct gfs2_sbd *sdp, struct gfs2_jdesc *jd, 8337c70b896SBob Peterson u64 seq, u32 tail, u32 lblock, u32 flags, 83467688c08SBart Van Assche blk_opf_t op_flags) 835588bff95SBob Peterson { 836588bff95SBob Peterson struct gfs2_log_header *lh; 837c1696fb8SBob Peterson u32 hash, crc; 838ade48088SBob Peterson struct page *page; 839c1696fb8SBob Peterson struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local; 840c1696fb8SBob Peterson struct timespec64 tv; 841c1696fb8SBob Peterson struct super_block *sb = sdp->sd_vfs; 8427c70b896SBob Peterson u64 dblock; 843588bff95SBob Peterson 844ade48088SBob Peterson if (gfs2_withdrawn(sdp)) 8454a3d049dSAndreas Gruenbacher return; 846ade48088SBob Peterson 847ade48088SBob Peterson page = mempool_alloc(gfs2_page_pool, GFP_NOIO); 848588bff95SBob Peterson lh = page_address(page); 849588bff95SBob Peterson clear_page(lh); 850588bff95SBob Peterson 851588bff95SBob Peterson lh->lh_header.mh_magic = cpu_to_be32(GFS2_MAGIC); 852588bff95SBob Peterson lh->lh_header.mh_type = cpu_to_be32(GFS2_METATYPE_LH); 853588bff95SBob Peterson lh->lh_header.__pad0 = cpu_to_be64(0); 854588bff95SBob Peterson lh->lh_header.mh_format = cpu_to_be32(GFS2_FORMAT_LH); 855588bff95SBob Peterson lh->lh_header.mh_jid = cpu_to_be32(sdp->sd_jdesc->jd_jid); 856588bff95SBob Peterson lh->lh_sequence = cpu_to_be64(seq); 857588bff95SBob Peterson lh->lh_flags = cpu_to_be32(flags); 858588bff95SBob Peterson lh->lh_tail = cpu_to_be32(tail); 8597c70b896SBob Peterson lh->lh_blkno = cpu_to_be32(lblock); 860c1696fb8SBob Peterson hash = ~crc32(~0, lh, LH_V1_SIZE); 861588bff95SBob Peterson lh->lh_hash = cpu_to_be32(hash); 862588bff95SBob Peterson 863ee9c7f9aSArnd Bergmann ktime_get_coarse_real_ts64(&tv); 864c1696fb8SBob Peterson lh->lh_nsec = cpu_to_be32(tv.tv_nsec); 865c1696fb8SBob Peterson lh->lh_sec = cpu_to_be64(tv.tv_sec); 8667c70b896SBob Peterson if (!list_empty(&jd->extent_list)) 86719ebc050SAndreas Gruenbacher dblock = gfs2_log_bmap(jd, lblock); 8687c70b896SBob Peterson else { 869152f58c9SAndreas Gruenbacher unsigned int extlen; 870152f58c9SAndreas Gruenbacher int ret; 871152f58c9SAndreas Gruenbacher 872152f58c9SAndreas Gruenbacher extlen = 1; 873152f58c9SAndreas Gruenbacher ret = gfs2_get_extent(jd->jd_inode, lblock, &dblock, &extlen); 8747c70b896SBob Peterson if (gfs2_assert_withdraw(sdp, ret == 0)) 8757c70b896SBob Peterson return; 8767c70b896SBob Peterson } 8777c70b896SBob Peterson lh->lh_addr = cpu_to_be64(dblock); 878c1696fb8SBob Peterson lh->lh_jinode = cpu_to_be64(GFS2_I(jd->jd_inode)->i_no_addr); 879c1696fb8SBob Peterson 880c1696fb8SBob Peterson /* We may only write local statfs, quota, etc., when writing to our 881c1696fb8SBob Peterson own journal. The values are left 0 when recovering a journal 882c1696fb8SBob Peterson different from our own. */ 883c1696fb8SBob Peterson if (!(flags & GFS2_LOG_HEAD_RECOVERY)) { 884c1696fb8SBob Peterson lh->lh_statfs_addr = 885c1696fb8SBob Peterson cpu_to_be64(GFS2_I(sdp->sd_sc_inode)->i_no_addr); 886c1696fb8SBob Peterson lh->lh_quota_addr = 887c1696fb8SBob Peterson cpu_to_be64(GFS2_I(sdp->sd_qc_inode)->i_no_addr); 888c1696fb8SBob Peterson 889c1696fb8SBob Peterson spin_lock(&sdp->sd_statfs_spin); 890c1696fb8SBob Peterson lh->lh_local_total = cpu_to_be64(l_sc->sc_total); 891c1696fb8SBob Peterson lh->lh_local_free = cpu_to_be64(l_sc->sc_free); 892c1696fb8SBob Peterson lh->lh_local_dinodes = cpu_to_be64(l_sc->sc_dinodes); 893c1696fb8SBob Peterson spin_unlock(&sdp->sd_statfs_spin); 894c1696fb8SBob Peterson } 895c1696fb8SBob Peterson 896c1696fb8SBob Peterson BUILD_BUG_ON(offsetof(struct gfs2_log_header, lh_crc) != LH_V1_SIZE); 897c1696fb8SBob Peterson 898c1696fb8SBob Peterson crc = crc32c(~0, (void *)lh + LH_V1_SIZE + 4, 899c1696fb8SBob Peterson sb->s_blocksize - LH_V1_SIZE - 4); 900c1696fb8SBob Peterson lh->lh_crc = cpu_to_be32(crc); 901c1696fb8SBob Peterson 90282218943SBob Peterson gfs2_log_write(sdp, jd, page, sb->s_blocksize, 0, dblock); 90382218943SBob Peterson gfs2_log_submit_bio(&jd->jd_log_bio, REQ_OP_WRITE | op_flags); 904588bff95SBob Peterson } 905588bff95SBob Peterson 906588bff95SBob Peterson /** 90734cc1781SSteven Whitehouse * log_write_header - Get and initialize a journal header buffer 90834cc1781SSteven Whitehouse * @sdp: The GFS2 superblock 909c1696fb8SBob Peterson * @flags: The log header flags, including log header origin 91034cc1781SSteven Whitehouse * 91134cc1781SSteven Whitehouse * Returns: the initialized log buffer descriptor 91234cc1781SSteven Whitehouse */ 91334cc1781SSteven Whitehouse 914fdb76a42SSteven Whitehouse static void log_write_header(struct gfs2_sbd *sdp, u32 flags) 91534cc1781SSteven Whitehouse { 91667688c08SBart Van Assche blk_opf_t op_flags = REQ_PREFLUSH | REQ_FUA | REQ_META | REQ_SYNC; 91734cc1781SSteven Whitehouse 9185432af15SAndreas Gruenbacher gfs2_assert_withdraw(sdp, !test_bit(SDF_FROZEN, &sdp->sd_flags)); 91934cc1781SSteven Whitehouse 92034cc1781SSteven Whitehouse if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags)) { 92134cc1781SSteven Whitehouse gfs2_ordered_wait(sdp); 92234cc1781SSteven Whitehouse log_flush_wait(sdp); 92370fd7614SChristoph Hellwig op_flags = REQ_SYNC | REQ_META | REQ_PRIO; 92434cc1781SSteven Whitehouse } 9255cb738b5SAndreas Gruenbacher sdp->sd_log_idle = (sdp->sd_log_flush_tail == sdp->sd_log_flush_head); 9265cb738b5SAndreas Gruenbacher gfs2_write_log_header(sdp, sdp->sd_jdesc, sdp->sd_log_sequence++, 9275cb738b5SAndreas Gruenbacher sdp->sd_log_flush_tail, sdp->sd_log_flush_head, 9285cb738b5SAndreas Gruenbacher flags, op_flags); 92919ebc050SAndreas Gruenbacher gfs2_log_incr_head(sdp); 9304a3d049dSAndreas Gruenbacher log_flush_wait(sdp); 9315cb738b5SAndreas Gruenbacher log_pull_tail(sdp); 932fe3e3976SAndreas Gruenbacher gfs2_log_update_head(sdp); 93334cc1781SSteven Whitehouse } 93434cc1781SSteven Whitehouse 93534cc1781SSteven Whitehouse /** 936f5456b5dSBob Peterson * gfs2_ail_drain - drain the ail lists after a withdraw 9372ca0c2fbSBob Peterson * @sdp: Pointer to GFS2 superblock 9382ca0c2fbSBob Peterson */ 939f5456b5dSBob Peterson void gfs2_ail_drain(struct gfs2_sbd *sdp) 9402ca0c2fbSBob Peterson { 9412ca0c2fbSBob Peterson struct gfs2_trans *tr; 9422ca0c2fbSBob Peterson 9432ca0c2fbSBob Peterson spin_lock(&sdp->sd_ail_lock); 9442ca0c2fbSBob Peterson /* 9452ca0c2fbSBob Peterson * For transactions on the sd_ail1_list we need to drain both the 9462ca0c2fbSBob Peterson * ail1 and ail2 lists. That's because function gfs2_ail1_start_one 9472ca0c2fbSBob Peterson * (temporarily) moves items from its tr_ail1 list to tr_ail2 list 9482ca0c2fbSBob Peterson * before revokes are sent for that block. Items on the sd_ail2_list 9492ca0c2fbSBob Peterson * should have already gotten beyond that point, so no need. 9502ca0c2fbSBob Peterson */ 9512ca0c2fbSBob Peterson while (!list_empty(&sdp->sd_ail1_list)) { 9522ca0c2fbSBob Peterson tr = list_first_entry(&sdp->sd_ail1_list, struct gfs2_trans, 9532ca0c2fbSBob Peterson tr_list); 9542ca0c2fbSBob Peterson gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail1_list); 9552ca0c2fbSBob Peterson gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail2_list); 9562ca0c2fbSBob Peterson list_del(&tr->tr_list); 957b839dadaSBob Peterson gfs2_trans_free(sdp, tr); 9582ca0c2fbSBob Peterson } 9592ca0c2fbSBob Peterson while (!list_empty(&sdp->sd_ail2_list)) { 9602ca0c2fbSBob Peterson tr = list_first_entry(&sdp->sd_ail2_list, struct gfs2_trans, 9612ca0c2fbSBob Peterson tr_list); 9622ca0c2fbSBob Peterson gfs2_ail_empty_tr(sdp, tr, &tr->tr_ail2_list); 9632ca0c2fbSBob Peterson list_del(&tr->tr_list); 964b839dadaSBob Peterson gfs2_trans_free(sdp, tr); 9652ca0c2fbSBob Peterson } 966f5456b5dSBob Peterson gfs2_drain_revokes(sdp); 9672ca0c2fbSBob Peterson spin_unlock(&sdp->sd_ail_lock); 9682ca0c2fbSBob Peterson } 9692ca0c2fbSBob Peterson 9702ca0c2fbSBob Peterson /** 971d5dc3d96SBob Peterson * empty_ail1_list - try to start IO and empty the ail1 list 972d5dc3d96SBob Peterson * @sdp: Pointer to GFS2 superblock 973d5dc3d96SBob Peterson */ 974d5dc3d96SBob Peterson static void empty_ail1_list(struct gfs2_sbd *sdp) 975d5dc3d96SBob Peterson { 976d5dc3d96SBob Peterson unsigned long start = jiffies; 977d5dc3d96SBob Peterson 978d5dc3d96SBob Peterson for (;;) { 979d5dc3d96SBob Peterson if (time_after(jiffies, start + (HZ * 600))) { 980d5dc3d96SBob Peterson fs_err(sdp, "Error: In %s for 10 minutes! t=%d\n", 981d5dc3d96SBob Peterson __func__, current->journal_info ? 1 : 0); 982d5dc3d96SBob Peterson dump_ail_list(sdp); 983d5dc3d96SBob Peterson return; 984d5dc3d96SBob Peterson } 985d5dc3d96SBob Peterson gfs2_ail1_start(sdp); 986d5dc3d96SBob Peterson gfs2_ail1_wait(sdp); 987d5dc3d96SBob Peterson if (gfs2_ail1_empty(sdp, 0)) 988d5dc3d96SBob Peterson return; 989d5dc3d96SBob Peterson } 990d5dc3d96SBob Peterson } 991d5dc3d96SBob Peterson 992d5dc3d96SBob Peterson /** 993521031faSBob Peterson * trans_drain - drain the buf and databuf queue for a failed transaction 994462582b9SBob Peterson * @tr: the transaction to drain 995462582b9SBob Peterson * 996462582b9SBob Peterson * When this is called, we're taking an error exit for a log write that failed 997462582b9SBob Peterson * but since we bypassed the after_commit functions, we need to remove the 998462582b9SBob Peterson * items from the buf and databuf queue. 999462582b9SBob Peterson */ 1000462582b9SBob Peterson static void trans_drain(struct gfs2_trans *tr) 1001462582b9SBob Peterson { 1002462582b9SBob Peterson struct gfs2_bufdata *bd; 1003462582b9SBob Peterson struct list_head *head; 1004462582b9SBob Peterson 1005462582b9SBob Peterson if (!tr) 1006462582b9SBob Peterson return; 1007462582b9SBob Peterson 1008462582b9SBob Peterson head = &tr->tr_buf; 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 head = &tr->tr_databuf; 1017462582b9SBob Peterson while (!list_empty(head)) { 1018462582b9SBob Peterson bd = list_first_entry(head, struct gfs2_bufdata, bd_list); 1019462582b9SBob Peterson list_del_init(&bd->bd_list); 10201a5a2cfdSBob Peterson if (!list_empty(&bd->bd_ail_st_list)) 10211a5a2cfdSBob Peterson gfs2_remove_from_ail(bd); 1022462582b9SBob Peterson kmem_cache_free(gfs2_bufdata_cachep, bd); 1023462582b9SBob Peterson } 1024462582b9SBob Peterson } 1025462582b9SBob Peterson 1026462582b9SBob Peterson /** 1027b09e593dSSteven Whitehouse * gfs2_log_flush - flush incore transaction(s) 1028c551f66cSLee Jones * @sdp: The filesystem 1029b3b94faaSDavid Teigland * @gl: The glock structure to flush. If NULL, flush the whole incore log 1030805c0907SBob Peterson * @flags: The log header flags: GFS2_LOG_HEAD_FLUSH_* and debug flags 1031b3b94faaSDavid Teigland * 1032b3b94faaSDavid Teigland */ 1033b3b94faaSDavid Teigland 1034c1696fb8SBob Peterson void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags) 1035b3b94faaSDavid Teigland { 10362ca0c2fbSBob Peterson struct gfs2_trans *tr = NULL; 1037fe3e3976SAndreas Gruenbacher unsigned int reserved_blocks = 0, used_blocks = 0; 10385432af15SAndreas Gruenbacher bool frozen = test_bit(SDF_FROZEN, &sdp->sd_flags); 1039fe3e3976SAndreas Gruenbacher unsigned int first_log_head; 10402129b428SAndreas Gruenbacher unsigned int reserved_revokes = 0; 1041b3b94faaSDavid Teigland 1042484adff8SSteven Whitehouse down_write(&sdp->sd_log_flush_lock); 1043fe3e3976SAndreas Gruenbacher trace_gfs2_log_flush(sdp, 1, flags); 1044f55ab26aSSteven Whitehouse 1045fe3e3976SAndreas Gruenbacher repeat: 10462ca0c2fbSBob Peterson /* 10472ca0c2fbSBob Peterson * Do this check while holding the log_flush_lock to prevent new 10482ca0c2fbSBob Peterson * buffers from being added to the ail via gfs2_pin() 10492ca0c2fbSBob Peterson */ 10500efc4976SBob Peterson if (gfs2_withdrawn(sdp) || !test_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags)) 10512ca0c2fbSBob Peterson goto out; 10522ca0c2fbSBob Peterson 10532bcd610dSSteven Whitehouse /* Log might have been flushed while we waited for the flush lock */ 10545a61ae14SAndreas Gruenbacher if (gl && !test_bit(GLF_LFLUSH, &gl->gl_flags)) 10555a61ae14SAndreas Gruenbacher goto out; 1056f55ab26aSSteven Whitehouse 1057fe3e3976SAndreas Gruenbacher first_log_head = sdp->sd_log_head; 1058fe3e3976SAndreas Gruenbacher sdp->sd_log_flush_head = first_log_head; 1059400ac52eSBenjamin Marzinski 106016ca9412SBenjamin Marzinski tr = sdp->sd_log_tr; 1061fe3e3976SAndreas Gruenbacher if (tr || sdp->sd_log_num_revoke) { 1062fe3e3976SAndreas Gruenbacher if (reserved_blocks) 1063fe3e3976SAndreas Gruenbacher gfs2_log_release(sdp, reserved_blocks); 1064fe3e3976SAndreas Gruenbacher reserved_blocks = sdp->sd_log_blks_reserved; 10652129b428SAndreas Gruenbacher reserved_revokes = sdp->sd_log_num_revoke; 106616ca9412SBenjamin Marzinski if (tr) { 106716ca9412SBenjamin Marzinski sdp->sd_log_tr = NULL; 1068fe3e3976SAndreas Gruenbacher tr->tr_first = first_log_head; 10695432af15SAndreas Gruenbacher if (unlikely(frozen)) { 1070ca399c96SBob Peterson if (gfs2_assert_withdraw_delayed(sdp, 1071ca399c96SBob Peterson !tr->tr_num_buf_new && !tr->tr_num_databuf_new)) 10725a61ae14SAndreas Gruenbacher goto out_withdraw; 107316ca9412SBenjamin Marzinski } 10742129b428SAndreas Gruenbacher } 1075fe3e3976SAndreas Gruenbacher } else if (!reserved_blocks) { 1076fe3e3976SAndreas Gruenbacher unsigned int taboo_blocks = GFS2_LOG_FLUSH_MIN_BLOCKS; 1077fe3e3976SAndreas Gruenbacher 1078fe3e3976SAndreas Gruenbacher reserved_blocks = GFS2_LOG_FLUSH_MIN_BLOCKS; 1079fe3e3976SAndreas Gruenbacher if (current == sdp->sd_logd_process) 1080fe3e3976SAndreas Gruenbacher taboo_blocks = 0; 1081fe3e3976SAndreas Gruenbacher 1082fe3e3976SAndreas Gruenbacher if (!__gfs2_log_try_reserve(sdp, reserved_blocks, taboo_blocks)) { 1083fe3e3976SAndreas Gruenbacher up_write(&sdp->sd_log_flush_lock); 1084fe3e3976SAndreas Gruenbacher __gfs2_log_reserve(sdp, reserved_blocks, taboo_blocks); 1085fe3e3976SAndreas Gruenbacher down_write(&sdp->sd_log_flush_lock); 1086fe3e3976SAndreas Gruenbacher goto repeat; 1087fe3e3976SAndreas Gruenbacher } 10882129b428SAndreas Gruenbacher BUG_ON(sdp->sd_log_num_revoke); 1089fe3e3976SAndreas Gruenbacher } 1090fe3e3976SAndreas Gruenbacher 1091fe3e3976SAndreas Gruenbacher if (flags & GFS2_LOG_HEAD_FLUSH_SHUTDOWN) 1092fe3e3976SAndreas Gruenbacher clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags); 1093b3b94faaSDavid Teigland 10945432af15SAndreas Gruenbacher if (unlikely(frozen)) 10952129b428SAndreas Gruenbacher if (gfs2_assert_withdraw_delayed(sdp, !reserved_revokes)) 10965a61ae14SAndreas Gruenbacher goto out_withdraw; 1097b3b94faaSDavid Teigland 1098d7b616e2SSteven Whitehouse gfs2_ordered_write(sdp); 10992ca0c2fbSBob Peterson if (gfs2_withdrawn(sdp)) 11005a61ae14SAndreas Gruenbacher goto out_withdraw; 1101d69a3c65SSteven Whitehouse lops_before_commit(sdp, tr); 11022ca0c2fbSBob Peterson if (gfs2_withdrawn(sdp)) 11035a61ae14SAndreas Gruenbacher goto out_withdraw; 110482218943SBob Peterson gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE); 11052ca0c2fbSBob Peterson if (gfs2_withdrawn(sdp)) 11065a61ae14SAndreas Gruenbacher goto out_withdraw; 1107d7b616e2SSteven Whitehouse 110834cc1781SSteven Whitehouse if (sdp->sd_log_head != sdp->sd_log_flush_head) { 1109c1696fb8SBob Peterson log_write_header(sdp, flags); 11105cb738b5SAndreas Gruenbacher } else if (sdp->sd_log_tail != sdp->sd_log_flush_tail && !sdp->sd_log_idle) { 1111c1696fb8SBob Peterson log_write_header(sdp, flags); 11122332c443SRobert Peterson } 11132ca0c2fbSBob Peterson if (gfs2_withdrawn(sdp)) 11145a61ae14SAndreas Gruenbacher goto out_withdraw; 111516ca9412SBenjamin Marzinski lops_after_commit(sdp, tr); 1116fe1a698fSSteven Whitehouse 1117fe1a698fSSteven Whitehouse gfs2_log_lock(sdp); 1118faa31ce8SSteven Whitehouse sdp->sd_log_blks_reserved = 0; 1119b3b94faaSDavid Teigland 1120d6a079e8SDave Chinner spin_lock(&sdp->sd_ail_lock); 112116ca9412SBenjamin Marzinski if (tr && !list_empty(&tr->tr_ail1_list)) { 112216ca9412SBenjamin Marzinski list_add(&tr->tr_list, &sdp->sd_ail1_list); 112316ca9412SBenjamin Marzinski tr = NULL; 1124b3b94faaSDavid Teigland } 1125d6a079e8SDave Chinner spin_unlock(&sdp->sd_ail_lock); 1126b3b94faaSDavid Teigland gfs2_log_unlock(sdp); 112724972557SBenjamin Marzinski 1128c1696fb8SBob Peterson if (!(flags & GFS2_LOG_HEAD_FLUSH_NORMAL)) { 112924972557SBenjamin Marzinski if (!sdp->sd_log_idle) { 1130d5dc3d96SBob Peterson empty_ail1_list(sdp); 113130fe70a8SBob Peterson if (gfs2_withdrawn(sdp)) 11325a61ae14SAndreas Gruenbacher goto out_withdraw; 1133c1696fb8SBob Peterson log_write_header(sdp, flags); 113424972557SBenjamin Marzinski } 1135c1696fb8SBob Peterson if (flags & (GFS2_LOG_HEAD_FLUSH_SHUTDOWN | 1136c1696fb8SBob Peterson GFS2_LOG_HEAD_FLUSH_FREEZE)) 113724972557SBenjamin Marzinski gfs2_log_shutdown(sdp); 113824972557SBenjamin Marzinski } 113924972557SBenjamin Marzinski 11405a61ae14SAndreas Gruenbacher out_end: 1141fe3e3976SAndreas Gruenbacher used_blocks = log_distance(sdp, sdp->sd_log_flush_head, first_log_head); 11422129b428SAndreas Gruenbacher reserved_revokes += atomic_read(&sdp->sd_log_revokes_available); 11432129b428SAndreas Gruenbacher atomic_set(&sdp->sd_log_revokes_available, sdp->sd_ldptrs); 11442129b428SAndreas Gruenbacher gfs2_assert_withdraw(sdp, reserved_revokes % sdp->sd_inptrs == sdp->sd_ldptrs); 11452129b428SAndreas Gruenbacher if (reserved_revokes > sdp->sd_ldptrs) 11462129b428SAndreas Gruenbacher reserved_blocks += (reserved_revokes - sdp->sd_ldptrs) / sdp->sd_inptrs; 114730fe70a8SBob Peterson out: 11482129b428SAndreas Gruenbacher if (used_blocks != reserved_blocks) { 11492129b428SAndreas Gruenbacher gfs2_assert_withdraw_delayed(sdp, used_blocks < reserved_blocks); 1150fe3e3976SAndreas Gruenbacher gfs2_log_release(sdp, reserved_blocks - used_blocks); 11512129b428SAndreas Gruenbacher } 11525a61ae14SAndreas Gruenbacher up_write(&sdp->sd_log_flush_lock); 11535a61ae14SAndreas Gruenbacher gfs2_trans_free(sdp, tr); 11545a61ae14SAndreas Gruenbacher if (gfs2_withdrawing(sdp)) 11555a61ae14SAndreas Gruenbacher gfs2_withdraw(sdp); 1156fe3e3976SAndreas Gruenbacher trace_gfs2_log_flush(sdp, 0, flags); 11575a61ae14SAndreas Gruenbacher return; 11585a61ae14SAndreas Gruenbacher 11595a61ae14SAndreas Gruenbacher out_withdraw: 1160462582b9SBob Peterson trans_drain(tr); 116158e08e8dSBob Peterson /** 116258e08e8dSBob Peterson * If the tr_list is empty, we're withdrawing during a log 116358e08e8dSBob Peterson * flush that targets a transaction, but the transaction was 116458e08e8dSBob Peterson * never queued onto any of the ail lists. Here we add it to 116558e08e8dSBob Peterson * ail1 just so that ail_drain() will find and free it. 116658e08e8dSBob Peterson */ 116758e08e8dSBob Peterson spin_lock(&sdp->sd_ail_lock); 116858e08e8dSBob Peterson if (tr && list_empty(&tr->tr_list)) 116958e08e8dSBob Peterson list_add(&tr->tr_list, &sdp->sd_ail1_list); 117058e08e8dSBob Peterson spin_unlock(&sdp->sd_ail_lock); 11712ca0c2fbSBob Peterson tr = NULL; 11725a61ae14SAndreas Gruenbacher goto out_end; 1173b3b94faaSDavid Teigland } 1174b3b94faaSDavid Teigland 1175d69a3c65SSteven Whitehouse /** 1176d69a3c65SSteven Whitehouse * gfs2_merge_trans - Merge a new transaction into a cached transaction 1177c551f66cSLee Jones * @sdp: the filesystem 1178d69a3c65SSteven Whitehouse * @new: New transaction to be merged 1179d69a3c65SSteven Whitehouse */ 1180d69a3c65SSteven Whitehouse 118183d060caSBob Peterson static void gfs2_merge_trans(struct gfs2_sbd *sdp, struct gfs2_trans *new) 1182d69a3c65SSteven Whitehouse { 118383d060caSBob Peterson struct gfs2_trans *old = sdp->sd_log_tr; 118483d060caSBob Peterson 11859862ca05SBob Peterson WARN_ON_ONCE(!test_bit(TR_ATTACHED, &old->tr_flags)); 1186d69a3c65SSteven Whitehouse 1187d69a3c65SSteven Whitehouse old->tr_num_buf_new += new->tr_num_buf_new; 1188d69a3c65SSteven Whitehouse old->tr_num_databuf_new += new->tr_num_databuf_new; 1189d69a3c65SSteven Whitehouse old->tr_num_buf_rm += new->tr_num_buf_rm; 1190d69a3c65SSteven Whitehouse old->tr_num_databuf_rm += new->tr_num_databuf_rm; 11912129b428SAndreas Gruenbacher old->tr_revokes += new->tr_revokes; 1192d69a3c65SSteven Whitehouse old->tr_num_revoke += new->tr_num_revoke; 1193d69a3c65SSteven Whitehouse 1194d69a3c65SSteven Whitehouse list_splice_tail_init(&new->tr_databuf, &old->tr_databuf); 1195d69a3c65SSteven Whitehouse list_splice_tail_init(&new->tr_buf, &old->tr_buf); 119683d060caSBob Peterson 119783d060caSBob Peterson spin_lock(&sdp->sd_ail_lock); 119883d060caSBob Peterson list_splice_tail_init(&new->tr_ail1_list, &old->tr_ail1_list); 119983d060caSBob Peterson list_splice_tail_init(&new->tr_ail2_list, &old->tr_ail2_list); 120083d060caSBob Peterson spin_unlock(&sdp->sd_ail_lock); 1201d69a3c65SSteven Whitehouse } 1202d69a3c65SSteven Whitehouse 1203b3b94faaSDavid Teigland static void log_refund(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 1204b3b94faaSDavid Teigland { 12052332c443SRobert Peterson unsigned int reserved; 1206ac39aaddSSteven Whitehouse unsigned int unused; 1207022ef4feSSteven Whitehouse unsigned int maxres; 1208b3b94faaSDavid Teigland 1209b3b94faaSDavid Teigland gfs2_log_lock(sdp); 1210b3b94faaSDavid Teigland 1211d69a3c65SSteven Whitehouse if (sdp->sd_log_tr) { 121283d060caSBob Peterson gfs2_merge_trans(sdp, tr); 1213d69a3c65SSteven Whitehouse } else if (tr->tr_num_buf_new || tr->tr_num_databuf_new) { 1214c968f578SAndreas Gruenbacher gfs2_assert_withdraw(sdp, !test_bit(TR_ONSTACK, &tr->tr_flags)); 121516ca9412SBenjamin Marzinski sdp->sd_log_tr = tr; 12169862ca05SBob Peterson set_bit(TR_ATTACHED, &tr->tr_flags); 121716ca9412SBenjamin Marzinski } 1218022ef4feSSteven Whitehouse 1219022ef4feSSteven Whitehouse reserved = calc_reserved(sdp); 1220022ef4feSSteven Whitehouse maxres = sdp->sd_log_blks_reserved + tr->tr_reserved; 1221022ef4feSSteven Whitehouse gfs2_assert_withdraw(sdp, maxres >= reserved); 1222022ef4feSSteven Whitehouse unused = maxres - reserved; 12235ae8fff8SAndreas Gruenbacher if (unused) 1224c1eba1b0SAndreas Gruenbacher gfs2_log_release(sdp, unused); 1225022ef4feSSteven Whitehouse sdp->sd_log_blks_reserved = reserved; 1226022ef4feSSteven Whitehouse 1227b3b94faaSDavid Teigland gfs2_log_unlock(sdp); 1228b3b94faaSDavid Teigland } 1229b3b94faaSDavid Teigland 1230b3b94faaSDavid Teigland /** 1231b3b94faaSDavid Teigland * gfs2_log_commit - Commit a transaction to the log 1232b3b94faaSDavid Teigland * @sdp: the filesystem 1233b3b94faaSDavid Teigland * @tr: the transaction 1234b3b94faaSDavid Teigland * 12355e687eacSBenjamin Marzinski * We wake up gfs2_logd if the number of pinned blocks exceed thresh1 12365e687eacSBenjamin Marzinski * or the total number of used blocks (pinned blocks plus AIL blocks) 12375e687eacSBenjamin Marzinski * is greater than thresh2. 12385e687eacSBenjamin Marzinski * 1239b57bc0fbSBob Peterson * At mount time thresh1 is 2/5ths of journal size, thresh2 is 4/5ths of 12405e687eacSBenjamin Marzinski * journal size. 12415e687eacSBenjamin Marzinski * 1242b3b94faaSDavid Teigland * Returns: errno 1243b3b94faaSDavid Teigland */ 1244b3b94faaSDavid Teigland 1245b3b94faaSDavid Teigland void gfs2_log_commit(struct gfs2_sbd *sdp, struct gfs2_trans *tr) 1246b3b94faaSDavid Teigland { 1247b3b94faaSDavid Teigland log_refund(sdp, tr); 1248b3b94faaSDavid Teigland 12495e687eacSBenjamin Marzinski if (atomic_read(&sdp->sd_log_pinned) > atomic_read(&sdp->sd_log_thresh1) || 12505e687eacSBenjamin Marzinski ((sdp->sd_jdesc->jd_blocks - atomic_read(&sdp->sd_log_blks_free)) > 12515e687eacSBenjamin Marzinski atomic_read(&sdp->sd_log_thresh2))) 12525e687eacSBenjamin Marzinski wake_up(&sdp->sd_logd_waitq); 1253faa31ce8SSteven Whitehouse } 1254b3b94faaSDavid Teigland 1255b3b94faaSDavid Teigland /** 1256b3b94faaSDavid Teigland * gfs2_log_shutdown - write a shutdown header into a journal 1257b3b94faaSDavid Teigland * @sdp: the filesystem 1258b3b94faaSDavid Teigland * 1259b3b94faaSDavid Teigland */ 1260b3b94faaSDavid Teigland 1261feed98a8SBob Peterson static void gfs2_log_shutdown(struct gfs2_sbd *sdp) 1262b3b94faaSDavid Teigland { 1263b3b94faaSDavid Teigland gfs2_assert_withdraw(sdp, !sdp->sd_log_blks_reserved); 1264b3b94faaSDavid Teigland gfs2_assert_withdraw(sdp, !sdp->sd_log_num_revoke); 1265b3b94faaSDavid Teigland gfs2_assert_withdraw(sdp, list_empty(&sdp->sd_ail1_list)); 1266b3b94faaSDavid Teigland 1267805c0907SBob Peterson log_write_header(sdp, GFS2_LOG_HEAD_UNMOUNT | GFS2_LFC_SHUTDOWN); 1268fe3e3976SAndreas Gruenbacher log_pull_tail(sdp); 1269b3b94faaSDavid Teigland 1270a74604beSSteven Whitehouse gfs2_assert_warn(sdp, sdp->sd_log_head == sdp->sd_log_tail); 1271a74604beSSteven Whitehouse gfs2_assert_warn(sdp, list_empty(&sdp->sd_ail2_list)); 1272a25311c8SSteven Whitehouse } 1273a25311c8SSteven Whitehouse 12745e687eacSBenjamin Marzinski static inline int gfs2_jrnl_flush_reqd(struct gfs2_sbd *sdp) 12755e687eacSBenjamin Marzinski { 1276f07b3520SBob Peterson return (atomic_read(&sdp->sd_log_pinned) + 1277f07b3520SBob Peterson atomic_read(&sdp->sd_log_blks_needed) >= 1278f07b3520SBob Peterson atomic_read(&sdp->sd_log_thresh1)); 12795e687eacSBenjamin Marzinski } 12805e687eacSBenjamin Marzinski 12815e687eacSBenjamin Marzinski static inline int gfs2_ail_flush_reqd(struct gfs2_sbd *sdp) 12825e687eacSBenjamin Marzinski { 12835e687eacSBenjamin Marzinski unsigned int used_blocks = sdp->sd_jdesc->jd_blocks - atomic_read(&sdp->sd_log_blks_free); 1284b066a4eeSAbhi Das 1285f07b3520SBob Peterson return used_blocks + atomic_read(&sdp->sd_log_blks_needed) >= 1286f07b3520SBob Peterson atomic_read(&sdp->sd_log_thresh2); 12875e687eacSBenjamin Marzinski } 1288ec69b188SSteven Whitehouse 1289ec69b188SSteven Whitehouse /** 1290ec69b188SSteven Whitehouse * gfs2_logd - Update log tail as Active Items get flushed to in-place blocks 1291c551f66cSLee Jones * @data: Pointer to GFS2 superblock 1292ec69b188SSteven Whitehouse * 1293ec69b188SSteven Whitehouse * Also, periodically check to make sure that we're using the most recent 1294ec69b188SSteven Whitehouse * journal index. 1295ec69b188SSteven Whitehouse */ 1296ec69b188SSteven Whitehouse 1297ec69b188SSteven Whitehouse int gfs2_logd(void *data) 1298ec69b188SSteven Whitehouse { 1299ec69b188SSteven Whitehouse struct gfs2_sbd *sdp = data; 13005e687eacSBenjamin Marzinski unsigned long t = 1; 1301ec69b188SSteven Whitehouse 1302ec69b188SSteven Whitehouse while (!kthread_should_stop()) { 1303ec69b188SSteven Whitehouse 1304d22f69a0SBob Peterson if (gfs2_withdrawn(sdp)) { 1305d22f69a0SBob Peterson msleep_interruptible(HZ); 1306d22f69a0SBob Peterson continue; 1307d22f69a0SBob Peterson } 1308942b0cddSBob Peterson /* Check for errors writing to the journal */ 1309942b0cddSBob Peterson if (sdp->sd_log_error) { 1310badb55ecSAndreas Gruenbacher gfs2_lm(sdp, 1311942b0cddSBob Peterson "GFS2: fsid=%s: error %d: " 1312942b0cddSBob Peterson "withdrawing the file system to " 1313942b0cddSBob Peterson "prevent further damage.\n", 1314942b0cddSBob Peterson sdp->sd_fsname, sdp->sd_log_error); 1315badb55ecSAndreas Gruenbacher gfs2_withdraw(sdp); 1316d22f69a0SBob Peterson continue; 1317942b0cddSBob Peterson } 1318942b0cddSBob Peterson 13195e687eacSBenjamin Marzinski if (gfs2_jrnl_flush_reqd(sdp) || t == 0) { 13205e4c7632SBob Peterson gfs2_ail1_empty(sdp, 0); 1321805c0907SBob Peterson gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL | 1322805c0907SBob Peterson GFS2_LFC_LOGD_JFLUSH_REQD); 1323ec69b188SSteven Whitehouse } 1324ec69b188SSteven Whitehouse 1325*b74cd55aSAndreas Gruenbacher if (test_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags) || 1326*b74cd55aSAndreas Gruenbacher gfs2_ail_flush_reqd(sdp)) { 1327*b74cd55aSAndreas Gruenbacher clear_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags); 13285e687eacSBenjamin Marzinski gfs2_ail1_start(sdp); 132926b06a69SSteven Whitehouse gfs2_ail1_wait(sdp); 13305e4c7632SBob Peterson gfs2_ail1_empty(sdp, 0); 1331805c0907SBob Peterson gfs2_log_flush(sdp, NULL, GFS2_LOG_HEAD_FLUSH_NORMAL | 1332805c0907SBob Peterson GFS2_LFC_LOGD_AIL_FLUSH_REQD); 13335e687eacSBenjamin Marzinski } 13345e687eacSBenjamin Marzinski 1335ec69b188SSteven Whitehouse t = gfs2_tune_get(sdp, gt_logd_secs) * HZ; 1336a0acae0eSTejun Heo 1337a0acae0eSTejun Heo try_to_freeze(); 13385e687eacSBenjamin Marzinski 13396df373b0SAndreas Gruenbacher t = wait_event_interruptible_timeout(sdp->sd_logd_waitq, 1340*b74cd55aSAndreas Gruenbacher test_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags) || 13416df373b0SAndreas Gruenbacher gfs2_ail_flush_reqd(sdp) || 13426df373b0SAndreas Gruenbacher gfs2_jrnl_flush_reqd(sdp) || 13436df373b0SAndreas Gruenbacher kthread_should_stop(), 13446df373b0SAndreas Gruenbacher t); 1345ec69b188SSteven Whitehouse } 1346ec69b188SSteven Whitehouse 1347ec69b188SSteven Whitehouse return 0; 1348ec69b188SSteven Whitehouse } 1349ec69b188SSteven Whitehouse 1350