From mboxrd@z Thu Jan 1 00:00:00 1970 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 8AF16C433EF for ; Wed, 13 Apr 2022 12:29:59 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nec8D-0000CM-84; Wed, 13 Apr 2022 12:29:56 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nec8B-0000C6-9R for linux-f2fs-devel@lists.sourceforge.net; Wed, 13 Apr 2022 12:29:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=References:Content-Type:Content-Transfer-Encoding: MIME-Version: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:In-Reply-To:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8tceLpQCZY8XtXPcoFL1bD1vU5G4FDe/1Ig7REroJXA=; b=G+doMGg+zGbnJRTh60QA+ZvCGn JbuYMXkrXFWyVEtWShgzuaL/8oDQz/+jT9ErjwT7nNXz0QR63uH6H4MtRMJ+/2/5FyEzzDMbj8Jv/ 1E+KbqOk+n1TpRSmN1zm7REZNSbrqF6LQx1keUZgRQf5oh6b8n3GgZk0bfCwKoMtY9uM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=References:Content-Type:Content-Transfer-Encoding:MIME-Version: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: In-Reply-To:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=8tceLpQCZY8XtXPcoFL1bD1vU5G4FDe/1Ig7REroJXA=; b=V XIp4NctsA6/yxFgEFwvdVIhBKnMaemNRJc3UN+0Ib6Rcd+OUnT84aR4LUzCYib4dk/JBJvDpwQnaC TL8RCdPRS8x0abVTkGaVIsOvlL5BWHDqWwGPRzTcTV3sr1t1xQW7QaBE3i5EEKvz4hJHbVMlxQvUY qTyhoJi3Uz9ZFVo0=; Received: from mailout2.w1.samsung.com ([210.118.77.12]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1nec88-0000kg-25 for linux-f2fs-devel@lists.sourceforge.net; Wed, 13 Apr 2022 12:29:54 +0000 Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20220413122942euoutp0202a4a74eda647f885832b33b98636e5a~ldIvZntgu0776207762euoutp02h for ; Wed, 13 Apr 2022 12:29:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20220413122942euoutp0202a4a74eda647f885832b33b98636e5a~ldIvZntgu0776207762euoutp02h DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1649852982; bh=8tceLpQCZY8XtXPcoFL1bD1vU5G4FDe/1Ig7REroJXA=; h=From:To:Cc:Subject:Date:References:From; b=YnB2ER6IraJk9D5LhxymTG4ZpayYBMdrOi/ABiRElYyHZn9V++m1zUB9qOusHreJz fUQzYX4etkc5EA/AEXfJTQXzrydy0aB1gfQXMRYzD55HEcfiEP1PulNda8T+RWdkK4 Jhbk/zunmYomz59sg8qA2Q580N7SMZL3KgHlEdlk= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20220413122941eucas1p18ae16aaaf33eddc1590815e70278057c~ldIuy-4to1480414804eucas1p1A; Wed, 13 Apr 2022 12:29:41 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id FB.FF.10260.532C6526; Wed, 13 Apr 2022 13:29:41 +0100 (BST) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20220413122941eucas1p1ec05e8e8dfe2baf451fcb549d60fda35~ldIuT-wvG1000610006eucas1p1v; Wed, 13 Apr 2022 12:29:41 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20220413122941eusmtrp24d0a4f8986c1443744045953cd30cec3~ldIuTJ9U10748907489eusmtrp2w; Wed, 13 Apr 2022 12:29:41 +0000 (GMT) X-AuditID: cbfec7f5-bf3ff70000002814-8e-6256c23576a0 Received: from eusmtip1.samsung.com ( [203.254.199.221]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id A9.FD.09522.532C6526; Wed, 13 Apr 2022 13:29:41 +0100 (BST) Received: from localhost (unknown [106.210.248.178]) by eusmtip1.samsung.com (KnoxPortal) with ESMTPA id 20220413122940eusmtip173c8d6a57ad0f4a2856b8f0f3677a438~ldIt-82rA1762317623eusmtip1j; Wed, 13 Apr 2022 12:29:40 +0000 (GMT) From: Pankaj Raghav To: linux-f2fs-devel@lists.sourceforge.net Date: Wed, 13 Apr 2022 14:29:40 +0200 Message-Id: <20220413122940.133981-1-p.raghav@samsung.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAA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e2baf451fcb549d60fda35 X-Msg-Generator: CA X-RootMTR: 20220413122941eucas1p1ec05e8e8dfe2baf451fcb549d60fda35 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20220413122941eucas1p1ec05e8e8dfe2baf451fcb549d60fda35 References: X-Headers-End: 1nec88-0000kg-25 Subject: [f2fs-dev] [PATCH v2] libf2fs: don't allow mkfs / fsck on non power-of-2 zoned devices 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: Pankaj Raghav , Damien.LeMoal@wdc.com, pankydev8@gmail.com, mcgrof@kernel.org, javier.gonz@samsung.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Luis Chamberlain f2fs currently only work with zoned storage devices with a zone size which is a power of 2 (PO2). So check if a non-power of 2 zoned device is found, and if so disallow its use. This prevents users from incorrectly using these devices. This is a non-issue today given today's kernel does not allow NPO2 zoned devices to exist as a block device. But NPO2 zoned devices do exist so proactively put a stop-gap measure in place to prevent it from being incorrectly used. Signed-off-by: Luis Chamberlain Signed-off-by: Pankaj Raghav --- Changes since v1: - Squash the commits for clarity (Damien) - f2fs_get_zone_chunk_sectors can return uint32_t (Damien) - Include the units for zone size in msg info (Damien) - Sections can be npo2 but it should only be a multiple of 2MB (Jaegeuk) include/f2fs_fs.h | 1 + lib/libf2fs.c | 17 +++++++++++++++-- lib/libf2fs_zoned.c | 34 ++++++++++++++++++++++------------ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index d236437..83c5b33 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -386,6 +386,7 @@ struct device_info { u_int32_t nr_zones; u_int32_t nr_rnd_zones; size_t zone_blocks; + uint64_t zone_size; size_t *zone_cap_blocks; }; diff --git a/lib/libf2fs.c b/lib/libf2fs.c index 420dfda..8104667 100644 --- a/lib/libf2fs.c +++ b/lib/libf2fs.c @@ -882,6 +882,11 @@ static int open_check_fs(char *path, int flag) return open(path, O_RDONLY | flag); } +static int is_power_of_2(unsigned long n) +{ + return (n != 0 && ((n & (n - 1)) == 0)); +} + int get_device_info(int i) { int32_t fd = 0; @@ -1043,6 +1048,13 @@ int get_device_info(int i) return -1; } + if (!is_power_of_2(dev->zone_size)) { + MSG(0, "\tError: zoned: illegal zone size %lu (not a power of 2)\n", + dev->zone_size); + free(stat_buf); + return -1; + } + /* * Check zone configuration: for the first disk of a * multi-device volume, conventional zones are needed. @@ -1055,8 +1067,9 @@ int get_device_info(int i) MSG(0, "Info: Host-%s zoned block device:\n", (dev->zoned_model == F2FS_ZONED_HA) ? "aware" : "managed"); - MSG(0, " %u zones, %u randomly writeable zones\n", - dev->nr_zones, dev->nr_rnd_zones); + MSG(0, " %u zones, %lu zone size(bytes), %u randomly writeable zones\n", + dev->nr_zones, dev->zone_size, + dev->nr_rnd_zones); MSG(0, " %lu blocks per zone\n", dev->zone_blocks); } diff --git a/lib/libf2fs_zoned.c b/lib/libf2fs_zoned.c index ce73b9a..48a23c0 100644 --- a/lib/libf2fs_zoned.c +++ b/lib/libf2fs_zoned.c @@ -146,40 +146,50 @@ int f2fs_get_zoned_model(int i) return 0; } -int f2fs_get_zone_blocks(int i) +uint32_t f2fs_get_zone_chunk_sectors(struct device_info *dev) { - struct device_info *dev = c.devices + i; - uint64_t sectors; + uint32_t sectors; char str[PATH_MAX]; FILE *file; int res; - /* Get zone size */ - dev->zone_blocks = 0; - res = get_sysfs_path(dev, "queue/chunk_sectors", str, sizeof(str)); if (res != 0) { MSG(0, "\tError: Failed to get device sysfs attribute path\n"); - return -1; + return 0; } file = fopen(str, "r"); if (!file) - return -1; + return 0; memset(str, 0, sizeof(str)); res = fscanf(file, "%s", str); fclose(file); if (res != 1) - return -1; + return 0; - sectors = atol(str); + sectors = atoi(str); + + return sectors; +} + +int f2fs_get_zone_blocks(int i) +{ + struct device_info *dev = c.devices + i; + uint64_t sectors; + + /* Get zone size */ + dev->zone_blocks = 0; + + sectors = f2fs_get_zone_chunk_sectors(dev); if (!sectors) return -1; - dev->zone_blocks = sectors >> (F2FS_BLKSIZE_BITS - 9); - sectors = (sectors << 9) / c.sector_size; + dev->zone_size = sectors << SECTOR_SHIFT; + dev->zone_blocks = sectors >> (F2FS_BLKSIZE_BITS - SECTOR_SHIFT); + sectors = dev->zone_size / c.sector_size; /* * Total number of zones: there may -- 2.25.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel