Similar to the multi device mode, erofs could be mounted from multiple
blob files (one bootstrap blob file and optional multiple data blob
files). In this case, each device slot contains the path of
corresponding data blob file.

This patch registers corresponding cookie context for each data blob
file. Similarly, the cleanup routine shall be contained in both
.kill_sb() and .put_super() callback for the same reason.

Signed-off-by: Jeffle Xu <jeffl...@linux.alibaba.com>
---
 fs/erofs/internal.h |  1 +
 fs/erofs/super.c    | 12 +++++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index f3a1aa429a93..f60577a7aade 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -52,6 +52,7 @@ struct erofs_device_info {
        char *path;
        struct block_device *bdev;
        struct dax_device *dax_dev;
+       struct erofs_cookie_ctx *ctx;
 
        u32 blocks;
        u32 mapped_blkaddr;
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index 0e5964d8b24b..ea56122f7a35 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -287,6 +287,7 @@ static int erofs_init_devices(struct super_block *sb,
        idr_for_each_entry(&sbi->devs->tree, dif, id) {
                erofs_blk_t blk = erofs_blknr(pos);
                struct block_device *bdev;
+               struct erofs_cookie_ctx *ctx;
 
                if (!page || page->index != blk) {
                        if (page) {
@@ -315,7 +316,12 @@ static int erofs_init_devices(struct super_block *sb,
                        dif->bdev = bdev;
                        dif->dax_dev = fs_dax_get_by_bdev(bdev);
                } else {
-                       /* TODO: multi devs in nodev mode */
+                       ctx = erofs_fscache_get_ctx(sb, dif->path);
+                       if (IS_ERR(ctx)) {
+                               err = PTR_ERR(ctx);
+                               goto err_out;
+                       }
+                       dif->ctx = ctx;
                }
                dif->blocks = le32_to_cpu(dis->blocks);
                dif->mapped_blkaddr = le32_to_cpu(dis->mapped_blkaddr);
@@ -755,6 +761,7 @@ static int erofs_release_device_info(int id, void *ptr, 
void *data)
 {
        struct erofs_device_info *dif = ptr;
 
+       erofs_fscache_put_ctx(dif->ctx);
        fs_put_dax(dif->dax_dev);
        if (dif->bdev)
                blkdev_put(dif->bdev, FMODE_READ | FMODE_EXCL);
@@ -845,6 +852,9 @@ static void erofs_put_super(struct super_block *sb)
        iput(sbi->managed_cache);
        sbi->managed_cache = NULL;
 #endif
+       erofs_free_dev_context(sbi->devs);
+       sbi->devs = NULL;
+
        erofs_fscache_put_ctx(sbi->bootstrap);
        sbi->bootstrap = NULL;
 }
-- 
2.27.0

--
Linux-cachefs mailing list
Linux-cachefs@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-cachefs

Reply via email to