📄 jbd.h
字号:
/* * linux/include/linux/jbd.h * * Written by Stephen C. Tweedie <sct@redhat.com> * * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved * * This file is part of the Linux kernel and is made available under * the terms of the GNU General Public License, version 2, or at your * option, any later version, incorporated herein by reference. * * Definitions for transaction data structures for the buffer cache * filesystem journaling support. */#ifndef _LINUX_JBD_H#define _LINUX_JBD_H/* Allow this file to be included directly into e2fsprogs */#ifndef __KERNEL__#include "jfs_compat.h"#define JFS_DEBUG#define jfs_debug jbd_debug#else#include <linux/types.h>#include <linux/buffer_head.h>#include <linux/journal-head.h>#include <linux/stddef.h>#include <linux/bit_spinlock.h>#include <linux/mutex.h>#include <linux/timer.h>#include <asm/semaphore.h>#endif#define journal_oom_retry 1/* * Define JBD_PARANIOD_IOFAIL to cause a kernel BUG() if ext3 finds * certain classes of error which can occur due to failed IOs. Under * normal use we want ext3 to continue after such errors, because * hardware _can_ fail, but for debugging purposes when running tests on * known-good hardware we may want to trap these errors. */#undef JBD_PARANOID_IOFAIL/* * The default maximum commit age, in seconds. */#define JBD_DEFAULT_MAX_COMMIT_AGE 5#ifdef CONFIG_JBD_DEBUG/* * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal * consistency checks. By default we don't do this unless * CONFIG_JBD_DEBUG is on. */#define JBD_EXPENSIVE_CHECKINGextern int journal_enable_debug;#define jbd_debug(n, f, a...) \ do { \ if ((n) <= journal_enable_debug) { \ printk (KERN_DEBUG "(%s, %d): %s: ", \ __FILE__, __LINE__, __FUNCTION__); \ printk (f, ## a); \ } \ } while (0)#else#define jbd_debug(f, a...) /**/#endifextern void * __jbd_kmalloc (const char *where, size_t size, gfp_t flags, int retry);extern void * jbd_slab_alloc(size_t size, gfp_t flags);extern void jbd_slab_free(void *ptr, size_t size);#define jbd_kmalloc(size, flags) \ __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry)#define jbd_rep_kmalloc(size, flags) \ __jbd_kmalloc(__FUNCTION__, (size), (flags), 1)#define JFS_MIN_JOURNAL_BLOCKS 1024#ifdef __KERNEL__/** * typedef handle_t - The handle_t type represents a single atomic update being performed by some process. * * All filesystem modifications made by the process go * through this handle. Recursive operations (such as quota operations) * are gathered into a single update. * * The buffer credits field is used to account for journaled buffers * being modified by the running process. To ensure that there is * enough log space for all outstanding operations, we need to limit the * number of outstanding buffers possible at any time. When the * operation completes, any buffer credits not used are credited back to * the transaction, so that at all times we know how many buffers the * outstanding updates on a transaction might possibly touch. * * This is an opaque datatype. **/typedef struct handle_s handle_t; /* Atomic operation type *//** * typedef journal_t - The journal_t maintains all of the journaling state information for a single filesystem. * * journal_t is linked to from the fs superblock structure. * * We use the journal_t to keep track of all outstanding transaction * activity on the filesystem, and to manage the state of the log * writing process. * * This is an opaque datatype. **/typedef struct journal_s journal_t; /* Journal control structure */#endif/* * Internal structures used by the logging mechanism: */#define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! *//* * On-disk structures *//* * Descriptor block types: */#define JFS_DESCRIPTOR_BLOCK 1#define JFS_COMMIT_BLOCK 2#define JFS_SUPERBLOCK_V1 3#define JFS_SUPERBLOCK_V2 4#define JFS_REVOKE_BLOCK 5/* * Standard header for all descriptor blocks: */typedef struct journal_header_s{ __be32 h_magic; __be32 h_blocktype; __be32 h_sequence;} journal_header_t;/* * The block tag: used to describe a single buffer in the journal */typedef struct journal_block_tag_s{ __be32 t_blocknr; /* The on-disk block number */ __be32 t_flags; /* See below */} journal_block_tag_t;/* * The revoke descriptor: used on disk to describe a series of blocks to * be revoked from the log */typedef struct journal_revoke_header_s{ journal_header_t r_header; __be32 r_count; /* Count of bytes used in the block */} journal_revoke_header_t;/* Definitions for the journal tag flags word: */#define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */#define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */#define JFS_FLAG_DELETED 4 /* block deleted by this transaction */#define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block *//* * The journal superblock. All fields are in big-endian byte order. */typedef struct journal_superblock_s{/* 0x0000 */ journal_header_t s_header;/* 0x000C */ /* Static information describing the journal */ __be32 s_blocksize; /* journal device blocksize */ __be32 s_maxlen; /* total blocks in journal file */ __be32 s_first; /* first block of log information *//* 0x0018 */ /* Dynamic information describing the current state of the log */ __be32 s_sequence; /* first commit ID expected in log */ __be32 s_start; /* blocknr of start of log *//* 0x0020 */ /* Error value, as set by journal_abort(). */ __be32 s_errno;/* 0x0024 */ /* Remaining fields are only valid in a version-2 superblock */ __be32 s_feature_compat; /* compatible feature set */ __be32 s_feature_incompat; /* incompatible feature set */ __be32 s_feature_ro_compat; /* readonly-compatible feature set *//* 0x0030 */ __u8 s_uuid[16]; /* 128-bit uuid for journal *//* 0x0040 */ __be32 s_nr_users; /* Nr of filesystems sharing log */ __be32 s_dynsuper; /* Blocknr of dynamic superblock copy*//* 0x0048 */ __be32 s_max_transaction; /* Limit of journal blocks per trans.*/ __be32 s_max_trans_data; /* Limit of data blocks per trans. *//* 0x0050 */ __u32 s_padding[44];/* 0x0100 */ __u8 s_users[16*48]; /* ids of all fs'es sharing the log *//* 0x0400 */} journal_superblock_t;#define JFS_HAS_COMPAT_FEATURE(j,mask) \ ((j)->j_format_version >= 2 && \ ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))#define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \ ((j)->j_format_version >= 2 && \ ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask))))#define JFS_HAS_INCOMPAT_FEATURE(j,mask) \ ((j)->j_format_version >= 2 && \ ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))#define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001/* Features known to this kernel version: */#define JFS_KNOWN_COMPAT_FEATURES 0#define JFS_KNOWN_ROCOMPAT_FEATURES 0#define JFS_KNOWN_INCOMPAT_FEATURES JFS_FEATURE_INCOMPAT_REVOKE#ifdef __KERNEL__#include <linux/fs.h>#include <linux/sched.h>#define JBD_ASSERTIONS#ifdef JBD_ASSERTIONS#define J_ASSERT(assert) \do { \ if (!(assert)) { \ printk (KERN_EMERG \ "Assertion failure in %s() at %s:%d: \"%s\"\n", \ __FUNCTION__, __FILE__, __LINE__, # assert); \ BUG(); \ } \} while (0)#if defined(CONFIG_BUFFER_DEBUG)void buffer_assertion_failure(struct buffer_head *bh);#define J_ASSERT_BH(bh, expr) \ do { \ if (!(expr)) \ buffer_assertion_failure(bh); \ J_ASSERT(expr); \ } while (0)#define J_ASSERT_JH(jh, expr) J_ASSERT_BH(jh2bh(jh), expr)#else#define J_ASSERT_BH(bh, expr) J_ASSERT(expr)#define J_ASSERT_JH(jh, expr) J_ASSERT(expr)#endif#else#define J_ASSERT(assert) do { } while (0)#endif /* JBD_ASSERTIONS */#if defined(JBD_PARANOID_IOFAIL)#define J_EXPECT(expr, why...) J_ASSERT(expr)#define J_EXPECT_BH(bh, expr, why...) J_ASSERT_BH(bh, expr)#define J_EXPECT_JH(jh, expr, why...) J_ASSERT_JH(jh, expr)#else#define __journal_expect(expr, why...) \ ({ \ int val = (expr); \ if (!val) { \ printk(KERN_ERR \ "EXT3-fs unexpected failure: %s;\n",# expr); \ printk(KERN_ERR why "\n"); \ } \ val; \ })#define J_EXPECT(expr, why...) __journal_expect(expr, ## why)#define J_EXPECT_BH(bh, expr, why...) __journal_expect(expr, ## why)#define J_EXPECT_JH(jh, expr, why...) __journal_expect(expr, ## why)#endifenum jbd_state_bits { BH_JBD /* Has an attached ext3 journal_head */ = BH_PrivateStart, BH_JWrite, /* Being written to log (@@@ DEBUGGING) */ BH_Freed, /* Has been freed (truncated) */ BH_Revoked, /* Has been revoked from the log */ BH_RevokeValid, /* Revoked flag is valid */ BH_JBDDirty, /* Is dirty but journaled */ BH_State, /* Pins most journal_head state */ BH_JournalHead, /* Pins bh->b_private and jh->b_bh */ BH_Unshadow, /* Dummy bit, for BJ_Shadow wakeup filtering */};BUFFER_FNS(JBD, jbd)BUFFER_FNS(JWrite, jwrite)BUFFER_FNS(JBDDirty, jbddirty)TAS_BUFFER_FNS(JBDDirty, jbddirty)BUFFER_FNS(Revoked, revoked)TAS_BUFFER_FNS(Revoked, revoked)BUFFER_FNS(RevokeValid, revokevalid)TAS_BUFFER_FNS(RevokeValid, revokevalid)BUFFER_FNS(Freed, freed)static inline struct buffer_head *jh2bh(struct journal_head *jh){ return jh->b_bh;}static inline struct journal_head *bh2jh(struct buffer_head *bh){ return bh->b_private;}static inline void jbd_lock_bh_state(struct buffer_head *bh){ bit_spin_lock(BH_State, &bh->b_state);}static inline int jbd_trylock_bh_state(struct buffer_head *bh){ return bit_spin_trylock(BH_State, &bh->b_state);}static inline int jbd_is_locked_bh_state(struct buffer_head *bh){ return bit_spin_is_locked(BH_State, &bh->b_state);}static inline void jbd_unlock_bh_state(struct buffer_head *bh){ bit_spin_unlock(BH_State, &bh->b_state);}static inline void jbd_lock_bh_journal_head(struct buffer_head *bh){ bit_spin_lock(BH_JournalHead, &bh->b_state);}static inline void jbd_unlock_bh_journal_head(struct buffer_head *bh){ bit_spin_unlock(BH_JournalHead, &bh->b_state);}struct jbd_revoke_table_s;/** * struct handle_s - The handle_s type is the concrete type associated with * handle_t.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -