21 #include "jfs_compat.h"
23 #define jfs_debug jbd_debug
26 #include <linux/types.h>
29 #include <linux/stddef.h>
33 #include <linux/slab.h>
37 #define journal_oom_retry 1
46 #undef JBD2_PARANOID_IOFAIL
51 #define JBD2_DEFAULT_MAX_COMMIT_AGE 5
53 #ifdef CONFIG_JBD2_DEBUG
59 #define JBD2_EXPENSIVE_CHECKING
60 extern u8 jbd2_journal_enable_debug;
62 #define jbd_debug(n, f, a...) \
64 if ((n) <= jbd2_journal_enable_debug) { \
65 printk (KERN_DEBUG "(%s, %d): %s: ", \
66 __FILE__, __LINE__, __func__); \
71 #define jbd_debug(f, a...)
77 #define JBD2_MIN_JOURNAL_BLOCKS 1024
98 typedef struct jbd2_journal_handle handle_t;
112 typedef struct journal_s journal_t;
119 #define JBD2_MAGIC_NUMBER 0xc03b3998U
129 #define JBD2_DESCRIPTOR_BLOCK 1
130 #define JBD2_COMMIT_BLOCK 2
131 #define JBD2_SUPERBLOCK_V1 3
132 #define JBD2_SUPERBLOCK_V2 4
133 #define JBD2_REVOKE_BLOCK 5
148 #define JBD2_CRC32_CHKSUM 1
149 #define JBD2_MD5_CHKSUM 2
150 #define JBD2_SHA1_CHKSUM 3
151 #define JBD2_CRC32C_CHKSUM 4
153 #define JBD2_CRC32_CHKSUM_SIZE 4
155 #define JBD2_CHECKSUM_BYTES (32 / sizeof(u32))
196 #define JBD2_TAG_SIZE32 (offsetof(journal_block_tag_t, t_blocknr_high))
197 #define JBD2_TAG_SIZE64 (sizeof(journal_block_tag_t))
220 #define JBD2_FLAG_ESCAPE 1
221 #define JBD2_FLAG_SAME_UUID 2
222 #define JBD2_FLAG_DELETED 4
223 #define JBD2_FLAG_LAST_TAG 8
277 #define JBD2_HAS_COMPAT_FEATURE(j,mask) \
278 ((j)->j_format_version >= 2 && \
279 ((j)->j_superblock->s_feature_compat & cpu_to_be32((mask))))
280 #define JBD2_HAS_RO_COMPAT_FEATURE(j,mask) \
281 ((j)->j_format_version >= 2 && \
282 ((j)->j_superblock->s_feature_ro_compat & cpu_to_be32((mask))))
283 #define JBD2_HAS_INCOMPAT_FEATURE(j,mask) \
284 ((j)->j_format_version >= 2 && \
285 ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask))))
287 #define JBD2_FEATURE_COMPAT_CHECKSUM 0x00000001
289 #define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001
290 #define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002
291 #define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004
292 #define JBD2_FEATURE_INCOMPAT_CSUM_V2 0x00000008
295 #define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM
296 #define JBD2_KNOWN_ROCOMPAT_FEATURES 0
297 #define JBD2_KNOWN_INCOMPAT_FEATURES (JBD2_FEATURE_INCOMPAT_REVOKE | \
298 JBD2_FEATURE_INCOMPAT_64BIT | \
299 JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT | \
300 JBD2_FEATURE_INCOMPAT_CSUM_V2)
304 #include <linux/fs.h>
305 #include <linux/sched.h>
308 #define J_ASSERT(assert) BUG_ON(!(assert))
310 #define J_ASSERT_BH(bh, expr) J_ASSERT(expr)
311 #define J_ASSERT_JH(jh, expr) J_ASSERT(expr)
313 #if defined(JBD2_PARANOID_IOFAIL)
314 #define J_EXPECT(expr, why...) J_ASSERT(expr)
315 #define J_EXPECT_BH(bh, expr, why...) J_ASSERT_BH(bh, expr)
316 #define J_EXPECT_JH(jh, expr, why...) J_ASSERT_JH(jh, expr)
318 #define __journal_expect(expr, why...) \
323 "JBD2 unexpected failure: %s: %s;\n", \
325 printk(KERN_ERR why "\n"); \
329 #define J_EXPECT(expr, why...) __journal_expect(expr, ## why)
330 #define J_EXPECT_BH(bh, expr, why...) __journal_expect(expr, ## why)
331 #define J_EXPECT_JH(jh, expr, why...) __journal_expect(expr, ## why)
335 #define __JI_COMMIT_RUNNING 0
340 #define JI_COMMIT_RUNNING (1 << __JI_COMMIT_RUNNING)
360 struct inode *i_vfs_inode;
384 struct jbd2_journal_handle
390 int h_buffer_credits;
400 unsigned int h_sync:1;
401 unsigned int h_jdata:1;
402 unsigned int h_aborted:1;
403 unsigned int h_cowing:1;
407 unsigned int h_base_credits:14;
411 unsigned int h_user_credits:14;
414 #ifdef CONFIG_DEBUG_LOCK_ALLOC
415 struct lockdep_map h_lockdep_map;
418 #ifdef CONFIG_JBD2_DEBUG
420 unsigned int h_cow_moved;
421 unsigned int h_cow_copied;
422 unsigned int h_cow_ok_jh;
424 unsigned int h_cow_ok_bitmap;
425 unsigned int h_cow_ok_mapped;
426 unsigned int h_cow_bitmaps;
427 unsigned int h_cow_excluded;
435 struct transaction_chp_stats_s {
436 unsigned long cs_chp_time;
437 __u32 cs_forced_to_close;
481 journal_t *t_journal;
507 unsigned long t_log_start;
576 unsigned long t_max_wait;
581 unsigned long t_start;
586 struct transaction_chp_stats_s t_chp_stats;
610 unsigned long t_expires;
626 unsigned int t_synchronous_commit:1;
629 int t_need_data_flush;
638 struct transaction_run_stats_s {
639 unsigned long rs_wait;
640 unsigned long rs_running;
641 unsigned long rs_locked;
642 unsigned long rs_flushing;
643 unsigned long rs_logging;
645 __u32 rs_handle_count;
647 __u32 rs_blocks_logged;
650 struct transaction_stats_s {
651 unsigned long ts_tid;
652 struct transaction_run_stats_s
run;
655 static inline unsigned long
656 jbd2_time_diff(
unsigned long start,
unsigned long end)
664 #define JBD2_NR_BATCH 64
739 unsigned long j_flags;
748 struct buffer_head *j_sb_buffer;
752 int j_format_version;
765 struct mutex j_barrier;
807 struct mutex j_checkpoint_mutex;
815 struct buffer_head *j_chkpt_bhs[JBD2_NR_BATCH];
821 unsigned long j_head;
827 unsigned long j_tail;
833 unsigned long j_free;
839 unsigned long j_first;
840 unsigned long j_last;
848 unsigned long long j_blk_offset;
858 unsigned int j_maxlen;
868 struct inode *j_inode;
873 tid_t j_tail_sequence;
878 tid_t j_transaction_sequence;
884 tid_t j_commit_sequence;
890 tid_t j_commit_request;
907 int j_max_transaction_buffers;
912 unsigned long j_commit_interval;
928 struct buffer_head **j_wbuf;
935 pid_t j_last_sync_writer;
941 u64 j_average_commit_time;
948 u32 j_min_batch_time;
949 u32 j_max_batch_time;
952 void (*j_commit_callback)(journal_t *,
960 struct transaction_stats_s j_stats;
963 unsigned int j_failed_commit;
981 #define JBD2_UNMOUNT 0x001
982 #define JBD2_ABORT 0x002
983 #define JBD2_ACK_ERR 0x004
984 #define JBD2_FLUSHED 0x008
985 #define JBD2_LOADED 0x010
986 #define JBD2_BARRIER 0x020
987 #define JBD2_ABORT_ON_SYNCDATA_ERR 0x040
1001 extern void __journal_free_buffer(
struct journal_head *bh);
1009 unsigned long *
block);
1026 struct jbd2_buffer_trigger_type {
1033 void (*t_frozen)(
struct jbd2_buffer_trigger_type *
type,
1034 struct buffer_head *bh,
void *mapped_data,
1041 void (*t_abort)(
struct jbd2_buffer_trigger_type *
type,
1042 struct buffer_head *bh);
1047 struct jbd2_buffer_trigger_type *triggers);
1049 struct jbd2_buffer_trigger_type *triggers);
1059 extern void __wait_on_journal (journal_t *);
1077 static inline handle_t *journal_current_handle(
void)
1097 struct jbd2_buffer_trigger_type *
type);
1101 extern void journal_sync_buffer (
struct buffer_head *);
1103 struct page *,
unsigned long);
1112 unsigned long long start,
int len,
int bsize);
1114 extern int jbd2_journal_update_format (journal_t *);
1116 (journal_t *,
unsigned long,
unsigned long,
unsigned long);
1118 (journal_t *,
unsigned long,
unsigned long,
unsigned long);
1120 (journal_t *,
unsigned long,
unsigned long,
unsigned long);
1122 (journal_t *,
unsigned long,
unsigned long,
unsigned long);
1130 unsigned long,
int);
1140 struct jbd2_inode *
inode, loff_t new_size);
1156 static inline handle_t *jbd2_alloc_handle(
gfp_t gfp_flags)
1161 static inline void jbd2_free_handle(handle_t *
handle)
1172 static inline struct jbd2_inode *jbd2_alloc_inode(
gfp_t gfp_flags)
1177 static inline void jbd2_free_inode(
struct jbd2_inode *jinode)
1183 #define JOURNAL_REVOKE_DEFAULT_HASH 256
1189 extern int jbd2_journal_revoke (handle_t *,
unsigned long long,
struct buffer_head *);
1190 extern int jbd2_journal_cancel_revoke(handle_t *,
struct journal_head *);
1191 extern void jbd2_journal_write_revoke_records(journal_t *,
1198 extern void jbd2_journal_switch_revoke_table(journal_t *journal);
1199 extern void jbd2_clear_buffer_revoked_flags(journal_t *journal);
1223 #define jbd_ENOSYS() \
1225 printk (KERN_ERR "JBD unimplemented function %s\n", __func__); \
1226 current->state = TASK_UNINTERRUPTIBLE; \
1240 static inline int is_journal_aborted(journal_t *journal)
1242 return journal->j_flags & JBD2_ABORT;
1245 static inline int is_handle_aborted(handle_t *
handle)
1247 if (handle->h_aborted)
1249 return is_journal_aborted(handle->h_transaction->t_journal);
1252 static inline void jbd2_journal_abort_handle(handle_t *handle)
1254 handle->h_aborted = 1;
1264 int difference = (x -
y);
1265 return (difference > 0);
1270 int difference = (x -
y);
1271 return (difference >= 0);
1281 static inline int jbd_space_needed(journal_t *journal)
1283 int nblocks = journal->j_max_transaction_buffers;
1284 if (journal->j_committing_transaction)
1285 nblocks +=
atomic_read(&journal->j_committing_transaction->
1286 t_outstanding_credits);
1296 #define BJ_Metadata 1
1301 #define BJ_Reserved 6
1306 static inline u32 jbd2_chksum(journal_t *journal,
u32 crc,
1311 char ctx[crypto_shash_descsize(journal->j_chksum_driver)];
1315 desc.shash.tfm = journal->j_chksum_driver;
1327 #define buffer_trace_init(bh) do {} while (0)
1328 #define print_buffer_fields(bh) do {} while (0)
1329 #define print_buffer_trace(bh) do {} while (0)
1330 #define BUFFER_TRACE(bh, info) do {} while (0)
1331 #define BUFFER_TRACE2(bh, bh2, info) do {} while (0)
1332 #define JBUFFER_TRACE(jh, info) do {} while (0)