summaryrefslogtreecommitdiff
path: root/libbcachefs/extents.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-01-07 19:49:15 -0500
committerKent Overstreet <kent.overstreet@gmail.com>2021-01-08 21:33:27 -0500
commitf39f0bde7875aceb3e82a330f3a86223c6dd8af4 (patch)
tree06f46528e9c5ac2f472699c8b857fee11b37b0f1 /libbcachefs/extents.c
parent41dc1733f12fab96df2089d7c62036a880891010 (diff)
Update bcachefs sources to fcf8a0889c bcachefs: bch2_alloc_write() should be writing for all devices
Diffstat (limited to 'libbcachefs/extents.c')
-rw-r--r--libbcachefs/extents.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/libbcachefs/extents.c b/libbcachefs/extents.c
index 828ccf07..c0ae3123 100644
--- a/libbcachefs/extents.c
+++ b/libbcachefs/extents.c
@@ -665,7 +665,7 @@ bool bch2_bkey_is_incompressible(struct bkey_s_c k)
}
bool bch2_check_range_allocated(struct bch_fs *c, struct bpos pos, u64 size,
- unsigned nr_replicas)
+ unsigned nr_replicas, bool compressed)
{
struct btree_trans trans;
struct btree_iter *iter;
@@ -683,7 +683,8 @@ bool bch2_check_range_allocated(struct bch_fs *c, struct bpos pos, u64 size,
if (bkey_cmp(bkey_start_pos(k.k), end) >= 0)
break;
- if (nr_replicas > bch2_bkey_nr_ptrs_fully_allocated(k)) {
+ if (nr_replicas > bch2_bkey_replicas(c, k) ||
+ (!compressed && bch2_bkey_sectors_compressed(k))) {
ret = false;
break;
}
@@ -693,6 +694,33 @@ bool bch2_check_range_allocated(struct bch_fs *c, struct bpos pos, u64 size,
return ret;
}
+unsigned bch2_bkey_replicas(struct bch_fs *c, struct bkey_s_c k)
+{
+ struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k);
+ const union bch_extent_entry *entry;
+ struct extent_ptr_decoded p;
+ unsigned replicas = 0;
+
+ bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
+ if (p.ptr.cached)
+ continue;
+
+ if (p.has_ec) {
+ struct stripe *s =
+ genradix_ptr(&c->stripes[0], p.ec.idx);
+
+ WARN_ON(!s);
+ if (s)
+ replicas += s->nr_redundant;
+ }
+
+ replicas++;
+
+ }
+
+ return replicas;
+}
+
static unsigned bch2_extent_ptr_durability(struct bch_fs *c,
struct extent_ptr_decoded p)
{