From patchwork Fri Nov 1 01:37:41 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: 13858590 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 68D01E67495 for ; Fri, 1 Nov 2024 01:38:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 79FA56B00A7; Thu, 31 Oct 2024 21:38:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6FEA26B00A8; Thu, 31 Oct 2024 21:38:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C5F16B00A9; Thu, 31 Oct 2024 21:38:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3EF3B6B00A7 for ; Thu, 31 Oct 2024 21:38:15 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BD0E5140D28 for ; Fri, 1 Nov 2024 01:38:14 +0000 (UTC) X-FDA: 82735815456.28.59A742A Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf17.hostedemail.com (Postfix) with ESMTP id C184340012 for ; Fri, 1 Nov 2024 01:37:51 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=P7renoAq; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf17.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=1730425037; a=rsa-sha256; cv=none; b=HRTlFSsMqQUGkabld4Kdk5FYXzzYNXv3VDH6jjOFZhYBKrOJyuXP7QrF9DpiCsNMBWv2AC +/WW8N+AOjVaJnczcLaIHa+LRSV0ymd1uYk41/6v13W5rbcTM5Hy/AtCez+5+IjvLJ5h2/ wtgPvNJHFO2gPtsv8y04sPAhlBthz6o= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=P7renoAq; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf17.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=1730425037; 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=k/VHsL4n8pERS64P5NHMSQf1JEBAuX2jkWl5gqjSdQw=; b=NxvileDyXbMc5sgz7gVjh6w+8qruNt0gCo5s51r8hfT64Or1PTqpZeY1Nt0wMV2WdhV0fe Fe4g6CzBKPkJ2y7htcPNltfHA0lN7YjCxWfDw4tft61Wh+12X7IHNHt8fK01pKOIeqcm2y X7aM2/Vn2qtS+boq5ZZXuF2Nd5FyNIQ= 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=k/VHsL4n8pERS64P5NHMSQf1JEBAuX2jkWl5gqjSdQw=; b=P7renoAq/Nj0A3/1vK6ktV09ha 0YPhZg8HwiIH7CYXUUh3/A5MNQ8peqcpFMAQzX/AeCLfbjuEzmFgJVHu/96iSWH7NzooTvRg94Tgo gIA4OKIxxushW8a3C2javH97VxijDClm2UDI+7+h6tooabgWxwmMY4L95Iu7KPgb4n6zy+grPFKAJ jrobxJOCpsjclHQsYboorxe67fkiNuMVAibvI85AqDGo0dsG/jwhSKuCiPzDa4Ao/GdKNM1hV4iMx iYd5PCsCI5aajLgFHt5PEIYKOPQwMOGxLWeDQ8udu/X3kUaZQdrd/6wtKNvk/FvYXi7WddYan2D4x 2jm6T2oA==; 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 1t6gbz-000G0m-6J; Fri, 01 Nov 2024 02:38:03 +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 3/3] tmpfs: Initialize sysfs during tmpfs init Date: Thu, 31 Oct 2024 22:37:41 -0300 Message-ID: <20241101013741.295792-4-andrealmeid@igalia.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241101013741.295792-1-andrealmeid@igalia.com> References: <20241101013741.295792-1-andrealmeid@igalia.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: C184340012 X-Rspamd-Server: rspam01 X-Stat-Signature: 6wdy3c5ytrauxi5sctuqs4pgxeto7p1w X-HE-Tag: 1730425071-726672 X-HE-Meta: U2FsdGVkX1/ZPuCKF9m65zOZk8JyGZ8WtOq4f7RsFUqIhdMUvFHl4lvQz2Nh1nI+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ixOEuaScdYamS9HOgOq7uOgXy35jM093N0XejZMgO+nh5OUGpR1ZZpseXPESqtZdgxOwFCQ2poZ5QwtiL+p89Wu6OR6Ch1THuk6AS5WeaWynmGSGTCqg48jzH1sHQyJcLXy647n6YXxAulI/OsUahJ4+PxabUU9++NxdUmp+adxKM5w= 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 --- mm/shmem.c | 130 ++++++++++++++++++++++++++++------------------------- 1 file changed, 68 insertions(+), 62 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 6038e1d11987..8ff2f619f531 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; } +#ifdef CONFIG_SYSFS + 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 */