From patchwork Thu Mar 28 07:21:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13608056 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 lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 00A96C54E64 for ; Thu, 28 Mar 2024 07:22:01 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rpk5H-0004C6-0x; Thu, 28 Mar 2024 07:21:59 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rpk5F-0004C0-7m for linux-f2fs-devel@lists.sourceforge.net; Thu, 28 Mar 2024 07:21:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=upgLhKHDEDAb3V+ZFIqdhUsafDs9WmlXkWLPKWUL+98=; b=ab8gn4Xkzs2xPN3jcTTIHYqiHX DnF6Clx+0m3g0bzBdBwElZArHlX2Hw3PhCvx2qn63/RMLlnp5U2FdtmssINl+LWfpBILQGGAl8Dcj npjqQMc81UnF9h5Oi5SyCmVWCLweyauUULqPvmb0kq7coC5snWGHDoaGBGd6w4bRrxUg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=upgLhKHDEDAb3V+ZFIqdhUsafDs9WmlXkWLPKWUL+98=; b=G qi+UPLTSJHnNJuJKRfgo/ITPIUzoIegVyjnfkN3vvM9IkcitEbqoieDAz8MD7fVmiqJ2w14mkfaXy SM54m1idEHnn/Oq0dgvajwqOB2Rg8RpyOPjT8cxLn33xDHt6lUWx3U5HuaN/IJpvCSkGOBEpAKD7w qPy0rsLn/BaDJX0c=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rpk5E-0007eR-JO for linux-f2fs-devel@lists.sourceforge.net; Thu, 28 Mar 2024 07:21:57 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 80FE4616E3; Thu, 28 Mar 2024 07:21:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDBE2C433F1; Thu, 28 Mar 2024 07:21:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711610506; bh=+c2g+QOTgg3995dvAWPf1MaHsDGDdMPE+6RXTZkhIfU=; h=From:To:Cc:Subject:Date:From; b=lifRrg5QafFFOULEjnABkBHqjSe3HGSscym8oS9j8noUEpXmokgf5nu5DkPvMfv1e KnSKru2ZKysI2Td1Zlj9qUtsow7d/Qtd0JD1/Idy8JteuuLfdR4TrTNCM5OAaZ8Qsa 8nh6NGByrO7433qrcNrszUCD/6GZ84aeJwlaIEy3VlaN3BSOGh5xwxmLLm4cUgEZN3 nLEik4Ll6Nn9ZyKPipX4MvpUyRBHHNRG9kmlpYc64k0fI0rC+BvuR6i8N+ZVUvJASQ XeAOB5QOFiTsFxLdrecXzj5ijVMNnGtm+6bqqFwroDqo6BcHLV6Z5qCiutJAdKjk0g 0BWix70blxtgA== From: Chao Yu To: jaegeuk@kernel.org Date: Thu, 28 Mar 2024 15:21:36 +0800 Message-Id: <20240328072136.3023135-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Headers-End: 1rpk5E-0007eR-JO Subject: [f2fs-dev] [PATCH v6] f2fs: fix zoned block device information initialization X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Wenjie Qi , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Wenjie Qi If the max open zones of zoned devices are less than the active logs of F2FS, the device may error due to insufficient zone resources when multiple active logs are being written at the same time. Signed-off-by: Wenjie Qi Signed-off-by: Chao Yu --- v6: - add check condition to avoid remount failure. fs/f2fs/f2fs.h | 1 + fs/f2fs/super.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 0550929dc6e5..694f8a52cb84 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1559,6 +1559,7 @@ struct f2fs_sb_info { #ifdef CONFIG_BLK_DEV_ZONED unsigned int blocks_per_blkz; /* F2FS blocks per zone */ + unsigned int max_open_zones; /* max open zone resources of the zoned device */ #endif /* for node-related operations */ diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 7c45929671ad..642540782471 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2326,6 +2326,17 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data) if (err) goto restore_opts; +#ifdef CONFIG_BLK_DEV_ZONED + if (f2fs_is_multi_device(sbi) && + sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) { + f2fs_err(sbi, + "zoned: max open zones %u is too small, need at least %u open zones", + sbi->max_open_zones, F2FS_OPTION(sbi).active_logs); + err = -EINVAL; + goto restore_opts; + } +#endif + /* flush outstanding errors before changing fs state */ flush_work(&sbi->s_error_work); @@ -3868,11 +3879,24 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) sector_t nr_sectors = bdev_nr_sectors(bdev); struct f2fs_report_zones_args rep_zone_arg; u64 zone_sectors; + unsigned int max_open_zones; int ret; if (!f2fs_sb_has_blkzoned(sbi)) return 0; + if (bdev_is_zoned(FDEV(devi).bdev)) { + max_open_zones = bdev_max_open_zones(bdev); + if (max_open_zones && (max_open_zones < sbi->max_open_zones)) + sbi->max_open_zones = max_open_zones; + if (sbi->max_open_zones < F2FS_OPTION(sbi).active_logs) { + f2fs_err(sbi, + "zoned: max open zones %u is too small, need at least %u open zones", + sbi->max_open_zones, F2FS_OPTION(sbi).active_logs); + return -EINVAL; + } + } + zone_sectors = bdev_zone_sectors(bdev); if (sbi->blocks_per_blkz && sbi->blocks_per_blkz != SECTOR_TO_BLOCK(zone_sectors)) @@ -4186,6 +4210,9 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi) logical_blksize = bdev_logical_block_size(sbi->sb->s_bdev); sbi->aligned_blksize = true; +#ifdef CONFIG_BLK_DEV_ZONED + sbi->max_open_zones = UINT_MAX; +#endif for (i = 0; i < max_devices; i++) { if (i == 0)