1
0
mirror of https://github.com/bobranten/Ext4Fsd.git synced 2025-10-30 05:18:31 -05:00

more work on jbd2

This commit is contained in:
Bo Brantén
2020-02-19 11:51:30 +01:00
parent 857c69dbb6
commit 94c7dde8ad
2 changed files with 64 additions and 45 deletions

View File

@@ -1259,7 +1259,7 @@ journal_t *jbd2_journal_init_inode(struct inode *inode)
char *p; char *p;
unsigned long long blocknr; unsigned long long blocknr;
DbgPrint("jbd2_journal_init_inode begin\n"); DbgPrint("jbd2_journal_init_inode: begin\n");
blocknr = bmap(inode, 0); blocknr = bmap(inode, 0);
if (!blocknr) { if (!blocknr) {
/*pr_err("%s: Cannot locate journal superblock\n", /*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, '/', '!'); p = strreplace(journal->j_devname, '/', '!');
sprintf(p, "-%lu", journal->j_inode->i_ino);*/ sprintf(p, "-%lu", journal->j_inode->i_ino);*/
jbd2_stats_proc_init(journal); jbd2_stats_proc_init(journal);
DbgPrint("jbd2_journal_init_inode end\n"); DbgPrint("jbd2_journal_init_inode: end\n");
return journal; 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 * If the journal init or create aborts, we need to mark the journal
* superblock as being NULL to prevent the journal destroy from writing * 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: out:
return ret; return ret;
} }
#if 0
/** /**
* jbd2_mark_journal_empty() - Mark on disk journal as empty. * jbd2_mark_journal_empty() - Mark on disk journal as empty.
* @journal: The journal to update. * @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; journal_superblock_t *sb = journal->j_superblock;
BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex)); DbgPrint("jbd2_mark_journal_empty: begin\n");
read_lock(&journal->j_state_lock);
//BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex));
//read_lock(&journal->j_state_lock);
/* Is it already empty? */ /* Is it already empty? */
if (sb->s_start == 0) { if (sb->s_start == 0) {
read_unlock(&journal->j_state_lock); //read_unlock(&journal->j_state_lock);
return; return;
} }
jbd_debug(1, "JBD2: Marking journal as empty (seq %d)\n", 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_sequence = cpu_to_be32(journal->j_tail_sequence);
sb->s_start = cpu_to_be32(0); 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); jbd2_write_superblock(journal, write_op);
/* Log is no longer empty */ /* Log is no longer empty */
write_lock(&journal->j_state_lock); //write_lock(&journal->j_state_lock);
journal->j_flags |= JBD2_FLUSHED; 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. * jbd2_journal_update_sb_errno() - Update error in the journal.
@@ -1668,7 +1665,7 @@ int jbd2_journal_load(journal_t *journal)
int err; int err;
journal_superblock_t *sb; journal_superblock_t *sb;
DbgPrint("jbd2_journal_load begin\n"); DbgPrint("jbd2_journal_load: begin\n");
err = load_superblock(journal); err = load_superblock(journal);
if (err) if (err)
return err; return err;
@@ -1715,7 +1712,7 @@ int jbd2_journal_load(journal_t *journal)
journal->j_flags &= ~JBD2_ABORT; journal->j_flags &= ~JBD2_ABORT;
journal->j_flags |= JBD2_LOADED; journal->j_flags |= JBD2_LOADED;
DbgPrint("jbd2_journal_load end\n"); DbgPrint("jbd2_journal_load: end\n");
return 0; return 0;
recovery_error: recovery_error:
@@ -1723,11 +1720,6 @@ recovery_error:
return -EIO; return -EIO;
} }
int journal_load(journal_t *journal)
{
return jbd2_journal_load(journal);
}
/** /**
* void jbd2_journal_destroy() - Release a journal_t structure. * void jbd2_journal_destroy() - Release a journal_t structure.
* @journal: Journal to act on. * @journal: Journal to act on.
@@ -1739,7 +1731,7 @@ int journal_load(journal_t *journal)
int jbd2_journal_destroy(journal_t *journal) int jbd2_journal_destroy(journal_t *journal)
{ {
int err = 0; int err = 0;
DbgPrint("jbd2_journal_destroy begin\n"); DbgPrint("jbd2_journal_destroy: begin\n");
#if 0 #if 0
/* Wait for the commit thread to wake up and die. */ /* Wait for the commit thread to wake up and die. */
journal_kill_thread(journal); journal_kill_thread(journal);
@@ -1803,16 +1795,11 @@ int jbd2_journal_destroy(journal_t *journal)
crypto_free_shash(journal->j_chksum_driver);*/ crypto_free_shash(journal->j_chksum_driver);*/
kfree(journal->j_wbuf); kfree(journal->j_wbuf);
kfree(journal); kfree(journal);
DbgPrint("jbd2_journal_destroy end\n"); DbgPrint("jbd2_journal_destroy: end\n");
return err; return err;
} }
int journal_destroy(journal_t *journal)
{
return jbd2_journal_destroy(journal);
}
#if 0 #if 0
/** /**
*int jbd2_journal_check_used_features () - Check if features specified are used. *int jbd2_journal_check_used_features () - Check if features specified are used.
@@ -2064,7 +2051,7 @@ int jbd2_journal_flush(journal_t *journal)
out: out:
return err; return err;
} }
#endif
/** /**
* int jbd2_journal_wipe() - Wipe journal contents * int jbd2_journal_wipe() - Wipe journal contents
* @journal: Journal to act on. * @journal: Journal to act on.
@@ -2082,14 +2069,18 @@ int jbd2_journal_wipe(journal_t *journal, int write)
{ {
int err = 0; int err = 0;
DbgPrint("jbd2_journal_wipe: begin\n");
J_ASSERT (!(journal->j_flags & JBD2_LOADED)); J_ASSERT (!(journal->j_flags & JBD2_LOADED));
err = load_superblock(journal); err = load_superblock(journal);
if (err) if (err)
return err; return err;
if (!journal->j_tail) if (!journal->j_tail) {
DbgPrint("jbd2_journal_wipe: journal is clean\n");
goto no_recovery; goto no_recovery;
}
printk(KERN_WARNING "JBD2: %s recovery information on journal\n", printk(KERN_WARNING "JBD2: %s recovery information on journal\n",
write ? "Clearing" : "Ignoring"); write ? "Clearing" : "Ignoring");
@@ -2098,14 +2089,15 @@ int jbd2_journal_wipe(journal_t *journal, int write)
if (write) { if (write) {
/* Lock to make assertions happy... */ /* Lock to make assertions happy... */
mutex_lock(&journal->j_checkpoint_mutex); 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); mutex_unlock(&journal->j_checkpoint_mutex);
} }
no_recovery: no_recovery:
DbgPrint("jbd2_journal_wipe end:\n");
return err; return err;
} }
#endif
/* /*
* Journal abort has very specific semantics, which we describe * Journal abort has very specific semantics, which we describe
* for journal abort. * for journal abort.
@@ -2651,11 +2643,6 @@ restart:
} }
#endif #endif
int journal_wipe_recovery(journal_t *journal)
{
return 0;
}
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
#define JBD2_STATS_PROC_NAME "fs/jbd2" #define JBD2_STATS_PROC_NAME "fs/jbd2"
@@ -2735,7 +2722,7 @@ static int __init journal_init(void)
{ {
int ret; int ret;
DbgPrint("journal_init begin\n"); DbgPrint("journal_init: begin\n");
/*BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024);*/ /*BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024);*/
@@ -2745,7 +2732,7 @@ static int __init journal_init(void)
} else { } else {
jbd2_journal_destroy_caches(); jbd2_journal_destroy_caches();
} }
DbgPrint("journal_init end\n"); DbgPrint("journal_init: end\n");
return ret; return ret;
} }
@@ -2756,10 +2743,10 @@ static void __exit journal_exit(void)
if (n) if (n)
printk(KERN_ERR "JBD2: leaked %d journal_heads!\n", n); printk(KERN_ERR "JBD2: leaked %d journal_heads!\n", n);
#endif #endif
DbgPrint("journal_exit begin\n"); DbgPrint("journal_exit: begin\n");
jbd2_remove_jbd_stats_proc_entry(); jbd2_remove_jbd_stats_proc_entry();
jbd2_journal_destroy_caches(); jbd2_journal_destroy_caches();
DbgPrint("journal_exit end\n"); DbgPrint("journal_exit: end\n");
} }
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");

View File

@@ -291,7 +291,7 @@ int jbd2_journal_recover(journal_t *journal)
}*/ }*/
return err; return err;
} }
#if 0
/** /**
* jbd2_journal_skip_recovery - Start journal and wipe exiting records * jbd2_journal_skip_recovery - Start journal and wipe exiting records
* @journal: journal to startup * @journal: journal to startup
@@ -311,6 +311,8 @@ int jbd2_journal_skip_recovery(journal_t *journal)
struct recovery_info info; struct recovery_info info;
DbgPrint("jbd2_journal_skip_recovery: begin\n");
memset (&info, 0, sizeof(info)); memset (&info, 0, sizeof(info));
err = do_one_pass(journal, &info, PASS_SCAN); err = do_one_pass(journal, &info, PASS_SCAN);
@@ -330,9 +332,10 @@ int jbd2_journal_skip_recovery(journal_t *journal)
} }
journal->j_tail = 0; journal->j_tail = 0;
DbgPrint("jbd2_journal_skip_recovery: end\n");
return err; return err;
} }
#endif
static inline unsigned long long read_tag_block(journal_t *journal, static inline unsigned long long read_tag_block(journal_t *journal,
journal_block_tag_t *tag) 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; block |= (u64)be32_to_cpu(tag->t_blocknr_high) << 32;
return block; 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 * calc_chksums calculates the checksums for the blocks described in the
* descriptor block. * descriptor block.