From 94c7dde8adda82dd2ef14800e4066b370a102b28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bo=20Brant=C3=A9n?= Date: Wed, 19 Feb 2020 11:51:30 +0100 Subject: [PATCH] more work on jbd2 --- Ext4Fsd/jbd2/journal.c | 71 +++++++++++++++++------------------------ Ext4Fsd/jbd2/recovery.c | 38 ++++++++++++++++++++-- 2 files changed, 64 insertions(+), 45 deletions(-) diff --git a/Ext4Fsd/jbd2/journal.c b/Ext4Fsd/jbd2/journal.c index e03adce..ad9b1ee 100644 --- a/Ext4Fsd/jbd2/journal.c +++ b/Ext4Fsd/jbd2/journal.c @@ -1259,7 +1259,7 @@ journal_t *jbd2_journal_init_inode(struct inode *inode) char *p; unsigned long long blocknr; - DbgPrint("jbd2_journal_init_inode begin\n"); + DbgPrint("jbd2_journal_init_inode: begin\n"); blocknr = bmap(inode, 0); if (!blocknr) { /*pr_err("%s: Cannot locate journal superblock\n", @@ -1282,16 +1282,11 @@ journal_t *jbd2_journal_init_inode(struct inode *inode) p = strreplace(journal->j_devname, '/', '!'); sprintf(p, "-%lu", journal->j_inode->i_ino);*/ jbd2_stats_proc_init(journal); - DbgPrint("jbd2_journal_init_inode end\n"); + DbgPrint("jbd2_journal_init_inode: end\n"); return journal; } -journal_t *journal_init_inode(struct inode *inode) -{ - return jbd2_journal_init_inode(inode); -} - /* * If the journal init or create aborts, we need to mark the journal * superblock as being NULL to prevent the journal destroy from writing @@ -1453,7 +1448,7 @@ int jbd2_journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid, out: return ret; } -#if 0 + /** * jbd2_mark_journal_empty() - Mark on disk journal as empty. * @journal: The journal to update. @@ -1466,11 +1461,13 @@ static void jbd2_mark_journal_empty(journal_t *journal, int write_op) { journal_superblock_t *sb = journal->j_superblock; - BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex)); - read_lock(&journal->j_state_lock); + DbgPrint("jbd2_mark_journal_empty: begin\n"); + + //BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex)); + //read_lock(&journal->j_state_lock); /* Is it already empty? */ if (sb->s_start == 0) { - read_unlock(&journal->j_state_lock); + //read_unlock(&journal->j_state_lock); return; } jbd_debug(1, "JBD2: Marking journal as empty (seq %d)\n", @@ -1478,16 +1475,16 @@ static void jbd2_mark_journal_empty(journal_t *journal, int write_op) sb->s_sequence = cpu_to_be32(journal->j_tail_sequence); sb->s_start = cpu_to_be32(0); - read_unlock(&journal->j_state_lock); + //read_unlock(&journal->j_state_lock); jbd2_write_superblock(journal, write_op); /* Log is no longer empty */ - write_lock(&journal->j_state_lock); + //write_lock(&journal->j_state_lock); journal->j_flags |= JBD2_FLUSHED; - write_unlock(&journal->j_state_lock); + //write_unlock(&journal->j_state_lock); + DbgPrint("jbd2_mark_journal_empty: end\n"); } -#endif /** * jbd2_journal_update_sb_errno() - Update error in the journal. @@ -1668,7 +1665,7 @@ int jbd2_journal_load(journal_t *journal) int err; journal_superblock_t *sb; - DbgPrint("jbd2_journal_load begin\n"); + DbgPrint("jbd2_journal_load: begin\n"); err = load_superblock(journal); if (err) return err; @@ -1715,7 +1712,7 @@ int jbd2_journal_load(journal_t *journal) journal->j_flags &= ~JBD2_ABORT; journal->j_flags |= JBD2_LOADED; - DbgPrint("jbd2_journal_load end\n"); + DbgPrint("jbd2_journal_load: end\n"); return 0; recovery_error: @@ -1723,11 +1720,6 @@ recovery_error: return -EIO; } -int journal_load(journal_t *journal) -{ - return jbd2_journal_load(journal); -} - /** * void jbd2_journal_destroy() - Release a journal_t structure. * @journal: Journal to act on. @@ -1739,7 +1731,7 @@ int journal_load(journal_t *journal) int jbd2_journal_destroy(journal_t *journal) { int err = 0; - DbgPrint("jbd2_journal_destroy begin\n"); + DbgPrint("jbd2_journal_destroy: begin\n"); #if 0 /* Wait for the commit thread to wake up and die. */ journal_kill_thread(journal); @@ -1803,16 +1795,11 @@ int jbd2_journal_destroy(journal_t *journal) crypto_free_shash(journal->j_chksum_driver);*/ kfree(journal->j_wbuf); kfree(journal); - DbgPrint("jbd2_journal_destroy end\n"); + DbgPrint("jbd2_journal_destroy: end\n"); return err; } -int journal_destroy(journal_t *journal) -{ - return jbd2_journal_destroy(journal); -} - #if 0 /** *int jbd2_journal_check_used_features () - Check if features specified are used. @@ -2064,7 +2051,7 @@ int jbd2_journal_flush(journal_t *journal) out: return err; } - +#endif /** * int jbd2_journal_wipe() - Wipe journal contents * @journal: Journal to act on. @@ -2082,14 +2069,18 @@ int jbd2_journal_wipe(journal_t *journal, int write) { int err = 0; + DbgPrint("jbd2_journal_wipe: begin\n"); + J_ASSERT (!(journal->j_flags & JBD2_LOADED)); err = load_superblock(journal); if (err) return err; - if (!journal->j_tail) + if (!journal->j_tail) { + DbgPrint("jbd2_journal_wipe: journal is clean\n"); goto no_recovery; + } printk(KERN_WARNING "JBD2: %s recovery information on journal\n", write ? "Clearing" : "Ignoring"); @@ -2098,14 +2089,15 @@ int jbd2_journal_wipe(journal_t *journal, int write) if (write) { /* Lock to make assertions happy... */ mutex_lock(&journal->j_checkpoint_mutex); - jbd2_mark_journal_empty(journal, REQ_SYNC | REQ_FUA); + jbd2_mark_journal_empty(journal, 0/*REQ_SYNC | REQ_FUA*/); mutex_unlock(&journal->j_checkpoint_mutex); } no_recovery: + DbgPrint("jbd2_journal_wipe end:\n"); return err; } -#endif + /* * Journal abort has very specific semantics, which we describe * for journal abort. @@ -2651,11 +2643,6 @@ restart: } #endif -int journal_wipe_recovery(journal_t *journal) -{ - return 0; -} - #ifdef CONFIG_PROC_FS #define JBD2_STATS_PROC_NAME "fs/jbd2" @@ -2735,7 +2722,7 @@ static int __init journal_init(void) { int ret; - DbgPrint("journal_init begin\n"); + DbgPrint("journal_init: begin\n"); /*BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024);*/ @@ -2745,7 +2732,7 @@ static int __init journal_init(void) } else { jbd2_journal_destroy_caches(); } - DbgPrint("journal_init end\n"); + DbgPrint("journal_init: end\n"); return ret; } @@ -2756,10 +2743,10 @@ static void __exit journal_exit(void) if (n) printk(KERN_ERR "JBD2: leaked %d journal_heads!\n", n); #endif - DbgPrint("journal_exit begin\n"); + DbgPrint("journal_exit: begin\n"); jbd2_remove_jbd_stats_proc_entry(); jbd2_journal_destroy_caches(); - DbgPrint("journal_exit end\n"); + DbgPrint("journal_exit: end\n"); } MODULE_LICENSE("GPL"); diff --git a/Ext4Fsd/jbd2/recovery.c b/Ext4Fsd/jbd2/recovery.c index 0d0ab0c..bb6c4aa 100644 --- a/Ext4Fsd/jbd2/recovery.c +++ b/Ext4Fsd/jbd2/recovery.c @@ -291,7 +291,7 @@ int jbd2_journal_recover(journal_t *journal) }*/ return err; } -#if 0 + /** * jbd2_journal_skip_recovery - Start journal and wipe exiting records * @journal: journal to startup @@ -311,6 +311,8 @@ int jbd2_journal_skip_recovery(journal_t *journal) struct recovery_info info; + DbgPrint("jbd2_journal_skip_recovery: begin\n"); + memset (&info, 0, sizeof(info)); err = do_one_pass(journal, &info, PASS_SCAN); @@ -330,9 +332,10 @@ int jbd2_journal_skip_recovery(journal_t *journal) } journal->j_tail = 0; + DbgPrint("jbd2_journal_skip_recovery: end\n"); return err; } -#endif + static inline unsigned long long read_tag_block(journal_t *journal, journal_block_tag_t *tag) { @@ -341,7 +344,36 @@ static inline unsigned long long read_tag_block(journal_t *journal, block |= (u64)be32_to_cpu(tag->t_blocknr_high) << 32; return block; } -#define crc32_be crc32c + +/* + * The standard CRC-32 polynomial, first popularized by Ethernet. + * x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0 + */ +#define CRC32_POLY_LE 0xedb88320 +#define CRC32_POLY_BE 0x04c11db7 + +u32 crc32_le(u32 crc, unsigned char const *p, size_t len) +{ + int i; + while (len--) { + crc ^= *p++; + for (i = 0; i < 8; i++) + crc = (crc >> 1) ^ ((crc & 1) ? CRC32_POLY_LE : 0); + } + return crc; +} + +u32 crc32_be(u32 crc, unsigned char const *p, size_t len) +{ + int i; + while (len--) { + crc ^= *p++ << 24; + for (i = 0; i < 8; i++) + crc = (crc << 1) ^ ((crc & 0x80000000) ? CRC32_POLY_BE : 0); + } + return crc; +} + /* * calc_chksums calculates the checksums for the blocks described in the * descriptor block.