Skip to content

Commit ff9bce3

Browse files
committed
Merge tag 'bcachefs-2024-05-30' of https://evilpiepirate.org/git/bcachefs
Pull bcachefs fixes from Kent Overstreet: "Assorted odds and ends... - two downgrade fixes - a couple snapshot deletion and repair fixes, thanks to noradtux for finding these and providing the image to debug them - a couple assert fixes - convert to folio helper, from Matthew - some improved error messages - bit of code reorganization (just moving things around); doing this while things are quiet so I'm not rebasing fixes past reorgs - don't return -EROFS on inconsistency error in recovery, this confuses util-linux and has it retry the mount - fix failure to return error on misaligned dio write; reported as an issue with coreutils shred" * tag 'bcachefs-2024-05-30' of https://evilpiepirate.org/git/bcachefs: (21 commits) bcachefs: Fix failure to return error on misaligned dio write bcachefs: Don't return -EROFS from mount on inconsistency error bcachefs: Fix uninitialized var warning bcachefs: Split out sb-errors_format.h bcachefs: Split out journal_seq_blacklist_format.h bcachefs: Split out replicas_format.h bcachefs: Split out disk_groups_format.h bcachefs: split out sb-downgrade_format.h bcachefs: split out sb-members_format.h bcachefs: Better fsck error message for key version bcachefs: btree_gc can now handle unknown btrees bcachefs: add missing MODULE_DESCRIPTION() bcachefs: Fix setting of downgrade recovery passes/errors bcachefs: Run check_key_has_snapshot in snapshot_delete_keys() bcachefs: Refactor delete_dead_snapshots() bcachefs: Fix locking assert bcachefs: Fix lookup_first_inode() when inode_generations are present bcachefs: Plumb bkey into __btree_err() bcachefs: Use copy_folio_from_iter_atomic() bcachefs: Fix sb-downgrade validation ...
2 parents d8ec198 + 7b038b5 commit ff9bce3

27 files changed

+706
-686
lines changed

fs/bcachefs/backpointers.c

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

691691
ptrs = bch2_bkey_ptrs_c(k);
692692
bkey_for_each_ptr_decode(k.k, ptrs, p, entry) {
693-
struct bpos bucket_pos;
693+
struct bpos bucket_pos = POS_MIN;
694694
struct bch_backpointer bp;
695695

696696
if (p.ptr.cached)

fs/bcachefs/bcachefs.h

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ enum bch_time_stats {
457457
};
458458

459459
#include "alloc_types.h"
460+
#include "btree_gc_types.h"
460461
#include "btree_types.h"
461462
#include "btree_node_scan_types.h"
462463
#include "btree_write_buffer_types.h"
@@ -488,49 +489,6 @@ enum bch_time_stats {
488489

489490
struct btree;
490491

491-
enum gc_phase {
492-
GC_PHASE_NOT_RUNNING,
493-
GC_PHASE_START,
494-
GC_PHASE_SB,
495-
496-
GC_PHASE_BTREE_stripes,
497-
GC_PHASE_BTREE_extents,
498-
GC_PHASE_BTREE_inodes,
499-
GC_PHASE_BTREE_dirents,
500-
GC_PHASE_BTREE_xattrs,
501-
GC_PHASE_BTREE_alloc,
502-
GC_PHASE_BTREE_quotas,
503-
GC_PHASE_BTREE_reflink,
504-
GC_PHASE_BTREE_subvolumes,
505-
GC_PHASE_BTREE_snapshots,
506-
GC_PHASE_BTREE_lru,
507-
GC_PHASE_BTREE_freespace,
508-
GC_PHASE_BTREE_need_discard,
509-
GC_PHASE_BTREE_backpointers,
510-
GC_PHASE_BTREE_bucket_gens,
511-
GC_PHASE_BTREE_snapshot_trees,
512-
GC_PHASE_BTREE_deleted_inodes,
513-
GC_PHASE_BTREE_logged_ops,
514-
GC_PHASE_BTREE_rebalance_work,
515-
GC_PHASE_BTREE_subvolume_children,
516-
517-
GC_PHASE_PENDING_DELETE,
518-
};
519-
520-
struct gc_pos {
521-
enum gc_phase phase;
522-
u16 level;
523-
struct bpos pos;
524-
};
525-
526-
struct reflink_gc {
527-
u64 offset;
528-
u32 size;
529-
u32 refcount;
530-
};
531-
532-
typedef GENRADIX(struct reflink_gc) reflink_gc_table;
533-
534492
struct io_count {
535493
u64 sectors[2][BCH_DATA_NR];
536494
};

fs/bcachefs/bcachefs_format.h

Lines changed: 10 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -503,16 +503,22 @@ struct bch_sb_field {
503503

504504
#include "alloc_background_format.h"
505505
#include "extents_format.h"
506-
#include "reflink_format.h"
507506
#include "ec_format.h"
508-
#include "inode_format.h"
509507
#include "dirent_format.h"
510-
#include "xattr_format.h"
511-
#include "quota_format.h"
508+
#include "disk_groups_format.h"
509+
#include "inode_format.h"
510+
#include "journal_seq_blacklist_format.h"
512511
#include "logged_ops_format.h"
512+
#include "quota_format.h"
513+
#include "reflink_format.h"
514+
#include "replicas_format.h"
513515
#include "snapshot_format.h"
514516
#include "subvolume_format.h"
515517
#include "sb-counters_format.h"
518+
#include "sb-downgrade_format.h"
519+
#include "sb-errors_format.h"
520+
#include "sb-members_format.h"
521+
#include "xattr_format.h"
516522

517523
enum bch_sb_field_type {
518524
#define x(f, nr) BCH_SB_FIELD_##f = nr,
@@ -545,107 +551,6 @@ struct bch_sb_field_journal_v2 {
545551
} d[];
546552
};
547553

548-
/* BCH_SB_FIELD_members_v1: */
549-
550-
#define BCH_MIN_NR_NBUCKETS (1 << 6)
551-
552-
#define BCH_IOPS_MEASUREMENTS() \
553-
x(seqread, 0) \
554-
x(seqwrite, 1) \
555-
x(randread, 2) \
556-
x(randwrite, 3)
557-
558-
enum bch_iops_measurement {
559-
#define x(t, n) BCH_IOPS_##t = n,
560-
BCH_IOPS_MEASUREMENTS()
561-
#undef x
562-
BCH_IOPS_NR
563-
};
564-
565-
#define BCH_MEMBER_ERROR_TYPES() \
566-
x(read, 0) \
567-
x(write, 1) \
568-
x(checksum, 2)
569-
570-
enum bch_member_error_type {
571-
#define x(t, n) BCH_MEMBER_ERROR_##t = n,
572-
BCH_MEMBER_ERROR_TYPES()
573-
#undef x
574-
BCH_MEMBER_ERROR_NR
575-
};
576-
577-
struct bch_member {
578-
__uuid_t uuid;
579-
__le64 nbuckets; /* device size */
580-
__le16 first_bucket; /* index of first bucket used */
581-
__le16 bucket_size; /* sectors */
582-
__u8 btree_bitmap_shift;
583-
__u8 pad[3];
584-
__le64 last_mount; /* time_t */
585-
586-
__le64 flags;
587-
__le32 iops[4];
588-
__le64 errors[BCH_MEMBER_ERROR_NR];
589-
__le64 errors_at_reset[BCH_MEMBER_ERROR_NR];
590-
__le64 errors_reset_time;
591-
__le64 seq;
592-
__le64 btree_allocated_bitmap;
593-
/*
594-
* On recovery from a clean shutdown we don't normally read the journal,
595-
* but we still want to resume writing from where we left off so we
596-
* don't overwrite more than is necessary, for list journal debugging:
597-
*/
598-
__le32 last_journal_bucket;
599-
__le32 last_journal_bucket_offset;
600-
};
601-
602-
/*
603-
* This limit comes from the bucket_gens array - it's a single allocation, and
604-
* kernel allocation are limited to INT_MAX
605-
*/
606-
#define BCH_MEMBER_NBUCKETS_MAX (INT_MAX - 64)
607-
608-
#define BCH_MEMBER_V1_BYTES 56
609-
610-
LE64_BITMASK(BCH_MEMBER_STATE, struct bch_member, flags, 0, 4)
611-
/* 4-14 unused, was TIER, HAS_(META)DATA, REPLACEMENT */
612-
LE64_BITMASK(BCH_MEMBER_DISCARD, struct bch_member, flags, 14, 15)
613-
LE64_BITMASK(BCH_MEMBER_DATA_ALLOWED, struct bch_member, flags, 15, 20)
614-
LE64_BITMASK(BCH_MEMBER_GROUP, struct bch_member, flags, 20, 28)
615-
LE64_BITMASK(BCH_MEMBER_DURABILITY, struct bch_member, flags, 28, 30)
616-
LE64_BITMASK(BCH_MEMBER_FREESPACE_INITIALIZED,
617-
struct bch_member, flags, 30, 31)
618-
619-
#if 0
620-
LE64_BITMASK(BCH_MEMBER_NR_READ_ERRORS, struct bch_member, flags[1], 0, 20);
621-
LE64_BITMASK(BCH_MEMBER_NR_WRITE_ERRORS,struct bch_member, flags[1], 20, 40);
622-
#endif
623-
624-
#define BCH_MEMBER_STATES() \
625-
x(rw, 0) \
626-
x(ro, 1) \
627-
x(failed, 2) \
628-
x(spare, 3)
629-
630-
enum bch_member_state {
631-
#define x(t, n) BCH_MEMBER_STATE_##t = n,
632-
BCH_MEMBER_STATES()
633-
#undef x
634-
BCH_MEMBER_STATE_NR
635-
};
636-
637-
struct bch_sb_field_members_v1 {
638-
struct bch_sb_field field;
639-
struct bch_member _members[]; //Members are now variable size
640-
};
641-
642-
struct bch_sb_field_members_v2 {
643-
struct bch_sb_field field;
644-
__le16 member_bytes; //size of single member entry
645-
u8 pad[6];
646-
struct bch_member _members[];
647-
};
648-
649554
/* BCH_SB_FIELD_crypt: */
650555

651556
struct nonce {
@@ -694,8 +599,6 @@ LE64_BITMASK(BCH_KDF_SCRYPT_N, struct bch_sb_field_crypt, kdf_flags, 0, 16);
694599
LE64_BITMASK(BCH_KDF_SCRYPT_R, struct bch_sb_field_crypt, kdf_flags, 16, 32);
695600
LE64_BITMASK(BCH_KDF_SCRYPT_P, struct bch_sb_field_crypt, kdf_flags, 32, 48);
696601

697-
/* BCH_SB_FIELD_replicas: */
698-
699602
#define BCH_DATA_TYPES() \
700603
x(free, 0) \
701604
x(sb, 1) \
@@ -738,50 +641,6 @@ static inline bool data_type_is_hidden(enum bch_data_type type)
738641
}
739642
}
740643

741-
struct bch_replicas_entry_v0 {
742-
__u8 data_type;
743-
__u8 nr_devs;
744-
__u8 devs[];
745-
} __packed;
746-
747-
struct bch_sb_field_replicas_v0 {
748-
struct bch_sb_field field;
749-
struct bch_replicas_entry_v0 entries[];
750-
} __packed __aligned(8);
751-
752-
struct bch_replicas_entry_v1 {
753-
__u8 data_type;
754-
__u8 nr_devs;
755-
__u8 nr_required;
756-
__u8 devs[];
757-
} __packed;
758-
759-
#define replicas_entry_bytes(_i) \
760-
(offsetof(typeof(*(_i)), devs) + (_i)->nr_devs)
761-
762-
struct bch_sb_field_replicas {
763-
struct bch_sb_field field;
764-
struct bch_replicas_entry_v1 entries[];
765-
} __packed __aligned(8);
766-
767-
/* BCH_SB_FIELD_disk_groups: */
768-
769-
#define BCH_SB_LABEL_SIZE 32
770-
771-
struct bch_disk_group {
772-
__u8 label[BCH_SB_LABEL_SIZE];
773-
__le64 flags[2];
774-
} __packed __aligned(8);
775-
776-
LE64_BITMASK(BCH_GROUP_DELETED, struct bch_disk_group, flags[0], 0, 1)
777-
LE64_BITMASK(BCH_GROUP_DATA_ALLOWED, struct bch_disk_group, flags[0], 1, 6)
778-
LE64_BITMASK(BCH_GROUP_PARENT, struct bch_disk_group, flags[0], 6, 24)
779-
780-
struct bch_sb_field_disk_groups {
781-
struct bch_sb_field field;
782-
struct bch_disk_group entries[];
783-
} __packed __aligned(8);
784-
785644
/*
786645
* On clean shutdown, store btree roots and current journal sequence number in
787646
* the superblock:
@@ -809,46 +668,13 @@ struct bch_sb_field_clean {
809668
__u64 _data[];
810669
};
811670

812-
struct journal_seq_blacklist_entry {
813-
__le64 start;
814-
__le64 end;
815-
};
816-
817-
struct bch_sb_field_journal_seq_blacklist {
818-
struct bch_sb_field field;
819-
struct journal_seq_blacklist_entry start[];
820-
};
821-
822-
struct bch_sb_field_errors {
823-
struct bch_sb_field field;
824-
struct bch_sb_field_error_entry {
825-
__le64 v;
826-
__le64 last_error_time;
827-
} entries[];
828-
};
829-
830-
LE64_BITMASK(BCH_SB_ERROR_ENTRY_ID, struct bch_sb_field_error_entry, v, 0, 16);
831-
LE64_BITMASK(BCH_SB_ERROR_ENTRY_NR, struct bch_sb_field_error_entry, v, 16, 64);
832-
833671
struct bch_sb_field_ext {
834672
struct bch_sb_field field;
835673
__le64 recovery_passes_required[2];
836674
__le64 errors_silent[8];
837675
__le64 btrees_lost_data;
838676
};
839677

840-
struct bch_sb_field_downgrade_entry {
841-
__le16 version;
842-
__le64 recovery_passes[2];
843-
__le16 nr_errors;
844-
__le16 errors[] __counted_by(nr_errors);
845-
} __packed __aligned(2);
846-
847-
struct bch_sb_field_downgrade {
848-
struct bch_sb_field field;
849-
struct bch_sb_field_downgrade_entry entries[];
850-
};
851-
852678
/* Superblock: */
853679

854680
/*
@@ -909,7 +735,6 @@ unsigned bcachefs_metadata_required_upgrade_below = bcachefs_metadata_version_re
909735
#define bcachefs_metadata_version_current (bcachefs_metadata_version_max - 1)
910736

911737
#define BCH_SB_SECTOR 8
912-
#define BCH_SB_MEMBERS_MAX 64 /* XXX kill */
913738

914739
#define BCH_SB_LAYOUT_SIZE_BITS_MAX 16 /* 32 MB */
915740

fs/bcachefs/btree_gc.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -585,16 +585,17 @@ static int bch2_gc_mark_key(struct btree_trans *trans, enum btree_id btree_id,
585585

586586
if (fsck_err_on(k.k->version.lo > atomic64_read(&c->key_version), c,
587587
bkey_version_in_future,
588-
"key version number higher than recorded: %llu > %llu",
589-
k.k->version.lo,
590-
atomic64_read(&c->key_version)))
588+
"key version number higher than recorded %llu\n %s",
589+
atomic64_read(&c->key_version),
590+
(bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
591591
atomic64_set(&c->key_version, k.k->version.lo);
592592
}
593593

594594
if (mustfix_fsck_err_on(level && !bch2_dev_btree_bitmap_marked(c, k),
595595
c, btree_bitmap_not_marked,
596596
"btree ptr not marked in member info btree allocated bitmap\n %s",
597-
(bch2_bkey_val_to_text(&buf, c, k),
597+
(printbuf_reset(&buf),
598+
bch2_bkey_val_to_text(&buf, c, k),
598599
buf.buf))) {
599600
mutex_lock(&c->sb_lock);
600601
bch2_dev_btree_bitmap_mark(c, k);
@@ -673,8 +674,7 @@ static int bch2_gc_btree(struct btree_trans *trans, enum btree_id btree, bool in
673674

674675
static inline int btree_id_gc_phase_cmp(enum btree_id l, enum btree_id r)
675676
{
676-
return (int) btree_id_to_gc_phase(l) -
677-
(int) btree_id_to_gc_phase(r);
677+
return cmp_int(gc_btree_order(l), gc_btree_order(r));
678678
}
679679

680680
static int bch2_gc_btrees(struct bch_fs *c)
@@ -711,7 +711,7 @@ static int bch2_gc_btrees(struct bch_fs *c)
711711
static int bch2_mark_superblocks(struct bch_fs *c)
712712
{
713713
mutex_lock(&c->sb_lock);
714-
gc_pos_set(c, gc_phase(GC_PHASE_SB));
714+
gc_pos_set(c, gc_phase(GC_PHASE_sb));
715715

716716
int ret = bch2_trans_mark_dev_sbs_flags(c, BTREE_TRIGGER_gc);
717717
mutex_unlock(&c->sb_lock);
@@ -1209,7 +1209,7 @@ int bch2_check_allocations(struct bch_fs *c)
12091209
if (ret)
12101210
goto out;
12111211

1212-
gc_pos_set(c, gc_phase(GC_PHASE_START));
1212+
gc_pos_set(c, gc_phase(GC_PHASE_start));
12131213

12141214
ret = bch2_mark_superblocks(c);
12151215
BUG_ON(ret);
@@ -1231,7 +1231,7 @@ int bch2_check_allocations(struct bch_fs *c)
12311231

12321232
percpu_down_write(&c->mark_lock);
12331233
/* Indicates that gc is no longer in progress: */
1234-
__gc_pos_set(c, gc_phase(GC_PHASE_NOT_RUNNING));
1234+
__gc_pos_set(c, gc_phase(GC_PHASE_not_running));
12351235

12361236
bch2_gc_free(c);
12371237
percpu_up_write(&c->mark_lock);

0 commit comments

Comments
 (0)