From: Naohiro Aota <naohiro.aota@wdc.com>
To: linux-btrfs@vger.kernel.org
Cc: David Sterba <dsterba@suse.com>, Naohiro Aota <naohiro.aota@wdc.com>
Subject: [PATCH 2/2] btrfs-progs: do not zone reset on emulated zoned mode
Date: Wed, 22 Sep 2021 16:53:43 +0900 [thread overview]
Message-ID: <20210922075343.1160788-3-naohiro.aota@wdc.com> (raw)
In-Reply-To: <20210922075343.1160788-1-naohiro.aota@wdc.com>
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 <naohiro.aota@wdc.com>
---
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);
--
2.33.0
next prev parent reply other threads:[~2021-09-22 7:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-22 7:53 [PATCH 0/2] btrfs-progs: fixes for mkfs.btrfs on file with emulated zones Naohiro Aota
2021-09-22 7:53 ` [PATCH 1/2] btrfs-progs: use btrfs_device_size() instead of device_get_partition_size_fd() Naohiro Aota
2021-09-22 7:53 ` Naohiro Aota [this message]
2021-09-22 19:47 ` [PATCH 0/2] btrfs-progs: fixes for mkfs.btrfs on file with emulated zones David Sterba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210922075343.1160788-3-naohiro.aota@wdc.com \
--to=naohiro.aota@wdc.com \
--cc=dsterba@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).