From: Hans Holmberg <hans.holmberg@wdc.com>
To: Karel Zak <kzak@redhat.com>
Cc: Damien Le Moal <damien.lemoal@wdc.com>,
Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>,
Matias Bjorling <matias.bjorling@wdc.com>,
util-linux@vger.kernel.org, Hans Holmberg <hans.holmberg@wdc.com>
Subject: [PATCH] blkzone: add report capacity command
Date: Fri, 11 Sep 2020 10:47:23 +0200 [thread overview]
Message-ID: <20200911084723.14996-1-hans.holmberg@wdc.com> (raw)
Add a command that answers the the question:
"How much data can I store on this device/in this range of zones?"
Implement this by summing up zone capacities over the given range.
Signed-off-by: Hans Holmberg <hans.holmberg@wdc.com>
---
As commands like blockdev --getsize and lsblk returns the size
of the entire address space, it is useful to provide users with a command
that calculates the actual storage capacity in that address space
for zoned block devices.
sys-utils/blkzone.8 | 7 +++++++
sys-utils/blkzone.c | 28 ++++++++++++++++++++--------
2 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/sys-utils/blkzone.8 b/sys-utils/blkzone.8
index 043bc96e23ac..958677e1bffa 100644
--- a/sys-utils/blkzone.8
+++ b/sys-utils/blkzone.8
@@ -52,6 +52,13 @@ ro:Read only
x?:Reserved conditions (should not be reported)
.TE
+.SS capacity
+The command \fBblkzone capacity\fP is used to report device capacity information.
+.PP
+By default, the command will report the sum, in number of sectors, of all
+zone capacities on the device. Options may be used to modify this behavior,
+changing the starting zone or the size of the report, as explained below.
+
.SS reset
The command \fBblkzone reset\fP is used to reset one or more zones. Unlike
.BR sg_reset_wp (8),
diff --git a/sys-utils/blkzone.c b/sys-utils/blkzone.c
index 67eaf1a02430..c416e0711fc3 100644
--- a/sys-utils/blkzone.c
+++ b/sys-utils/blkzone.c
@@ -91,6 +91,10 @@ static const struct blkzone_command commands[] = {
.name = "report",
.handler = blkzone_report,
.help = N_("Report zone information about the given device")
+ },{
+ .name = "capacity",
+ .handler = blkzone_report,
+ .help = N_("Report sum of zone capacities for the given device")
},{
.name = "reset",
.handler = blkzone_action,
@@ -224,6 +228,8 @@ static const char *condition_str[] = {
static int blkzone_report(struct blkzone_control *ctl)
{
+ bool only_capacity_sum = !strcmp(ctl->command->name, "capacity");
+ uint64_t capacity_sum = 0;
struct blk_zone_report *zi;
unsigned long zonesize;
uint32_t i, nr_zones;
@@ -290,21 +296,27 @@ static int blkzone_report(struct blkzone_control *ctl)
else
cap = entry->len;
- printf(_(" start: 0x%09"PRIx64", len 0x%06"PRIx64
- ", cap 0x%06"PRIx64", wptr 0x%06"PRIx64
- " reset:%u non-seq:%u, zcond:%2u(%s) [type: %u(%s)]\n"),
- start, len, cap, (type == 0x1) ? 0 : wp - start,
- entry->reset, entry->non_seq,
- cond, condition_str[cond & (ARRAY_SIZE(condition_str) - 1)],
- type, type_text[type]);
+ if (only_capacity_sum) {
+ capacity_sum += cap;
+ } else {
+ printf(_(" start: 0x%09"PRIx64", len 0x%06"PRIx64
+ ", cap 0x%06"PRIx64", wptr 0x%06"PRIx64
+ " reset:%u non-seq:%u, zcond:%2u(%s) [type: %u(%s)]\n"),
+ start, len, cap, (type == 0x1) ? 0 : wp - start,
+ entry->reset, entry->non_seq,
+ cond, condition_str[cond & (ARRAY_SIZE(condition_str) - 1)],
+ type, type_text[type]);
+ }
nr_zones--;
ctl->offset = start + len;
-
}
}
+ if (only_capacity_sum)
+ printf(_("0x%09"PRIx64"\n"), capacity_sum);
+
free(zi);
close(fd);
--
2.20.1
next reply other threads:[~2020-09-11 8:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-11 8:47 Hans Holmberg [this message]
2020-09-11 10:42 ` [PATCH] blkzone: add report capacity command Karel Zak
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=20200911084723.14996-1-hans.holmberg@wdc.com \
--to=hans.holmberg@wdc.com \
--cc=damien.lemoal@wdc.com \
--cc=kzak@redhat.com \
--cc=matias.bjorling@wdc.com \
--cc=shinichiro.kawasaki@wdc.com \
--cc=util-linux@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).