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.
22 struct closure_waitlist wait;
25 unsigned disk_sectors;
27 unsigned long has_inode[1024 / sizeof(unsigned long)];
31 * Something that makes a journal entry dirty - i.e. a btree node that has to be
35 struct journal_entry_pin_list {
36 struct list_head list;
37 struct list_head flushed;
39 struct bch_devs_list devs;
43 struct journal_entry_pin;
44 typedef void (*journal_pin_flush_fn)(struct journal *j,
45 struct journal_entry_pin *, u64);
47 struct journal_entry_pin {
48 struct list_head list;
49 journal_pin_flush_fn flush;
53 /* corresponds to a btree node with a blacklisted bset: */
54 struct blacklisted_node {
56 enum btree_id btree_id;
60 struct journal_seq_blacklist {
61 struct list_head list;
65 struct journal_entry_pin pin;
67 struct blacklisted_node *entries;
79 union journal_res_state {
89 u64 cur_entry_offset:20,
98 #define JOURNAL_ENTRY_SIZE_MIN (64U << 10) /* 64k */
99 #define JOURNAL_ENTRY_SIZE_MAX (4U << 20) /* 4M */
102 * We stash some journal state as sentinal values in cur_entry_offset:
103 * note - cur_entry_offset is in units of u64s
105 #define JOURNAL_ENTRY_OFFSET_MAX ((1U << 20) - 1)
107 #define JOURNAL_ENTRY_CLOSED_VAL (JOURNAL_ENTRY_OFFSET_MAX - 1)
108 #define JOURNAL_ENTRY_ERROR_VAL (JOURNAL_ENTRY_OFFSET_MAX)
111 * JOURNAL_NEED_WRITE - current (pending) journal entry should be written ASAP,
112 * either because something's waiting on the write to complete or because it's
113 * been dirty too long and the timer's expired.
123 /* Embedded in struct bch_fs */
125 /* Fastpath stuff up front: */
129 union journal_res_state reservations;
130 unsigned cur_entry_u64s;
131 unsigned prev_buf_sectors;
132 unsigned cur_buf_sectors;
133 unsigned buf_size_want;
136 * Two journal entries -- one is currently open for new entries, the
137 * other is possibly being written out.
139 struct journal_buf buf[2];
143 /* Used when waiting because the journal was full */
144 wait_queue_head_t wait;
145 struct closure_waitlist async_wait;
148 struct delayed_work write_work;
150 /* Sequence number of most recent journal entry (last entry in @pin) */
153 /* seq, last_seq from the most recent journal entry successfully written */
158 * FIFO of journal entries whose btree updates have not yet been
161 * Each entry is a reference count. The position in the FIFO is the
162 * entry's sequence number relative to @seq.
164 * The journal entry itself holds a reference count, put when the
165 * journal entry is written out. Each btree node modified by the journal
166 * entry also holds a reference count, put when the btree node is
169 * When a reference count reaches zero, the journal entry is no longer
170 * needed. When all journal entries in the oldest journal bucket are no
171 * longer needed, the bucket can be discarded and reused.
174 u64 front, back, size, mask;
175 struct journal_entry_pin_list *data;
178 struct journal_entry_pin *flush_in_progress;
179 wait_queue_head_t pin_flush_wait;
181 u64 replay_journal_seq;
183 struct mutex blacklist_lock;
184 struct list_head seq_blacklist;
185 struct journal_seq_blacklist *new_blacklist;
187 struct write_point wp;
190 struct delayed_work reclaim_work;
191 unsigned long last_flushed;
193 /* protects advancing ja->last_idx: */
194 struct mutex reclaim_lock;
195 unsigned write_delay_ms;
196 unsigned reclaim_delay_ms;
198 u64 res_get_blocked_start;
200 u64 write_start_time;
202 struct time_stats *write_time;
203 struct time_stats *delay_time;
204 struct time_stats *blocked_time;
205 struct time_stats *flush_seq_time;
207 #ifdef CONFIG_DEBUG_LOCK_ALLOC
208 struct lockdep_map res_map;
213 * Embedded in struct bch_dev. First three fields refer to the array of journal
214 * buckets, in bch_sb.
216 struct journal_device {
218 * For each journal bucket, contains the max sequence number of the
219 * journal writes it contains - so we know when a bucket can be reused.
223 unsigned sectors_free;
225 /* Journal bucket we're currently writing to */
228 /* Last journal bucket that still contains an open journal entry */
231 * j->lock and j->reclaim_lock must both be held to modify, j->lock
232 * sufficient to read:
238 /* Bio for journal reads/writes to this device */
241 /* for bch_journal_read_device */
245 #endif /* _BCACHEFS_JOURNAL_TYPES_H */