summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fs/bcachefs/btree_update_interior.c19
-rw-r--r--fs/bcachefs/compress.c17
-rw-r--r--fs/bcachefs/compress.h36
-rw-r--r--fs/bcachefs/extents.c14
-rw-r--r--fs/bcachefs/extents.h1
5 files changed, 46 insertions, 41 deletions
diff --git a/fs/bcachefs/btree_update_interior.c b/fs/bcachefs/btree_update_interior.c
index 8084ca2dde3c..ebdb4d2f1be9 100644
--- a/fs/bcachefs/btree_update_interior.c
+++ b/fs/bcachefs/btree_update_interior.c
@@ -305,13 +305,18 @@ static struct btree *__bch2_btree_node_alloc(struct btree_trans *trans,
mutex_lock(&c->btree_reserve_cache_lock);
if (c->btree_reserve_cache_nr > nr_reserve) {
- struct btree_alloc *a =
- &c->btree_reserve_cache[--c->btree_reserve_cache_nr];
-
- bkey_copy(&b->key, &a->k);
- b->ob = a->ob;
- mutex_unlock(&c->btree_reserve_cache_lock);
- goto out;
+ for (struct btree_alloc *a = c->btree_reserve_cache;
+ a < c->btree_reserve_cache + c->btree_reserve_cache_nr;
+ a++) {
+ if (target && !bch2_bkey_in_target(c, bkey_i_to_s_c(&a->k), target))
+ continue;
+
+ bkey_copy(&b->key, &a->k);
+ b->ob = a->ob;
+ *a = c->btree_reserve_cache[--c->btree_reserve_cache_nr];
+ mutex_unlock(&c->btree_reserve_cache_lock);
+ goto out;
+ }
}
mutex_unlock(&c->btree_reserve_cache_lock);
retry:
diff --git a/fs/bcachefs/compress.c b/fs/bcachefs/compress.c
index b37b1f325f0a..5f74de920c92 100644
--- a/fs/bcachefs/compress.c
+++ b/fs/bcachefs/compress.c
@@ -336,7 +336,7 @@ static int attempt_compress(struct bch_fs *c,
void *workspace,
void *dst, size_t dst_len,
void *src, size_t src_len,
- struct bch_compression_opt compression)
+ union bch_compression_opt compression)
{
enum bch_compression_type compression_type =
__bch2_compression_opt_to_type[compression.type];
@@ -426,7 +426,7 @@ static int attempt_compress(struct bch_fs *c,
static unsigned __bio_compress(struct bch_fs *c,
struct bio *dst, size_t *dst_len,
struct bio *src, size_t *src_len,
- struct bch_compression_opt compression)
+ union bch_compression_opt compression)
{
struct bbuf src_data = { NULL }, dst_data = { NULL };
void *workspace;
@@ -553,7 +553,7 @@ unsigned bch2_bio_compress(struct bch_fs *c,
compression_type =
__bio_compress(c, dst, dst_len, src, src_len,
- bch2_compression_decode(compression_opt));
+ (union bch_compression_opt){ .value = compression_opt });
dst->bi_iter.bi_size = orig_dst;
src->bi_iter.bi_size = orig_src;
@@ -602,7 +602,8 @@ static int __bch2_check_set_has_compressed_data(struct bch_fs *c, u64 f)
int bch2_check_set_has_compressed_data(struct bch_fs *c,
unsigned compression_opt)
{
- unsigned compression_type = bch2_compression_decode(compression_opt).type;
+ unsigned int compression_type = ((union bch_compression_opt){ .value = compression_opt })
+ .type;
BUG_ON(compression_type >= ARRAY_SIZE(bch2_compression_opt_to_feature));
@@ -683,7 +684,7 @@ static int __bch2_fs_compress_init(struct bch_fs *c, u64 features)
static u64 compression_opt_to_feature(unsigned v)
{
- unsigned type = bch2_compression_decode(v).type;
+ unsigned int type = ((union bch_compression_opt){ .value = v }).type;
return BIT_ULL(bch2_compression_opt_to_feature[type]);
}
@@ -703,7 +704,7 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
{
char *val = kstrdup(_val, GFP_KERNEL);
char *p = val, *type_str, *level_str;
- struct bch_compression_opt opt = { 0 };
+ union bch_compression_opt opt = { 0 };
int ret;
if (!val)
@@ -736,7 +737,7 @@ int bch2_opt_compression_parse(struct bch_fs *c, const char *_val, u64 *res,
opt.level = level;
}
- *res = bch2_compression_encode(opt);
+ *res = opt.value;
err:
kfree(val);
return ret;
@@ -744,7 +745,7 @@ err:
void bch2_compression_opt_to_text(struct printbuf *out, u64 v)
{
- struct bch_compression_opt opt = bch2_compression_decode(v);
+ union bch_compression_opt opt = { .value = v };
if (opt.type < BCH_COMPRESSION_OPT_NR)
prt_str(out, bch2_compression_opts[opt.type]);
diff --git a/fs/bcachefs/compress.h b/fs/bcachefs/compress.h
index bec2f05bfd52..667ddb91d47a 100644
--- a/fs/bcachefs/compress.h
+++ b/fs/bcachefs/compress.h
@@ -10,41 +10,27 @@ static const unsigned __bch2_compression_opt_to_type[] = {
#undef x
};
-struct bch_compression_opt {
- u8 type:4,
- level:4;
-};
-
-static inline struct bch_compression_opt __bch2_compression_decode(unsigned v)
-{
- return (struct bch_compression_opt) {
- .type = v & 15,
- .level = v >> 4,
+union bch_compression_opt {
+ u8 value;
+ struct {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+ u8 type:4, level:4;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+ u8 level:4, type:4;
+#endif
};
-}
+};
static inline bool bch2_compression_opt_valid(unsigned v)
{
- struct bch_compression_opt opt = __bch2_compression_decode(v);
+ union bch_compression_opt opt = { .value = v };
return opt.type < ARRAY_SIZE(__bch2_compression_opt_to_type) && !(!opt.type && opt.level);
}
-static inline struct bch_compression_opt bch2_compression_decode(unsigned v)
-{
- return bch2_compression_opt_valid(v)
- ? __bch2_compression_decode(v)
- : (struct bch_compression_opt) { 0 };
-}
-
-static inline unsigned bch2_compression_encode(struct bch_compression_opt opt)
-{
- return opt.type|(opt.level << 4);
-}
-
static inline enum bch_compression_type bch2_compression_opt_to_type(unsigned v)
{
- return __bch2_compression_opt_to_type[bch2_compression_decode(v).type];
+ return __bch2_compression_opt_to_type[((union bch_compression_opt){ .value = v }).type];
}
struct bch_write_op;
diff --git a/fs/bcachefs/extents.c b/fs/bcachefs/extents.c
index 83cbd77dcb9c..a286bd994101 100644
--- a/fs/bcachefs/extents.c
+++ b/fs/bcachefs/extents.c
@@ -1023,6 +1023,18 @@ bool bch2_bkey_has_target(struct bch_fs *c, struct bkey_s_c k, unsigned target)
return false;
}
+bool bch2_bkey_in_target(struct bch_fs *c, struct bkey_s_c k, unsigned target)
+{
+ struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
+
+ guard(rcu)();
+ bkey_for_each_ptr(ptrs, ptr)
+ if (!bch2_dev_in_target(c, ptr->dev, target))
+ return false;
+
+ return true;
+}
+
bool bch2_bkey_matches_ptr(struct bch_fs *c, struct bkey_s_c k,
struct bch_extent_ptr m, u64 offset)
{
@@ -1512,7 +1524,7 @@ int bch2_bkey_ptrs_validate(struct bch_fs *c, struct bkey_s_c k,
const struct bch_extent_rebalance *r = &entry->rebalance;
if (!bch2_compression_opt_valid(r->compression)) {
- struct bch_compression_opt opt = __bch2_compression_decode(r->compression);
+ union bch_compression_opt opt = { .value = r->compression };
prt_printf(err, "invalid compression opt %u:%u",
opt.type, opt.level);
return bch_err_throw(c, invalid_bkey);
diff --git a/fs/bcachefs/extents.h b/fs/bcachefs/extents.h
index b8590e51b76e..f212f91c278d 100644
--- a/fs/bcachefs/extents.h
+++ b/fs/bcachefs/extents.h
@@ -615,6 +615,7 @@ static inline struct bch_extent_ptr *bch2_bkey_has_device(struct bkey_s k, unsig
}
bool bch2_bkey_has_target(struct bch_fs *, struct bkey_s_c, unsigned);
+bool bch2_bkey_in_target(struct bch_fs *, struct bkey_s_c, unsigned);
void bch2_bkey_extent_entry_drop(struct bkey_i *, union bch_extent_entry *);