]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
bcachefs: Stash a pointer to the filesystem for blk_holder_ops
authorKent Overstreet <kent.overstreet@linux.dev>
Tue, 25 Feb 2025 23:58:46 +0000 (18:58 -0500)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 15 Mar 2025 01:02:16 +0000 (21:02 -0400)
Note that we open block devices before we allocate bch_fs, but once
attached to a filesystem they will be closed before the bch_fs is torn
down - so stashing a pointer without a refcount looks incorrect but it's
not.

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

index 2fef285cfc1ac5c702245f4a6629ddd15105c7f9..74f1e45980db6ced62a4a86cd9862d6c2f0fd6ef 100644 (file)
@@ -748,7 +748,7 @@ retry:
        memset(sb, 0, sizeof(*sb));
        sb->mode        = BLK_OPEN_READ;
        sb->have_bio    = true;
-       sb->holder      = kmalloc(1, GFP_KERNEL);
+       sb->holder      = kzalloc(sizeof(*sb->holder), GFP_KERNEL);
        if (!sb->holder)
                return -ENOMEM;
 
index 11877aea38ec3af2bf074bdd38a2861e3dd16ba0..4d656139561cf0d7329b7efad565854b3fa02b45 100644 (file)
@@ -1431,6 +1431,13 @@ static int __bch2_dev_attach_bdev(struct bch_dev *ca, struct bch_sb_handle *sb)
        ca->disk_sb = *sb;
        memset(sb, 0, sizeof(*sb));
 
+       /*
+        * Stash pointer to the filesystem for blk_holder_ops - note that once
+        * attached to a filesystem, we will always close the block device
+        * before tearing down the filesystem object.
+        */
+       ca->disk_sb.holder->c = ca->fs;
+
        ca->dev = ca->disk_sb.bdev->bd_dev;
 
        percpu_ref_reinit(&ca->io_ref);
index 368a63d938cfc910186fcf13ab9a7917868b269f..3a899f799d1d188a2b3325b6086498229cde188e 100644 (file)
@@ -2,13 +2,19 @@
 #ifndef _BCACHEFS_SUPER_TYPES_H
 #define _BCACHEFS_SUPER_TYPES_H
 
+struct bch_fs;
+
+struct bch_sb_handle_holder {
+       struct bch_fs           *c;
+};
+
 struct bch_sb_handle {
        struct bch_sb           *sb;
        struct file             *s_bdev_file;
        struct block_device     *bdev;
        char                    *sb_name;
        struct bio              *bio;
-       void                    *holder;
+       struct bch_sb_handle_holder *holder;
        size_t                  buffer_size;
        blk_mode_t              mode;
        unsigned                have_layout:1;