]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
REORG: cli: move 'show pools' to memory.c
authorWilliam Lallemand <wlallemand@haproxy.com>
Sat, 19 Nov 2016 01:25:36 +0000 (02:25 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 24 Nov 2016 15:59:27 +0000 (16:59 +0100)
Move 'show pools' CLI functions to memory.c and use the cli keyword
API to register it on the CLI.

include/types/cli.h
src/cli.c
src/memory.c

index a7a85653f95c26b5a3e4dcedc105b03cef58513e..a6fe57a0d0ffc543a51995aa7e0c7630b1dbf0f8 100644 (file)
@@ -117,7 +117,6 @@ enum {
        STAT_CLI_O_CLR,      /* clear tables */
        STAT_CLI_O_SET,      /* set entries in tables */
        STAT_CLI_O_STAT,     /* dump stats */
-       STAT_CLI_O_POOLS,    /* dump memory pools */
        STAT_CLI_O_SERVERS_STATE, /* dump server state and changing information */
        STAT_CLI_O_BACKEND,  /* dump backend list */
        STAT_CLI_O_ENV,      /* dump environment */
index 7c847081032466feb0c67c5b17a31abb82d02ed5..e96c32381dfbf75a960d6becd4ae6a4caa22fdea 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -137,7 +137,6 @@ static int stats_dump_backend_to_buffer(struct stream_interface *si);
 static int stats_dump_env_to_buffer(struct stream_interface *si);
 static int stats_dump_info_to_buffer(struct stream_interface *si);
 static int stats_dump_servers_state_to_buffer(struct stream_interface *si);
-static int stats_dump_pools_to_buffer(struct stream_interface *si);
 static int stats_dump_full_sess_to_buffer(struct stream_interface *si, struct stream *sess);
 static int stats_dump_sess_to_buffer(struct stream_interface *si);
 static int stats_dump_errors_to_buffer(struct stream_interface *si);
@@ -157,7 +156,6 @@ static const char stats_sock_usage_msg[] =
        "  show backend   : list backends in the current running config\n"
        "  show env [var] : dump environment variables known to the process\n"
        "  show info      : report information about the running process\n"
-       "  show pools     : report information about the memory pools usage\n"
        "  show stat      : report counters for each proxy and server\n"
        "  show errors    : report last request and response errors for each proxy\n"
        "  show sess [id] : report the list of current sessions or dump this session\n"
@@ -1136,10 +1134,6 @@ static int stats_sock_parse_request(struct stream_interface *si, char *line)
                        appctx->st0 = STAT_CLI_O_SERVERS_STATE; // stats_dump_servers_state_to_buffer
                        return 1;
                }
-               else if (strcmp(args[1], "pools") == 0) {
-                       appctx->st2 = STAT_ST_INIT;
-                       appctx->st0 = STAT_CLI_O_POOLS; // stats_dump_pools_to_buffer
-               }
                else if (strcmp(args[1], "sess") == 0) {
                        appctx->st2 = STAT_ST_INIT;
                        if (strm_li(s)->bind_conf->level < ACCESS_LVL_OPER) {
@@ -1961,10 +1955,6 @@ static void cli_io_handler(struct appctx *appctx)
                                if (stats_table_request(si, appctx->st0))
                                        appctx->st0 = STAT_CLI_PROMPT;
                                break;
-                       case STAT_CLI_O_POOLS:
-                               if (stats_dump_pools_to_buffer(si))
-                                       appctx->st0 = STAT_CLI_PROMPT;
-                               break;
                        case STAT_CLI_O_ENV:    /* environment dump */
                                if (stats_dump_env_to_buffer(si))
                                        appctx->st0 = STAT_CLI_PROMPT;
@@ -2344,20 +2334,6 @@ static int stats_dump_servers_state_to_buffer(struct stream_interface *si)
        return 1;
 }
 
-/* This function dumps memory usage information onto the stream interface's
- * read buffer. It returns 0 as long as it does not complete, non-zero upon
- * completion. No state is used.
- */
-static int stats_dump_pools_to_buffer(struct stream_interface *si)
-{
-       dump_pools_to_trash();
-       if (bi_putchk(si_ic(si), &trash) == -1) {
-               si_applet_cant_put(si);
-               return 0;
-       }
-       return 1;
-}
-
 static inline const char *get_conn_ctrl_name(const struct connection *conn)
 {
        if (!conn_ctrl_ready(conn))
index 53ab4890a3da06ca03c346b2a7eb3d75712e6da1..4681d58f4b32ffd23aecbf62bdf35d03a4a36bc6 100644 (file)
  *
  */
 
+#include <types/applet.h>
+#include <types/cli.h>
 #include <types/global.h>
+#include <types/stats.h>
+
 #include <common/config.h>
 #include <common/debug.h>
 #include <common/memory.h>
 #include <common/mini-clist.h>
 #include <common/standard.h>
 
+#include <proto/applet.h>
+#include <proto/cli.h>
+#include <proto/channel.h>
 #include <proto/log.h>
+#include <proto/stream_interface.h>
+#include <proto/stats.h>
 
 static struct list pools = LIST_HEAD_INIT(pools);
 int mem_poison_byte = -1;
@@ -264,6 +273,39 @@ unsigned long pool_total_used()
        return used;
 }
 
+/* This function dumps memory usage information onto the stream interface's
+ * read buffer. It returns 0 as long as it does not complete, non-zero upon
+ * completion. No state is used.
+ */
+static int cli_io_handler_dump_pools(struct appctx *appctx)
+{
+       struct stream_interface *si = appctx->owner;
+
+       dump_pools_to_trash();
+       if (bi_putchk(si_ic(si), &trash) == -1) {
+               si_applet_cant_put(si);
+               return 0;
+       }
+       return 1;
+}
+
+static int cli_parse_show_pools(char **args, struct appctx *appctx, void *private)
+{
+       return 0;
+}
+
+/* register cli keywords */
+static struct cli_kw_list cli_kws = {{ },{
+       { { "show", "pools",  NULL }, "show pools     : report information about the memory pools usage", cli_parse_show_pools, cli_io_handler_dump_pools },
+       {{},}
+}};
+
+__attribute__((constructor))
+static void __memory_init(void)
+{
+       cli_register_kw(&cli_kws);
+}
+
 /*
  * Local variables:
  *  c-indent-level: 8