* [PATCH 0/2] btrfs-progs: fixes for mkfs.btrfs on file with emulated zones
@ 2021-09-22 7:53 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
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Naohiro Aota @ 2021-09-22 7:53 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba, Naohiro Aota
The following two errors occur when mkfs.btrfs is called on a regular file
with emulated zones. These patches address the errors.
ERROR: zoned: failed to read size of /home/naota/tmp/btrfs.img: Inappropriate ioctl for device
ERROR: zoned: failed to reset device '/home/naota/tmp/btrfs.img' zones: Inappropriate ioctl for device
Naohiro Aota (2):
btrfs-progs: use btrfs_device_size() instead of
device_get_partition_size_fd()
btrfs-progs: do not zone reset on emulated zoned mode
common/device-utils.c | 27 +++++++++++++++------------
kernel-shared/zoned.c | 15 ++++++++++-----
kernel-shared/zoned.h | 1 +
3 files changed, 26 insertions(+), 17 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] btrfs-progs: use btrfs_device_size() instead of device_get_partition_size_fd()
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 ` Naohiro Aota
2021-09-22 7:53 ` [PATCH 2/2] btrfs-progs: do not zone reset on emulated zoned mode Naohiro Aota
2021-09-22 19:47 ` [PATCH 0/2] btrfs-progs: fixes for mkfs.btrfs on file with emulated zones David Sterba
2 siblings, 0 replies; 4+ messages in thread
From: Naohiro Aota @ 2021-09-22 7:53 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba, Naohiro Aota
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 <naohiro.aota@wdc.com>
---
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);
--
2.33.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] btrfs-progs: do not zone reset on emulated zoned mode
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
2021-09-22 19:47 ` [PATCH 0/2] btrfs-progs: fixes for mkfs.btrfs on file with emulated zones David Sterba
2 siblings, 0 replies; 4+ messages in thread
From: Naohiro Aota @ 2021-09-22 7:53 UTC (permalink / raw)
To: linux-btrfs; +Cc: David Sterba, Naohiro Aota
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] btrfs-progs: fixes for mkfs.btrfs on file with emulated zones
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 ` [PATCH 2/2] btrfs-progs: do not zone reset on emulated zoned mode Naohiro Aota
@ 2021-09-22 19:47 ` David Sterba
2 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2021-09-22 19:47 UTC (permalink / raw)
To: Naohiro Aota; +Cc: linux-btrfs, David Sterba
On Wed, Sep 22, 2021 at 04:53:41PM +0900, Naohiro Aota wrote:
> The following two errors occur when mkfs.btrfs is called on a regular file
> with emulated zones. These patches address the errors.
>
> ERROR: zoned: failed to read size of /home/naota/tmp/btrfs.img: Inappropriate ioctl for device
>
> ERROR: zoned: failed to reset device '/home/naota/tmp/btrfs.img' zones: Inappropriate ioctl for device
>
> Naohiro Aota (2):
> btrfs-progs: use btrfs_device_size() instead of
> device_get_partition_size_fd()
> btrfs-progs: do not zone reset on emulated zoned mode
Added to devel, thanks.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-22 19:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 2/2] btrfs-progs: do not zone reset on emulated zoned mode Naohiro Aota
2021-09-22 19:47 ` [PATCH 0/2] btrfs-progs: fixes for mkfs.btrfs on file with emulated zones David Sterba
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).