diff options
-rw-r--r-- | drivers/md/bcache/alloc.c | 33 | ||||
-rw-r--r-- | drivers/md/bcache/journal.c | 22 | ||||
-rw-r--r-- | drivers/md/bcache/journal_types.h | 10 |
3 files changed, 47 insertions, 18 deletions
diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c index 7bc41a3a21b1..376721461381 100644 --- a/drivers/md/bcache/alloc.c +++ b/drivers/md/bcache/alloc.c @@ -241,6 +241,9 @@ static int prio_io(struct cache *ca, uint64_t bucket, int op) static int bch_prio_write(struct cache *ca) { struct cache_set *c = ca->set; + struct journal *j = &c->journal; + struct journal_res res = { 0 }; + bool need_new_journal_entry; int i, ret; trace_bcache_prio_write_start(ca); @@ -291,16 +294,28 @@ static int bch_prio_write(struct cache *ca) return ret; } - spin_lock(&c->journal.lock); - c->journal.prio_buckets[ca->sb.nr_this_dev] = cpu_to_le64(ca->prio_buckets[0]); - c->journal.nr_prio_buckets = max_t(unsigned, - ca->sb.nr_this_dev + 1, - c->journal.nr_prio_buckets); - spin_unlock(&c->journal.lock); + spin_lock(&j->lock); + j->prio_buckets[ca->sb.nr_this_dev] = cpu_to_le64(ca->prio_buckets[0]); + j->nr_prio_buckets = max_t(unsigned, + ca->sb.nr_this_dev + 1, + j->nr_prio_buckets); + spin_unlock(&j->lock); - ret = bch_journal_meta(&c->journal); - if (ret) - return ret; + do { + unsigned u64s = jset_u64s(0); + + ret = bch_journal_res_get(j, &res, u64s, u64s); + if (ret) + return ret; + + need_new_journal_entry = j->buf[res.idx].nr_prio_buckets < + ca->sb.nr_this_dev + 1; + bch_journal_res_put(j, &res); + + ret = bch_journal_flush_seq(j, res.seq); + if (ret) + return ret; + } while (need_new_journal_entry); /* * Don't want the old priorities to get garbage collected until after we diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c index 254c3d2ab8c1..1b68796154fb 100644 --- a/drivers/md/bcache/journal.c +++ b/drivers/md/bcache/journal.c @@ -144,10 +144,10 @@ static inline void bch_journal_add_prios(struct journal *j, * no prio bucket ptrs yet... XXX should change the allocator so this * can't happen: */ - if (!j->nr_prio_buckets) + if (!buf->nr_prio_buckets) return; - bch_journal_add_entry(buf, j->prio_buckets, j->nr_prio_buckets, + bch_journal_add_entry(buf, j->prio_buckets, buf->nr_prio_buckets, JOURNAL_ENTRY_PRIO_PTRS, 0, 0); } @@ -1004,10 +1004,14 @@ static void __bch_journal_next_entry(struct journal *j) BUG_ON(journal_pin_seq(j, p) != atomic64_read(&j->seq)); } -static inline size_t journal_entry_u64s_reserve(struct journal *j) +static inline size_t journal_entry_u64s_reserve(struct journal_buf *buf) { - return BTREE_ID_NR * (JSET_KEYS_U64s + BKEY_EXTENT_U64s_MAX) + - JSET_KEYS_U64s + j->nr_prio_buckets; + unsigned ret = BTREE_ID_NR * (JSET_KEYS_U64s + BKEY_EXTENT_U64s_MAX); + + if (buf->nr_prio_buckets) + ret += JSET_KEYS_U64s + buf->nr_prio_buckets; + + return ret; } static enum { @@ -1058,7 +1062,7 @@ static enum { j->prev_buf_sectors = __set_blocks(buf->data, le32_to_cpu(buf->data->u64s) + - journal_entry_u64s_reserve(j), + journal_entry_u64s_reserve(buf), block_bytes(c)) * c->sb.block_size; BUG_ON(j->prev_buf_sectors > j->cur_buf_sectors); @@ -1199,18 +1203,18 @@ static int journal_entry_open(struct journal *j) if (sectors <= 0) return sectors; - j->cur_buf_sectors = sectors; + j->cur_buf_sectors = sectors; + buf->nr_prio_buckets = j->nr_prio_buckets; u64s = (sectors << 9) / sizeof(u64); /* Subtract the journal header */ u64s -= sizeof(struct jset) / sizeof(u64); - /* * Btree roots, prio pointers don't get added until right before we do * the write: */ - u64s -= journal_entry_u64s_reserve(j); + u64s -= journal_entry_u64s_reserve(buf); u64s = max_t(ssize_t, 0L, u64s); if (u64s > le32_to_cpu(buf->data->u64s)) { diff --git a/drivers/md/bcache/journal_types.h b/drivers/md/bcache/journal_types.h index cb131eaafea8..78c304d51d3a 100644 --- a/drivers/md/bcache/journal_types.h +++ b/drivers/md/bcache/journal_types.h @@ -20,6 +20,12 @@ struct journal_buf { struct jset *data; struct closure_waitlist wait; + /* + * ugh, prio_buckets are stupid - need to convert them to new + * transaction machinery when it arrives + */ + unsigned nr_prio_buckets; + /* bloom filter: */ unsigned long has_inode[1024 / sizeof(unsigned long)]; }; @@ -170,6 +176,10 @@ struct journal { /* protects advancing ja->last_idx: */ struct mutex reclaim_lock; + /* + * ugh: need to get prio_buckets converted over to the eventual new + * transaction machinery + */ __le64 prio_buckets[MAX_CACHES_PER_SET]; unsigned nr_prio_buckets; |