Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

fs: prepare for stackable filesystems backing file helpers

In preparation for factoring out some backing file io helpers from
overlayfs, move backing_file_open() into a new file fs/backing-file.c
and header.

Add a MAINTAINERS entry for stackable filesystems and add a Kconfig
FS_STACK which stackable filesystems need to select.

For now, the backing_file struct, the backing_file alloc/free functions
and the backing_file_real_path() accessor remain internal to file_table.c.
We may change that in the future.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>

+81 -41
+9
MAINTAINERS
··· 8186 8186 F: fs/iomap/ 8187 8187 F: include/linux/iomap.h 8188 8188 8189 + FILESYSTEMS [STACKABLE] 8190 + M: Miklos Szeredi <miklos@szeredi.hu> 8191 + M: Amir Goldstein <amir73il@gmail.com> 8192 + L: linux-fsdevel@vger.kernel.org 8193 + L: linux-unionfs@vger.kernel.org 8194 + S: Maintained 8195 + F: fs/backing-file.c 8196 + F: include/linux/backing-file.h 8197 + 8189 8198 FINTEK F75375S HARDWARE MONITOR AND FAN CONTROLLER DRIVER 8190 8199 M: Riku Voipio <riku.voipio@iki.fi> 8191 8200 L: linux-hwmon@vger.kernel.org
+4
fs/Kconfig
··· 18 18 config FS_IOMAP 19 19 bool 20 20 21 + # Stackable filesystems 22 + config FS_STACK 23 + bool 24 + 21 25 config BUFFER_HEAD 22 26 bool 23 27
+1
fs/Makefile
··· 39 39 obj-$(CONFIG_BINFMT_ELF_FDPIC) += binfmt_elf_fdpic.o 40 40 obj-$(CONFIG_BINFMT_FLAT) += binfmt_flat.o 41 41 42 + obj-$(CONFIG_FS_STACK) += backing-file.o 42 43 obj-$(CONFIG_FS_MBCACHE) += mbcache.o 43 44 obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o 44 45 obj-$(CONFIG_NFS_COMMON) += nfs_common/
+48
fs/backing-file.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Common helpers for stackable filesystems and backing files. 4 + * 5 + * Copyright (C) 2023 CTERA Networks. 6 + */ 7 + 8 + #include <linux/fs.h> 9 + #include <linux/backing-file.h> 10 + 11 + #include "internal.h" 12 + 13 + /** 14 + * backing_file_open - open a backing file for kernel internal use 15 + * @user_path: path that the user reuqested to open 16 + * @flags: open flags 17 + * @real_path: path of the backing file 18 + * @cred: credentials for open 19 + * 20 + * Open a backing file for a stackable filesystem (e.g., overlayfs). 21 + * @user_path may be on the stackable filesystem and @real_path on the 22 + * underlying filesystem. In this case, we want to be able to return the 23 + * @user_path of the stackable filesystem. This is done by embedding the 24 + * returned file into a container structure that also stores the stacked 25 + * file's path, which can be retrieved using backing_file_user_path(). 26 + */ 27 + struct file *backing_file_open(const struct path *user_path, int flags, 28 + const struct path *real_path, 29 + const struct cred *cred) 30 + { 31 + struct file *f; 32 + int error; 33 + 34 + f = alloc_empty_backing_file(flags, cred); 35 + if (IS_ERR(f)) 36 + return f; 37 + 38 + path_get(user_path); 39 + *backing_file_user_path(f) = *user_path; 40 + error = vfs_open(real_path, f); 41 + if (error) { 42 + fput(f); 43 + f = ERR_PTR(error); 44 + } 45 + 46 + return f; 47 + } 48 + EXPORT_SYMBOL_GPL(backing_file_open);
-38
fs/open.c
··· 1184 1184 } 1185 1185 EXPORT_SYMBOL_GPL(kernel_file_open); 1186 1186 1187 - /** 1188 - * backing_file_open - open a backing file for kernel internal use 1189 - * @user_path: path that the user reuqested to open 1190 - * @flags: open flags 1191 - * @real_path: path of the backing file 1192 - * @cred: credentials for open 1193 - * 1194 - * Open a backing file for a stackable filesystem (e.g., overlayfs). 1195 - * @user_path may be on the stackable filesystem and @real_path on the 1196 - * underlying filesystem. In this case, we want to be able to return the 1197 - * @user_path of the stackable filesystem. This is done by embedding the 1198 - * returned file into a container structure that also stores the stacked 1199 - * file's path, which can be retrieved using backing_file_user_path(). 1200 - */ 1201 - struct file *backing_file_open(const struct path *user_path, int flags, 1202 - const struct path *real_path, 1203 - const struct cred *cred) 1204 - { 1205 - struct file *f; 1206 - int error; 1207 - 1208 - f = alloc_empty_backing_file(flags, cred); 1209 - if (IS_ERR(f)) 1210 - return f; 1211 - 1212 - path_get(user_path); 1213 - *backing_file_user_path(f) = *user_path; 1214 - f->f_path = *real_path; 1215 - error = do_dentry_open(f, d_inode(real_path->dentry), NULL); 1216 - if (error) { 1217 - fput(f); 1218 - f = ERR_PTR(error); 1219 - } 1220 - 1221 - return f; 1222 - } 1223 - EXPORT_SYMBOL_GPL(backing_file_open); 1224 - 1225 1187 #define WILL_CREATE(flags) (flags & (O_CREAT | __O_TMPFILE)) 1226 1188 #define O_PATH_FLAGS (O_DIRECTORY | O_NOFOLLOW | O_PATH | O_CLOEXEC) 1227 1189
+1
fs/overlayfs/Kconfig
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 config OVERLAY_FS 3 3 tristate "Overlay filesystem support" 4 + select FS_STACK 4 5 select EXPORTFS 5 6 help 6 7 An overlay filesystem combines two filesystems - an 'upper' filesystem
+1
fs/overlayfs/file.c
··· 13 13 #include <linux/security.h> 14 14 #include <linux/mm.h> 15 15 #include <linux/fs.h> 16 + #include <linux/backing-file.h> 16 17 #include "overlayfs.h" 17 18 18 19 #include "../internal.h" /* for sb_init_dio_done_wq */
+17
include/linux/backing-file.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Common helpers for stackable filesystems and backing files. 4 + * 5 + * Copyright (C) 2023 CTERA Networks. 6 + */ 7 + 8 + #ifndef _LINUX_BACKING_FILE_H 9 + #define _LINUX_BACKING_FILE_H 10 + 11 + #include <linux/file.h> 12 + 13 + struct file *backing_file_open(const struct path *user_path, int flags, 14 + const struct path *real_path, 15 + const struct cred *cred); 16 + 17 + #endif /* _LINUX_BACKING_FILE_H */
-3
include/linux/fs.h
··· 2575 2575 const struct cred *creds); 2576 2576 struct file *dentry_create(const struct path *path, int flags, umode_t mode, 2577 2577 const struct cred *cred); 2578 - struct file *backing_file_open(const struct path *user_path, int flags, 2579 - const struct path *real_path, 2580 - const struct cred *cred); 2581 2578 struct path *backing_file_user_path(struct file *f); 2582 2579 2583 2580 /*