Skip to content

Commit 9c69f88

Browse files
committed
Merge tag 'bcachefs-2025-05-08' of git://evilpiepirate.org/bcachefs
Pull bcachefs fixes from Kent Overstreet: - Some fixes to help with filesystem analysis: ensure superblock error count gets written if we go ERO, don't discard the journal aggressively (so it's available for list_journal -a) - Fix lost wakeup on arm causing us to get stuck when reading btree nodes - Fix fsck failing to exit on ctrl-c - An additional fix for filesystems with misaligned bucket sizes: we now ensure that allocations are properly aligned - Setting background target but not promote target will now leave that data cached on the foreground target, as it used to - Revert a change to when we allocate the VFS superblock, this was done for implementing blk_holder_ops but ended up not being needed, and allocating a superblock and not setting SB_BORN while we do recovery caused sync() calls and other things to hang - Assorted fixes for harmless error messages that caused concern to users * tag 'bcachefs-2025-05-08' of git://evilpiepirate.org/bcachefs: bcachefs: Don't aggressively discard the journal bcachefs: Ensure superblock gets written when we go ERO bcachefs: Filter out harmless EROFS error messages bcachefs: journal_shutdown is EROFS, not EIO bcachefs: Call bch2_fs_start before getting vfs superblock bcachefs: fix hung task timeout in journal read bcachefs: Add missing barriers before wake_up_bit() bcachefs: Ensure proper write alignment bcachefs: Improve want_cached_ptr() bcachefs: thread_with_stdio: fix spinning instead of exiting
2 parents acaa3e7 + 8e4d280 commit 9c69f88

File tree

12 files changed

+55
-19
lines changed

12 files changed

+55
-19
lines changed

fs/bcachefs/alloc_foreground.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,11 +1422,31 @@ int bch2_alloc_sectors_start_trans(struct btree_trans *trans,
14221422

14231423
wp->sectors_free = UINT_MAX;
14241424

1425-
open_bucket_for_each(c, &wp->ptrs, ob, i)
1425+
open_bucket_for_each(c, &wp->ptrs, ob, i) {
1426+
/*
1427+
* Ensure proper write alignment - either due to misaligned
1428+
* bucket sizes (from buggy bcachefs-tools), or writes that mix
1429+
* logical/physical alignment:
1430+
*/
1431+
struct bch_dev *ca = ob_dev(c, ob);
1432+
u64 offset = bucket_to_sector(ca, ob->bucket) +
1433+
ca->mi.bucket_size -
1434+
ob->sectors_free;
1435+
unsigned align = round_up(offset, block_sectors(c)) - offset;
1436+
1437+
ob->sectors_free = max_t(int, 0, ob->sectors_free - align);
1438+
14261439
wp->sectors_free = min(wp->sectors_free, ob->sectors_free);
1440+
}
14271441

14281442
wp->sectors_free = rounddown(wp->sectors_free, block_sectors(c));
14291443

1444+
/* Did alignment use up space in an open_bucket? */
1445+
if (unlikely(!wp->sectors_free)) {
1446+
bch2_alloc_sectors_done(c, wp);
1447+
goto retry;
1448+
}
1449+
14301450
BUG_ON(!wp->sectors_free || wp->sectors_free == UINT_MAX);
14311451

14321452
return 0;

fs/bcachefs/btree_io.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ void bch2_btree_node_io_unlock(struct btree *b)
4141

4242
clear_btree_node_write_in_flight_inner(b);
4343
clear_btree_node_write_in_flight(b);
44+
smp_mb__after_atomic();
4445
wake_up_bit(&b->flags, BTREE_NODE_write_in_flight);
4546
}
4647

@@ -1400,6 +1401,7 @@ static void btree_node_read_work(struct work_struct *work)
14001401

14011402
printbuf_exit(&buf);
14021403
clear_btree_node_read_in_flight(b);
1404+
smp_mb__after_atomic();
14031405
wake_up_bit(&b->flags, BTREE_NODE_read_in_flight);
14041406
}
14051407

@@ -1595,6 +1597,7 @@ static CLOSURE_CALLBACK(btree_node_read_all_replicas_done)
15951597
printbuf_exit(&buf);
15961598

15971599
clear_btree_node_read_in_flight(b);
1600+
smp_mb__after_atomic();
15981601
wake_up_bit(&b->flags, BTREE_NODE_read_in_flight);
15991602
}
16001603

@@ -1721,6 +1724,7 @@ void bch2_btree_node_read(struct btree_trans *trans, struct btree *b,
17211724
set_btree_node_read_error(b);
17221725
bch2_btree_lost_data(c, b->c.btree_id);
17231726
clear_btree_node_read_in_flight(b);
1727+
smp_mb__after_atomic();
17241728
wake_up_bit(&b->flags, BTREE_NODE_read_in_flight);
17251729
printbuf_exit(&buf);
17261730
return;
@@ -2061,8 +2065,10 @@ static void __btree_node_write_done(struct bch_fs *c, struct btree *b, u64 start
20612065

20622066
if (new & (1U << BTREE_NODE_write_in_flight))
20632067
__bch2_btree_node_write(c, b, BTREE_WRITE_ALREADY_STARTED|type);
2064-
else
2068+
else {
2069+
smp_mb__after_atomic();
20652070
wake_up_bit(&b->flags, BTREE_NODE_write_in_flight);
2071+
}
20662072
}
20672073

20682074
static void btree_node_write_done(struct bch_fs *c, struct btree *b, u64 start_time)
@@ -2175,6 +2181,7 @@ static void btree_node_write_endio(struct bio *bio)
21752181
}
21762182

21772183
clear_btree_node_write_in_flight_inner(b);
2184+
smp_mb__after_atomic();
21782185
wake_up_bit(&b->flags, BTREE_NODE_write_in_flight_inner);
21792186
INIT_WORK(&wb->work, btree_node_write_work);
21802187
queue_work(c->btree_io_complete_wq, &wb->work);

fs/bcachefs/buckets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static inline void bucket_unlock(struct bucket *b)
4444
BUILD_BUG_ON(!((union ulong_byte_assert) { .ulong = 1UL << BUCKET_LOCK_BITNR }).byte);
4545

4646
clear_bit_unlock(BUCKET_LOCK_BITNR, (void *) &b->lock);
47+
smp_mb__after_atomic();
4748
wake_up_bit((void *) &b->lock, BUCKET_LOCK_BITNR);
4849
}
4950

fs/bcachefs/ec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ static inline void gc_stripe_unlock(struct gc_stripe *s)
160160
BUILD_BUG_ON(!((union ulong_byte_assert) { .ulong = 1UL << BUCKET_LOCK_BITNR }).byte);
161161

162162
clear_bit_unlock(BUCKET_LOCK_BITNR, (void *) &s->lock);
163+
smp_mb__after_atomic();
163164
wake_up_bit((void *) &s->lock, BUCKET_LOCK_BITNR);
164165
}
165166

fs/bcachefs/errcode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@
269269
x(BCH_ERR_invalid_sb, invalid_sb_downgrade) \
270270
x(BCH_ERR_invalid, invalid_bkey) \
271271
x(BCH_ERR_operation_blocked, nocow_lock_blocked) \
272-
x(EIO, journal_shutdown) \
272+
x(EROFS, journal_shutdown) \
273273
x(EIO, journal_flush_err) \
274274
x(EIO, journal_write_err) \
275275
x(EIO, btree_node_read_err) \

fs/bcachefs/extents.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,8 +1056,9 @@ bch2_extent_has_ptr(struct bkey_s_c k1, struct extent_ptr_decoded p1, struct bke
10561056
static bool want_cached_ptr(struct bch_fs *c, struct bch_io_opts *opts,
10571057
struct bch_extent_ptr *ptr)
10581058
{
1059-
if (!opts->promote_target ||
1060-
!bch2_dev_in_target(c, ptr->dev, opts->promote_target))
1059+
unsigned target = opts->promote_target ?: opts->foreground_target;
1060+
1061+
if (target && !bch2_dev_in_target(c, ptr->dev, target))
10611062
return false;
10621063

10631064
struct bch_dev *ca = bch2_dev_rcu_noerror(c, ptr->dev);

fs/bcachefs/fs.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,10 +2502,9 @@ static int bch2_fs_get_tree(struct fs_context *fc)
25022502

25032503
bch2_opts_apply(&c->opts, opts);
25042504

2505-
/*
2506-
* need to initialise sb and set c->vfs_sb _before_ starting fs,
2507-
* for blk_holder_ops
2508-
*/
2505+
ret = bch2_fs_start(c);
2506+
if (ret)
2507+
goto err_stop_fs;
25092508

25102509
sb = sget(fc->fs_type, NULL, bch2_set_super, fc->sb_flags|SB_NOSEC, c);
25112510
ret = PTR_ERR_OR_ZERO(sb);
@@ -2567,10 +2566,6 @@ static int bch2_fs_get_tree(struct fs_context *fc)
25672566

25682567
sb->s_shrink->seeks = 0;
25692568

2570-
ret = bch2_fs_start(c);
2571-
if (ret)
2572-
goto err_put_super;
2573-
25742569
#ifdef CONFIG_UNICODE
25752570
sb->s_encoding = c->cf_encoding;
25762571
#endif

fs/bcachefs/journal_io.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <linux/ioprio.h>
2121
#include <linux/string_choices.h>
22+
#include <linux/sched/sysctl.h>
2223

2324
void bch2_journal_pos_from_member_info_set(struct bch_fs *c)
2425
{
@@ -1262,7 +1263,8 @@ int bch2_journal_read(struct bch_fs *c,
12621263
degraded = true;
12631264
}
12641265

1265-
closure_sync(&jlist.cl);
1266+
while (closure_sync_timeout(&jlist.cl, sysctl_hung_task_timeout_secs * HZ / 2))
1267+
;
12661268

12671269
if (jlist.ret)
12681270
return jlist.ret;

fs/bcachefs/journal_reclaim.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,11 @@ void bch2_journal_space_available(struct journal *j)
266266

267267
static bool should_discard_bucket(struct journal *j, struct journal_device *ja)
268268
{
269-
bool ret;
270-
271269
spin_lock(&j->lock);
272-
ret = ja->discard_idx != ja->dirty_idx_ondisk;
270+
unsigned min_free = max(4, ja->nr / 8);
271+
272+
bool ret = bch2_journal_dev_buckets_available(j, ja, journal_space_discarded) < min_free &&
273+
ja->discard_idx != ja->dirty_idx_ondisk;
273274
spin_unlock(&j->lock);
274275

275276
return ret;

fs/bcachefs/move.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,8 @@ static int __bch2_move_data_phys(struct moving_context *ctxt,
784784
goto err;
785785

786786
ret = bch2_btree_write_buffer_tryflush(trans);
787-
bch_err_msg(c, ret, "flushing btree write buffer");
787+
if (!bch2_err_matches(ret, EROFS))
788+
bch_err_msg(c, ret, "flushing btree write buffer");
788789
if (ret)
789790
goto err;
790791

0 commit comments

Comments
 (0)