]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: flags/fd: decode FD flags states
authorWilly Tarreau <w@1wt.eu>
Mon, 12 Sep 2022 16:53:06 +0000 (18:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 12 Sep 2022 17:33:07 +0000 (19:33 +0200)
The new function is fd_show_flags() and it reports known FD flags:

  $ ./dev/flags/flags fd 0x000121
  fd->flags = FD_POLL_IN | FD_EV_READY_W | FD_EV_ACTIVE_R

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

index ac933e252a2ed79ab69a9edbab0b0075787dda3a..d867ba247fdad037c0fa2cce8b71db8c875a1141 100644 (file)
@@ -3,9 +3,10 @@
 
 #include <haproxy/channel-t.h>
 #include <haproxy/connection-t.h>
-#include <haproxy/stconn-t.h>
+#include <haproxy/fd-t.h>
 #include <haproxy/http_ana-t.h>
 #include <haproxy/htx-t.h>
+#include <haproxy/stconn-t.h>
 #include <haproxy/stream-t.h>
 #include <haproxy/task-t.h>
 
 #define SHOW_AS_HSL   0x00000200
 #define SHOW_AS_HTX   0x00000400
 #define SHOW_AS_HMSG  0x00000800
+#define SHOW_AS_FD    0x00001000
 
 // command line names, must be in exact same order as the SHOW_AS_* flags above
 // so that show_as_words[i] matches flag 1U<<i.
-const char *show_as_words[] = { "ana", "chn", "conn", "sc", "stet", "strm", "task", "txn", "sd", "hsl", "htx", "hmsg", };
+const char *show_as_words[] = { "ana", "chn", "conn", "sc", "stet", "strm", "task", "txn", "sd", "hsl", "htx", "hmsg", "fd", };
 
 /* will be sufficient for even largest flag names */
 static char buf[4096];
@@ -131,6 +133,7 @@ int main(int argc, char **argv)
                if (show_as & SHOW_AS_HSL)   printf("sl->flags = %s\n",   (hsl_show_flags    (buf, bsz, " | ", flags), buf));
                if (show_as & SHOW_AS_HTX)   printf("htx->flags = %s\n",  (htx_show_flags    (buf, bsz, " | ", flags), buf));
                if (show_as & SHOW_AS_HMSG)  printf("hmsg->flags = %s\n", (hmsg_show_flags   (buf, bsz, " | ", flags), buf));
+               if (show_as & SHOW_AS_FD)    printf("fd->flags = %s\n",   (fd_show_flags     (buf, bsz, " | ", flags), buf));
        }
        return 0;
 }
index cecf797fe39e7187d82e08fb8a48ad4fcc3f44ba..b2ca87cb175033e8476e3ad1462a5a6174385b00 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <haproxy/api-t.h>
 #include <haproxy/port_range-t.h>
+#include <haproxy/show_flags-t.h>
 
 /* Direction for each FD event update */
 enum {
@@ -112,6 +113,27 @@ enum {
 #define FD_EXCL_SYSCALL     (1U << FD_EXCL_SYSCALL_BIT)
 #define FD_DISOWN           (1U << FD_DISOWN_BIT)
 
+/* 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 *fd_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 */
+       _(FD_EV_ACTIVE_R, _(FD_EV_ACTIVE_W, _(FD_EV_READY_R, _(FD_EV_READY_W,
+       _(FD_EV_SHUT_R, _(FD_EV_SHUT_W, _(FD_EV_ERR_RW, _(FD_POLL_IN,
+       _(FD_POLL_PRI, _(FD_POLL_OUT, _(FD_POLL_ERR, _(FD_POLL_HUP,
+       _(FD_LINGER_RISK, _(FD_CLONED, _(FD_INITIALIZED, _(FD_ET_POSSIBLE,
+       _(FD_EXPORTED, _(FD_EXCL_SYSCALL, _(FD_DISOWN)))))))))))))))))));
+       /* epilogue */
+       _(~0U);
+       return buf;
+#undef _
+}
+
 /* FD update status after fd_update_events() */
 enum {
        FD_UPDT_DONE = 0,    // update done, nothing else to be done