Skip to content

Commit caab547

Browse files
author
Kent Overstreet
committed
bcachefs: Print mount opts earlier
If we aren't mounting with the correct degraded option, it's helpful to know that before we fail to mount degraded. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 7cb8532 commit caab547

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

fs/bcachefs/super.c

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,13 +1004,50 @@ static void print_mount_opts(struct bch_fs *c)
10041004
printbuf_exit(&p);
10051005
}
10061006

1007+
static bool bch2_fs_may_start(struct bch_fs *c)
1008+
{
1009+
struct bch_dev *ca;
1010+
unsigned i, flags = 0;
1011+
1012+
if (c->opts.very_degraded)
1013+
flags |= BCH_FORCE_IF_DEGRADED|BCH_FORCE_IF_LOST;
1014+
1015+
if (c->opts.degraded)
1016+
flags |= BCH_FORCE_IF_DEGRADED;
1017+
1018+
if (!c->opts.degraded &&
1019+
!c->opts.very_degraded) {
1020+
mutex_lock(&c->sb_lock);
1021+
1022+
for (i = 0; i < c->disk_sb.sb->nr_devices; i++) {
1023+
if (!bch2_member_exists(c->disk_sb.sb, i))
1024+
continue;
1025+
1026+
ca = bch2_dev_locked(c, i);
1027+
1028+
if (!bch2_dev_is_online(ca) &&
1029+
(ca->mi.state == BCH_MEMBER_STATE_rw ||
1030+
ca->mi.state == BCH_MEMBER_STATE_ro)) {
1031+
mutex_unlock(&c->sb_lock);
1032+
return false;
1033+
}
1034+
}
1035+
mutex_unlock(&c->sb_lock);
1036+
}
1037+
1038+
return bch2_have_enough_devs(c, bch2_online_devs(c), flags, true);
1039+
}
1040+
10071041
int bch2_fs_start(struct bch_fs *c)
10081042
{
10091043
time64_t now = ktime_get_real_seconds();
10101044
int ret = 0;
10111045

10121046
print_mount_opts(c);
10131047

1048+
if (!bch2_fs_may_start(c))
1049+
return -BCH_ERR_insufficient_devices_to_start;
1050+
10141051
down_write(&c->state_lock);
10151052
mutex_lock(&c->sb_lock);
10161053

@@ -1537,40 +1574,6 @@ bool bch2_dev_state_allowed(struct bch_fs *c, struct bch_dev *ca,
15371574
}
15381575
}
15391576

1540-
static bool bch2_fs_may_start(struct bch_fs *c)
1541-
{
1542-
struct bch_dev *ca;
1543-
unsigned i, flags = 0;
1544-
1545-
if (c->opts.very_degraded)
1546-
flags |= BCH_FORCE_IF_DEGRADED|BCH_FORCE_IF_LOST;
1547-
1548-
if (c->opts.degraded)
1549-
flags |= BCH_FORCE_IF_DEGRADED;
1550-
1551-
if (!c->opts.degraded &&
1552-
!c->opts.very_degraded) {
1553-
mutex_lock(&c->sb_lock);
1554-
1555-
for (i = 0; i < c->disk_sb.sb->nr_devices; i++) {
1556-
if (!bch2_member_exists(c->disk_sb.sb, i))
1557-
continue;
1558-
1559-
ca = bch2_dev_locked(c, i);
1560-
1561-
if (!bch2_dev_is_online(ca) &&
1562-
(ca->mi.state == BCH_MEMBER_STATE_rw ||
1563-
ca->mi.state == BCH_MEMBER_STATE_ro)) {
1564-
mutex_unlock(&c->sb_lock);
1565-
return false;
1566-
}
1567-
}
1568-
mutex_unlock(&c->sb_lock);
1569-
}
1570-
1571-
return bch2_have_enough_devs(c, bch2_online_devs(c), flags, true);
1572-
}
1573-
15741577
static void __bch2_dev_read_only(struct bch_fs *c, struct bch_dev *ca)
15751578
{
15761579
bch2_dev_io_ref_stop(ca, WRITE);
@@ -2206,11 +2209,6 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
22062209
}
22072210
up_write(&c->state_lock);
22082211

2209-
if (!bch2_fs_may_start(c)) {
2210-
ret = -BCH_ERR_insufficient_devices_to_start;
2211-
goto err_print;
2212-
}
2213-
22142212
if (!c->opts.nostart) {
22152213
ret = bch2_fs_start(c);
22162214
if (ret)

0 commit comments

Comments
 (0)