pretty: ABD flags

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
This commit is contained in:
Rob Norris 2024-02-29 13:23:56 +11:00 committed by Rob Norris
parent 0ed16548e4
commit db1e59a63d
2 changed files with 93 additions and 0 deletions

View File

@ -40,6 +40,13 @@ _ZFS_PRETTY_H size_t zfs_pretty_zio_flag_pairs(
_ZFS_PRETTY_H size_t zfs_pretty_zio_flag_str(
uint64_t bits, char *out, size_t outlen);
_ZFS_PRETTY_H size_t zfs_pretty_abd_flag_bits(
uint64_t bits, char *out, size_t outlen);
_ZFS_PRETTY_H size_t zfs_pretty_abd_flag_pairs(
uint64_t bits, char *out, size_t outlen);
_ZFS_PRETTY_H size_t zfs_pretty_abd_flag_str(
uint64_t bits, char *out, size_t outlen);
#ifdef __cplusplus
}
#endif

View File

@ -140,3 +140,89 @@ zfs_pretty_zio_flag_str(uint64_t bits, char *out, size_t outlen)
out[n++] = '\0';
return (n);
}
static const pretty_bit_t pretty_abd_flag_table[] = {
{ 'L', "LN", "LINEAR" },
{ 'O', "OW", "OWNER" },
{ 'M', "MT", "META" },
{ 'Z', "MZ", "MULTI_ZONE" },
{ 'C', "MC", "MULTI_CHUNK" },
{ 'P', "LP", "LINEAR_PAGE" },
{ 'G', "GG", "GANG" },
{ 'F', "GF", "GANG_FREE" },
{ 'Z', "ZR", "ZEROS" },
{ 'A', "AL", "ALLOCD" },
};
static const size_t pretty_abd_flag_table_elems =
sizeof (pretty_abd_flag_table) / sizeof (pretty_bit_t);
size_t
zfs_pretty_abd_flag_bits(uint64_t bits, char *out, size_t outlen)
{
ASSERT(out);
size_t n = 0;
for (int b = pretty_abd_flag_table_elems; b >= 0; b--) {
if (n == outlen)
break;
uint64_t mask = (1ULL << b);
out[n++] =
(bits & mask) ? pretty_abd_flag_table[b].pb_bit : ' ';
}
if (n < outlen)
out[n++] = '\0';
return (n);
}
size_t
zfs_pretty_abd_flag_pairs(uint64_t bits, char *out, size_t outlen)
{
ASSERT(out);
size_t n = 0;
for (int b = pretty_abd_flag_table_elems; b >= 0; b--) {
ASSERT3U(n, <=, outlen);
if (n == outlen)
break;
uint64_t mask = (1ULL << b);
if (bits & mask) {
size_t len = (n > 0) ? 3 : 2;
if (n > outlen-len)
break;
if (n > 0)
out[n++] = '|';
out[n++] = pretty_abd_flag_table[b].pb_pair[0];
out[n++] = pretty_abd_flag_table[b].pb_pair[1];
}
}
if (n < outlen)
out[n++] = '\0';
return (n);
}
size_t
zfs_pretty_abd_flag_str(uint64_t bits, char *out, size_t outlen)
{
ASSERT(out);
size_t n = 0;
for (int b = 0; b <= pretty_abd_flag_table_elems; b++) {
ASSERT3U(n, <=, outlen);
if (n == outlen)
break;
uint64_t mask = (1ULL << b);
if (bits & mask) {
size_t len = strlen(pretty_abd_flag_table[b].pb_name);
if (n > 0)
len++;
if (n > outlen-len)
break;
if (n > 0) {
out[n++] = ' ';
len--;
}
memcpy(&out[n], pretty_abd_flag_table[b].pb_name, len);
n += len;
}
}
if (n < outlen)
out[n++] = '\0';
return (n);
}