summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2018-04-15 01:21:07 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2018-05-04 13:46:00 -0400
commit62c8bbbef93bcea63241f952da9972696d4af585 (patch)
tree37bcc1defdff4abfed405309d74889f903075e2d
parent0e643b2d53dccd7cdb90959a002417eae9c8a011 (diff)
bcachefs: refactor some init code
-rw-r--r--fs/bcachefs/io.c26
-rw-r--r--fs/bcachefs/io.h3
-rw-r--r--fs/bcachefs/super.c17
3 files changed, 31 insertions, 15 deletions
diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c
index 9cc37dba1d83..16bca0580929 100644
--- a/fs/bcachefs/io.c
+++ b/fs/bcachefs/io.c
@@ -1631,3 +1631,29 @@ void bch2_read(struct bch_fs *c, struct bch_read_bio *rbio, u64 inode)
bcache_io_error(c, &rbio->bio, "btree IO error %i", ret);
bio_endio(&rbio->bio);
}
+
+void bch2_fs_io_exit(struct bch_fs *c)
+{
+ mempool_exit(&c->bio_bounce_pages);
+ bioset_exit(&c->bio_write);
+ bioset_exit(&c->bio_read_split);
+ bioset_exit(&c->bio_read);
+}
+
+int bch2_fs_io_init(struct bch_fs *c)
+{
+ if (bioset_init(&c->bio_read, 1, offsetof(struct bch_read_bio, bio),
+ BIOSET_NEED_BVECS) ||
+ bioset_init(&c->bio_read_split, 1, offsetof(struct bch_read_bio, bio),
+ BIOSET_NEED_BVECS) ||
+ bioset_init(&c->bio_write, 1, offsetof(struct bch_write_bio, bio),
+ BIOSET_NEED_BVECS) ||
+ mempool_init_page_pool(&c->bio_bounce_pages,
+ max_t(unsigned,
+ c->opts.btree_node_size,
+ c->sb.encoded_extent_max) /
+ PAGE_SECTORS, 0))
+ return -ENOMEM;
+
+ return 0;
+}
diff --git a/fs/bcachefs/io.h b/fs/bcachefs/io.h
index ac7becbd5f21..8562a5d01e37 100644
--- a/fs/bcachefs/io.h
+++ b/fs/bcachefs/io.h
@@ -134,4 +134,7 @@ static inline struct bch_read_bio *rbio_init(struct bio *bio,
return rbio;
}
+void bch2_fs_io_exit(struct bch_fs *);
+int bch2_fs_io_init(struct bch_fs *);
+
#endif /* _BCACHEFS_IO_H */
diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c
index 9d14e873eb1c..c5aacb4ce852 100644
--- a/fs/bcachefs/super.c
+++ b/fs/bcachefs/super.c
@@ -401,6 +401,7 @@ static void bch2_fs_free(struct bch_fs *c)
bch2_fs_quota_exit(c);
bch2_fs_fsio_exit(c);
bch2_fs_encryption_exit(c);
+ bch2_fs_io_exit(c);
bch2_fs_btree_cache_exit(c);
bch2_fs_journal_exit(&c->journal);
bch2_io_clock_exit(&c->io_clock[WRITE]);
@@ -409,10 +410,6 @@ static void bch2_fs_free(struct bch_fs *c)
lg_lock_free(&c->usage_lock);
free_percpu(c->usage_percpu);
mempool_exit(&c->btree_bounce_pool);
- mempool_exit(&c->bio_bounce_pages);
- bioset_exit(&c->bio_write);
- bioset_exit(&c->bio_read_split);
- bioset_exit(&c->bio_read);
bioset_exit(&c->btree_bio);
mempool_exit(&c->btree_interior_update_pool);
mempool_exit(&c->btree_reserve_pool);
@@ -642,17 +639,6 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
max(offsetof(struct btree_read_bio, bio),
offsetof(struct btree_write_bio, wbio.bio)),
BIOSET_NEED_BVECS) ||
- bioset_init(&c->bio_read, 1, offsetof(struct bch_read_bio, bio),
- BIOSET_NEED_BVECS) ||
- bioset_init(&c->bio_read_split, 1, offsetof(struct bch_read_bio, bio),
- BIOSET_NEED_BVECS) ||
- bioset_init(&c->bio_write, 1, offsetof(struct bch_write_bio, bio),
- BIOSET_NEED_BVECS) ||
- mempool_init_page_pool(&c->bio_bounce_pages,
- max_t(unsigned,
- c->opts.btree_node_size,
- c->sb.encoded_extent_max) /
- PAGE_SECTORS, 0) ||
!(c->usage_percpu = alloc_percpu(struct bch_fs_usage)) ||
lg_lock_init(&c->usage_lock) ||
mempool_init_vp_pool(&c->btree_bounce_pool, 1, btree_bytes(c)) ||
@@ -660,6 +646,7 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts)
bch2_io_clock_init(&c->io_clock[WRITE]) ||
bch2_fs_journal_init(&c->journal) ||
bch2_fs_btree_cache_init(c) ||
+ bch2_fs_io_init(c) ||
bch2_fs_encryption_init(c) ||
bch2_fs_compress_init(c) ||
bch2_fs_fsio_init(c))