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.
18 struct closure_waitlist wait;
21 * ugh, prio_buckets are stupid - need to convert them to new
22 * transaction machinery when it arrives
24 unsigned nr_prio_buckets;
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;
41 struct journal_entry_pin;
42 typedef void (*journal_pin_flush_fn)(struct journal *j, struct journal_entry_pin *);
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_MAX (4U << 20)
97 * We stash some journal state as sentinal values in cur_entry_offset:
99 #define JOURNAL_ENTRY_OFFSET_MAX ((1U << 20) - 1)
101 #define JOURNAL_ENTRY_CLOSED_VAL (JOURNAL_ENTRY_OFFSET_MAX - 1)
102 #define JOURNAL_ENTRY_ERROR_VAL (JOURNAL_ENTRY_OFFSET_MAX)
105 * JOURNAL_NEED_WRITE - current (pending) journal entry should be written ASAP,
106 * either because something's waiting on the write to complete or because it's
107 * been dirty too long and the timer's expired.
116 /* Embedded in struct cache_set */
118 /* Fastpath stuff up front: */
122 union journal_res_state reservations;
123 unsigned cur_entry_u64s;
124 unsigned prev_buf_sectors;
125 unsigned cur_buf_sectors;
126 unsigned entry_size_max; /* bytes */
129 * Two journal entries -- one is currently open for new entries, the
130 * other is possibly being written out.
132 struct journal_buf buf[2];
136 /* Used when waiting because the journal was full */
137 wait_queue_head_t wait;
140 struct delayed_work write_work;
142 /* Sequence number of most recent journal entry (last entry in @pin) */
145 /* last_seq from the most recent journal entry written */
149 * FIFO of journal entries whose btree updates have not yet been
152 * Each entry is a reference count. The position in the FIFO is the
153 * entry's sequence number relative to @seq.
155 * The journal entry itself holds a reference count, put when the
156 * journal entry is written out. Each btree node modified by the journal
157 * entry also holds a reference count, put when the btree node is
160 * When a reference count reaches zero, the journal entry is no longer
161 * needed. When all journal entries in the oldest journal bucket are no
162 * longer needed, the bucket can be discarded and reused.
164 DECLARE_FIFO(struct journal_entry_pin_list, pin);
165 struct journal_entry_pin_list *cur_pin_list;
168 * Protects the pin lists - the fifo itself is still protected by
173 struct mutex blacklist_lock;
174 struct list_head seq_blacklist;
177 struct cache_group devs;
179 struct delayed_work reclaim_work;
180 unsigned long last_flushed;
182 /* protects advancing ja->last_idx: */
183 struct mutex reclaim_lock;
186 * ugh: need to get prio_buckets converted over to the eventual new
187 * transaction machinery
189 __le64 prio_buckets[MAX_CACHES_PER_SET];
190 unsigned nr_prio_buckets;
192 unsigned write_delay_ms;
193 unsigned reclaim_delay_ms;
195 u64 res_get_blocked_start;
197 u64 write_start_time;
199 struct time_stats *write_time;
200 struct time_stats *delay_time;
201 struct time_stats *blocked_time;
202 struct time_stats *flush_seq_time;
204 #ifdef CONFIG_DEBUG_LOCK_ALLOC
205 struct lockdep_map res_map;
210 * Embedded in struct cache. First three fields refer to the array of journal
211 * buckets, in cache_sb.
213 struct journal_device {
215 * For each journal bucket, contains the max sequence number of the
216 * journal writes it contains - so we know when a bucket can be reused.
220 unsigned sectors_free;
222 /* Journal bucket we're currently writing to */
225 /* Last journal bucket that still contains an open journal entry */
228 * j->lock and j->reclaim_lock must both be held to modify, j->lock
229 * sufficient to read:
233 /* Bio for journal reads/writes to this device */
236 /* for bch_journal_read_device */
240 #endif /* _BCACHE_JOURNAL_TYPES_H */