From patchwork Tue Mar 5 23:08:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 13583078 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2670D41760 for ; Tue, 5 Mar 2024 23:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709680127; cv=none; b=W1fZ84VhEL837OU29swC7uJShONPZ/6y7J3pU+d6sPQTS6o76TPAgNUIosgN8UgIAQNJIiPfCi26TKeMliMjqBpCBx8D4ib9UpbHHiaPIm/U0LiRleMbOYqHgCDxxGWJ3E8AqvzZ8WGrbkXehN3zkjz/otIr9IARTaoitfgQiys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709680127; c=relaxed/simple; bh=WahJi691px2HbISMWp7obAm0qtvVi/xNabmzwdrhntg=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=gi2xLrjgwSZ3t3F5of+KyZR5fh5OAVZhFUxpXFQfGwgaFvI/gDB+kGpIVT4dEZi4U7S5Q+XSsisxK9qhtp/QL8Wm/FAu5TMdDiZLtbkXBkf1O2htcA6g2U4M6TIVh+0agI1zqawP03TMjzOqrnhyI3eGStBAIOsMNle6NBTbQz4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WoC9sk/N; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WoC9sk/N" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709680124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=k4zEhLylkVYxuq8jN+r2udJ/BfLYP8M/KqSxgUaIftk=; b=WoC9sk/NcHfTXcOrCD9NJ17MivG7Fsy8lIinXw51OncdtVjkkn/GeGPK2PijJ/eus2ldeH 8CbFxJsyhA6IdVCC59KLZlOBD93J6zPjrcEKeBmeqmaE82w5IL68BxNwWnIRvsPYSVEgdE RgMRN7C9m6bk3TQ/SFK/zkaZcCxFMCE= Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-64-QFpHNVP3M_-d1KGWhEnuKQ-1; Tue, 05 Mar 2024 18:08:42 -0500 X-MC-Unique: QFpHNVP3M_-d1KGWhEnuKQ-1 Received: by mail-il1-f197.google.com with SMTP id e9e14a558f8ab-3651a261194so13154385ab.1 for ; Tue, 05 Mar 2024 15:08:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709680121; x=1710284921; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=k4zEhLylkVYxuq8jN+r2udJ/BfLYP8M/KqSxgUaIftk=; b=i34hadXUoZ1khaqbhEQFIIMVTgOETEhhm5Yh1UTbTrA0ZOUSIlstZTslqnidPjMf+w OFBHy2fc82vfC6y80gtWrCesODasxYPLfWrxprBXs35Yu3p8aNP1iVwlvI7nWDrMedF3 DDZ5Ek9MPDL3OyqNq+u/3Uojb7ly2rNe75OfZqrIC2KmTQ3Nfo2prB5DREQLzAJrgj1N Mm3aBCOcPxbdO4EtcXZK1ypDaSWIS0MIFzAbRgq1V/z9G1TgD8WjcKpNwKyo6zDRVWro 9rHa4b0axwSP+1PqE4xcgaG+qS755kIjJREAs7qBsYzze5BpmAyZvjmzY9QT0AYIlBIa JMHw== X-Gm-Message-State: AOJu0Yy+1hWVsv+G9RJ4omuBXr0lLFvizNoxBts1NyyDF5Oq8K3kIpll R7vXCMFGo+Agj7MmiG6OaZx6N/JPBNHGKiYUCXB3MplrZJsmGcQOeuP5FBK1lljxr4Bs3tNQmDT wnp1chlVKaIk9btIHnfpXWpY2DzzX8tbts75GNy0Ojknhjd1LavmPbi6z1SkH/5QSnnqoJ9r5ZU OpD73/Ei5Z4jhFIvhcl8/Lj+5PkFZyMJhY7h4jqKIPl54emc5a X-Received: by 2002:a92:2a12:0:b0:365:fe08:8268 with SMTP id r18-20020a922a12000000b00365fe088268mr2432965ile.5.1709680121029; Tue, 05 Mar 2024 15:08:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMtMbVl5rdNWnHCtrmrtao16YtmiXNjBFhb1rTLa/2uPILDGeH74WPU7dzzgc9lLERTJ68eA== X-Received: by 2002:a92:2a12:0:b0:365:fe08:8268 with SMTP id r18-20020a922a12000000b00365fe088268mr2432931ile.5.1709680120621; Tue, 05 Mar 2024 15:08:40 -0800 (PST) Received: from [10.0.0.71] (sandeen.net. [63.231.237.45]) by smtp.gmail.com with ESMTPSA id u11-20020a92d1cb000000b0036600aa51dbsm390770ilg.47.2024.03.05.15.08.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 15:08:40 -0800 (PST) Message-ID: <49d1f108-46e3-443f-85a3-6dd730c5d076@redhat.com> Date: Tue, 5 Mar 2024 17:08:39 -0600 Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/2] vfs: Convert debugfs to use the new mount API Content-Language: en-US From: Eric Sandeen To: linux-fsdevel@vger.kernel.org Cc: Steven Rostedt , Greg Kroah-Hartman , "Rafael J. Wysocki" , Christian Brauner , Bill O'Donnell , David Howells References: In-Reply-To: From: David Howells Convert the debugfs filesystem to the new internal mount API as the old one will be obsoleted and removed. This allows greater flexibility in communication of mount parameters between userspace, the VFS and the filesystem. See Documentation/filesystems/mount_api.txt for more information. Signed-off-by: David Howells Co-developed-by: Eric Sandeen Signed-off-by: Eric Sandeen [sandeen: forward port to modern kernel, fix remounting] cc: Greg Kroah-Hartman cc: "Rafael J. Wysocki" Acked-by: Greg Kroah-Hartman --- fs/debugfs/inode.c | 198 +++++++++++++++++++++------------------------ 1 file changed, 93 insertions(+), 105 deletions(-) diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index 034a617cb1a5..c2adfb272da8 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -14,7 +14,8 @@ #include #include -#include +#include +#include #include #include #include @@ -23,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -77,7 +77,7 @@ static struct inode *debugfs_get_inode(struct super_block *sb) return inode; } -struct debugfs_mount_opts { +struct debugfs_fs_info { kuid_t uid; kgid_t gid; umode_t mode; @@ -89,68 +89,51 @@ enum { Opt_uid, Opt_gid, Opt_mode, - Opt_err }; -static const match_table_t tokens = { - {Opt_uid, "uid=%u"}, - {Opt_gid, "gid=%u"}, - {Opt_mode, "mode=%o"}, - {Opt_err, NULL} +static const struct fs_parameter_spec debugfs_param_specs[] = { + fsparam_u32 ("gid", Opt_gid), + fsparam_u32oct ("mode", Opt_mode), + fsparam_u32 ("uid", Opt_uid), + {} }; -struct debugfs_fs_info { - struct debugfs_mount_opts mount_opts; -}; - -static int debugfs_parse_options(char *data, struct debugfs_mount_opts *opts) +static int debugfs_parse_param(struct fs_context *fc, struct fs_parameter *param) { - substring_t args[MAX_OPT_ARGS]; - int option; - int token; + struct debugfs_fs_info *opts = fc->s_fs_info; + struct fs_parse_result result; kuid_t uid; kgid_t gid; - char *p; - - opts->opts = 0; - opts->mode = DEBUGFS_DEFAULT_MODE; - - while ((p = strsep(&data, ",")) != NULL) { - if (!*p) - continue; - - token = match_token(p, tokens, args); - switch (token) { - case Opt_uid: - if (match_int(&args[0], &option)) - return -EINVAL; - uid = make_kuid(current_user_ns(), option); - if (!uid_valid(uid)) - return -EINVAL; - opts->uid = uid; - break; - case Opt_gid: - if (match_int(&args[0], &option)) - return -EINVAL; - gid = make_kgid(current_user_ns(), option); - if (!gid_valid(gid)) - return -EINVAL; - opts->gid = gid; - break; - case Opt_mode: - if (match_octal(&args[0], &option)) - return -EINVAL; - opts->mode = option & S_IALLUGO; - break; - /* - * We might like to report bad mount options here; - * but traditionally debugfs has ignored all mount options - */ - } - - opts->opts |= BIT(token); + int opt; + + opt = fs_parse(fc, debugfs_param_specs, param, &result); + if (opt < 0) + return opt; + + switch (opt) { + case Opt_uid: + uid = make_kuid(current_user_ns(), result.uint_32); + if (!uid_valid(uid)) + return invalf(fc, "Unknown uid"); + opts->uid = uid; + break; + case Opt_gid: + gid = make_kgid(current_user_ns(), result.uint_32); + if (!gid_valid(gid)) + return invalf(fc, "Unknown gid"); + opts->gid = gid; + break; + case Opt_mode: + opts->mode = result.uint_32 & S_IALLUGO; + break; + /* + * We might like to report bad mount options here; + * but traditionally debugfs has ignored all mount options + */ } + opts->opts |= BIT(opt); + return 0; } @@ -158,23 +141,22 @@ static void _debugfs_apply_options(struct super_block *sb, bool remount) { struct debugfs_fs_info *fsi = sb->s_fs_info; struct inode *inode = d_inode(sb->s_root); - struct debugfs_mount_opts *opts = &fsi->mount_opts; /* * On remount, only reset mode/uid/gid if they were provided as mount * options. */ - if (!remount || opts->opts & BIT(Opt_mode)) { + if (!remount || fsi->opts & BIT(Opt_mode)) { inode->i_mode &= ~S_IALLUGO; - inode->i_mode |= opts->mode; + inode->i_mode |= fsi->mode; } - if (!remount || opts->opts & BIT(Opt_uid)) - inode->i_uid = opts->uid; + if (!remount || fsi->opts & BIT(Opt_uid)) + inode->i_uid = fsi->uid; - if (!remount || opts->opts & BIT(Opt_gid)) - inode->i_gid = opts->gid; + if (!remount || fsi->opts & BIT(Opt_gid)) + inode->i_gid = fsi->gid; } static void debugfs_apply_options(struct super_block *sb) @@ -187,35 +169,33 @@ static void debugfs_apply_options_remount(struct super_block *sb) _debugfs_apply_options(sb, true); } -static int debugfs_remount(struct super_block *sb, int *flags, char *data) +static int debugfs_reconfigure(struct fs_context *fc) { - int err; - struct debugfs_fs_info *fsi = sb->s_fs_info; + struct super_block *sb = fc->root->d_sb; + struct debugfs_fs_info *sb_opts = sb->s_fs_info; + struct debugfs_fs_info *new_opts = fc->s_fs_info; sync_filesystem(sb); - err = debugfs_parse_options(data, &fsi->mount_opts); - if (err) - goto fail; + /* structure copy of new mount options to sb */ + *sb_opts = *new_opts; debugfs_apply_options_remount(sb); -fail: - return err; + return 0; } static int debugfs_show_options(struct seq_file *m, struct dentry *root) { struct debugfs_fs_info *fsi = root->d_sb->s_fs_info; - struct debugfs_mount_opts *opts = &fsi->mount_opts; - if (!uid_eq(opts->uid, GLOBAL_ROOT_UID)) + if (!uid_eq(fsi->uid, GLOBAL_ROOT_UID)) seq_printf(m, ",uid=%u", - from_kuid_munged(&init_user_ns, opts->uid)); - if (!gid_eq(opts->gid, GLOBAL_ROOT_GID)) + from_kuid_munged(&init_user_ns, fsi->uid)); + if (!gid_eq(fsi->gid, GLOBAL_ROOT_GID)) seq_printf(m, ",gid=%u", - from_kgid_munged(&init_user_ns, opts->gid)); - if (opts->mode != DEBUGFS_DEFAULT_MODE) - seq_printf(m, ",mode=%o", opts->mode); + from_kgid_munged(&init_user_ns, fsi->gid)); + if (fsi->mode != DEBUGFS_DEFAULT_MODE) + seq_printf(m, ",mode=%o", fsi->mode); return 0; } @@ -229,7 +209,6 @@ static void debugfs_free_inode(struct inode *inode) static const struct super_operations debugfs_super_operations = { .statfs = simple_statfs, - .remount_fs = debugfs_remount, .show_options = debugfs_show_options, .free_inode = debugfs_free_inode, }; @@ -263,26 +242,14 @@ static const struct dentry_operations debugfs_dops = { .d_automount = debugfs_automount, }; -static int debug_fill_super(struct super_block *sb, void *data, int silent) +static int debugfs_fill_super(struct super_block *sb, struct fs_context *fc) { static const struct tree_descr debug_files[] = {{""}}; - struct debugfs_fs_info *fsi; int err; - fsi = kzalloc(sizeof(struct debugfs_fs_info), GFP_KERNEL); - sb->s_fs_info = fsi; - if (!fsi) { - err = -ENOMEM; - goto fail; - } - - err = debugfs_parse_options(data, &fsi->mount_opts); + err = simple_fill_super(sb, DEBUGFS_MAGIC, debug_files); if (err) - goto fail; - - err = simple_fill_super(sb, DEBUGFS_MAGIC, debug_files); - if (err) - goto fail; + return err; sb->s_op = &debugfs_super_operations; sb->s_d_op = &debugfs_dops; @@ -290,27 +257,48 @@ static int debug_fill_super(struct super_block *sb, void *data, int silent) debugfs_apply_options(sb); return 0; - -fail: - kfree(fsi); - sb->s_fs_info = NULL; - return err; } -static struct dentry *debug_mount(struct file_system_type *fs_type, - int flags, const char *dev_name, - void *data) +static int debugfs_get_tree(struct fs_context *fc) { if (!(debugfs_allow & DEBUGFS_ALLOW_API)) - return ERR_PTR(-EPERM); + return -EPERM; + + return get_tree_single(fc, debugfs_fill_super); +} + +static void debugfs_free_fc(struct fs_context *fc) +{ + kfree(fc->s_fs_info); +} - return mount_single(fs_type, flags, data, debug_fill_super); +static const struct fs_context_operations debugfs_context_ops = { + .free = debugfs_free_fc, + .parse_param = debugfs_parse_param, + .get_tree = debugfs_get_tree, + .reconfigure = debugfs_reconfigure, +}; + +static int debugfs_init_fs_context(struct fs_context *fc) +{ + struct debugfs_fs_info *fsi; + + fsi = kzalloc(sizeof(struct debugfs_fs_info), GFP_KERNEL); + if (!fsi) + return -ENOMEM; + + fsi->mode = DEBUGFS_DEFAULT_MODE; + + fc->s_fs_info = fsi; + fc->ops = &debugfs_context_ops; + return 0; } static struct file_system_type debug_fs_type = { .owner = THIS_MODULE, .name = "debugfs", - .mount = debug_mount, + .init_fs_context = debugfs_init_fs_context, + .parameters = debugfs_param_specs, .kill_sb = kill_litter_super, }; MODULE_ALIAS_FS("debugfs"); From patchwork Tue Mar 5 23:09:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Sandeen X-Patchwork-Id: 13583079 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC5B241760 for ; Tue, 5 Mar 2024 23:09:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709680178; cv=none; b=iJgHNixswyQ17EZt5TAF4cO/huuRNlOizW5FkgQNRfoKJYq+gewKMbFbMhyunD2H4t7PfBOmAp1SQdetnYN+LgYxccHVl3elne80vxS2D7k+DKinlx0HvfLguJa+jOn/CWSJSQ5Sd+SypEOUUn0fl9zrjqHh1Dlph5ZwGBpHVkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709680178; c=relaxed/simple; bh=IJ9aojpkJmxYtFGSIIJ9LCRD3xs5LMQNYlnl0wvLuXQ=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=r680UTvhE1FJW9CuPmw8OiPI5oopUP75sODgSnOTIG1cqPhU37qbqPdhrdCXhFMxFv9FSX5gH1qPQt0uvS47nglErZ5mQUK9jY+Z99aMhUlMXw5oh80Vd7gwEhv2HvLkdlucmWP3F7NHghmmLgvCRop/z0pbJISyw+b50Y5lSqk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Lrj3l22d; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Lrj3l22d" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709680175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zJaQu7t353O8uY3bvGcCFr7/5QWG6aSanVNZbb37UEY=; b=Lrj3l22dhLxMksgQ226BVY/AYiLkKNtT2U2S141ucLAotcH9iL6mE8wPq+SJxfxHwHvVSL KYeWGeDuXMYN3PAbiS4tpXNO703Q0aLT+EIoYjwnnELeBJ1k8R73f1s1JIT6b8JZkGnMGX OEEsQ9hxnUNzQNrd0UJvtvk8Y+GO24c= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-527-8sPRQ032Nqu-K7mlokC2Uw-1; Tue, 05 Mar 2024 18:09:34 -0500 X-MC-Unique: 8sPRQ032Nqu-K7mlokC2Uw-1 Received: by mail-io1-f71.google.com with SMTP id ca18e2360f4ac-7c49c867608so649752739f.3 for ; Tue, 05 Mar 2024 15:09:34 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709680172; x=1710284972; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zJaQu7t353O8uY3bvGcCFr7/5QWG6aSanVNZbb37UEY=; b=BnAR9Tj/4REWP23Yaf5Nv8H16KUdAAode8C/sF5qgt36ClI8zGJlPfhnA2umo7cLSy EfnafdEkaZfSGNTC/Yz84ei4pdcuhKHjdcMR7S0MqJGAf5ONBoAp/qiBmyE6jss7ROkX 1vZXRa2HnnnmoFP07/p/cnG9z899du4BhxQYOoFLiBM7AKHQEAHT9j46OxW0n5okhWE6 Vnk7H+zjqj1Tjp0eKSCLRxn9VmIGortgUi10uHvaZs20f/iG3OgUhvOnIFIi3sWOx23L xCNQaOwRM3N0fBxwDBNSHHUPYUtzjv+tUY51f2IdWYCzC6+bquB1aNoqLY+4h74P+Q04 Cr+Q== X-Gm-Message-State: AOJu0YwYhl/nBUshKysR8hOr+nxaMnsqhGkZ5xPvevaPUhIsHwfEE1We 1JgbA2P2VGFOvXTIPMZdMWaPZTmVKgd2dcR8p+V5shveBEKzmJel4Ob5D59QsI58xGgpBSPj6xK AJWaCvhNigvsuj8I+1vpjPBxSLSiiQaeg3IunKXWn32h8kf57VTcC9zxd7Vh5/94mxwhXmFuN5k Oz45ECIQH8trwxtUwHbwWRtybALXwwReaNOEc1M2upRCYfmWyq X-Received: by 2002:a05:6e02:1c82:b0:365:1563:c4e5 with SMTP id w2-20020a056e021c8200b003651563c4e5mr17433775ill.9.1709680172467; Tue, 05 Mar 2024 15:09:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmmRL2kuGmWOveWvjB3db+x8Z5UB73/B5/cIrRIb0BYvejzdOdxkRVo5061OWPaQVqMdUCNA== X-Received: by 2002:a05:6e02:1c82:b0:365:1563:c4e5 with SMTP id w2-20020a056e021c8200b003651563c4e5mr17433755ill.9.1709680172125; Tue, 05 Mar 2024 15:09:32 -0800 (PST) Received: from [10.0.0.71] (sandeen.net. [63.231.237.45]) by smtp.gmail.com with ESMTPSA id u11-20020a92d1cb000000b0036600aa51dbsm390770ilg.47.2024.03.05.15.09.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 15:09:31 -0800 (PST) Message-ID: <536e99d3-345c-448b-adee-a21389d7ab4b@redhat.com> Date: Tue, 5 Mar 2024 17:09:30 -0600 Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/2] vfs: Convert tracefs to use the new mount API Content-Language: en-US From: Eric Sandeen To: linux-fsdevel@vger.kernel.org Cc: Steven Rostedt , Greg Kroah-Hartman , "Rafael J. Wysocki" , Christian Brauner , Bill O'Donnell , David Howells References: In-Reply-To: From: David Howells Convert the tracefs filesystem to the new internal mount API as the old one will be obsoleted and removed. This allows greater flexibility in communication of mount parameters between userspace, the VFS and the filesystem. See Documentation/filesystems/mount_api.txt for more information. Signed-off-by: David Howells Co-developed-by: Eric Sandeen Signed-off-by: Eric Sandeen [sandeen: forward port to modern kernel, fix remounting] cc: Steven Rostedt cc: Greg Kroah-Hartman Acked-by: Steven Rostedt (Google) Tested-by: Steven Rostedt (Google) --- fs/tracefs/inode.c | 196 +++++++++++++++++++++------------------------ 1 file changed, 91 insertions(+), 105 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index d65ffad4c327..69d0fb2e03a2 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -11,14 +11,14 @@ #include #include -#include +#include +#include #include #include #include #include #include #include -#include #include #include #include "internal.h" @@ -231,7 +231,7 @@ struct inode *tracefs_get_inode(struct super_block *sb) return inode; } -struct tracefs_mount_opts { +struct tracefs_fs_info { kuid_t uid; kgid_t gid; umode_t mode; @@ -243,68 +243,51 @@ enum { Opt_uid, Opt_gid, Opt_mode, - Opt_err }; -static const match_table_t tokens = { - {Opt_uid, "uid=%u"}, - {Opt_gid, "gid=%u"}, - {Opt_mode, "mode=%o"}, - {Opt_err, NULL} +static const struct fs_parameter_spec tracefs_param_specs[] = { + fsparam_u32 ("gid", Opt_gid), + fsparam_u32oct ("mode", Opt_mode), + fsparam_u32 ("uid", Opt_uid), + {} }; -struct tracefs_fs_info { - struct tracefs_mount_opts mount_opts; -}; - -static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts) +static int tracefs_parse_param(struct fs_context *fc, struct fs_parameter *param) { - substring_t args[MAX_OPT_ARGS]; - int option; - int token; + struct tracefs_fs_info *opts = fc->s_fs_info; + struct fs_parse_result result; kuid_t uid; kgid_t gid; - char *p; - - opts->opts = 0; - opts->mode = TRACEFS_DEFAULT_MODE; - - while ((p = strsep(&data, ",")) != NULL) { - if (!*p) - continue; - - token = match_token(p, tokens, args); - switch (token) { - case Opt_uid: - if (match_int(&args[0], &option)) - return -EINVAL; - uid = make_kuid(current_user_ns(), option); - if (!uid_valid(uid)) - return -EINVAL; - opts->uid = uid; - break; - case Opt_gid: - if (match_int(&args[0], &option)) - return -EINVAL; - gid = make_kgid(current_user_ns(), option); - if (!gid_valid(gid)) - return -EINVAL; - opts->gid = gid; - break; - case Opt_mode: - if (match_octal(&args[0], &option)) - return -EINVAL; - opts->mode = option & S_IALLUGO; - break; - /* - * We might like to report bad mount options here; - * but traditionally tracefs has ignored all mount options - */ - } - - opts->opts |= BIT(token); + int opt; + + opt = fs_parse(fc, tracefs_param_specs, param, &result); + if (opt < 0) + return opt; + + switch (opt) { + case Opt_uid: + uid = make_kuid(current_user_ns(), result.uint_32); + if (!uid_valid(uid)) + return invalf(fc, "Unknown uid"); + opts->uid = uid; + break; + case Opt_gid: + gid = make_kgid(current_user_ns(), result.uint_32); + if (!gid_valid(gid)) + return invalf(fc, "Unknown gid"); + opts->gid = gid; + break; + case Opt_mode: + opts->mode = result.uint_32 & S_IALLUGO; + break; + /* + * We might like to report bad mount options here; + * but traditionally tracefs has ignored all mount options + */ } + opts->opts |= BIT(opt); + return 0; } @@ -312,7 +295,6 @@ static int tracefs_apply_options(struct super_block *sb, bool remount) { struct tracefs_fs_info *fsi = sb->s_fs_info; struct inode *inode = d_inode(sb->s_root); - struct tracefs_mount_opts *opts = &fsi->mount_opts; umode_t tmp_mode; /* @@ -320,50 +302,46 @@ static int tracefs_apply_options(struct super_block *sb, bool remount) * options. */ - if (!remount || opts->opts & BIT(Opt_mode)) { + if (!remount || fsi->opts & BIT(Opt_mode)) { tmp_mode = READ_ONCE(inode->i_mode) & ~S_IALLUGO; - tmp_mode |= opts->mode; + tmp_mode |= fsi->mode; WRITE_ONCE(inode->i_mode, tmp_mode); } - if (!remount || opts->opts & BIT(Opt_uid)) - inode->i_uid = opts->uid; + if (!remount || fsi->opts & BIT(Opt_uid)) + inode->i_uid = fsi->uid; - if (!remount || opts->opts & BIT(Opt_gid)) - inode->i_gid = opts->gid; + if (!remount || fsi->opts & BIT(Opt_gid)) + inode->i_gid = fsi->gid; return 0; } -static int tracefs_remount(struct super_block *sb, int *flags, char *data) +static int tracefs_reconfigure(struct fs_context *fc) { - int err; - struct tracefs_fs_info *fsi = sb->s_fs_info; + struct super_block *sb = fc->root->d_sb; + struct tracefs_fs_info *sb_opts = sb->s_fs_info; + struct tracefs_fs_info *new_opts = fc->s_fs_info; sync_filesystem(sb); - err = tracefs_parse_options(data, &fsi->mount_opts); - if (err) - goto fail; + /* structure copy of new mount options to sb */ + *sb_opts = *new_opts; - tracefs_apply_options(sb, true); - -fail: - return err; + return tracefs_apply_options(sb, true); } static int tracefs_show_options(struct seq_file *m, struct dentry *root) { struct tracefs_fs_info *fsi = root->d_sb->s_fs_info; - struct tracefs_mount_opts *opts = &fsi->mount_opts; - if (!uid_eq(opts->uid, GLOBAL_ROOT_UID)) + if (!uid_eq(fsi->uid, GLOBAL_ROOT_UID)) seq_printf(m, ",uid=%u", - from_kuid_munged(&init_user_ns, opts->uid)); - if (!gid_eq(opts->gid, GLOBAL_ROOT_GID)) + from_kuid_munged(&init_user_ns, fsi->uid)); + if (!gid_eq(fsi->gid, GLOBAL_ROOT_GID)) seq_printf(m, ",gid=%u", - from_kgid_munged(&init_user_ns, opts->gid)); - if (opts->mode != TRACEFS_DEFAULT_MODE) - seq_printf(m, ",mode=%o", opts->mode); + from_kgid_munged(&init_user_ns, fsi->gid)); + if (fsi->mode != TRACEFS_DEFAULT_MODE) + seq_printf(m, ",mode=%o", fsi->mode); return 0; } @@ -373,7 +351,6 @@ static const struct super_operations tracefs_super_operations = { .free_inode = tracefs_free_inode, .drop_inode = generic_delete_inode, .statfs = simple_statfs, - .remount_fs = tracefs_remount, .show_options = tracefs_show_options, }; @@ -403,26 +380,14 @@ static const struct dentry_operations tracefs_dentry_operations = { .d_release = tracefs_d_release, }; -static int trace_fill_super(struct super_block *sb, void *data, int silent) +static int tracefs_fill_super(struct super_block *sb, struct fs_context *fc) { static const struct tree_descr trace_files[] = {{""}}; - struct tracefs_fs_info *fsi; int err; - fsi = kzalloc(sizeof(struct tracefs_fs_info), GFP_KERNEL); - sb->s_fs_info = fsi; - if (!fsi) { - err = -ENOMEM; - goto fail; - } - - err = tracefs_parse_options(data, &fsi->mount_opts); - if (err) - goto fail; - - err = simple_fill_super(sb, TRACEFS_MAGIC, trace_files); + err = simple_fill_super(sb, TRACEFS_MAGIC, trace_files); if (err) - goto fail; + return err; sb->s_op = &tracefs_super_operations; sb->s_d_op = &tracefs_dentry_operations; @@ -430,24 +395,45 @@ static int trace_fill_super(struct super_block *sb, void *data, int silent) tracefs_apply_options(sb, false); return 0; +} -fail: - kfree(fsi); - sb->s_fs_info = NULL; - return err; +static int tracefs_get_tree(struct fs_context *fc) +{ + return get_tree_single(fc, tracefs_fill_super); } -static struct dentry *trace_mount(struct file_system_type *fs_type, - int flags, const char *dev_name, - void *data) +static void tracefs_free_fc(struct fs_context *fc) { - return mount_single(fs_type, flags, data, trace_fill_super); + kfree(fc->s_fs_info); +} + +static const struct fs_context_operations tracefs_context_ops = { + .free = tracefs_free_fc, + .parse_param = tracefs_parse_param, + .get_tree = tracefs_get_tree, + .reconfigure = tracefs_reconfigure, +}; + +static int tracefs_init_fs_context(struct fs_context *fc) +{ + struct tracefs_fs_info *fsi; + + fsi = kzalloc(sizeof(struct tracefs_fs_info), GFP_KERNEL); + if (!fsi) + return -ENOMEM; + + fsi->mode = TRACEFS_DEFAULT_MODE; + + fc->s_fs_info = fsi; + fc->ops = &tracefs_context_ops; + return 0; } static struct file_system_type trace_fs_type = { .owner = THIS_MODULE, .name = "tracefs", - .mount = trace_mount, + .init_fs_context = tracefs_init_fs_context, + .parameters = tracefs_param_specs, .kill_sb = kill_litter_super, }; MODULE_ALIAS_FS("tracefs");