From patchwork Thu Mar 21 11:48:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 10863349 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD9DC14DE for ; Thu, 21 Mar 2019 11:48:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8FB62A0B2 for ; Thu, 21 Mar 2019 11:48:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C28E2A0DD; Thu, 21 Mar 2019 11:48:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FB6F2A0B2 for ; Thu, 21 Mar 2019 11:48:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728240AbfCULsJ (ORCPT ); Thu, 21 Mar 2019 07:48:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31781 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728102AbfCULsJ (ORCPT ); Thu, 21 Mar 2019 07:48:09 -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 9342E3086206; Thu, 21 Mar 2019 11:48:08 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-98.rdu2.redhat.com [10.10.121.98]) by smtp.corp.redhat.com (Postfix) with ESMTP id E557719C7F; Thu, 21 Mar 2019 11:48:06 +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: [RFC PATCH 4/8] vfs: Convert pstore to fs_context From: David Howells To: viro@zeniv.linux.org.uk Cc: Kees Cook , Anton Vorontsov , Colin Cross , Tony Luck , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, dhowells@redhat.com Date: Thu, 21 Mar 2019 11:48:06 +0000 Message-ID: <155316888615.29437.17558157678296689830.stgit@warthog.procyon.org.uk> In-Reply-To: <155316885201.29437.3428987891437242750.stgit@warthog.procyon.org.uk> References: <155316885201.29437.3428987891437242750.stgit@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 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.42]); Thu, 21 Mar 2019 11:48:08 +0000 (UTC) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: David Howells cc: Kees Cook cc: Anton Vorontsov cc: Colin Cross cc: Tony Luck Acked-by: Kees Cook --- fs/pstore/inode.c | 110 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 71 insertions(+), 39 deletions(-) diff --git a/fs/pstore/inode.c b/fs/pstore/inode.c index c60ee46f3e39..4625246fa992 100644 --- a/fs/pstore/inode.c +++ b/fs/pstore/inode.c @@ -19,6 +19,8 @@ #include #include +#include +#include #include #include #include @@ -26,10 +28,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -227,38 +227,48 @@ static struct inode *pstore_get_inode(struct super_block *sb) return inode; } +struct pstore_fs_context { + unsigned int kmsg_bytes; +}; + enum { - Opt_kmsg_bytes, Opt_err + Opt_kmsg_bytes, }; -static const match_table_t tokens = { - {Opt_kmsg_bytes, "kmsg_bytes=%u"}, - {Opt_err, NULL} +static const struct fs_parameter_spec pstore_param_specs[] = { + fsparam_u32 ("kmsg_bytes", Opt_kmsg_bytes), + {} }; -static void parse_options(char *options) -{ - char *p; - substring_t args[MAX_OPT_ARGS]; - int option; +static const struct fs_parameter_description pstore_fs_parameters = { + .name = "pstore", + .specs = pstore_param_specs, +}; - if (!options) - return; +static int pstore_parse_param(struct fs_context *fc, struct fs_parameter *param) +{ + struct pstore_fs_context *ctx = fc->fs_private; + struct fs_parse_result result; + int opt; + + opt = fs_parse(fc, &pstore_fs_parameters, param, &result); + if (opt < 0) + return opt; + + switch (opt) { + case Opt_kmsg_bytes: + ctx->kmsg_bytes = result.uint_32; + break; + } - while ((p = strsep(&options, ",")) != NULL) { - int token; + return 0; +} - if (!*p) - continue; +static void pstore_apply_param(struct fs_context *fc) +{ + struct pstore_fs_context *ctx = fc->fs_private; - token = match_token(p, tokens, args); - switch (token) { - case Opt_kmsg_bytes: - if (!match_int(&args[0], &option)) - pstore_set_kmsg_bytes(option); - break; - } - } + pstore_set_kmsg_bytes(ctx->kmsg_bytes); } /* @@ -271,11 +281,10 @@ static int pstore_show_options(struct seq_file *m, struct dentry *root) return 0; } -static int pstore_remount(struct super_block *sb, int *flags, char *data) +static int pstore_reconfigure(struct fs_context *fc) { - sync_filesystem(sb); - parse_options(data); - + sync_filesystem(fc->root->d_sb); + pstore_apply_param(fc); return 0; } @@ -283,7 +292,6 @@ static const struct super_operations pstore_ops = { .statfs = simple_statfs, .drop_inode = generic_delete_inode, .evict_inode = pstore_evict_inode, - .remount_fs = pstore_remount, .show_options = pstore_show_options, }; @@ -389,12 +397,10 @@ void pstore_get_records(int quiet) inode_unlock(d_inode(root)); } -static int pstore_fill_super(struct super_block *sb, void *data, int silent) +static int pstore_fill_super(struct super_block *sb, struct fs_context *fc) { struct inode *inode; - pstore_sb = sb; - sb->s_maxbytes = MAX_LFS_FILESIZE; sb->s_blocksize = PAGE_SIZE; sb->s_blocksize_bits = PAGE_SHIFT; @@ -402,7 +408,8 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent) sb->s_op = &pstore_ops; sb->s_time_gran = 1; - parse_options(data); + pstore_sb = sb; + pstore_apply_param(fc); inode = pstore_get_inode(sb); if (inode) { @@ -416,14 +423,38 @@ static int pstore_fill_super(struct super_block *sb, void *data, int silent) return -ENOMEM; pstore_get_records(0); - return 0; } -static struct dentry *pstore_mount(struct file_system_type *fs_type, - int flags, const char *dev_name, void *data) +static int pstore_get_tree(struct fs_context *fc) +{ + return vfs_get_super(fc, vfs_get_single_reconf_super, + pstore_fill_super); +} + +static void pstore_free_fc(struct fs_context *fc) { - return mount_single(fs_type, flags, data, pstore_fill_super); + kfree(fc->fs_private); +} + +static const struct fs_context_operations pstore_context_ops = { + .free = pstore_free_fc, + .parse_param = pstore_parse_param, + .get_tree = pstore_get_tree, + .reconfigure = pstore_reconfigure, +}; + +static int pstore_init_fs_context(struct fs_context *fc) +{ + struct pstore_fs_context *ctx; + + ctx = kzalloc(sizeof(struct pstore_fs_context), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + fc->fs_private = ctx; + fc->ops = &pstore_context_ops; + return 0; } static void pstore_kill_sb(struct super_block *sb) @@ -435,7 +466,8 @@ static void pstore_kill_sb(struct super_block *sb) static struct file_system_type pstore_fs_type = { .owner = THIS_MODULE, .name = "pstore", - .mount = pstore_mount, + .init_fs_context = pstore_init_fs_context, + .parameters = &pstore_fs_parameters, .kill_sb = pstore_kill_sb, };