Home | History | Annotate | Download | only in linux
      1 /*
      2  * linux/include/linux/jbd.h
      3  *
      4  * Written by Stephen C. Tweedie <sct (at) redhat.com>
      5  *
      6  * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved
      7  *
      8  * This file is part of the Linux kernel and is made available under
      9  * the terms of the GNU General Public License, version 2, or at your
     10  * option, any later version, incorporated herein by reference.
     11  *
     12  * Definitions for transaction data structures for the buffer cache
     13  * filesystem journaling support.
     14  */
     15 
     16 #ifndef _LINUX_JBD_H
     17 #define _LINUX_JBD_H
     18 
     19 /* Allow this file to be included directly into e2fsprogs */
     20 #include "jfs_compat.h"
     21 #define JFS_DEBUG
     22 #define jfs_debug jbd_debug
     23 
     24 #define journal_oom_retry 1
     25 
     26 /*
     27  * Define JBD_PARANIOD_IOFAIL to cause a kernel BUG() if ext3 finds
     28  * certain classes of error which can occur due to failed IOs.  Under
     29  * normal use we want ext3 to continue after such errors, because
     30  * hardware _can_ fail, but for debugging purposes when running tests on
     31  * known-good hardware we may want to trap these errors.
     32  */
     33 #undef JBD_PARANOID_IOFAIL
     34 
     35 /*
     36  * The default maximum commit age, in seconds.
     37  */
     38 #define JBD_DEFAULT_MAX_COMMIT_AGE 5
     39 
     40 #ifdef CONFIG_JBD_DEBUG
     41 /*
     42  * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal
     43  * consistency checks.  By default we don't do this unless
     44  * CONFIG_JBD_DEBUG is on.
     45  */
     46 #define JBD_EXPENSIVE_CHECKING
     47 extern u8 journal_enable_debug;
     48 
     49 #define jbd_debug(n, f, a...)						\
     50 	do {								\
     51 		if ((n) <= journal_enable_debug) {			\
     52 			printk (KERN_DEBUG "(%s, %d): %s: ",		\
     53 				__FILE__, __LINE__, __FUNCTION__);	\
     54 			printk (f, ## a);				\
     55 		}							\
     56 	} while (0)
     57 #else
     58 #define jbd_debug(f, a...)	/**/
     59 #endif
     60 
     61 static __inline__ void *jbd_alloc(size_t size, gfp_t flags)
     62 {
     63 	return (void *)__get_free_pages(flags, get_order(size));
     64 }
     65 
     66 static __inline__ void jbd_free(void *ptr, size_t size)
     67 {
     68 	free_pages((unsigned long)ptr, get_order(size));
     69 };
     70 
     71 #define JFS_MIN_JOURNAL_BLOCKS 1024
     72 
     73 
     74 /*
     75  * Internal structures used by the logging mechanism:
     76  */
     77 
     78 #define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
     79 
     80 /*
     81  * On-disk structures
     82  */
     83 
     84 /*
     85  * Descriptor block types:
     86  */
     87 
     88 #define JFS_DESCRIPTOR_BLOCK	1
     89 #define JFS_COMMIT_BLOCK	2
     90 #define JFS_SUPERBLOCK_V1	3
     91 #define JFS_SUPERBLOCK_V2	4
     92 #define JFS_REVOKE_BLOCK	5
     93 
     94 /*
     95  * Standard header for all descriptor blocks:
     96  */
     97 typedef struct journal_header_s
     98 {
     99 	__be32		h_magic;
    100 	__be32		h_blocktype;
    101 	__be32		h_sequence;
    102 } journal_header_t;
    103 
    104 
    105 /*
    106  * The block tag: used to describe a single buffer in the journal
    107  */
    108 typedef struct journal_block_tag_s
    109 {
    110 	__be32		t_blocknr;	/* The on-disk block number */
    111 	__be32		t_flags;	/* See below */
    112 } journal_block_tag_t;
    113 
    114 /*
    115  * The revoke descriptor: used on disk to describe a series of blocks to
    116  * be revoked from the log
    117  */
    118 typedef struct journal_revoke_header_s
    119 {
    120 	journal_header_t r_header;
    121 	__be32		 r_count;	/* Count of bytes used in the block */
    122 } journal_revoke_header_t;
    123 
    124 
    125 /* Definitions for the journal tag flags word: */
    126 #define JFS_FLAG_ESCAPE		1	/* on-disk block is escaped */
    127 #define JFS_FLAG_SAME_UUID	2	/* block has same uuid as previous */
    128 #define JFS_FLAG_DELETED	4	/* block deleted by this transaction */
    129 #define JFS_FLAG_LAST_TAG	8	/* last tag in this descriptor block */
    130 
    131 
    132 /*
    133  * The journal superblock.  All fields are in big-endian byte order.
    134  */
    135 typedef struct journal_superblock_s
    136 {
    137 /* 0x0000 */
    138 	journal_header_t s_header;
    139 
    140 /* 0x000C */
    141 	/* Static information describing the journal */
    142 	__be32	s_blocksize;		/* journal device blocksize */
    143 	__be32	s_maxlen;		/* total blocks in journal file */
    144 	__be32	s_first;		/* first block of log information */
    145 
    146 /* 0x0018 */
    147 	/* Dynamic information describing the current state of the log */
    148 	__be32	s_sequence;		/* first commit ID expected in log */
    149 	__be32	s_start;		/* blocknr of start of log */
    150 
    151 /* 0x0020 */
    152 	/* Error value, as set by journal_abort(). */
    153 	__be32	s_errno;
    154 
    155 /* 0x0024 */
    156 	/* Remaining fields are only valid in a version-2 superblock */
    157 	__be32	s_feature_compat;	/* compatible feature set */
    158 	__be32	s_feature_incompat;	/* incompatible feature set */
    159 	__be32	s_feature_ro_compat;	/* readonly-compatible feature set */
    160 /* 0x0030 */
    161 	__u8	s_uuid[16];		/* 128-bit uuid for journal */
    162 
    163 /* 0x0040 */
    164 	__be32	s_nr_users;		/* Nr of filesystems sharing log */
    165 
    166 	__be32	s_dynsuper;		/* Blocknr of dynamic superblock copy*/
    167 
    168 /* 0x0048 */
    169 	__be32	s_max_transaction;	/* Limit of journal blocks per trans.*/
    170 	__be32	s_max_trans_data;	/* Limit of data blocks per trans. */
    171 
    172 /* 0x0050 */
    173 	__u32	s_padding[44];
    174 
    175 /* 0x0100 */
    176 	__u8	s_users[16*48];		/* ids of all fs'es sharing the log */
    177 /* 0x0400 */
    178 } journal_superblock_t;
    179 
    180 #define JFS_HAS_COMPAT_FEATURE(j,mask)					\
    181 	((j)->j_format_version >= 2 &&					\
    182 	 ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))
    183 #define JFS_HAS_RO_COMPAT_FEATURE(j,mask)				\
    184 	((j)->j_format_version >= 2 &&					\
    185 	 ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask))))
    186 #define JFS_HAS_INCOMPAT_FEATURE(j,mask)				\
    187 	((j)->j_format_version >= 2 &&					\
    188 	 ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
    189 
    190 #define JFS_FEATURE_INCOMPAT_REVOKE	0x00000001
    191 
    192 /* Features known to this kernel version: */
    193 #define JFS_KNOWN_COMPAT_FEATURES	0
    194 #define JFS_KNOWN_ROCOMPAT_FEATURES	0
    195 #define JFS_KNOWN_INCOMPAT_FEATURES	JFS_FEATURE_INCOMPAT_REVOKE
    196 
    197 
    198 /* Comparison functions for transaction IDs: perform comparisons using
    199  * modulo arithmetic so that they work over sequence number wraps. */
    200 
    201 static __inline__ int tid_gt(tid_t x, tid_t y)
    202 {
    203 	int difference = (x - y);
    204 	return (difference > 0);
    205 }
    206 
    207 static __inline__ int tid_geq(tid_t x, tid_t y)
    208 {
    209 	int difference = (x - y);
    210 	return (difference >= 0);
    211 }
    212 
    213 extern int journal_blocks_per_page(struct inode *inode);
    214 
    215 /*
    216  * Return the minimum number of blocks which must be free in the journal
    217  * before a new transaction may be started.  Must be called under j_state_lock.
    218  */
    219 static __inline__ int jbd_space_needed(journal_t *journal)
    220 {
    221 	int nblocks = journal->j_max_transaction_buffers;
    222 	if (journal->j_committing_transaction)
    223 		nblocks += journal->j_committing_transaction->
    224 					t_outstanding_credits;
    225 	return nblocks;
    226 }
    227 
    228 /*
    229  * Definitions which augment the buffer_head layer
    230  */
    231 
    232 /* journaling buffer types */
    233 #define BJ_None		0	/* Not journaled */
    234 #define BJ_SyncData	1	/* Normal data: flush before commit */
    235 #define BJ_Metadata	2	/* Normal journaled metadata */
    236 #define BJ_Forget	3	/* Buffer superseded by this transaction */
    237 #define BJ_IO		4	/* Buffer is for temporary IO use */
    238 #define BJ_Shadow	5	/* Buffer contents being shadowed to the log */
    239 #define BJ_LogCtl	6	/* Buffer contains log descriptors */
    240 #define BJ_Reserved	7	/* Buffer is reserved for access by journal */
    241 #define BJ_Locked	8	/* Locked for I/O during commit */
    242 #define BJ_Types	9
    243 
    244 extern int jbd_blocks_per_page(struct inode *inode);
    245 
    246 
    247 #endif	/* _LINUX_JBD_H */
    248