mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-24 01:50:54 +07:00
8d0347f6c3
Replace do_remount_sb() with a function, reconfigure_super(), that's fs_context aware. The fs_context is expected to be parameterised already and have ->root pointing to the superblock to be reconfigured. A legacy wrapper is provided that is intended to be called from the fs_context ops when those appear, but for now is called directly from reconfigure_super(). This wrapper invokes the ->remount_fs() superblock op for the moment. It is intended that the remount_fs() op will be phased out. The fs_context->purpose is set to FS_CONTEXT_FOR_RECONFIGURE to indicate that the context is being used for reconfiguration. do_umount_root() is provided to consolidate remount-to-R/O for umount and emergency remount by creating a context and invoking reconfiguration. do_remount(), do_umount() and do_emergency_remount_callback() are switched to use the new process. [AV -- fold UMOUNT and EMERGENCY_REMOUNT in; fixes the umount / bug, gets rid of pointless complexity] [AV -- set ->net_ns in all cases; nfs remount will need that] [AV -- shift security_sb_remount() call into reconfigure_super(); the callers that didn't do security_sb_remount() have NULL fc->security anyway, so it's a no-op for them] Signed-off-by: David Howells <dhowells@redhat.com> Co-developed-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
222 lines
5.5 KiB
C
222 lines
5.5 KiB
C
/* Provide a way to create a superblock configuration context within the kernel
|
|
* that allows a superblock to be set up prior to mounting.
|
|
*
|
|
* Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public Licence
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the Licence, or (at your option) any later version.
|
|
*/
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
#include <linux/fs_context.h>
|
|
#include <linux/fs.h>
|
|
#include <linux/mount.h>
|
|
#include <linux/nsproxy.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/magic.h>
|
|
#include <linux/security.h>
|
|
#include <linux/mnt_namespace.h>
|
|
#include <linux/pid_namespace.h>
|
|
#include <linux/user_namespace.h>
|
|
#include <net/net_namespace.h>
|
|
#include "mount.h"
|
|
#include "internal.h"
|
|
|
|
struct legacy_fs_context {
|
|
char *legacy_data; /* Data page for legacy filesystems */
|
|
size_t data_size;
|
|
};
|
|
|
|
static int legacy_init_fs_context(struct fs_context *fc);
|
|
|
|
/**
|
|
* alloc_fs_context - Create a filesystem context.
|
|
* @fs_type: The filesystem type.
|
|
* @reference: The dentry from which this one derives (or NULL)
|
|
* @sb_flags: Filesystem/superblock flags (SB_*)
|
|
* @sb_flags_mask: Applicable members of @sb_flags
|
|
* @purpose: The purpose that this configuration shall be used for.
|
|
*
|
|
* Open a filesystem and create a mount context. The mount context is
|
|
* initialised with the supplied flags and, if a submount/automount from
|
|
* another superblock (referred to by @reference) is supplied, may have
|
|
* parameters such as namespaces copied across from that superblock.
|
|
*/
|
|
static struct fs_context *alloc_fs_context(struct file_system_type *fs_type,
|
|
struct dentry *reference,
|
|
unsigned int sb_flags,
|
|
unsigned int sb_flags_mask,
|
|
enum fs_context_purpose purpose)
|
|
{
|
|
struct fs_context *fc;
|
|
int ret = -ENOMEM;
|
|
|
|
fc = kzalloc(sizeof(struct fs_context), GFP_KERNEL);
|
|
if (!fc)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
fc->purpose = purpose;
|
|
fc->sb_flags = sb_flags;
|
|
fc->sb_flags_mask = sb_flags_mask;
|
|
fc->fs_type = get_filesystem(fs_type);
|
|
fc->cred = get_current_cred();
|
|
fc->net_ns = get_net(current->nsproxy->net_ns);
|
|
|
|
switch (purpose) {
|
|
case FS_CONTEXT_FOR_MOUNT:
|
|
fc->user_ns = get_user_ns(fc->cred->user_ns);
|
|
break;
|
|
case FS_CONTEXT_FOR_RECONFIGURE:
|
|
/* We don't pin any namespaces as the superblock's
|
|
* subscriptions cannot be changed at this point.
|
|
*/
|
|
atomic_inc(&reference->d_sb->s_active);
|
|
fc->root = dget(reference);
|
|
break;
|
|
}
|
|
|
|
ret = legacy_init_fs_context(fc);
|
|
if (ret < 0)
|
|
goto err_fc;
|
|
fc->need_free = true;
|
|
return fc;
|
|
|
|
err_fc:
|
|
put_fs_context(fc);
|
|
return ERR_PTR(ret);
|
|
}
|
|
|
|
struct fs_context *fs_context_for_mount(struct file_system_type *fs_type,
|
|
unsigned int sb_flags)
|
|
{
|
|
return alloc_fs_context(fs_type, NULL, sb_flags, 0,
|
|
FS_CONTEXT_FOR_MOUNT);
|
|
}
|
|
EXPORT_SYMBOL(fs_context_for_mount);
|
|
|
|
struct fs_context *fs_context_for_reconfigure(struct dentry *dentry,
|
|
unsigned int sb_flags,
|
|
unsigned int sb_flags_mask)
|
|
{
|
|
return alloc_fs_context(dentry->d_sb->s_type, dentry, sb_flags,
|
|
sb_flags_mask, FS_CONTEXT_FOR_RECONFIGURE);
|
|
}
|
|
EXPORT_SYMBOL(fs_context_for_reconfigure);
|
|
|
|
void fc_drop_locked(struct fs_context *fc)
|
|
{
|
|
struct super_block *sb = fc->root->d_sb;
|
|
dput(fc->root);
|
|
fc->root = NULL;
|
|
deactivate_locked_super(sb);
|
|
}
|
|
|
|
static void legacy_fs_context_free(struct fs_context *fc);
|
|
|
|
/**
|
|
* put_fs_context - Dispose of a superblock configuration context.
|
|
* @fc: The context to dispose of.
|
|
*/
|
|
void put_fs_context(struct fs_context *fc)
|
|
{
|
|
struct super_block *sb;
|
|
|
|
if (fc->root) {
|
|
sb = fc->root->d_sb;
|
|
dput(fc->root);
|
|
fc->root = NULL;
|
|
deactivate_super(sb);
|
|
}
|
|
|
|
if (fc->need_free)
|
|
legacy_fs_context_free(fc);
|
|
|
|
security_free_mnt_opts(&fc->security);
|
|
put_net(fc->net_ns);
|
|
put_user_ns(fc->user_ns);
|
|
put_cred(fc->cred);
|
|
kfree(fc->subtype);
|
|
put_filesystem(fc->fs_type);
|
|
kfree(fc->source);
|
|
kfree(fc);
|
|
}
|
|
EXPORT_SYMBOL(put_fs_context);
|
|
|
|
/*
|
|
* Free the config for a filesystem that doesn't support fs_context.
|
|
*/
|
|
static void legacy_fs_context_free(struct fs_context *fc)
|
|
{
|
|
kfree(fc->fs_private);
|
|
}
|
|
|
|
/*
|
|
* Add monolithic mount data.
|
|
*/
|
|
static int legacy_parse_monolithic(struct fs_context *fc, void *data)
|
|
{
|
|
struct legacy_fs_context *ctx = fc->fs_private;
|
|
ctx->legacy_data = data;
|
|
if (!ctx->legacy_data)
|
|
return 0;
|
|
if (fc->fs_type->fs_flags & FS_BINARY_MOUNTDATA)
|
|
return 0;
|
|
return security_sb_eat_lsm_opts(ctx->legacy_data, &fc->security);
|
|
}
|
|
|
|
/*
|
|
* Get a mountable root with the legacy mount command.
|
|
*/
|
|
int legacy_get_tree(struct fs_context *fc)
|
|
{
|
|
struct legacy_fs_context *ctx = fc->fs_private;
|
|
struct super_block *sb;
|
|
struct dentry *root;
|
|
|
|
root = fc->fs_type->mount(fc->fs_type, fc->sb_flags,
|
|
fc->source, ctx->legacy_data);
|
|
if (IS_ERR(root))
|
|
return PTR_ERR(root);
|
|
|
|
sb = root->d_sb;
|
|
BUG_ON(!sb);
|
|
|
|
fc->root = root;
|
|
return 0;
|
|
}
|
|
|
|
/*
|
|
* Handle remount.
|
|
*/
|
|
int legacy_reconfigure(struct fs_context *fc)
|
|
{
|
|
struct legacy_fs_context *ctx = fc->fs_private;
|
|
struct super_block *sb = fc->root->d_sb;
|
|
|
|
if (!sb->s_op->remount_fs)
|
|
return 0;
|
|
|
|
return sb->s_op->remount_fs(sb, &fc->sb_flags,
|
|
ctx ? ctx->legacy_data : NULL);
|
|
}
|
|
|
|
/*
|
|
* Initialise a legacy context for a filesystem that doesn't support
|
|
* fs_context.
|
|
*/
|
|
static int legacy_init_fs_context(struct fs_context *fc)
|
|
{
|
|
fc->fs_private = kzalloc(sizeof(struct legacy_fs_context), GFP_KERNEL);
|
|
if (!fc->fs_private)
|
|
return -ENOMEM;
|
|
return 0;
|
|
}
|
|
|
|
int parse_monolithic_mount_data(struct fs_context *fc, void *data)
|
|
{
|
|
return legacy_parse_monolithic(fc, data);
|
|
}
|