Skip to content

Commit d5c5b33

Browse files
author
Kent Overstreet
committed
bcachefs: Don't drop devices with stripe pointers
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 035d72f commit d5c5b33

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

fs/bcachefs/data_update.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ int bch2_extent_drop_ptrs(struct btree_trans *trans,
571571
while (data_opts.kill_ptrs) {
572572
unsigned i = 0, drop = __fls(data_opts.kill_ptrs);
573573

574-
bch2_bkey_drop_ptrs(bkey_i_to_s(n), ptr, i++ == drop);
574+
bch2_bkey_drop_ptrs_noerror(bkey_i_to_s(n), ptr, i++ == drop);
575575
data_opts.kill_ptrs ^= 1U << drop;
576576
}
577577

fs/bcachefs/ec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ static int ec_stripe_update_extent(struct btree_trans *trans,
13221322

13231323
bkey_reassemble(n, k);
13241324

1325-
bch2_bkey_drop_ptrs(bkey_i_to_s(n), ptr, ptr->dev != dev);
1325+
bch2_bkey_drop_ptrs_noerror(bkey_i_to_s(n), ptr, ptr->dev != dev);
13261326
ec_ptr = bch2_bkey_has_device(bkey_i_to_s(n), dev);
13271327
BUG_ON(!ec_ptr);
13281328

fs/bcachefs/extents.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,18 @@ void bch2_bkey_drop_ptr_noerror(struct bkey_s k, struct bch_extent_ptr *ptr)
818818

819819
void bch2_bkey_drop_ptr(struct bkey_s k, struct bch_extent_ptr *ptr)
820820
{
821+
if (k.k->type != KEY_TYPE_stripe) {
822+
struct bkey_ptrs_c ptrs = bch2_bkey_ptrs_c(k.s_c);
823+
const union bch_extent_entry *entry;
824+
struct extent_ptr_decoded p;
825+
826+
bkey_for_each_ptr_decode(k.k, ptrs, p, entry)
827+
if (p.ptr.dev == ptr->dev && p.has_ec) {
828+
ptr->dev = BCH_SB_MEMBER_INVALID;
829+
return;
830+
}
831+
}
832+
821833
bool have_dirty = bch2_bkey_dirty_devs(k.s_c).nr;
822834

823835
bch2_bkey_drop_ptr_noerror(k, ptr);
@@ -845,10 +857,7 @@ void bch2_bkey_drop_device(struct bkey_s k, unsigned dev)
845857

846858
void bch2_bkey_drop_device_noerror(struct bkey_s k, unsigned dev)
847859
{
848-
struct bch_extent_ptr *ptr = bch2_bkey_has_device(k, dev);
849-
850-
if (ptr)
851-
bch2_bkey_drop_ptr_noerror(k, ptr);
860+
bch2_bkey_drop_ptrs_noerror(k, ptr, ptr->dev == dev);
852861
}
853862

854863
const struct bch_extent_ptr *bch2_bkey_has_device_c(struct bkey_s_c k, unsigned dev)

fs/bcachefs/extents.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,6 @@ unsigned bch2_extent_ptr_desired_durability(struct bch_fs *, struct extent_ptr_d
611611
unsigned bch2_extent_ptr_durability(struct bch_fs *, struct extent_ptr_decoded *);
612612
unsigned bch2_bkey_durability(struct bch_fs *, struct bkey_s_c);
613613

614-
void bch2_bkey_drop_device(struct bkey_s, unsigned);
615-
void bch2_bkey_drop_device_noerror(struct bkey_s, unsigned);
616-
617614
const struct bch_extent_ptr *bch2_bkey_has_device_c(struct bkey_s_c, unsigned);
618615

619616
static inline struct bch_extent_ptr *bch2_bkey_has_device(struct bkey_s k, unsigned dev)
@@ -652,6 +649,23 @@ void bch2_extent_ptr_decoded_append(struct bkey_i *,
652649
void bch2_bkey_drop_ptr_noerror(struct bkey_s, struct bch_extent_ptr *);
653650
void bch2_bkey_drop_ptr(struct bkey_s, struct bch_extent_ptr *);
654651

652+
void bch2_bkey_drop_device_noerror(struct bkey_s, unsigned);
653+
void bch2_bkey_drop_device(struct bkey_s, unsigned);
654+
655+
#define bch2_bkey_drop_ptrs_noerror(_k, _ptr, _cond) \
656+
do { \
657+
__label__ _again; \
658+
struct bkey_ptrs _ptrs; \
659+
_again: \
660+
_ptrs = bch2_bkey_ptrs(_k); \
661+
\
662+
bkey_for_each_ptr(_ptrs, _ptr) \
663+
if (_cond) { \
664+
bch2_bkey_drop_ptr_noerror(_k, _ptr); \
665+
goto _again; \
666+
} \
667+
} while (0)
668+
655669
#define bch2_bkey_drop_ptrs(_k, _ptr, _cond) \
656670
do { \
657671
__label__ _again; \

0 commit comments

Comments
 (0)