1 #ifndef _BCACHEFS_JOURNAL_TYPES_H
2 #define _BCACHEFS_JOURNAL_TYPES_H
4 #include <linux/cache.h>
5 #include <linux/workqueue.h>
7 #include "alloc_types.h"
8 #include "super_types.h"
14 * We put two of these in struct journal; we used them for writes to the
15 * journal that are being staged or in flight.
20 struct closure_waitlist wait;
23 unsigned disk_sectors;
25 unsigned long has_inode[1024 / sizeof(unsigned long)];
29 * Something that makes a journal entry dirty - i.e. a btree node that has to be
33 struct journal_entry_pin_list {
34 struct list_head list;
35 struct list_head flushed;
40 struct journal_entry_pin;
41 typedef void (*journal_pin_flush_fn)(struct journal *j,
42 struct journal_entry_pin *, u64);
44 struct journal_entry_pin {
45 struct list_head list;
46 journal_pin_flush_fn flush;
47 struct journal_entry_pin_list *pin_list;
50 /* corresponds to a btree node with a blacklisted bset: */
51 struct blacklisted_node {
53 enum btree_id btree_id;
57 struct journal_seq_blacklist {
58 struct list_head list;
61 struct journal_entry_pin pin;
63 struct blacklisted_node *entries;
75 union journal_res_state {
85 u64 cur_entry_offset:20,
94 #define JOURNAL_ENTRY_SIZE_MIN (64U << 10) /* 64k */
95 #define JOURNAL_ENTRY_SIZE_MAX (4U << 20) /* 4M */
98 * We stash some journal state as sentinal values in cur_entry_offset:
99 * note - cur_entry_offset is in units of u64s
101 #define JOURNAL_ENTRY_OFFSET_MAX ((1U << 20) - 1)
103 #define JOURNAL_ENTRY_CLOSED_VAL (JOURNAL_ENTRY_OFFSET_MAX - 1)
104 #define JOURNAL_ENTRY_ERROR_VAL (JOURNAL_ENTRY_OFFSET_MAX)
107 * JOURNAL_NEED_WRITE - current (pending) journal entry should be written ASAP,
108 * either because something's waiting on the write to complete or because it's
109 * been dirty too long and the timer's expired.
118 /* Embedded in struct bch_fs */
120 /* Fastpath stuff up front: */
124 union journal_res_state reservations;
125 unsigned cur_entry_u64s;
126 unsigned prev_buf_sectors;
127 unsigned cur_buf_sectors;
128 unsigned buf_size_want;
131 * Two journal entries -- one is currently open for new entries, the
132 * other is possibly being written out.
134 struct journal_buf buf[2];
138 /* Used when waiting because the journal was full */
139 wait_queue_head_t wait;
142 struct delayed_work write_work;
143 unsigned long replicas_failed;
145 /* Sequence number of most recent journal entry (last entry in @pin) */
148 /* last_seq from the most recent journal entry written */
152 * FIFO of journal entries whose btree updates have not yet been
155 * Each entry is a reference count. The position in the FIFO is the
156 * entry's sequence number relative to @seq.
158 * The journal entry itself holds a reference count, put when the
159 * journal entry is written out. Each btree node modified by the journal
160 * entry also holds a reference count, put when the btree node is
163 * When a reference count reaches zero, the journal entry is no longer
164 * needed. When all journal entries in the oldest journal bucket are no
165 * longer needed, the bucket can be discarded and reused.
167 DECLARE_FIFO(struct journal_entry_pin_list, pin);
168 struct journal_entry_pin_list *replay_pin_list;
171 * Protects the pin lists - the fifo itself is still protected by
176 struct mutex blacklist_lock;
177 struct list_head seq_blacklist;
180 struct write_point wp;
182 struct delayed_work reclaim_work;
183 unsigned long last_flushed;
185 /* protects advancing ja->last_idx: */
186 struct mutex reclaim_lock;
187 unsigned write_delay_ms;
188 unsigned reclaim_delay_ms;
190 u64 res_get_blocked_start;
192 u64 write_start_time;
194 struct time_stats *write_time;
195 struct time_stats *delay_time;
196 struct time_stats *blocked_time;
197 struct time_stats *flush_seq_time;
199 #ifdef CONFIG_DEBUG_LOCK_ALLOC
200 struct lockdep_map res_map;
205 * Embedded in struct bch_dev. First three fields refer to the array of journal
206 * buckets, in bch_sb.
208 struct journal_device {
210 * For each journal bucket, contains the max sequence number of the
211 * journal writes it contains - so we know when a bucket can be reused.
215 unsigned sectors_free;
217 /* Journal bucket we're currently writing to */
220 /* Last journal bucket that still contains an open journal entry */
223 * j->lock and j->reclaim_lock must both be held to modify, j->lock
224 * sufficient to read:
230 /* Bio for journal reads/writes to this device */
234 /* for bch_journal_read_device */
238 #endif /* _BCACHEFS_JOURNAL_TYPES_H */