]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: flags/stream: use flag dumping for stream error type
authorWilly Tarreau <w@1wt.eu>
Fri, 9 Sep 2022 13:38:30 +0000 (15:38 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 9 Sep 2022 14:52:09 +0000 (16:52 +0200)
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.

dev/flags/flags.c
include/haproxy/stream-t.h

index a8eb81b566feb5f07b7afbfc473e87517a4fb442..fbcbe692808ab092d1e5c5c82311127c65e16fc9 100644 (file)
@@ -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)
index a2928e5de906ad466a9ee2f0801fdf7fe8a57924..2d5e540b34821d62442453db1a7776e18308da4c 100644 (file)
@@ -30,6 +30,7 @@
 #include <haproxy/dynbuf-t.h>
 #include <haproxy/filters-t.h>
 #include <haproxy/obj_type-t.h>
+#include <haproxy/show_flags-t.h>
 #include <haproxy/stick_table-t.h>
 #include <haproxy/vars-t.h>
 
@@ -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;