]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: server: Allow relative weights greater than 100%
authorSimon Horman <horms@verge.net.au>
Tue, 12 Feb 2013 01:45:52 +0000 (10:45 +0900)
committerWilly Tarreau <w@1wt.eu>
Wed, 13 Feb 2013 09:56:28 +0000 (10:56 +0100)
Allow relative weights greater than 100%,
capping the absolute value to 256 which is
the largest supported absolute weight.

Signed-off-by: Simon Horman <horms@verge.net.au>
doc/configuration.txt
src/server.c

index 5f7a65bb0929ec93f5b233ed024d9c9643ecdf03..df8e70c8af3a840ae55959bda3246fd1ac708f14 100644 (file)
@@ -11439,18 +11439,19 @@ set timeout cli <delay>
 set weight <backend>/<server> <weight>[%]
   Change a server's weight to the value passed in argument. If the value ends
   with the '%' sign, then the new weight will be relative to the initially
-  configured weight. Relative weights are only permitted between 0 and 100%,
-  and absolute weights are permitted between 0 and 256. Servers which are part
-  of a farm running a static load-balancing algorithm have stricter limitations
-  because the weight cannot change once set. Thus for these servers, the only
-  accepted values are 0 and 100% (or 0 and the initial weight). Changes take
-  effect immediately, though certain LB algorithms require a certain amount of
-  requests to consider changes. A typical usage of this command is to disable
-  a server during an update by setting its weight to zero, then to enable it
-  again after the update by setting it back to 100%. This command is restricted
-  and can only be issued on sockets configured for level "admin". Both the
-  backend and the server may be specified either by their name or by their
-  numeric ID, prefixed with a sharp ('#').
+  configured weight.  Absolute weights are permitted between 0 and 256.
+  Relative weights must be positive with the resulting absolute weight is
+  capped at 256.  Servers which are part of a farm running a static
+  load-balancing algorithm have stricter limitations because the weight
+  cannot change once set. Thus for these servers, the only accepted values
+  are 0 and 100% (or 0 and the initial weight). Changes take effect
+  immediately, though certain LB algorithms require a certain amount of
+  requests to consider changes. A typical usage of this command is to
+  disable a server during an update by setting its weight to zero, then to
+  enable it again after the update by setting it back to 100%. This command
+  is restricted and can only be issued on sockets configured for level
+  "admin". Both the backend and the server may be specified either by their
+  name or by their numeric ID, prefixed with a sharp ('#').
 
 show errors [<iid>]
   Dump last known request and response errors collected by frontends and
index 7a2774c47a5c3e5ef7bcaa86c3d7db6c49400e9f..4c1762f425019c40f41a65ca674fda4db66d33a5 100644 (file)
@@ -176,9 +176,14 @@ const char *server_parse_weight_change_request(struct server *sv,
 
        w = atoi(weight_str);
        if (strchr(weight_str, '%') != NULL) {
-               if (w < 0 || w > 100)
+               if (w < 0)
                        return "Relative weight must be positive.\n";
+               /* Avoid integer overflow */
+               if (w > 25600)
+                       w = 25600;
                w = sv->iweight * w / 100;
+               if (w > 256)
+                       w = 256;
        }
        else if (w < 0 || w > 256)
                return "Absolute weight can only be between 0 and 256 inclusive.\n";