Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


handle_tis atypedefto thestruct handle_sdata type used to define a handle (a simplified version is
shown):

<jbd.h>
typedef struct handle_s handle_t; /* Atomic operation type */

<jbd.h>
struct handle_s
{
/* Which compound transaction is this update a part of? */
transaction_t *h_transaction;

/* Number of remaining buffers we are allowed to dirty: */
int h_buffer_credits;
...
};

h_transactionis a pointer to the transaction data structure with which the handle is associated, and
h_buffer_creditsspecifies how many free buffers are still available for journal operations (discussed
shortly).

The kernel provides thejournal_startandjournal_stopfunctions that are used in pairs to label a code
section whose operation is to be regarded as atomic by the journal layer:

handle_t *handle = journal_start(journal, nblocks);
/* Perform operations to be regarded as atomic */
journal_stop(handle);

The functions can be nested, but it must be ensured thatjournal_stopis invoked the same number of
times asjournal_start. The kernel provides the wrapper functionext3_journal_start, which takes
a pointer to the inode in question as a parameter to infer the associated journal. With this information,
journal_startis called. Whilejournal_startis usually not used directly,ext3_journal_startis used
all over the Ext3 code.

Each handle consists of various log operations, each of which has its own buffer head (see Chapter 16)
to save the change — even if only a single bit is modified in the underlying filesystem. What appears at
first glance to be a massive waste of memory is compensated by higher performance because buffers are
processed very efficiently.

The data structure is defined (in greatly simplified form) as follows:

<journal_head.h>
struct journal_head {
struct buffer_head *b_bh;

transaction_t *b_transaction;
struct journal_head *b_tnext, *b_tprev;

❑ b_bhpoints to the buffer head that contains the operation data.
❑ b_transactionreferences the transaction to which the log entry is assigned.
❑ b_tnextandb_tprevhelp implement a doubly linked list of all logs associated with an atomic
operation.
Free download pdf