* @brief Journal handle functions
*/
-#include "ext4_config.h"
-#include "ext4_types.h"
-#include "ext4_misc.h"
-#include "ext4_errno.h"
-#include "ext4_debug.h"
-
-#include "ext4_fs.h"
-#include "ext4_super.h"
-#include "ext4_journal.h"
-#include "ext4_blockdev.h"
-#include "ext4_crc32.h"
-#include "ext4_journal.h"
+#include <ext4_config.h>
+#include <ext4_types.h>
+#include <ext4_misc.h>
+#include <ext4_errno.h>
+#include <ext4_debug.h>
+
+#include <ext4_fs.h>
+#include <ext4_super.h>
+#include <ext4_journal.h>
+#include <ext4_blockdev.h>
+#include <ext4_crc32.h>
+#include <ext4_journal.h>
#include <string.h>
#include <stdlib.h>
/**@brief block number stored in this tag.*/
ext4_fsblk_t block;
+ /**@brief Is the first 4 bytes of block equals to
+ * JBD_MAGIC_NUMBER? */
+ bool is_escape;
+
/**@brief whether UUID part exists or not.*/
bool uuid_exist;
tag_info->tag_bytes = tag_bytes;
tag_info->uuid_exist = false;
tag_info->last_tag = false;
+ tag_info->is_escape = false;
/* See whether it is possible to hold a valid block tag.*/
if (remain_buf_size - tag_bytes < 0)
(uint64_t)jbd_get32(tag, blocknr_high) << 32;
if (jbd_get32(tag, flags) & JBD_FLAG_ESCAPE)
- tag_info->block = 0;
+ tag_info->is_escape = true;
if (!(jbd_get32(tag, flags) & JBD_FLAG_SAME_UUID)) {
/* See whether it is possible to hold UUID part.*/
(uint64_t)jbd_get32(tag, blocknr_high) << 32;
if (jbd_get16(tag, flags) & JBD_FLAG_ESCAPE)
- tag_info->block = 0;
+ tag_info->is_escape = true;
if (!(jbd_get16(tag, flags) & JBD_FLAG_SAME_UUID)) {
/* See whether it is possible to hold UUID part.*/
jbd_set32(tag, flags,
jbd_get32(tag, flags) | JBD_FLAG_LAST_TAG);
+ if (tag_info->is_escape)
+ jbd_set32(tag, flags,
+ jbd_get32(tag, flags) | JBD_FLAG_ESCAPE);
+
} else {
struct jbd_block_tag *tag = __tag;
memset(tag, 0, sizeof(struct jbd_block_tag));
jbd_set16(tag, flags,
jbd_get16(tag, flags) | JBD_FLAG_LAST_TAG);
+
+ if (tag_info->is_escape)
+ jbd_set16(tag, flags,
+ jbd_get16(tag, flags) | JBD_FLAG_ESCAPE);
+
}
return EOK;
}
void *__tag_start,
int32_t tag_tbl_size,
void (*func)(struct jbd_fs * jbd_fs,
- ext4_fsblk_t block,
- uint8_t *uuid,
- void *arg),
+ struct tag_info *tag_info,
+ void *arg),
void *arg)
{
char *tag_start, *tag_ptr;
break;
if (func)
- func(jbd_fs, tag_info.block, tag_info.uuid, arg);
+ func(jbd_fs, &tag_info, arg);
/* Stop the iteration when we reach the last tag. */
if (tag_info.last_tag)
}
static void jbd_display_block_tags(struct jbd_fs *jbd_fs,
- ext4_fsblk_t block,
- uint8_t *uuid,
+ struct tag_info *tag_info,
void *arg)
{
uint32_t *iblock = arg;
- ext4_dbg(DEBUG_JBD, "Block in block_tag: %" PRIu64 "\n", block);
+ ext4_dbg(DEBUG_JBD, "Block in block_tag: %" PRIu64 "\n", tag_info->block);
(*iblock)++;
wrap(&jbd_fs->sb, *iblock);
(void)jbd_fs;
- (void)uuid;
return;
}
/**@brief Replay a block in a transaction.
* @param jbd_fs jbd filesystem
- * @param block block address to be replayed.*/
+ * @param tag_info tag_info of the logged block.*/
static void jbd_replay_block_tags(struct jbd_fs *jbd_fs,
- ext4_fsblk_t block,
- uint8_t *uuid __unused,
+ struct tag_info *tag_info,
void *__arg)
{
int r;
/* We replay this block only if the current transaction id
* is equal or greater than that in revoke entry.*/
- revoke_entry = jbd_revoke_entry_lookup(info, block);
+ revoke_entry = jbd_revoke_entry_lookup(info, tag_info->block);
if (revoke_entry &&
trans_id_diff(arg->this_trans_id, revoke_entry->trans_id) <= 0)
return;
ext4_dbg(DEBUG_JBD,
"Replaying block in block_tag: %" PRIu64 "\n",
- block);
+ tag_info->block);
r = jbd_block_get(jbd_fs, &journal_block, *this_block);
if (r != EOK)
return;
/* We need special treatment for ext4 superblock. */
- if (block) {
- r = ext4_block_get_noread(fs->bdev, &ext4_block, block);
+ if (tag_info->block) {
+ r = ext4_block_get_noread(fs->bdev, &ext4_block, tag_info->block);
if (r != EOK) {
jbd_block_set(jbd_fs, &journal_block);
return;
journal_block.data,
jbd_get32(&jbd_fs->sb, blocksize));
+ if (tag_info->is_escape)
+ ((struct jbd_bhdr *)ext4_block.data)->magic =
+ to_be32(JBD_MAGIC_NUMBER);
+
ext4_bcache_set_dirty(ext4_block.buf);
ext4_block_set(fs->bdev, &ext4_block);
} else {
ext4_dbg(DEBUG_JBD, "Commit block: %" PRIu32", "
"trans_id: %" PRIu32"\n",
this_block, this_trans_id);
- /* This is the end of a transaction,
+ /*
+ * This is the end of a transaction,
* we may now proceed to the next transaction.
*/
this_trans_id++;
- info->trans_cnt++;
+ if (action == ACTION_SCAN)
+ info->trans_cnt++;
break;
case JBD_REVOKE_BLOCK:
if (!jbd_verify_meta_csum(jbd_fs, header)) {
ext4_get32(&jbd_fs->inode_ref.fs->sb,
features_incompatible);
jbd_set32(&jbd_fs->sb, start, 0);
+ jbd_set32(&jbd_fs->sb, sequence, info.last_trans_id);
features_incompatible &= ~EXT4_FINCOM_RECOVER;
ext4_set32(&jbd_fs->inode_ref.fs->sb,
features_incompatible,
uint32_t features_incompatible =
ext4_get32(&jbd_fs->inode_ref.fs->sb,
features_incompatible);
- struct ext4_block block = EXT4_BLOCK_ZERO();
features_incompatible |= EXT4_FINCOM_RECOVER;
ext4_set32(&jbd_fs->inode_ref.fs->sb,
features_incompatible,
journal->first = jbd_get32(&jbd_fs->sb, first);
journal->start = journal->first;
journal->last = journal->first;
- journal->trans_id = 1;
- journal->alloc_trans_id = 1;
+ /*
+ * To invalidate any stale records we need to start from
+ * the checkpoint transaction ID of the previous journalling session
+ * plus 1.
+ */
+ journal->trans_id = jbd_get32(&jbd_fs->sb, sequence) + 1;
+ journal->alloc_trans_id = journal->trans_id;
journal->block_size = jbd_get32(&jbd_fs->sb, blocksize);
- r = jbd_block_get_noread(jbd_fs,
- &block,
- journal->start);
- if (r != EOK) {
- memset(journal, 0, sizeof(struct jbd_journal));
- return r;
- }
- memset(block.data, 0, journal->block_size);
- ext4_bcache_set_dirty(block.buf);
- r = jbd_block_set(jbd_fs, &block);
- if (r != EOK) {
- memset(journal, 0, sizeof(struct jbd_journal));
- return r;
- }
-
TAILQ_INIT(&journal->cp_queue);
RB_INIT(&journal->block_rec_root);
journal->jbd_fs = jbd_fs;
trans->alloc_blocks++;
wrap(&journal->jbd_fs->sb, journal->last);
- /* If there is no space left, flush all journalled
- * blocks to disk first.*/
- if (journal->last == journal->start)
- jbd_journal_purge_cp_trans(journal, true, false);
+ /* If there is no space left, flush just one journalled
+ * transaction.*/
+ if (journal->last == journal->start) {
+ jbd_journal_purge_cp_trans(journal, true, true);
+ ext4_assert(journal->last != journal->start);
+ }
return start_block;
}
int rc;
struct ext4_block block;
struct jbd_commit_header *header;
- uint32_t commit_iblock, orig_commit_iblock;
+ uint32_t commit_iblock;
struct jbd_journal *journal = trans->journal;
commit_iblock = jbd_journal_alloc_block(journal, trans);
- orig_commit_iblock = commit_iblock;
- commit_iblock++;
- wrap(&journal->jbd_fs->sb, commit_iblock);
-
- /* To prevent accidental reference to stale journalling metadata. */
- if (orig_commit_iblock < commit_iblock) {
- rc = jbd_block_get_noread(journal->jbd_fs, &block, commit_iblock);
- if (rc != EOK)
- return rc;
- memset(block.data, 0, journal->block_size);
- ext4_bcache_set_dirty(block.buf);
- ext4_bcache_set_flag(block.buf, BC_TMP);
- rc = jbd_block_set(journal->jbd_fs, &block);
- if (rc != EOK)
- return rc;
- }
-
- rc = jbd_block_get_noread(journal->jbd_fs, &block, orig_commit_iblock);
+ rc = jbd_block_get_noread(journal->jbd_fs, &block, commit_iblock);
if (rc != EOK)
return rc;
TAILQ_FOREACH_SAFE(jbd_buf, &trans->buf_queue, buf_node, tmp) {
struct tag_info tag_info;
bool uuid_exist = false;
+ bool is_escape = false;
struct jbd_revoke_rec tmp_rec = {
.lba = jbd_buf->block_rec->lba
};
jbd_buf->block.data,
checksum,
trans->trans_id);
+ if (((struct jbd_bhdr *)jbd_buf->block.data)->magic ==
+ to_be32(JBD_MAGIC_NUMBER))
+ is_escape = true;
+
again:
if (!desc_iblock) {
desc_iblock = jbd_journal_alloc_block(journal, trans);
}
tag_info.block = jbd_buf->block.lb_id;
tag_info.uuid_exist = uuid_exist;
+ tag_info.is_escape = is_escape;
if (i == trans->data_cnt - 1)
tag_info.last_tag = true;
else
data = data_block.data;
memcpy(data, jbd_buf->block.data,
journal->block_size);
+ if (is_escape)
+ ((struct jbd_bhdr *)data)->magic = 0;
+
ext4_bcache_set_dirty(data_block.buf);
ext4_bcache_set_flag(data_block.buf, BC_TMP);
rc = jbd_block_set(journal->jbd_fs, &data_block);