Commit 31b24446 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'bcachefs-2024-08-10' of git://evilpiepirate.org/bcachefs

Pull more bcachefs fixes from Kent Overstreet:
 "A couple last minute fixes for the new disk accounting

   - fix a bug that was causing ACLs to seemingly "disappear"

   - new on disk format version, bcachefs_metadata_version_disk_accounting_v3

     bcachefs_metadata_version_disk_accounting_v2 accidentally included
     padding in disk_accounting_key; fortunately, 6.11 isn't out yet so
     we can fix this with another version bump"

* tag 'bcachefs-2024-08-10' of git://evilpiepirate.org/bcachefs:
  bcachefs: bcachefs_metadata_version_disk_accounting_v3
  bcachefs: improve bch2_dev_usage_to_text()
  bcachefs: bch2_accounting_invalid()
  bcachefs: Switch to .get_inode_acl()
parents 34ac1e82 8a2491db
...@@ -272,16 +272,19 @@ bch2_acl_to_xattr(struct btree_trans *trans, ...@@ -272,16 +272,19 @@ bch2_acl_to_xattr(struct btree_trans *trans,
return xattr; return xattr;
} }
struct posix_acl *bch2_get_acl(struct mnt_idmap *idmap, struct posix_acl *bch2_get_acl(struct inode *vinode, int type, bool rcu)
struct dentry *dentry, int type)
{ {
struct bch_inode_info *inode = to_bch_ei(dentry->d_inode); struct bch_inode_info *inode = to_bch_ei(vinode);
struct bch_fs *c = inode->v.i_sb->s_fs_info; struct bch_fs *c = inode->v.i_sb->s_fs_info;
struct bch_hash_info hash = bch2_hash_info_init(c, &inode->ei_inode); struct bch_hash_info hash = bch2_hash_info_init(c, &inode->ei_inode);
struct xattr_search_key search = X_SEARCH(acl_to_xattr_type(type), "", 0); struct xattr_search_key search = X_SEARCH(acl_to_xattr_type(type), "", 0);
struct btree_trans *trans = bch2_trans_get(c);
struct btree_iter iter = { NULL }; struct btree_iter iter = { NULL };
struct posix_acl *acl = NULL; struct posix_acl *acl = NULL;
if (rcu)
return ERR_PTR(-ECHILD);
struct btree_trans *trans = bch2_trans_get(c);
retry: retry:
bch2_trans_begin(trans); bch2_trans_begin(trans);
......
...@@ -28,7 +28,7 @@ void bch2_acl_to_text(struct printbuf *, const void *, size_t); ...@@ -28,7 +28,7 @@ void bch2_acl_to_text(struct printbuf *, const void *, size_t);
#ifdef CONFIG_BCACHEFS_POSIX_ACL #ifdef CONFIG_BCACHEFS_POSIX_ACL
struct posix_acl *bch2_get_acl(struct mnt_idmap *, struct dentry *, int); struct posix_acl *bch2_get_acl(struct inode *, int, bool);
int bch2_set_acl_trans(struct btree_trans *, subvol_inum, int bch2_set_acl_trans(struct btree_trans *, subvol_inum,
struct bch_inode_unpacked *, struct bch_inode_unpacked *,
......
...@@ -1740,7 +1740,7 @@ void bch2_dev_alloc_debug_to_text(struct printbuf *out, struct bch_dev *ca) ...@@ -1740,7 +1740,7 @@ void bch2_dev_alloc_debug_to_text(struct printbuf *out, struct bch_dev *ca)
printbuf_tabstop_push(out, 16); printbuf_tabstop_push(out, 16);
printbuf_tabstop_push(out, 16); printbuf_tabstop_push(out, 16);
bch2_dev_usage_to_text(out, &stats); bch2_dev_usage_to_text(out, ca, &stats);
prt_newline(out); prt_newline(out);
......
...@@ -675,7 +675,8 @@ struct bch_sb_field_ext { ...@@ -675,7 +675,8 @@ struct bch_sb_field_ext {
x(btree_subvolume_children, BCH_VERSION(1, 6)) \ x(btree_subvolume_children, BCH_VERSION(1, 6)) \
x(mi_btree_bitmap, BCH_VERSION(1, 7)) \ x(mi_btree_bitmap, BCH_VERSION(1, 7)) \
x(bucket_stripe_sectors, BCH_VERSION(1, 8)) \ x(bucket_stripe_sectors, BCH_VERSION(1, 8)) \
x(disk_accounting_v2, BCH_VERSION(1, 9)) x(disk_accounting_v2, BCH_VERSION(1, 9)) \
x(disk_accounting_v3, BCH_VERSION(1, 10))
enum bcachefs_metadata_version { enum bcachefs_metadata_version {
bcachefs_metadata_version_min = 9, bcachefs_metadata_version_min = 9,
......
...@@ -71,7 +71,9 @@ bch2_fs_usage_read_short(struct bch_fs *c) ...@@ -71,7 +71,9 @@ bch2_fs_usage_read_short(struct bch_fs *c)
return ret; return ret;
} }
void bch2_dev_usage_to_text(struct printbuf *out, struct bch_dev_usage *usage) void bch2_dev_usage_to_text(struct printbuf *out,
struct bch_dev *ca,
struct bch_dev_usage *usage)
{ {
prt_printf(out, "\tbuckets\rsectors\rfragmented\r\n"); prt_printf(out, "\tbuckets\rsectors\rfragmented\r\n");
...@@ -82,6 +84,8 @@ void bch2_dev_usage_to_text(struct printbuf *out, struct bch_dev_usage *usage) ...@@ -82,6 +84,8 @@ void bch2_dev_usage_to_text(struct printbuf *out, struct bch_dev_usage *usage)
usage->d[i].sectors, usage->d[i].sectors,
usage->d[i].fragmented); usage->d[i].fragmented);
} }
prt_printf(out, "capacity\t%llu\r\n", ca->mi.nbuckets);
} }
static int bch2_check_fix_ptr(struct btree_trans *trans, static int bch2_check_fix_ptr(struct btree_trans *trans,
......
...@@ -212,7 +212,7 @@ static inline struct bch_dev_usage bch2_dev_usage_read(struct bch_dev *ca) ...@@ -212,7 +212,7 @@ static inline struct bch_dev_usage bch2_dev_usage_read(struct bch_dev *ca)
return ret; return ret;
} }
void bch2_dev_usage_to_text(struct printbuf *, struct bch_dev_usage *); void bch2_dev_usage_to_text(struct printbuf *, struct bch_dev *, struct bch_dev_usage *);
static inline u64 bch2_dev_buckets_reserved(struct bch_dev *ca, enum bch_watermark watermark) static inline u64 bch2_dev_buckets_reserved(struct bch_dev *ca, enum bch_watermark watermark)
{ {
......
...@@ -114,11 +114,74 @@ int bch2_mod_dev_cached_sectors(struct btree_trans *trans, ...@@ -114,11 +114,74 @@ int bch2_mod_dev_cached_sectors(struct btree_trans *trans,
return bch2_disk_accounting_mod(trans, &acc, &sectors, 1, gc); return bch2_disk_accounting_mod(trans, &acc, &sectors, 1, gc);
} }
static inline bool is_zero(char *start, char *end)
{
BUG_ON(start > end);
for (; start < end; start++)
if (*start)
return false;
return true;
}
#define field_end(p, member) (((void *) (&p.member)) + sizeof(p.member))
int bch2_accounting_invalid(struct bch_fs *c, struct bkey_s_c k, int bch2_accounting_invalid(struct bch_fs *c, struct bkey_s_c k,
enum bch_validate_flags flags, enum bch_validate_flags flags,
struct printbuf *err) struct printbuf *err)
{ {
return 0; struct disk_accounting_pos acc_k;
bpos_to_disk_accounting_pos(&acc_k, k.k->p);
void *end = &acc_k + 1;
int ret = 0;
switch (acc_k.type) {
case BCH_DISK_ACCOUNTING_nr_inodes:
end = field_end(acc_k, nr_inodes);
break;
case BCH_DISK_ACCOUNTING_persistent_reserved:
end = field_end(acc_k, persistent_reserved);
break;
case BCH_DISK_ACCOUNTING_replicas:
bkey_fsck_err_on(!acc_k.replicas.nr_devs,
c, err, accounting_key_replicas_nr_devs_0,
"accounting key replicas entry with nr_devs=0");
bkey_fsck_err_on(acc_k.replicas.nr_required > acc_k.replicas.nr_devs ||
(acc_k.replicas.nr_required > 1 &&
acc_k.replicas.nr_required == acc_k.replicas.nr_devs),
c, err, accounting_key_replicas_nr_required_bad,
"accounting key replicas entry with bad nr_required");
for (unsigned i = 0; i + 1 < acc_k.replicas.nr_devs; i++)
bkey_fsck_err_on(acc_k.replicas.devs[i] > acc_k.replicas.devs[i + 1],
c, err, accounting_key_replicas_devs_unsorted,
"accounting key replicas entry with unsorted devs");
end = (void *) &acc_k.replicas + replicas_entry_bytes(&acc_k.replicas);
break;
case BCH_DISK_ACCOUNTING_dev_data_type:
end = field_end(acc_k, dev_data_type);
break;
case BCH_DISK_ACCOUNTING_compression:
end = field_end(acc_k, compression);
break;
case BCH_DISK_ACCOUNTING_snapshot:
end = field_end(acc_k, snapshot);
break;
case BCH_DISK_ACCOUNTING_btree:
end = field_end(acc_k, btree);
break;
case BCH_DISK_ACCOUNTING_rebalance_work:
end = field_end(acc_k, rebalance_work);
break;
}
bkey_fsck_err_on(!is_zero(end, (void *) (&acc_k + 1)),
c, err, accounting_key_junk_at_end,
"junk at end of accounting key");
fsck_err:
return ret;
} }
void bch2_accounting_key_to_text(struct printbuf *out, struct disk_accounting_pos *k) void bch2_accounting_key_to_text(struct printbuf *out, struct disk_accounting_pos *k)
......
...@@ -124,20 +124,19 @@ struct bch_dev_data_type { ...@@ -124,20 +124,19 @@ struct bch_dev_data_type {
__u8 data_type; __u8 data_type;
}; };
struct bch_dev_stripe_buckets {
__u8 dev;
};
struct bch_acct_compression { struct bch_acct_compression {
__u8 type; __u8 type;
}; };
struct bch_acct_snapshot { struct bch_acct_snapshot {
__u32 id; __u32 id;
}; } __packed;
struct bch_acct_btree { struct bch_acct_btree {
__u32 id; __u32 id;
} __packed;
struct bch_acct_rebalance_work {
}; };
struct disk_accounting_pos { struct disk_accounting_pos {
...@@ -149,12 +148,12 @@ struct disk_accounting_pos { ...@@ -149,12 +148,12 @@ struct disk_accounting_pos {
struct bch_persistent_reserved persistent_reserved; struct bch_persistent_reserved persistent_reserved;
struct bch_replicas_entry_v1 replicas; struct bch_replicas_entry_v1 replicas;
struct bch_dev_data_type dev_data_type; struct bch_dev_data_type dev_data_type;
struct bch_dev_stripe_buckets dev_stripe_buckets;
struct bch_acct_compression compression; struct bch_acct_compression compression;
struct bch_acct_snapshot snapshot; struct bch_acct_snapshot snapshot;
struct bch_acct_btree btree; struct bch_acct_btree btree;
}; struct bch_acct_rebalance_work rebalance_work;
}; } __packed;
} __packed;
struct bpos _pad; struct bpos _pad;
}; };
}; };
......
...@@ -1199,7 +1199,7 @@ static const struct inode_operations bch_file_inode_operations = { ...@@ -1199,7 +1199,7 @@ static const struct inode_operations bch_file_inode_operations = {
.fiemap = bch2_fiemap, .fiemap = bch2_fiemap,
.listxattr = bch2_xattr_list, .listxattr = bch2_xattr_list,
#ifdef CONFIG_BCACHEFS_POSIX_ACL #ifdef CONFIG_BCACHEFS_POSIX_ACL
.get_acl = bch2_get_acl, .get_inode_acl = bch2_get_acl,
.set_acl = bch2_set_acl, .set_acl = bch2_set_acl,
#endif #endif
}; };
...@@ -1219,7 +1219,7 @@ static const struct inode_operations bch_dir_inode_operations = { ...@@ -1219,7 +1219,7 @@ static const struct inode_operations bch_dir_inode_operations = {
.tmpfile = bch2_tmpfile, .tmpfile = bch2_tmpfile,
.listxattr = bch2_xattr_list, .listxattr = bch2_xattr_list,
#ifdef CONFIG_BCACHEFS_POSIX_ACL #ifdef CONFIG_BCACHEFS_POSIX_ACL
.get_acl = bch2_get_acl, .get_inode_acl = bch2_get_acl,
.set_acl = bch2_set_acl, .set_acl = bch2_set_acl,
#endif #endif
}; };
...@@ -1241,7 +1241,7 @@ static const struct inode_operations bch_symlink_inode_operations = { ...@@ -1241,7 +1241,7 @@ static const struct inode_operations bch_symlink_inode_operations = {
.setattr = bch2_setattr, .setattr = bch2_setattr,
.listxattr = bch2_xattr_list, .listxattr = bch2_xattr_list,
#ifdef CONFIG_BCACHEFS_POSIX_ACL #ifdef CONFIG_BCACHEFS_POSIX_ACL
.get_acl = bch2_get_acl, .get_inode_acl = bch2_get_acl,
.set_acl = bch2_set_acl, .set_acl = bch2_set_acl,
#endif #endif
}; };
...@@ -1251,7 +1251,7 @@ static const struct inode_operations bch_special_inode_operations = { ...@@ -1251,7 +1251,7 @@ static const struct inode_operations bch_special_inode_operations = {
.setattr = bch2_setattr, .setattr = bch2_setattr,
.listxattr = bch2_xattr_list, .listxattr = bch2_xattr_list,
#ifdef CONFIG_BCACHEFS_POSIX_ACL #ifdef CONFIG_BCACHEFS_POSIX_ACL
.get_acl = bch2_get_acl, .get_inode_acl = bch2_get_acl,
.set_acl = bch2_set_acl, .set_acl = bch2_set_acl,
#endif #endif
}; };
......
...@@ -24,7 +24,6 @@ static int bch2_memcmp(const void *l, const void *r, const void *priv) ...@@ -24,7 +24,6 @@ static int bch2_memcmp(const void *l, const void *r, const void *priv)
static void verify_replicas_entry(struct bch_replicas_entry_v1 *e) static void verify_replicas_entry(struct bch_replicas_entry_v1 *e)
{ {
#ifdef CONFIG_BCACHEFS_DEBUG #ifdef CONFIG_BCACHEFS_DEBUG
BUG_ON(e->data_type >= BCH_DATA_NR);
BUG_ON(!e->nr_devs); BUG_ON(!e->nr_devs);
BUG_ON(e->nr_required > 1 && BUG_ON(e->nr_required > 1 &&
e->nr_required >= e->nr_devs); e->nr_required >= e->nr_devs);
......
...@@ -61,12 +61,37 @@ ...@@ -61,12 +61,37 @@
BCH_FSCK_ERR_dev_usage_buckets_wrong, \ BCH_FSCK_ERR_dev_usage_buckets_wrong, \
BCH_FSCK_ERR_dev_usage_sectors_wrong, \ BCH_FSCK_ERR_dev_usage_sectors_wrong, \
BCH_FSCK_ERR_dev_usage_fragmented_wrong, \ BCH_FSCK_ERR_dev_usage_fragmented_wrong, \
BCH_FSCK_ERR_accounting_mismatch) BCH_FSCK_ERR_accounting_mismatch) \
x(disk_accounting_v3, \
BIT_ULL(BCH_RECOVERY_PASS_check_allocations), \
BCH_FSCK_ERR_bkey_version_in_future, \
BCH_FSCK_ERR_dev_usage_buckets_wrong, \
BCH_FSCK_ERR_dev_usage_sectors_wrong, \
BCH_FSCK_ERR_dev_usage_fragmented_wrong, \
BCH_FSCK_ERR_accounting_mismatch, \
BCH_FSCK_ERR_accounting_key_replicas_nr_devs_0, \
BCH_FSCK_ERR_accounting_key_replicas_nr_required_bad, \
BCH_FSCK_ERR_accounting_key_replicas_devs_unsorted, \
BCH_FSCK_ERR_accounting_key_junk_at_end)
#define DOWNGRADE_TABLE() \ #define DOWNGRADE_TABLE() \
x(bucket_stripe_sectors, \ x(bucket_stripe_sectors, \
0) \ 0) \
x(disk_accounting_v2, \ x(disk_accounting_v2, \
BIT_ULL(BCH_RECOVERY_PASS_check_allocations), \
BCH_FSCK_ERR_dev_usage_buckets_wrong, \
BCH_FSCK_ERR_dev_usage_sectors_wrong, \
BCH_FSCK_ERR_dev_usage_fragmented_wrong, \
BCH_FSCK_ERR_fs_usage_hidden_wrong, \
BCH_FSCK_ERR_fs_usage_btree_wrong, \
BCH_FSCK_ERR_fs_usage_data_wrong, \
BCH_FSCK_ERR_fs_usage_cached_wrong, \
BCH_FSCK_ERR_fs_usage_reserved_wrong, \
BCH_FSCK_ERR_fs_usage_nr_inodes_wrong, \
BCH_FSCK_ERR_fs_usage_persistent_reserved_wrong, \
BCH_FSCK_ERR_fs_usage_replicas_wrong, \
BCH_FSCK_ERR_bkey_version_in_future) \
x(disk_accounting_v3, \
BIT_ULL(BCH_RECOVERY_PASS_check_allocations), \ BIT_ULL(BCH_RECOVERY_PASS_check_allocations), \
BCH_FSCK_ERR_dev_usage_buckets_wrong, \ BCH_FSCK_ERR_dev_usage_buckets_wrong, \
BCH_FSCK_ERR_dev_usage_sectors_wrong, \ BCH_FSCK_ERR_dev_usage_sectors_wrong, \
......
...@@ -287,7 +287,11 @@ enum bch_fsck_flags { ...@@ -287,7 +287,11 @@ enum bch_fsck_flags {
x(accounting_replicas_not_marked, 273, 0) \ x(accounting_replicas_not_marked, 273, 0) \
x(invalid_btree_id, 274, 0) \ x(invalid_btree_id, 274, 0) \
x(alloc_key_io_time_bad, 275, 0) \ x(alloc_key_io_time_bad, 275, 0) \
x(alloc_key_fragmentation_lru_wrong, 276, FSCK_AUTOFIX) x(alloc_key_fragmentation_lru_wrong, 276, FSCK_AUTOFIX) \
x(accounting_key_junk_at_end, 277, 0) \
x(accounting_key_replicas_nr_devs_0, 278, 0) \
x(accounting_key_replicas_nr_required_bad, 279, 0) \
x(accounting_key_replicas_devs_unsorted, 280, 0) \
enum bch_sb_error_id { enum bch_sb_error_id {
#define x(t, n, ...) BCH_FSCK_ERR_##t = n, #define x(t, n, ...) BCH_FSCK_ERR_##t = n,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment