summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
Diffstat (limited to 'fs')
-rw-r--r--fs/bcachefs/bcachefs_format.h3
-rw-r--r--fs/bcachefs/checksum.c3
-rw-r--r--fs/bcachefs/compress.c2
-rw-r--r--fs/bcachefs/extents.c7
-rw-r--r--fs/bcachefs/extents.h6
-rw-r--r--fs/bcachefs/io.c17
-rw-r--r--fs/bcachefs/sysfs.c3
-rw-r--r--fs/bcachefs/tier.c8
8 files changed, 30 insertions, 19 deletions
diff --git a/fs/bcachefs/bcachefs_format.h b/fs/bcachefs/bcachefs_format.h
index 0f2c9cecda72..007fec9284d5 100644
--- a/fs/bcachefs/bcachefs_format.h
+++ b/fs/bcachefs/bcachefs_format.h
@@ -370,7 +370,8 @@ enum bch_compression_type {
BCH_COMPRESSION_GZIP = 2,
BCH_COMPRESSION_LZ4 = 3,
BCH_COMPRESSION_ZSTD = 4,
- BCH_COMPRESSION_NR = 5,
+ BCH_COMPRESSION_INCOMPRESSIBLE = 5,
+ BCH_COMPRESSION_NR = 6,
};
enum bch_extent_entry_type {
diff --git a/fs/bcachefs/checksum.c b/fs/bcachefs/checksum.c
index 56bd99fd8b71..0777aacb5026 100644
--- a/fs/bcachefs/checksum.c
+++ b/fs/bcachefs/checksum.c
@@ -460,7 +460,7 @@ int bch2_rechecksum_bio(struct bch_fs *c, struct bio *bio,
BUG_ON(len_a + len_b > bio_sectors(bio));
BUG_ON(crc_old.uncompressed_size != bio_sectors(bio));
- BUG_ON(crc_old.compression_type);
+ BUG_ON(crc_is_compressed(crc_old));
BUG_ON(bch2_csum_type_is_encryption(crc_old.csum_type) !=
bch2_csum_type_is_encryption(new_csum_type));
@@ -489,6 +489,7 @@ int bch2_rechecksum_bio(struct bch_fs *c, struct bio *bio,
if (i->crc)
*i->crc = (struct bch_extent_crc_unpacked) {
.csum_type = i->csum_type,
+ .compression_type = crc_old.compression_type,
.compressed_size = i->len,
.uncompressed_size = i->len,
.offset = 0,
diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
index 18c945985636..2e1f402b6538 100644
--- a/fs/bcachefs/compress.c
+++ b/fs/bcachefs/compress.c
@@ -439,7 +439,7 @@ out:
bio_unmap_or_unbounce(c, dst_data);
return compression_type;
err:
- compression_type = 0;
+ compression_type = BCH_COMPRESSION_INCOMPRESSIBLE;
goto out;
}
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
index 9fbc642cf532..58f94264e395 100644
--- a/fs/bcachefs/extents.c
+++ b/fs/bcachefs/extents.c
@@ -228,7 +228,6 @@ unsigned bch2_extent_is_compressed(struct bkey_s_c k)
extent_for_each_ptr_crc(e, ptr, crc)
if (!ptr->cached &&
- crc.compression_type != BCH_COMPRESSION_NONE &&
crc.compressed_size < crc.live_size)
ret = max_t(unsigned, ret, crc.compressed_size);
}
@@ -272,7 +271,7 @@ void bch2_extent_drop_ptr(struct bkey_s_extent e, struct bch_extent_ptr *ptr)
static inline bool can_narrow_crc(struct bch_extent_crc_unpacked u,
struct bch_extent_crc_unpacked n)
{
- return !u.compression_type &&
+ return !crc_is_compressed(u) &&
u.csum_type &&
u.uncompressed_size > u.live_size &&
bch2_csum_type_is_encryption(u.csum_type) ==
@@ -314,7 +313,7 @@ bool bch2_extent_narrow_crcs(struct bkey_i_extent *e,
/* Find a checksum entry that covers only live data: */
if (!n.csum_type)
extent_for_each_crc(extent_i_to_s(e), u, i)
- if (!u.compression_type &&
+ if (!crc_is_compressed(u) &&
u.csum_type &&
u.live_size == u.uncompressed_size) {
n = u;
@@ -324,7 +323,7 @@ bool bch2_extent_narrow_crcs(struct bkey_i_extent *e,
if (!bch2_can_narrow_extent_crcs(extent_i_to_s_c(e), n))
return false;
- BUG_ON(n.compression_type);
+ BUG_ON(crc_is_compressed(n));
BUG_ON(n.offset);
BUG_ON(n.live_size != e->k.size);
diff --git a/fs/bcachefs/extents.h b/fs/bcachefs/extents.h
index 1ce0d38d278a..303bab983ee8 100644
--- a/fs/bcachefs/extents.h
+++ b/fs/bcachefs/extents.h
@@ -272,6 +272,12 @@ bch2_extent_crc_unpack(const struct bkey *k, const union bch_extent_crc *crc)
#undef common_fields
}
+static inline bool crc_is_compressed(struct bch_extent_crc_unpacked crc)
+{
+ return (crc.compression_type != BCH_COMPRESSION_NONE &&
+ crc.compression_type != BCH_COMPRESSION_INCOMPRESSIBLE);
+}
+
/* Extent entry iteration: */
#define extent_entry_next(_entry) \
diff --git a/fs/bcachefs/io.c b/fs/bcachefs/io.c
index 6624d8af574f..025b7b0c7fbe 100644
--- a/fs/bcachefs/io.c
+++ b/fs/bcachefs/io.c
@@ -480,8 +480,9 @@ static enum prep_encoded_ret {
/* Can we just write the entire extent as is? */
if (op->crc.uncompressed_size == op->crc.live_size &&
op->crc.compressed_size <= wp->sectors_free &&
- op->crc.compression_type == op->compression_type) {
- if (!op->crc.compression_type &&
+ (op->crc.compression_type == op->compression_type ||
+ op->crc.compression_type == BCH_COMPRESSION_INCOMPRESSIBLE)) {
+ if (!crc_is_compressed(op->crc) &&
op->csum_type != op->crc.csum_type &&
bch2_write_rechecksum(c, op, op->csum_type))
return PREP_ENCODED_CHECKSUM_ERR;
@@ -493,7 +494,7 @@ static enum prep_encoded_ret {
* If the data is compressed and we couldn't write the entire extent as
* is, we have to decompress it:
*/
- if (op->crc.compression_type) {
+ if (crc_is_compressed(op->crc)) {
struct bch_csum csum;
if (bch2_write_decrypt(op))
@@ -594,7 +595,7 @@ static int bch2_write_extent(struct bch_write_op *op, struct write_point *wp)
? bch2_bio_compress(c, dst, &dst_len, src, &src_len,
op->compression_type)
: 0;
- if (!crc.compression_type) {
+ if (!crc_is_compressed(crc)) {
dst_len = min(dst->bi_iter.bi_size, src->bi_iter.bi_size);
dst_len = min_t(unsigned, dst_len, wp->sectors_free << 9);
@@ -623,7 +624,7 @@ static int bch2_write_extent(struct bch_write_op *op, struct write_point *wp)
}
if ((op->flags & BCH_WRITE_DATA_ENCODED) &&
- !crc.compression_type &&
+ !crc_is_compressed(crc) &&
bch2_csum_type_is_encryption(op->crc.csum_type) ==
bch2_csum_type_is_encryption(op->csum_type)) {
/*
@@ -1099,7 +1100,7 @@ static void bch2_rbio_narrow_crcs(struct bch_read_bio *rbio)
unsigned offset;
int ret;
- if (rbio->pick.crc.compression_type)
+ if (crc_is_compressed(rbio->pick.crc))
return;
bch2_btree_iter_init(&iter, c, BTREE_ID_EXTENTS, rbio->pos,
@@ -1195,7 +1196,7 @@ static void __bch2_read_endio(struct work_struct *work)
crc.offset += rbio->bvec_iter.bi_sector - rbio->pos.offset;
crc.live_size = bvec_iter_sectors(rbio->bvec_iter);
- if (crc.compression_type != BCH_COMPRESSION_NONE) {
+ if (crc_is_compressed(crc)) {
bch2_encrypt_bio(c, crc.csum_type, nonce, src);
if (bch2_bio_uncompress(c, src, dst, dst_iter, crc))
goto decompression_err;
@@ -1287,7 +1288,7 @@ static void bch2_read_endio(struct bio *bio)
}
if (rbio->narrow_crcs ||
- rbio->pick.crc.compression_type ||
+ crc_is_compressed(rbio->pick.crc) ||
bch2_csum_type_is_encryption(rbio->pick.crc.csum_type))
context = RBIO_CONTEXT_UNBOUND, wq = system_unbound_wq;
else if (rbio->pick.crc.csum_type)
diff --git a/fs/bcachefs/sysfs.c b/fs/bcachefs/sysfs.c
index b7c1d03c412f..8cacac36cbe7 100644
--- a/fs/bcachefs/sysfs.c
+++ b/fs/bcachefs/sysfs.c
@@ -267,7 +267,8 @@ static ssize_t bch2_compression_stats(struct bch_fs *c, char *buf)
struct bch_extent_crc_unpacked crc;
extent_for_each_ptr_crc(e, ptr, crc) {
- if (crc.compression_type == BCH_COMPRESSION_NONE) {
+ if (crc.compression_type == BCH_COMPRESSION_NONE ||
+ crc.compression_type == BCH_COMPRESSION_INCOMPRESSIBLE) {
nr_uncompressed_extents++;
uncompressed_sectors += e.k->size;
} else {
diff --git a/fs/bcachefs/tier.c b/fs/bcachefs/tier.c
index 211a844c69cf..c12b649658b9 100644
--- a/fs/bcachefs/tier.c
+++ b/fs/bcachefs/tier.c
@@ -23,13 +23,15 @@ static inline bool rebalance_ptr_pred(struct bch_fs *c,
struct bch_dev *ca = bch_dev_bkey_exists(c, ptr->dev);
if (io_opts->background_target &&
- !dev_in_target(ca, io_opts->background_target) &&
- !ptr->cached)
+ !ptr->cached &&
+ !dev_in_target(ca, io_opts->background_target))
return true;
if (io_opts->background_compression &&
+ crc.compression_type != BCH_COMPRESSION_INCOMPRESSIBLE &&
crc.compression_type !=
- bch2_compression_opt_to_type[io_opts->background_compression])
+ bch2_compression_opt_to_type[io_opts->background_compression] &&
+ crc.compressed_size > c->opts.block_size)
return true;
return false;