diff options
-rw-r--r-- | drivers/md/bcache/btree_io.c | 2 | ||||
-rw-r--r-- | drivers/md/bcache/extents.c | 2 | ||||
-rw-r--r-- | drivers/md/bcache/extents.h | 1 | ||||
-rw-r--r-- | drivers/md/bcache/fs-io.c | 17 | ||||
-rw-r--r-- | drivers/md/bcache/io.c | 102 | ||||
-rw-r--r-- | drivers/md/bcache/io.h | 12 | ||||
-rw-r--r-- | drivers/md/bcache/io_types.h | 5 | ||||
-rw-r--r-- | drivers/md/bcache/move.c | 6 | ||||
-rw-r--r-- | drivers/md/bcache/request.c | 18 |
9 files changed, 64 insertions, 101 deletions
diff --git a/drivers/md/bcache/btree_io.c b/drivers/md/bcache/btree_io.c index eb7378509f56..9108b24556b0 100644 --- a/drivers/md/bcache/btree_io.c +++ b/drivers/md/bcache/btree_io.c @@ -650,7 +650,7 @@ static void do_btree_node_write(struct closure *cl) b->written += sectors_to_write; - bch_submit_bbio_replicas(wbio, c, &k.key, 0, true); + bch_submit_bbio_replicas(wbio, c, &k.key, true); continue_at(cl, btree_node_write_done, NULL); } diff --git a/drivers/md/bcache/extents.c b/drivers/md/bcache/extents.c index 380ee86d0da4..ec7482df32de 100644 --- a/drivers/md/bcache/extents.c +++ b/drivers/md/bcache/extents.c @@ -314,7 +314,7 @@ static bool should_drop_ptr(const struct cache_set *c, return (ca = PTR_CACHE(c, ptr)) && ptr_stale(ca, ptr); } -void bch_extent_drop_stale(struct cache_set *c, struct bkey_s_extent e) +static void bch_extent_drop_stale(struct cache_set *c, struct bkey_s_extent e) { struct bch_extent_ptr *ptr = &e.v->start->ptr; bool dropped = false; diff --git a/drivers/md/bcache/extents.h b/drivers/md/bcache/extents.h index 3024fb539335..c87630f50111 100644 --- a/drivers/md/bcache/extents.h +++ b/drivers/md/bcache/extents.h @@ -60,7 +60,6 @@ bch_insert_fixup_extent(struct btree_insert *, struct btree_insert_entry *, struct journal_res *); -void bch_extent_drop_stale(struct cache_set *c, struct bkey_s_extent); bool bch_extent_normalize(struct cache_set *, struct bkey_s); unsigned bch_extent_nr_ptrs_from(struct bkey_s_c_extent, diff --git a/drivers/md/bcache/fs-io.c b/drivers/md/bcache/fs-io.c index 6062da0a8622..6509545ba3c4 100644 --- a/drivers/md/bcache/fs-io.c +++ b/drivers/md/bcache/fs-io.c @@ -829,8 +829,7 @@ static void bch_writepage_io_done(struct closure *cl) static void bch_writepage_do_io(struct bch_writepage_io *io) { - io->op.op.insert_key.k.p.offset = bio_end_sector(&io->bio.bio.bio); - io->op.op.insert_key.k.size = bio_sectors(&io->bio.bio.bio); + io->op.op.pos.offset = io->bio.bio.bio.bi_iter.bi_sector; closure_call(&io->op.op.cl, bch_write, NULL, &io->cl); continue_at(&io->cl, bch_writepage_io_done, NULL); @@ -859,9 +858,9 @@ alloc_io: (struct disk_reservation) { .nr_replicas = w->c->opts.data_replicas, }, - NULL, - bkey_to_s_c(&KEY(w->inum, 0, 0)), - NULL, &ei->journal_seq, 0); + foreground_write_point(w->c, ei->vfs_inode.i_ino), + POS(w->inum, 0), + &ei->journal_seq, 0); w->io->op.op.index_update_fn = bchfs_write_index_update; } @@ -1309,11 +1308,9 @@ static void bch_do_direct_IO_write(struct dio_write *dio) dio->iop.new_i_size = U64_MAX; bch_write_op_init(&dio->iop.op, dio->c, &dio->bio, dio->res, - NULL, - bkey_to_s_c(&KEY(inode->i_ino, - bio_end_sector(bio), - bio_sectors(bio))), - NULL, &ei->journal_seq, flags); + foreground_write_point(dio->c, inode->i_ino), + POS(inode->i_ino, bio->bi_iter.bi_sector), + &ei->journal_seq, flags); dio->iop.op.index_update_fn = bchfs_write_index_update; dio->res.sectors -= bio_sectors(bio); diff --git a/drivers/md/bcache/io.c b/drivers/md/bcache/io.c index e383e6c561de..0d24dbab5b3b 100644 --- a/drivers/md/bcache/io.c +++ b/drivers/md/bcache/io.c @@ -25,6 +25,7 @@ #include <linux/blkdev.h> #include <linux/lz4.h> +#include <linux/random.h> #include <linux/zlib.h> #include <trace/events/bcache.h> @@ -140,20 +141,15 @@ void bch_submit_bbio(struct bbio *b, struct cache *ca, } void bch_submit_bbio_replicas(struct bch_write_bio *bio, struct cache_set *c, - const struct bkey_i *k, unsigned ptrs_from, - bool punt) + const struct bkey_i *k, bool punt) { struct bkey_s_c_extent e = bkey_i_to_s_c_extent(k); const struct bch_extent_ptr *ptr; struct cache *ca; - unsigned ptr_idx = 0; BUG_ON(bio->orig); extent_for_each_ptr(e, ptr) { - if (ptr_idx++ < ptrs_from) - continue; - rcu_read_lock(); ca = PTR_CACHE(c, ptr); if (ca) @@ -661,8 +657,7 @@ static int bch_write_index_default(struct bch_write_op *op) bkey_start_pos(&bch_keylist_front(keys)->k)); ret = bch_btree_insert_list_at(&iter, keys, &op->res, - op->insert_hook, - op_journal_seq(op), + NULL, op_journal_seq(op), BTREE_INSERT_NOFAIL); bch_btree_iter_unlock(&iter); @@ -723,12 +718,11 @@ static void bch_write_discard(struct closure *cl) { struct bch_write_op *op = container_of(cl, struct bch_write_op, cl); struct bio *bio = &op->bio->bio.bio; - u64 inode = op->insert_key.k.p.inode; + struct bpos end = op->pos; + + end.offset += bio_sectors(bio); - op->error = bch_discard(op->c, - POS(inode, bio->bi_iter.bi_sector), - POS(inode, bio_end_sector(bio)), - op->insert_key.k.version, + op->error = bch_discard(op->c, op->pos, end, op->version, &op->res, NULL, NULL); } @@ -813,9 +807,9 @@ static int bch_write_extent(struct bch_write_op *op, struct cache_set *c = op->c; struct bio *bio; struct bch_write_bio *wbio; - unsigned ptrs_from = bch_extent_nr_ptrs(extent_i_to_s_c(e)); unsigned csum_type = c->opts.data_checksum; unsigned compression_type = op->compression_type; + int ret; /* don't refetch csum type/compression type */ barrier(); @@ -849,6 +843,7 @@ static int bch_write_extent(struct bch_write_op *op, wbio->orig = NULL; wbio->bounce = false; wbio->split = false; + ret = 0; } else if (csum_type != BCH_CSUM_NONE || compression_type != BCH_COMPRESSION_NONE) { /* all units here in bytes */ @@ -912,7 +907,7 @@ static int bch_write_extent(struct bch_write_op *op, e, op->nr_replicas, ob, bio_sectors(bio)); - bch_extent_narrow_crcs(extent_i_to_s(e)); + ret = orig->bi_iter.bi_size != 0; } else { if (e->k.size > ob->sectors_free) bch_key_resize(&e->k, ob->sectors_free); @@ -935,6 +930,8 @@ static int bch_write_extent(struct bch_write_op *op, wbio->orig = NULL; wbio->bounce = false; wbio->split = bio != orig; + + ret = bio != orig; } bio->bi_end_io = bch_write_endio; @@ -942,14 +939,13 @@ static int bch_write_extent(struct bch_write_op *op, bio_set_op_attrs(bio, REQ_OP_WRITE, 0); #ifndef CONFIG_BCACHE_NO_IO - bch_submit_bbio_replicas(wbio, op->c, &e->k_i, ptrs_from, false); + bch_submit_bbio_replicas(wbio, op->c, &e->k_i, false); #else - ptrs_from = ptrs_from; bch_bbio_prep(&wbio->bio, NULL); closure_get(bio->bi_private); bio_endio(bio); #endif - return 0; + return ret; } static void __bch_write(struct closure *cl) @@ -969,10 +965,6 @@ static void __bch_write(struct closure *cl) continue_at(cl, bch_write_done, op->c->wq); } - if (bkey_extent_is_data(&op->insert_key.k)) - bch_extent_drop_stale(op->c, - bkey_i_to_s_extent(&op->insert_key)); - /* * Journal writes are marked REQ_PREFLUSH; if the original write was a * flush, it'll wait on the journal write. @@ -982,12 +974,7 @@ static void __bch_write(struct closure *cl) do { struct bkey_i *k; - EBUG_ON(bio->bi_iter.bi_sector != - bkey_start_offset(&op->insert_key.k)); - EBUG_ON(bio_sectors(bio) != - ((op->flags & BCH_WRITE_DATA_COMPRESSED) - ? op->crc.compressed_size - : op->insert_key.k.size)); + EBUG_ON(bio->bi_iter.bi_sector != op->pos.offset); EBUG_ON(!bio_sectors(bio)); if (open_bucket_nr == ARRAY_SIZE(op->open_buckets)) @@ -999,7 +986,9 @@ static void __bch_write(struct closure *cl) continue_at(cl, bch_write_index, op->c->wq); k = op->insert_keys.top; - bkey_copy(k, &op->insert_key); + bkey_extent_init(k); + k->k.p = op->pos; + bch_key_resize(&k->k, bio_sectors(bio)); b = bch_alloc_sectors_start(op->c, op->wp, bkey_i_to_extent(k), op->nr_replicas, @@ -1043,15 +1032,10 @@ static void __bch_write(struct closure *cl) op->open_buckets[open_bucket_nr++] = b; ret = bch_write_extent(op, b, bkey_i_to_extent(k), bio); - if (ret) + if (ret < 0) goto err; - bch_cut_front(k->k.p, &op->insert_key); - - EBUG_ON(op->insert_key.k.size && - op->insert_key.k.size != bio_sectors(bio)); - - bch_extent_normalize(op->c, bkey_i_to_s(k)); + op->pos.offset += k->k.size; bkey_extent_set_cached(&k->k, (op->flags & BCH_WRITE_CACHED)); @@ -1061,7 +1045,7 @@ static void __bch_write(struct closure *cl) bch_keylist_enqueue(&op->insert_keys); trace_bcache_cache_insert(&k->k); - } while (op->insert_key.k.size); + } while (ret); op->flags |= BCH_WRITE_DONE; continue_at(cl, bch_write_index, op->c->wq); @@ -1149,10 +1133,10 @@ void bch_write(struct closure *cl) struct bch_write_op *op = container_of(cl, struct bch_write_op, cl); struct bio *bio = &op->bio->bio.bio; struct cache_set *c = op->c; - u64 inode = op->insert_key.k.p.inode; + u64 inode = op->pos.inode; trace_bcache_write(c, inode, bio, - !bkey_extent_is_cached(&op->insert_key.k), + !(op->flags & BCH_WRITE_CACHED), op->flags & BCH_WRITE_DISCARD); if (!percpu_ref_tryget(&c->writes)) { @@ -1215,18 +1199,9 @@ void bch_write(struct closure *cl) void bch_write_op_init(struct bch_write_op *op, struct cache_set *c, struct bch_write_bio *bio, struct disk_reservation res, - struct write_point *wp, struct bkey_s_c insert_key, - struct extent_insert_hook *insert_hook, + struct write_point *wp, struct bpos pos, u64 *journal_seq, unsigned flags) { - if (!wp) { - unsigned wp_idx = hash_long((unsigned long) current, - ilog2(ARRAY_SIZE(c->write_points))); - - BUG_ON(wp_idx > ARRAY_SIZE(c->write_points)); - wp = &c->write_points[wp_idx]; - } - op->c = c; op->io_wq = op->c->wq; op->bio = bio; @@ -1235,6 +1210,8 @@ void bch_write_op_init(struct bch_write_op *op, struct cache_set *c, op->flags = flags; op->compression_type = c->opts.compression; op->nr_replicas = res.nr_replicas; + op->pos = pos; + op->version = 0; op->res = res; op->wp = wp; @@ -1245,28 +1222,14 @@ void bch_write_op_init(struct bch_write_op *op, struct cache_set *c, op->journal_seq = 0; } - op->insert_hook = insert_hook; op->index_update_fn = bch_write_index_default; bch_keylist_init(&op->insert_keys, op->inline_keys, ARRAY_SIZE(op->inline_keys)); - bkey_reassemble(&op->insert_key, insert_key); - - if (!bkey_val_u64s(&op->insert_key.k)) { - /* - * If the new key has no pointers, we're either doing a - * discard or we're writing new data and we're going to - * allocate pointers - */ - op->insert_key.k.type = - (op->flags & BCH_WRITE_DISCARD) ? KEY_TYPE_DISCARD : - (op->flags & BCH_WRITE_CACHED) ? BCH_EXTENT_CACHED : - BCH_EXTENT; - } if (version_stress_test(c)) - op->insert_key.k.version = bch_rand_range(UINT_MAX); + get_random_bytes(&op->version, sizeof(op->version)); } /* Discard */ @@ -1649,17 +1612,14 @@ void bch_read_extent_iter(struct cache_set *c, struct bch_read_bio *orig, promote_bio->bi_iter.bi_size = k.k->size << 9; } else { /* - * Adjust insert_key to correspond to what we're - * actually reading: + * Set insert pos to correspond to what we're actually + * reading: */ - bch_cut_front(POS(k.k->p.inode, iter.bi_sector), - &promote_op->write.op.insert_key); - bch_key_resize(&promote_op->write.op.insert_key.k, - bvec_iter_sectors(iter)); + promote_op->write.op.pos.offset = iter.bi_sector; } promote_bio->bi_iter.bi_sector = - bkey_start_offset(&promote_op->write.op.insert_key.k); + promote_op->write.op.pos.offset; } /* _after_ promete stuff has looked at rbio->crc.offset */ diff --git a/drivers/md/bcache/io.h b/drivers/md/bcache/io.h index c6c4089003c7..3f611e652c64 100644 --- a/drivers/md/bcache/io.h +++ b/drivers/md/bcache/io.h @@ -39,11 +39,17 @@ static inline u64 *op_journal_seq(struct bch_write_op *op) ? op->journal_seq_p : &op->journal_seq; } +static inline struct write_point *foreground_write_point(struct cache_set *c, + unsigned long v) +{ + return c->write_points + + hash_long(v, ilog2(ARRAY_SIZE(c->write_points))); +} + void bch_write_op_init(struct bch_write_op *, struct cache_set *, struct bch_write_bio *, struct disk_reservation, struct write_point *, - struct bkey_s_c, - struct extent_insert_hook *, u64 *, unsigned); + struct bpos, u64 *, unsigned); void bch_write(struct closure *); struct cache_promote_op; @@ -81,7 +87,7 @@ void bch_bio_submit_work(struct work_struct *); void bch_submit_bbio(struct bbio *, struct cache *, const struct bch_extent_ptr *, bool); void bch_submit_bbio_replicas(struct bch_write_bio *, struct cache_set *, - const struct bkey_i *, unsigned, bool); + const struct bkey_i *, bool); int bch_discard(struct cache_set *, struct bpos, struct bpos, u64, struct disk_reservation *, diff --git a/drivers/md/bcache/io_types.h b/drivers/md/bcache/io_types.h index 50856c6ce207..4454c70799af 100644 --- a/drivers/md/bcache/io_types.h +++ b/drivers/md/bcache/io_types.h @@ -99,6 +99,9 @@ struct bch_write_op { unsigned compression_type:4; unsigned nr_replicas:4; + struct bpos pos; + unsigned version; + struct bch_extent_crc64 crc; struct disk_reservation res; @@ -122,11 +125,9 @@ struct bch_write_op { u64 journal_seq; }; - struct extent_insert_hook *insert_hook; int (*index_update_fn)(struct bch_write_op *); struct keylist insert_keys; - BKEY_PADDED(insert_key); u64 inline_keys[BKEY_EXTENT_U64s_MAX * 2]; }; diff --git a/drivers/md/bcache/move.c b/drivers/md/bcache/move.c index 218fc0c9b32a..dc44da658284 100644 --- a/drivers/md/bcache/move.c +++ b/drivers/md/bcache/move.c @@ -144,10 +144,8 @@ void bch_migrate_write_init(struct cache_set *c, bch_write_op_init(&m->op, c, &m->wbio, (struct disk_reservation) { 0 }, wp, - bkey_to_s_c(&KEY(k.k->p.inode, - k.k->p.offset, - k.k->size)), - NULL, NULL, flags); + bkey_start_pos(k.k), + NULL, flags); m->op.nr_replicas = 1; m->op.index_update_fn = bch_migrate_index_update; diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index fc760de6d997..a2006bfa9f0c 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -622,9 +622,11 @@ 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->wbio, - (struct disk_reservation) { 0 }, NULL, - bkey_to_s_c(&insert_key), - NULL, NULL, flags); + (struct disk_reservation) { 0 }, + foreground_write_point(dc->disk.c, + (unsigned long) current), + bkey_start_pos(&insert_key), + NULL, flags); closure_call(&s->iop.cl, bch_write, NULL, cl); continue_at(cl, cached_dev_write_complete, NULL); @@ -766,11 +768,11 @@ static void __blockdev_volume_make_request(struct request_queue *q, if (bio_op(bio) == REQ_OP_DISCARD) flags |= BCH_WRITE_DISCARD; - bch_write_op_init(&s->iop, d->c, &s->wbio, res, NULL, - bkey_to_s_c(&KEY(s->inode, - bio_end_sector(&s->wbio.bio.bio), - bio_sectors(&s->wbio.bio.bio))), - NULL, NULL, flags); + bch_write_op_init(&s->iop, d->c, &s->wbio, res, + foreground_write_point(d->c, + (unsigned long) current), + POS(s->inode, bio->bi_iter.bi_sector), + NULL, flags); closure_call(&s->iop.cl, bch_write, NULL, &s->cl); } else { |