From patchwork Sat Apr 11 00:36:36 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2159 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=1775867831; bh=oclxdzzI7s9gpMzmoeF7J0UmjBLoA0N3iICxjrOf1pw=; 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=hcm9yOEK1pV0iYJyVfCynyBJepUVWOL9w99D9fDfwXz1q3HWdsAL9d+ZYTfZd2ZG0 Cpvgk4JttCEsa+u/8PjmO6KSTuDBf3h/V0+EtKk1QMXp9fdEukXHs0axLLVHmGuQnm yc9ZkDQQM4UHHRIbwszMmLwG4GvH8+JhC6LfKnA0I22KYBpJ+o4etBO1dW0Po19X+c VjMqj3J1sUrjeMuCz6qN0InjaitOLD8UM2UJi0/FufUDmZNa+TjZ/y6RkHcKihNXrm CfXofJY5nGHEU6Olc/moKR6qYRnrHzWXaXqzBNX//11d3iIBtcmJUmyxd6n5pkcc0K +lS+Wlb/3JhZw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 38AB36A438 for ; Fri, 10 Apr 2026 18:37:11 -0600 (MDT) 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 ycE9AHAdLuJA for ; Fri, 10 Apr 2026 18:37:11 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775867829; bh=oclxdzzI7s9gpMzmoeF7J0UmjBLoA0N3iICxjrOf1pw=; 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=RYLdPFYXJxTzu7sG7bzmnRjERXbvAHnXzQLPDKV7OpTA5y1F02ipfoYp60UHFHNUl AxHi80yScMZ6u25pQRsMzMK5Os2wW/MnsJ/bGPhUFyJuetPC+DR4z6fgyogFG+5BP8 aiiH/xlCDfvgr0qSpveq05kkj8kzk3LoMtrOi8aUZKwy6A0SNioPf2s4Es6krkoivH kbad41EPunaOc29bfC/o9bPKSUPYp4ZCI1JIOUftpaVe++Bf5EAc4w8hWeLQcaTjqZ S40qxtaedEtFvTER3xintJzyXug5eOIevnvpSlQ+2d5PyBT+M6l8lOzCK4I0sEzspm fAbQUBpPU/Xtw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A44D76A439 for ; Fri, 10 Apr 2026 18:37:09 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775867825; bh=FT4IXqpKNcg5rNAqCRmsCo3Ocis9cMGpRKFUxuW3Lxs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D4cew0zuKi+iFfeNomq2yQ/0KajXqwmjamFLOHwZxos08paNw0BySqWnZAxzFCfqs vX2UDDOyfzmNkChxZiw1QsTQXYvP4ZydUVMWWA9oyC/UO1/gNjWxOCjuOdJwiQI1bM VovM9DA/OMiNoTa2hWQwj+5og65t6fFMRkZUuh2d50EpetoaB25sS/OL/QJMwFRnzd +CoC4YDADF6iMpbNEr8F5bBfh5e7r0Nbxp2hztF+cfXy9D9zJax/YigeJG6oKXbY9L PiUsNtnBPLHNRoawzb8Kyw47lWB9fWqxqpyhjE4cBx3DDK2CILB9LBu8U2ceL86LTP xkj+6jSb8u2KQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 9C5866A42C; Fri, 10 Apr 2026 18:37:05 -0600 (MDT) 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 3Cy5oA4GD0GD; Fri, 10 Apr 2026 18:37:05 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1775867824; bh=9ZYzvAa90/Ur3jWW+AMJlieF2uYeZEScORn3Oeo8Vv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nYhYiov5wNIne0EAcTjYVFzEC554tJSDiJBCVGy02SjlhFATMdBQju2AYZcn6Cge2 6BjeLie/oqpWKBi2B1OiVbFcCYeywWK4hRY7cDxq/DV58Gq/tPu19Bi0hz/s9vrkUH UbN/LB+REWHjqpQ6dxsTS6rCd0/gSY4hbk5al/rvS8o5Ntf7jzWllT7SzcU9InFM90 p15adDU+/8GW9fcZR+ttZb9z+XmFmuVRTBfKB24/OxCSdskfpWg2FC48VYh115gMAZ T6bN28KxSQp3kk/lbCy90qep6d5z8kitXczQbLp3N84kyrE8oMhbPZP7kf6+jLeQlL Bg/b/F06vlqrg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 12FF36A3B8; Fri, 10 Apr 2026 18:37:04 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Fri, 10 Apr 2026 18:36:36 -0600 Message-ID: <20260411003647.2592586-5-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260411003647.2592586-1-sjg@u-boot.org> References: <20260411003647.2592586-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: LLJTTAOELZGAVHKRVIBCQSGBOBX2BB6K X-Message-ID-Hash: LLJTTAOELZGAVHKRVIBCQSGBOBX2BB6K 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 X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 4/8] ext4l: Rename ext4l_probe() to ext4l_mount() 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 The name ext4l_probe() comes from the legacy filesystem interface where each operation re-mounts the filesystem. Rename the internal function to ext4l_mount() which better describes what it does. ext4l_mount() takes a struct ext4l_state pointer and a struct udevice so the caller can provide per-mount state and a proper block device. It zeroes the state at entry so callers do not need to pre-initialise it. The legacy ext4l_probe() wrapper allocates the global state, handles auto-unmount of any previous mount, and converts blk_desc to udevice before calling ext4l_mount() Also handle unmount in the same way. Signed-off-by: Simon Glass --- fs/ext4l/interface.c | 77 ++++++++++++++++++++++++++------------------ include/ext4l.h | 24 ++++++++++++-- 2 files changed, 67 insertions(+), 34 deletions(-) diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index 7cc739042eb..5a7d65fafdc 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -108,15 +109,14 @@ int ext4l_statfs(struct fs_statfs *stats) } /** - * ext4l_set_blk_dev() - Set the block device for ext4l operations + * ext4l_set_blk() - Set the block device for ext4l operations * - * @blk_dev: Block device descriptor + * @blk: Block device descriptor * @partition: Partition info (can be NULL for whole disk) */ -void ext4l_set_blk_dev(struct udevice *blk_dev, - struct disk_partition *partition) +void ext4l_set_blk(struct udevice *blk, struct disk_partition *partition) { - efs.blk = blk_dev; + efs.blk = blk; if (partition) memcpy(&efs.partition, partition, sizeof(efs.partition)); else @@ -125,9 +125,9 @@ void ext4l_set_blk_dev(struct udevice *blk_dev, } /** - * ext4l_clear_blk_dev() - Clear block device (unmount) + * ext4l_clear_blk() - Clear block device (unmount) */ -void ext4l_clear_blk_dev(void) +void ext4l_clear_blk(void) { /* Clear buffer cache before unmounting */ bh_cache_clear(); @@ -207,31 +207,32 @@ static void ext4l_free_sb(struct super_block *sb, bool skip_io) kfree(sbi->s_blockgroup_lock); kfree(sbi); - /* Free structures allocated in ext4l_probe() */ + /* Free structures allocated in ext4l_mount() */ kfree(sb->s_bdev->bd_mapping); kfree(sb->s_bdev); kfree(sb); } /** - * ext4l_close_internal() - Internal close function + * ext4l_umount_internal() - Internal close function + * @state: Per-mount state to initialise * @skip_io: If true, skip all I/O operations (for forced close) * - * When called from the safeguard in ext4l_probe(), the device may be + * When called from the safeguard in ext4l_mount(), the device may be * invalid (rebound to a different file), so skip_io should be true to * avoid crashes when trying to write to the device. */ -static void ext4l_close_internal(bool skip_io) +static void ext4l_umount_internal(struct ext4l_state *state, bool skip_io) { - struct super_block *sb = efs.sb; + struct super_block *sb = state->sb; - if (efs.open_dirs > 0) + if (state->open_dirs > 0) return; if (sb) ext4l_free_sb(sb, skip_io); - efs.sb = NULL; + state->sb = NULL; /* * Force cleanup of any remaining journal_heads before clearing @@ -242,7 +243,7 @@ static void ext4l_close_internal(bool skip_io) */ bh_cache_release_jbd(); - ext4l_clear_blk_dev(); + ext4l_clear_blk(); /* * Clean up ext4 and JBD2 global state so it can be properly @@ -263,9 +264,10 @@ static void ext4l_close_internal(bool skip_io) destroy_inodecache(); } -int ext4l_probe(struct blk_desc *fs_dev_desc, +int ext4l_mount(struct ext4l_state *state, struct udevice *dev, struct disk_partition *fs_partition) { + struct blk_desc *fs_dev_desc = dev_get_uclass_plat(dev); struct ext4_fs_context *ctx; struct super_block *sb; struct fs_context *fc; @@ -274,19 +276,10 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, u8 *buf; int ret; - if (!fs_dev_desc) - return -EINVAL; + memset(state, '\0', sizeof(*state)); - /* - * Ensure any previous mount is properly closed before mounting again. - * This prevents resource leaks if probe is called without close. - * - * Since we're being called while a previous mount exists, we can't - * trust the old device state (it may have been rebound to a different - * file). Use skip_io=true to skip all I/O during close. - */ - if (efs.sb) - ext4l_close_internal(true); + if (!dev) + return -EINVAL; /* Initialise message buffer for recording ext4 messages */ ext4l_msg_init(); @@ -393,7 +386,7 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, } /* Set block device for buffer I/O */ - ext4l_set_blk_dev(fs_dev_desc->bdev, fs_partition); + ext4l_set_blk(dev, fs_partition); /* * Test if device supports writes by writing back the same data. @@ -415,7 +408,7 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, } /* Store super_block for later operations */ - efs.sb = sb; + state->sb = sb; /* Free mount context - no longer needed after successful mount */ kfree(ctx); @@ -444,6 +437,23 @@ err_exit_es: return ret; } +int ext4l_probe(struct blk_desc *fs_dev_desc, + struct disk_partition *fs_partition) +{ + if (!fs_dev_desc) + return -EINVAL; + + /* + * The legacy interface may call probe without a preceding close. + * Clean up any previous mount to prevent resource leaks. Use + * skip_io=true because the old device may have been rebound. + */ + if (efs.sb) + ext4l_umount_internal(&efs, true); + + return ext4l_mount(&efs, fs_dev_desc->bdev, fs_partition); +} + /** * ext4l_read_symlink() - Read the target of a symlink inode * @@ -1347,9 +1357,14 @@ out_old: return ret; } +void ext4l_umount(struct ext4l_state *state) +{ + ext4l_umount_internal(state, false); +} + void ext4l_close(void) { - ext4l_close_internal(false); + ext4l_umount(&efs); } /** diff --git a/include/ext4l.h b/include/ext4l.h index 19fbe8a7fa2..5ef1cc0a30f 100644 --- a/include/ext4l.h +++ b/include/ext4l.h @@ -43,18 +43,36 @@ struct ext4l_state { #endif /** - * ext4l_probe() - Probe a block device for an ext4 filesystem + * ext4l_mount() - Mount an ext4 filesystem * - * @fs_dev_desc: Block device descriptor + * @state: Per-mount state to initialise + * @dev: Block device (struct udevice) * @fs_partition: Partition information * Return: 0 on success, -EINVAL if no device or invalid magic, * -ENOMEM on allocation failure, -EIO on read error */ +int ext4l_mount(struct ext4l_state *state, struct udevice *dev, + struct disk_partition *fs_partition); + +/** + * ext4l_probe() - Legacy probe: mount using the global state + * + * @fs_dev_desc: Block device descriptor + * @fs_partition: Partition information + * Return: 0 on success, negative on error + */ int ext4l_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition); /** - * ext4l_close() - Close the ext4 filesystem + * ext4l_umount() - Unmount an ext4 filesystem + * + * @state: Per-mount state to tear down + */ +void ext4l_umount(struct ext4l_state *state); + +/** + * ext4l_close() - Legacy close: unmount using the global state */ void ext4l_close(void);