erofs: support idmapped mounts
authorChao Yu <chao@kernel.org>
Tue, 17 May 2022 10:41:03 +0000 (18:41 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Tue, 17 May 2022 15:56:20 +0000 (23:56 +0800)
This patch enables idmapped mounts for erofs, since all dedicated helpers
for this functionality existsm, so, in this patch we just pass down the
user_namespace argument from the VFS methods to the relevant helpers.

Simple idmap example on erofs image:

1. mkdir dir
2. touch dir/file
3. mkfs.erofs erofs.img dir
4. mount -t erofs -o loop erofs.img  /mnt/erofs/

5. ls -ln /mnt/erofs/
total 0
-rw-rw-r-- 1 1000 1000 0 May 17 15:26 file

6. mount-idmapped --map-mount b:1000:1001:1 /mnt/erofs/ /mnt/scratch_erofs/

7. ls -ln /mnt/scratch_erofs/
total 0
-rw-rw-r-- 1 1001 1001 0 May 17 15:26 file

Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Signed-off-by: Chao Yu <chao.yu@oppo.com>
Link: https://lore.kernel.org/r/20220517104103.3570721-1-chao@kernel.org
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
fs/erofs/inode.c
fs/erofs/super.c

index 4b2b1f357972a1e5ff8ac89db76de328da168817..6c28ed75dc82b04e920ef46d4169282b2555cac9 100644 (file)
@@ -365,7 +365,7 @@ int erofs_getattr(struct user_namespace *mnt_userns, const struct path *path,
        stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
                                  STATX_ATTR_IMMUTABLE);
 
-       generic_fillattr(&init_user_ns, inode, stat);
+       generic_fillattr(mnt_userns, inode, stat);
        return 0;
 }
 
index dbfe2cbbb00efabac05802225410fdd2ecb9c00e..a326445af7d0c581bf4a2930f341b9ceeda3fdd2 100644 (file)
@@ -821,7 +821,7 @@ static struct file_system_type erofs_fs_type = {
        .name           = "erofs",
        .init_fs_context = erofs_init_fs_context,
        .kill_sb        = erofs_kill_sb,
-       .fs_flags       = FS_REQUIRES_DEV,
+       .fs_flags       = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
 };
 MODULE_ALIAS_FS("erofs");