blob: fb1bfafa21e43b975fabc7334553c13fe9407a01 [file] [log] [blame]
Kent Overstreetcafe5632013-03-23 16:11:31 -07001/*
2 * bcache journalling code, for btree insertions
3 *
4 * Copyright 2012 Google, Inc.
5 */
6
7#include "bcache.h"
8#include "btree.h"
9#include "debug.h"
10#include "request.h"
11
12/*
13 * Journal replay/recovery:
14 *
15 * This code is all driven from run_cache_set(); we first read the journal
16 * entries, do some other stuff, then we mark all the keys in the journal
17 * entries (same as garbage collection would), then we replay them - reinserting
18 * them into the cache in precisely the same order as they appear in the
19 * journal.
20 *
21 * We only journal keys that go in leaf nodes, which simplifies things quite a
22 * bit.
23 */
24
25static void journal_read_endio(struct bio *bio, int error)
26{
27 struct closure *cl = bio->bi_private;
28 closure_put(cl);
29}
30
31static int journal_read_bucket(struct cache *ca, struct list_head *list,
32 struct btree_op *op, unsigned bucket_index)
33{
34 struct journal_device *ja = &ca->journal;
35 struct bio *bio = &ja->bio;
36
37 struct journal_replay *i;
38 struct jset *j, *data = ca->set->journal.w[0].data;
39 unsigned len, left, offset = 0;
40 int ret = 0;
41 sector_t bucket = bucket_to_sector(ca->set, ca->sb.d[bucket_index]);
42
43 pr_debug("reading %llu", (uint64_t) bucket);
44
45 while (offset < ca->sb.bucket_size) {
46reread: left = ca->sb.bucket_size - offset;
47 len = min_t(unsigned, left, PAGE_SECTORS * 8);
48
49 bio_reset(bio);
50 bio->bi_sector = bucket + offset;
51 bio->bi_bdev = ca->bdev;
52 bio->bi_rw = READ;
53 bio->bi_size = len << 9;
54
55 bio->bi_end_io = journal_read_endio;
56 bio->bi_private = &op->cl;
Kent Overstreet169ef1c2013-03-28 12:50:55 -060057 bch_bio_map(bio, data);
Kent Overstreetcafe5632013-03-23 16:11:31 -070058
59 closure_bio_submit(bio, &op->cl, ca);
60 closure_sync(&op->cl);
61
62 /* This function could be simpler now since we no longer write
63 * journal entries that overlap bucket boundaries; this means
64 * the start of a bucket will always have a valid journal entry
65 * if it has any journal entries at all.
66 */
67
68 j = data;
69 while (len) {
70 struct list_head *where;
71 size_t blocks, bytes = set_bytes(j);
72
73 if (j->magic != jset_magic(ca->set))
74 return ret;
75
76 if (bytes > left << 9)
77 return ret;
78
79 if (bytes > len << 9)
80 goto reread;
81
82 if (j->csum != csum_set(j))
83 return ret;
84
85 blocks = set_blocks(j, ca->set);
86
87 while (!list_empty(list)) {
88 i = list_first_entry(list,
89 struct journal_replay, list);
90 if (i->j.seq >= j->last_seq)
91 break;
92 list_del(&i->list);
93 kfree(i);
94 }
95
96 list_for_each_entry_reverse(i, list, list) {
97 if (j->seq == i->j.seq)
98 goto next_set;
99
100 if (j->seq < i->j.last_seq)
101 goto next_set;
102
103 if (j->seq > i->j.seq) {
104 where = &i->list;
105 goto add;
106 }
107 }
108
109 where = list;
110add:
111 i = kmalloc(offsetof(struct journal_replay, j) +
112 bytes, GFP_KERNEL);
113 if (!i)
114 return -ENOMEM;
115 memcpy(&i->j, j, bytes);
116 list_add(&i->list, where);
117 ret = 1;
118
119 ja->seq[bucket_index] = j->seq;
120next_set:
121 offset += blocks * ca->sb.block_size;
122 len -= blocks * ca->sb.block_size;
123 j = ((void *) j) + blocks * block_bytes(ca);
124 }
125 }
126
127 return ret;
128}
129
130int bch_journal_read(struct cache_set *c, struct list_head *list,
131 struct btree_op *op)
132{
133#define read_bucket(b) \
134 ({ \
135 int ret = journal_read_bucket(ca, list, op, b); \
136 __set_bit(b, bitmap); \
137 if (ret < 0) \
138 return ret; \
139 ret; \
140 })
141
142 struct cache *ca;
143 unsigned iter;
144
145 for_each_cache(ca, c, iter) {
146 struct journal_device *ja = &ca->journal;
147 unsigned long bitmap[SB_JOURNAL_BUCKETS / BITS_PER_LONG];
148 unsigned i, l, r, m;
149 uint64_t seq;
150
151 bitmap_zero(bitmap, SB_JOURNAL_BUCKETS);
152 pr_debug("%u journal buckets", ca->sb.njournal_buckets);
153
154 /* Read journal buckets ordered by golden ratio hash to quickly
155 * find a sequence of buckets with valid journal entries
156 */
157 for (i = 0; i < ca->sb.njournal_buckets; i++) {
158 l = (i * 2654435769U) % ca->sb.njournal_buckets;
159
160 if (test_bit(l, bitmap))
161 break;
162
163 if (read_bucket(l))
164 goto bsearch;
165 }
166
167 /* If that fails, check all the buckets we haven't checked
168 * already
169 */
170 pr_debug("falling back to linear search");
171
172 for (l = 0; l < ca->sb.njournal_buckets; l++) {
173 if (test_bit(l, bitmap))
174 continue;
175
176 if (read_bucket(l))
177 goto bsearch;
178 }
179bsearch:
180 /* Binary search */
181 m = r = find_next_bit(bitmap, ca->sb.njournal_buckets, l + 1);
182 pr_debug("starting binary search, l %u r %u", l, r);
183
184 while (l + 1 < r) {
Kent Overstreet5e20e8b2013-07-11 22:42:14 -0700185 seq = list_entry(list->prev, struct journal_replay,
186 list)->j.seq;
Kent Overstreetcafe5632013-03-23 16:11:31 -0700187
Kent Overstreet5e20e8b2013-07-11 22:42:14 -0700188 m = (l + r) >> 1;
189 read_bucket(m);
190
191 if (seq != list_entry(list->prev, struct journal_replay,
192 list)->j.seq)
Kent Overstreetcafe5632013-03-23 16:11:31 -0700193 l = m;
194 else
195 r = m;
196 }
197
198 /* Read buckets in reverse order until we stop finding more
199 * journal entries
200 */
201 pr_debug("finishing up");
202 l = m;
203
204 while (1) {
205 if (!l--)
206 l = ca->sb.njournal_buckets - 1;
207
208 if (l == m)
209 break;
210
211 if (test_bit(l, bitmap))
212 continue;
213
214 if (!read_bucket(l))
215 break;
216 }
217
218 seq = 0;
219
220 for (i = 0; i < ca->sb.njournal_buckets; i++)
221 if (ja->seq[i] > seq) {
222 seq = ja->seq[i];
223 ja->cur_idx = ja->discard_idx =
224 ja->last_idx = i;
225
226 }
227 }
228
229 c->journal.seq = list_entry(list->prev,
230 struct journal_replay,
231 list)->j.seq;
232
233 return 0;
234#undef read_bucket
235}
236
237void bch_journal_mark(struct cache_set *c, struct list_head *list)
238{
239 atomic_t p = { 0 };
240 struct bkey *k;
241 struct journal_replay *i;
242 struct journal *j = &c->journal;
243 uint64_t last = j->seq;
244
245 /*
246 * journal.pin should never fill up - we never write a journal
247 * entry when it would fill up. But if for some reason it does, we
248 * iterate over the list in reverse order so that we can just skip that
249 * refcount instead of bugging.
250 */
251
252 list_for_each_entry_reverse(i, list, list) {
253 BUG_ON(last < i->j.seq);
254 i->pin = NULL;
255
256 while (last-- != i->j.seq)
257 if (fifo_free(&j->pin) > 1) {
258 fifo_push_front(&j->pin, p);
259 atomic_set(&fifo_front(&j->pin), 0);
260 }
261
262 if (fifo_free(&j->pin) > 1) {
263 fifo_push_front(&j->pin, p);
264 i->pin = &fifo_front(&j->pin);
265 atomic_set(i->pin, 1);
266 }
267
268 for (k = i->j.start;
269 k < end(&i->j);
270 k = bkey_next(k)) {
271 unsigned j;
272
273 for (j = 0; j < KEY_PTRS(k); j++) {
274 struct bucket *g = PTR_BUCKET(c, k, j);
275 atomic_inc(&g->pin);
276
277 if (g->prio == BTREE_PRIO &&
278 !ptr_stale(c, k, j))
279 g->prio = INITIAL_PRIO;
280 }
281
282 __bch_btree_mark_key(c, 0, k);
283 }
284 }
285}
286
287int bch_journal_replay(struct cache_set *s, struct list_head *list,
288 struct btree_op *op)
289{
290 int ret = 0, keys = 0, entries = 0;
291 struct bkey *k;
292 struct journal_replay *i =
293 list_entry(list->prev, struct journal_replay, list);
294
295 uint64_t start = i->j.last_seq, end = i->j.seq, n = start;
296
297 list_for_each_entry(i, list, list) {
298 BUG_ON(i->pin && atomic_read(i->pin) != 1);
299
300 if (n != i->j.seq)
Kent Overstreetb1a67b02013-03-25 11:46:44 -0700301 pr_err(
302 "journal entries %llu-%llu missing! (replaying %llu-%llu)\n",
303 n, i->j.seq - 1, start, end);
Kent Overstreetcafe5632013-03-23 16:11:31 -0700304
305 for (k = i->j.start;
306 k < end(&i->j);
307 k = bkey_next(k)) {
308 pr_debug("%s", pkey(k));
309 bkey_copy(op->keys.top, k);
310 bch_keylist_push(&op->keys);
311
312 op->journal = i->pin;
313 atomic_inc(op->journal);
314
315 ret = bch_btree_insert(op, s);
316 if (ret)
317 goto err;
318
319 BUG_ON(!bch_keylist_empty(&op->keys));
320 keys++;
321
322 cond_resched();
323 }
324
325 if (i->pin)
326 atomic_dec(i->pin);
327 n = i->j.seq + 1;
328 entries++;
329 }
330
331 pr_info("journal replay done, %i keys in %i entries, seq %llu",
332 keys, entries, end);
333
334 while (!list_empty(list)) {
335 i = list_first_entry(list, struct journal_replay, list);
336 list_del(&i->list);
337 kfree(i);
338 }
339err:
340 closure_sync(&op->cl);
341 return ret;
342}
343
344/* Journalling */
345
346static void btree_flush_write(struct cache_set *c)
347{
348 /*
349 * Try to find the btree node with that references the oldest journal
350 * entry, best is our current candidate and is locked if non NULL:
351 */
352 struct btree *b, *best = NULL;
353 unsigned iter;
354
355 for_each_cached_btree(b, c, iter) {
356 if (!down_write_trylock(&b->lock))
357 continue;
358
359 if (!btree_node_dirty(b) ||
360 !btree_current_write(b)->journal) {
361 rw_unlock(true, b);
362 continue;
363 }
364
365 if (!best)
366 best = b;
367 else if (journal_pin_cmp(c,
368 btree_current_write(best),
369 btree_current_write(b))) {
370 rw_unlock(true, best);
371 best = b;
372 } else
373 rw_unlock(true, b);
374 }
375
376 if (best)
377 goto out;
378
379 /* We can't find the best btree node, just pick the first */
380 list_for_each_entry(b, &c->btree_cache, list)
381 if (!b->level && btree_node_dirty(b)) {
382 best = b;
383 rw_lock(true, best, best->level);
384 goto found;
385 }
386
387out:
388 if (!best)
389 return;
390found:
391 if (btree_node_dirty(best))
392 bch_btree_write(best, true, NULL);
393 rw_unlock(true, best);
394}
395
396#define last_seq(j) ((j)->seq - fifo_used(&(j)->pin) + 1)
397
398static void journal_discard_endio(struct bio *bio, int error)
399{
400 struct journal_device *ja =
401 container_of(bio, struct journal_device, discard_bio);
402 struct cache *ca = container_of(ja, struct cache, journal);
403
404 atomic_set(&ja->discard_in_flight, DISCARD_DONE);
405
406 closure_wake_up(&ca->set->journal.wait);
407 closure_put(&ca->set->cl);
408}
409
410static void journal_discard_work(struct work_struct *work)
411{
412 struct journal_device *ja =
413 container_of(work, struct journal_device, discard_work);
414
415 submit_bio(0, &ja->discard_bio);
416}
417
418static void do_journal_discard(struct cache *ca)
419{
420 struct journal_device *ja = &ca->journal;
421 struct bio *bio = &ja->discard_bio;
422
423 if (!ca->discard) {
424 ja->discard_idx = ja->last_idx;
425 return;
426 }
427
Kent Overstreet0a22f482013-09-23 23:17:27 -0700428 switch (atomic_read(&ja->discard_in_flight)) {
Kent Overstreetcafe5632013-03-23 16:11:31 -0700429 case DISCARD_IN_FLIGHT:
430 return;
431
432 case DISCARD_DONE:
433 ja->discard_idx = (ja->discard_idx + 1) %
434 ca->sb.njournal_buckets;
435
436 atomic_set(&ja->discard_in_flight, DISCARD_READY);
437 /* fallthrough */
438
439 case DISCARD_READY:
440 if (ja->discard_idx == ja->last_idx)
441 return;
442
443 atomic_set(&ja->discard_in_flight, DISCARD_IN_FLIGHT);
444
445 bio_init(bio);
446 bio->bi_sector = bucket_to_sector(ca->set,
Kent Overstreetb1a67b02013-03-25 11:46:44 -0700447 ca->sb.d[ja->discard_idx]);
Kent Overstreetcafe5632013-03-23 16:11:31 -0700448 bio->bi_bdev = ca->bdev;
449 bio->bi_rw = REQ_WRITE|REQ_DISCARD;
450 bio->bi_max_vecs = 1;
451 bio->bi_io_vec = bio->bi_inline_vecs;
452 bio->bi_size = bucket_bytes(ca);
453 bio->bi_end_io = journal_discard_endio;
454
455 closure_get(&ca->set->cl);
456 INIT_WORK(&ja->discard_work, journal_discard_work);
457 schedule_work(&ja->discard_work);
458 }
459}
460
461static void journal_reclaim(struct cache_set *c)
462{
463 struct bkey *k = &c->journal.key;
464 struct cache *ca;
465 uint64_t last_seq;
466 unsigned iter, n = 0;
467 atomic_t p;
468
469 while (!atomic_read(&fifo_front(&c->journal.pin)))
470 fifo_pop(&c->journal.pin, p);
471
472 last_seq = last_seq(&c->journal);
473
474 /* Update last_idx */
475
476 for_each_cache(ca, c, iter) {
477 struct journal_device *ja = &ca->journal;
478
479 while (ja->last_idx != ja->cur_idx &&
480 ja->seq[ja->last_idx] < last_seq)
481 ja->last_idx = (ja->last_idx + 1) %
482 ca->sb.njournal_buckets;
483 }
484
485 for_each_cache(ca, c, iter)
486 do_journal_discard(ca);
487
488 if (c->journal.blocks_free)
489 return;
490
491 /*
492 * Allocate:
493 * XXX: Sort by free journal space
494 */
495
496 for_each_cache(ca, c, iter) {
497 struct journal_device *ja = &ca->journal;
498 unsigned next = (ja->cur_idx + 1) % ca->sb.njournal_buckets;
499
500 /* No space available on this device */
501 if (next == ja->discard_idx)
502 continue;
503
504 ja->cur_idx = next;
505 k->ptr[n++] = PTR(0,
506 bucket_to_sector(c, ca->sb.d[ja->cur_idx]),
507 ca->sb.nr_this_dev);
508 }
509
510 bkey_init(k);
511 SET_KEY_PTRS(k, n);
512
513 if (n)
514 c->journal.blocks_free = c->sb.bucket_size >> c->block_bits;
515
516 if (!journal_full(&c->journal))
517 __closure_wake_up(&c->journal.wait);
518}
519
520void bch_journal_next(struct journal *j)
521{
522 atomic_t p = { 1 };
523
524 j->cur = (j->cur == j->w)
525 ? &j->w[1]
526 : &j->w[0];
527
528 /*
529 * The fifo_push() needs to happen at the same time as j->seq is
530 * incremented for last_seq() to be calculated correctly
531 */
532 BUG_ON(!fifo_push(&j->pin, p));
533 atomic_set(&fifo_back(&j->pin), 1);
534
535 j->cur->data->seq = ++j->seq;
536 j->cur->need_write = false;
537 j->cur->data->keys = 0;
538
539 if (fifo_full(&j->pin))
540 pr_debug("journal_pin full (%zu)", fifo_used(&j->pin));
541}
542
543static void journal_write_endio(struct bio *bio, int error)
544{
545 struct journal_write *w = bio->bi_private;
546
547 cache_set_err_on(error, w->c, "journal io error");
548 closure_put(&w->c->journal.io.cl);
549}
550
551static void journal_write(struct closure *);
552
553static void journal_write_done(struct closure *cl)
554{
555 struct journal *j = container_of(cl, struct journal, io.cl);
556 struct cache_set *c = container_of(j, struct cache_set, journal);
557
558 struct journal_write *w = (j->cur == j->w)
559 ? &j->w[1]
560 : &j->w[0];
561
562 __closure_wake_up(&w->wait);
563
564 if (c->journal_delay_ms)
565 closure_delay(&j->io, msecs_to_jiffies(c->journal_delay_ms));
566
567 continue_at(cl, journal_write, system_wq);
568}
569
570static void journal_write_unlocked(struct closure *cl)
Kent Overstreetc19ed232013-03-26 13:49:02 -0700571 __releases(c->journal.lock)
Kent Overstreetcafe5632013-03-23 16:11:31 -0700572{
573 struct cache_set *c = container_of(cl, struct cache_set, journal.io.cl);
574 struct cache *ca;
575 struct journal_write *w = c->journal.cur;
576 struct bkey *k = &c->journal.key;
577 unsigned i, sectors = set_blocks(w->data, c) * c->sb.block_size;
578
579 struct bio *bio;
580 struct bio_list list;
581 bio_list_init(&list);
582
583 if (!w->need_write) {
584 /*
585 * XXX: have to unlock closure before we unlock journal lock,
586 * else we race with bch_journal(). But this way we race
587 * against cache set unregister. Doh.
588 */
589 set_closure_fn(cl, NULL, NULL);
590 closure_sub(cl, CLOSURE_RUNNING + 1);
591 spin_unlock(&c->journal.lock);
592 return;
593 } else if (journal_full(&c->journal)) {
594 journal_reclaim(c);
595 spin_unlock(&c->journal.lock);
596
597 btree_flush_write(c);
598 continue_at(cl, journal_write, system_wq);
599 }
600
601 c->journal.blocks_free -= set_blocks(w->data, c);
602
603 w->data->btree_level = c->root->level;
604
605 bkey_copy(&w->data->btree_root, &c->root->key);
606 bkey_copy(&w->data->uuid_bucket, &c->uuid_bucket);
607
608 for_each_cache(ca, c, i)
609 w->data->prio_bucket[ca->sb.nr_this_dev] = ca->prio_buckets[0];
610
611 w->data->magic = jset_magic(c);
612 w->data->version = BCACHE_JSET_VERSION;
613 w->data->last_seq = last_seq(&c->journal);
614 w->data->csum = csum_set(w->data);
615
616 for (i = 0; i < KEY_PTRS(k); i++) {
617 ca = PTR_CACHE(c, k, i);
618 bio = &ca->journal.bio;
619
620 atomic_long_add(sectors, &ca->meta_sectors_written);
621
622 bio_reset(bio);
623 bio->bi_sector = PTR_OFFSET(k, i);
624 bio->bi_bdev = ca->bdev;
Kent Overstreetae61fd442013-06-26 17:25:38 -0700625 bio->bi_rw = REQ_WRITE|REQ_SYNC|REQ_META|REQ_FLUSH|REQ_FUA;
Kent Overstreetcafe5632013-03-23 16:11:31 -0700626 bio->bi_size = sectors << 9;
627
628 bio->bi_end_io = journal_write_endio;
629 bio->bi_private = w;
Kent Overstreet169ef1c2013-03-28 12:50:55 -0600630 bch_bio_map(bio, w->data);
Kent Overstreetcafe5632013-03-23 16:11:31 -0700631
632 trace_bcache_journal_write(bio);
633 bio_list_add(&list, bio);
634
635 SET_PTR_OFFSET(k, i, PTR_OFFSET(k, i) + sectors);
636
637 ca->journal.seq[ca->journal.cur_idx] = w->data->seq;
638 }
639
640 atomic_dec_bug(&fifo_back(&c->journal.pin));
641 bch_journal_next(&c->journal);
642 journal_reclaim(c);
643
644 spin_unlock(&c->journal.lock);
645
646 while ((bio = bio_list_pop(&list)))
647 closure_bio_submit(bio, cl, c->cache[0]);
648
649 continue_at(cl, journal_write_done, NULL);
650}
651
652static void journal_write(struct closure *cl)
653{
654 struct cache_set *c = container_of(cl, struct cache_set, journal.io.cl);
655
656 spin_lock(&c->journal.lock);
657 journal_write_unlocked(cl);
658}
659
660static void __journal_try_write(struct cache_set *c, bool noflush)
Kent Overstreetc19ed232013-03-26 13:49:02 -0700661 __releases(c->journal.lock)
Kent Overstreetcafe5632013-03-23 16:11:31 -0700662{
663 struct closure *cl = &c->journal.io.cl;
664
665 if (!closure_trylock(cl, &c->cl))
666 spin_unlock(&c->journal.lock);
667 else if (noflush && journal_full(&c->journal)) {
668 spin_unlock(&c->journal.lock);
669 continue_at(cl, journal_write, system_wq);
670 } else
671 journal_write_unlocked(cl);
672}
673
674#define journal_try_write(c) __journal_try_write(c, false)
675
676void bch_journal_meta(struct cache_set *c, struct closure *cl)
677{
678 struct journal_write *w;
679
680 if (CACHE_SYNC(&c->sb)) {
681 spin_lock(&c->journal.lock);
682
683 w = c->journal.cur;
684 w->need_write = true;
685
686 if (cl)
687 BUG_ON(!closure_wait(&w->wait, cl));
688
689 __journal_try_write(c, true);
690 }
691}
692
693/*
694 * Entry point to the journalling code - bio_insert() and btree_invalidate()
695 * pass bch_journal() a list of keys to be journalled, and then
696 * bch_journal() hands those same keys off to btree_insert_async()
697 */
698
699void bch_journal(struct closure *cl)
700{
701 struct btree_op *op = container_of(cl, struct btree_op, cl);
702 struct cache_set *c = op->c;
703 struct journal_write *w;
704 size_t b, n = ((uint64_t *) op->keys.top) - op->keys.list;
705
706 if (op->type != BTREE_INSERT ||
707 !CACHE_SYNC(&c->sb))
708 goto out;
709
710 /*
711 * If we're looping because we errored, might already be waiting on
712 * another journal write:
713 */
714 while (atomic_read(&cl->parent->remaining) & CLOSURE_WAITING)
715 closure_sync(cl->parent);
716
717 spin_lock(&c->journal.lock);
718
719 if (journal_full(&c->journal)) {
720 /* XXX: tracepoint */
721 closure_wait(&c->journal.wait, cl);
722
723 journal_reclaim(c);
724 spin_unlock(&c->journal.lock);
725
726 btree_flush_write(c);
727 continue_at(cl, bch_journal, bcache_wq);
728 }
729
730 w = c->journal.cur;
731 w->need_write = true;
732 b = __set_blocks(w->data, w->data->keys + n, c);
733
734 if (b * c->sb.block_size > PAGE_SECTORS << JSET_BITS ||
735 b > c->journal.blocks_free) {
736 /* XXX: If we were inserting so many keys that they won't fit in
737 * an _empty_ journal write, we'll deadlock. For now, handle
738 * this in bch_keylist_realloc() - but something to think about.
739 */
740 BUG_ON(!w->data->keys);
741
742 /* XXX: tracepoint */
743 BUG_ON(!closure_wait(&w->wait, cl));
744
745 closure_flush(&c->journal.io);
746
747 journal_try_write(c);
748 continue_at(cl, bch_journal, bcache_wq);
749 }
750
751 memcpy(end(w->data), op->keys.list, n * sizeof(uint64_t));
752 w->data->keys += n;
753
754 op->journal = &fifo_back(&c->journal.pin);
755 atomic_inc(op->journal);
756
757 if (op->flush_journal) {
758 closure_flush(&c->journal.io);
759 closure_wait(&w->wait, cl->parent);
760 }
761
762 journal_try_write(c);
763out:
764 bch_btree_insert_async(cl);
765}
766
767void bch_journal_free(struct cache_set *c)
768{
769 free_pages((unsigned long) c->journal.w[1].data, JSET_BITS);
770 free_pages((unsigned long) c->journal.w[0].data, JSET_BITS);
771 free_fifo(&c->journal.pin);
772}
773
774int bch_journal_alloc(struct cache_set *c)
775{
776 struct journal *j = &c->journal;
777
778 closure_init_unlocked(&j->io);
779 spin_lock_init(&j->lock);
780
781 c->journal_delay_ms = 100;
782
783 j->w[0].c = c;
784 j->w[1].c = c;
785
786 if (!(init_fifo(&j->pin, JOURNAL_PIN, GFP_KERNEL)) ||
787 !(j->w[0].data = (void *) __get_free_pages(GFP_KERNEL, JSET_BITS)) ||
788 !(j->w[1].data = (void *) __get_free_pages(GFP_KERNEL, JSET_BITS)))
789 return -ENOMEM;
790
791 return 0;
792}