summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2015-06-04 22:39:07 -0700
committerKent Overstreet <kent.overstreet@gmail.com>2016-10-07 12:34:23 -0800
commit5073b4e77d2dbb8231fdf82075edf48cc64f2ffa (patch)
tree35266dc8d00b96fd930de34569725c5a5ba36049
parent44c8f531eed9e0971a909d7a12f785caaacbfc4a (diff)
bcache: Drop closure arg top bch_btree_insert/update()
-rw-r--r--drivers/md/bcache/blockdev.c11
-rw-r--r--drivers/md/bcache/btree.c20
-rw-r--r--drivers/md/bcache/btree.h7
-rw-r--r--drivers/md/bcache/fs.c10
-rw-r--r--drivers/md/bcache/inode.c3
-rw-r--r--drivers/md/bcache/inode.h5
-rw-r--r--drivers/md/bcache/io.c48
-rw-r--r--drivers/md/bcache/io.h15
-rw-r--r--drivers/md/bcache/journal.c2
-rw-r--r--drivers/md/bcache/migrate.c4
-rw-r--r--drivers/md/bcache/movinggc.c2
-rw-r--r--drivers/md/bcache/request.c5
-rw-r--r--drivers/md/bcache/super.c2
-rw-r--r--drivers/md/bcache/sysfs.c43
-rw-r--r--drivers/md/bcache/tier.c2
-rw-r--r--drivers/md/bcache/writeback.c2
16 files changed, 110 insertions, 71 deletions
diff --git a/drivers/md/bcache/blockdev.c b/drivers/md/bcache/blockdev.c
index 0723e509a65e..1a788f2fd7c5 100644
--- a/drivers/md/bcache/blockdev.c
+++ b/drivers/md/bcache/blockdev.c
@@ -361,9 +361,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c)
char buf[BDEVNAME_SIZE];
bool found;
int ret;
- struct closure cl;
- closure_init_stack(&cl);
bdevname(dc->disk_sb.bdev, buf);
if (memcmp(&dc->sb.set_uuid, &c->sb.set_uuid, sizeof(c->sb.set_uuid)))
@@ -409,6 +407,10 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c)
*/
if (!found) {
+ struct closure cl;
+
+ closure_init_stack(&cl);
+
bkey_inode_blockdev_init(&dc->disk.inode.k_i);
dc->disk.inode.k.type = BCH_INODE_CACHED_DEV;
dc->disk.inode.v.i_uuid = dc->sb.disk_uuid;
@@ -430,13 +432,12 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c)
SET_BDEV_STATE(&dc->sb, BDEV_STATE_CLEAN);
bch_write_bdev_super(dc, &cl);
+ closure_sync(&cl);
} else {
dc->disk.inode.v.i_inode.i_mtime = rtime;
- bch_inode_update(c, &dc->disk.inode.k_i, &cl, NULL);
+ bch_inode_update(c, &dc->disk.inode.k_i, NULL);
}
- closure_sync(&cl);
-
/* Count dirty sectors before attaching */
if (BDEV_STATE(&dc->sb) == BDEV_STATE_DIRTY)
bch_sectors_dirty_init(dc, c);
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index 16649749dfbb..51b521669052 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -2870,15 +2870,11 @@ int bch_btree_insert_check_key(struct btree_iter *iter,
*/
int bch_btree_insert(struct cache_set *c, enum btree_id id,
struct keylist *keys, struct bch_replace_info *replace,
- struct closure *persistent, u64 *journal_seq, int flags)
+ u64 *journal_seq, int flags)
{
struct btree_iter iter;
- u64 jseq = 0;
int ret, ret2;
- if (!journal_seq)
- journal_seq = &jseq;
-
bch_btree_iter_init_intent(&iter, c, id,
bkey_start_pos(&bch_keylist_front(keys)->k));
@@ -2890,9 +2886,6 @@ int bch_btree_insert(struct cache_set *c, enum btree_id id,
journal_seq, flags);
out: ret2 = bch_btree_iter_unlock(&iter);
- if (persistent)
- bch_journal_push_seq(&c->journal, *journal_seq, persistent);
-
return ret ?: ret2;
}
@@ -2900,17 +2893,13 @@ out: ret2 = bch_btree_iter_unlock(&iter);
* bch_btree_update - like bch_btree_insert(), but asserts that we're
* overwriting an existing key
*/
-int bch_btree_update(struct cache_set *c, enum btree_id id, struct bkey_i *k,
- struct closure *persistent, u64 *journal_seq)
+int bch_btree_update(struct cache_set *c, enum btree_id id,
+ struct bkey_i *k, u64 *journal_seq)
{
struct btree_iter iter;
struct bkey_s_c u;
- u64 jseq = 0;
int ret, ret2;
- if (!journal_seq)
- journal_seq = &jseq;
-
EBUG_ON(id == BTREE_ID_EXTENTS);
bch_btree_iter_init_intent(&iter, c, id, k->k.p);
@@ -2926,9 +2915,6 @@ int bch_btree_update(struct cache_set *c, enum btree_id id, struct bkey_i *k,
journal_seq, 0);
out: ret2 = bch_btree_iter_unlock(&iter);
- if (persistent)
- bch_journal_push_seq(&c->journal, *journal_seq, persistent);
-
return ret ?: ret2;
}
diff --git a/drivers/md/bcache/btree.h b/drivers/md/bcache/btree.h
index a7fc9b969664..f4aef01f97e5 100644
--- a/drivers/md/bcache/btree.h
+++ b/drivers/md/bcache/btree.h
@@ -501,10 +501,9 @@ int bch_btree_insert_at(struct btree_iter *, struct keylist *,
struct bch_replace_info *, u64 *, unsigned);
int bch_btree_insert_check_key(struct btree_iter *, struct bkey_i *);
int bch_btree_insert(struct cache_set *, enum btree_id, struct keylist *,
- struct bch_replace_info *, struct closure *,
- u64 *, int flags);
-int bch_btree_update(struct cache_set *, enum btree_id, struct bkey_i *,
- struct closure *, u64 *);
+ struct bch_replace_info *, u64 *, int flags);
+int bch_btree_update(struct cache_set *, enum btree_id,
+ struct bkey_i *, u64 *);
int bch_btree_node_rewrite(struct btree *, struct btree_iter *, bool);
diff --git a/drivers/md/bcache/fs.c b/drivers/md/bcache/fs.c
index 80884f3adc96..7731c0409ce8 100644
--- a/drivers/md/bcache/fs.c
+++ b/drivers/md/bcache/fs.c
@@ -113,7 +113,7 @@ static int __bch_write_inode(struct inode *inode)
bi->i_mtime = timespec_to_ns(&inode->i_mtime);
bi->i_ctime = timespec_to_ns(&inode->i_ctime);
- return bch_inode_update(c, &ei->inode.k_i, NULL, &ei->journal_seq);
+ return bch_inode_update(c, &ei->inode.k_i, &ei->journal_seq);
}
static struct inode *bch_vfs_inode_get(struct super_block *sb, u64 inum)
@@ -1115,8 +1115,8 @@ do_io:
closure_init(&w->io->cl, NULL);
bch_write_op_init(&w->io->op, w->c, &w->io->bio, NULL,
bkey_to_s_c(&KEY(w->inum, 0, 0)),
- bkey_s_c_null, 0);
- w->io->op.journal_seq = &ei->journal_seq;
+ bkey_s_c_null,
+ &ei->journal_seq, 0);
}
if (bch_bio_add_page(&w->io->bio.bio.bio, page)) {
@@ -1576,8 +1576,8 @@ static int bch_direct_IO_write(struct cache_set *c, struct kiocb *req,
bkey_to_s_c(&KEY(inum,
bio_end_sector(bio),
bio_sectors(bio))),
- bkey_s_c_null, flags);
- op->iop.journal_seq = &ei->journal_seq;
+ bkey_s_c_null,
+ &ei->journal_seq, flags);
task_io_account_write(bio->bi_iter.bi_size);
diff --git a/drivers/md/bcache/inode.c b/drivers/md/bcache/inode.c
index fa6064cb96d7..7061193777e2 100644
--- a/drivers/md/bcache/inode.c
+++ b/drivers/md/bcache/inode.c
@@ -194,8 +194,7 @@ int bch_inode_rm(struct cache_set *c, u64 inode_nr)
return bch_btree_insert(c, BTREE_ID_INODES,
&keylist_single(&delete),
- NULL, NULL, NULL,
- BTREE_INSERT_NOFAIL);
+ NULL, NULL, BTREE_INSERT_NOFAIL);
}
int bch_inode_find_by_inum(struct cache_set *c, u64 inode_nr,
diff --git a/drivers/md/bcache/inode.h b/drivers/md/bcache/inode.h
index e2ca50afff2f..c5d337c0903b 100644
--- a/drivers/md/bcache/inode.h
+++ b/drivers/md/bcache/inode.h
@@ -11,10 +11,9 @@ int bch_inode_truncate(struct cache_set *, u64, u64);
int bch_inode_rm(struct cache_set *, u64);
static inline int bch_inode_update(struct cache_set *c, struct bkey_i *inode,
- struct closure *cl, u64 *journal_seq)
+ u64 *journal_seq)
{
- return bch_btree_update(c, BTREE_ID_INODES, inode,
- cl, journal_seq);
+ return bch_btree_update(c, BTREE_ID_INODES, inode, journal_seq);
}
int bch_inode_find_by_inum(struct cache_set *, u64, struct bkey_i_inode *);
diff --git a/drivers/md/bcache/io.c b/drivers/md/bcache/io.c
index 3249eba03d7b..1beeb0cb5494 100644
--- a/drivers/md/bcache/io.c
+++ b/drivers/md/bcache/io.c
@@ -15,6 +15,7 @@
#include "extents.h"
#include "gc.h"
#include "io.h"
+#include "journal.h"
#include "keylist.h"
#include "notify.h"
#include "stats.h"
@@ -504,19 +505,19 @@ copy:
static void __bch_write(struct closure *);
+static inline u64 *op_journal_seq(struct bch_write_op *op)
+{
+ return op->journal_seq_ptr ? op->journal_seq_p : &op->journal_seq;
+}
+
static void bch_write_done(struct closure *cl)
{
struct bch_write_op *op = container_of(cl, struct bch_write_op, cl);
- unsigned i;
- for (i = 0; i < ARRAY_SIZE(op->open_buckets); i++)
- if (op->open_buckets[i]) {
- bch_open_bucket_put(op->c, op->open_buckets[i]);
- op->open_buckets[i] = NULL;
- }
+ BUG_ON(!op->write_done);
- if (!op->write_done)
- continue_at(cl, __bch_write, op->io_wq);
+ if (!op->error && op->flush)
+ bch_journal_push_seq(&op->c->journal, *op_journal_seq(op), cl);
if (op->replace_collision) {
trace_bcache_promote_collision(&op->replace_info.key.k);
@@ -534,18 +535,28 @@ static void bch_write_done(struct closure *cl)
static void bch_write_index(struct closure *cl)
{
struct bch_write_op *op = container_of(cl, struct bch_write_op, cl);
+ unsigned i;
+ int ret;
- int ret = bch_btree_insert(op->c, BTREE_ID_EXTENTS, &op->insert_keys,
- op->replace ? &op->replace_info : NULL,
- op->flush ? &op->cl : NULL,
- op->journal_seq, BTREE_INSERT_NOFAIL);
+ ret = bch_btree_insert(op->c, BTREE_ID_EXTENTS, &op->insert_keys,
+ op->replace ? &op->replace_info : NULL,
+ op_journal_seq(op), BTREE_INSERT_NOFAIL);
if (ret) {
__bcache_io_error(op->c, "btree IO error");
op->error = ret;
} else if (op->replace && op->replace_info.successes == 0)
op->replace_collision = true;
- continue_at(cl, bch_write_done, op->c->wq);
+ for (i = 0; i < ARRAY_SIZE(op->open_buckets); i++)
+ if (op->open_buckets[i]) {
+ bch_open_bucket_put(op->c, op->open_buckets[i]);
+ op->open_buckets[i] = NULL;
+ }
+
+ if (op->write_done)
+ continue_at_nobarrier(cl, bch_write_done, NULL);
+ else
+ continue_at(cl, __bch_write, op->io_wq);
}
/**
@@ -1133,7 +1144,7 @@ void bch_write_op_init(struct bch_write_op *op, struct cache_set *c,
struct bch_write_bio *bio, struct write_point *wp,
struct bkey_s_c insert_key,
struct bkey_s_c replace_key,
- unsigned flags)
+ u64 *journal_seq, unsigned flags)
{
if (!wp) {
unsigned wp_idx = hash_long((unsigned long) current,
@@ -1154,7 +1165,12 @@ void bch_write_op_init(struct bch_write_op *op, struct cache_set *c,
op->cached = (flags & BCH_WRITE_CACHED) != 0;
op->flush = (flags & BCH_WRITE_FLUSH) != 0;
op->wp = wp;
- op->journal_seq = NULL;
+ op->journal_seq_ptr = journal_seq != NULL;
+
+ if (op->journal_seq_ptr)
+ op->journal_seq_p = journal_seq;
+ else
+ op->journal_seq = 0;
bch_keylist_init(&op->insert_keys,
op->inline_keys,
@@ -1632,7 +1648,7 @@ void bch_read_extent(struct cache_set *c, struct bio *orig,
bch_write_op_init(&promote_op->iop, c,
&promote_op->bio,
&c->promote_write_point,
- k, k,
+ k, k, NULL,
BCH_WRITE_CHECK_ENOSPC|
BCH_WRITE_ALLOC_NOWAIT);
diff --git a/drivers/md/bcache/io.h b/drivers/md/bcache/io.h
index 53c8b3aa07ea..5c819c77a6ec 100644
--- a/drivers/md/bcache/io.h
+++ b/drivers/md/bcache/io.h
@@ -40,7 +40,7 @@ struct bch_write_op {
short error;
union {
- u8 flags;
+ u16 flags;
struct {
/* Return -ENOSPC if cache set is full? */
@@ -58,6 +58,8 @@ struct bch_write_op {
/* Set on completion, if cmpxchg index update failed */
unsigned replace_collision:1;
+ /* Are we using the prt member of journal_seq union? */
+ unsigned journal_seq_ptr:1;
/* Internal */
unsigned write_done:1;
};
@@ -73,7 +75,14 @@ struct bch_write_op {
};
};
- u64 *journal_seq;
+ /*
+ * If caller wants to flush but hasn't passed us a journal_seq ptr, we
+ * still need to stash the journal_seq somewhere:
+ */
+ union {
+ u64 *journal_seq_p;
+ u64 journal_seq;
+ };
struct keylist insert_keys;
BKEY_PADDED(insert_key);
@@ -91,7 +100,7 @@ enum bch_write_flags {
void bch_write_op_init(struct bch_write_op *, struct cache_set *,
struct bch_write_bio *, struct write_point *,
- struct bkey_s_c, struct bkey_s_c, unsigned);
+ struct bkey_s_c, struct bkey_s_c, u64 *, unsigned);
void bch_write(struct closure *);
struct cache_promote_op;
diff --git a/drivers/md/bcache/journal.c b/drivers/md/bcache/journal.c
index 08879ba95be7..770c36e57ae9 100644
--- a/drivers/md/bcache/journal.c
+++ b/drivers/md/bcache/journal.c
@@ -901,7 +901,7 @@ static int bch_journal_replay_key(struct cache_set *c, enum btree_id id,
if (do_subtract)
bkey_copy(&temp.key, k);
- ret = bch_btree_insert(c, id, &keylist_single(k), NULL, NULL, NULL, 0);
+ ret = bch_btree_insert(c, id, &keylist_single(k), NULL, NULL, 0);
if (ret)
return ret;
diff --git a/drivers/md/bcache/migrate.c b/drivers/md/bcache/migrate.c
index 09c0b8137d73..65727374b804 100644
--- a/drivers/md/bcache/migrate.c
+++ b/drivers/md/bcache/migrate.c
@@ -163,8 +163,8 @@ static int issue_migration_move(struct cache *ca,
/* This also copies k into the write op's replace_key and insert_key */
- bch_write_op_init(&io->op, c, &io->bio,
- wp, k, k, BCH_WRITE_CHECK_ENOSPC);
+ bch_write_op_init(&io->op, c, &io->bio, wp, k, k,
+ NULL, BCH_WRITE_CHECK_ENOSPC);
BUG_ON(q->wq == NULL);
io->op.io_wq = q->wq;
diff --git a/drivers/md/bcache/movinggc.c b/drivers/md/bcache/movinggc.c
index 91cba2715773..95d67b8de4c4 100644
--- a/drivers/md/bcache/movinggc.c
+++ b/drivers/md/bcache/movinggc.c
@@ -60,7 +60,7 @@ static int issue_moving_gc_move(struct moving_queue *q,
}
bch_write_op_init(&io->op, c, &io->bio, NULL,
- bkey_i_to_s_c(k), bkey_i_to_s_c(k),
+ bkey_i_to_s_c(k), bkey_i_to_s_c(k), NULL,
bkey_extent_is_cached(&k->k)
? BCH_WRITE_CACHED : 0);
diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c
index 6538df0ea499..7d2145689482 100644
--- a/drivers/md/bcache/request.c
+++ b/drivers/md/bcache/request.c
@@ -555,7 +555,8 @@ static void cached_dev_write(struct cached_dev *dc, struct search *s)
flags |= BCH_WRITE_DISCARD;
bch_write_op_init(&s->iop, dc->disk.c, &s->bio, NULL,
- bkey_to_s_c(&insert_key), bkey_s_c_null, flags);
+ bkey_to_s_c(&insert_key), bkey_s_c_null,
+ NULL, flags);
closure_call(&s->iop.cl, bch_write, NULL, cl);
continue_at(cl, cached_dev_write_complete, NULL);
@@ -687,7 +688,7 @@ static void __blockdev_volume_make_request(struct request_queue *q,
bch_write_op_init(&s->iop, d->c, &s->bio, NULL,
bkey_to_s_c(&KEY(s->inode, 0, 0)),
- bkey_s_c_null, flags);
+ bkey_s_c_null, NULL, flags);
closure_call(&s->iop.cl, bch_write, NULL, &s->cl);
continue_at(&s->cl, search_free, NULL);
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 44c15a371f78..6c0c44274c1e 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -1286,7 +1286,7 @@ static const char *run_cache_set(struct cache_set *c)
err = "error creating root directory";
if (bch_btree_insert(c, BTREE_ID_INODES,
&keylist_single(&inode.k_i),
- NULL, NULL, NULL, 0))
+ NULL, NULL, 0))
goto err;
bch_journal_meta(&c->journal, &cl);
diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c
index 02a31295220b..90c0078d7fd7 100644
--- a/drivers/md/bcache/sysfs.c
+++ b/drivers/md/bcache/sysfs.c
@@ -286,6 +286,9 @@ STORE(__cached_dev)
}
if (attr == &sysfs_label) {
+ u64 journal_seq = 0;
+ int ret = 0;
+
if (size > SB_LABEL_SIZE)
return -EINVAL;
@@ -303,11 +306,17 @@ STORE(__cached_dev)
bch_write_bdev_super(dc, NULL);
if (dc->disk.c)
- bch_inode_update(dc->disk.c, &dc->disk.inode.k_i,
- &cl, NULL);
+ ret = bch_inode_update(dc->disk.c, &dc->disk.inode.k_i,
+ &journal_seq);
mutex_unlock(&dc->disk.inode_lock);
+ if (ret)
+ return ret;
+
+ if (dc->disk.c)
+ bch_journal_push_seq(&dc->disk.c->journal,
+ journal_seq, &cl);
closure_sync(&cl);
env = kzalloc(sizeof(struct kobj_uevent_env), GFP_KERNEL);
@@ -422,29 +431,49 @@ STORE(__bch_blockdev_volume)
sysfs_strtoul(data_csum, d->data_csum);
if (attr == &sysfs_size) {
+ u64 journal_seq = 0;
u64 v = strtoi_h_or_return(buf);
+ int ret;
mutex_lock(&d->inode_lock);
- if (v < d->inode.v.i_inode.i_size)
- bch_inode_truncate(d->c, d->inode.k.p.inode, v >> 9);
+ if (v < d->inode.v.i_inode.i_size) {
+ ret = bch_inode_truncate(d->c, d->inode.k.p.inode,
+ v >> 9);
+ if (ret) {
+ mutex_unlock(&d->inode_lock);
+ return ret;
+ }
+ }
d->inode.v.i_inode.i_size = v;
- bch_inode_update(d->c, &d->inode.k_i, &cl, NULL);
- set_capacity(d->disk, d->inode.v.i_inode.i_size >> 9);
+ ret = bch_inode_update(d->c, &d->inode.k_i, &journal_seq);
mutex_unlock(&d->inode_lock);
+ if (ret)
+ return ret;
+
+ bch_journal_push_seq(&d->c->journal, journal_seq, &cl);
closure_sync(&cl);
+
+ set_capacity(d->disk, d->inode.v.i_inode.i_size >> 9);
}
if (attr == &sysfs_label) {
+ u64 journal_seq = 0;
+ int ret;
+
mutex_lock(&d->inode_lock);
memcpy(d->inode.v.i_label, buf, SB_LABEL_SIZE);
- bch_inode_update(d->c, &d->inode.k_i, &cl, NULL);
+ ret = bch_inode_update(d->c, &d->inode.k_i, &journal_seq);
mutex_unlock(&d->inode_lock);
+ if (ret)
+ return ret;
+
+ bch_journal_push_seq(&d->c->journal, journal_seq, &cl);
closure_sync(&cl);
}
diff --git a/drivers/md/bcache/tier.c b/drivers/md/bcache/tier.c
index 62108446b82d..abf8d7a66e6d 100644
--- a/drivers/md/bcache/tier.c
+++ b/drivers/md/bcache/tier.c
@@ -222,7 +222,7 @@ static int issue_tiering_move(struct moving_queue *q,
bch_write_op_init(&io->op, c, &io->bio,
&ca->tiering_write_point,
bkey_i_to_s_c(&io->key),
- bkey_i_to_s_c(&io->key), 0);
+ bkey_i_to_s_c(&io->key), NULL, 0);
io->op.io_wq = q->wq;
trace_bcache_tiering_copy(k.k);
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 6c1ef352e188..34bec1106f0e 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -118,7 +118,7 @@ static void write_dirty_finish(struct closure *cl)
ret = bch_btree_insert(dc->disk.c, BTREE_ID_EXTENTS,
&keylist_single(&tmp.k),
- &io->replace, NULL, NULL, 0);
+ &io->replace, NULL, 0);
if (io->replace.successes == 0)
trace_bcache_writeback_collision(&io->replace.key.k);