Skip to content

Commit f2667e0

Browse files
committed
Merge tag 'bcachefs-2024-02-17' of https://evilpiepirate.org/git/bcachefs
Pull bcachefs fixes from Kent Overstreet: "Mostly pretty trivial, the user visible ones are: - don't barf when replicas_required > replicas - fix check_version_upgrade() so it doesn't do something nonsensical when we're downgrading" * tag 'bcachefs-2024-02-17' of https://evilpiepirate.org/git/bcachefs: bcachefs: Fix missing va_end() bcachefs: Fix check_version_upgrade() bcachefs: Clamp replicas_required to replicas bcachefs: fix missing endiannes conversion in sb_members bcachefs: fix kmemleak in __bch2_read_super error handling path bcachefs: Fix missing bch2_err_class() calls
2 parents ced5905 + 816054f commit f2667e0

File tree

11 files changed

+35
-16
lines changed

11 files changed

+35
-16
lines changed

fs/bcachefs/bcachefs.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,18 @@ static inline struct stdio_redirect *bch2_fs_stdio_redirect(struct bch_fs *c)
12491249
return stdio;
12501250
}
12511251

1252+
static inline unsigned metadata_replicas_required(struct bch_fs *c)
1253+
{
1254+
return min(c->opts.metadata_replicas,
1255+
c->opts.metadata_replicas_required);
1256+
}
1257+
1258+
static inline unsigned data_replicas_required(struct bch_fs *c)
1259+
{
1260+
return min(c->opts.data_replicas,
1261+
c->opts.data_replicas_required);
1262+
}
1263+
12521264
#define BKEY_PADDED_ONSTACK(key, pad) \
12531265
struct { struct bkey_i key; __u64 key ## _pad[pad]; }
12541266

fs/bcachefs/btree_update_interior.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@ static struct btree *__bch2_btree_node_alloc(struct btree_trans *trans,
280280
writepoint_ptr(&c->btree_write_point),
281281
&devs_have,
282282
res->nr_replicas,
283-
c->opts.metadata_replicas_required,
283+
min(res->nr_replicas,
284+
c->opts.metadata_replicas_required),
284285
watermark, 0, cl, &wp);
285286
if (unlikely(ret))
286287
return ERR_PTR(ret);

fs/bcachefs/fs.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ static int bch2_link(struct dentry *old_dentry, struct inode *vdir,
435435
bch2_subvol_is_ro(c, inode->ei_subvol) ?:
436436
__bch2_link(c, inode, dir, dentry);
437437
if (unlikely(ret))
438-
return ret;
438+
return bch2_err_class(ret);
439439

440440
ihold(&inode->v);
441441
d_instantiate(dentry, &inode->v);
@@ -487,8 +487,9 @@ static int bch2_unlink(struct inode *vdir, struct dentry *dentry)
487487
struct bch_inode_info *dir= to_bch_ei(vdir);
488488
struct bch_fs *c = dir->v.i_sb->s_fs_info;
489489

490-
return bch2_subvol_is_ro(c, dir->ei_subvol) ?:
490+
int ret = bch2_subvol_is_ro(c, dir->ei_subvol) ?:
491491
__bch2_unlink(vdir, dentry, false);
492+
return bch2_err_class(ret);
492493
}
493494

494495
static int bch2_symlink(struct mnt_idmap *idmap,
@@ -523,7 +524,7 @@ static int bch2_symlink(struct mnt_idmap *idmap,
523524
return 0;
524525
err:
525526
iput(&inode->v);
526-
return ret;
527+
return bch2_err_class(ret);
527528
}
528529

529530
static int bch2_mkdir(struct mnt_idmap *idmap,
@@ -641,7 +642,7 @@ static int bch2_rename2(struct mnt_idmap *idmap,
641642
src_inode,
642643
dst_inode);
643644

644-
return ret;
645+
return bch2_err_class(ret);
645646
}
646647

647648
static void bch2_setattr_copy(struct mnt_idmap *idmap,

fs/bcachefs/io_write.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,7 @@ CLOSURE_CALLBACK(bch2_write)
15641564
BUG_ON(!op->write_point.v);
15651565
BUG_ON(bkey_eq(op->pos, POS_MAX));
15661566

1567+
op->nr_replicas_required = min_t(unsigned, op->nr_replicas_required, op->nr_replicas);
15671568
op->start_time = local_clock();
15681569
bch2_keylist_init(&op->insert_keys, op->inline_keys);
15691570
wbio_init(bio)->put_bio = false;

fs/bcachefs/journal_io.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,8 @@ static int journal_write_alloc(struct journal *j, struct journal_buf *w)
14781478
c->opts.foreground_target;
14791479
unsigned i, replicas = 0, replicas_want =
14801480
READ_ONCE(c->opts.metadata_replicas);
1481+
unsigned replicas_need = min_t(unsigned, replicas_want,
1482+
READ_ONCE(c->opts.metadata_replicas_required));
14811483

14821484
rcu_read_lock();
14831485
retry:
@@ -1526,7 +1528,7 @@ static int journal_write_alloc(struct journal *j, struct journal_buf *w)
15261528

15271529
BUG_ON(bkey_val_u64s(&w->key.k) > BCH_REPLICAS_MAX);
15281530

1529-
return replicas >= c->opts.metadata_replicas_required ? 0 : -EROFS;
1531+
return replicas >= replicas_need ? 0 : -EROFS;
15301532
}
15311533

15321534
static void journal_buf_realloc(struct journal *j, struct journal_buf *buf)

fs/bcachefs/journal_reclaim.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void bch2_journal_space_available(struct journal *j)
205205

206206
j->can_discard = can_discard;
207207

208-
if (nr_online < c->opts.metadata_replicas_required) {
208+
if (nr_online < metadata_replicas_required(c)) {
209209
ret = JOURNAL_ERR_insufficient_devices;
210210
goto out;
211211
}

fs/bcachefs/printbuf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void bch2_prt_vprintf(struct printbuf *out, const char *fmt, va_list args)
5656

5757
va_copy(args2, args);
5858
len = vsnprintf(out->buf + out->pos, printbuf_remaining(out), fmt, args2);
59+
va_end(args2);
5960
} while (len + 1 >= printbuf_remaining(out) &&
6061
!bch2_printbuf_make_room(out, len + 1));
6162

fs/bcachefs/recovery.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,9 @@ u64 bch2_recovery_passes_from_stable(u64 v)
577577

578578
static bool check_version_upgrade(struct bch_fs *c)
579579
{
580-
unsigned latest_compatible = bch2_latest_compatible_version(c->sb.version);
581580
unsigned latest_version = bcachefs_metadata_version_current;
581+
unsigned latest_compatible = min(latest_version,
582+
bch2_latest_compatible_version(c->sb.version));
582583
unsigned old_version = c->sb.version_upgrade_complete ?: c->sb.version;
583584
unsigned new_version = 0;
584585

@@ -597,7 +598,7 @@ static bool check_version_upgrade(struct bch_fs *c)
597598
new_version = latest_version;
598599
break;
599600
case BCH_VERSION_UPGRADE_none:
600-
new_version = old_version;
601+
new_version = min(old_version, latest_version);
601602
break;
602603
}
603604
}
@@ -774,7 +775,7 @@ int bch2_fs_recovery(struct bch_fs *c)
774775
goto err;
775776
}
776777

777-
if (!(c->opts.nochanges && c->opts.norecovery)) {
778+
if (!c->opts.nochanges) {
778779
mutex_lock(&c->sb_lock);
779780
bool write_sb = false;
780781

@@ -804,15 +805,15 @@ int bch2_fs_recovery(struct bch_fs *c)
804805
if (bch2_check_version_downgrade(c)) {
805806
struct printbuf buf = PRINTBUF;
806807

807-
prt_str(&buf, "Version downgrade required:\n");
808+
prt_str(&buf, "Version downgrade required:");
808809

809810
__le64 passes = ext->recovery_passes_required[0];
810811
bch2_sb_set_downgrade(c,
811812
BCH_VERSION_MINOR(bcachefs_metadata_version_current),
812813
BCH_VERSION_MINOR(c->sb.version));
813814
passes = ext->recovery_passes_required[0] & ~passes;
814815
if (passes) {
815-
prt_str(&buf, " running recovery passes: ");
816+
prt_str(&buf, "\n running recovery passes: ");
816817
prt_bitflags(&buf, bch2_recovery_passes,
817818
bch2_recovery_passes_from_stable(le64_to_cpu(passes)));
818819
}

fs/bcachefs/sb-members.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ void bch2_dev_errors_reset(struct bch_dev *ca)
421421
m = bch2_members_v2_get_mut(c->disk_sb.sb, ca->dev_idx);
422422
for (unsigned i = 0; i < ARRAY_SIZE(m->errors_at_reset); i++)
423423
m->errors_at_reset[i] = cpu_to_le64(atomic64_read(&ca->errors[i]));
424-
m->errors_reset_time = ktime_get_real_seconds();
424+
m->errors_reset_time = cpu_to_le64(ktime_get_real_seconds());
425425

426426
bch2_write_super(c);
427427
mutex_unlock(&c->sb_lock);

fs/bcachefs/super-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ static int __bch2_read_super(const char *path, struct bch_opts *opts,
717717

718718
if (IS_ERR(sb->bdev_handle)) {
719719
ret = PTR_ERR(sb->bdev_handle);
720-
goto out;
720+
goto err;
721721
}
722722
sb->bdev = sb->bdev_handle->bdev;
723723

0 commit comments

Comments
 (0)