bcachefs: Print mount opts earlier
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 22 Apr 2025 01:16:24 +0000 (21:16 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Thu, 24 Apr 2025 23:09:52 +0000 (19:09 -0400)
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>
fs/bcachefs/super.c

index 4060af4692f92866f6a313ba139b7e7ca974779f..e4ab0595c0aef66eff53f9bdc520ff514ad16ede 100644 (file)
@@ -1004,6 +1004,40 @@ static void print_mount_opts(struct bch_fs *c)
        printbuf_exit(&p);
 }
 
+static bool bch2_fs_may_start(struct bch_fs *c)
+{
+       struct bch_dev *ca;
+       unsigned i, flags = 0;
+
+       if (c->opts.very_degraded)
+               flags |= BCH_FORCE_IF_DEGRADED|BCH_FORCE_IF_LOST;
+
+       if (c->opts.degraded)
+               flags |= BCH_FORCE_IF_DEGRADED;
+
+       if (!c->opts.degraded &&
+           !c->opts.very_degraded) {
+               mutex_lock(&c->sb_lock);
+
+               for (i = 0; i < c->disk_sb.sb->nr_devices; i++) {
+                       if (!bch2_member_exists(c->disk_sb.sb, i))
+                               continue;
+
+                       ca = bch2_dev_locked(c, i);
+
+                       if (!bch2_dev_is_online(ca) &&
+                           (ca->mi.state == BCH_MEMBER_STATE_rw ||
+                            ca->mi.state == BCH_MEMBER_STATE_ro)) {
+                               mutex_unlock(&c->sb_lock);
+                               return false;
+                       }
+               }
+               mutex_unlock(&c->sb_lock);
+       }
+
+       return bch2_have_enough_devs(c, bch2_online_devs(c), flags, true);
+}
+
 int bch2_fs_start(struct bch_fs *c)
 {
        time64_t now = ktime_get_real_seconds();
@@ -1011,6 +1045,9 @@ int bch2_fs_start(struct bch_fs *c)
 
        print_mount_opts(c);
 
+       if (!bch2_fs_may_start(c))
+               return -BCH_ERR_insufficient_devices_to_start;
+
        down_write(&c->state_lock);
        mutex_lock(&c->sb_lock);
 
@@ -1537,40 +1574,6 @@ bool bch2_dev_state_allowed(struct bch_fs *c, struct bch_dev *ca,
        }
 }
 
-static bool bch2_fs_may_start(struct bch_fs *c)
-{
-       struct bch_dev *ca;
-       unsigned i, flags = 0;
-
-       if (c->opts.very_degraded)
-               flags |= BCH_FORCE_IF_DEGRADED|BCH_FORCE_IF_LOST;
-
-       if (c->opts.degraded)
-               flags |= BCH_FORCE_IF_DEGRADED;
-
-       if (!c->opts.degraded &&
-           !c->opts.very_degraded) {
-               mutex_lock(&c->sb_lock);
-
-               for (i = 0; i < c->disk_sb.sb->nr_devices; i++) {
-                       if (!bch2_member_exists(c->disk_sb.sb, i))
-                               continue;
-
-                       ca = bch2_dev_locked(c, i);
-
-                       if (!bch2_dev_is_online(ca) &&
-                           (ca->mi.state == BCH_MEMBER_STATE_rw ||
-                            ca->mi.state == BCH_MEMBER_STATE_ro)) {
-                               mutex_unlock(&c->sb_lock);
-                               return false;
-                       }
-               }
-               mutex_unlock(&c->sb_lock);
-       }
-
-       return bch2_have_enough_devs(c, bch2_online_devs(c), flags, true);
-}
-
 static void __bch2_dev_read_only(struct bch_fs *c, struct bch_dev *ca)
 {
        bch2_dev_io_ref_stop(ca, WRITE);
@@ -2206,11 +2209,6 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
        }
        up_write(&c->state_lock);
 
-       if (!bch2_fs_may_start(c)) {
-               ret = -BCH_ERR_insufficient_devices_to_start;
-               goto err_print;
-       }
-
        if (!c->opts.nostart) {
                ret = bch2_fs_start(c);
                if (ret)