journal.c (7a8532b537ca069bbf5ae4890b4f2f79eb856a3a) | journal.c (b81c3758c1df0c308ba8b28934fcd63d9dba9c41) |
---|---|
1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * linux/fs/jbd2/journal.c 4 * 5 * Written by Stephen C. Tweedie <sct@redhat.com>, 1998 6 * 7 * Copyright 1998 Red Hat corp --- All Rights Reserved 8 * --- 1437 unchanged lines hidden (view full) --- 1446 else 1447 record_size = 4; 1448 1449 if (jbd2_journal_has_csum_v2or3(journal)) 1450 space -= sizeof(struct jbd2_journal_block_tail); 1451 return space / record_size; 1452} 1453 | 1// SPDX-License-Identifier: GPL-2.0+ 2/* 3 * linux/fs/jbd2/journal.c 4 * 5 * Written by Stephen C. Tweedie <sct@redhat.com>, 1998 6 * 7 * Copyright 1998 Red Hat corp --- All Rights Reserved 8 * --- 1437 unchanged lines hidden (view full) --- 1446 else 1447 record_size = 4; 1448 1449 if (jbd2_journal_has_csum_v2or3(journal)) 1450 space -= sizeof(struct jbd2_journal_block_tail); 1451 return space / record_size; 1452} 1453 |
1454static int jbd2_journal_get_max_txn_bufs(journal_t *journal) 1455{ 1456 return (journal->j_total_len - journal->j_fc_wbufsize) / 4; 1457} 1458 |
|
1454/* | 1459/* |
1460 * Base amount of descriptor blocks we reserve for each transaction. 1461 */ 1462static int jbd2_descriptor_blocks_per_trans(journal_t *journal) 1463{ 1464 int tag_space = journal->j_blocksize - sizeof(journal_header_t); 1465 int tags_per_block; 1466 1467 /* Subtract UUID */ 1468 tag_space -= 16; 1469 if (jbd2_journal_has_csum_v2or3(journal)) 1470 tag_space -= sizeof(struct jbd2_journal_block_tail); 1471 /* Commit code leaves a slack space of 16 bytes at the end of block */ 1472 tags_per_block = (tag_space - 16) / journal_tag_bytes(journal); 1473 /* 1474 * Revoke descriptors are accounted separately so we need to reserve 1475 * space for commit block and normal transaction descriptor blocks. 1476 */ 1477 return 1 + DIV_ROUND_UP(jbd2_journal_get_max_txn_bufs(journal), 1478 tags_per_block); 1479} 1480 1481/* 1482 * Initialize number of blocks each transaction reserves for its bookkeeping 1483 * and maximum number of blocks a transaction can use. This needs to be called 1484 * after the journal size and the fastcommit area size are initialized. 1485 */ 1486static void jbd2_journal_init_transaction_limits(journal_t *journal) 1487{ 1488 journal->j_revoke_records_per_block = 1489 journal_revoke_records_per_block(journal); 1490 journal->j_transaction_overhead_buffers = 1491 jbd2_descriptor_blocks_per_trans(journal); 1492 journal->j_max_transaction_buffers = 1493 jbd2_journal_get_max_txn_bufs(journal); 1494} 1495 1496/* |
|
1455 * Load the on-disk journal superblock and read the key fields into the 1456 * journal_t. 1457 */ 1458static int journal_load_superblock(journal_t *journal) 1459{ 1460 int err; 1461 struct buffer_head *bh; 1462 journal_superblock_t *sb; --- 24 unchanged lines hidden (view full) --- 1487 journal->j_last = be32_to_cpu(sb->s_maxlen); 1488 1489 if (be32_to_cpu(sb->s_maxlen) < journal->j_total_len) 1490 journal->j_total_len = be32_to_cpu(sb->s_maxlen); 1491 /* Precompute checksum seed for all metadata */ 1492 if (jbd2_journal_has_csum_v2or3(journal)) 1493 journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid, 1494 sizeof(sb->s_uuid)); | 1497 * Load the on-disk journal superblock and read the key fields into the 1498 * journal_t. 1499 */ 1500static int journal_load_superblock(journal_t *journal) 1501{ 1502 int err; 1503 struct buffer_head *bh; 1504 journal_superblock_t *sb; --- 24 unchanged lines hidden (view full) --- 1529 journal->j_last = be32_to_cpu(sb->s_maxlen); 1530 1531 if (be32_to_cpu(sb->s_maxlen) < journal->j_total_len) 1532 journal->j_total_len = be32_to_cpu(sb->s_maxlen); 1533 /* Precompute checksum seed for all metadata */ 1534 if (jbd2_journal_has_csum_v2or3(journal)) 1535 journal->j_csum_seed = jbd2_chksum(journal, ~0, sb->s_uuid, 1536 sizeof(sb->s_uuid)); |
1495 journal->j_revoke_records_per_block = 1496 journal_revoke_records_per_block(journal); | 1537 /* After journal features are set, we can compute transaction limits */ 1538 jbd2_journal_init_transaction_limits(journal); |
1497 1498 if (jbd2_has_feature_fast_commit(journal)) { 1499 journal->j_fc_last = be32_to_cpu(sb->s_maxlen); 1500 journal->j_last = journal->j_fc_last - 1501 jbd2_journal_get_num_fc_blks(sb); 1502 journal->j_fc_first = journal->j_last + 1; 1503 journal->j_fc_off = 0; 1504 } --- 180 unchanged lines hidden (view full) --- 1685 snprintf(journal->j_devname, sizeof(journal->j_devname), 1686 "%pg-%lu", journal->j_dev, journal->j_inode->i_ino); 1687 strreplace(journal->j_devname, '/', '!'); 1688 jbd2_stats_proc_init(journal); 1689 1690 return journal; 1691} 1692 | 1539 1540 if (jbd2_has_feature_fast_commit(journal)) { 1541 journal->j_fc_last = be32_to_cpu(sb->s_maxlen); 1542 journal->j_last = journal->j_fc_last - 1543 jbd2_journal_get_num_fc_blks(sb); 1544 journal->j_fc_first = journal->j_last + 1; 1545 journal->j_fc_off = 0; 1546 } --- 180 unchanged lines hidden (view full) --- 1727 snprintf(journal->j_devname, sizeof(journal->j_devname), 1728 "%pg-%lu", journal->j_dev, journal->j_inode->i_ino); 1729 strreplace(journal->j_devname, '/', '!'); 1730 jbd2_stats_proc_init(journal); 1731 1732 return journal; 1733} 1734 |
1693static int jbd2_journal_get_max_txn_bufs(journal_t *journal) 1694{ 1695 return (journal->j_total_len - journal->j_fc_wbufsize) / 4; 1696} 1697 | |
1698/* 1699 * Given a journal_t structure, initialise the various fields for 1700 * startup of a new journaling session. We use this both when creating 1701 * a journal, and after recovering an old journal to reset it for 1702 * subsequent use. 1703 */ 1704 1705static int journal_reset(journal_t *journal) --- 29 unchanged lines hidden (view full) --- 1735 } 1736 journal->j_tail = journal->j_head; 1737 journal->j_free = journal->j_last - journal->j_first; 1738 1739 journal->j_tail_sequence = journal->j_transaction_sequence; 1740 journal->j_commit_sequence = journal->j_transaction_sequence - 1; 1741 journal->j_commit_request = journal->j_commit_sequence; 1742 | 1735/* 1736 * Given a journal_t structure, initialise the various fields for 1737 * startup of a new journaling session. We use this both when creating 1738 * a journal, and after recovering an old journal to reset it for 1739 * subsequent use. 1740 */ 1741 1742static int journal_reset(journal_t *journal) --- 29 unchanged lines hidden (view full) --- 1772 } 1773 journal->j_tail = journal->j_head; 1774 journal->j_free = journal->j_last - journal->j_first; 1775 1776 journal->j_tail_sequence = journal->j_transaction_sequence; 1777 journal->j_commit_sequence = journal->j_transaction_sequence - 1; 1778 journal->j_commit_request = journal->j_commit_sequence; 1779 |
1743 journal->j_max_transaction_buffers = jbd2_journal_get_max_txn_bufs(journal); 1744 | |
1745 /* 1746 * Now that journal recovery is done, turn fast commits off here. This 1747 * way, if fast commit was enabled before the crash but if now FS has 1748 * disabled it, we don't enable fast commits. 1749 */ 1750 jbd2_clear_feature_fast_commit(journal); 1751 1752 /* --- 524 unchanged lines hidden (view full) --- 2277 return -ENOMEM; 2278 2279 journal->j_fc_wbufsize = num_fc_blks; 2280 journal->j_fc_last = journal->j_last; 2281 journal->j_last = journal->j_fc_last - num_fc_blks; 2282 journal->j_fc_first = journal->j_last + 1; 2283 journal->j_fc_off = 0; 2284 journal->j_free = journal->j_last - journal->j_first; | 1780 /* 1781 * Now that journal recovery is done, turn fast commits off here. This 1782 * way, if fast commit was enabled before the crash but if now FS has 1783 * disabled it, we don't enable fast commits. 1784 */ 1785 jbd2_clear_feature_fast_commit(journal); 1786 1787 /* --- 524 unchanged lines hidden (view full) --- 2312 return -ENOMEM; 2313 2314 journal->j_fc_wbufsize = num_fc_blks; 2315 journal->j_fc_last = journal->j_last; 2316 journal->j_last = journal->j_fc_last - num_fc_blks; 2317 journal->j_fc_first = journal->j_last + 1; 2318 journal->j_fc_off = 0; 2319 journal->j_free = journal->j_last - journal->j_first; |
2285 journal->j_max_transaction_buffers = 2286 jbd2_journal_get_max_txn_bufs(journal); | |
2287 2288 return 0; 2289} 2290 2291/** 2292 * jbd2_journal_set_features() - Mark a given journal feature in the superblock 2293 * @journal: Journal to act on. 2294 * @compat: bitmask of compatible features --- 71 unchanged lines hidden (view full) --- 2366 sb->s_feature_incompat &= 2367 ~cpu_to_be32(JBD2_FEATURE_INCOMPAT_CSUM_V2 | 2368 JBD2_FEATURE_INCOMPAT_CSUM_V3); 2369 2370 sb->s_feature_compat |= cpu_to_be32(compat); 2371 sb->s_feature_ro_compat |= cpu_to_be32(ro); 2372 sb->s_feature_incompat |= cpu_to_be32(incompat); 2373 unlock_buffer(journal->j_sb_buffer); | 2320 2321 return 0; 2322} 2323 2324/** 2325 * jbd2_journal_set_features() - Mark a given journal feature in the superblock 2326 * @journal: Journal to act on. 2327 * @compat: bitmask of compatible features --- 71 unchanged lines hidden (view full) --- 2399 sb->s_feature_incompat &= 2400 ~cpu_to_be32(JBD2_FEATURE_INCOMPAT_CSUM_V2 | 2401 JBD2_FEATURE_INCOMPAT_CSUM_V3); 2402 2403 sb->s_feature_compat |= cpu_to_be32(compat); 2404 sb->s_feature_ro_compat |= cpu_to_be32(ro); 2405 sb->s_feature_incompat |= cpu_to_be32(incompat); 2406 unlock_buffer(journal->j_sb_buffer); |
2374 journal->j_revoke_records_per_block = 2375 journal_revoke_records_per_block(journal); | 2407 jbd2_journal_init_transaction_limits(journal); |
2376 2377 return 1; 2378#undef COMPAT_FEATURE_ON 2379#undef INCOMPAT_FEATURE_ON 2380} 2381 2382/* 2383 * jbd2_journal_clear_features() - Clear a given journal feature in the --- 14 unchanged lines hidden (view full) --- 2398 jbd2_debug(1, "Clear features 0x%lx/0x%lx/0x%lx\n", 2399 compat, ro, incompat); 2400 2401 sb = journal->j_superblock; 2402 2403 sb->s_feature_compat &= ~cpu_to_be32(compat); 2404 sb->s_feature_ro_compat &= ~cpu_to_be32(ro); 2405 sb->s_feature_incompat &= ~cpu_to_be32(incompat); | 2408 2409 return 1; 2410#undef COMPAT_FEATURE_ON 2411#undef INCOMPAT_FEATURE_ON 2412} 2413 2414/* 2415 * jbd2_journal_clear_features() - Clear a given journal feature in the --- 14 unchanged lines hidden (view full) --- 2430 jbd2_debug(1, "Clear features 0x%lx/0x%lx/0x%lx\n", 2431 compat, ro, incompat); 2432 2433 sb = journal->j_superblock; 2434 2435 sb->s_feature_compat &= ~cpu_to_be32(compat); 2436 sb->s_feature_ro_compat &= ~cpu_to_be32(ro); 2437 sb->s_feature_incompat &= ~cpu_to_be32(incompat); |
2406 journal->j_revoke_records_per_block = 2407 journal_revoke_records_per_block(journal); | 2438 jbd2_journal_init_transaction_limits(journal); |
2408} 2409EXPORT_SYMBOL(jbd2_journal_clear_features); 2410 2411/** 2412 * jbd2_journal_flush() - Flush journal 2413 * @journal: Journal to act on. 2414 * @flags: optional operation on the journal blocks after the flush (see below) 2415 * --- 769 unchanged lines hidden --- | 2439} 2440EXPORT_SYMBOL(jbd2_journal_clear_features); 2441 2442/** 2443 * jbd2_journal_flush() - Flush journal 2444 * @journal: Journal to act on. 2445 * @flags: optional operation on the journal blocks after the flush (see below) 2446 * --- 769 unchanged lines hidden --- |