Skip to contentSkip to conversation

Feature bug with the new mount API: no way of doing read only bind mounts

RFC Superseded James Bottomley 3 participants 13 messages Nov 21, 2019 – Nov 27, 2019

Subsystems (18)
Arm (32-bit) x86 VFS PowerPC +14 more subsystems

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

James Bottomley

author maintainer
#0 lore raw

My understanding is the new mount API will eventually replace the current mount API, so it needs to be feature for feature compatible before that happens. I was looking to use the read only bind mount as a template for reimplementing shiftfs when I discovered that you can't actually create a read only bind mount with the new API. The problem is that fspick() will only reconfigure the underlying superblock, which you don't want because you only want the bound subtree to become read only and open_tree()/move_mount() doesn't give you any facility to add or change options on the bind.

The way it works with the current API is that you create a bind mount with MS_BIND and then remount it with MS_BIND|MS_REMOUNT|MS_RDONLY which makes the subtree go read only. It looks like the nearest way of getting this to work with the new API would be to add an additional fspick() flag, say FSPICK_BIND, that tells it to operate on the subtree not the superblock and then pass this down to fsconfig() so it will accept the "ro" and "rw" flags and the reconfigure command and nothing else (although I'd like it to accept additional flags on down the road for the shiftfs rewrite).

There are some caveats, in that fspick/fsconfig seem to be fairly adamantly coded to work with the superblock, so the subtree handling will have to be special cased, but if everyone's happy with that, I can code up something.

Regards,

James

#1 lore raw
Quoted 6 lines · James Bottomley

I was looking to use the read only bind mount as a template for reimplementing shiftfs when I discovered that you can't actually create a read only bind mount with the new API. The problem is that fspick() will only reconfigure the underlying superblock, which you don't want because you only want the bound subtree to become read only and open_tree()/move_mount() doesn't give you any facility to add or change options on the bind.

You'd use open_tree() with OPEN_TREE_CLONE and possibly AT_RECURSIVE rather than fspick(). fspick() is, as you observed, more for reconfiguring the superblock.

What is missing is a mount_setattr() syscall - something like:

	mount_setattr(int dfd, const char *path, unsigned int at_flags,
		      unsigned int attr_change_mask, unsigned int attrs);

which would allow what you want to be done like:

	fd = open_tree(AT_FDCWD, "/my/source/", OPEN_TREE_CLONE);
	mount_setattr(fd, "", AT_EMPTY_PATH | AT_RECURSIVE,
		      MOUNT_ATTR_RDONLY, MOUNT_ATTR_RDONLY);
	move_mount(fd, "", AT_FDCWD, "/mnt", MOVE_MOUNT_F_EMPTY_PATH);

Christian: you said you wanted to have a look at doing this - is that still your intention?

Al: Is it too late to change OPEN_TREE_CLONE to be a definite value rather than tying it to O_CLOEXEC? OPEN_TREE_CLONE shares its space with the AT_flags, but O_CLOEXEC has one of three different values, depending on arch. Perhaps we can nail it to 02000000 (0x80000), which is what's used on everything but alpha, mips, parisc and sparc.

David

#2 lore raw
Quoted 20 lines · David Howells
Quoted 6 lines · James Bottomley

I was looking to use the read only bind mount as a template for reimplementing shiftfs when I discovered that you can't actually create a read only bind mount with the new API. The problem is that fspick() will only reconfigure the underlying superblock, which you don't want because you only want the bound subtree to become read only and open_tree()/move_mount() doesn't give you any facility to add or change options on the bind.

You'd use open_tree() with OPEN_TREE_CLONE and possibly AT_RECURSIVE rather than fspick(). fspick() is, as you observed, more for reconfiguring the superblock.

What is missing is a mount_setattr() syscall - something like:

	mount_setattr(int dfd, const char *path, unsigned int at_flags,
		      unsigned int attr_change_mask, unsigned int attrs);

which would allow what you want to be done like:

Quoted 7 lines
	fd = open_tree(AT_FDCWD, "/my/source/", OPEN_TREE_CLONE);
	mount_setattr(fd, "", AT_EMPTY_PATH | AT_RECURSIVE,
		      MOUNT_ATTR_RDONLY, MOUNT_ATTR_RDONLY);
	move_mount(fd, "", AT_FDCWD, "/mnt", MOVE_MOUNT_F_EMPTY_PATH);

Christian: you said you wanted to have a look at doing this - is that still your intention?

Yes, it is. I can't put an exact time-frame on this rn. Also, I thought we've agreed a while back that the flags would move into a struct since mount is gaining flags quickly too. :)

Christian

author maintainer
#4 lore raw
In reply to David Howells
Quoted 20 lines · David Howells
Quoted 7 lines · James Bottomley

I was looking to use the read only bind mount as a template for reimplementing shiftfs when I discovered that you can't actually create a read only bind mount with the new API. The problem is that fspick() will only reconfigure the underlying superblock, which you don't want because you only want the bound subtree to become read only and open_tree()/move_mount() doesn't give you any facility to add or change options on the bind.

You'd use open_tree() with OPEN_TREE_CLONE and possibly AT_RECURSIVE rather than fspick(). fspick() is, as you observed, more for reconfiguring the superblock.

What is missing is a mount_setattr() syscall - something like:

mount_setattr(int dfd, const char *path, unsigned int at_flags,
unsigned int attr_change_mask, unsigned int
attrs);

Quoted 6 lines

which would allow what you want to be done like:

	fd = open_tree(AT_FDCWD, "/my/source/", OPEN_TREE_CLONE);
	mount_setattr(fd, "", AT_EMPTY_PATH | AT_RECURSIVE,
		      MOUNT_ATTR_RDONLY, MOUNT_ATTR_RDONLY);
	move_mount(fd, "", AT_FDCWD, "/mnt", MOVE_MOUNT_F_EMPTY_PATH);

That would work for read only, which is a simple mount attribute flag, but wouldn't work for anything more complex like shiftfs which wants more complex parameters. What I'm looking for in that case is the ability to reconfigure the bind mount in the same way you would reconfigure the superblock.

James

#3 lore raw
In reply to Christian Brauner
Quoted 2 lines · Christian Brauner

Also, I thought we've agreed a while back that the flags would move into a struct since mount is gaining flags quickly too. :)

I think we did agree that. What I just wrote in the email was more of a tentative illustration.

David

author maintainer
#5 lore raw
In reply to David Howells
Quoted 10 lines · David Howells
Quoted 7 lines · James Bottomley

I was looking to use the read only bind mount as a template for reimplementing shiftfs when I discovered that you can't actually create a read only bind mount with the new API. The problem is that fspick() will only reconfigure the underlying superblock, which you don't want because you only want the bound subtree to become read only and open_tree()/move_mount() doesn't give you any facility to add or change options on the bind.

Quoted 3 lines

You'd use open_tree() with OPEN_TREE_CLONE and possibly AT_RECURSIVE rather than fspick(). fspick() is, as you observed, more for reconfiguring the superblock.

In the abstract, I think the concept of a configuration file descriptor with the, open add parameters and execution to fd, and optionally convert to representation or reconfigure in place is a very generic one. If we did agree to do that for bind mounts as well, I wouldn't overload the existing logic, I'd lift it up to the generic level, probably by hooking the execution parts, and make superblock and bind two implementations of it. It would basically be 3 system calls:
configopen, configparam and configconvert although obviously with more appealing names.

The reason for thinking like this is I can see it having utility in some of the more complex SCSI configuration operations we do today via a bunch of mechanisms including configfs that could more compactly be done by this file descriptor mechanism.

I'd also note that this plethora of system calls you have could then go
away: fspick itself would just become an open type to which the path file descriptor would then be a required parameter, as would open_tree and the missing mount_setattr would then just work.

James

author maintainer
#6 lore raw
Quoted 30 lines · James Bottomley
Quoted 10 lines · David Howells
Quoted 7 lines · James Bottomley

I was looking to use the read only bind mount as a template for reimplementing shiftfs when I discovered that you can't actually create a read only bind mount with the new API. The problem is that fspick() will only reconfigure the underlying superblock, which you don't want because you only want the bound subtree to become read only and open_tree()/move_mount() doesn't give you any facility to add or change options on the bind.

Quoted 3 lines

You'd use open_tree() with OPEN_TREE_CLONE and possibly AT_RECURSIVE rather than fspick(). fspick() is, as you observed, more for reconfiguring the superblock.

In the abstract, I think the concept of a configuration file descriptor with the, open add parameters and execution to fd, and optionally convert to representation or reconfigure in place is a very generic one. If we did agree to do that for bind mounts as well, I wouldn't overload the existing logic, I'd lift it up to the generic level, probably by hooking the execution parts, and make superblock and bind two implementations of it. It would basically be 3 system calls: configopen, configparam and configconvert although obviously with more appealing names.

The reason for thinking like this is I can see it having utility in some of the more complex SCSI configuration operations we do today via a bunch of mechanisms including configfs that could more compactly be done by this file descriptor mechanism.

Quoted 4 lines

I'd also note that this plethora of system calls you have could then go away: fspick itself would just become an open type to which the path file descriptor would then be a required parameter, as would open_tree and the missing mount_setattr would then just work.

Well, that suggestion got crickets, so let me show you how it would look. I actually pulled the logger out into lib/ because that's not filesystem dependent and implemented a generic configfd handler for doing configuration via a file descriptor. Configfd is completely separated from the mechanics of filesystem reconfiguration, so it can be used as a configuration mechanism for anything.

Once configuration file descriptor mechanics are made generic, you can get away with two operations for everything, thus giving you the ability to eliminate fsopen, fsmount, fsconfigure, fspick and open_tree. Note, I didn't do that: I just reimplemented them via internal configfd calls instead, but it is a possibility. Note also I've now got the ability to do a ro bind mount without any new system calls and I now have a scaffold on which I could successfully hang shiftfs as a propertied bind mount.

The final patch introduces a bind configfd type that can be used both in place of open_tree and to implement the ro bind mount as a bind mount reconfigure operation.

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 +
 fs/Makefile                                 |   3 +-
 fs/bind.c                                   | 193 ++++++++++
 fs/configfd.c                               | 450 +++++++++++++++++++++++
 fs/filesystems.c                            |   8 +-
 fs/fs_context.c                             | 124 +------
 fs/fsopen.c                                 | 535 ++++++++++++++--------------
 fs/internal.h                               |   7 +
 fs/namespace.c                              | 115 +++---
 include/linux/configfd.h                    |  61 ++++
 include/linux/fs.h                          |   2 +
 include/linux/fs_context.h                  |  23 +-
 include/linux/fs_parser.h                   |   2 +
 include/linux/logger.h                      |  34 ++
 include/linux/syscalls.h                    |   5 +
 include/uapi/asm-generic/unistd.h           |   7 +-
 include/uapi/linux/configfd.h               |  20 ++
 lib/Makefile                                |   3 +-
 lib/logger.c                                | 211 +++++++++++
 36 files changed, 1368 insertions(+), 473 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
#7 lore raw

RFC 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 e7582e16a170db4c85995c1c03d194ea1ea621fc "vfs: Implement logging through fs_context".

---
 include/linux/logger.h |  34 ++++++++
 lib/Makefile           |   3 +-
 lib/logger.c           | 211 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 247 insertions(+), 1 deletion(-)
 create mode 100644 include/linux/logger.h
 create mode 100644 lib/logger.c
include/linux/logger.h new file +34 -0
new file mode 100644
index 000000000000..cf7a87f1d8d2
@@ -0,0 +1,34 @@
+#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 {
+	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];
+};
+
+extern __printf(2, 3)
+void logger_log(struct logger *, const char *fmt, ...);
+extern __printf(2, 0)
+void logger_valog(struct logger *, 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, "e "fmt, ## __VA_ARGS__); })
+#define logger_warn(log, fmt, ...) ({ logger_log(log, "w "fmt, ## __VA_ARGS__); })
+#define logger_info(log, fmt, ...) ({ logger_log(log, "i "fmt, ## __VA_ARGS__); })
+
+#endif
lib/Makefile +2 -1
index c5892807e06f..57a90d1eed29 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 +211 -0

211 lines not on this page · raw message

Signature · 1 line
2.16.4
author maintainer
#8 lore raw

RFC 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.

---
 fs/Makefile                   |   3 +-
 fs/configfd.c                 | 450 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/configfd.h      |  61 ++++++
 include/uapi/linux/configfd.h |  20 ++
 4 files changed, 533 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 14231b4cf383..569563f6c0d5 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 +450 -0

450 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
#10 lore raw

RFC 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);

---
 fs/filesystems.c           |   8 +-
 fs/fs_context.c            | 124 ++---------
 fs/fsopen.c                | 535 ++++++++++++++++++++++-----------------------
 fs/internal.h              |   4 +
 fs/namespace.c             | 111 ++++------
 include/linux/fs.h         |   2 +
 include/linux/fs_context.h |  23 +-
 include/linux/fs_parser.h  |   2 +
 8 files changed, 342 insertions(+), 467 deletions(-)
fs/filesystems.c +6 -2
index 9135646e41ac..ceb6532754c1 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>
@@ -82,10 +83,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;
 }
@@ -114,6 +117,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 +15 -109

160 lines not on this page · raw message

fs/fsopen.c +261 -274

610 lines not on this page · raw message

fs/internal.h +4 -0
index 315fcd8d237c..e3039de79134 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/fs.h +2 -0
index e0d909d35763..51f1408180f5 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>
@@ -2233,6 +2234,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 +5 -18
index e5c14e2c53d3..83686c0c9fed 100644
@@ -97,10 +97,12 @@ struct fs_context {
 	const char		*source;	/* The source name (eg. dev path) */
 	void			*security;	/* Linux S&M options */
 	void			*s_fs_info;	/* Proposed s_fs_info */
+	struct configfd_context	*cfc;
 	unsigned int		sb_flags;	/* Proposed superblock flags (SB_*) */
 	unsigned int		sb_flags_mask;	/* Superblock flags that were changed */
 	unsigned int		s_iflags;	/* OR'd with sb->s_iflags */
 	unsigned int		lsm_flags;	/* Information flags from the fs to the LSM */
+	unsigned int		mnt_flags;	/* mnt flags translated from MOUNT_ATTRS */
 	enum fs_context_purpose	purpose:8;
 	enum fs_context_phase	phase:8;	/* The phase the context is in */
 	bool			need_free:1;	/* Need to call ops->free() */
@@ -134,6 +136,8 @@ extern int vfs_parse_fs_string(struct fs_context *fc, const char *key,
 extern int generic_parse_monolithic(struct fs_context *fc, void *data);
 extern int vfs_get_tree(struct fs_context *fc);
 extern void put_fs_context(struct fs_context *fc);
+extern void fs_context_set_reconfigure(struct fs_context *fc,
+				       struct dentry *reference);
 
 /*
  * sget() wrappers to be called from the ->get_tree() op.
@@ -166,24 +170,7 @@ extern int get_tree_keyed(struct fs_context *fc,
 extern int get_tree_bdev(struct fs_context *fc,
 			       int (*fill_super)(struct super_block *sb,
 						 struct fs_context *fc));
-
-extern const struct file_operations fscontext_fops;
-
-/*
- * Mount error, warning and informational message logging.  This structure is
- * shareable between a mount and a subordinate mount.
- */
-struct fc_log {
-	refcount_t	usage;
-	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 */
-	char		*buffer[8];
-};
-
-extern __attribute__((format(printf, 2, 3)))
-void logfc(struct fs_context *fc, const char *fmt, ...);
+#define logfc(fc, fmt, ...) ({ logger_log(fc->cfc->log, fmt, ## __VA_ARGS__); })
 
 /**
  * infof - Store supplementary informational message
include/linux/fs_parser.h +2 -0
index dee140db6240..c41af1b51af6 100644
@@ -143,5 +143,7 @@ static inline bool fs_validate_description(const struct fs_parameter_description
 #define fsparam_path(NAME, OPT)	__fsparam(fs_param_is_path, NAME, OPT, 0)
 #define fsparam_fd(NAME, OPT)	__fsparam(fs_param_is_fd, NAME, OPT, 0)
 
+int fs_context_register(struct file_system_type *fs);
+void fs_context_unregister(struct file_system_type *fs);
 
 #endif /* _LINUX_FS_PARSER_H */
Signature · 1 line
2.16.4
author maintainer
#11 lore raw

RFC 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 e3039de79134..f27136058d7d 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 13be853e9225..9dcbafe62e4e 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
#12 lore raw

RFC 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.

---
 fs/Makefile |   2 +-
 fs/bind.c   | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 194 insertions(+), 1 deletion(-)
 create mode 100644 fs/bind.c
fs/Makefile +1 -1
index 569563f6c0d5..c676ca15c644 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 +193 -0

193 lines not on this page · raw message

Signature · 1 line
2.16.4
author maintainer
#9 lore raw

RFC 3/6 configfd: syscall: wire up configfd syscalls

In reply to James Bottomley
---
 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           | 7 ++++++-
 20 files changed, 48 insertions(+), 2 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl +2 -0
index 728fe028c02c..eb13483c2867 100644
@@ -475,3 +475,5 @@
 543	common	fspick				sys_fspick
 544	common	pidfd_open			sys_pidfd_open
 # 545 reserved for clone3
+546	common	configfd_open			configfd_open
+547	common	configfd_action			configfd_action
arch/arm/tools/syscall.tbl +2 -0
index 6da7dc4d79cc..024ae0ca80d1 100644
@@ -449,3 +449,5 @@
 433	common	fspick				sys_fspick
 434	common	pidfd_open			sys_pidfd_open
 435	common	clone3				sys_clone3
+436	common	configfd_open			sys_configfd_open
+437	common	configfd_action			sys_configfd_action
arch/arm64/include/asm/unistd.h +1 -1
index 2629a68b8724..8aa00ccb0b96 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		436
+#define __NR_compat_syscalls		438
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
arch/arm64/include/asm/unistd32.h +4 -0
index 94ab29cf4f00..785fc47ede34 100644
@@ -879,6 +879,10 @@ __SYSCALL(__NR_fspick, sys_fspick)
 __SYSCALL(__NR_pidfd_open, sys_pidfd_open)
 #define __NR_clone3 435
 __SYSCALL(__NR_clone3, sys_clone3)
+#define __NR_configfd_open 436
+__SYSCALL(__NR_configfd_open, sys_configfd_open)
+#define __NR_configfd_action 437
+__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 36d5faf4c86c..9679b0e06dea 100644
@@ -356,3 +356,5 @@
 433	common	fspick				sys_fspick
 434	common	pidfd_open			sys_pidfd_open
 # 435 reserved for clone3
+436	common	configfd_open			sys_configfd_open
+437	common	configfd_action			sys_configfd_action
arch/m68k/kernel/syscalls/syscall.tbl +2 -0
index a88a285a0e5f..a78740ac8285 100644
@@ -435,3 +435,5 @@
 433	common	fspick				sys_fspick
 434	common	pidfd_open			sys_pidfd_open
 # 435 reserved for clone3
+436	common	configfd_open			sys_configfd_open
+437	common	configfd_action			sys_configfd_action
arch/microblaze/kernel/syscalls/syscall.tbl +2 -0
index 09b0cd7dab0a..c0ae38557315 100644
@@ -441,3 +441,5 @@
 433	common	fspick				sys_fspick
 434	common	pidfd_open			sys_pidfd_open
 435	common	clone3				sys_clone3
+436	common	configfd_open			sys_configfd_open
+437	common	configfd_action			sys_configfd_action
arch/mips/kernel/syscalls/syscall_n32.tbl +2 -0
index e7c5ab38e403..8a85da0a2fe5 100644
@@ -374,3 +374,5 @@
 433	n32	fspick				sys_fspick
 434	n32	pidfd_open			sys_pidfd_open
 435	n32	clone3				__sys_clone3
+436	n32	configfd_open			sys_configfd_open
+437	n32	configfd_action			sys_configfd_action
arch/mips/kernel/syscalls/syscall_n64.tbl +2 -0
index 13cd66581f3b..cafd5c2cf6f4 100644
@@ -350,3 +350,5 @@
 433	n64	fspick				sys_fspick
 434	n64	pidfd_open			sys_pidfd_open
 435	n64	clone3				__sys_clone3
+436	n64	configfd_open			sys_configfd_open
+437	n64	configfd_action			sys_configfd_action
arch/mips/kernel/syscalls/syscall_o32.tbl +2 -0
index 353539ea4140..8745d12c06c4 100644
@@ -423,3 +423,5 @@
 433	o32	fspick				sys_fspick
 434	o32	pidfd_open			sys_pidfd_open
 435	o32	clone3				__sys_clone3
+436	o32	configfd_open			sys_configfd_open
+437	o32	configfd_action			sys_configfd_action
arch/parisc/kernel/syscalls/syscall.tbl +2 -0
index 285ff516150c..fad358f6c107 100644
@@ -433,3 +433,5 @@
 433	common	fspick				sys_fspick
 434	common	pidfd_open			sys_pidfd_open
 435	common	clone3				sys_clone3_wrapper
+436	common	configfd_open			sys_configfd_open
+437	common	configfd_action			sys_configfd_action
arch/powerpc/kernel/syscalls/syscall.tbl +2 -0
index 43f736ed47f2..2fa485b229fa 100644
@@ -517,3 +517,5 @@
 433	common	fspick				sys_fspick
 434	common	pidfd_open			sys_pidfd_open
 435	nospu	clone3				ppc_clone3
+436	common	configfd_open			sys_configfd_open
+437	common	configfd_action			sys_configfd_action
arch/s390/kernel/syscalls/syscall.tbl +2 -0
index 3054e9c035a3..e6401600f8e9 100644
@@ -438,3 +438,5 @@
 433  common	fspick			sys_fspick			sys_fspick
 434  common	pidfd_open		sys_pidfd_open			sys_pidfd_open
 435  common	clone3			sys_clone3			sys_clone3
+436  common	configfd_open		sys_configfd_open		sys_configfd_open
+437  common	configfd_action		sys_configfd_action		sys_configfd_action
arch/sh/kernel/syscalls/syscall.tbl +2 -0
index b5ed26c4c005..d97009f75bf9 100644
@@ -438,3 +438,5 @@
 433	common	fspick				sys_fspick
 434	common	pidfd_open			sys_pidfd_open
 # 435 reserved for clone3
+436	common	configfd_open			sys_configfd_open
+437	common	configfd_action			sys_configfd_action
arch/sparc/kernel/syscalls/syscall.tbl +2 -0
index 8c8cc7537fb2..d899bcef3279 100644
@@ -481,3 +481,5 @@
 433	common	fspick				sys_fspick
 434	common	pidfd_open			sys_pidfd_open
 # 435 reserved for clone3
+436	common	configfd_open			sys_configfd_open
+437	common	configfd_action			sys_configfd_action
arch/x86/entry/syscalls/syscall_32.tbl +2 -0
index 3fe02546aed3..077cdd659227 100644
@@ -440,3 +440,5 @@
 433	i386	fspick			sys_fspick			__ia32_sys_fspick
 434	i386	pidfd_open		sys_pidfd_open			__ia32_sys_pidfd_open
 435	i386	clone3			sys_clone3			__ia32_sys_clone3
+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 c29976eca4a8..e5d24b9ed28c 100644
@@ -357,6 +357,8 @@
 433	common	fspick			__x64_sys_fspick
 434	common	pidfd_open		__x64_sys_pidfd_open
 435	common	clone3			__x64_sys_clone3/ptregs
+436	common	configfd_open		__x64_sys_configfd_open
+437	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 25f4de729a6d..77ec1f6997e4 100644
@@ -406,3 +406,5 @@
 433	common	fspick				sys_fspick
 434	common	pidfd_open			sys_pidfd_open
 435	common	clone3				sys_clone3
+436	common	configfd_open			sys_configfd_open
+437	common	configfd_action			sys_configfd_action
include/linux/syscalls.h +5 -0
index f7c561c4dcdd..9dd70803e2b1 100644
@@ -1000,6 +1000,11 @@ asmlinkage long sys_fspick(int dfd, const char __user *path, unsigned int flags)
 asmlinkage long sys_pidfd_send_signal(int pidfd, int sig,
 				       siginfo_t __user *info,
 				       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 +6 -1
index 1fc8faa6e973..6ae20cdfb081 100644
@@ -849,10 +849,15 @@ __SYSCALL(__NR_pidfd_open, sys_pidfd_open)
 #ifdef __ARCH_WANT_SYS_CLONE3
 #define __NR_clone3 435
 __SYSCALL(__NR_clone3, sys_clone3)
+
 #endif
+#define __NR_configfd_open 436
+__SYSCALL(__NR_configfd_open, sys_configfd_open)
+#define __NR_configfd_action 437
+__SYSCALL(__NR_configfd_action, sys_configfd_action)
 
 #undef __NR_syscalls
-#define __NR_syscalls 436
+#define __NR_syscalls 438
 
 /*
  * 32 bit systems traditionally used different
Signature · 1 line
2.16.4