From patchwork Tue Dec 30 20:51:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1118 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767127967; bh=AWfuxu8/la2itweoGef6qA6cDDH9D7LgAP1eOOX0xhQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=UC2Dc2KCKb/ivFMYnlaMFbq1hzNeOrAW6Zv8aJyjR1dx6UY4cuPulRN4BniR89ie8 SNXzNF2it0MOdYdkZbyXbT3RjKPjENjW5PJfh99rdqY8N08o0pMdbsaemAXCOVoFLl O5vQVQ+ysnoa9rDsUwwOJ2qbkIPwkXCHhM9L/AwPYeBUlIm7itNqWF278OczIB4nCU kYCx0M+62YyBw5NrVO82Ql+DEyOYUmqmNhDjBwfLxqDrPysKmmoBnsb+wz5d+6YSJ+ 36KUGGoxp6qLzNoxXw3qgLs6KaYfTBSX1HvEyNx2sb/HBNvCmtnipi4D/rACPmh5NK jlHtvDfklAP8g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C677868F86 for ; Tue, 30 Dec 2025 13:52:47 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id X0ebFnp4WI-L for ; Tue, 30 Dec 2025 13:52:47 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767127965; bh=AWfuxu8/la2itweoGef6qA6cDDH9D7LgAP1eOOX0xhQ=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=PoCR9web1fLqBgTx8Df4VVwZUXETykMygiRswPTZsvKnuw77/QXTTDaj4iC3y2z5n YGIoWvOC1J609V/lTJKGoHmTM4/jNWFiO7wKD1+bOxZyHXy1g4W69P/c4ia60/0T78 c7zvKX/IeNexqvY9CCOd2bWESwRyg0XzWnaPD2stRbxQ+7/PsDLIloh9Y8u2wMksA2 pwgLdVdwBk3BZYIs5IqIvP03vgF2KdniEXzY18YpjjLiQ6VcMZyCodOovBaKbkpWlb gTCaNRcZy9tTTp4ZD4zwRryYsNiIYObvwisnVK1pkd5eT3+uj5p+M1E68TwzyNS1w0 uWRRhh+oBP64g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C124364C8A for ; Tue, 30 Dec 2025 13:52:45 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767127963; bh=/7g8dCp5vXealhpdpBDU3UO7JG0T+LBYMbNsA3+hcgA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jD9I/FPU9zQC5jSTRVQV81eNl85KDykfeZMs8K41qgCK1YHV/+el3IqbIqeWzK6lz l1WJnpY6gTOcjG20GUH5GAkd/U4IFdK7+jqpyX7EeNqlWxXUx22rCXTHDElHr9rrwx axV95Sfea9qOI4n/DheAAMHcxTyeZtbhmvxjs626NoZXLvoP9RZB60zpI2eY+l8b2V zpsd7E1bpa3nB51wGfww/z89NTMvwgifLnY4Qq9DLbAB3kXxSidxjQrIZdeyUuxC0N KqGmcJllNMzne7WmoVE719mzJdlqRYksETphvjLt6OLB5mmhWOKKp6tAJyp1Yv4MBq ZJCdkuTNF+6Vg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BAE0B64C8A; Tue, 30 Dec 2025 13:52:43 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id CrHTyv89DHvN; Tue, 30 Dec 2025 13:52:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1767127963; bh=xQrpGNJ+Ai2wr0eVzOerHCDJNXce5bJmderHgKpmMyw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mu9Fq1/HnIkn/cebN4cov28QjtuGnSIzdO5HNagNF4jujInMUPTWjL9ZvSDOzb2w9 MuezsSOyMVee/ixtwoDmCfgFEmiGLnE+TZdGEZy0lpyWCB1U4oSTb96ecCrklOUOW3 Ggiz/L6opxpIHHqjpltn+x4Sr4IdDfbOYEP/4WPq+Bylj4kTtKuPAgBrJhB45YRdYg q1Ee8WAe5aw65nSmo1CbEPuPs4fvxOOeip/toeFvmLEB1bfW0x4xQ1qsxHJKYCcJyV fxPWG645QbVldwv98mWXpSNcMOlQyw9GUHePFYPW6usOQryRLAiHGETnLCxc9dv9CJ xNwP/o8AS+Cow== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2BA9F68C06; Tue, 30 Dec 2025 13:52:43 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Tue, 30 Dec 2025 13:51:46 -0700 Message-ID: <20251230205157.3383926-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251230205157.3383926-1-sjg@u-boot.org> References: <20251230205157.3383926-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5GYKZKIAMSPN26HYT6WEW3XIQII22JZB X-Message-ID-Hash: 5GYKZKIAMSPN26HYT6WEW3XIQII22JZB X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 09/14] linux: jbd2: Add jbd2_journal_exit_global for clean shutdown List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass In U-Boot, filesystems may be mounted and unmounted multiple times in a single session. The JBD2 global state (caches) was only initialized once and never cleaned up, preventing proper reinitialization. Add jbd2_journal_exit_global() to properly destroy caches and reset the initialization flag. This allows the JBD2 subsystem to be cleanly reinitialized on subsequent mounts. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/jbd2/journal.c | 33 +++++++++++++++++++++++++++++++++ include/linux/jbd2.h | 1 + 2 files changed, 34 insertions(+) diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c index 138b650fae9..f6478c6ca94 100644 --- a/fs/jbd2/journal.c +++ b/fs/jbd2/journal.c @@ -3140,6 +3140,10 @@ static int __init journal_init(void) return ret; } +#ifdef __UBOOT__ +static bool jbd2_initialized; +#endif + /** * jbd2_journal_init_global() - Initialize JBD2 global state * @@ -3150,18 +3154,47 @@ static int __init journal_init(void) */ int jbd2_journal_init_global(void) { +#ifdef __UBOOT__ + if (jbd2_initialized) + return 0; +#else static bool initialized; if (initialized) return 0; +#endif if (journal_init()) return -ENOMEM; +#ifdef __UBOOT__ + jbd2_initialized = true; +#else initialized = true; +#endif return 0; } +#ifdef __UBOOT__ +/** + * jbd2_journal_exit_global() - Clean up JBD2 global state + * + * This should be called when unmounting the last ext4 filesystem to + * properly clean up all JBD2 caches and reset global state. This is + * important in U-Boot where we may mount/unmount filesystems multiple + * times in a single session. + */ +void jbd2_journal_exit_global(void) +{ + if (!jbd2_initialized) + return; + + jbd2_remove_jbd_stats_proc_entry(); + jbd2_journal_destroy_caches(); + jbd2_initialized = false; +} +#endif + static void __exit journal_exit(void) { #ifdef CONFIG_JBD2_DEBUG diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h index 41725fb42af..796d896f70f 100644 --- a/include/linux/jbd2.h +++ b/include/linux/jbd2.h @@ -75,6 +75,7 @@ void __jbd2_debug(int level, const char *file, const char *func, extern void *jbd2_alloc(size_t size, gfp_t flags); extern void jbd2_free(void *ptr, size_t size); extern int jbd2_journal_init_global(void); +extern void jbd2_journal_exit_global(void); #define JBD2_MIN_JOURNAL_BLOCKS 1024 #define JBD2_DEFAULT_FAST_COMMIT_BLOCKS 256