bcachefs: Turn encoded_extent_max into a regular option

It'll now be handled at format time and in sysfs like other options - it
still can only be set at format time, though.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
This commit is contained in:
Kent Overstreet 2021-12-14 14:34:03 -05:00 committed by Kent Overstreet
parent 8244f3209b
commit e409999069
7 changed files with 25 additions and 22 deletions

View file

@ -634,7 +634,6 @@ struct bch_fs {
u16 version;
u16 version_min;
u16 encoded_extent_max;
u8 nr_devices;
u8 clean;

View file

@ -26,7 +26,7 @@ static struct bbuf __bounce_alloc(struct bch_fs *c, unsigned size, int rw)
{
void *b;
BUG_ON(size > c->sb.encoded_extent_max << 9);
BUG_ON(size > c->opts.encoded_extent_max);
b = kmalloc(size, GFP_NOIO|__GFP_NOWARN);
if (b)
@ -68,7 +68,7 @@ static struct bbuf __bio_map_or_bounce(struct bch_fs *c, struct bio *bio,
struct page **pages = NULL;
void *data;
BUG_ON(bvec_iter_sectors(start) > c->sb.encoded_extent_max);
BUG_ON(start.bi_size > c->opts.encoded_extent_max);
if (!PageHighMem(bio_iter_page(bio, start)) &&
bio_phys_contig(bio, start))
@ -231,8 +231,8 @@ int bch2_bio_uncompress_inplace(struct bch_fs *c, struct bio *bio,
BUG_ON(!bio->bi_vcnt);
BUG_ON(DIV_ROUND_UP(crc->live_size, PAGE_SECTORS) > bio->bi_max_vecs);
if (crc->uncompressed_size > c->sb.encoded_extent_max ||
crc->compressed_size > c->sb.encoded_extent_max) {
if (crc->uncompressed_size << 9 > c->opts.encoded_extent_max ||
crc->compressed_size << 9 > c->opts.encoded_extent_max) {
bch_err(c, "error rewriting existing data: extent too big");
return -EIO;
}
@ -272,8 +272,8 @@ int bch2_bio_uncompress(struct bch_fs *c, struct bio *src,
size_t dst_len = crc.uncompressed_size << 9;
int ret = -ENOMEM;
if (crc.uncompressed_size > c->sb.encoded_extent_max ||
crc.compressed_size > c->sb.encoded_extent_max)
if (crc.uncompressed_size << 9 > c->opts.encoded_extent_max ||
crc.compressed_size << 9 > c->opts.encoded_extent_max)
return -EIO;
dst_data = dst_len == dst_iter.bi_size
@ -466,7 +466,7 @@ unsigned bch2_bio_compress(struct bch_fs *c,
/* Don't consume more than BCH_ENCODED_EXTENT_MAX from @src: */
src->bi_iter.bi_size = min_t(unsigned, src->bi_iter.bi_size,
c->sb.encoded_extent_max << 9);
c->opts.encoded_extent_max);
/* Don't generate a bigger output than input: */
dst->bi_iter.bi_size = min(dst->bi_iter.bi_size, src->bi_iter.bi_size);
@ -544,10 +544,9 @@ void bch2_fs_compress_exit(struct bch_fs *c)
static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
{
size_t max_extent = c->sb.encoded_extent_max << 9;
size_t decompress_workspace_size = 0;
bool decompress_workspace_needed;
ZSTD_parameters params = zstd_get_params(0, max_extent);
ZSTD_parameters params = zstd_get_params(0, c->opts.encoded_extent_max);
struct {
unsigned feature;
unsigned type;
@ -579,14 +578,14 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
if (!mempool_initialized(&c->compression_bounce[READ])) {
ret = mempool_init_kvpmalloc_pool(&c->compression_bounce[READ],
1, max_extent);
1, c->opts.encoded_extent_max);
if (ret)
goto out;
}
if (!mempool_initialized(&c->compression_bounce[WRITE])) {
ret = mempool_init_kvpmalloc_pool(&c->compression_bounce[WRITE],
1, max_extent);
1, c->opts.encoded_extent_max);
if (ret)
goto out;
}

View file

@ -1152,7 +1152,7 @@ static void ec_stripe_key_init(struct bch_fs *c,
s->v.algorithm = 0;
s->v.nr_blocks = nr_data + nr_parity;
s->v.nr_redundant = nr_parity;
s->v.csum_granularity_bits = ilog2(c->sb.encoded_extent_max);
s->v.csum_granularity_bits = ilog2(c->opts.encoded_extent_max >> 9);
s->v.csum_type = BCH_CSUM_crc32c;
s->v.pad = 0;

View file

@ -302,7 +302,7 @@ bool bch2_extent_merge(struct bch_fs *c, struct bkey_s l, struct bkey_s_c r)
if (lp.crc.csum_type &&
lp.crc.uncompressed_size +
rp.crc.uncompressed_size > c->sb.encoded_extent_max)
rp.crc.uncompressed_size > (c->opts.encoded_extent_max >> 9))
return false;
if (lp.crc.uncompressed_size + rp.crc.uncompressed_size >

View file

@ -806,7 +806,7 @@ static struct bio *bch2_write_bio_alloc(struct bch_fs *c,
*/
bch2_bio_alloc_pages_pool(c, bio,
min_t(unsigned, output_available,
c->sb.encoded_extent_max << 9));
c->opts.encoded_extent_max));
if (bio->bi_iter.bi_size < output_available)
*page_alloc_failed =
@ -1003,8 +1003,8 @@ static int bch2_write_extent(struct bch_write_op *op, struct write_point *wp,
size_t dst_len, src_len;
if (page_alloc_failed &&
bio_sectors(dst) < wp->sectors_free &&
bio_sectors(dst) < c->sb.encoded_extent_max)
dst->bi_iter.bi_size < (wp->sectors_free << 9) &&
dst->bi_iter.bi_size < c->opts.encoded_extent_max)
break;
BUG_ON(op->compression_type &&
@ -1024,7 +1024,7 @@ static int bch2_write_extent(struct bch_write_op *op, struct write_point *wp,
if (op->csum_type)
dst_len = min_t(unsigned, dst_len,
c->sb.encoded_extent_max << 9);
c->opts.encoded_extent_max);
if (bounce) {
swap(dst->bi_iter.bi_size, dst_len);
@ -2437,9 +2437,9 @@ int bch2_fs_io_init(struct bch_fs *c)
BIOSET_NEED_BVECS) ||
mempool_init_page_pool(&c->bio_bounce_pages,
max_t(unsigned,
btree_sectors(c),
c->sb.encoded_extent_max) /
PAGE_SECTORS, 0) ||
c->opts.btree_node_size,
c->opts.encoded_extent_max) /
PAGE_SIZE, 0) ||
rhashtable_init(&c->promote_table, &bch_promote_params))
return -ENOMEM;

View file

@ -127,6 +127,12 @@ enum opt_type {
OPT_UINT(1, BCH_REPLICAS_MAX), \
BCH_SB_DATA_REPLICAS_REQ, 1, \
"#", NULL) \
x(encoded_extent_max, u32, \
OPT_FS|OPT_FORMAT| \
OPT_HUMAN_READABLE|OPT_MUST_BE_POW_2|OPT_SB_FIELD_SECTORS|OPT_SB_FIELD_ILOG2,\
OPT_UINT(4096, 2U << 20), \
BCH_SB_ENCODED_EXTENT_MAX_BITS, 64 << 10, \
"size", "Maximum size of checksummed/compressed extents")\
x(metadata_checksum, u8, \
OPT_FS|OPT_FORMAT|OPT_MOUNT|OPT_RUNTIME, \
OPT_STR(bch2_csum_opts), \

View file

@ -368,7 +368,6 @@ static void bch2_sb_update(struct bch_fs *c)
c->sb.nr_devices = src->nr_devices;
c->sb.clean = BCH_SB_CLEAN(src);
c->sb.encryption_type = BCH_SB_ENCRYPTION_TYPE(src);
c->sb.encoded_extent_max= 1 << BCH_SB_ENCODED_EXTENT_MAX_BITS(src);
c->sb.nsec_per_time_unit = le32_to_cpu(src->time_precision);
c->sb.time_units_per_sec = NSEC_PER_SEC / c->sb.nsec_per_time_unit;