bcachefs: Don't fail mount if device has been removed
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 7 Sep 2020 02:58:28 +0000 (22:58 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:44 +0000 (17:08 -0400)
Also - make sure to show the devices we actually have open in /proc

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs.c
fs/bcachefs/super.c

index 562a7a8334363230728a7075bd49d83f396851c6..a4a3085e51850b9962fd9096cb2bc923e1506002 100644 (file)
@@ -1428,6 +1428,24 @@ static int bch2_remount(struct super_block *sb, int *flags, char *data)
        return ret;
 }
 
+static int bch2_show_devname(struct seq_file *seq, struct dentry *root)
+{
+       struct bch_fs *c = root->d_sb->s_fs_info;
+       struct bch_dev *ca;
+       unsigned i;
+       bool first = true;
+
+       for_each_online_member(ca, c, i) {
+               if (!first)
+                       seq_putc(seq, ':');
+               first = false;
+               seq_puts(seq, "/dev/");
+               seq_puts(seq, ca->name);
+       }
+
+       return 0;
+}
+
 static int bch2_show_options(struct seq_file *seq, struct dentry *root)
 {
        struct bch_fs *c = root->d_sb->s_fs_info;
@@ -1451,7 +1469,6 @@ static int bch2_show_options(struct seq_file *seq, struct dentry *root)
        }
 
        return 0;
-
 }
 
 static const struct super_operations bch_super_operations = {
@@ -1461,6 +1478,7 @@ static const struct super_operations bch_super_operations = {
        .evict_inode    = bch2_evict_inode,
        .sync_fs        = bch2_sync_fs,
        .statfs         = bch2_statfs,
+       .show_devname   = bch2_show_devname,
        .show_options   = bch2_show_options,
        .remount_fs     = bch2_remount,
 #if 0
index 7377f44f15df200fa511b7153ec880a9a405a367..cb2b719165cee0069c34c3d7976d1f019b70883a 100644 (file)
@@ -1790,7 +1790,6 @@ err:
 /* return with ref on ca->ref: */
 struct bch_dev *bch2_dev_lookup(struct bch_fs *c, const char *path)
 {
-
        struct bch_dev *ca;
        dev_t dev;
        unsigned i;
@@ -1816,6 +1815,7 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
 {
        struct bch_sb_handle *sb = NULL;
        struct bch_fs *c = NULL;
+       struct bch_sb_field_members *mi;
        unsigned i, best_sb = 0;
        const char *err;
        int ret = -ENOMEM;
@@ -1851,10 +1851,22 @@ struct bch_fs *bch2_fs_open(char * const *devices, unsigned nr_devices,
                    le64_to_cpu(sb[best_sb].sb->seq))
                        best_sb = i;
 
-       for (i = 0; i < nr_devices; i++) {
+       mi = bch2_sb_get_members(sb[best_sb].sb);
+
+       i = 0;
+       while (i < nr_devices) {
+               if (i != best_sb &&
+                   !bch2_dev_exists(sb[best_sb].sb, mi, sb[i].sb->dev_idx)) {
+                       pr_info("%pg has been removed, skipping", sb[i].bdev);
+                       bch2_free_super(&sb[i]);
+                       array_remove_item(sb, nr_devices, i);
+                       continue;
+               }
+
                err = bch2_dev_in_fs(sb[best_sb].sb, sb[i].sb);
                if (err)
                        goto err_print;
+               i++;
        }
 
        ret = -ENOMEM;