3
0

kernel-jbd.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. /*
  2. * linux/include/linux/jbd.h
  3. *
  4. * Written by Stephen C. Tweedie <sct@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. #ifndef _LINUX_JBD_H
  16. #define _LINUX_JBD_H
  17. #if defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE) || !defined(__KERNEL__)
  18. /* Allow this file to be included directly into e2fsprogs */
  19. #ifndef __KERNEL__
  20. #include "jfs_compat.h"
  21. #define JFS_DEBUG
  22. #define jfs_debug jbd_debug
  23. #else
  24. #include <linux/journal-head.h>
  25. #include <linux/stddef.h>
  26. #include <asm/semaphore.h>
  27. #endif
  28. #ifndef __GNUC__
  29. #define __FUNCTION__ ""
  30. #endif
  31. #define journal_oom_retry 1
  32. #ifdef __STDC__
  33. #ifdef __CONFIG_JBD_DEBUG__E2FS
  34. /*
  35. * Define JBD_EXPENSIVE_CHECKING to enable more expensive internal
  36. * consistency checks. By default we don't do this unless
  37. * __CONFIG_JBD_DEBUG__E2FS is on.
  38. */
  39. #define JBD_EXPENSIVE_CHECKING
  40. extern int journal_enable_debug;
  41. #define jbd_debug(n, f, a...) \
  42. do { \
  43. if ((n) <= journal_enable_debug) { \
  44. printk (KERN_DEBUG "(%s, %d): %s: ", \
  45. __FILE__, __LINE__, __FUNCTION__); \
  46. printk (f, ## a); \
  47. } \
  48. } while (0)
  49. #else
  50. #ifdef __GNUC__
  51. #define jbd_debug(f, a...) /**/
  52. #else
  53. #define jbd_debug(f, ...) /**/
  54. #endif
  55. #endif
  56. #else
  57. #define jbd_debug(x) /* AIX doesn't do STDC */
  58. #endif
  59. extern void * __jbd_kmalloc (char *where, size_t size, int flags, int retry);
  60. #define jbd_kmalloc(size, flags) \
  61. __jbd_kmalloc(__FUNCTION__, (size), (flags), journal_oom_retry)
  62. #define jbd_rep_kmalloc(size, flags) \
  63. __jbd_kmalloc(__FUNCTION__, (size), (flags), 1)
  64. #define JFS_MIN_JOURNAL_BLOCKS 1024
  65. #ifdef __KERNEL__
  66. typedef struct handle_s handle_t; /* Atomic operation type */
  67. typedef struct journal_s journal_t; /* Journal control structure */
  68. #endif
  69. /*
  70. * Internal structures used by the logging mechanism:
  71. */
  72. #define JFS_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
  73. /*
  74. * On-disk structures
  75. */
  76. /*
  77. * Descriptor block types:
  78. */
  79. #define JFS_DESCRIPTOR_BLOCK 1
  80. #define JFS_COMMIT_BLOCK 2
  81. #define JFS_SUPERBLOCK_V1 3
  82. #define JFS_SUPERBLOCK_V2 4
  83. #define JFS_REVOKE_BLOCK 5
  84. /*
  85. * Standard header for all descriptor blocks:
  86. */
  87. typedef struct journal_header_s
  88. {
  89. __u32 h_magic;
  90. __u32 h_blocktype;
  91. __u32 h_sequence;
  92. } journal_header_t;
  93. /*
  94. * The block tag: used to describe a single buffer in the journal
  95. */
  96. typedef struct journal_block_tag_s
  97. {
  98. __u32 t_blocknr; /* The on-disk block number */
  99. __u32 t_flags; /* See below */
  100. } journal_block_tag_t;
  101. /*
  102. * The revoke descriptor: used on disk to describe a series of blocks to
  103. * be revoked from the log
  104. */
  105. typedef struct journal_revoke_header_s
  106. {
  107. journal_header_t r_header;
  108. int r_count; /* Count of bytes used in the block */
  109. } journal_revoke_header_t;
  110. /* Definitions for the journal tag flags word: */
  111. #define JFS_FLAG_ESCAPE 1 /* on-disk block is escaped */
  112. #define JFS_FLAG_SAME_UUID 2 /* block has same uuid as previous */
  113. #define JFS_FLAG_DELETED 4 /* block deleted by this transaction */
  114. #define JFS_FLAG_LAST_TAG 8 /* last tag in this descriptor block */
  115. /*
  116. * The journal superblock. All fields are in big-endian byte order.
  117. */
  118. typedef struct journal_superblock_s
  119. {
  120. /* 0x0000 */
  121. journal_header_t s_header;
  122. /* 0x000C */
  123. /* Static information describing the journal */
  124. __u32 s_blocksize; /* journal device blocksize */
  125. __u32 s_maxlen; /* total blocks in journal file */
  126. __u32 s_first; /* first block of log information */
  127. /* 0x0018 */
  128. /* Dynamic information describing the current state of the log */
  129. __u32 s_sequence; /* first commit ID expected in log */
  130. __u32 s_start; /* blocknr of start of log */
  131. /* 0x0020 */
  132. /* Error value, as set by journal_abort(). */
  133. __s32 s_errno;
  134. /* 0x0024 */
  135. /* Remaining fields are only valid in a version-2 superblock */
  136. __u32 s_feature_compat; /* compatible feature set */
  137. __u32 s_feature_incompat; /* incompatible feature set */
  138. __u32 s_feature_ro_compat; /* readonly-compatible feature set */
  139. /* 0x0030 */
  140. __u8 s_uuid[16]; /* 128-bit uuid for journal */
  141. /* 0x0040 */
  142. __u32 s_nr_users; /* Nr of filesystems sharing log */
  143. __u32 s_dynsuper; /* Blocknr of dynamic superblock copy*/
  144. /* 0x0048 */
  145. __u32 s_max_transaction; /* Limit of journal blocks per trans.*/
  146. __u32 s_max_trans_data; /* Limit of data blocks per trans. */
  147. /* 0x0050 */
  148. __u32 s_padding[44];
  149. /* 0x0100 */
  150. __u8 s_users[16*48]; /* ids of all fs'es sharing the log */
  151. /* 0x0400 */
  152. } journal_superblock_t;
  153. #define JFS_HAS_COMPAT_FEATURE(j,mask) \
  154. ((j)->j_format_version >= 2 && \
  155. ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))
  156. #define JFS_HAS_RO_COMPAT_FEATURE(j,mask) \
  157. ((j)->j_format_version >= 2 && \
  158. ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask))))
  159. #define JFS_HAS_INCOMPAT_FEATURE(j,mask) \
  160. ((j)->j_format_version >= 2 && \
  161. ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
  162. #define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001
  163. /* Features known to this kernel version: */
  164. #define JFS_KNOWN_COMPAT_FEATURES 0
  165. #define JFS_KNOWN_ROCOMPAT_FEATURES 0
  166. #define JFS_KNOWN_INCOMPAT_FEATURES JFS_FEATURE_INCOMPAT_REVOKE
  167. #ifdef __KERNEL__
  168. #include <linux/fs.h>
  169. #include <linux/sched.h>
  170. #define JBD_ASSERTIONS
  171. #ifdef JBD_ASSERTIONS
  172. #define J_ASSERT(assert) \
  173. do { \
  174. if (!(assert)) { \
  175. printk (KERN_EMERG \
  176. "Assertion failure in %s() at %s:%d: \"%s\"\n", \
  177. __FUNCTION__, __FILE__, __LINE__, # assert); \
  178. BUG(); \
  179. } \
  180. } while (0)
  181. #if defined(CONFIG_BUFFER_DEBUG)
  182. void buffer_assertion_failure(struct buffer_head *bh);
  183. #define J_ASSERT_BH(bh, expr) \
  184. do { \
  185. if (!(expr)) \
  186. buffer_assertion_failure(bh); \
  187. J_ASSERT(expr); \
  188. } while (0)
  189. #define J_ASSERT_JH(jh, expr) J_ASSERT_BH(jh2bh(jh), expr)
  190. #else
  191. #define J_ASSERT_BH(bh, expr) J_ASSERT(expr)
  192. #define J_ASSERT_JH(jh, expr) J_ASSERT(expr)
  193. #endif
  194. #else
  195. #define J_ASSERT(assert)
  196. #endif /* JBD_ASSERTIONS */
  197. enum jbd_state_bits {
  198. BH_JWrite
  199. = BH_PrivateStart, /* 1 if being written to log (@@@ DEBUGGING) */
  200. BH_Freed, /* 1 if buffer has been freed (truncated) */
  201. BH_Revoked, /* 1 if buffer has been revoked from the log */
  202. BH_RevokeValid, /* 1 if buffer revoked flag is valid */
  203. BH_JBDDirty, /* 1 if buffer is dirty but journaled */
  204. };
  205. /* Return true if the buffer is one which JBD is managing */
  206. static inline int buffer_jbd(struct buffer_head *bh)
  207. {
  208. return __buffer_state(bh, JBD);
  209. }
  210. static inline struct buffer_head *jh2bh(struct journal_head *jh)
  211. {
  212. return jh->b_bh;
  213. }
  214. static inline struct journal_head *bh2jh(struct buffer_head *bh)
  215. {
  216. return bh->b_private;
  217. }
  218. struct jbd_revoke_table_s;
  219. /* The handle_t type represents a single atomic update being performed
  220. * by some process. All filesystem modifications made by the process go
  221. * through this handle. Recursive operations (such as quota operations)
  222. * are gathered into a single update.
  223. *
  224. * The buffer credits field is used to account for journaled buffers
  225. * being modified by the running process. To ensure that there is
  226. * enough log space for all outstanding operations, we need to limit the
  227. * number of outstanding buffers possible at any time. When the
  228. * operation completes, any buffer credits not used are credited back to
  229. * the transaction, so that at all times we know how many buffers the
  230. * outstanding updates on a transaction might possibly touch. */
  231. struct handle_s
  232. {
  233. /* Which compound transaction is this update a part of? */
  234. transaction_t * h_transaction;
  235. /* Number of remaining buffers we are allowed to dirty: */
  236. int h_buffer_credits;
  237. /* Reference count on this handle */
  238. int h_ref;
  239. /* Field for caller's use to track errors through large fs
  240. operations */
  241. int h_err;
  242. /* Flags */
  243. unsigned int h_sync: 1; /* sync-on-close */
  244. unsigned int h_jdata: 1; /* force data journaling */
  245. unsigned int h_aborted: 1; /* fatal error on handle */
  246. };
  247. /* The transaction_t type is the guts of the journaling mechanism. It
  248. * tracks a compound transaction through its various states:
  249. *
  250. * RUNNING: accepting new updates
  251. * LOCKED: Updates still running but we don't accept new ones
  252. * RUNDOWN: Updates are tidying up but have finished requesting
  253. * new buffers to modify (state not used for now)
  254. * FLUSH: All updates complete, but we are still writing to disk
  255. * COMMIT: All data on disk, writing commit record
  256. * FINISHED: We still have to keep the transaction for checkpointing.
  257. *
  258. * The transaction keeps track of all of the buffers modified by a
  259. * running transaction, and all of the buffers committed but not yet
  260. * flushed to home for finished transactions.
  261. */
  262. struct transaction_s
  263. {
  264. /* Pointer to the journal for this transaction. */
  265. journal_t * t_journal;
  266. /* Sequence number for this transaction */
  267. tid_t t_tid;
  268. /* Transaction's current state */
  269. enum {
  270. T_RUNNING,
  271. T_LOCKED,
  272. T_RUNDOWN,
  273. T_FLUSH,
  274. T_COMMIT,
  275. T_FINISHED
  276. } t_state;
  277. /* Where in the log does this transaction's commit start? */
  278. unsigned long t_log_start;
  279. /* Doubly-linked circular list of all inodes owned by this
  280. transaction */ /* AKPM: unused */
  281. struct inode * t_ilist;
  282. /* Number of buffers on the t_buffers list */
  283. int t_nr_buffers;
  284. /* Doubly-linked circular list of all buffers reserved but not
  285. yet modified by this transaction */
  286. struct journal_head * t_reserved_list;
  287. /* Doubly-linked circular list of all metadata buffers owned by this
  288. transaction */
  289. struct journal_head * t_buffers;
  290. /*
  291. * Doubly-linked circular list of all data buffers still to be
  292. * flushed before this transaction can be committed.
  293. * Protected by journal_datalist_lock.
  294. */
  295. struct journal_head * t_sync_datalist;
  296. /*
  297. * Doubly-linked circular list of all writepage data buffers
  298. * still to be written before this transaction can be committed.
  299. * Protected by journal_datalist_lock.
  300. */
  301. struct journal_head * t_async_datalist;
  302. /* Doubly-linked circular list of all forget buffers (superceded
  303. buffers which we can un-checkpoint once this transaction
  304. commits) */
  305. struct journal_head * t_forget;
  306. /*
  307. * Doubly-linked circular list of all buffers still to be
  308. * flushed before this transaction can be checkpointed.
  309. */
  310. /* Protected by journal_datalist_lock */
  311. struct journal_head * t_checkpoint_list;
  312. /* Doubly-linked circular list of temporary buffers currently
  313. undergoing IO in the log */
  314. struct journal_head * t_iobuf_list;
  315. /* Doubly-linked circular list of metadata buffers being
  316. shadowed by log IO. The IO buffers on the iobuf list and the
  317. shadow buffers on this list match each other one for one at
  318. all times. */
  319. struct journal_head * t_shadow_list;
  320. /* Doubly-linked circular list of control buffers being written
  321. to the log. */
  322. struct journal_head * t_log_list;
  323. /* Number of outstanding updates running on this transaction */
  324. int t_updates;
  325. /* Number of buffers reserved for use by all handles in this
  326. * transaction handle but not yet modified. */
  327. int t_outstanding_credits;
  328. /*
  329. * Forward and backward links for the circular list of all
  330. * transactions awaiting checkpoint.
  331. */
  332. /* Protected by journal_datalist_lock */
  333. transaction_t *t_cpnext, *t_cpprev;
  334. /* When will the transaction expire (become due for commit), in
  335. * jiffies ? */
  336. unsigned long t_expires;
  337. /* How many handles used this transaction? */
  338. int t_handle_count;
  339. };
  340. /* The journal_t maintains all of the journaling state information for a
  341. * single filesystem. It is linked to from the fs superblock structure.
  342. *
  343. * We use the journal_t to keep track of all outstanding transaction
  344. * activity on the filesystem, and to manage the state of the log
  345. * writing process. */
  346. struct journal_s
  347. {
  348. /* General journaling state flags */
  349. unsigned long j_flags;
  350. /* Is there an outstanding uncleared error on the journal (from
  351. * a prior abort)? */
  352. int j_errno;
  353. /* The superblock buffer */
  354. struct buffer_head * j_sb_buffer;
  355. journal_superblock_t * j_superblock;
  356. /* Version of the superblock format */
  357. int j_format_version;
  358. /* Number of processes waiting to create a barrier lock */
  359. int j_barrier_count;
  360. /* The barrier lock itself */
  361. struct semaphore j_barrier;
  362. /* Transactions: The current running transaction... */
  363. transaction_t * j_running_transaction;
  364. /* ... the transaction we are pushing to disk ... */
  365. transaction_t * j_committing_transaction;
  366. /* ... and a linked circular list of all transactions waiting
  367. * for checkpointing. */
  368. /* Protected by journal_datalist_lock */
  369. transaction_t * j_checkpoint_transactions;
  370. /* Wait queue for waiting for a locked transaction to start
  371. committing, or for a barrier lock to be released */
  372. wait_queue_head_t j_wait_transaction_locked;
  373. /* Wait queue for waiting for checkpointing to complete */
  374. wait_queue_head_t j_wait_logspace;
  375. /* Wait queue for waiting for commit to complete */
  376. wait_queue_head_t j_wait_done_commit;
  377. /* Wait queue to trigger checkpointing */
  378. wait_queue_head_t j_wait_checkpoint;
  379. /* Wait queue to trigger commit */
  380. wait_queue_head_t j_wait_commit;
  381. /* Wait queue to wait for updates to complete */
  382. wait_queue_head_t j_wait_updates;
  383. /* Semaphore for locking against concurrent checkpoints */
  384. struct semaphore j_checkpoint_sem;
  385. /* The main journal lock, used by lock_journal() */
  386. struct semaphore j_sem;
  387. /* Journal head: identifies the first unused block in the journal. */
  388. unsigned long j_head;
  389. /* Journal tail: identifies the oldest still-used block in the
  390. * journal. */
  391. unsigned long j_tail;
  392. /* Journal free: how many free blocks are there in the journal? */
  393. unsigned long j_free;
  394. /* Journal start and end: the block numbers of the first usable
  395. * block and one beyond the last usable block in the journal. */
  396. unsigned long j_first, j_last;
  397. /* Device, blocksize and starting block offset for the location
  398. * where we store the journal. */
  399. kdev_t j_dev;
  400. int j_blocksize;
  401. unsigned int j_blk_offset;
  402. /* Device which holds the client fs. For internal journal this
  403. * will be equal to j_dev. */
  404. kdev_t j_fs_dev;
  405. /* Total maximum capacity of the journal region on disk. */
  406. unsigned int j_maxlen;
  407. /* Optional inode where we store the journal. If present, all
  408. * journal block numbers are mapped into this inode via
  409. * bmap(). */
  410. struct inode * j_inode;
  411. /* Sequence number of the oldest transaction in the log */
  412. tid_t j_tail_sequence;
  413. /* Sequence number of the next transaction to grant */
  414. tid_t j_transaction_sequence;
  415. /* Sequence number of the most recently committed transaction */
  416. tid_t j_commit_sequence;
  417. /* Sequence number of the most recent transaction wanting commit */
  418. tid_t j_commit_request;
  419. /* Journal uuid: identifies the object (filesystem, LVM volume
  420. * etc) backed by this journal. This will eventually be
  421. * replaced by an array of uuids, allowing us to index multiple
  422. * devices within a single journal and to perform atomic updates
  423. * across them. */
  424. __u8 j_uuid[16];
  425. /* Pointer to the current commit thread for this journal */
  426. struct task_struct * j_task;
  427. /* Maximum number of metadata buffers to allow in a single
  428. * compound commit transaction */
  429. int j_max_transaction_buffers;
  430. /* What is the maximum transaction lifetime before we begin a
  431. * commit? */
  432. unsigned long j_commit_interval;
  433. /* The timer used to wakeup the commit thread: */
  434. struct timer_list * j_commit_timer;
  435. int j_commit_timer_active;
  436. /* Link all journals together - system-wide */
  437. struct list_head j_all_journals;
  438. /* The revoke table: maintains the list of revoked blocks in the
  439. current transaction. */
  440. struct jbd_revoke_table_s *j_revoke;
  441. };
  442. /*
  443. * Journal flag definitions
  444. */
  445. #define JFS_UNMOUNT 0x001 /* Journal thread is being destroyed */
  446. #define JFS_ABORT 0x002 /* Journaling has been aborted for errors. */
  447. #define JFS_ACK_ERR 0x004 /* The errno in the sb has been acked */
  448. #define JFS_FLUSHED 0x008 /* The journal superblock has been flushed */
  449. #define JFS_LOADED 0x010 /* The journal superblock has been loaded */
  450. /*
  451. * Function declarations for the journaling transaction and buffer
  452. * management
  453. */
  454. /* Filing buffers */
  455. extern void __journal_unfile_buffer(struct journal_head *);
  456. extern void journal_unfile_buffer(struct journal_head *);
  457. extern void __journal_refile_buffer(struct journal_head *);
  458. extern void journal_refile_buffer(struct journal_head *);
  459. extern void __journal_file_buffer(struct journal_head *, transaction_t *, int);
  460. extern void __journal_free_buffer(struct journal_head *bh);
  461. extern void journal_file_buffer(struct journal_head *, transaction_t *, int);
  462. extern void __journal_clean_data_list(transaction_t *transaction);
  463. /* Log buffer allocation */
  464. extern struct journal_head * journal_get_descriptor_buffer(journal_t *);
  465. extern unsigned long journal_next_log_block(journal_t *);
  466. /* Commit management */
  467. extern void journal_commit_transaction(journal_t *);
  468. /* Checkpoint list management */
  469. int __journal_clean_checkpoint_list(journal_t *journal);
  470. extern void journal_remove_checkpoint(struct journal_head *);
  471. extern void __journal_remove_checkpoint(struct journal_head *);
  472. extern void journal_insert_checkpoint(struct journal_head *, transaction_t *);
  473. extern void __journal_insert_checkpoint(struct journal_head *,transaction_t *);
  474. /* Buffer IO */
  475. extern int
  476. journal_write_metadata_buffer(transaction_t *transaction,
  477. struct journal_head *jh_in,
  478. struct journal_head **jh_out,
  479. int blocknr);
  480. /* Transaction locking */
  481. extern void __wait_on_journal (journal_t *);
  482. /*
  483. * Journal locking.
  484. *
  485. * We need to lock the journal during transaction state changes so that
  486. * nobody ever tries to take a handle on the running transaction while
  487. * we are in the middle of moving it to the commit phase.
  488. *
  489. * Note that the locking is completely interrupt unsafe. We never touch
  490. * journal structures from interrupts.
  491. *
  492. * In 2.2, the BKL was required for lock_journal. This is no longer
  493. * the case.
  494. */
  495. static inline void lock_journal(journal_t *journal)
  496. {
  497. down(&journal->j_sem);
  498. }
  499. /* This returns zero if we acquired the semaphore */
  500. static inline int try_lock_journal(journal_t * journal)
  501. {
  502. return down_trylock(&journal->j_sem);
  503. }
  504. static inline void unlock_journal(journal_t * journal)
  505. {
  506. up(&journal->j_sem);
  507. }
  508. static inline handle_t *journal_current_handle(void)
  509. {
  510. return current->journal_info;
  511. }
  512. /* The journaling code user interface:
  513. *
  514. * Create and destroy handles
  515. * Register buffer modifications against the current transaction.
  516. */
  517. extern handle_t *journal_start(journal_t *, int nblocks);
  518. extern handle_t *journal_try_start(journal_t *, int nblocks);
  519. extern int journal_restart (handle_t *, int nblocks);
  520. extern int journal_extend (handle_t *, int nblocks);
  521. extern int journal_get_write_access (handle_t *, struct buffer_head *);
  522. extern int journal_get_create_access (handle_t *, struct buffer_head *);
  523. extern int journal_get_undo_access (handle_t *, struct buffer_head *);
  524. extern int journal_dirty_data (handle_t *,
  525. struct buffer_head *, int async);
  526. extern int journal_dirty_metadata (handle_t *, struct buffer_head *);
  527. extern void journal_release_buffer (handle_t *, struct buffer_head *);
  528. extern void journal_forget (handle_t *, struct buffer_head *);
  529. extern void journal_sync_buffer (struct buffer_head *);
  530. extern int journal_flushpage(journal_t *, struct page *, unsigned long);
  531. extern int journal_try_to_free_buffers(journal_t *, struct page *, int);
  532. extern int journal_stop(handle_t *);
  533. extern int journal_flush (journal_t *);
  534. extern void journal_lock_updates (journal_t *);
  535. extern void journal_unlock_updates (journal_t *);
  536. extern journal_t * journal_init_dev(kdev_t dev, kdev_t fs_dev,
  537. int start, int len, int bsize);
  538. extern journal_t * journal_init_inode (struct inode *);
  539. extern int journal_update_format (journal_t *);
  540. extern int journal_check_used_features
  541. (journal_t *, unsigned long, unsigned long, unsigned long);
  542. extern int journal_check_available_features
  543. (journal_t *, unsigned long, unsigned long, unsigned long);
  544. extern int journal_set_features
  545. (journal_t *, unsigned long, unsigned long, unsigned long);
  546. extern int journal_create (journal_t *);
  547. extern int journal_load (journal_t *journal);
  548. extern void journal_destroy (journal_t *);
  549. extern int journal_recover (journal_t *journal);
  550. extern int journal_wipe (journal_t *, int);
  551. extern int journal_skip_recovery (journal_t *);
  552. extern void journal_update_superblock (journal_t *, int);
  553. extern void __journal_abort (journal_t *);
  554. extern void journal_abort (journal_t *, int);
  555. extern int journal_errno (journal_t *);
  556. extern void journal_ack_err (journal_t *);
  557. extern int journal_clear_err (journal_t *);
  558. extern unsigned long journal_bmap(journal_t *journal, unsigned long blocknr);
  559. extern int journal_force_commit(journal_t *journal);
  560. /*
  561. * journal_head management
  562. */
  563. extern struct journal_head
  564. *journal_add_journal_head(struct buffer_head *bh);
  565. extern void journal_remove_journal_head(struct buffer_head *bh);
  566. extern void __journal_remove_journal_head(struct buffer_head *bh);
  567. extern void journal_unlock_journal_head(struct journal_head *jh);
  568. /* Primary revoke support */
  569. #define JOURNAL_REVOKE_DEFAULT_HASH 256
  570. extern int journal_init_revoke(journal_t *, int);
  571. extern void journal_destroy_revoke_caches(void);
  572. extern int journal_init_revoke_caches(void);
  573. extern void journal_destroy_revoke(journal_t *);
  574. extern int journal_revoke (handle_t *,
  575. unsigned long, struct buffer_head *);
  576. extern int journal_cancel_revoke(handle_t *, struct journal_head *);
  577. extern void journal_write_revoke_records(journal_t *, transaction_t *);
  578. /* Recovery revoke support */
  579. extern int journal_set_revoke(journal_t *, unsigned long, tid_t);
  580. extern int journal_test_revoke(journal_t *, unsigned long, tid_t);
  581. extern void journal_clear_revoke(journal_t *);
  582. extern void journal_brelse_array(struct buffer_head *b[], int n);
  583. /* The log thread user interface:
  584. *
  585. * Request space in the current transaction, and force transaction commit
  586. * transitions on demand.
  587. */
  588. extern int log_space_left (journal_t *); /* Called with journal locked */
  589. extern tid_t log_start_commit (journal_t *, transaction_t *);
  590. extern void log_wait_commit (journal_t *, tid_t);
  591. extern int log_do_checkpoint (journal_t *, int);
  592. extern void log_wait_for_space(journal_t *, int nblocks);
  593. extern void __journal_drop_transaction(journal_t *, transaction_t *);
  594. extern int cleanup_journal_tail(journal_t *);
  595. /* Reduce journal memory usage by flushing */
  596. extern void shrink_journal_memory(void);
  597. /* Debugging code only: */
  598. #define jbd_ENOSYS() \
  599. do { \
  600. printk (KERN_ERR "JBD unimplemented function " __FUNCTION__); \
  601. current->state = TASK_UNINTERRUPTIBLE; \
  602. schedule(); \
  603. } while (1)
  604. /*
  605. * is_journal_abort
  606. *
  607. * Simple test wrapper function to test the JFS_ABORT state flag. This
  608. * bit, when set, indicates that we have had a fatal error somewhere,
  609. * either inside the journaling layer or indicated to us by the client
  610. * (eg. ext3), and that we and should not commit any further
  611. * transactions.
  612. */
  613. static inline int is_journal_aborted(journal_t *journal)
  614. {
  615. return journal->j_flags & JFS_ABORT;
  616. }
  617. static inline int is_handle_aborted(handle_t *handle)
  618. {
  619. if (handle->h_aborted)
  620. return 1;
  621. return is_journal_aborted(handle->h_transaction->t_journal);
  622. }
  623. static inline void journal_abort_handle(handle_t *handle)
  624. {
  625. handle->h_aborted = 1;
  626. }
  627. /* Not all architectures define BUG() */
  628. #ifndef BUG
  629. #define BUG() do { \
  630. printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
  631. * ((char *) 0) = 0; \
  632. } while (0)
  633. #endif /* BUG */
  634. #else
  635. extern int journal_recover (journal_t *journal);
  636. extern int journal_skip_recovery (journal_t *);
  637. /* Primary revoke support */
  638. extern int journal_init_revoke(journal_t *, int);
  639. extern void journal_destroy_revoke_caches(void);
  640. extern int journal_init_revoke_caches(void);
  641. /* Recovery revoke support */
  642. extern int journal_set_revoke(journal_t *, unsigned long, tid_t);
  643. extern int journal_test_revoke(journal_t *, unsigned long, tid_t);
  644. extern void journal_clear_revoke(journal_t *);
  645. extern void journal_brelse_array(struct buffer_head *b[], int n);
  646. extern void journal_destroy_revoke(journal_t *);
  647. #endif /* __KERNEL__ */
  648. /* Comparison functions for transaction IDs: perform comparisons using
  649. * modulo arithmetic so that they work over sequence number wraps. */
  650. static inline int tid_gt(tid_t x, tid_t y)
  651. {
  652. int difference = (x - y);
  653. return (difference > 0);
  654. }
  655. static inline int tid_geq(tid_t x, tid_t y)
  656. {
  657. int difference = (x - y);
  658. return (difference >= 0);
  659. }
  660. extern int journal_blocks_per_page(struct inode *inode);
  661. /*
  662. * Definitions which augment the buffer_head layer
  663. */
  664. /* journaling buffer types */
  665. #define BJ_None 0 /* Not journaled */
  666. #define BJ_SyncData 1 /* Normal data: flush before commit */
  667. #define BJ_AsyncData 2 /* writepage data: wait on it before commit */
  668. #define BJ_Metadata 3 /* Normal journaled metadata */
  669. #define BJ_Forget 4 /* Buffer superceded by this transaction */
  670. #define BJ_IO 5 /* Buffer is for temporary IO use */
  671. #define BJ_Shadow 6 /* Buffer contents being shadowed to the log */
  672. #define BJ_LogCtl 7 /* Buffer contains log descriptors */
  673. #define BJ_Reserved 8 /* Buffer is reserved for access by journal */
  674. #define BJ_Types 9
  675. extern int jbd_blocks_per_page(struct inode *inode);
  676. #ifdef __KERNEL__
  677. extern spinlock_t jh_splice_lock;
  678. /*
  679. * Once `expr1' has been found true, take jh_splice_lock
  680. * and then reevaluate everything.
  681. */
  682. #define SPLICE_LOCK(expr1, expr2) \
  683. ({ \
  684. int ret = (expr1); \
  685. if (ret) { \
  686. spin_lock(&jh_splice_lock); \
  687. ret = (expr1) && (expr2); \
  688. spin_unlock(&jh_splice_lock); \
  689. } \
  690. ret; \
  691. })
  692. /*
  693. * A number of buffer state predicates. They test for
  694. * buffer_jbd() because they are used in core kernel code.
  695. *
  696. * These will be racy on SMP unless we're *sure* that the
  697. * buffer won't be detached from the journalling system
  698. * in parallel.
  699. */
  700. /* Return true if the buffer is on journal list `list' */
  701. static inline int buffer_jlist_eq(struct buffer_head *bh, int list)
  702. {
  703. return SPLICE_LOCK(buffer_jbd(bh), bh2jh(bh)->b_jlist == list);
  704. }
  705. /* Return true if this bufer is dirty wrt the journal */
  706. static inline int buffer_jdirty(struct buffer_head *bh)
  707. {
  708. return buffer_jbd(bh) && __buffer_state(bh, JBDDirty);
  709. }
  710. /* Return true if it's a data buffer which journalling is managing */
  711. static inline int buffer_jbd_data(struct buffer_head *bh)
  712. {
  713. return SPLICE_LOCK(buffer_jbd(bh),
  714. bh2jh(bh)->b_jlist == BJ_SyncData ||
  715. bh2jh(bh)->b_jlist == BJ_AsyncData);
  716. }
  717. #ifdef CONFIG_SMP
  718. #define assert_spin_locked(lock) J_ASSERT(spin_is_locked(lock))
  719. #else
  720. #define assert_spin_locked(lock) do {} while(0)
  721. #endif
  722. #define buffer_trace_init(bh) do {} while (0)
  723. #define print_buffer_fields(bh) do {} while (0)
  724. #define print_buffer_trace(bh) do {} while (0)
  725. #define BUFFER_TRACE(bh, info) do {} while (0)
  726. #define BUFFER_TRACE2(bh, bh2, info) do {} while (0)
  727. #define JBUFFER_TRACE(jh, info) do {} while (0)
  728. #endif /* __KERNEL__ */
  729. #endif /* CONFIG_JBD || CONFIG_JBD_MODULE || !__KERNEL__ */
  730. /*
  731. * Compatibility no-ops which allow the kernel to compile without CONFIG_JBD
  732. * go here.
  733. */
  734. #if defined(__KERNEL__) && !(defined(CONFIG_JBD) || defined(CONFIG_JBD_MODULE))
  735. #define J_ASSERT(expr) do {} while (0)
  736. #define J_ASSERT_BH(bh, expr) do {} while (0)
  737. #define buffer_jbd(bh) 0
  738. #define buffer_jlist_eq(bh, val) 0
  739. #define journal_buffer_journal_lru(bh) 0
  740. #endif /* defined(__KERNEL__) && !defined(CONFIG_JBD) */
  741. #endif /* _LINUX_JBD_H */