Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


* we will come here when we just failed to allocate from
* the first part of the window. We still have another part
* that belongs to the next group. In this case, there is no
* point to discard our window and try to allocate a new one
* in this group(which will fail). we should
* keep the reservation window, just simply move on.
*/

if ((my_rsv->rsv_start <= group_end_block) &&
(my_rsv->rsv_end > group_end_block) &&
(start_block >= my_rsv->rsv_start))
return -1;

if ((my_rsv->rsv_alloc_hit >
(my_rsv->rsv_end - my_rsv->rsv_start + 1) / 2)) {
/*
* if the previously allocation hit ratio is
* greater than 1/2, then we double the size of
* the reservation window the next time,
* otherwise we keep the same size window
*/
size = size * 2;
if (size > EXT2_MAX_RESERVE_BLOCKS)
size = EXT2_MAX_RESERVE_BLOCKS;
my_rsv->rsv_goal_size= size;
}
}
...

The kernel code precisely states what is going on (and especially why this is going on), and for a change,
there’s nothing further to add.

If new boundaries for the window have been computed (or if there has not been a reservation window
before),search_reserve_windowchecks if a reserve window that contains the allocation goal is already
present. If this is not the case, the window before the allocation goal is returned. The selected window is
used as a starting point forfind_next_reservable_window, which tries to find a suitable new reservation
window. Finally, the kernel checks if the window contains at least a single free bit. If not, it does not make
any sense to pre-allocate space, so the window is discarded. Otherwise, the function returns successfully.

Creating and Deleting Inodes


Inodes must also be created and deleted by low-levelfunctions of the Ext2 filesystem. This is necessary
when a file or directory is created (or deleted) — the core code of the two variants hardly differs.

Let’s begin with the creation of a file or directory. As explained in Chapter 8, theopenandmkdirsystem
calls are available for this purpose. They work through the various functions of the virtual filesystem
to arrive at thecreateandmkdirfunctions, each of which is pointed to by a function pointer in the
file-specific instance ofinode_operations.Theext2_createandext2_mkdirfunctions are inserted as
described in Section 9.2.4. Both functions are located infs/ext2/namei.c. The flow of both actions is
shown in the code flow diagrams in Figures 9-18 and 9-19.
Free download pdf