blkzone: add report capacity command

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>
This commit is contained in:
Hans Holmberg 2020-09-11 10:47:23 +02:00 committed by Karel Zak
parent df09e21c24
commit 049859a6df
2 changed files with 27 additions and 8 deletions

View File

@ -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),

View File

@ -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);