]> www.infradead.org Git - users/willy/linux.git/commitdiff
vfs: syscall: Add fspick() to select a superblock for reconfiguration
authorDavid Howells <dhowells@redhat.com>
Fri, 7 Sep 2018 06:41:02 +0000 (07:41 +0100)
committerDavid Howells <dhowells@redhat.com>
Tue, 23 Oct 2018 16:39:02 +0000 (17:39 +0100)
Provide an fspick() system call that can be used to pick an existing
mountpoint into an fs_context which can thereafter be used to reconfigure a
superblock (equivalent of the superblock side of -o remount).

This looks like:

int fd = fspick(AT_FDCWD, "/mnt",
FSPICK_CLOEXEC | FSPICK_NO_AUTOMOUNT);
fsconfig(fd, FSCONFIG_SET_FLAG, "intr", NULL, 0);
fsconfig(fd, FSCONFIG_SET_FLAG, "noac", NULL, 0);
fsconfig(fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0);

At the point of fspick being called, the file descriptor referring to the
filesystem context is in exactly the same state as the one that was created
by fsopen() after fsmount() has been successfully called.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: linux-api@vger.kernel.org

arch/x86/entry/syscalls/syscall_32.tbl
arch/x86/entry/syscalls/syscall_64.tbl
fs/fsopen.c
include/linux/syscalls.h
include/uapi/linux/mount.h

index c78b68256f8afbdad60cce2f518a15a8a367e831..d1eb6c815790a2d6b86245e9fd538453227f6713 100644 (file)
 389    i386    fsopen                  sys_fsopen                      __ia32_sys_fsopen
 390    i386    fsconfig                sys_fsconfig                    __ia32_sys_fsconfig
 391    i386    fsmount                 sys_fsmount                     __ia32_sys_fsmount
+392    i386    fspick                  sys_fspick                      __ia32_sys_fspick
index d44ead5d436847cecee5b9a033d69d229babf8ac..d3ab703c02bbbe95628c4bdd18f97cd32634b2ae 100644 (file)
 337    common  fsopen                  __x64_sys_fsopen
 338    common  fsconfig                __x64_sys_fsconfig
 339    common  fsmount                 __x64_sys_fsmount
+340    common  fspick                  __x64_sys_fspick
 
 #
 # x32-specific system call numbers start at 512 to avoid cache impact
index 0b563a8fc8a764d90a6b7259dc956e8fa66875d8..aaaaa17a233c4e2ee784c0f9e2d3deca28a6310b 100644 (file)
@@ -156,6 +156,64 @@ err_fc:
        return ret;
 }
 
+/*
+ * Pick a superblock into a context for reconfiguration.
+ */
+SYSCALL_DEFINE3(fspick, int, dfd, const char __user *, path, unsigned int, flags)
+{
+       struct fs_context *fc;
+       struct path target;
+       unsigned int lookup_flags;
+       int ret;
+
+       if (!ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN))
+               return -EPERM;
+
+       if ((flags & ~(FSPICK_CLOEXEC |
+                      FSPICK_SYMLINK_NOFOLLOW |
+                      FSPICK_NO_AUTOMOUNT |
+                      FSPICK_EMPTY_PATH)) != 0)
+               return -EINVAL;
+
+       lookup_flags = LOOKUP_FOLLOW | LOOKUP_AUTOMOUNT;
+       if (flags & FSPICK_SYMLINK_NOFOLLOW)
+               lookup_flags &= ~LOOKUP_FOLLOW;
+       if (flags & FSPICK_NO_AUTOMOUNT)
+               lookup_flags &= ~LOOKUP_AUTOMOUNT;
+       if (flags & FSPICK_EMPTY_PATH)
+               lookup_flags |= LOOKUP_EMPTY;
+       ret = user_path_at(dfd, path, lookup_flags, &target);
+       if (ret < 0)
+               goto err;
+
+       ret = -EINVAL;
+       if (target.mnt->mnt_root != target.dentry)
+               goto err_path;
+
+       fc = vfs_new_fs_context(target.dentry->d_sb->s_type, target.dentry,
+                               0, 0, FS_CONTEXT_FOR_RECONFIGURE);
+       if (IS_ERR(fc)) {
+               ret = PTR_ERR(fc);
+               goto err_path;
+       }
+
+       fc->phase = FS_CONTEXT_RECONF_PARAMS;
+
+       ret = fscontext_alloc_log(fc);
+       if (ret < 0)
+               goto err_fc;
+
+       path_put(&target);
+       return fscontext_create_fd(fc, flags & FSPICK_CLOEXEC ? O_CLOEXEC : 0);
+
+err_fc:
+       put_fs_context(fc);
+err_path:
+       path_put(&target);
+err:
+       return ret;
+}
+
 /*
  * Check the state and apply the configuration.  Note that this function is
  * allowed to 'steal' the value by setting param->xxx to NULL before returning.
index 4697fad47789af91a07bda6c25e6ecd978af0b5a..eb8d62f4ee24efa703444705628fdded1a189172 100644 (file)
@@ -914,6 +914,7 @@ asmlinkage long sys_fsopen(const char __user *fs_name, unsigned int flags);
 asmlinkage long sys_fsconfig(int fs_fd, unsigned int cmd, const char __user *key,
                             const void __user *value, int aux);
 asmlinkage long sys_fsmount(int fs_fd, unsigned int flags, unsigned int ms_flags);
+asmlinkage long sys_fspick(int dfd, const char __user *path, unsigned int flags);
 
 /*
  * Architecture-specific system calls
index 3888d3b91dc5035f86f3575e7760f387db1aa299..96a0240f23fed37be9430b72d2f2d9ffd6d42237 100644 (file)
  */
 #define FSOPEN_CLOEXEC         0x00000001
 
+/*
+ * fspick() flags.
+ */
+#define FSPICK_CLOEXEC         0x00000001
+#define FSPICK_SYMLINK_NOFOLLOW        0x00000002
+#define FSPICK_NO_AUTOMOUNT    0x00000004
+#define FSPICK_EMPTY_PATH      0x00000008
+
 /*
  * The type of fsconfig() call made.
  */