Skip to content

Commit 31b2444

Browse files
committed
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()
2 parents 34ac1e8 + 8a2491d commit 31b2444

File tree

12 files changed

+126
-28
lines changed

12 files changed

+126
-28
lines changed

fs/bcachefs/acl.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,19 @@ bch2_acl_to_xattr(struct btree_trans *trans,
272272
return xattr;
273273
}
274274

275-
struct posix_acl *bch2_get_acl(struct mnt_idmap *idmap,
276-
struct dentry *dentry, int type)
275+
struct posix_acl *bch2_get_acl(struct inode *vinode, int type, bool rcu)
277276
{
278-
struct bch_inode_info *inode = to_bch_ei(dentry->d_inode);
277+
struct bch_inode_info *inode = to_bch_ei(vinode);
279278
struct bch_fs *c = inode->v.i_sb->s_fs_info;
280279
struct bch_hash_info hash = bch2_hash_info_init(c, &inode->ei_inode);
281280
struct xattr_search_key search = X_SEARCH(acl_to_xattr_type(type), "", 0);
282-
struct btree_trans *trans = bch2_trans_get(c);
283281
struct btree_iter iter = { NULL };
284282
struct posix_acl *acl = NULL;
283+
284+
if (rcu)
285+
return ERR_PTR(-ECHILD);
286+
287+
struct btree_trans *trans = bch2_trans_get(c);
285288
retry:
286289
bch2_trans_begin(trans);
287290

fs/bcachefs/acl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void bch2_acl_to_text(struct printbuf *, const void *, size_t);
2828

2929
#ifdef CONFIG_BCACHEFS_POSIX_ACL
3030

31-
struct posix_acl *bch2_get_acl(struct mnt_idmap *, struct dentry *, int);
31+
struct posix_acl *bch2_get_acl(struct inode *, int, bool);
3232

3333
int bch2_set_acl_trans(struct btree_trans *, subvol_inum,
3434
struct bch_inode_unpacked *,

fs/bcachefs/alloc_foreground.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ void bch2_dev_alloc_debug_to_text(struct printbuf *out, struct bch_dev *ca)
17401740
printbuf_tabstop_push(out, 16);
17411741
printbuf_tabstop_push(out, 16);
17421742

1743-
bch2_dev_usage_to_text(out, &stats);
1743+
bch2_dev_usage_to_text(out, ca, &stats);
17441744

17451745
prt_newline(out);
17461746

fs/bcachefs/bcachefs_format.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,8 @@ struct bch_sb_field_ext {
675675
x(btree_subvolume_children, BCH_VERSION(1, 6)) \
676676
x(mi_btree_bitmap, BCH_VERSION(1, 7)) \
677677
x(bucket_stripe_sectors, BCH_VERSION(1, 8)) \
678-
x(disk_accounting_v2, BCH_VERSION(1, 9))
678+
x(disk_accounting_v2, BCH_VERSION(1, 9)) \
679+
x(disk_accounting_v3, BCH_VERSION(1, 10))
679680

680681
enum bcachefs_metadata_version {
681682
bcachefs_metadata_version_min = 9,

fs/bcachefs/buckets.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,21 @@ bch2_fs_usage_read_short(struct bch_fs *c)
7171
return ret;
7272
}
7373

74-
void bch2_dev_usage_to_text(struct printbuf *out, struct bch_dev_usage *usage)
74+
void bch2_dev_usage_to_text(struct printbuf *out,
75+
struct bch_dev *ca,
76+
struct bch_dev_usage *usage)
7577
{
7678
prt_printf(out, "\tbuckets\rsectors\rfragmented\r\n");
7779

7880
for (unsigned i = 0; i < BCH_DATA_NR; i++) {
7981
bch2_prt_data_type(out, i);
8082
prt_printf(out, "\t%llu\r%llu\r%llu\r\n",
81-
usage->d[i].buckets,
82-
usage->d[i].sectors,
83-
usage->d[i].fragmented);
83+
usage->d[i].buckets,
84+
usage->d[i].sectors,
85+
usage->d[i].fragmented);
8486
}
87+
88+
prt_printf(out, "capacity\t%llu\r\n", ca->mi.nbuckets);
8589
}
8690

8791
static int bch2_check_fix_ptr(struct btree_trans *trans,

fs/bcachefs/buckets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static inline struct bch_dev_usage bch2_dev_usage_read(struct bch_dev *ca)
212212
return ret;
213213
}
214214

215-
void bch2_dev_usage_to_text(struct printbuf *, struct bch_dev_usage *);
215+
void bch2_dev_usage_to_text(struct printbuf *, struct bch_dev *, struct bch_dev_usage *);
216216

217217
static inline u64 bch2_dev_buckets_reserved(struct bch_dev *ca, enum bch_watermark watermark)
218218
{

fs/bcachefs/disk_accounting.c

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,74 @@ int bch2_mod_dev_cached_sectors(struct btree_trans *trans,
114114
return bch2_disk_accounting_mod(trans, &acc, &sectors, 1, gc);
115115
}
116116

117+
static inline bool is_zero(char *start, char *end)
118+
{
119+
BUG_ON(start > end);
120+
121+
for (; start < end; start++)
122+
if (*start)
123+
return false;
124+
return true;
125+
}
126+
127+
#define field_end(p, member) (((void *) (&p.member)) + sizeof(p.member))
128+
117129
int bch2_accounting_invalid(struct bch_fs *c, struct bkey_s_c k,
118130
enum bch_validate_flags flags,
119131
struct printbuf *err)
120132
{
121-
return 0;
133+
struct disk_accounting_pos acc_k;
134+
bpos_to_disk_accounting_pos(&acc_k, k.k->p);
135+
void *end = &acc_k + 1;
136+
int ret = 0;
137+
138+
switch (acc_k.type) {
139+
case BCH_DISK_ACCOUNTING_nr_inodes:
140+
end = field_end(acc_k, nr_inodes);
141+
break;
142+
case BCH_DISK_ACCOUNTING_persistent_reserved:
143+
end = field_end(acc_k, persistent_reserved);
144+
break;
145+
case BCH_DISK_ACCOUNTING_replicas:
146+
bkey_fsck_err_on(!acc_k.replicas.nr_devs,
147+
c, err, accounting_key_replicas_nr_devs_0,
148+
"accounting key replicas entry with nr_devs=0");
149+
150+
bkey_fsck_err_on(acc_k.replicas.nr_required > acc_k.replicas.nr_devs ||
151+
(acc_k.replicas.nr_required > 1 &&
152+
acc_k.replicas.nr_required == acc_k.replicas.nr_devs),
153+
c, err, accounting_key_replicas_nr_required_bad,
154+
"accounting key replicas entry with bad nr_required");
155+
156+
for (unsigned i = 0; i + 1 < acc_k.replicas.nr_devs; i++)
157+
bkey_fsck_err_on(acc_k.replicas.devs[i] > acc_k.replicas.devs[i + 1],
158+
c, err, accounting_key_replicas_devs_unsorted,
159+
"accounting key replicas entry with unsorted devs");
160+
161+
end = (void *) &acc_k.replicas + replicas_entry_bytes(&acc_k.replicas);
162+
break;
163+
case BCH_DISK_ACCOUNTING_dev_data_type:
164+
end = field_end(acc_k, dev_data_type);
165+
break;
166+
case BCH_DISK_ACCOUNTING_compression:
167+
end = field_end(acc_k, compression);
168+
break;
169+
case BCH_DISK_ACCOUNTING_snapshot:
170+
end = field_end(acc_k, snapshot);
171+
break;
172+
case BCH_DISK_ACCOUNTING_btree:
173+
end = field_end(acc_k, btree);
174+
break;
175+
case BCH_DISK_ACCOUNTING_rebalance_work:
176+
end = field_end(acc_k, rebalance_work);
177+
break;
178+
}
179+
180+
bkey_fsck_err_on(!is_zero(end, (void *) (&acc_k + 1)),
181+
c, err, accounting_key_junk_at_end,
182+
"junk at end of accounting key");
183+
fsck_err:
184+
return ret;
122185
}
123186

124187
void bch2_accounting_key_to_text(struct printbuf *out, struct disk_accounting_pos *k)

fs/bcachefs/disk_accounting_format.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,19 @@ struct bch_dev_data_type {
124124
__u8 data_type;
125125
};
126126

127-
struct bch_dev_stripe_buckets {
128-
__u8 dev;
129-
};
130-
131127
struct bch_acct_compression {
132128
__u8 type;
133129
};
134130

135131
struct bch_acct_snapshot {
136132
__u32 id;
137-
};
133+
} __packed;
138134

139135
struct bch_acct_btree {
140136
__u32 id;
137+
} __packed;
138+
139+
struct bch_acct_rebalance_work {
141140
};
142141

143142
struct disk_accounting_pos {
@@ -149,12 +148,12 @@ struct disk_accounting_pos {
149148
struct bch_persistent_reserved persistent_reserved;
150149
struct bch_replicas_entry_v1 replicas;
151150
struct bch_dev_data_type dev_data_type;
152-
struct bch_dev_stripe_buckets dev_stripe_buckets;
153151
struct bch_acct_compression compression;
154152
struct bch_acct_snapshot snapshot;
155153
struct bch_acct_btree btree;
156-
};
157-
};
154+
struct bch_acct_rebalance_work rebalance_work;
155+
} __packed;
156+
} __packed;
158157
struct bpos _pad;
159158
};
160159
};

fs/bcachefs/fs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ static const struct inode_operations bch_file_inode_operations = {
11991199
.fiemap = bch2_fiemap,
12001200
.listxattr = bch2_xattr_list,
12011201
#ifdef CONFIG_BCACHEFS_POSIX_ACL
1202-
.get_acl = bch2_get_acl,
1202+
.get_inode_acl = bch2_get_acl,
12031203
.set_acl = bch2_set_acl,
12041204
#endif
12051205
};
@@ -1219,7 +1219,7 @@ static const struct inode_operations bch_dir_inode_operations = {
12191219
.tmpfile = bch2_tmpfile,
12201220
.listxattr = bch2_xattr_list,
12211221
#ifdef CONFIG_BCACHEFS_POSIX_ACL
1222-
.get_acl = bch2_get_acl,
1222+
.get_inode_acl = bch2_get_acl,
12231223
.set_acl = bch2_set_acl,
12241224
#endif
12251225
};
@@ -1241,7 +1241,7 @@ static const struct inode_operations bch_symlink_inode_operations = {
12411241
.setattr = bch2_setattr,
12421242
.listxattr = bch2_xattr_list,
12431243
#ifdef CONFIG_BCACHEFS_POSIX_ACL
1244-
.get_acl = bch2_get_acl,
1244+
.get_inode_acl = bch2_get_acl,
12451245
.set_acl = bch2_set_acl,
12461246
#endif
12471247
};
@@ -1251,7 +1251,7 @@ static const struct inode_operations bch_special_inode_operations = {
12511251
.setattr = bch2_setattr,
12521252
.listxattr = bch2_xattr_list,
12531253
#ifdef CONFIG_BCACHEFS_POSIX_ACL
1254-
.get_acl = bch2_get_acl,
1254+
.get_inode_acl = bch2_get_acl,
12551255
.set_acl = bch2_set_acl,
12561256
#endif
12571257
};

fs/bcachefs/replicas.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ static int bch2_memcmp(const void *l, const void *r, const void *priv)
2424
static void verify_replicas_entry(struct bch_replicas_entry_v1 *e)
2525
{
2626
#ifdef CONFIG_BCACHEFS_DEBUG
27-
BUG_ON(e->data_type >= BCH_DATA_NR);
2827
BUG_ON(!e->nr_devs);
2928
BUG_ON(e->nr_required > 1 &&
3029
e->nr_required >= e->nr_devs);

0 commit comments

Comments
 (0)