kernel-jbd.h revision b49d67ddd8af9568bd5eee319af0479f042db4fd
1586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 28cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * linux/include/linux/jbd.h 3efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o * 4586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * Written by Stephen C. Tweedie <sct@redhat.com> 5586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * 6586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * Copyright 1998-2000 Red Hat, Inc --- All Rights Reserved 7586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * 8586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * This file is part of the Linux kernel and is made available under 9586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * the terms of the GNU General Public License, version 2, or at your 10586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * option, any later version, incorporated herein by reference. 11586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * 12586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * Definitions for transaction data structures for the buffer cache 13586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * filesystem journaling support. 14586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 15586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 168cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#ifndef _LINUX_JBD_H 178cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define _LINUX_JBD_H 188cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 198cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#if defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE) || !defined(__KERNEL__) 20586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 21586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Allow this file to be included directly into e2fsprogs */ 22586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#ifndef __KERNEL__ 23586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#include "jfs_compat.h" 248cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define JFS_DEBUG 258cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define jfs_debug jbd_debug 268cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#else 278cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 288cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#include <linux/journal-head.h> 298cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#include <linux/stddef.h> 308cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#include <asm/semaphore.h> 31586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#endif 32586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 33ed78c021c3b111d8ab9a51aef5d5156e3004083fTheodore Ts'o#ifndef __GNUC__ 34ed78c021c3b111d8ab9a51aef5d5156e3004083fTheodore Ts'o#define __FUNCTION__ "" 35ed78c021c3b111d8ab9a51aef5d5156e3004083fTheodore Ts'o#endif 36ed78c021c3b111d8ab9a51aef5d5156e3004083fTheodore Ts'o 378cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define journal_oom_retry 1 388cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 397d4343d0d05ce69e0a72da5ac34eea415d4c789fTheodore Ts'o#ifdef __STDC__ 408cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#ifdef CONFIG_JBD_DEBUG 41586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 428cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal 438cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * consistency checks. By default we don't do this unless 448cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * CONFIG_JBD_DEBUG is on. 45586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 468cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define JBD_EXPENSIVE_CHECKING 47586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_enable_debug; 48586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 498cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define jbd_debug(n, f, a...) \ 50586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o do { \ 51586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o if ((n) <= journal_enable_debug) { \ 528cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o printk (KERN_DEBUG "(%s, %d): %s: ", \ 53586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __FILE__, __LINE__, __FUNCTION__); \ 54f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o printk (f, ## a); \ 55586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o } \ 56586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o } while (0) 57586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#else 58ed78c021c3b111d8ab9a51aef5d5156e3004083fTheodore Ts'o#ifdef __GNUC__ 598cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define jbd_debug(f, a...) /**/ 60ed78c021c3b111d8ab9a51aef5d5156e3004083fTheodore Ts'o#else 61ed78c021c3b111d8ab9a51aef5d5156e3004083fTheodore Ts'o#define jbd_debug(f, ...) /**/ 62efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o#endif 63586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#endif 647d4343d0d05ce69e0a72da5ac34eea415d4c789fTheodore Ts'o#else 657d4343d0d05ce69e0a72da5ac34eea415d4c789fTheodore Ts'o#define jbd_debug(x) /* AIX doesn't do STDC */ 667d4343d0d05ce69e0a72da5ac34eea415d4c789fTheodore Ts'o#endif 67586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 688cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void * __jbd_kmalloc (char *where, size_t size, int flags, int retry); 698cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define jbd_kmalloc(size, flags) \ 708cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry) 718cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define jbd_rep_kmalloc(size, flags) \ 728cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o __jbd_kmalloc(__FUNCTION__, (size), (flags), 1) 738cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 74586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_MIN_JOURNAL_BLOCKS 1024 75586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 768cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#ifdef __KERNEL__ 778cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'otypedef struct handle_s handle_t; /* Atomic operation type */ 788cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'otypedef struct journal_s journal_t; /* Journal control structure */ 798cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#endif 808cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 81586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 82586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * Internal structures used by the logging mechanism: 83586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 84586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 85586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */ 86586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 87586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 88586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * On-disk structures 89586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 90586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 91efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o/* 92586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * Descriptor block types: 93586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 94586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 95586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_DESCRIPTOR_BLOCK 1 96586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_COMMIT_BLOCK 2 97586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_SUPERBLOCK_V1 3 98586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_SUPERBLOCK_V2 4 99586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_REVOKE_BLOCK 5 100586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 101586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 102586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * Standard header for all descriptor blocks: 103586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 104586187372afea65ae685687505b49b40fc5f3212Theodore Ts'otypedef struct journal_header_s 105586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 106586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 h_magic; 107586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 h_blocktype; 108586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 h_sequence; 109586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} journal_header_t; 110586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 111185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o/* 112185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o * Checksum types. 113185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o */ 114185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JBD2_CRC32_CHKSUM 1 115185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JBD2_MD5_CHKSUM 2 116185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JBD2_SHA1_CHKSUM 3 117185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o 118185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JBD2_CRC32_CHKSUM_SIZE 4 119185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o 120185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JBD2_CHECKSUM_BYTES (32 / sizeof(__u32)) 121185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o/* 122185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o * Commit block header for storing transactional checksums: 123185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o */ 124185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'ostruct commit_header { 125185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o __u32 h_magic; 126185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o __u32 h_blocktype; 127185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o __u32 h_sequence; 128185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o unsigned char h_chksum_type; 129185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o unsigned char h_chksum_size; 130185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o unsigned char h_padding[2]; 131185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o __u32 h_chksum[JBD2_CHECKSUM_BYTES]; 132185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o __u64 h_commit_sec; 133185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o __u32 h_commit_nsec; 134185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o}; 135586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 136efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o/* 137efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o * The block tag: used to describe a single buffer in the journal 138586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 139586187372afea65ae685687505b49b40fc5f3212Theodore Ts'otypedef struct journal_block_tag_s 140586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 141586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 t_blocknr; /* The on-disk block number */ 142586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 t_flags; /* See below */ 143185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o __u32 t_blocknr_high; /* most-significant high 32bits. */ 144586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} journal_block_tag_t; 145586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 146185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JBD_TAG_SIZE64 (sizeof(journal_block_tag_t)) 147185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JBD_TAG_SIZE32 (8) 148185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o 149efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o/* 150586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * The revoke descriptor: used on disk to describe a series of blocks to 151efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o * be revoked from the log 152586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 153586187372afea65ae685687505b49b40fc5f3212Theodore Ts'otypedef struct journal_revoke_header_s 154586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 155586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o journal_header_t r_header; 156586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int r_count; /* Count of bytes used in the block */ 157586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} journal_revoke_header_t; 158586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 159586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 160586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Definitions for the journal tag flags word: */ 161586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */ 162586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */ 163586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_FLAG_DELETED 4 /* block deleted by this transaction */ 164586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */ 165586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 166586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 167586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 168586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * The journal superblock. All fields are in big-endian byte order. 169586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 170586187372afea65ae685687505b49b40fc5f3212Theodore Ts'otypedef struct journal_superblock_s 171586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 172586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x0000 */ 173586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o journal_header_t s_header; 174586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 175586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x000C */ 176586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Static information describing the journal */ 177586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_blocksize; /* journal device blocksize */ 178586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_maxlen; /* total blocks in journal file */ 179586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_first; /* first block of log information */ 180efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 181586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x0018 */ 182586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Dynamic information describing the current state of the log */ 183586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_sequence; /* first commit ID expected in log */ 184586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_start; /* blocknr of start of log */ 185586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 186586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x0020 */ 187586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Error value, as set by journal_abort(). */ 188586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __s32 s_errno; 189586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 190586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x0024 */ 191586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Remaining fields are only valid in a version-2 superblock */ 192586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_feature_compat; /* compatible feature set */ 193586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_feature_incompat; /* incompatible feature set */ 194586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_feature_ro_compat; /* readonly-compatible feature set */ 195586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x0030 */ 196586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u8 s_uuid[16]; /* 128-bit uuid for journal */ 197586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 198586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x0040 */ 199586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_nr_users; /* Nr of filesystems sharing log */ 200efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 201586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_dynsuper; /* Blocknr of dynamic superblock copy*/ 202efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 203586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x0048 */ 204586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_max_transaction; /* Limit of journal blocks per trans.*/ 205586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_max_trans_data; /* Limit of data blocks per trans. */ 206586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 207586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x0050 */ 208586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u32 s_padding[44]; 209586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 210586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x0100 */ 211586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u8 s_users[16*48]; /* ids of all fs'es sharing the log */ 212586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 0x0400 */ 213586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} journal_superblock_t; 214586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 215586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_HAS_COMPAT_FEATURE(j,mask) \ 216586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o ((j)->j_format_version >= 2 && \ 217b49d67ddd8af9568bd5eee319af0479f042db4fdTheodore Ts'o ((j)->j_superblock->s_feature_compat & ext2fs_cpu_to_be32((mask)))) 218586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \ 219586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o ((j)->j_format_version >= 2 && \ 220b49d67ddd8af9568bd5eee319af0479f042db4fdTheodore Ts'o ((j)->j_superblock->s_feature_ro_compat & ext2fs_cpu_to_be32((mask)))) 221586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_HAS_INCOMPAT_FEATURE(j,mask) \ 222586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o ((j)->j_format_version >= 2 && \ 223b49d67ddd8af9568bd5eee319af0479f042db4fdTheodore Ts'o ((j)->j_superblock->s_feature_incompat & ext2fs_cpu_to_be32((mask)))) 224586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 225185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JFS_FEATURE_COMPAT_CHECKSUM 0x00000001 226185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o 227586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001 228586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 229185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001 230185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JFS_FEATURE_INCOMPAT_64BIT 0x00000002 231185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JFS_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004 232185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o 233586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Features known to this kernel version: */ 234586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_KNOWN_COMPAT_FEATURES 0 235586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JFS_KNOWN_ROCOMPAT_FEATURES 0 236185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o#define JFS_KNOWN_INCOMPAT_FEATURES (JFS_FEATURE_INCOMPAT_REVOKE|\ 237054e5a9ccf8d65e015f2af85bfddd3fda3a0472fValerie Aurora Henson JFS_FEATURE_INCOMPAT_ASYNC_COMMIT|\ 238054e5a9ccf8d65e015f2af85bfddd3fda3a0472fValerie Aurora Henson JFS_FEATURE_INCOMPAT_64BIT) 239586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 240586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#ifdef __KERNEL__ 241586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 242586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#include <linux/fs.h> 2438cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#include <linux/sched.h> 244586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 2458cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define JBD_ASSERTIONS 2468cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#ifdef JBD_ASSERTIONS 247586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define J_ASSERT(assert) \ 2488cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'odo { \ 2498cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o if (!(assert)) { \ 250586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o printk (KERN_EMERG \ 2518cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o "Assertion failure in %s() at %s:%d: \"%s\"\n", \ 252586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __FUNCTION__, __FILE__, __LINE__, # assert); \ 2538cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o BUG(); \ 2548cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o } \ 2558cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o} while (0) 2568cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 2578cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#if defined(CONFIG_BUFFER_DEBUG) 2588cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ovoid buffer_assertion_failure(struct buffer_head *bh); 2598cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define J_ASSERT_BH(bh, expr) \ 2608cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o do { \ 2618cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o if (!(expr)) \ 2628cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o buffer_assertion_failure(bh); \ 2638cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o J_ASSERT(expr); \ 2648cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o } while (0) 2658cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define J_ASSERT_JH(jh, expr) J_ASSERT_BH(jh2bh(jh), expr) 2668cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#else 2678cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define J_ASSERT_BH(bh, expr) J_ASSERT(expr) 2688cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define J_ASSERT_JH(jh, expr) J_ASSERT(expr) 2698cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#endif 2708cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 2718cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#else 2728cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define J_ASSERT(assert) 2738cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#endif /* JBD_ASSERTIONS */ 2748cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 2758cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oenum jbd_state_bits { 2768cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o BH_JWrite 2778cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o = BH_PrivateStart, /* 1 if being written to log (@@@ DEBUGGING) */ 2788cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o BH_Freed, /* 1 if buffer has been freed (truncated) */ 2798cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o BH_Revoked, /* 1 if buffer has been revoked from the log */ 2808cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o BH_RevokeValid, /* 1 if buffer revoked flag is valid */ 2818cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o BH_JBDDirty, /* 1 if buffer is dirty but journaled */ 2828cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o}; 2838cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 2848cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* Return true if the buffer is one which JBD is managing */ 2858cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline int buffer_jbd(struct buffer_head *bh) 2868cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o{ 2878cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o return __buffer_state(bh, JBD); 2888cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o} 2898cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 2908cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline struct buffer_head *jh2bh(struct journal_head *jh) 2918cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o{ 2928cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o return jh->b_bh; 2938cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o} 294586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 2958cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline struct journal_head *bh2jh(struct buffer_head *bh) 2968cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o{ 2978cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o return bh->b_private; 2988cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o} 299586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 3008cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostruct jbd_revoke_table_s; 301586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 302586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* The handle_t type represents a single atomic update being performed 303586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * by some process. All filesystem modifications made by the process go 304586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * through this handle. Recursive operations (such as quota operations) 305586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * are gathered into a single update. 306586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * 307586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * The buffer credits field is used to account for journaled buffers 308586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * being modified by the running process. To ensure that there is 309586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * enough log space for all outstanding operations, we need to limit the 310586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * number of outstanding buffers possible at any time. When the 311586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * operation completes, any buffer credits not used are credited back to 312586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * the transaction, so that at all times we know how many buffers the 313586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * outstanding updates on a transaction might possibly touch. */ 314586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 315efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'ostruct handle_s 316586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 317586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Which compound transaction is this update a part of? */ 318586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o transaction_t * h_transaction; 319586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 320586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Number of remaining buffers we are allowed to dirty: */ 321586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int h_buffer_credits; 322586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 323586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Reference count on this handle */ 324586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int h_ref; 325586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 3268cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* Field for caller's use to track errors through large fs 3278cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o operations */ 3288cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o int h_err; 3298cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 330586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Flags */ 3318cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o unsigned int h_sync: 1; /* sync-on-close */ 3328cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o unsigned int h_jdata: 1; /* force data journaling */ 3338cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o unsigned int h_aborted: 1; /* fatal error on handle */ 334586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o}; 335586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 336586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 337586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* The transaction_t type is the guts of the journaling mechanism. It 338586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * tracks a compound transaction through its various states: 339586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * 340586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * RUNNING: accepting new updates 341586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * LOCKED: Updates still running but we don't accept new ones 342586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * RUNDOWN: Updates are tidying up but have finished requesting 343586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * new buffers to modify (state not used for now) 344586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * FLUSH: All updates complete, but we are still writing to disk 345586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * COMMIT: All data on disk, writing commit record 346586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * FINISHED: We still have to keep the transaction for checkpointing. 347586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * 348586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * The transaction keeps track of all of the buffers modified by a 349586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * running transaction, and all of the buffers committed but not yet 350586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * flushed to home for finished transactions. 351586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 352586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 353efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'ostruct transaction_s 354586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 355586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Pointer to the journal for this transaction. */ 356586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o journal_t * t_journal; 357efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 358586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Sequence number for this transaction */ 359586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o tid_t t_tid; 360efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 361586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Transaction's current state */ 362586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o enum { 363586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o T_RUNNING, 364586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o T_LOCKED, 365586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o T_RUNDOWN, 366586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o T_FLUSH, 367586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o T_COMMIT, 368efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o T_FINISHED 369586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o } t_state; 370586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 371586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Where in the log does this transaction's commit start? */ 372586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o unsigned long t_log_start; 373efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 374586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Doubly-linked circular list of all inodes owned by this 3758cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o transaction */ /* AKPM: unused */ 376586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o struct inode * t_ilist; 377efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 378586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Number of buffers on the t_buffers list */ 379586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int t_nr_buffers; 380efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 381586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Doubly-linked circular list of all buffers reserved but not 382586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o yet modified by this transaction */ 3838cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head * t_reserved_list; 384efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 385586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Doubly-linked circular list of all metadata buffers owned by this 386586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o transaction */ 3878cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head * t_buffers; 388efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 3898cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* 3908cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Doubly-linked circular list of all data buffers still to be 3918cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * flushed before this transaction can be committed. 3928cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Protected by journal_datalist_lock. 3938cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o */ 3948cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head * t_sync_datalist; 395efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 3968cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* 3978cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Doubly-linked circular list of all writepage data buffers 3988cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * still to be written before this transaction can be committed. 3998cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Protected by journal_datalist_lock. 4008cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o */ 4018cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head * t_async_datalist; 402efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 403586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Doubly-linked circular list of all forget buffers (superceded 404586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o buffers which we can un-checkpoint once this transaction 405586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o commits) */ 4068cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head * t_forget; 407efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 4088cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* 4098cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Doubly-linked circular list of all buffers still to be 4108cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * flushed before this transaction can be checkpointed. 4118cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o */ 4128cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* Protected by journal_datalist_lock */ 4138cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head * t_checkpoint_list; 414efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 415586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Doubly-linked circular list of temporary buffers currently 416586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o undergoing IO in the log */ 4178cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head * t_iobuf_list; 418efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 419586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Doubly-linked circular list of metadata buffers being 420586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o shadowed by log IO. The IO buffers on the iobuf list and the 421586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o shadow buffers on this list match each other one for one at 422586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o all times. */ 4238cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head * t_shadow_list; 424efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 425586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Doubly-linked circular list of control buffers being written 426586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o to the log. */ 4278cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head * t_log_list; 428efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 429586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Number of outstanding updates running on this transaction */ 430586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int t_updates; 431586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 432586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Number of buffers reserved for use by all handles in this 433586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * transaction handle but not yet modified. */ 434586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int t_outstanding_credits; 435efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 4368cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* 4378cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Forward and backward links for the circular list of all 4388cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * transactions awaiting checkpoint. 4398cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o */ 4408cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* Protected by journal_datalist_lock */ 441586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o transaction_t *t_cpnext, *t_cpprev; 442586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 443586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* When will the transaction expire (become due for commit), in 444586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * jiffies ? */ 445586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o unsigned long t_expires; 4468cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 4478cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* How many handles used this transaction? */ 4488cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o int t_handle_count; 449586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o}; 450586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 451586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 452586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* The journal_t maintains all of the journaling state information for a 453586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * single filesystem. It is linked to from the fs superblock structure. 454efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o * 455586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * We use the journal_t to keep track of all outstanding transaction 456586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * activity on the filesystem, and to manage the state of the log 457586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * writing process. */ 458586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 459586187372afea65ae685687505b49b40fc5f3212Theodore Ts'ostruct journal_s 460586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 461586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* General journaling state flags */ 462586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o unsigned long j_flags; 463586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 464586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Is there an outstanding uncleared error on the journal (from 465586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * a prior abort)? */ 466586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int j_errno; 467efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 468586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* The superblock buffer */ 469586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o struct buffer_head * j_sb_buffer; 470586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o journal_superblock_t * j_superblock; 471586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 472586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Version of the superblock format */ 473586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int j_format_version; 474f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o 475f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o /* Number of processes waiting to create a barrier lock */ 476f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o int j_barrier_count; 477efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 478f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o /* The barrier lock itself */ 479f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o struct semaphore j_barrier; 480efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 481586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Transactions: The current running transaction... */ 482586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o transaction_t * j_running_transaction; 483efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 484586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* ... the transaction we are pushing to disk ... */ 485586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o transaction_t * j_committing_transaction; 486efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 487586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* ... and a linked circular list of all transactions waiting 488586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * for checkpointing. */ 4898cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* Protected by journal_datalist_lock */ 490586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o transaction_t * j_checkpoint_transactions; 491586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 492586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Wait queue for waiting for a locked transaction to start 493f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o committing, or for a barrier lock to be released */ 4948cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o wait_queue_head_t j_wait_transaction_locked; 495efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 496586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Wait queue for waiting for checkpointing to complete */ 4978cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o wait_queue_head_t j_wait_logspace; 498efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 499586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Wait queue for waiting for commit to complete */ 5008cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o wait_queue_head_t j_wait_done_commit; 501efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 502586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Wait queue to trigger checkpointing */ 5038cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o wait_queue_head_t j_wait_checkpoint; 504efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 505586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Wait queue to trigger commit */ 5068cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o wait_queue_head_t j_wait_commit; 507efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 508f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o /* Wait queue to wait for updates to complete */ 5098cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o wait_queue_head_t j_wait_updates; 510f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o 511586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Semaphore for locking against concurrent checkpoints */ 512586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o struct semaphore j_checkpoint_sem; 513586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 5148cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* The main journal lock, used by lock_journal() */ 5158cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct semaphore j_sem; 516efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 517586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Journal head: identifies the first unused block in the journal. */ 518586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o unsigned long j_head; 519efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 520586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Journal tail: identifies the oldest still-used block in the 521586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * journal. */ 522586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o unsigned long j_tail; 523586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 524586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Journal free: how many free blocks are there in the journal? */ 525586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o unsigned long j_free; 526586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 527586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Journal start and end: the block numbers of the first usable 528586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * block and one beyond the last usable block in the journal. */ 529586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o unsigned long j_first, j_last; 530586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 531586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Device, blocksize and starting block offset for the location 532586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * where we store the journal. */ 533586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o kdev_t j_dev; 534586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int j_blocksize; 535586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o unsigned int j_blk_offset; 536586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 5378cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* Device which holds the client fs. For internal journal this 5388cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * will be equal to j_dev. */ 5398cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o kdev_t j_fs_dev; 5408cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 541586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Total maximum capacity of the journal region on disk. */ 542586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o unsigned int j_maxlen; 543586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 544586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Optional inode where we store the journal. If present, all 545586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * journal block numbers are mapped into this inode via 546586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * bmap(). */ 547586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o struct inode * j_inode; 548586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 549586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Sequence number of the oldest transaction in the log */ 550586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o tid_t j_tail_sequence; 551586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Sequence number of the next transaction to grant */ 552586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o tid_t j_transaction_sequence; 553586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Sequence number of the most recently committed transaction */ 554586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o tid_t j_commit_sequence; 555586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Sequence number of the most recent transaction wanting commit */ 556586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o tid_t j_commit_request; 557586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 558586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Journal uuid: identifies the object (filesystem, LVM volume 559586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * etc) backed by this journal. This will eventually be 560586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * replaced by an array of uuids, allowing us to index multiple 561586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * devices within a single journal and to perform atomic updates 562586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * across them. */ 563586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 564586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o __u8 j_uuid[16]; 565586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 566586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Pointer to the current commit thread for this journal */ 567586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o struct task_struct * j_task; 568586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 569586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* Maximum number of metadata buffers to allow in a single 570586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * compound commit transaction */ 571586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int j_max_transaction_buffers; 572586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 573586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* What is the maximum transaction lifetime before we begin a 574586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * commit? */ 575586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o unsigned long j_commit_interval; 576586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 577586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* The timer used to wakeup the commit thread: */ 578586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o struct timer_list * j_commit_timer; 579586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int j_commit_timer_active; 580586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 5818cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o /* Link all journals together - system-wide */ 5828cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct list_head j_all_journals; 5838cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 584586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o /* The revoke table: maintains the list of revoked blocks in the 585586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o current transaction. */ 5868cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct jbd_revoke_table_s *j_revoke; 587185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o 588185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o /* Failed journal commit ID */ 589185c4aeaf23d48375e3506218305031663203d0fTheodore Ts'o unsigned int j_failed_commit; 590586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o}; 591586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 592efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o/* 593efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o * Journal flag definitions 594586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 595f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o#define JFS_UNMOUNT 0x001 /* Journal thread is being destroyed */ 5968cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define JFS_ABORT 0x002 /* Journaling has been aborted for errors. */ 5978cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define JFS_ACK_ERR 0x004 /* The errno in the sb has been acked */ 5988cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define JFS_FLUSHED 0x008 /* The journal superblock has been flushed */ 5998cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define JFS_LOADED 0x010 /* The journal superblock has been loaded */ 600586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 601efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o/* 602586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * Function declarations for the journaling transaction and buffer 603586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * management 604586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 605586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 606586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Filing buffers */ 6078cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void __journal_unfile_buffer(struct journal_head *); 6088cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_unfile_buffer(struct journal_head *); 6098cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void __journal_refile_buffer(struct journal_head *); 6108cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_refile_buffer(struct journal_head *); 6118cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void __journal_file_buffer(struct journal_head *, transaction_t *, int); 6128cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void __journal_free_buffer(struct journal_head *bh); 6138cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_file_buffer(struct journal_head *, transaction_t *, int); 6148cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void __journal_clean_data_list(transaction_t *transaction); 615586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 616586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Log buffer allocation */ 6178cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern struct journal_head * journal_get_descriptor_buffer(journal_t *); 618586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern unsigned long journal_next_log_block(journal_t *); 619586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 620586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Commit management */ 621586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void journal_commit_transaction(journal_t *); 622586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 623586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Checkpoint list management */ 6248cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oint __journal_clean_checkpoint_list(journal_t *journal); 6258cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_remove_checkpoint(struct journal_head *); 6268cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void __journal_remove_checkpoint(struct journal_head *); 6278cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_insert_checkpoint(struct journal_head *, transaction_t *); 6288cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void __journal_insert_checkpoint(struct journal_head *,transaction_t *); 629586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 630586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Buffer IO */ 631efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'oextern int 632586187372afea65ae685687505b49b40fc5f3212Theodore Ts'ojournal_write_metadata_buffer(transaction_t *transaction, 6338cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head *jh_in, 6348cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct journal_head **jh_out, 635586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int blocknr); 636586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 637586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Transaction locking */ 638586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void __wait_on_journal (journal_t *); 639586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 6408cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* 6418cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Journal locking. 6428cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * 6438cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * We need to lock the journal during transaction state changes so that 6448cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * nobody ever tries to take a handle on the running transaction while 645efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o * we are in the middle of moving it to the commit phase. 6468cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * 6478cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Note that the locking is completely interrupt unsafe. We never touch 6488cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * journal structures from interrupts. 6498cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * 6508cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * In 2.2, the BKL was required for lock_journal. This is no longer 6518cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * the case. 6528cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o */ 6538cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 6548cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline void lock_journal(journal_t *journal) 655586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 6568cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o down(&journal->j_sem); 657586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} 658586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 6598cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* This returns zero if we acquired the semaphore */ 6608cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline int try_lock_journal(journal_t * journal) 661586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 6628cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o return down_trylock(&journal->j_sem); 663586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} 664586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 6658cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline void unlock_journal(journal_t * journal) 666586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 6678cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o up(&journal->j_sem); 668586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} 669586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 670586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 6718cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline handle_t *journal_current_handle(void) 672586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 6738cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o return current->journal_info; 674586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} 675586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 676586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* The journaling code user interface: 677586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * 678586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * Create and destroy handles 679efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o * Register buffer modifications against the current transaction. 680586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 681586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 6828cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern handle_t *journal_start(journal_t *, int nblocks); 6838cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern handle_t *journal_try_start(journal_t *, int nblocks); 684586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_restart (handle_t *, int nblocks); 685586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_extend (handle_t *, int nblocks); 686586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_get_write_access (handle_t *, struct buffer_head *); 687586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_get_create_access (handle_t *, struct buffer_head *); 688586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_get_undo_access (handle_t *, struct buffer_head *); 6898cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_dirty_data (handle_t *, 6908cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o struct buffer_head *, int async); 691586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_dirty_metadata (handle_t *, struct buffer_head *); 692586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void journal_release_buffer (handle_t *, struct buffer_head *); 693586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void journal_forget (handle_t *, struct buffer_head *); 694586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void journal_sync_buffer (struct buffer_head *); 6958cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_flushpage(journal_t *, struct page *, unsigned long); 6968cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_try_to_free_buffers(journal_t *, struct page *, int); 6978cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_stop(handle_t *); 698586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_flush (journal_t *); 699586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 700f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'oextern void journal_lock_updates (journal_t *); 701f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'oextern void journal_unlock_updates (journal_t *); 702f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o 7038cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern journal_t * journal_init_dev(kdev_t dev, kdev_t fs_dev, 7048cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o int start, int len, int bsize); 705586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern journal_t * journal_init_inode (struct inode *); 706586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_update_format (journal_t *); 707efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'oextern int journal_check_used_features 708586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o (journal_t *, unsigned long, unsigned long, unsigned long); 709efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'oextern int journal_check_available_features 710586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o (journal_t *, unsigned long, unsigned long, unsigned long); 711efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'oextern int journal_set_features 712586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o (journal_t *, unsigned long, unsigned long, unsigned long); 713586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_create (journal_t *); 7148cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_load (journal_t *journal); 7158cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_destroy (journal_t *); 7168cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_recover (journal_t *journal); 717f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'oextern int journal_wipe (journal_t *, int); 718f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'oextern int journal_skip_recovery (journal_t *); 719586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void journal_update_superblock (journal_t *, int); 720586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void __journal_abort (journal_t *); 721586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void journal_abort (journal_t *, int); 722586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_errno (journal_t *); 723586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void journal_ack_err (journal_t *); 724586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int journal_clear_err (journal_t *); 7258cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern unsigned long journal_bmap(journal_t *journal, unsigned long blocknr); 7268cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_force_commit(journal_t *journal); 7278cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 7288cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* 7298cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * journal_head management 7308cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o */ 7318cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern struct journal_head 7328cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o *journal_add_journal_head(struct buffer_head *bh); 7338cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_remove_journal_head(struct buffer_head *bh); 7348cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void __journal_remove_journal_head(struct buffer_head *bh); 7358cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_unlock_journal_head(struct journal_head *jh); 736586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 737586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Primary revoke support */ 738586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o#define JOURNAL_REVOKE_DEFAULT_HASH 256 7398cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_init_revoke(journal_t *, int); 7408cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_destroy_revoke_caches(void); 7418cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_init_revoke_caches(void); 7428cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 7438cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_destroy_revoke(journal_t *); 7448cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_revoke (handle_t *, 7458cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o unsigned long, struct buffer_head *); 7468cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_cancel_revoke(handle_t *, struct journal_head *); 747586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void journal_write_revoke_records(journal_t *, transaction_t *); 748586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 7498cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* Recovery revoke support */ 7508cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_set_revoke(journal_t *, unsigned long, tid_t); 7518cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_test_revoke(journal_t *, unsigned long, tid_t); 7528cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_clear_revoke(journal_t *); 7538cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_brelse_array(struct buffer_head *b[], int n); 7548cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 755586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* The log thread user interface: 756586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * 757586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * Request space in the current transaction, and force transaction commit 758586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * transitions on demand. 759586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 760586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 761586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int log_space_left (journal_t *); /* Called with journal locked */ 7628cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern tid_t log_start_commit (journal_t *, transaction_t *); 763586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void log_wait_commit (journal_t *, tid_t); 764586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int log_do_checkpoint (journal_t *, int); 765586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 766586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern void log_wait_for_space(journal_t *, int nblocks); 7678cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void __journal_drop_transaction(journal_t *, transaction_t *); 768586187372afea65ae685687505b49b40fc5f3212Theodore Ts'oextern int cleanup_journal_tail(journal_t *); 769586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 7708cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* Reduce journal memory usage by flushing */ 7718cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void shrink_journal_memory(void); 772586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 773586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Debugging code only: */ 774586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 7758cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define jbd_ENOSYS() \ 776586187372afea65ae685687505b49b40fc5f3212Theodore Ts'odo { \ 7778cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o printk (KERN_ERR "JBD unimplemented function " __FUNCTION__); \ 778586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o current->state = TASK_UNINTERRUPTIBLE; \ 779586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o schedule(); \ 780586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} while (1) 781586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 782586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* 783586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * is_journal_abort 784586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * 785586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * Simple test wrapper function to test the JFS_ABORT state flag. This 786586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * bit, when set, indicates that we have had a fatal error somewhere, 787586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * either inside the journaling layer or indicated to us by the client 788586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * (eg. ext3), and that we and should not commit any further 789efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o * transactions. 790586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o */ 791586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 7928cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline int is_journal_aborted(journal_t *journal) 793586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 794586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o return journal->j_flags & JFS_ABORT; 795586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} 796586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 7978cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline int is_handle_aborted(handle_t *handle) 7988cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o{ 7998cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o if (handle->h_aborted) 8008cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o return 1; 8018cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o return is_journal_aborted(handle->h_transaction->t_journal); 8028cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o} 80350286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'o 8048cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline void journal_abort_handle(handle_t *handle) 80550286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'o{ 8068cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o handle->h_aborted = 1; 80750286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'o} 80850286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'o 809f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o/* Not all architectures define BUG() */ 810f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o#ifndef BUG 81148e6e81362f264aee4f3945c14928efaf71a06c9Theodore Ts'o#define BUG() do { \ 812f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \ 813f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o * ((char *) 0) = 0; \ 814f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o } while (0) 815f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o#endif /* BUG */ 816f13a987afa5b7d12c8da69d1a1c282b0dfc0b5f4Theodore Ts'o 8178cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#else 81850286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'o 8198cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_recover (journal_t *journal); 8208cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_skip_recovery (journal_t *); 82150286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'o 8228cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* Primary revoke support */ 82350286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'oextern int journal_init_revoke(journal_t *, int); 8248cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_destroy_revoke_caches(void); 8258cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_init_revoke_caches(void); 82650286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'o 8278cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* Recovery revoke support */ 82850286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'oextern int journal_set_revoke(journal_t *, unsigned long, tid_t); 82950286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'oextern int journal_test_revoke(journal_t *, unsigned long, tid_t); 83050286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'oextern void journal_clear_revoke(journal_t *); 8318cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_brelse_array(struct buffer_head *b[], int n); 83250286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'o 8338cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern void journal_destroy_revoke(journal_t *); 8348cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#endif /* __KERNEL__ */ 83550286ad488f04d222a4ab7949f2db11a0fbb3098Theodore Ts'o 836dec5cd13fff821d1d3f6a922fbd986b3a86abb77Theodore Ts'ostatic inline int tid_gt(tid_t x, tid_t y) EXT2FS_ATTR((unused)); 837dec5cd13fff821d1d3f6a922fbd986b3a86abb77Theodore Ts'ostatic inline int tid_geq(tid_t x, tid_t y) EXT2FS_ATTR((unused)); 838dec5cd13fff821d1d3f6a922fbd986b3a86abb77Theodore Ts'o 839586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o/* Comparison functions for transaction IDs: perform comparisons using 840586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o * modulo arithmetic so that they work over sequence number wraps. */ 841586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 842725c474ffcf09bbdbd6cd396a867914fec7b4510Theodore Ts'ostatic inline int tid_gt(tid_t x, tid_t y) 843586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 844586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int difference = (x - y); 845586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o return (difference > 0); 846586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} 847586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 848586187372afea65ae685687505b49b40fc5f3212Theodore Ts'ostatic inline int tid_geq(tid_t x, tid_t y) 849586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o{ 850586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o int difference = (x - y); 851586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o return (difference >= 0); 852586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o} 853586187372afea65ae685687505b49b40fc5f3212Theodore Ts'o 8548cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int journal_blocks_per_page(struct inode *inode); 8558cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 8568cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* 8578cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Definitions which augment the buffer_head layer 8588cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o */ 8598cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 8608cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* journaling buffer types */ 8618cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BJ_None 0 /* Not journaled */ 8628cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BJ_SyncData 1 /* Normal data: flush before commit */ 8638cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BJ_AsyncData 2 /* writepage data: wait on it before commit */ 8648cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BJ_Metadata 3 /* Normal journaled metadata */ 8658cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BJ_Forget 4 /* Buffer superceded by this transaction */ 8668cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BJ_IO 5 /* Buffer is for temporary IO use */ 8678cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BJ_Shadow 6 /* Buffer contents being shadowed to the log */ 8688cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BJ_LogCtl 7 /* Buffer contains log descriptors */ 8698cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BJ_Reserved 8 /* Buffer is reserved for access by journal */ 8708cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BJ_Types 9 871efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o 8728cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern int jbd_blocks_per_page(struct inode *inode); 8738cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 8748cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#ifdef __KERNEL__ 8758cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 8768cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'oextern spinlock_t jh_splice_lock; 8778cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* 8788cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Once `expr1' has been found true, take jh_splice_lock 8798cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * and then reevaluate everything. 8808cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o */ 8818cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define SPLICE_LOCK(expr1, expr2) \ 8828cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o ({ \ 8838cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o int ret = (expr1); \ 8848cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o if (ret) { \ 8858cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o spin_lock(&jh_splice_lock); \ 8868cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o ret = (expr1) && (expr2); \ 8878cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o spin_unlock(&jh_splice_lock); \ 8888cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o } \ 8898cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o ret; \ 8908cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o }) 8918cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 8928cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* 8938cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * A number of buffer state predicates. They test for 8948cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * buffer_jbd() because they are used in core kernel code. 8958cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * 8968cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * These will be racy on SMP unless we're *sure* that the 8978cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * buffer won't be detached from the journalling system 8988cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * in parallel. 8998cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o */ 9008cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9018cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* Return true if the buffer is on journal list `list' */ 9028cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline int buffer_jlist_eq(struct buffer_head *bh, int list) 9038cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o{ 9048cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o return SPLICE_LOCK(buffer_jbd(bh), bh2jh(bh)->b_jlist == list); 9058cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o} 9068cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9078cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* Return true if this bufer is dirty wrt the journal */ 9088cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline int buffer_jdirty(struct buffer_head *bh) 9098cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o{ 9108cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o return buffer_jbd(bh) && __buffer_state(bh, JBDDirty); 9118cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o} 9128cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9138cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* Return true if it's a data buffer which journalling is managing */ 9148cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'ostatic inline int buffer_jbd_data(struct buffer_head *bh) 9158cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o{ 9168cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o return SPLICE_LOCK(buffer_jbd(bh), 9178cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o bh2jh(bh)->b_jlist == BJ_SyncData || 9188cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o bh2jh(bh)->b_jlist == BJ_AsyncData); 9198cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o} 9208cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9218cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#ifdef CONFIG_SMP 9228cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define assert_spin_locked(lock) J_ASSERT(spin_is_locked(lock)) 9238cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#else 9248cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define assert_spin_locked(lock) do {} while(0) 9258cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#endif 9268cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9278cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define buffer_trace_init(bh) do {} while (0) 9288cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define print_buffer_fields(bh) do {} while (0) 9298cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define print_buffer_trace(bh) do {} while (0) 9308cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BUFFER_TRACE(bh, info) do {} while (0) 9318cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define BUFFER_TRACE2(bh, bh2, info) do {} while (0) 9328cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define JBUFFER_TRACE(jh, info) do {} while (0) 9338cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9348cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#endif /* __KERNEL__ */ 9358cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9368cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#endif /* CONFIG_JBD || CONFIG_JBD_MODULE || !__KERNEL__ */ 9378cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9388cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o/* 9398cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * Compatibility no-ops which allow the kernel to compile without CONFIG_JBD 9408cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o * go here. 9418cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o */ 9428cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9438cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#if defined(__KERNEL__) && !(defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE)) 9448cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9458cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define J_ASSERT(expr) do {} while (0) 9468cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define J_ASSERT_BH(bh, expr) do {} while (0) 9478cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define buffer_jbd(bh) 0 9488cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define buffer_jlist_eq(bh, val) 0 9498cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#define journal_buffer_journal_lru(bh) 0 9508cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o 9518cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#endif /* defined(__KERNEL__) && !defined(CONFIG_JBD) */ 9528cf93332d180e6929d73cd8c855c3a83d6a6648cTheodore Ts'o#endif /* _LINUX_JBD_H */ 953