Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


❑ To achieve better performance, the kernel also performs block reservation. This means that for
regular files, a number of blocks is pre-allocated. If the need for further blocks arises, they are
preferably allocated from the pre-allocated area.

The code flow diagram forext2_get_blocksin Figure 9-10 shows how the first and third tasks are done:
detecting that new blocks are required, deciding which level of indirection is required, and adding the
newly allocated blocks with the file. I leave the remaining two tasks for below.


The following diagram is a little bit more complicated than the simpler version in Figure 9-9, where
the fact that a data block could be locatedoutsidethe available range is ignored. Figure 9-10 shows the
situation that arises whenext2_get_blocksneeds to request new blocks.


ext2_get_blocks

ext2_blocks_to_path

ext2_get_branch

ext2_init_block_alloc_info

ext2_find_goal ext2_find_near

ext2_blks_to_allocate

ext2_alloc_branch

ext2_splice_branch

Regular file and no reservation info?

Figure 9-10: Code flow diagram forext2_get_blocks(creation of a
block).

The path array passed as a function argument is structured in accordance with the familiar method
because it doesn’t make any difference whether a block is available in a file or not. Only the position
within the file and the block size of the filesystem must be known in order to set up the path.


Thedifferenceascomparedwiththeext2_get_blocksversion above does not become apparent until
theext2_get_branchfunction is invoked. Whereas previously aNULLpointer was returned to indicate
a successful search, the address of the last indirection block is now returned as the starting point for
extending the file if the desired data block is outside the previously valid range.


To understand the situation where a new block is created, it is necessary to take a closer look at how
ext2_get_branchworks because a new data structure is introduced:


fs/ext2/inode.c
typedef struct {
__le32 *p;
__le32 key;
struct buffer_head *bh;
} Indirect;
Free download pdf