Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp13723imm; Fri, 21 Sep 2018 09:31:38 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdapf2SK0DsqaX2woWriD5qL0kr0DUG40PYlJTN3Ut6gkUOX+E1INMIed/Jo8U6XuB/b7aNv X-Received: by 2002:a17:902:7205:: with SMTP id ba5-v6mr6108126plb.15.1537547497947; Fri, 21 Sep 2018 09:31:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537547497; cv=none; d=google.com; s=arc-20160816; b=fcXTHD6V3SuGW8YVkCoyycAEVHlCDcTck3yvMQs+RhSkP96GQP9dG5WDgS8/3sQ01U pxNsLLyGMsxi/0mfvLzhSpEZDoa8Xq3vQi8SkIRoI+Y/GDlNfbeFb2vNTzqH61xH4VwZ ujtKZENGaQYsOODeQyl43uhWIKPSPzI2qvMXYKK8U0A3fPqtaxBYF8eJ5PN/6I0tGQaK em5joM28mQfLK7Cl2CUDAxKGnETGThzxug5Zo4SCUdk4Z07RMSTIwe0od4rHmQhFhQOi FrWXBT+oayl7p/YyzPJsKuDTEZMTv9EUKb2uQpWPCMthPLSWkRt+Ua9Fzh4h/dSa5og5 kLOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=dpCB/sFFze3b4eAS9ctcuByREquUVz8z0FTS+IVF4do=; b=MmfAYiZuMxbDIrQM7sMwdOPDQC/h4xl8gEx6yEpogwXF8uIGZzM30FDXKGFYl3heOb zFWmPAwYngdO6i3lT+2yxsjaGifDNPYnZcEjcuSJi8/bsgk2ByW76TxOIcDfyX+EUPqp FLrvK6398pD/30UiAU5VsyT+G2L1PCuRiUPu1dSs6c7qp/5rEuEy8zhYxVVcH81elsFv y5iRrWaucRK86fNeuQAMUFdCNY9AqdJ6x8ztlecGgc/dd2zbtOBRmg7pQiJLYlN1fNp9 UpeQ/sfQmSDFJR2877RUxGm1S7acnIma8oZD/PLYti1+Ob6d1U9J1c9ixwkU5MJ5/4vv ePUQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61-v6si3309894plq.11.2018.09.21.09.31.22; Fri, 21 Sep 2018 09:31:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390789AbeIUWUb (ORCPT + 99 others); Fri, 21 Sep 2018 18:20:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48610 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390076AbeIUWUb (ORCPT ); Fri, 21 Sep 2018 18:20:31 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A68873F722; Fri, 21 Sep 2018 16:30:52 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-123-84.rdu2.redhat.com [10.10.123.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C8397FFF0; Fri, 21 Sep 2018 16:30:50 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 05/34] vfs: Introduce the basic header for the new mount API's filesystem context [ver #12] From: David Howells To: viro@zeniv.linux.org.uk Cc: torvalds@linux-foundation.org, dhowells@redhat.com, ebiederm@xmission.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, mszeredi@redhat.com Date: Fri, 21 Sep 2018 17:30:50 +0100 Message-ID: <153754745035.17872.13757011010081275911.stgit@warthog.procyon.org.uk> In-Reply-To: <153754740781.17872.7869536526927736855.stgit@warthog.procyon.org.uk> References: <153754740781.17872.7869536526927736855.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 21 Sep 2018 16:30:52 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce a filesystem context concept to be used during superblock creation for mount and superblock reconfiguration for remount. This is allocated at the beginning of the mount procedure and into it is placed: (1) Filesystem type. (2) Namespaces. (3) Source/Device names (there may be multiple). (4) Superblock flags (SB_*). (5) Security details. (6) Filesystem-specific data, as set by the mount options. Also introduce a struct for typed key=value parameter concept with which configuration data will be passed to filesystems. This will allow not only for ordinary string values, but also make it possible to pass more exotic values such as binary blobs, paths and fds with greater ease. Signed-off-by: David Howells --- include/linux/fs_context.h | 108 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 include/linux/fs_context.h diff --git a/include/linux/fs_context.h b/include/linux/fs_context.h new file mode 100644 index 000000000000..56e406a96b80 --- /dev/null +++ b/include/linux/fs_context.h @@ -0,0 +1,108 @@ +/* Filesystem superblock creation and reconfiguration context. + * + * Copyright (C) 2018 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. + */ + +#ifndef _LINUX_FS_CONTEXT_H +#define _LINUX_FS_CONTEXT_H + +#include +#include + +struct cred; +struct dentry; +struct file_operations; +struct file_system_type; +struct mnt_namespace; +struct net; +struct pid_namespace; +struct super_block; +struct user_namespace; +struct vfsmount; +struct path; + +enum fs_context_purpose { + FS_CONTEXT_FOR_USER_MOUNT, /* New superblock for user-specified mount */ + FS_CONTEXT_FOR_KERNEL_MOUNT, /* New superblock for kernel-internal mount */ + FS_CONTEXT_FOR_SUBMOUNT, /* New superblock for automatic submount */ + FS_CONTEXT_FOR_ROOT_MOUNT, /* New superblock for internal root mount */ + FS_CONTEXT_FOR_RECONFIGURE, /* Superblock reconfiguration (remount) */ + FS_CONTEXT_FOR_UMOUNT, /* Reconfiguration to R/O for unmount */ + FS_CONTEXT_FOR_EMERGENCY_RO, /* Emergency reconfiguration to R/O */ +}; + +/* + * Type of parameter value. + */ +enum fs_value_type { + fs_value_is_undefined, + fs_value_is_flag, /* Value not given a value */ + fs_value_is_string, /* Value is a string */ + fs_value_is_blob, /* Value is a binary blob */ + fs_value_is_filename, /* Value is a filename* + dirfd */ + fs_value_is_filename_empty, /* Value is a filename* + dirfd + AT_EMPTY_PATH */ + fs_value_is_file, /* Value is a file* */ +}; + +/* + * Configuration parameter. + */ +struct fs_parameter { + const char *key; /* Parameter name */ + enum fs_value_type type:8; /* The type of value here */ + union { + char *string; + void *blob; + struct filename *name; + struct file *file; + }; + size_t size; + int dirfd; +}; + +/* + * Filesystem context for holding the parameters used in the creation or + * reconfiguration of a superblock. + * + * Superblock creation fills in ->root whereas reconfiguration begins with this + * already set. + * + * See Documentation/filesystems/mounting.txt + */ +struct fs_context { + const struct fs_context_operations *ops; + struct file_system_type *fs_type; + void *fs_private; /* The filesystem's context */ + struct dentry *root; /* The root and superblock */ + struct user_namespace *user_ns; /* The user namespace for this mount */ + struct net *net_ns; /* The network namespace for this mount */ + const struct cred *cred; /* The mounter's credentials */ + char *source; /* The source name (eg. dev path) */ + char *subtype; /* The subtype to set on the superblock */ + void *security; /* The LSM context */ + void *s_fs_info; /* Proposed s_fs_info */ + unsigned int sb_flags; /* Proposed superblock flags (SB_*) */ + unsigned int sb_flags_mask; /* Superblock flags that were changed */ + enum fs_context_purpose purpose:8; + bool sloppy:1; /* T if unrecognised options are okay */ + bool silent:1; /* T if "o silent" specified */ + bool need_free:1; /* Need to call ops->free() */ +}; + +struct fs_context_operations { + void (*free)(struct fs_context *fc); + int (*dup)(struct fs_context *fc, struct fs_context *src_fc); + int (*parse_param)(struct fs_context *fc, struct fs_parameter *param); + int (*parse_monolithic)(struct fs_context *fc, void *data, size_t data_size); + int (*validate)(struct fs_context *fc); + int (*get_tree)(struct fs_context *fc); + int (*reconfigure)(struct fs_context *fc); +}; + +#endif /* _LINUX_FS_CONTEXT_H */