@@ -1427,6 +1427,48 @@ static int journal_revoke_records_per_block(journal_t *journal)
1427
1427
return space / record_size ;
1428
1428
}
1429
1429
1430
+ static int jbd2_journal_get_max_txn_bufs (journal_t * journal )
1431
+ {
1432
+ return (journal -> j_total_len - journal -> j_fc_wbufsize ) / 4 ;
1433
+ }
1434
+
1435
+ /*
1436
+ * Base amount of descriptor blocks we reserve for each transaction.
1437
+ */
1438
+ static int jbd2_descriptor_blocks_per_trans (journal_t * journal )
1439
+ {
1440
+ int tag_space = journal -> j_blocksize - sizeof (journal_header_t );
1441
+ int tags_per_block ;
1442
+
1443
+ /* Subtract UUID */
1444
+ tag_space -= 16 ;
1445
+ if (jbd2_journal_has_csum_v2or3 (journal ))
1446
+ tag_space -= sizeof (struct jbd2_journal_block_tail );
1447
+ /* Commit code leaves a slack space of 16 bytes at the end of block */
1448
+ tags_per_block = (tag_space - 16 ) / journal_tag_bytes (journal );
1449
+ /*
1450
+ * Revoke descriptors are accounted separately so we need to reserve
1451
+ * space for commit block and normal transaction descriptor blocks.
1452
+ */
1453
+ return 1 + DIV_ROUND_UP (jbd2_journal_get_max_txn_bufs (journal ),
1454
+ tags_per_block );
1455
+ }
1456
+
1457
+ /*
1458
+ * Initialize number of blocks each transaction reserves for its bookkeeping
1459
+ * and maximum number of blocks a transaction can use. This needs to be called
1460
+ * after the journal size and the fastcommit area size are initialized.
1461
+ */
1462
+ static void jbd2_journal_init_transaction_limits (journal_t * journal )
1463
+ {
1464
+ journal -> j_revoke_records_per_block =
1465
+ journal_revoke_records_per_block (journal );
1466
+ journal -> j_transaction_overhead_buffers =
1467
+ jbd2_descriptor_blocks_per_trans (journal );
1468
+ journal -> j_max_transaction_buffers =
1469
+ jbd2_journal_get_max_txn_bufs (journal );
1470
+ }
1471
+
1430
1472
/*
1431
1473
* Load the on-disk journal superblock and read the key fields into the
1432
1474
* journal_t.
@@ -1468,8 +1510,8 @@ static int journal_load_superblock(journal_t *journal)
1468
1510
if (jbd2_journal_has_csum_v2or3 (journal ))
1469
1511
journal -> j_csum_seed = jbd2_chksum (journal , ~0 , sb -> s_uuid ,
1470
1512
sizeof (sb -> s_uuid ));
1471
- journal -> j_revoke_records_per_block =
1472
- journal_revoke_records_per_block (journal );
1513
+ /* After journal features are set, we can compute transaction limits */
1514
+ jbd2_journal_init_transaction_limits (journal );
1473
1515
1474
1516
if (jbd2_has_feature_fast_commit (journal )) {
1475
1517
journal -> j_fc_last = be32_to_cpu (sb -> s_maxlen );
@@ -1674,11 +1716,6 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
1674
1716
return journal ;
1675
1717
}
1676
1718
1677
- static int jbd2_journal_get_max_txn_bufs (journal_t * journal )
1678
- {
1679
- return (journal -> j_total_len - journal -> j_fc_wbufsize ) / 4 ;
1680
- }
1681
-
1682
1719
/*
1683
1720
* Given a journal_t structure, initialise the various fields for
1684
1721
* startup of a new journaling session. We use this both when creating
@@ -1724,8 +1761,6 @@ static int journal_reset(journal_t *journal)
1724
1761
journal -> j_commit_sequence = journal -> j_transaction_sequence - 1 ;
1725
1762
journal -> j_commit_request = journal -> j_commit_sequence ;
1726
1763
1727
- journal -> j_max_transaction_buffers = jbd2_journal_get_max_txn_bufs (journal );
1728
-
1729
1764
/*
1730
1765
* Now that journal recovery is done, turn fast commits off here. This
1731
1766
* way, if fast commit was enabled before the crash but if now FS has
@@ -2266,8 +2301,6 @@ jbd2_journal_initialize_fast_commit(journal_t *journal)
2266
2301
journal -> j_fc_first = journal -> j_last + 1 ;
2267
2302
journal -> j_fc_off = 0 ;
2268
2303
journal -> j_free = journal -> j_last - journal -> j_first ;
2269
- journal -> j_max_transaction_buffers =
2270
- jbd2_journal_get_max_txn_bufs (journal );
2271
2304
2272
2305
return 0 ;
2273
2306
}
@@ -2355,8 +2388,7 @@ int jbd2_journal_set_features(journal_t *journal, unsigned long compat,
2355
2388
sb -> s_feature_ro_compat |= cpu_to_be32 (ro );
2356
2389
sb -> s_feature_incompat |= cpu_to_be32 (incompat );
2357
2390
unlock_buffer (journal -> j_sb_buffer );
2358
- journal -> j_revoke_records_per_block =
2359
- journal_revoke_records_per_block (journal );
2391
+ jbd2_journal_init_transaction_limits (journal );
2360
2392
2361
2393
return 1 ;
2362
2394
#undef COMPAT_FEATURE_ON
@@ -2387,8 +2419,7 @@ void jbd2_journal_clear_features(journal_t *journal, unsigned long compat,
2387
2419
sb -> s_feature_compat &= ~cpu_to_be32 (compat );
2388
2420
sb -> s_feature_ro_compat &= ~cpu_to_be32 (ro );
2389
2421
sb -> s_feature_incompat &= ~cpu_to_be32 (incompat );
2390
- journal -> j_revoke_records_per_block =
2391
- journal_revoke_records_per_block (journal );
2422
+ jbd2_journal_init_transaction_limits (journal );
2392
2423
}
2393
2424
EXPORT_SYMBOL (jbd2_journal_clear_features );
2394
2425
0 commit comments