From 754fb75395f0bbb57c70ff1f8d3b4175e02f5ef8 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Thu, 29 Feb 2024 13:59:45 +1100 Subject: [PATCH] pretty: code generators Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc. --- include/zfs_pretty.h | 23 +++++----- module/zcommon/zfs_pretty.c | 86 +++++++++++++++---------------------- 2 files changed, 46 insertions(+), 63 deletions(-) diff --git a/include/zfs_pretty.h b/include/zfs_pretty.h index d30419ac10..651779d634 100644 --- a/include/zfs_pretty.h +++ b/include/zfs_pretty.h @@ -33,19 +33,18 @@ extern "C" { #endif -_ZFS_PRETTY_H size_t zfs_pretty_zio_flag_bits( - uint64_t bits, char *out, size_t outlen); -_ZFS_PRETTY_H size_t zfs_pretty_zio_flag_pairs( - uint64_t bits, char *out, size_t outlen); -_ZFS_PRETTY_H size_t zfs_pretty_zio_flag_str( - uint64_t bits, char *out, size_t outlen); +#define _ZFS_PRETTY_DECLARE(name) \ + _ZFS_PRETTY_H size_t zfs_pretty_ ## name ## _bits( \ + uint64_t bits, char *out, size_t outlen); \ + _ZFS_PRETTY_H size_t zfs_pretty_ ## name ## _pairs( \ + 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( - 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); +_ZFS_PRETTY_DECLARE(zio_flag) +_ZFS_PRETTY_DECLARE(abd_flag) + +#undef _ZFS_PRETTY_DECLARE #ifdef __cplusplus } diff --git a/module/zcommon/zfs_pretty.c b/module/zcommon/zfs_pretty.c index 5600557bf7..a2b378e2da 100644 --- a/module/zcommon/zfs_pretty.c +++ b/module/zcommon/zfs_pretty.c @@ -109,7 +109,34 @@ zfs_pretty_str(const pretty_bit_t *table, const size_t nelems, 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" }, { '.', "RP", "IO_REPAIR" }, { '.', "SH", "SELF_HEAL" }, @@ -140,33 +167,11 @@ static const pretty_bit_t pretty_zio_flag_table[] = { { '.', "NP", "NOPWRITE" }, { '.', "EX", "REEXECUTED" }, { '.', "DG", "DELEGATED" }, -}; +) +/* END CSTYLED */ -size_t -zfs_pretty_zio_flag_bits(uint64_t bits, char *out, size_t outlen) -{ - 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[] = { +/* BEGIN CSTYLED */ +_PRETTY_BIT_IMPL(abd_flag, { 'L', "LN", "LINEAR" }, { 'O', "OW", "OWNER" }, { 'M', "MT", "META" }, @@ -177,28 +182,7 @@ static const pretty_bit_t pretty_abd_flag_table[] = { { 'F', "GF", "GANG_FREE" }, { 'Z', "ZR", "ZEROS" }, { 'A', "AL", "ALLOCD" }, -}; +) +/* END CSTYLED */ -size_t -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)); -} +#undef _PRETTY_BIT_IMPL