1 #ifndef _BCACHE_JOURNAL_TYPES_H
2 #define _BCACHE_JOURNAL_TYPES_H
4 #include <linux/cache.h>
5 #include <linux/workqueue.h>
7 #include "alloc_types.h"
13 * We put two of these in struct journal; we used them for writes to the
14 * journal that are being staged or in flight.
19 struct closure_waitlist wait;
22 unsigned disk_sectors;
25 * ugh, prio_buckets are stupid - need to convert them to new
26 * transaction machinery when it arrives
28 unsigned nr_prio_buckets;
31 unsigned long has_inode[1024 / sizeof(unsigned long)];
35 * Something that makes a journal entry dirty - i.e. a btree node that has to be
39 struct journal_entry_pin_list {
40 struct list_head list;
45 struct journal_entry_pin;
46 typedef void (*journal_pin_flush_fn)(struct journal *j,
47 struct journal_entry_pin *, u64);
49 struct journal_entry_pin {
50 struct list_head list;
51 journal_pin_flush_fn flush;
52 struct journal_entry_pin_list *pin_list;
55 /* corresponds to a btree node with a blacklisted bset: */
56 struct blacklisted_node {
58 enum btree_id btree_id;
62 struct journal_seq_blacklist {
63 struct list_head list;
66 struct journal_entry_pin pin;
68 struct blacklisted_node *entries;
80 union journal_res_state {
90 u64 cur_entry_offset:20,
99 #define JOURNAL_ENTRY_SIZE_MIN (64U << 10) /* 64k */
100 #define JOURNAL_ENTRY_SIZE_MAX (4U << 20) /* 4M */
103 * We stash some journal state as sentinal values in cur_entry_offset:
104 * note - cur_entry_offset is in units of u64s
106 #define JOURNAL_ENTRY_OFFSET_MAX ((1U << 20) - 1)
108 #define JOURNAL_ENTRY_CLOSED_VAL (JOURNAL_ENTRY_OFFSET_MAX - 1)
109 #define JOURNAL_ENTRY_ERROR_VAL (JOURNAL_ENTRY_OFFSET_MAX)
112 * JOURNAL_NEED_WRITE - current (pending) journal entry should be written ASAP,
113 * either because something's waiting on the write to complete or because it's
114 * 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;
147 struct delayed_work write_work;
149 /* Sequence number of most recent journal entry (last entry in @pin) */
152 /* last_seq from the most recent journal entry written */
156 * FIFO of journal entries whose btree updates have not yet been
159 * Each entry is a reference count. The position in the FIFO is the
160 * entry's sequence number relative to @seq.
162 * The journal entry itself holds a reference count, put when the
163 * journal entry is written out. Each btree node modified by the journal
164 * entry also holds a reference count, put when the btree node is
167 * When a reference count reaches zero, the journal entry is no longer
168 * needed. When all journal entries in the oldest journal bucket are no
169 * longer needed, the bucket can be discarded and reused.
171 DECLARE_FIFO(struct journal_entry_pin_list, pin);
172 struct journal_entry_pin_list *replay_pin_list;
175 * Protects the pin lists - the fifo itself is still protected by
180 struct mutex blacklist_lock;
181 struct list_head seq_blacklist;
184 struct dev_group devs;
186 struct delayed_work reclaim_work;
187 unsigned long last_flushed;
189 /* protects advancing ja->last_idx: */
190 struct mutex reclaim_lock;
193 * ugh: need to get prio_buckets converted over to the eventual new
194 * transaction machinery
196 __le64 prio_buckets[BCH_SB_MEMBERS_MAX];
197 unsigned nr_prio_buckets;
199 unsigned write_delay_ms;
200 unsigned reclaim_delay_ms;
202 u64 res_get_blocked_start;
204 u64 write_start_time;
206 struct time_stats *write_time;
207 struct time_stats *delay_time;
208 struct time_stats *blocked_time;
209 struct time_stats *flush_seq_time;
211 #ifdef CONFIG_DEBUG_LOCK_ALLOC
212 struct lockdep_map res_map;
217 * Embedded in struct bch_dev. First three fields refer to the array of journal
218 * buckets, in bch_sb.
220 struct journal_device {
222 * For each journal bucket, contains the max sequence number of the
223 * journal writes it contains - so we know when a bucket can be reused.
227 unsigned sectors_free;
229 /* Journal bucket we're currently writing to */
232 /* Last journal bucket that still contains an open journal entry */
235 * j->lock and j->reclaim_lock must both be held to modify, j->lock
236 * sufficient to read:
242 /* Bio for journal reads/writes to this device */
245 /* for bch_journal_read_device */
249 #endif /* _BCACHE_JOURNAL_TYPES_H */