summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2020-06-24 15:45:01 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2020-06-28 18:12:46 -0400
commit919b1e2379b8f5ae68ddb4a63ca208373bae9fdc (patch)
tree612daa065125a9e9ba66f52f612801de07372836
parent126619b518574792453def7d3e79dd151a1210de (diff)
bcache: make writeback_keys a ptr
This is so the bcache2 code can use struct cached_dev without having to pull in the bcache1 struct bkey.
-rw-r--r--drivers/md/bcache/bcache.h2
-rw-r--r--drivers/md/bcache/btree.c6
-rw-r--r--drivers/md/bcache/request.c2
-rw-r--r--drivers/md/bcache/super.c4
-rw-r--r--drivers/md/bcache/writeback.c37
-rw-r--r--drivers/md/bcache/writeback.h2
6 files changed, 26 insertions, 27 deletions
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 4694080ca51d..646ce2bacb3c 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -342,7 +342,7 @@ struct cached_dev {
struct task_struct *writeback_thread;
struct workqueue_struct *writeback_write_wq;
- struct keybuf writeback_keys;
+ struct keybuf *writeback_keys;
struct task_struct *status_update_thread;
/*
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 72856e5f23a3..b1b91f869641 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -1733,13 +1733,13 @@ static void bch_btree_gc_finish(struct cache_set *c)
continue;
dc = container_of(d, struct cached_dev, disk);
- spin_lock(&dc->writeback_keys.lock);
+ spin_lock(&dc->writeback_keys->lock);
rbtree_postorder_for_each_entry_safe(w, n,
- &dc->writeback_keys.keys, node)
+ &dc->writeback_keys->keys, node)
for (j = 0; j < KEY_PTRS(&w->key); j++)
SET_GC_MARK(PTR_BUCKET(c, &w->key, j),
GC_MARK_DIRTY);
- spin_unlock(&dc->writeback_keys.lock);
+ spin_unlock(&dc->writeback_keys->lock);
}
rcu_read_unlock();
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index fb8b50592c1f..8b85ad8b3f45 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -978,7 +978,7 @@ static void cached_dev_write(struct cached_dev *dc, struct search *s)
bch_keybuf_check_overlapping(&s->iop.c->moving_gc_keys, &start, &end);
down_read_non_owner(&dc->writeback_lock);
- if (bch_keybuf_check_overlapping(&dc->writeback_keys, &start, &end)) {
+ if (bch_keybuf_check_overlapping(dc->writeback_keys, &start, &end)) {
/*
* We overlap with some dirty data undergoing background
* writeback, force this write to writeback
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 9f3e769b5a67..0da9b3af944c 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1289,6 +1289,7 @@ static void cached_dev_free(struct closure *cl)
wake_up(&unregister_wait);
+ kfree(dc->writeback_keys);
kobject_put(&dc->disk.kobj);
}
@@ -1354,8 +1355,7 @@ static int cached_dev_init(struct cached_dev *dc, unsigned int block_size)
dc->stop_when_cache_set_failed = BCH_CACHED_DEV_STOP_AUTO;
bch_cached_dev_request_init(dc);
- bch_cached_dev_writeback_init(dc);
- return 0;
+ return bch_cached_dev_writeback_init(dc);
}
/* Cached device - bcache superblock */
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 805eff2cb2e6..4e8b6f42e19b 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -231,8 +231,8 @@ static void update_writeback_rate(struct work_struct *work)
smp_mb__after_atomic();
}
-static unsigned int writeback_delay(struct cached_dev *dc,
- unsigned int sectors)
+unsigned int bch_writeback_delay(struct cached_dev *dc,
+ unsigned int sectors)
{
if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags) ||
!dc->writeback_percent)
@@ -303,7 +303,7 @@ static void write_dirty_finish(struct closure *cl)
: &dc->disk.c->writeback_keys_done);
}
- bch_keybuf_del(&dc->writeback_keys, w);
+ bch_keybuf_del(dc->writeback_keys, w);
up(&dc->in_flight);
closure_return_with_destructor(cl, dirty_io_destructor);
@@ -412,7 +412,7 @@ static void read_dirty(struct cached_dev *dc)
* mempools.
*/
- next = bch_keybuf_next(&dc->writeback_keys);
+ next = bch_keybuf_next(dc->writeback_keys);
while (!kthread_should_stop() &&
!test_bit(CACHE_SET_IO_DISABLE, &dc->disk.c->flags) &&
@@ -452,7 +452,7 @@ static void read_dirty(struct cached_dev *dc)
size += KEY_SIZE(&next->key);
keys[nk++] = next;
- } while ((next = bch_keybuf_next(&dc->writeback_keys)));
+ } while ((next = bch_keybuf_next(dc->writeback_keys)));
/* Now we have gathered a set of 1..5 keys to write back. */
for (i = 0; i < nk; i++) {
@@ -492,13 +492,13 @@ static void read_dirty(struct cached_dev *dc)
closure_call(&io->cl, read_dirty_submit, NULL, &cl);
}
- delay = writeback_delay(dc, size);
+ delay = bch_writeback_delay(dc, size);
while (!kthread_should_stop() &&
!test_bit(CACHE_SET_IO_DISABLE, &dc->disk.c->flags) &&
delay) {
schedule_timeout_interruptible(delay);
- delay = writeback_delay(dc, 0);
+ delay = bch_writeback_delay(dc, 0);
}
}
@@ -506,7 +506,7 @@ static void read_dirty(struct cached_dev *dc)
err_free:
kfree(w->private);
err:
- bch_keybuf_del(&dc->writeback_keys, w);
+ bch_keybuf_del(dc->writeback_keys, w);
}
/*
@@ -558,18 +558,12 @@ void bcache_dev_sectors_dirty_add(struct cache_set *c, unsigned int inode,
static bool dirty_pred(struct keybuf *buf, struct bkey *k)
{
- struct cached_dev *dc = container_of(buf,
- struct cached_dev,
- writeback_keys);
-
- BUG_ON(KEY_INODE(k) != dc->disk.id);
-
return KEY_DIRTY(k);
}
static void refill_full_stripes(struct cached_dev *dc)
{
- struct keybuf *buf = &dc->writeback_keys;
+ struct keybuf *buf = dc->writeback_keys;
unsigned int start_stripe, stripe, next_stripe;
bool wrapped = false;
@@ -618,7 +612,7 @@ next:
*/
static bool refill_dirty(struct cached_dev *dc)
{
- struct keybuf *buf = &dc->writeback_keys;
+ struct keybuf *buf = dc->writeback_keys;
struct bkey start = KEY(dc->disk.id, 0, 0);
struct bkey end = KEY(dc->disk.id, MAX_KEY_OFFSET, 0);
struct bkey start_pos;
@@ -691,7 +685,7 @@ static int bch_writeback_thread(void *arg)
searched_full_index = refill_dirty(dc);
if (searched_full_index &&
- RB_EMPTY_ROOT(&dc->writeback_keys.keys)) {
+ RB_EMPTY_ROOT(&dc->writeback_keys->keys)) {
atomic_set(&dc->has_dirty, 0);
SET_BDEV_STATE(&dc->sb, BDEV_STATE_CLEAN);
bch_write_bdev_super(dc, NULL);
@@ -959,11 +953,15 @@ out:
kfree(state);
}
-void bch_cached_dev_writeback_init(struct cached_dev *dc)
+int bch_cached_dev_writeback_init(struct cached_dev *dc)
{
+ dc->writeback_keys = kzalloc(sizeof(*dc->writeback_keys), GFP_KERNEL);
+ if (!dc->writeback_keys)
+ return -ENOMEM;
+
sema_init(&dc->in_flight, 64);
init_rwsem(&dc->writeback_lock);
- bch_keybuf_init(&dc->writeback_keys);
+ bch_keybuf_init(dc->writeback_keys);
dc->writeback_metadata = true;
dc->writeback_running = false;
@@ -978,6 +976,7 @@ void bch_cached_dev_writeback_init(struct cached_dev *dc)
WARN_ON(test_and_clear_bit(BCACHE_DEV_WB_RUNNING, &dc->disk.flags));
INIT_DELAYED_WORK(&dc->writeback_rate_update, update_writeback_rate);
+ return 0;
}
int bch_cached_dev_writeback_start(struct cached_dev *dc)
diff --git a/drivers/md/bcache/writeback.h b/drivers/md/bcache/writeback.h
index b029843ce5b6..f69bef938a0a 100644
--- a/drivers/md/bcache/writeback.h
+++ b/drivers/md/bcache/writeback.h
@@ -130,7 +130,7 @@ void bcache_dev_sectors_dirty_add(struct cache_set *c, unsigned int inode,
uint64_t offset, int nr_sectors);
void bch_sectors_dirty_init(struct bcache_device *d);
-void bch_cached_dev_writeback_init(struct cached_dev *dc);
+int bch_cached_dev_writeback_init(struct cached_dev *dc);
int bch_cached_dev_writeback_start(struct cached_dev *dc);
#endif