Skip to contentSkip to conversation

introduce configfd as generalisation of fsconfig

PATCH In review James Bottomley 2 participants 9 messages Feb 15, 2020 – Feb 16, 2020

Subsystems (22)
Arm (32-bit) x86 VFS PowerPC +18 more subsystems
lore
Share & tools
lore

James Bottomley

author maintainer
#0 lore raw

v3 cover introduce configfd as generalisation of fsconfig

fsconfig is a very powerful configuration mechanism except that it only works for filesystems with superblocks. This patch series generalises the useful concept of a multiple step configurational mechanism carried by a file descriptor. The object of this patch series is to get bind mounts to be configurable in the same way that superblock based ones are, but it should have utility beyond the filesytem realm. Patch 4 also reimplements fsconfig in terms of configfd, but that's not a strictly necessary patch, it is merely a useful demonstration that configfd is a superset of the properties of fsconfig.

in v3, I swept up Al's prefix generalisation of the log that he expanded to use with ceph and rbd, because it's a nice extension to the original fsconfig log.

The main reason I'm strongly pushing this, is that by my background I dislike abstractions that aren't abstract enough (have unnecessary ties to concrete features like fsconfig does to the superblock), so the physicist in me likes to make them as abstract as possible. The objection, in the email replies to v2 is that making something so powerful too abstract is going to encourage incorrect reuse and thus cause problems because using an interface of huge power on something that doesn't need it damages the API confinement and makes unintended and unexpected uses easy. I still think this is a wrongheaded argument because we do have subsystems that need powerful config interfaces and we should have the taste to ensure the full power is only used there, but I think it's a useful debate to have. For instance, I think the entire annoying keyctl API could usefully deploy this.

Note: v1 of this patch series was originally sent as an rfc in reply to a thread about feature bugs with the new mount API:

https://lore.kernel.org/linux-fsdevel/[email protected]/

James

---

James Bottomley (6):
logger: add a limited buffer logging facility
configfd: add generic file descriptor based configuration parser
configfd: syscall: wire up configfd syscalls
fs: implement fsconfig via configfd
fs: expose internal interfaces open_detached_copy and
do_reconfigure_mount
fs: bind: add configfs type for bind mounts

 arch/alpha/kernel/syscalls/syscall.tbl      |   2 +
 arch/arm/tools/syscall.tbl                  |   2 +
 arch/arm64/include/asm/unistd.h             |   2 +-
 arch/arm64/include/asm/unistd32.h           |   4 +
 arch/ia64/kernel/syscalls/syscall.tbl       |   2 +
 arch/m68k/kernel/syscalls/syscall.tbl       |   2 +
 arch/microblaze/kernel/syscalls/syscall.tbl |   2 +
 arch/mips/kernel/syscalls/syscall_n32.tbl   |   2 +
 arch/mips/kernel/syscalls/syscall_n64.tbl   |   2 +
 arch/mips/kernel/syscalls/syscall_o32.tbl   |   2 +
 arch/parisc/kernel/syscalls/syscall.tbl     |   2 +
 arch/powerpc/kernel/syscalls/syscall.tbl    |   2 +
 arch/s390/kernel/syscalls/syscall.tbl       |   2 +
 arch/sh/kernel/syscalls/syscall.tbl         |   2 +
 arch/sparc/kernel/syscalls/syscall.tbl      |   2 +
 arch/x86/entry/syscalls/syscall_32.tbl      |   2 +
 arch/x86/entry/syscalls/syscall_64.tbl      |   2 +
 arch/xtensa/kernel/syscalls/syscall.tbl     |   2 +
 drivers/block/rbd.c                         |   2 +-
 fs/Makefile                                 |   3 +-
 fs/bind.c                                   | 232 ++++++++++++
 fs/ceph/super.c                             |   4 +-
 fs/configfd.c                               | 451 ++++++++++++++++++++++++
 fs/filesystems.c                            |   8 +-
 fs/fs_context.c                             |  97 +----
 fs/fs_parser.c                              |  24 +-
 fs/fsopen.c                                 | 529 ++++++++++++++--------------
 fs/internal.h                               |   7 +
 fs/namespace.c                              | 115 +++---
 include/linux/ceph/libceph.h                |   5 +-
 include/linux/configfd.h                    |  61 ++++
 include/linux/fs.h                          |   2 +
 include/linux/fs_context.h                  |  58 ++-
 include/linux/fs_parser.h                   |   9 +-
 include/linux/logger.h                      |  45 +++
 include/linux/syscalls.h                    |   5 +
 include/uapi/asm-generic/unistd.h           |   9 +-
 include/uapi/linux/configfd.h               |  20 ++
 lib/Makefile                                |   3 +-
 lib/logger.c                                | 190 ++++++++++
 net/ceph/ceph_common.c                      |  26 +-
 41 files changed, 1457 insertions(+), 486 deletions(-)
 create mode 100644 fs/bind.c
 create mode 100644 fs/configfd.c
 create mode 100644 include/linux/configfd.h
 create mode 100644 include/linux/logger.h
 create mode 100644 include/uapi/linux/configfd.h
 create mode 100644 lib/logger.c
Signature · 1 line
2.16.4
author maintainer
#1 lore raw

PATCH v3 1/6 logger: add a limited buffer logging facility

Can be used by anything that wants to add to a list of messages and then spit them back at a particular time. The current use case for this is the filesystem configuration descriptor, which can accumulate messages about config options which can then be read from the file descriptor later via a .read operation.

This code was based on fc_log originally written by David Howells in commit e7582e16a170 "vfs: Implement logging through fs_context" and subsequently extended to include a prefix logger by Al Viro in commit cc3c0b533ab9 "add prefix to fs_context->log".

---

v3: add prefix logger

---
 include/linux/logger.h |  45 ++++++++++++
 lib/Makefile           |   3 +-
 lib/logger.c           | 190 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 237 insertions(+), 1 deletion(-)
 create mode 100644 include/linux/logger.h
 create mode 100644 lib/logger.c
include/linux/logger.h new file +45 -0
new file mode 100644
index 000000000000..27c2650a72da
@@ -0,0 +1,45 @@
+#ifndef _LINUX_LOGGER_H
+#define _LINUX_LOGGER_H
+
+#include <stdarg.h>
+
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/refcount.h>
+#include <linux/types.h>
+
+struct logger {
+	const char	*prefix;
+	refcount_t	usage;
+	struct mutex	mutex;
+	u8		head;		/* Insertion index in buffer[] */
+	u8		tail;		/* Removal index in buffer[] */
+	u8		need_free;	/* Mask of kfree'able items in buffer[] */
+	struct module	*owner;		/* Owner module for strings that don't then need freeing */
+	const char	*buffer[8];
+};
+
+struct plogger {
+	const char	*prefix;
+	struct logger	*log;
+};
+
+extern __printf(4, 5)
+void logger_log(struct logger *, const char *prefix, char level,
+		const char *fmt, ...);
+extern __printf(4, 0)
+void logger_valog(struct logger *, const char *prefix, char level,
+		  const char *fmt, va_list va);
+ssize_t logger_read(struct logger *log, char __user *_buf,  size_t len);
+struct logger *logger_alloc(struct module *owner);
+void logger_put(struct logger **logp);
+void logger_get(struct logger *log);
+
+#define logger_err(log, fmt, ...) ({ logger_log(log, NULL, 'e', fmt, ## __VA_ARGS__); })
+#define logger_warn(log, fmt, ...) ({ logger_log(log, NULL, 'w', fmt, ## __VA_ARGS__); })
+#define logger_info(log, fmt, ...) ({ logger_log(log, NULL, 'i', fmt, ## __VA_ARGS__); })
+#define plogger_err(plog, fmt, ...) ({ logger_log((plog)->log, (plog)->prefix, 'e', fmt, ## __VA_ARGS__); })
+#define plogger_warn(log, fmt, ...) ({ logger_log((plog)->log, (plog)->prefix, 'w', fmt, ## __VA_ARGS__); })
+#define plogger_info(log, fmt, ...) ({ logger_log((plog)->log, (plog)->prefix, 'i', fmt, ## __VA_ARGS__); })
+
+#endif
lib/Makefile +2 -1
index 5d64890d6b6a..3c9b9db35e1a 100644
@@ -31,7 +31,8 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \
 	 flex_proportions.o ratelimit.o show_mem.o \
 	 is_single_threaded.o plist.o decompress.o kobject_uevent.o \
 	 earlycpio.o seq_buf.o siphash.o dec_and_lock.o \
-	 nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o
+	 nmi_backtrace.o nodemask.o win_minmax.o memcat_p.o \
+	 logger.o
 
 lib-$(CONFIG_PRINTK) += dump_stack.o
 lib-$(CONFIG_MMU) += ioremap.o
lib/logger.c new file +190 -0

190 lines not on this page · raw message

Signature · 1 line
2.16.4
author maintainer
#2 lore raw

PATCH v3 2/6 configfd: add generic file descriptor based configuration parser

In reply to James Bottomley

This code is based on the original filesystem context based configuration parser by David Howells, but lifted up so it can apply to anything rather than only filesystem contexts.

---

v3: use prefix logger

---
 fs/Makefile                   |   3 +-
 fs/configfd.c                 | 451 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/configfd.h      |  61 ++++++
 include/uapi/linux/configfd.h |  20 ++
 4 files changed, 534 insertions(+), 1 deletion(-)
 create mode 100644 fs/configfd.c
 create mode 100644 include/linux/configfd.h
 create mode 100644 include/uapi/linux/configfd.h
fs/Makefile +2 -1
index 505e51166973..2c078355fdf5 100644
@@ -13,7 +13,8 @@ obj-y :=	open.o read_write.o file_table.o super.o \
 		seq_file.o xattr.o libfs.o fs-writeback.o \
 		pnode.o splice.o sync.o utimes.o d_path.o \
 		stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \
-		fs_types.o fs_context.o fs_parser.o fsopen.o
+		fs_types.o fs_context.o fs_parser.o fsopen.o \
+		configfd.o
 
 ifeq ($(CONFIG_BLOCK),y)
 obj-y +=	buffer.o block_dev.o direct-io.o mpage.o
fs/configfd.c new file +451 -0

451 lines not on this page · raw message

include/linux/configfd.h new file +61 -0

61 lines not on this page · raw message

include/uapi/linux/configfd.h new file +20 -0
new file mode 100644
index 000000000000..3e54cfef0182
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later WITH Linux-syscall-note */
+
+#ifndef _UAPI_LINUX_CONFIGFD_H
+#define _UAPI_LINUX_CONFIGFD_H
+
+enum configfd_cmd {
+	CONFIGFD_SET_FLAG		= 0,
+	CONFIGFD_SET_STRING		= 1,
+	CONFIGFD_SET_BINARY		= 2,
+	CONFIGFD_SET_PATH		= 3,
+	CONFIGFD_SET_PATH_EMPTY		= 4,
+	CONFIGFD_SET_FD			= 5,
+	CONFIGFD_CMD_CREATE		= 6,
+	CONFIGFD_CMD_RECONFIGURE	= 7,
+	/* gap for 30 other commands */
+	CONFIGFD_SET_INT		= 38,
+	CONFIGFD_GET_FD			= 39,
+};
+
+#endif
Signature · 1 line
2.16.4
author maintainer
#3 lore raw

PATCH v3 3/6 configfd: syscall: wire up configfd syscalls

In reply to James Bottomley

---

v3: Changed numbering to avoid clash with pidfd calls

---
 arch/alpha/kernel/syscalls/syscall.tbl      | 2 ++
 arch/arm/tools/syscall.tbl                  | 2 ++
 arch/arm64/include/asm/unistd.h             | 2 +-
 arch/arm64/include/asm/unistd32.h           | 4 ++++
 arch/ia64/kernel/syscalls/syscall.tbl       | 2 ++
 arch/m68k/kernel/syscalls/syscall.tbl       | 2 ++
 arch/microblaze/kernel/syscalls/syscall.tbl | 2 ++
 arch/mips/kernel/syscalls/syscall_n32.tbl   | 2 ++
 arch/mips/kernel/syscalls/syscall_n64.tbl   | 2 ++
 arch/mips/kernel/syscalls/syscall_o32.tbl   | 2 ++
 arch/parisc/kernel/syscalls/syscall.tbl     | 2 ++
 arch/powerpc/kernel/syscalls/syscall.tbl    | 2 ++
 arch/s390/kernel/syscalls/syscall.tbl       | 2 ++
 arch/sh/kernel/syscalls/syscall.tbl         | 2 ++
 arch/sparc/kernel/syscalls/syscall.tbl      | 2 ++
 arch/x86/entry/syscalls/syscall_32.tbl      | 2 ++
 arch/x86/entry/syscalls/syscall_64.tbl      | 2 ++
 arch/xtensa/kernel/syscalls/syscall.tbl     | 2 ++
 include/linux/syscalls.h                    | 5 +++++
 include/uapi/asm-generic/unistd.h           | 9 +++++++--
 20 files changed, 49 insertions(+), 3 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl +2 -0
index 36d42da7466a..657c9cd71307 100644
@@ -477,3 +477,5 @@
 # 545 reserved for clone3
 547	common	openat2				sys_openat2
 548	common	pidfd_getfd			sys_pidfd_getfd
+549	common	configfd_open			configfd_open
+550	common	configfd_action			configfd_action
arch/arm/tools/syscall.tbl +2 -0
index 4d1cf74a2caa..43cbcfe14e38 100644
@@ -451,3 +451,5 @@
 435	common	clone3				sys_clone3
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
+439	common	configfd_open			sys_configfd_open
+440	common	configfd_action			sys_configfd_action
arch/arm64/include/asm/unistd.h +1 -1
index 1dd22da1c3a9..bc0f923e0e04 100644
@@ -38,7 +38,7 @@
 #define __ARM_NR_compat_set_tls		(__ARM_NR_COMPAT_BASE + 5)
 #define __ARM_NR_COMPAT_END		(__ARM_NR_COMPAT_BASE + 0x800)
 
-#define __NR_compat_syscalls		439
+#define __NR_compat_syscalls		441
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
arch/arm64/include/asm/unistd32.h +4 -0
index c1c61635f89c..46881451186e 100644
@@ -883,6 +883,10 @@ __SYSCALL(__NR_clone3, sys_clone3)
 __SYSCALL(__NR_openat2, sys_openat2)
 #define __NR_pidfd_getfd 438
 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
+#define __NR_configfd_open 439
+__SYSCALL(__NR_configfd_open, sys_configfd_open)
+#define __NR_configfd_action 440
+__SYSCALL(__NR_configfd_action, sys_configfd_action)
 
 /*
  * Please add new compat syscalls above this comment and update
arch/ia64/kernel/syscalls/syscall.tbl +2 -0
index 042911e670b8..e9c143d99b96 100644
@@ -358,3 +358,5 @@
 # 435 reserved for clone3
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
+439	common	configfd_open			sys_configfd_open
+440	common	configfd_action			sys_configfd_action
arch/m68k/kernel/syscalls/syscall.tbl +2 -0
index f4f49fcb76d0..d9b54e720918 100644
@@ -437,3 +437,5 @@
 435	common	clone3				__sys_clone3
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
+439	common	configfd_open			sys_configfd_open
+440	common	configfd_action			sys_configfd_action
arch/microblaze/kernel/syscalls/syscall.tbl +2 -0
index 4c67b11f9c9e..4431f66cb9a6 100644
@@ -443,3 +443,5 @@
 435	common	clone3				sys_clone3
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
+439	common	configfd_open			sys_configfd_open
+440	common	configfd_action			sys_configfd_action
arch/mips/kernel/syscalls/syscall_n32.tbl +2 -0
index 1f9e8ad636cc..51523527fe88 100644
@@ -376,3 +376,5 @@
 435	n32	clone3				__sys_clone3
 437	n32	openat2				sys_openat2
 438	n32	pidfd_getfd			sys_pidfd_getfd
+439	n32	configfd_open			sys_configfd_open
+440	n32	configfd_action			sys_configfd_action
arch/mips/kernel/syscalls/syscall_n64.tbl +2 -0
index c0b9d802dbf6..eae82af997c2 100644
@@ -352,3 +352,5 @@
 435	n64	clone3				__sys_clone3
 437	n64	openat2				sys_openat2
 438	n64	pidfd_getfd			sys_pidfd_getfd
+439	n64	configfd_open			sys_configfd_open
+440	n64	configfd_action			sys_configfd_action
arch/mips/kernel/syscalls/syscall_o32.tbl +2 -0
index ac586774c980..d813d89521a3 100644
@@ -425,3 +425,5 @@
 435	o32	clone3				__sys_clone3
 437	o32	openat2				sys_openat2
 438	o32	pidfd_getfd			sys_pidfd_getfd
+439	o32	configfd_open			sys_configfd_open
+440	o32	configfd_action			sys_configfd_action
arch/parisc/kernel/syscalls/syscall.tbl +2 -0
index 52a15f5cd130..f24f48b7123a 100644
@@ -435,3 +435,5 @@
 435	common	clone3				sys_clone3_wrapper
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
+439	common	configfd_open			sys_configfd_open
+440	common	configfd_action			sys_configfd_action
arch/powerpc/kernel/syscalls/syscall.tbl +2 -0
index 35b61bfc1b1a..4586f9c5a76c 100644
@@ -519,3 +519,5 @@
 435	nospu	clone3				ppc_clone3
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
+439	common	configfd_open			sys_configfd_open
+440	common	configfd_action			sys_configfd_action
arch/s390/kernel/syscalls/syscall.tbl +2 -0
index bd7bd3581a0f..a047a75ed6e7 100644
@@ -440,3 +440,5 @@
 435  common	clone3			sys_clone3			sys_clone3
 437  common	openat2			sys_openat2			sys_openat2
 438  common	pidfd_getfd		sys_pidfd_getfd			sys_pidfd_getfd
+439  common	configfd_open		sys_configfd_open		sys_configfd_open
+440  common	configfd_action		sys_configfd_action		sys_configfd_action
arch/sh/kernel/syscalls/syscall.tbl +2 -0
index c7a30fcd135f..435bf5ce7be0 100644
@@ -440,3 +440,5 @@
 # 435 reserved for clone3
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
+439	common	configfd_open			sys_configfd_open
+440	common	configfd_action			sys_configfd_action
arch/sparc/kernel/syscalls/syscall.tbl +2 -0
index f13615ecdecc..4f73a7d80c4a 100644
@@ -483,3 +483,5 @@
 # 435 reserved for clone3
 437	common	openat2			sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
+439	common	configfd_open			sys_configfd_open
+440	common	configfd_action			sys_configfd_action
arch/x86/entry/syscalls/syscall_32.tbl +2 -0
index c17cb77eb150..fc5101e9e6c4 100644
@@ -442,3 +442,5 @@
 435	i386	clone3			sys_clone3			__ia32_sys_clone3
 437	i386	openat2			sys_openat2			__ia32_sys_openat2
 438	i386	pidfd_getfd		sys_pidfd_getfd			__ia32_sys_pidfd_getfd
+436	i386	configfd_open		sys_configfd_open		__ia32_sys_configfd_open
+437	i386	configfd_action		sys_configfd_action		__ia32_sys_configfd_action
arch/x86/entry/syscalls/syscall_64.tbl +2 -0
index 44d510bc9b78..3dc52c1329dc 100644
@@ -359,6 +359,8 @@
 435	common	clone3			__x64_sys_clone3/ptregs
 437	common	openat2			__x64_sys_openat2
 438	common	pidfd_getfd		__x64_sys_pidfd_getfd
+439	common	configfd_open		__x64_sys_configfd_open
+440	common	configfd_action		__x64_sys_configfd_action
 
 #
 # x32-specific system call numbers start at 512 to avoid cache impact
arch/xtensa/kernel/syscalls/syscall.tbl +2 -0
index 85a9ab1bc04d..b023e36c4964 100644
@@ -408,3 +408,5 @@
 435	common	clone3				sys_clone3
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
+439	common	configfd_open			sys_configfd_open
+440	common	configfd_action			sys_configfd_action
include/linux/syscalls.h +5 -0
index 1815065d52f3..298d56120470 100644
@@ -1003,6 +1003,11 @@ asmlinkage long sys_pidfd_send_signal(int pidfd, int sig,
 				       siginfo_t __user *info,
 				       unsigned int flags);
 asmlinkage long sys_pidfd_getfd(int pidfd, int fd, unsigned int flags);
+asmlinkage long sys_configfd_open(const char __user *config_name,
+				  unsigned int flags, unsigned int op);
+asmlinkage long sys_configfd_action(int fd, unsigned int cmd,
+				    const char __user *key, void __user *value,
+				    int aux);
 
 /*
  * Architecture-specific system calls
include/uapi/asm-generic/unistd.h +7 -2
index 3a3201e4618e..29c55ef11fb1 100644
@@ -849,15 +849,20 @@ __SYSCALL(__NR_pidfd_open, sys_pidfd_open)
 #ifdef __ARCH_WANT_SYS_CLONE3
 #define __NR_clone3 435
 __SYSCALL(__NR_clone3, sys_clone3)
-#endif
 
+#endif
 #define __NR_openat2 437
 __SYSCALL(__NR_openat2, sys_openat2)
 #define __NR_pidfd_getfd 438
 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
+#define __NR_configfd_open 439
+__SYSCALL(__NR_configfd_open, sys_configfd_open)
+#define __NR_configfd_action 440
+__SYSCALL(__NR_configfd_action, sys_configfd_action)
+
 
 #undef __NR_syscalls
-#define __NR_syscalls 439
+#define __NR_syscalls 441
 
 /*
  * 32 bit systems traditionally used different
Signature · 1 line
2.16.4
#4 lore raw

Re: [PATCH v3 3/6] configfd: syscall: wire up configfd syscalls

arch/x86/entry/syscalls/syscall_32.tbl line 446

Quoted 10 lines · James Bottomley
arch/x86/entry/syscalls/syscall_32.tbl +2 -0
index c17cb77eb150..fc5101e9e6c4 100644
@@ -442,3 +442,5 @@
 435	i386	clone3			sys_clone3			__ia32_sys_clone3
 437	i386	openat2			sys_openat2			__ia32_sys_openat2
 438	i386	pidfd_getfd		sys_pidfd_getfd			__ia32_sys_pidfd_getfd
+436	i386	configfd_open		sys_configfd_open		__ia32_sys_configfd_open
+437	i386	configfd_action		sys_configfd_action		__ia32_sys_configfd_action

Did you mean:

+439 i386 configfd_open sys_configfd_open __ia32_sys_configfd_open
+440 i386 configfd_action sys_configfd_action __ia32_sys_configfd_action

Signature · 4 lines
Aleksa Sarai
Senior Software Engineer (Containers)
SUSE Linux GmbH
<https://www.cyphar.com/>
author maintainer
#5 lore raw

Re: [PATCH v3 3/6] configfd: syscall: wire up configfd syscalls

Quoted 21 lines · Aleksa Sarai

On 2020-02-15, James Bottomley <[email protected]

Quoted 13 lines

wrote:

arch/x86/entry/syscalls/syscall_32.tbl +0 -0
index c17cb77eb150..fc5101e9e6c4 100644
@@ -442,3 +442,5 @@
 435	i386	clone3			sys_clone3	
 		__ia32_sys_clone3
 437	i386	openat2			sys_openat2	
		__ia32_sys_openat2
 438	i386	pidfd_getfd		sys_pidfd_getfd	
		__ia32_sys_pidfd_getfd
Quoted 4 lines

+436 i386 configfd_open sys_configfd_o
pen __ia32_sys_configfd_open
+437 i386 configfd_action sys_configfd
_action __ia32_sys_configfd_action

Did you mean:

Quoted 4 lines

+439 i386 configfd_open sys_configfd_ope
n __ia32_sys_configfd_open
+440 i386 configfd_action sys_configfd_a
ction __ia32_sys_configfd_action

Yes, I obviously screwed up the rebase on that one.

James

author maintainer
#6 lore raw

PATCH v3 4/6 fs: implement fsconfig via configfd

In reply to James Bottomley

This changes the internal implementation of fsconfig, while keeping all the external system calls. However, it now becomes possible to all the same operations via configfd instead of fsconfig.

For example a filesystem remount read-only can be done:

fd = configfd_open("mount", O_CLOEXEC, CONFIGFD_CMD_RECONFIGURE); mntpnt = open("/path/to/mount", O_PATH); configfd_action(fd, CONFIGFD_SET_FD, "pathfd", NULL, mntpnt); configfd_action(fd, CONFIGFD_SET_FLAG, "ro", NULL, 0); configfd_action(fd, CONFIGFD_CMD_RECONFIGURE, NULL, NULL, 0);

And mounting a tmpfs filesystem nodev,noexec:

fd = configfd_open("tmpfs", O_CLOEXEC, CONFIGFD_CMD_CREATE); configfd_action(fd, CONFIGFD_SET_INT, "mount_attrs", NULL,

		MOUNT_ATTR_NODEV|MOUNT_ATTR_NOEXEC);

configfd_action(fd, CONFIGFD_CMD_CREATE, NULL, NULL, 0); configfd_action(fd, CONFIGFD_GET_FD, "mountfd", &mfd, O_CLOEXEC); mount_move("", mfd, AT_FDCWD, "/mountpoint", MOVE_MOUNT_F_EMPTY_PATH);

---
v2: fix a log oops
v3: sweep up ceph/rdb p_log

---
 drivers/block/rbd.c          |   2 +-
 fs/ceph/super.c              |   4 +-
 fs/filesystems.c             |   8 +-
 fs/fs_context.c              |  97 ++------
 fs/fs_parser.c               |  24 +-
 fs/fsopen.c                  | 529 +++++++++++++++++++++----------------------
 fs/internal.h                |   4 +
 fs/namespace.c               | 111 ++++-----
 include/linux/ceph/libceph.h |   5 +-
 include/linux/fs.h           |   2 +
 include/linux/fs_context.h   |  58 +++--
 include/linux/fs_parser.h    |   9 +-
 net/ceph/ceph_common.c       |  26 +--
 13 files changed, 400 insertions(+), 479 deletions(-)
drivers/block/rbd.c +1 -1
index 6343402c09e6..629fc9f1f6cc 100644
@@ -6348,7 +6348,7 @@ static int rbd_parse_param(struct fs_parameter *param,
 {
 	struct rbd_options *opt = pctx->opts;
 	struct fs_parse_result result;
-	struct p_log log = {.prefix = "rbd"};
+	struct plogger log = {.prefix = "rbd"};
 	int token, ret;
 
 	ret = ceph_parse_param(param, pctx->copts, NULL);
fs/ceph/super.c +2 -2
index 1d9f083b8a11..052750ae897f 100644
@@ -246,7 +246,7 @@ static int ceph_parse_source(struct fs_parameter *param, struct fs_context *fc)
 		dout("server path '%s'\n", fsopt->server_path);
 
 	ret = ceph_parse_mon_ips(param->string, dev_name_end - dev_name,
-				 pctx->copts, fc->log.log);
+				 pctx->copts, &fc->cfc->log);
 	if (ret)
 		return ret;
 
@@ -264,7 +264,7 @@ static int ceph_parse_mount_param(struct fs_context *fc,
 	unsigned int mode;
 	int token, ret;
 
-	ret = ceph_parse_param(param, pctx->copts, fc->log.log);
+	ret = ceph_parse_param(param, pctx->copts, &fc->cfc->log);
 	if (ret != -ENOPARAM)
 		return ret;
 
fs/filesystems.c +6 -2
index 77bf5f95362d..d68e8a415c01 100644
@@ -7,6 +7,7 @@
  *  table of configured filesystems
  */
 
+#include <linux/configfd.h>
 #include <linux/syscalls.h>
 #include <linux/fs.h>
 #include <linux/proc_fs.h>
@@ -83,10 +84,12 @@ int register_filesystem(struct file_system_type * fs)
 		return -EBUSY;
 	write_lock(&file_systems_lock);
 	p = find_filesystem(fs->name, strlen(fs->name));
-	if (*p)
+	if (*p) {
 		res = -EBUSY;
-	else
+	} else {
 		*p = fs;
+		res = fs_context_register(fs);
+	}
 	write_unlock(&file_systems_lock);
 	return res;
 }
@@ -115,6 +118,7 @@ int unregister_filesystem(struct file_system_type * fs)
 		if (fs == *tmp) {
 			*tmp = fs->next;
 			fs->next = NULL;
+			fs_context_unregister(fs);
 			write_unlock(&file_systems_lock);
 			synchronize_rcu();
 			return 0;
fs/fs_context.c +16 -81

139 lines not on this page · raw message

fs/fs_parser.c +12 -12
index 7e6fb43f9541..609f7e1ea506 100644
@@ -100,7 +100,7 @@ static const struct fs_parameter_spec *fs_lookup_key(
  * unknown parameters are okay and -EINVAL if there was a conversion issue or
  * the parameter wasn't recognised and unknowns aren't okay.
  */
-int __fs_parse(struct p_log *log,
+int __fs_parse(struct plogger *log,
 	     const struct fs_parameter_spec *desc,
 	     struct fs_parameter *param,
 	     struct fs_parse_result *result)
@@ -189,12 +189,12 @@ int fs_lookup_param(struct fs_context *fc,
 }
 EXPORT_SYMBOL(fs_lookup_param);
 
-int fs_param_bad_value(struct p_log *log, struct fs_parameter *param)
+int fs_param_bad_value(struct plogger *log, struct fs_parameter *param)
 {
 	return inval_plog(log, "Bad value for '%s'", param->key);
 }
 
-int fs_param_is_bool(struct p_log *log, const struct fs_parameter_spec *p,
+int fs_param_is_bool(struct plogger *log, const struct fs_parameter_spec *p,
 		     struct fs_parameter *param, struct fs_parse_result *result)
 {
 	int b;
@@ -208,7 +208,7 @@ int fs_param_is_bool(struct p_log *log, const struct fs_parameter_spec *p,
 }
 EXPORT_SYMBOL(fs_param_is_bool);
 
-int fs_param_is_u32(struct p_log *log, const struct fs_parameter_spec *p,
+int fs_param_is_u32(struct plogger *log, const struct fs_parameter_spec *p,
 		    struct fs_parameter *param, struct fs_parse_result *result)
 {
 	int base = (unsigned long)p->data;
@@ -219,7 +219,7 @@ int fs_param_is_u32(struct p_log *log, const struct fs_parameter_spec *p,
 }
 EXPORT_SYMBOL(fs_param_is_u32);
 
-int fs_param_is_s32(struct p_log *log, const struct fs_parameter_spec *p,
+int fs_param_is_s32(struct plogger *log, const struct fs_parameter_spec *p,
 		    struct fs_parameter *param, struct fs_parse_result *result)
 {
 	if (param->type != fs_value_is_string ||
@@ -229,7 +229,7 @@ int fs_param_is_s32(struct p_log *log, const struct fs_parameter_spec *p,
 }
 EXPORT_SYMBOL(fs_param_is_s32);
 
-int fs_param_is_u64(struct p_log *log, const struct fs_parameter_spec *p,
+int fs_param_is_u64(struct plogger *log, const struct fs_parameter_spec *p,
 		    struct fs_parameter *param, struct fs_parse_result *result)
 {
 	if (param->type != fs_value_is_string ||
@@ -239,7 +239,7 @@ int fs_param_is_u64(struct p_log *log, const struct fs_parameter_spec *p,
 }
 EXPORT_SYMBOL(fs_param_is_u64);
 
-int fs_param_is_enum(struct p_log *log, const struct fs_parameter_spec *p,
+int fs_param_is_enum(struct plogger *log, const struct fs_parameter_spec *p,
 		     struct fs_parameter *param, struct fs_parse_result *result)
 {
 	const struct constant_table *c;
@@ -253,7 +253,7 @@ int fs_param_is_enum(struct p_log *log, const struct fs_parameter_spec *p,
 }
 EXPORT_SYMBOL(fs_param_is_enum);
 
-int fs_param_is_string(struct p_log *log, const struct fs_parameter_spec *p,
+int fs_param_is_string(struct plogger *log, const struct fs_parameter_spec *p,
 		       struct fs_parameter *param, struct fs_parse_result *result)
 {
 	if (param->type != fs_value_is_string || !*param->string)
@@ -262,7 +262,7 @@ int fs_param_is_string(struct p_log *log, const struct fs_parameter_spec *p,
 }
 EXPORT_SYMBOL(fs_param_is_string);
 
-int fs_param_is_blob(struct p_log *log, const struct fs_parameter_spec *p,
+int fs_param_is_blob(struct plogger *log, const struct fs_parameter_spec *p,
 		     struct fs_parameter *param, struct fs_parse_result *result)
 {
 	if (param->type != fs_value_is_blob)
@@ -271,7 +271,7 @@ int fs_param_is_blob(struct p_log *log, const struct fs_parameter_spec *p,
 }
 EXPORT_SYMBOL(fs_param_is_blob);
 
-int fs_param_is_fd(struct p_log *log, const struct fs_parameter_spec *p,
+int fs_param_is_fd(struct plogger *log, const struct fs_parameter_spec *p,
 		  struct fs_parameter *param, struct fs_parse_result *result)
 {
 	switch (param->type) {
@@ -293,14 +293,14 @@ int fs_param_is_fd(struct p_log *log, const struct fs_parameter_spec *p,
 }
 EXPORT_SYMBOL(fs_param_is_fd);
 
-int fs_param_is_blockdev(struct p_log *log, const struct fs_parameter_spec *p,
+int fs_param_is_blockdev(struct plogger *log, const struct fs_parameter_spec *p,
 		  struct fs_parameter *param, struct fs_parse_result *result)
 {
 	return 0;
 }
 EXPORT_SYMBOL(fs_param_is_blockdev);
 
-int fs_param_is_path(struct p_log *log, const struct fs_parameter_spec *p,
+int fs_param_is_path(struct plogger *log, const struct fs_parameter_spec *p,
 		     struct fs_parameter *param, struct fs_parse_result *result)
 {
 	return 0;
fs/fsopen.c +261 -268

604 lines not on this page · raw message

fs/internal.h +4 -0
index f3f280b952a3..507d59e9a540 100644
@@ -91,6 +91,10 @@ extern int __mnt_want_write_file(struct file *);
 extern void __mnt_drop_write_file(struct file *);
 
 extern void dissolve_on_fput(struct vfsmount *);
+
+int fsopen_cf_get(const struct configfd_context *cfc,
+		  struct configfd_param *p);
+
 /*
  * fs_struct.c
  */
fs/namespace.c +47 -64

160 lines not on this page · raw message

include/linux/ceph/libceph.h +2 -3
index ec73ebc4827d..64b97014c388 100644
@@ -281,12 +281,11 @@ extern int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid);
 extern void *ceph_kvmalloc(size_t size, gfp_t flags);
 
 struct fs_parameter;
-struct fc_log;
 struct ceph_options *ceph_alloc_options(void);
 int ceph_parse_mon_ips(const char *buf, size_t len, struct ceph_options *opt,
-		       struct fc_log *l);
+		       struct plogger *l);
 int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
-		     struct fc_log *l);
+		     struct plogger *l);
 int ceph_print_client_options(struct seq_file *m, struct ceph_client *client,
 			      bool show_all);
 extern void ceph_destroy_options(struct ceph_options *opt);
include/linux/fs.h +2 -0
index 3cd4fe6b845e..4dc62a697817 100644
@@ -2,6 +2,7 @@
 #ifndef _LINUX_FS_H
 #define _LINUX_FS_H
 
+#include <linux/configfd.h>
 #include <linux/linkage.h>
 #include <linux/wait_bit.h>
 #include <linux/kdev_t.h>
@@ -2251,6 +2252,7 @@ struct file_system_type {
 	struct lock_class_key i_lock_key;
 	struct lock_class_key i_mutex_key;
 	struct lock_class_key i_mutex_dir_key;
+	struct configfd_type cft;
 };
 
 #define MODULE_ALIAS_FS(NAME) MODULE_ALIAS("fs-" NAME)
include/linux/fs_context.h +28 -30

108 lines not on this page · raw message

include/linux/fs_parser.h +6 -3
index 2eab6d5f6736..7a7302341b56 100644
@@ -19,7 +19,7 @@ struct constant_table {
 
 struct fs_parameter_spec;
 struct fs_parse_result;
-typedef int fs_param_type(struct p_log *,
+typedef int fs_param_type(struct plogger *,
 			  const struct fs_parameter_spec *,
 			  struct fs_parameter *,
 			  struct fs_parse_result *);
@@ -60,7 +60,7 @@ struct fs_parse_result {
 	};
 };
 
-extern int __fs_parse(struct p_log *log,
+extern int __fs_parse(struct plogger *log,
 		    const struct fs_parameter_spec *desc,
 		    struct fs_parameter *value,
 		    struct fs_parse_result *result);
@@ -70,7 +70,7 @@ static inline int fs_parse(struct fs_context *fc,
 	     struct fs_parameter *param,
 	     struct fs_parse_result *result)
 {
-	return __fs_parse(&fc->log, desc, param, result);
+	return __fs_parse(&fc->cfc->log, desc, param, result);
 }
 
 extern int fs_lookup_param(struct fs_context *fc,
@@ -131,4 +131,7 @@ static inline bool fs_validate_description(const char *name,
 #define fsparam_path(NAME, OPT)	__fsparam(fs_param_is_path, NAME, OPT, 0, NULL)
 #define fsparam_fd(NAME, OPT)	__fsparam(fs_param_is_fd, NAME, OPT, 0, NULL)
 
+int fs_context_register(struct file_system_type *fs);
+void fs_context_unregister(struct file_system_type *fs);
+
 #endif /* _LINUX_FS_PARSER_H */
net/ceph/ceph_common.c +13 -13
index a0e97f6c1072..f7112d36e4a2 100644
@@ -332,7 +332,7 @@ EXPORT_SYMBOL(ceph_destroy_options);
 
 /* get secret from key store */
 static int get_secret(struct ceph_crypto_key *dst, const char *name,
-		      struct p_log *log)
+		      struct plogger *log)
 {
 	struct key *ukey;
 	int key_err;
@@ -378,16 +378,16 @@ static int get_secret(struct ceph_crypto_key *dst, const char *name,
 }
 
 int ceph_parse_mon_ips(const char *buf, size_t len, struct ceph_options *opt,
-		       struct fc_log *l)
+		       struct plogger *l)
 {
-	struct p_log log = {.prefix = "libceph", .log = l};
 	int ret;
 
+	l->prefix = "libceph";
 	/* ip1[:port1][,ip2[:port2]...] */
 	ret = ceph_parse_ips(buf, buf + len, opt->mon_addr, CEPH_MAX_MON,
 			     &opt->num_mon);
 	if (ret) {
-		error_plog(&log, "Failed to parse monitor IPs: %d", ret);
+		error_plog(l, "Failed to parse monitor IPs: %d", ret);
 		return ret;
 	}
 
@@ -396,13 +396,13 @@ int ceph_parse_mon_ips(const char *buf, size_t len, struct ceph_options *opt,
 EXPORT_SYMBOL(ceph_parse_mon_ips);
 
 int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
-		     struct fc_log *l)
+		     struct plogger *l)
 {
 	struct fs_parse_result result;
 	int token, err;
-	struct p_log log = {.prefix = "libceph", .log = l};
 
-	token = __fs_parse(&log, ceph_parameters, param, &result);
+	l->prefix = "libceph";
+	token = __fs_parse(l, ceph_parameters, param, &result);
 	dout("%s fs_parse '%s' token %d\n", __func__, param->key, token);
 	if (token < 0)
 		return token;
@@ -414,7 +414,7 @@ int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
 				     &opt->my_addr,
 				     1, NULL);
 		if (err) {
-			error_plog(&log, "Failed to parse ip: %d", err);
+			error_plog(l, "Failed to parse ip: %d", err);
 			return err;
 		}
 		opt->flags |= CEPH_OPT_MYIP;
@@ -423,7 +423,7 @@ int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
 	case Opt_fsid:
 		err = parse_fsid(param->string, &opt->fsid);
 		if (err) {
-			error_plog(&log, "Failed to parse fsid: %d", err);
+			error_plog(l, "Failed to parse fsid: %d", err);
 			return err;
 		}
 		opt->flags |= CEPH_OPT_FSID;
@@ -442,7 +442,7 @@ int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
 			return -ENOMEM;
 		err = ceph_crypto_key_unarmor(opt->key, param->string);
 		if (err) {
-			error_plog(&log, "Failed to parse secret: %d", err);
+			error_plog(l, "Failed to parse secret: %d", err);
 			return err;
 		}
 		break;
@@ -453,10 +453,10 @@ int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
 		opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
 		if (!opt->key)
 			return -ENOMEM;
-		return get_secret(opt->key, param->string, &log);
+		return get_secret(opt->key, param->string, l);
 
 	case Opt_osdtimeout:
-		warn_plog(&log, "Ignoring osdtimeout");
+		warn_plog(l, "Ignoring osdtimeout");
 		break;
 	case Opt_osdkeepalivetimeout:
 		/* 0 isn't well defined right now, reject it */
@@ -527,7 +527,7 @@ int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
 	return 0;
 
 out_of_range:
-	return inval_plog(&log, "%s out of range", param->key);
+	return inval_plog(l, "%s out of range", param->key);
 }
 EXPORT_SYMBOL(ceph_parse_param);
 
Signature · 1 line
2.16.4
author maintainer
#7 lore raw

PATCH v3 5/6 fs: expose internal interfaces open_detached_copy and do_reconfigure_mount

In reply to James Bottomley

These are needed for the forthcoming bind configure type to work.

---
 fs/internal.h  | 3 +++
 fs/namespace.c | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
fs/internal.h +3 -0
index 507d59e9a540..80d89ddb9b28 100644
@@ -95,6 +95,9 @@ extern void dissolve_on_fput(struct vfsmount *);
 int fsopen_cf_get(const struct configfd_context *cfc,
 		  struct configfd_param *p);
 
+extern int do_reconfigure_mnt(struct path *path, unsigned int mnt_flags);
+extern struct file *open_detached_copy(struct path *path, bool recursive);
+
 /*
  * fs_struct.c
  */
fs/namespace.c +2 -2
index 09b3220d9437..69fb23ae3d8f 100644
@@ -2318,7 +2318,7 @@ static int do_loopback(struct path *path, const char *old_name,
 	return err;
 }
 
-static struct file *open_detached_copy(struct path *path, bool recursive)
+struct file *open_detached_copy(struct path *path, bool recursive)
 {
 	struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;
 	struct mnt_namespace *ns = alloc_mnt_ns(user_ns, true);
@@ -2494,7 +2494,7 @@ static void mnt_warn_timestamp_expiry(struct path *mountpoint, struct vfsmount *
  * superblock it refers to.  This is triggered by specifying MS_REMOUNT|MS_BIND
  * to mount(2).
  */
-static int do_reconfigure_mnt(struct path *path, unsigned int mnt_flags)
+int do_reconfigure_mnt(struct path *path, unsigned int mnt_flags)
 {
 	struct super_block *sb = path->mnt->mnt_sb;
 	struct mount *mnt = real_mount(path->mnt);
Signature · 1 line
2.16.4
author maintainer
#8 lore raw

PATCH v3 6/6 fs: bind: add configfs type for bind mounts

In reply to James Bottomley

This can do the equivalent of open_tree and also do bind mount reconfiguration from ro to rw and vice versa.

To get the equvalent of open tree you need to do

   mnt = open("/path/to/tree", O_PATH);
   fd = configfs_open(bind, O_CLOEXEC);
   configfs_action(fd, CONFIGFD_SET_FD, "pathfd", NULL, mnt);
   configfs_action(fd, CONFIGFD_SET_FLAG, "detached", NULL, 0);
   configfs_action(fd, CONFIGFD_SET_FLAG, "recursive", NULL, 0);
   configfs_action(fd, CONFIGFD_CMD_CREATE, NULL, NULL, 0);
   configfs_action(fd, CONFIGFD_GET_FD, "bindfd", &bfd, NULL, O_CLOEXEC);

And bfd will now contain the file descriptor to pass to move_tree. There is a deficiency over the original implementation in that the open system call has no way of clearing the LOOKUP_AUTOMOUNT path, but that's fixable.

To do a mount reconfigure to change the bind mount to readonly do

   mnt = open("/path/to/tree", O_PATH);
   fd = configfs_open(bind, O_CLOEXEC);
   configfs_action(fd, CONFIGFD_SET_FD, "pathfd", NULL, mnt);
   configfs_action(fd, CONFIGFD_SET_FLAG, "ro", NULL, 0);
   configfs_action(fd, CONFIGFD_CMD_RECONFIGURE, NULL, NULL, 0);

And the bind properties will be changed. You can also pass the "rw" flag to reset the read only.

---
v2: add nodev and noexec mount reconfigurations

---
 fs/Makefile |   2 +-
 fs/bind.c   | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 233 insertions(+), 1 deletion(-)
 create mode 100644 fs/bind.c
fs/Makefile +1 -1
index 2c078355fdf5..59b78e19f0d1 100644
@@ -14,7 +14,7 @@ obj-y :=	open.o read_write.o file_table.o super.o \
 		pnode.o splice.o sync.o utimes.o d_path.o \
 		stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \
 		fs_types.o fs_context.o fs_parser.o fsopen.o \
-		configfd.o
+		configfd.o bind.o
 
 ifeq ($(CONFIG_BLOCK),y)
 obj-y +=	buffer.o block_dev.o direct-io.o mpage.o
fs/bind.c new file +232 -0

232 lines not on this page · raw message

Signature · 1 line
2.16.4