From patchwork Fri Nov 1 16:42:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Almeida?= X-Patchwork-Id: 13859594 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1123E6F06E for ; Fri, 1 Nov 2024 16:43:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 394F06B0089; Fri, 1 Nov 2024 12:43:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3467D6B008C; Fri, 1 Nov 2024 12:43:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E6356B0093; Fri, 1 Nov 2024 12:43:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 02F7E6B0089 for ; Fri, 1 Nov 2024 12:43:35 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id ACAFD80A96 for ; Fri, 1 Nov 2024 16:43:35 +0000 (UTC) X-FDA: 82738096350.23.D7E64E4 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf09.hostedemail.com (Postfix) with ESMTP id 19BE414001A for ; Fri, 1 Nov 2024 16:43:13 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=pn87DnAX; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf09.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730479357; a=rsa-sha256; cv=none; b=Dp7FndQo9SJ1+/8zx6Ryk9iP8As4DCXry4dxfxugMh8w9fx/dUrZqdJw7TvGUThO4rTblP pHM/Jk7bf+1HIS26BAv0owz6UoP5odjyGWqE8o44xZtD/UH+iLpzHESrneg2Kjf7YweZ9l CCFPf2HgWPTZBBEgyU2ot8hDyHD1vZw= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=pn87DnAX; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf09.hostedemail.com: domain of andrealmeid@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=andrealmeid@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730479357; h=from:from:sender: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:dkim-signature; bh=1Ftxs1X2bzMP8j6QK8gh+paXxKWIM0HgFnEN8ePS9Tc=; b=RuEYvRd+2Xo+LvWBEFs2y9X454Lq860a6w1l9zk5g0ymDjUj/6lEjeIDKugg6xA+C1aCgP fz0B4DxeCtsB3D5sd5AvndNZfQSqEufR/GBiQVHIKvu5bXmyljG8ik0GcwbF7ROeoixvei ir9OSQCrqn4gFW3E1dBX0v71JM5ONdU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=1Ftxs1X2bzMP8j6QK8gh+paXxKWIM0HgFnEN8ePS9Tc=; b=pn87DnAXiqTKqX3MhKegErUZj5 8fCM7W1FYVlDWFulKMj228VX/ZFBQhPW4JdWHiNJiwft3+OKS2uzZ38b0zQkfN7UDdR63V5WJmxNJ 0cosR6SaUcOAmBfdPq5JkJzMoDj8rmyXRxm5n8gdLhSHxkpUdnkxrjNy6F6WQp+T9Hq942V7HLV3C riIgfxGS/lJw0g3kwhnuyvJbZ219OKN0jbsI4l8TPLXRXOdfFlve7BfHTYfALrHsT8CTepBHlg3m+ +N3x4S5N5bDYQV3qfkogt58NtqJQWVUwatzywOpDBtCpGXtluXxG07xA2u0cIp2s8qwApichjWNIj cvwLKPEQ==; Received: from [189.78.222.89] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1t6ukB-000V2F-9N; Fri, 01 Nov 2024 17:43:27 +0100 From: =?utf-8?q?Andr=C3=A9_Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org, Stephen Rothwell , Nathan Chancellor Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Theodore Ts'o , =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH v2 3/3] tmpfs: Initialize sysfs during tmpfs init Date: Fri, 1 Nov 2024 13:42:51 -0300 Message-ID: <20241101164251.327884-4-andrealmeid@igalia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241101164251.327884-1-andrealmeid@igalia.com> References: <20241101164251.327884-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 19BE414001A X-Rspamd-Server: rspam11 X-Stat-Signature: bgg5a6u5uuqwudddg3uxp8ehsa7fw6mr X-HE-Tag: 1730479393-979514 X-HE-Meta: U2FsdGVkX18ieDKsSN5yoBLrA7gng5ZmUpojI3s80spU1nGzSOn6orLBpj9xPZTGVnJI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x4GvzjDe0ar2JAOZ13vZsiQpxn0MD8PDvrKQCPFzNsaNfCtEiKVFGCVlAbeuo2pJfP3D+KRV+y6XBw3fdN9T44zJ70NrC87os3q4eeF3qxX3oJdF1i7wsirhPJd/6sV5oc1YpAT+uwUkx27SguNJOVxz4NBdhsyIXF7jVHnGf42X92Y= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Instead of using fs_initcall(), initialize sysfs with the rest of the filesystem. This is the right way to do it because otherwise any error during tmpfs_sysfs_init() would get silently ignored. It's also useful if tmpfs' sysfs ever need to display runtime information. Signed-off-by: André Almeida --- Changes from v1: - Fixed ifdef guard for tmpfs_sysfs_init() --- mm/shmem.c | 130 ++++++++++++++++++++++++++++------------------------- 1 file changed, 68 insertions(+), 62 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 6038e1d11987..a5355cf9443c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5126,6 +5126,66 @@ static struct file_system_type shmem_fs_type = { .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME, }; +#if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS) + +#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \ +{ \ + .attr = { .name = __stringify(_name), .mode = _mode }, \ + .show = _show, \ + .store = _store, \ +} + +#define TMPFS_ATTR_W(_name, _store) \ + static struct kobj_attribute tmpfs_attr_##_name = \ + __INIT_KOBJ_ATTR(_name, 0200, NULL, _store) + +#define TMPFS_ATTR_RW(_name, _show, _store) \ + static struct kobj_attribute tmpfs_attr_##_name = \ + __INIT_KOBJ_ATTR(_name, 0644, _show, _store) + +#define TMPFS_ATTR_RO(_name, _show) \ + static struct kobj_attribute tmpfs_attr_##_name = \ + __INIT_KOBJ_ATTR(_name, 0444, _show, NULL) + +#if IS_ENABLED(CONFIG_UNICODE) +static ssize_t casefold_show(struct kobject *kobj, struct kobj_attribute *a, + char *buf) +{ + return sysfs_emit(buf, "supported\n"); +} +TMPFS_ATTR_RO(casefold, casefold_show); +#endif + +static struct attribute *tmpfs_attributes[] = { +#if IS_ENABLED(CONFIG_UNICODE) + &tmpfs_attr_casefold.attr, +#endif + NULL +}; + +static const struct attribute_group tmpfs_attribute_group = { + .attrs = tmpfs_attributes, + .name = "features" +}; + +static struct kobject *tmpfs_kobj; + +static int __init tmpfs_sysfs_init(void) +{ + int ret; + + tmpfs_kobj = kobject_create_and_add("tmpfs", fs_kobj); + if (!tmpfs_kobj) + return -ENOMEM; + + ret = sysfs_create_group(tmpfs_kobj, &tmpfs_attribute_group); + if (ret) + kobject_put(tmpfs_kobj); + + return ret; +} +#endif /* CONFIG_SYSFS && CONFIG_TMPFS */ + void __init shmem_init(void) { int error; @@ -5149,6 +5209,14 @@ void __init shmem_init(void) goto out1; } +#if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS) + error = tmpfs_sysfs_init(); + if (error) { + pr_err("Could not init tmpfs sysfs\n"); + goto out1; + } +#endif + #ifdef CONFIG_TRANSPARENT_HUGEPAGE if (has_transparent_hugepage() && shmem_huge > SHMEM_HUGE_DENY) SHMEM_SB(shm_mnt->mnt_sb)->huge = shmem_huge; @@ -5546,65 +5614,3 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, return page; } EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp); - -#if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS) - -#define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \ -{ \ - .attr = { .name = __stringify(_name), .mode = _mode }, \ - .show = _show, \ - .store = _store, \ -} - -#define TMPFS_ATTR_W(_name, _store) \ - static struct kobj_attribute tmpfs_attr_##_name = \ - __INIT_KOBJ_ATTR(_name, 0200, NULL, _store) - -#define TMPFS_ATTR_RW(_name, _show, _store) \ - static struct kobj_attribute tmpfs_attr_##_name = \ - __INIT_KOBJ_ATTR(_name, 0644, _show, _store) - -#define TMPFS_ATTR_RO(_name, _show) \ - static struct kobj_attribute tmpfs_attr_##_name = \ - __INIT_KOBJ_ATTR(_name, 0444, _show, NULL) - -#if IS_ENABLED(CONFIG_UNICODE) -static ssize_t casefold_show(struct kobject *kobj, struct kobj_attribute *a, - char *buf) -{ - return sysfs_emit(buf, "supported\n"); -} -TMPFS_ATTR_RO(casefold, casefold_show); -#endif - -static struct attribute *tmpfs_attributes[] = { -#if IS_ENABLED(CONFIG_UNICODE) - &tmpfs_attr_casefold.attr, -#endif - NULL -}; - -static const struct attribute_group tmpfs_attribute_group = { - .attrs = tmpfs_attributes, - .name = "features" -}; - -static struct kobject *tmpfs_kobj; - -static int __init tmpfs_sysfs_init(void) -{ - int ret; - - tmpfs_kobj = kobject_create_and_add("tmpfs", fs_kobj); - if (!tmpfs_kobj) - return -ENOMEM; - - ret = sysfs_create_group(tmpfs_kobj, &tmpfs_attribute_group); - if (ret) - kobject_put(tmpfs_kobj); - - return ret; -} - -fs_initcall(tmpfs_sysfs_init); -#endif /* CONFIG_SYSFS && CONFIG_TMPFS */