]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: dynbuf: move the reserve and limit parsers to dynbuf.c
authorWilly Tarreau <w@1wt.eu>
Thu, 18 Apr 2024 14:11:52 +0000 (16:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 27 Apr 2024 07:36:36 +0000 (09:36 +0200)
I just added a new setting to set the number of reserved buffer, to
discover we already had one... Let's move the parsing of this keyword
(tune.buffers.reserve) and tune.buffers.limit to dynbuf.c where they
should be.

src/cfgparse-global.c
src/dynbuf.c

index 1f73fbdd89c1a73b60ab3f304e0a86f58019aca9..d93d5ffb4b00231ce136acac05c30546c2364ae8 100644 (file)
@@ -36,8 +36,7 @@ static const char *common_kw_list[] = {
        "insecure-fork-wanted", "insecure-setuid-wanted", "nosplice",
        "nogetaddrinfo", "noreuseport", "quiet", "zero-warning",
        "tune.runqueue-depth", "tune.maxpollevents", "tune.maxaccept",
-       "tune.recv_enough", "tune.buffers.limit",
-       "tune.buffers.reserve", "tune.bufsize", "tune.maxrewrite",
+       "tune.recv_enough", "tune.bufsize", "tune.maxrewrite",
        "tune.idletimer", "tune.rcvbuf.client", "tune.rcvbuf.server",
        "tune.sndbuf.client", "tune.sndbuf.server", "tune.pipesize",
        "tune.http.cookielen", "tune.http.logurilen", "tune.http.maxhdr",
@@ -267,36 +266,6 @@ int cfg_parse_global(const char *file, int linenum, char **args, int kwm)
                }
                global.tune.recv_enough = atol(args[1]);
        }
-       else if (strcmp(args[0], "tune.buffers.limit") == 0) {
-               if (alertif_too_many_args(1, file, linenum, args, &err_code))
-                       goto out;
-               if (*(args[1]) == 0) {
-                       ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-               global.tune.buf_limit = atol(args[1]);
-               if (global.tune.buf_limit) {
-                       if (global.tune.buf_limit < 3)
-                               global.tune.buf_limit = 3;
-                       if (global.tune.buf_limit <= global.tune.reserved_bufs)
-                               global.tune.buf_limit = global.tune.reserved_bufs + 1;
-               }
-       }
-       else if (strcmp(args[0], "tune.buffers.reserve") == 0) {
-               if (alertif_too_many_args(1, file, linenum, args, &err_code))
-                       goto out;
-               if (*(args[1]) == 0) {
-                       ha_alert("parsing [%s:%d] : '%s' expects an integer argument.\n", file, linenum, args[0]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-               global.tune.reserved_bufs = atol(args[1]);
-               if (global.tune.reserved_bufs < 2)
-                       global.tune.reserved_bufs = 2;
-               if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
-                       global.tune.buf_limit = global.tune.reserved_bufs + 1;
-       }
        else if (strcmp(args[0], "tune.bufsize") == 0) {
                if (alertif_too_many_args(1, file, linenum, args, &err_code))
                        goto out;
index 712e334f12dd475ef9d537418b04affdad2b2a3d..7a9deb886414d857e9d3ff50c3fe989d24af691d 100644 (file)
 #include <string.h>
 
 #include <haproxy/api.h>
+#include <haproxy/cfgparse.h>
 #include <haproxy/dynbuf.h>
 #include <haproxy/global.h>
 #include <haproxy/list.h>
 #include <haproxy/pool.h>
+#include <haproxy/tools.h>
 
 struct pool_head *pool_head_buffer __read_mostly;
 
@@ -121,6 +123,67 @@ void __offer_buffers(void *from, unsigned int count)
        }
 }
 
+/* config parser for global "tune.buffers.limit", accepts a number >= 0 */
+static int cfg_parse_tune_buffers_limit(char **args, int section_type, struct proxy *curpx,
+                                        const struct proxy *defpx, const char *file, int line,
+                                        char **err)
+{
+       int limit;
+
+       if (too_many_args(1, args, err, NULL))
+               return -1;
+
+       limit = atoi(args[1]);
+       if (limit < 0) {
+               memprintf(err, "'%s' expects a non-negative number but got '%s'.", args[0], args[1]);
+               return -1;
+       }
+
+       global.tune.buf_limit = limit;
+       if (global.tune.buf_limit) {
+               if (global.tune.buf_limit < 3)
+                       global.tune.buf_limit = 3;
+               if (global.tune.buf_limit <= global.tune.reserved_bufs)
+                       global.tune.buf_limit = global.tune.reserved_bufs + 1;
+       }
+
+       return 0;
+}
+
+/* config parser for global "tune.buffers.reserve", accepts a number >= 0 */
+static int cfg_parse_tune_buffers_reserve(char **args, int section_type, struct proxy *curpx,
+                                          const struct proxy *defpx, const char *file, int line,
+                                          char **err)
+{
+       int reserve;
+
+       if (too_many_args(1, args, err, NULL))
+               return -1;
+
+       reserve = atoi(args[1]);
+       if (reserve < 0) {
+               memprintf(err, "'%s' expects a non-negative number but got '%s'.", args[0], args[1]);
+               return -1;
+       }
+
+       global.tune.reserved_bufs = reserve;
+       if (global.tune.reserved_bufs < 2)
+               global.tune.reserved_bufs = 2;
+       if (global.tune.buf_limit && global.tune.buf_limit <= global.tune.reserved_bufs)
+               global.tune.buf_limit = global.tune.reserved_bufs + 1;
+
+       return 0;
+}
+
+/* config keyword parsers */
+static struct cfg_kw_list cfg_kws = {ILH, {
+       { CFG_GLOBAL, "tune.buffers.limit", cfg_parse_tune_buffers_limit },
+       { CFG_GLOBAL, "tune.buffers.reserve", cfg_parse_tune_buffers_reserve },
+       { 0, NULL, NULL }
+}};
+
+INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
+
 /*
  * Local variables:
  *  c-indent-level: 8