pretty: code generators

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
This commit is contained in:
Rob Norris 2024-02-29 13:59:45 +11:00 committed by Rob Norris
parent 42a69191b6
commit 754fb75395
2 changed files with 46 additions and 63 deletions

View File

@ -33,19 +33,18 @@
extern "C" { extern "C" {
#endif #endif
_ZFS_PRETTY_H size_t zfs_pretty_zio_flag_bits( #define _ZFS_PRETTY_DECLARE(name) \
uint64_t bits, char *out, size_t outlen); _ZFS_PRETTY_H size_t zfs_pretty_ ## name ## _bits( \
_ZFS_PRETTY_H size_t zfs_pretty_zio_flag_pairs( uint64_t bits, char *out, size_t outlen); \
uint64_t bits, char *out, size_t outlen); _ZFS_PRETTY_H size_t zfs_pretty_ ## name ## _pairs( \
_ZFS_PRETTY_H size_t zfs_pretty_zio_flag_str( uint64_t bits, char *out, size_t outlen); \
uint64_t bits, char *out, size_t outlen); _ZFS_PRETTY_H size_t zfs_pretty_ ## name ## _str( \
uint64_t bits, char *out, size_t outlen); \
_ZFS_PRETTY_H size_t zfs_pretty_abd_flag_bits( _ZFS_PRETTY_DECLARE(zio_flag)
uint64_t bits, char *out, size_t outlen); _ZFS_PRETTY_DECLARE(abd_flag)
_ZFS_PRETTY_H size_t zfs_pretty_abd_flag_pairs(
uint64_t bits, char *out, size_t outlen); #undef _ZFS_PRETTY_DECLARE
_ZFS_PRETTY_H size_t zfs_pretty_abd_flag_str(
uint64_t bits, char *out, size_t outlen);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -109,7 +109,34 @@ zfs_pretty_str(const pretty_bit_t *table, const size_t nelems,
return (n); return (n);
} }
static const pretty_bit_t pretty_zio_flag_table[] = { #define _PRETTY_BIT_IMPL(name, ...) \
static const pretty_bit_t pretty_ ## name ## _table[] = { __VA_ARGS__ };\
size_t \
zfs_pretty_ ## name ## _bits(uint64_t bits, char *out, size_t outlen) \
{ \
return (zfs_pretty_bits(pretty_ ## name ## _table, \
sizeof (pretty_ ## name ## _table) / sizeof (pretty_bit_t), \
bits, out, outlen)); \
} \
\
size_t \
zfs_pretty_ ## name ## _pairs(uint64_t bits, char *out, size_t outlen) \
{ \
return (zfs_pretty_pairs(pretty_ ## name ## _table, \
sizeof (pretty_ ## name ## _table) / sizeof (pretty_bit_t), \
bits, out, outlen)); \
} \
\
size_t \
zfs_pretty_ ## name ## _str(uint64_t bits, char *out, size_t outlen) \
{ \
return (zfs_pretty_str(pretty_ ## name ## _table, \
sizeof (pretty_ ## name ## _table) / sizeof (pretty_bit_t), \
bits, out, outlen)); \
} \
/* BEGIN CSTYLED */
_PRETTY_BIT_IMPL(zio_flag,
{ '.', "DA", "DONT_AGGREGATE" }, { '.', "DA", "DONT_AGGREGATE" },
{ '.', "RP", "IO_REPAIR" }, { '.', "RP", "IO_REPAIR" },
{ '.', "SH", "SELF_HEAL" }, { '.', "SH", "SELF_HEAL" },
@ -140,33 +167,11 @@ static const pretty_bit_t pretty_zio_flag_table[] = {
{ '.', "NP", "NOPWRITE" }, { '.', "NP", "NOPWRITE" },
{ '.', "EX", "REEXECUTED" }, { '.', "EX", "REEXECUTED" },
{ '.', "DG", "DELEGATED" }, { '.', "DG", "DELEGATED" },
}; )
/* END CSTYLED */
size_t /* BEGIN CSTYLED */
zfs_pretty_zio_flag_bits(uint64_t bits, char *out, size_t outlen) _PRETTY_BIT_IMPL(abd_flag,
{
return (zfs_pretty_bits(pretty_zio_flag_table,
sizeof (pretty_zio_flag_table) / sizeof (pretty_bit_t),
bits, out, outlen));
}
size_t
zfs_pretty_zio_flag_pairs(uint64_t bits, char *out, size_t outlen)
{
return (zfs_pretty_pairs(pretty_zio_flag_table,
sizeof (pretty_zio_flag_table) / sizeof (pretty_bit_t),
bits, out, outlen));
}
size_t
zfs_pretty_zio_flag_str(uint64_t bits, char *out, size_t outlen)
{
return (zfs_pretty_str(pretty_zio_flag_table,
sizeof (pretty_zio_flag_table) / sizeof (pretty_bit_t),
bits, out, outlen));
}
static const pretty_bit_t pretty_abd_flag_table[] = {
{ 'L', "LN", "LINEAR" }, { 'L', "LN", "LINEAR" },
{ 'O', "OW", "OWNER" }, { 'O', "OW", "OWNER" },
{ 'M', "MT", "META" }, { 'M', "MT", "META" },
@ -177,28 +182,7 @@ static const pretty_bit_t pretty_abd_flag_table[] = {
{ 'F', "GF", "GANG_FREE" }, { 'F', "GF", "GANG_FREE" },
{ 'Z', "ZR", "ZEROS" }, { 'Z', "ZR", "ZEROS" },
{ 'A', "AL", "ALLOCD" }, { 'A', "AL", "ALLOCD" },
}; )
/* END CSTYLED */
size_t #undef _PRETTY_BIT_IMPL
zfs_pretty_abd_flag_bits(uint64_t bits, char *out, size_t outlen)
{
return (zfs_pretty_bits(pretty_abd_flag_table,
sizeof (pretty_abd_flag_table) / sizeof (pretty_bit_t),
bits, out, outlen));
}
size_t
zfs_pretty_abd_flag_pairs(uint64_t bits, char *out, size_t outlen)
{
return (zfs_pretty_pairs(pretty_abd_flag_table,
sizeof (pretty_abd_flag_table) / sizeof (pretty_bit_t),
bits, out, outlen));
}
size_t
zfs_pretty_abd_flag_str(uint64_t bits, char *out, size_t outlen)
{
return (zfs_pretty_str(pretty_abd_flag_table,
sizeof (pretty_abd_flag_table) / sizeof (pretty_bit_t),
bits, out, outlen));
}