ref: c1a9671e59bf4170d374242dbd86631ea48a14f1
parent: 679728c0312fcc766e5ca5aafcfa7fa53406ebae
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Fri Dec 4 12:34:33 EST 2015
Deprecate uptodate and dirty fields in ext4_block.
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -248,7 +248,7 @@
return EIO;
ext4_dir_en_set_inode(res.dentry, parent->index);
- res.block.dirty = true;
+ ext4_bcache_set_dirty(res.block.buf);
r = ext4_dir_destroy_result(ch, &res);
if (r != EOK)
return r;
@@ -1509,7 +1509,7 @@
goto Finish;
memcpy(b.data + unalg, u8_buf, len);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(f->mp->fs.bdev, &b);
if (r != EOK)
@@ -1610,7 +1610,7 @@
goto Finish;
memcpy(b.data, u8_buf, size);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(f->mp->fs.bdev, &b);
if (r != EOK)
@@ -1894,7 +1894,7 @@
goto Finish;
memcpy(b.data, buf, size);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(f->mp->fs.bdev, &b);
if (r != EOK)
goto Finish;
--- a/lwext4/ext4_balloc.c
+++ b/lwext4/ext4_balloc.c
@@ -181,7 +181,7 @@
/* Modify bitmap */
ext4_bmap_bit_clr(bitmap_block.data, index_in_group);
ext4_balloc_set_bitmap_csum(sb, bg, bitmap_block.data);
- bitmap_block.dirty = true;
+ ext4_bcache_set_dirty(bitmap_block.buf);
/* Release block with bitmap */
rc = ext4_block_set(fs->bdev, &bitmap_block);
@@ -276,7 +276,7 @@
/* Modify bitmap */
ext4_bmap_bits_free(blk.data, idx_in_bg_first, free_cnt);
ext4_balloc_set_bitmap_csum(sb, bg, blk.data);
- blk.dirty = true;
+ ext4_bcache_set_dirty(blk.buf);
count -= free_cnt;
first += free_cnt;
@@ -384,7 +384,7 @@
ext4_bmap_bit_set(b.data, idx_in_bg);
ext4_balloc_set_bitmap_csum(sb, bg_ref.block_group,
b.data);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(inode_ref->fs->bdev, &b);
if (r != EOK) {
ext4_fs_put_block_group_ref(&bg_ref);
@@ -408,7 +408,7 @@
ext4_bmap_bit_set(b.data, tmp_idx);
ext4_balloc_set_bitmap_csum(sb, bg, b.data);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(inode_ref->fs->bdev, &b);
if (r != EOK)
return r;
@@ -423,7 +423,7 @@
if (r == EOK) {
ext4_bmap_bit_set(b.data, rel_blk_idx);
ext4_balloc_set_bitmap_csum(sb, bg_ref.block_group, b.data);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(inode_ref->fs->bdev, &b);
if (r != EOK)
return r;
@@ -491,7 +491,7 @@
if (r == EOK) {
ext4_bmap_bit_set(b.data, rel_blk_idx);
ext4_balloc_set_bitmap_csum(sb, bg, b.data);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(inode_ref->fs->bdev, &b);
if (r != EOK) {
ext4_fs_put_block_group_ref(&bg_ref);
@@ -594,7 +594,7 @@
if (*free) {
ext4_bmap_bit_set(b.data, index_in_group);
ext4_balloc_set_bitmap_csum(sb, bg_ref.block_group, b.data);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
}
/* Release block with bitmap */
--- a/lwext4/ext4_bcache.c
+++ b/lwext4/ext4_bcache.c
@@ -182,10 +182,6 @@
buf->refctr++;
- b->uptodate = ext4_bcache_test_flag(buf, BC_UPTODATE);
- /* Right now we don't propagate the dirty flag from ext4_buf to
- * ext4_block. */
- b->dirty = false;
b->buf = buf;
b->data = buf->data;
@@ -207,8 +203,6 @@
* by 1*/
buf->lru_id = ++bc->lru_ctr;
- b->uptodate = false;
- b->dirty = false;
b->buf = buf;
b->data = buf->data;
@@ -234,18 +228,6 @@
/*Just decrease reference counter*/
buf->refctr--;
- /* If buffer is modified, buf will be mark up-to-date and dirty. */
- if (b->dirty) {
- ext4_bcache_set_flag(buf, BC_DIRTY);
- ext4_bcache_set_flag(buf, BC_UPTODATE);
- b->uptodate = true;
- }
- /* Someone might want to drop this buffer from bcache. */
- if (!b->uptodate) {
- ext4_bcache_clear_flag(buf, BC_DIRTY);
- ext4_bcache_clear_flag(buf, BC_UPTODATE);
- }
-
/* We are the last one touching this buffer, do the cleanups. */
if (!buf->refctr) {
RB_INSERT(ext4_buf_lru, &bc->lru_root, buf);
@@ -265,8 +247,6 @@
b->lb_id = 0;
b->data = 0;
- b->uptodate = false;
- b->dirty = false;
return EOK;
}
--- a/lwext4/ext4_bcache.h
+++ b/lwext4/ext4_bcache.h
@@ -49,16 +49,10 @@
#include "queue.h"
#define EXT4_BLOCK_ZERO() \
- {.uptodate = 0, .dirty = 0, .lb_id = 0, .data = 0}
+ {.lb_id = 0, .data = 0}
/**@brief Single block descriptor*/
struct ext4_block {
- /**@brief Uptodate flag*/
- bool uptodate;
-
- /**@brief Dirty flag*/
- bool dirty;
-
/**@brief Logical block ID*/
uint64_t lb_id;
@@ -161,6 +155,16 @@
#define ext4_bcache_test_flag(buf, b) \
(((buf)->flags & (1 << (b))) >> (b))
+
+static inline void ext4_bcache_set_dirty(struct ext4_buf *buf) {
+ ext4_bcache_set_flag(buf, BC_UPTODATE);
+ ext4_bcache_set_flag(buf, BC_DIRTY);
+}
+
+static inline void ext4_bcache_clear_dirty(struct ext4_buf *buf) {
+ ext4_bcache_clear_flag(buf, BC_UPTODATE);
+ ext4_bcache_clear_flag(buf, BC_DIRTY);
+}
/**@brief Static initializer of block cache structure.*/
#define EXT4_BCACHE_STATIC_INSTANCE(__name, __cnt, __itemsize) \
--- a/lwext4/ext4_blockdev.c
+++ b/lwext4/ext4_blockdev.c
@@ -146,7 +146,6 @@
if (!(lba < bdev->lg_bcnt))
return ERANGE;
- b->dirty = 0;
b->lb_id = lba;
/*If cache is full we have to (flush and) drop it anyway :(*/
@@ -171,7 +170,7 @@
if (r != EOK)
return r;
- if (b->uptodate) {
+ if (ext4_bcache_test_flag(b->buf, BC_UPTODATE)) {
/* Data in the cache is up-to-date.
* Reading from physical device is not required */
return EOK;
@@ -187,7 +186,6 @@
/* Mark buffer up-to-date, since
* fresh data is read from physical device just now. */
ext4_bcache_set_flag(b->buf, BC_UPTODATE);
- b->uptodate = true;
return EOK;
}
--- a/lwext4/ext4_dir.c
+++ b/lwext4/ext4_dir.c
@@ -421,7 +421,7 @@
}
ext4_dir_set_csum(parent, (void *)b.data);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(fs->bdev, &b);
return r;
@@ -554,7 +554,7 @@
ext4_dir_set_csum(parent,
(struct ext4_dir_en *)result.block.data);
- result.block.dirty = true;
+ ext4_bcache_set_dirty(result.block.buf);
return ext4_dir_destroy_result(parent, &result);
}
@@ -591,7 +591,7 @@
ext4_dir_write_entry(sb, start, rec_len, child, name,
name_len);
ext4_dir_set_csum(inode_ref, (void *)dst_blk->data);
- dst_blk->dirty = true;
+ ext4_bcache_set_dirty(dst_blk->buf);
return EOK;
}
@@ -620,7 +620,7 @@
ext4_dir_set_csum(inode_ref,
(void *)dst_blk->data);
- dst_blk->dirty = true;
+ ext4_bcache_set_dirty(dst_blk->buf);
return EOK;
}
}
--- a/lwext4/ext4_dir_idx.c
+++ b/lwext4/ext4_dir_idx.c
@@ -425,7 +425,7 @@
ext4_dir_en_set_inode(be, 0);
- new_block.dirty = true;
+ ext4_bcache_set_dirty(new_block.buf);
rc = ext4_block_set(dir->fs->bdev, &new_block);
if (rc != EOK) {
ext4_block_set(dir->fs->bdev, &block);
@@ -437,7 +437,7 @@
ext4_dir_dx_entry_set_block(entry, iblock);
ext4_dir_set_dx_csum(dir, (struct ext4_dir_en *)block.data);
- block.dirty = true;
+ ext4_bcache_set_dirty(block.buf);
return ext4_block_set(dir->fs->bdev, &block);
}
@@ -897,7 +897,7 @@
ext4_dir_dx_entry_set_hash(new_index_entry, hash);
ext4_dir_dx_climit_set_count(climit, count + 1);
ext4_dir_set_dx_csum(inode_ref, (void *)index_block->b.data);
- index_block->b.dirty = true;
+ ext4_bcache_set_dirty(index_block->b.buf);
}
/**@brief Split directory entries to two parts preventing node overflow.
@@ -1073,8 +1073,8 @@
}
ext4_dir_set_csum(inode_ref, (void *)old_data_block->data);
ext4_dir_set_csum(inode_ref, (void *)new_data_block_tmp.data);
- old_data_block->dirty = true;
- new_data_block_tmp.dirty = true;
+ ext4_bcache_set_dirty(old_data_block->buf);
+ ext4_bcache_set_dirty(new_data_block_tmp.buf);
free(sort);
free(entry_buffer);
@@ -1187,7 +1187,7 @@
ino_ref,
(struct ext4_dir_en *)
dxb->b.data);
- dxb->b.dirty = true;
+ ext4_bcache_set_dirty(dxb->b.buf);
struct ext4_block block_tmp = dxb->b;
@@ -1205,11 +1205,11 @@
new_iblk);
ext4_dir_set_dx_csum(ino_ref, (void *)dx_blks[0].b.data);
ext4_dir_set_dx_csum(ino_ref, (void *)dx_blks[1].b.data);
- dx_blks[0].b.dirty = true;
- dx_blks[1].b.dirty = true;
+ ext4_bcache_set_dirty(dx_blks[0].b.buf);
+ ext4_bcache_set_dirty(dx_blks[1].b.buf);
ext4_dir_set_dx_csum(ino_ref, (void *)b.data);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
return ext4_block_set(ino_ref->fs->bdev, &b);
} else {
size_t sz;
@@ -1241,8 +1241,8 @@
ext4_dir_set_dx_csum(ino_ref, (void *)dx_blks[0].b.data);
ext4_dir_set_dx_csum(ino_ref, (void *)dx_blks[1].b.data);
- dx_blks[0].b.dirty = true;
- dx_blks[1].b.dirty = true;
+ ext4_bcache_set_dirty(dx_blks[0].b.buf);
+ ext4_bcache_set_dirty(dx_blks[1].b.buf);
}
}
@@ -1414,7 +1414,7 @@
ext4_dx_dot_en_set_inode(&root->dots[1], parent_inode);
ext4_dir_set_dx_csum(dir, (void *)block.data);
- block.dirty = true;
+ ext4_bcache_set_dirty(block.buf);
return ext4_block_set(dir->fs->bdev, &block);
}
--- a/lwext4/ext4_extent.c
+++ b/lwext4/ext4_extent.c
@@ -534,7 +534,7 @@
ext4_extent_header_set_entries_count(path_ptr->header, entries);
ext4_extent_block_csum_set(inode_ref, path_ptr->header);
- path_ptr->block.dirty = true;
+ ext4_bcache_set_dirty(path_ptr->block.buf);
/* If leaf node is empty, parent entry must be modified */
bool remove_parent_record = false;
@@ -576,7 +576,7 @@
ext4_extent_header_set_entries_count(path_ptr->header, entries);
ext4_extent_block_csum_set(inode_ref, path_ptr->header);
- path_ptr->block.dirty = true;
+ ext4_bcache_set_dirty(path_ptr->block.buf);
/* Free the node if it is empty */
if ((entries == 0) && (path_ptr != path)) {
@@ -704,7 +704,7 @@
ext4_extent_header_set_generation(path_ptr->header, 0);
ext4_extent_block_csum_set(inode_ref, path_ptr->header);
- path_ptr->block.dirty = true;
+ ext4_bcache_set_dirty(path_ptr->block.buf);
/* Jump to the preceding item */
path_ptr--;
@@ -730,7 +730,7 @@
ext4_extent_header_set_entries_count(path_ptr->header,
entries + 1);
ext4_extent_block_csum_set(inode_ref, path_ptr->header);
- path_ptr->block.dirty = true;
+ ext4_bcache_set_dirty(path_ptr->block.buf);
/* No more splitting needed */
return EOK;
@@ -813,7 +813,7 @@
limit);
ext4_extent_block_csum_set(inode_ref, old_root->header);
- old_root->block.dirty = true;
+ ext4_bcache_set_dirty(old_root->block.buf);
/* Re-initialize new root metadata */
new_root->depth = root_depth + 1;
@@ -831,7 +831,7 @@
/* Since new_root belongs to on-disk inode,
* we don't do checksum here */
- new_root->block.dirty = true;
+ ext4_bcache_set_dirty(new_root->block.buf);
} else {
if (path->depth) {
path->index =
@@ -848,7 +848,7 @@
ext4_extent_header_set_entries_count(path->header, entries + 1);
/* Since new_root belongs to on-disk inode,
* we don't do checksum here */
- path->block.dirty = true;
+ ext4_bcache_set_dirty(path->block.buf);
}
return EOK;
@@ -928,7 +928,7 @@
}
ext4_extent_block_csum_set(inode_ref, path_ptr->header);
- path_ptr->block.dirty = true;
+ ext4_bcache_set_dirty(path_ptr->block.buf);
goto finish;
} else {
@@ -970,7 +970,7 @@
}
ext4_extent_block_csum_set(inode_ref, path_ptr->header);
- path_ptr->block.dirty = true;
+ ext4_bcache_set_dirty(path_ptr->block.buf);
goto finish;
}
@@ -1011,7 +1011,7 @@
}
ext4_extent_block_csum_set(inode_ref, path_ptr->header);
- path_ptr->block.dirty = true;
+ ext4_bcache_set_dirty(path_ptr->block.buf);
finish:
/* Set return values */
--- a/lwext4/ext4_extent_full.c
+++ b/lwext4/ext4_extent_full.c
@@ -353,7 +353,7 @@
struct ext4_extent_path *path)
{
if (path->block.lb_id)
- path->block.dirty = true;
+ ext4_bcache_set_dirty(path->block.buf);
else
inode_ref->dirty = true;
@@ -374,7 +374,7 @@
for (i = 0; i <= depth; i++, path++) {
if (path->block.lb_id) {
- if (path->block.dirty)
+ if (ext4_bcache_test_flag(path->block.buf, BC_DIRTY))
ext4_extent_block_csum_set(inode_ref,
path->header);
@@ -798,7 +798,7 @@
} else if (bh.lb_id) {
/* If we got a sibling leaf. */
ext4_extent_block_csum_set(inode_ref, ext_block_hdr(&bh));
- bh.dirty = true;
+ ext4_bcache_set_dirty(bh.buf);
spt->path.p_block = ext4_idx_pblock(ix);
spt->path.depth = to_le16(eh->depth);
@@ -1070,7 +1070,7 @@
} else if (bh.lb_id) {
/* If we got a sibling leaf. */
ext4_extent_block_csum_set(inode_ref, ext_block_hdr(&bh));
- bh.dirty = true;
+ ext4_bcache_set_dirty(bh.buf);
spt->path.p_block = ext4_ext_pblock(ex);
spt->path.depth = to_le16(eh->depth);
@@ -1166,7 +1166,7 @@
}
neh->depth = to_le16(to_le16(neh->depth) + 1);
- bh.dirty = true;
+ ext4_bcache_set_dirty(bh.buf);
inode_ref->dirty = true;
ext4_block_set(inode_ref->fs->bdev, &bh);
@@ -1728,7 +1728,7 @@
break;
memset(bh.data, 0, block_size);
- bh.dirty = true;
+ ext4_bcache_set_dirty(bh.buf);
err = ext4_block_set(inode_ref->fs->bdev, &bh);
if (err != EOK)
break;
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -356,7 +356,7 @@
* of bitmap ), set rest of the block bitmap to 1
*/
ext4_fs_mark_bitmap_end(group_blocks, block_size * 8, block_bitmap.data);
- block_bitmap.dirty = true;
+ ext4_bcache_set_dirty(block_bitmap.buf);
ext4_balloc_set_bitmap_csum(sb, bg_ref->block_group, block_bitmap.data);
bg_ref->dirty = true;
@@ -399,7 +399,7 @@
if (i < end_bit)
memset(b.data + (i >> 3), 0xff, (end_bit - i) >> 3);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
ext4_ialloc_set_bitmap_csum(sb, bg, b.data);
bg_ref->dirty = true;
@@ -440,7 +440,7 @@
return rc;
memset(b.data, 0, block_size);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
ext4_block_set(bg_ref->fs->bdev, &b);
if (rc != EOK)
@@ -629,7 +629,7 @@
ref->block_group->checksum = to_le16(cs);
/* Mark block dirty for writing changes to physical device */
- ref->block.dirty = true;
+ ext4_bcache_set_dirty(ref->block.buf);
}
/* Put back block, that contains block group descriptor */
@@ -781,7 +781,7 @@
if (ref->dirty) {
/* Mark block dirty for writing changes to physical device */
ext4_fs_set_inode_checksum(ref);
- ref->block.dirty = true;
+ ext4_bcache_set_dirty(ref->block.buf);
}
/* Put back block, that contains i-node */
@@ -1118,7 +1118,7 @@
/* Set zero if physical data block address found */
if (level == 1) {
((uint32_t *)block.data)[offset_in_block] = to_le32(0);
- block.dirty = true;
+ ext4_bcache_set_dirty(block.buf);
}
rc = ext4_block_set(fs->bdev, &block);
@@ -1507,7 +1507,7 @@
/* Initialize new block */
memset(new_block.data, 0, block_size);
- new_block.dirty = true;
+ ext4_bcache_set_dirty(new_block.buf);
/* Put back the allocated block */
rc = ext4_block_set(fs->bdev, &new_block);
@@ -1554,7 +1554,7 @@
/* Initialize allocated block */
memset(new_block.data, 0, block_size);
- new_block.dirty = true;
+ ext4_bcache_set_dirty(new_block.buf);
rc = ext4_block_set(fs->bdev, &new_block);
if (rc != EOK) {
@@ -1565,7 +1565,7 @@
/* Write block address to the parent */
uint32_t * p = (uint32_t * )block.data;
p[off_in_blk] = to_le32((uint32_t)new_blk);
- block.dirty = true;
+ ext4_bcache_set_dirty(block.buf);
current_block = new_blk;
}
@@ -1573,7 +1573,7 @@
if (l == 1) {
uint32_t * p = (uint32_t * )block.data;
p[off_in_blk] = to_le32((uint32_t)fblock);
- block.dirty = true;
+ ext4_bcache_set_dirty(block.buf);
}
rc = ext4_block_set(fs->bdev, &block);
--- a/lwext4/ext4_ialloc.c
+++ b/lwext4/ext4_ialloc.c
@@ -184,7 +184,7 @@
uint32_t index_in_group = ext4_ialloc_inode_to_bgidx(sb, index);
ext4_bmap_bit_clr(b.data, index_in_group);
ext4_ialloc_set_bitmap_csum(sb, bg, b.data);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
/* Put back the block with bitmap */
rc = ext4_block_set(fs->bdev, &b);
@@ -300,7 +300,7 @@
/* Free i-node found, save the bitmap */
ext4_ialloc_set_bitmap_csum(sb,bg,
b.data);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
ext4_block_set(fs->bdev, &b);
if (rc != EOK) {
--- a/lwext4/ext4_journal.c
+++ b/lwext4/ext4_journal.c
@@ -410,7 +410,7 @@
journal_block.data,
jbd_get32(&jbd_fs->sb, blocksize));
- ext4_block.dirty = true;
+ ext4_bcache_set_dirty(ext4_block.buf);
ext4_block_set(fs->bdev, &ext4_block);
} else {
uint16_t mount_count, state;
--- a/lwext4/ext4_mkfs.c
+++ b/lwext4/ext4_mkfs.c
@@ -394,7 +394,7 @@
break;
}
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(bd, &b);
if (r != EOK)
return r;
@@ -407,7 +407,7 @@
if (r != EOK)
return r;
memset(b.data, 0, block_size);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(bd, &b);
if (r != EOK)
return r;
@@ -415,7 +415,7 @@
if (r != EOK)
return r;
memset(b.data, 0, block_size);
- b.dirty = true;
+ ext4_bcache_set_dirty(b.buf);
r = ext4_block_set(bd, &b);
if (r != EOK)
return r;
--- a/lwext4/ext4_xattr.c
+++ b/lwext4/ext4_xattr.c
@@ -655,7 +655,7 @@
block_data = (char *)block_header + block_size_rem;
block_size_rem -= sizeof(struct ext4_xattr_header);
- xattr_ref->block.dirty = true;
+ ext4_bcache_set_dirty(xattr_ref->block.buf);
} else {
/* We don't need an extra block.*/
if (xattr_ref->block_loaded) {
@@ -677,7 +677,7 @@
&xattr_ref->fs->sb, 0);
xattr_ref->inode_ref->dirty = true;
- xattr_ref->block.dirty = true;
+ ext4_bcache_set_dirty(xattr_ref->block.buf);
}
}
}
@@ -726,7 +726,7 @@
ext4_xattr_set_block_checksum(xattr_ref->inode_ref,
xattr_ref->block.lb_id,
block_header);
- xattr_ref->block.dirty = true;
+ ext4_bcache_set_dirty(xattr_ref->block.buf);
}
Finish: