ext2: How do we make sure indirect blocks are writeback before data block?

From: bbw725
Date: Thu Nov 19 2020 - 11:58:10 EST


Hi all,

I have one question about how ext2 's indirect block being write back. (I know ext2 is out of date but I am just starting learning).

From ext2_alloc_branch(), after it got indirect block and then it will setup the 'chain', during this, it will mark buffer head of indirect blocks to dirty,
and then the inode's associated block dev will write back this dirty buffer head.
My question is these indirect blocks are meta data of this inode, and usually we should write back inode's data first and then its meta data, but here, after we mark buffer heads of indirect blocks and how do we make sure they will be written back before its data ?


ext2_alloc_branch (...)
{

    bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
if (unlikely(!bh)) {
err = -ENOMEM;
goto failed;
}
branch[n].bh = bh;
lock_buffer(bh);
memset(bh->b_data, 0, blocksize);
branch[n].p = (__le32 *) bh->b_data + offsets[n];
branch[n].key = cpu_to_le32(new_blocks[n]);
*branch[n].p = branch[n].key;
if ( n == indirect_blks) {
current_block = new_blocks[n];
/*
* End of chain, update the last new metablock of
* the chain to point to the new allocated
* data blocks numbers
*/
for (i=1; i < num; i++)
*(branch[n].p + i) = cpu_to_le32(++current_block);
}
set_buffer_uptodate(bh);
unlock_buffer(bh);
mark_buffer_dirty_inode(bh, inode);
/* We used to sync bh here if IS_SYNC(inode).
* But we now rely upon generic_write_sync()
* and b_inode_buffers. But not for directories.
*/

Thanks very much.