From patchwork Wed Sep 22 07:53:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12509665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FC50C433EF for ; Wed, 22 Sep 2021 07:53:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 18E2560FA0 for ; Wed, 22 Sep 2021 07:53:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233379AbhIVHzT (ORCPT ); Wed, 22 Sep 2021 03:55:19 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:54798 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233283AbhIVHzS (ORCPT ); Wed, 22 Sep 2021 03:55:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1632297229; x=1663833229; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vnzCEkEsSr0wReGEZPQDyGtL670wd61z70BeguuQ/qU=; b=dIFoCYHha9dCefyYpdlusAYUvuo5sQXKk6vx/igoaKeQvnKcbNC1Amtq D16BRoiQvMa/RQMVDELY+D53knRCrgkfs0DUV02oLiPmAfRWlHD/YIuyF ytRrYqWViqbwgbPWgBkdFgT00PSUQI5Be6PHxqDz2TieFhc/JQF73Dud/ Pk7gjiPbp5ECdOJcxaAZyvPYNo7WsoUC8kti49yXQSSzFVI4N72btfKcB XgjGEf08x/5R0pCjbpa30MocEBI4Ww0p5l0TxjsQ+zq1KElo5NQIEytZg 8cs+knuXuH2ixx3b5PbvOJhtISV7VNgehO+ATRhr/hp3wyNVmEQC7Ycg8 w==; X-IronPort-AV: E=Sophos;i="5.85,313,1624291200"; d="scan'208";a="284429249" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Sep 2021 15:53:49 +0800 IronPort-SDR: XAf1VCD+N8k/V8bWU7rrkJqLNB4imtvRlY387MU0AcIFCJlH3V4Xt476lc3NUwMaRoTsHDeaan +5QneZDsGm6XbZpqO8ODNMKYiPs2ucAcCn2+xmy9xNdFZ1UgrzYW7XthNtVuHYTHOy9Kwv7A31 5alvKwhE1p3Aw+BRKDqoQjGsR44XtcSMoX0xxVUassgLufhH7Krn3kRURM0ldEKWdBHTcnwp1Y MwW1UbFRZLWuy1vlCMmHG/z3O6+QV1/iBMnnuKhLAlURz+PH8jrshGSG5ewLBhNI00Flv3YfNj wJRavaIgJ4OCifDAIIwYSLST Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 00:30:02 -0700 IronPort-SDR: jMsrPtQOFJ5Dgm+zUQRM+5MrRuExRoj3yoXU336kDKy+fF/gklpoLv0ugaGVclDt4ypt2q/6qm jWccEBb/VeSfVYt52UzltEeLjjTfae5KQoUKHHtltakInW5zQdYQ8dJLLrmBZAROmic0MJ5W9U HiCoRHJyjVz/q7knS4smEMkGCjU4h7KzarcU+X0uiUIU+0B5hjcobdbz8MY+hEDPOmFgDxlhyJ cMecAHBJv4CSRxyGAAN84G4I8S5Ic2LyDw+EygNIsjOoURow5+93nHJqDnQuHURUXThblfTaxY 1Rs= WDCIronportException: Internal Received: from wdmnc1780.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.67]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Sep 2021 00:53:49 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: David Sterba , Naohiro Aota Subject: [PATCH 1/2] btrfs-progs: use btrfs_device_size() instead of device_get_partition_size_fd() Date: Wed, 22 Sep 2021 16:53:42 +0900 Message-Id: <20210922075343.1160788-2-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922075343.1160788-1-naohiro.aota@wdc.com> References: <20210922075343.1160788-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org device_get_partition_size_fd() fails if we pass a regular file. This can happen when trying to create an emualted zoned btrfs on a regular file. Signed-off-by: Naohiro Aota --- kernel-shared/zoned.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 75c6c53393ac..891a2c0aeef2 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -267,6 +267,7 @@ static int report_zones(int fd, const char *file, u64 zone_bytes = zone_size(file); size_t rep_size; u64 sector = 0; + struct stat st; struct blk_zone_report *rep; struct blk_zone *zone; unsigned int i, n = 0; @@ -291,11 +292,13 @@ static int report_zones(int fd, const char *file, exit(1); } - /* - * No need to use btrfs_device_size() here, since it is ensured - * that the file is block device. - */ - device_size = device_get_partition_size_fd(fd); + ret = fstat(fd, &st); + if (ret < 0) { + error("unable to stat %s: %m", file); + return -EIO; + } + + device_size = btrfs_device_size(fd, &st); if (device_size == 0) { error("zoned: failed to read size of %s: %m", file); exit(1); From patchwork Wed Sep 22 07:53:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 12509667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78E87C433F5 for ; Wed, 22 Sep 2021 07:53:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 575DB60FA0 for ; Wed, 22 Sep 2021 07:53:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233383AbhIVHzU (ORCPT ); Wed, 22 Sep 2021 03:55:20 -0400 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:54798 "EHLO esa2.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233283AbhIVHzU (ORCPT ); Wed, 22 Sep 2021 03:55:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1632297230; x=1663833230; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TiKJpGwl5tEO1GdcALlNNYNHHQigIGjUs8ahYMTJGP0=; b=pVPl76AK0jxd5KTz43F4nuuyGQRE+l7FAKIqN3wbHjiM2vn9JvnsJtif hXPgFYV0CpFd7CSyzOSLL58hfMqmcWmELEQWhZGUfkmzG+XEz/9jtKe89 0+Il7p5hc0j+pDktupb3sWPYQcLBHLrx/AQZ4d7b1Y1ugm4IIhb9EXFIg ji96D9ntCIwKr7vMEArPojRGzPDyLCl17bAutsLSdpYPkrfGnR/xfC33x z3C13DEFWfM/rxGizlILofzBa11fEewZMED21TG+j8YIBJaCuF/dEISRq d41x4NQcOUSP1BXgjj17mkbc1UwZODj8sdz746+91o0/CcOU3qI9GxK8k w==; X-IronPort-AV: E=Sophos;i="5.85,313,1624291200"; d="scan'208";a="284429250" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 22 Sep 2021 15:53:50 +0800 IronPort-SDR: 3c/hdGHMOdrQLs6gpHr1fMPFjTh2GrvysbZxb91LU/0ObQVn2oAuXYyjNE+p2jvBESKFOwtuRV nF2xvmp13YDsRyUuZUIbV0P66hfd44a1jEUef0BPFaLj2y5F0srgk8LoCOIGRLhSitMVDhV5sw CDgA6cjj+DQ/WAFKmd0UMMdv/rClNtRuzSz3kFAbwy6J5DlFqF4j5Ui8I4O8dYzRHpDoEhTofy xB0OZIxifj7Ya0qqzhAzV0KgywWZacopLk9RT8z32qUYAcHZnquvrqXQc7exmMIOZHdsymwstJ /1ReSYQ4TaS81ksW4KCGBSQi Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2021 00:30:03 -0700 IronPort-SDR: x189Hsji2DcnU0ad0K1HySvwu3lRu0lfEXoezTlO+ad5wMc2s5DTpW6EwAWNgxEmLnykz6p4ET ZmV4/jHaDjNlJ++u3eFUdcE/cGuLF5GkQFIaiwW3zhcy8A7ebyz4zwBLW5M+iwbHDWDNaZENMh JkCHOVUxOiaLgZ3npOqlvY2XBHaCJ7fwZUioLRBQzTGAw372iV7bAACM7/PjrPy4ZdMKTgZk4G JbHEFbBMQNlpePhhE635/aXzlSc5tMGeiW/dlkh/mrHxaHJKHPPwG7ALluaMTmek1IQ4i2T79W tK8= WDCIronportException: Internal Received: from wdmnc1780.ad.shared (HELO naota-xeon.wdc.com) ([10.225.52.67]) by uls-op-cesaip02.wdc.com with ESMTP; 22 Sep 2021 00:53:50 -0700 From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: David Sterba , Naohiro Aota Subject: [PATCH 2/2] btrfs-progs: do not zone reset on emulated zoned mode Date: Wed, 22 Sep 2021 16:53:43 +0900 Message-Id: <20210922075343.1160788-3-naohiro.aota@wdc.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210922075343.1160788-1-naohiro.aota@wdc.com> References: <20210922075343.1160788-1-naohiro.aota@wdc.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We cannot zone reset a regular file with emulated zones. So, mkfs.btrfs on such a file cause a following error. ERROR: zoned: failed to reset device '/home/naota/tmp/btrfs.img' zones: Inappropriate ioctl for device Intorduce btrfs_zoned_device_info->emulated to distinguish the zones are emulated or not. And, use it to decide it needs zone reset or not. Signed-off-by: Naohiro Aota --- common/device-utils.c | 27 +++++++++++++++------------ kernel-shared/zoned.c | 2 ++ kernel-shared/zoned.h | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/common/device-utils.c b/common/device-utils.c index 1c853545c6ad..503705c43754 100644 --- a/common/device-utils.c +++ b/common/device-utils.c @@ -220,18 +220,21 @@ int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret, file); return 1; } - if (opflags & PREP_DEVICE_VERBOSE) - printf("Resetting device zones %s (%u zones) ...\n", - file, zinfo->nr_zones); - /* - * We cannot ignore zone reset errors for a zoned block - * device as this could result in the inability to write to - * non-empty sequential zones of the device. - */ - if (btrfs_reset_all_zones(fd, zinfo)) { - error("zoned: failed to reset device '%s' zones: %m", - file); - goto err; + + if (!zinfo->emulated) { + if (opflags & PREP_DEVICE_VERBOSE) + printf("Resetting device zones %s (%u zones) ...\n", + file, zinfo->nr_zones); + /* + * We cannot ignore zone reset errors for a zoned block + * device as this could result in the inability to write + * to non-empty sequential zones of the device. + */ + if (btrfs_reset_all_zones(fd, zinfo)) { + error("zoned: failed to reset device '%s' zones: %m", + file); + goto err; + } } } else if (opflags & PREP_DEVICE_DISCARD) { /* diff --git a/kernel-shared/zoned.c b/kernel-shared/zoned.c index 891a2c0aeef2..6e46354b8b52 100644 --- a/kernel-shared/zoned.c +++ b/kernel-shared/zoned.c @@ -346,6 +346,7 @@ static int report_zones(int fd, const char *file, error("zoned: ioctl BLKREPORTZONE failed (%m)"); exit(1); } + zinfo->emulated = false; } else { ret = emulate_report_zones(file, fd, sector << SECTOR_SHIFT, @@ -354,6 +355,7 @@ static int report_zones(int fd, const char *file, error("zoned: failed to emulate BLKREPORTZONE"); exit(1); } + zinfo->emulated = true; } if (!rep->nr_zones) diff --git a/kernel-shared/zoned.h b/kernel-shared/zoned.h index 99f8e9a2faac..66cf081b84c3 100644 --- a/kernel-shared/zoned.h +++ b/kernel-shared/zoned.h @@ -54,6 +54,7 @@ struct btrfs_zoned_device_info { u64 max_zone_append_size; u32 nr_zones; struct blk_zone *zones; + bool emulated; }; enum btrfs_zoned_model zoned_model(const char *file);