From: Willy Tarreau Date: Fri, 9 Sep 2022 13:38:30 +0000 (+0200) Subject: MINOR: flags/stream: use flag dumping for stream error type X-Git-Tag: v2.7-dev6~47 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f4cb98ce56b62ba5a4f8f0c1c1fe45ff19617f43;p=thirdparty%2Fhaproxy.git MINOR: flags/stream: use flag dumping for stream error type The new function is strm_et_show_flags(). Only the error type is handled at the moment, as a bit more complex logic is needed to mix the values and enums present in some fields. --- diff --git a/dev/flags/flags.c b/dev/flags/flags.c index a8eb81b566..fbcbe69280 100644 --- a/dev/flags/flags.c +++ b/dev/flags/flags.c @@ -78,28 +78,8 @@ void show_sc_flags(unsigned int f) void show_strm_et(unsigned int f) { - printf("strm->et = "); - if (!f) { - printf("STRM_ET_NONE\n"); - return; - } - - SHOW_FLAG(f, STRM_ET_QUEUE_TO); - SHOW_FLAG(f, STRM_ET_QUEUE_ERR); - SHOW_FLAG(f, STRM_ET_QUEUE_ABRT); - SHOW_FLAG(f, STRM_ET_CONN_TO); - SHOW_FLAG(f, STRM_ET_CONN_ERR); - SHOW_FLAG(f, STRM_ET_CONN_ABRT); - SHOW_FLAG(f, STRM_ET_CONN_RES); - SHOW_FLAG(f, STRM_ET_CONN_OTHER); - SHOW_FLAG(f, STRM_ET_DATA_TO); - SHOW_FLAG(f, STRM_ET_DATA_ERR); - SHOW_FLAG(f, STRM_ET_DATA_ABRT); - - if (f) { - printf("EXTRA(0x%08x)", f); - } - putchar('\n'); + strm_et_show_flags(tmpbuf, sizeof(tmpbuf), " | ", f); + printf("strm->et = %s\n", tmpbuf); } void show_task_state(unsigned int f) diff --git a/include/haproxy/stream-t.h b/include/haproxy/stream-t.h index a2928e5de9..2d5e540b34 100644 --- a/include/haproxy/stream-t.h +++ b/include/haproxy/stream-t.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -91,7 +92,9 @@ #define PCLI_F_PAYLOAD 0x20000 -/* error types reported on the streams for more accurate reporting */ +/* error types reported on the streams for more accurate reporting. + * Please also update the strm_et_show_flags() function below in case of changes. + */ enum { STRM_ET_NONE = 0x0000, /* no error yet, leave it to zero */ STRM_ET_QUEUE_TO = 0x0001, /* queue timeout */ @@ -107,6 +110,26 @@ enum { STRM_ET_DATA_ABRT = 0x0400, /* data phase aborted by external cause */ }; +/* This function is used to report flags in debugging tools. Please reflect + * below any single-bit flag addition above in the same order via the + * __APPEND_FLAG macro. The new end of the buffer is returned. + */ +static forceinline char *strm_et_show_flags(char *buf, size_t len, const char *delim, uint flg) +{ +#define _(f, ...) __APPEND_FLAG(buf, len, delim, flg, f, #f, __VA_ARGS__) + /* prologue */ + _(0); + /* flags */ + _(STRM_ET_QUEUE_TO, _(STRM_ET_QUEUE_ERR, _(STRM_ET_QUEUE_ABRT, + _(STRM_ET_CONN_TO, _(STRM_ET_CONN_ERR, _(STRM_ET_CONN_ABRT, + _(STRM_ET_CONN_RES, _(STRM_ET_CONN_OTHER, _(STRM_ET_DATA_TO, + _(STRM_ET_DATA_ERR, _(STRM_ET_DATA_ABRT))))))))))); + /* epilogue */ + _(~0U); + return buf; +#undef _ +} + struct hlua; struct proxy; struct pendconn;