blob: 94f9da8586d081edb85680ad9b94c7c56f370d10 [file] [log] [blame]
Willy Tarreaubaaee002006-06-26 02:48:02 +02001/*
2 * Queue management functions.
3 *
Willy Tarreauac68c5d2009-10-04 23:12:44 +02004 * Copyright 2000-2009 Willy Tarreau <w@1wt.eu>
Willy Tarreaubaaee002006-06-26 02:48:02 +02005 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
Willy Tarreau6bdd05c2018-07-25 15:21:00 +020013/* Short explanation on the locking, which is far from being trivial : a
14 * pendconn is a list element which necessarily is associated with an existing
15 * stream. It has pendconn->strm always valid. A pendconn may only be in one of
16 * these three states :
17 * - unlinked : in this case it is an empty list head ;
18 * - linked into the server's queue ;
19 * - linked into the proxy's queue.
20 *
21 * A stream does not necessarily have such a pendconn. Thus the pendconn is
22 * designated by the stream->pend_pos pointer. This results in some properties :
23 * - pendconn->strm->pend_pos is never NULL for any valid pendconn
Patrick Hemmer0355dab2018-05-11 12:52:31 -040024 * - if p->node.node.leaf_p is NULL, the element is unlinked,
Willy Tarreau6bdd05c2018-07-25 15:21:00 +020025 * otherwise it necessarily belongs to one of the other lists ; this may
26 * not be atomically checked under threads though ;
27 * - pendconn->px is never NULL if pendconn->list is not empty
Willy Tarreau88930dd2018-07-26 07:38:54 +020028 * - pendconn->srv is never NULL if pendconn->list is in the server's queue,
Willy Tarreau6bdd05c2018-07-25 15:21:00 +020029 * and is always NULL if pendconn->list is in the backend's queue or empty.
Willy Tarreau88930dd2018-07-26 07:38:54 +020030 * - pendconn->target is NULL while the element is queued, and points to the
31 * assigned server when the pendconn is picked.
Willy Tarreau6bdd05c2018-07-25 15:21:00 +020032 *
33 * Threads complicate the design a little bit but rules remain simple :
Willy Tarreau6bdd05c2018-07-25 15:21:00 +020034 * - the server's queue lock must be held at least when manipulating the
35 * server's queue, which is when adding a pendconn to the queue and when
36 * removing a pendconn from the queue. It protects the queue's integrity.
37 *
38 * - the proxy's queue lock must be held at least when manipulating the
39 * proxy's queue, which is when adding a pendconn to the queue and when
40 * removing a pendconn from the queue. It protects the queue's integrity.
41 *
Willy Tarreau3201e4e2018-07-26 08:23:24 +020042 * - both locks are compatible and may be held at the same time.
Willy Tarreau6bdd05c2018-07-25 15:21:00 +020043 *
44 * - a pendconn_add() is only performed by the stream which will own the
45 * pendconn ; the pendconn is allocated at this moment and returned ; it is
46 * added to either the server or the proxy's queue while holding this
Willy Tarreau49801602020-06-04 22:50:02 +020047s * queue's lock.
Willy Tarreau6bdd05c2018-07-25 15:21:00 +020048 *
49 * - the pendconn is then met by a thread walking over the proxy or server's
50 * queue with the respective lock held. This lock is exclusive and the
51 * pendconn can only appear in one queue so by definition a single thread
52 * may find this pendconn at a time.
53 *
54 * - the pendconn is unlinked either by its own stream upon success/abort/
55 * free, or by another one offering it its server slot. This is achieved by
56 * pendconn_process_next_strm() under either the server or proxy's lock,
57 * pendconn_redistribute() under the server's lock, pendconn_grab_from_px()
58 * under the proxy's lock, or pendconn_unlink() under either the proxy's or
59 * the server's lock depending on the queue the pendconn is attached to.
60 *
61 * - no single operation except the pendconn initialisation prior to the
Willy Tarreau3201e4e2018-07-26 08:23:24 +020062 * insertion are performed without eithre a queue lock held or the element
63 * being unlinked and visible exclusively to its stream.
Willy Tarreau6bdd05c2018-07-25 15:21:00 +020064 *
Willy Tarreau88930dd2018-07-26 07:38:54 +020065 * - pendconn_grab_from_px() and pendconn_process_next_strm() assign ->target
66 * so that the stream knows what server to work with (via
67 * pendconn_dequeue() which sets it on strm->target).
Willy Tarreau6bdd05c2018-07-25 15:21:00 +020068 *
69 * - a pendconn doesn't switch between queues, it stays where it is.
Willy Tarreau6bdd05c2018-07-25 15:21:00 +020070 */
71
Willy Tarreaudfd3de82020-06-04 23:46:14 +020072#include <import/eb32tree.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020073#include <haproxy/api.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020074#include <haproxy/backend.h>
Willy Tarreauc761f842020-06-04 11:40:28 +020075#include <haproxy/http_rules.h>
Willy Tarreaud0ef4392020-06-02 09:38:52 +020076#include <haproxy/pool.h>
Willy Tarreaua55c4542020-06-04 22:59:39 +020077#include <haproxy/queue.h>
Willy Tarreaue6ce10b2020-06-04 15:33:47 +020078#include <haproxy/sample.h>
Willy Tarreau1e56f922020-06-04 23:20:13 +020079#include <haproxy/server-t.h>
Willy Tarreaudfd3de82020-06-04 23:46:14 +020080#include <haproxy/stream.h>
Willy Tarreaucea0e1b2020-06-04 17:25:40 +020081#include <haproxy/task.h>
Willy Tarreau8b550af2020-06-04 17:42:48 +020082#include <haproxy/tcp_rules.h>
Willy Tarreau3f567e42020-05-28 15:29:19 +020083#include <haproxy/thread.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020084#include <haproxy/time.h>
Willy Tarreauc1a689f2021-05-08 13:59:05 +020085#include <haproxy/tools.h>
Willy Tarreaubaaee002006-06-26 02:48:02 +020086
87
Patrick Hemmer248cb4c2018-05-11 12:52:31 -040088#define NOW_OFFSET_BOUNDARY() ((now_ms - (TIMER_LOOK_BACK >> 12)) & 0xfffff)
89#define KEY_CLASS(key) ((u32)key & 0xfff00000)
90#define KEY_OFFSET(key) ((u32)key & 0x000fffff)
91#define KEY_CLASS_OFFSET_BOUNDARY(key) (KEY_CLASS(key) | NOW_OFFSET_BOUNDARY())
92#define MAKE_KEY(class, offset) (((u32)(class + 0x7ff) << 20) | ((u32)(now_ms + offset) & 0xfffff))
93
Willy Tarreau8ceae722018-11-26 11:58:30 +010094DECLARE_POOL(pool_head_pendconn, "pendconn", sizeof(struct pendconn));
Willy Tarreaubaaee002006-06-26 02:48:02 +020095
96/* returns the effective dynamic maxconn for a server, considering the minconn
Willy Tarreau86034312006-12-29 00:10:33 +010097 * and the proxy's usage relative to its dynamic connections limit. It is
Willy Tarreau9909fc12007-11-30 17:42:05 +010098 * expected that 0 < s->minconn <= s->maxconn when this is called. If the
99 * server is currently warming up, the slowstart is also applied to the
100 * resulting value, which can be lower than minconn in this case, but never
101 * less than 1.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200102 */
Willy Tarreaub17916e2006-10-15 15:17:57 +0200103unsigned int srv_dynamic_maxconn(const struct server *s)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200104{
Willy Tarreau9909fc12007-11-30 17:42:05 +0100105 unsigned int max;
106
Willy Tarreau86034312006-12-29 00:10:33 +0100107 if (s->proxy->beconn >= s->proxy->fullconn)
108 /* no fullconn or proxy is full */
Willy Tarreau9909fc12007-11-30 17:42:05 +0100109 max = s->maxconn;
110 else if (s->minconn == s->maxconn)
Willy Tarreau86034312006-12-29 00:10:33 +0100111 /* static limit */
Willy Tarreau9909fc12007-11-30 17:42:05 +0100112 max = s->maxconn;
113 else max = MAX(s->minconn,
114 s->proxy->beconn * s->maxconn / s->proxy->fullconn);
Willy Tarreau86034312006-12-29 00:10:33 +0100115
Emeric Brun52a91d32017-08-31 14:41:55 +0200116 if ((s->cur_state == SRV_ST_STARTING) &&
Willy Tarreau9909fc12007-11-30 17:42:05 +0100117 now.tv_sec < s->last_change + s->slowstart &&
118 now.tv_sec >= s->last_change) {
119 unsigned int ratio;
Willy Tarreau28a9e522008-09-14 17:43:27 +0200120 ratio = 100 * (now.tv_sec - s->last_change) / s->slowstart;
121 max = MAX(1, max * ratio / 100);
Willy Tarreau9909fc12007-11-30 17:42:05 +0100122 }
123 return max;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200124}
125
Willy Tarreau3e3ae252020-10-21 11:20:07 +0200126/* Remove the pendconn from the server's queue. At this stage, the connection
Willy Tarreau96bca332020-10-21 12:01:28 +0200127 * is not really dequeued. It will be done during the process_stream. It is
128 * up to the caller to atomically decrement the pending counts.
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100129 *
Willy Tarreau3e3ae252020-10-21 11:20:07 +0200130 * The caller must own the lock on the server queue. The pendconn must still be
131 * queued (p->node.leaf_p != NULL) and must be in a server (p->srv != NULL).
Christopher Fauletf3a55db2017-06-09 14:26:38 +0200132 */
Willy Tarreau3e3ae252020-10-21 11:20:07 +0200133static void __pendconn_unlink_srv(struct pendconn *p)
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100134{
Willy Tarreau51c63f02021-06-23 16:43:45 +0200135 p->strm->logs.srv_queue_pos += _HA_ATOMIC_LOAD(&p->queue->idx) - p->queue_idx;
Willy Tarreau3e3ae252020-10-21 11:20:07 +0200136 eb32_delete(&p->node);
137}
138
139/* Remove the pendconn from the proxy's queue. At this stage, the connection
Willy Tarreau96bca332020-10-21 12:01:28 +0200140 * is not really dequeued. It will be done during the process_stream. It is
141 * up to the caller to atomically decrement the pending counts.
Willy Tarreau3e3ae252020-10-21 11:20:07 +0200142 *
143 * The caller must own the lock on the proxy queue. The pendconn must still be
144 * queued (p->node.leaf_p != NULL) and must be in the proxy (p->srv == NULL).
145 */
146static void __pendconn_unlink_prx(struct pendconn *p)
147{
Willy Tarreau51c63f02021-06-23 16:43:45 +0200148 p->strm->logs.prx_queue_pos += _HA_ATOMIC_LOAD(&p->queue->idx) - p->queue_idx;
Patrick Hemmer0355dab2018-05-11 12:52:31 -0400149 eb32_delete(&p->node);
Christopher Fauletf3a55db2017-06-09 14:26:38 +0200150}
151
Willy Tarreau7c6f8a22018-07-26 08:03:14 +0200152/* Locks the queue the pendconn element belongs to. This relies on both p->px
153 * and p->srv to be properly initialized (which is always the case once the
154 * element has been added).
155 */
156static inline void pendconn_queue_lock(struct pendconn *p)
157{
Willy Tarreau51c63f02021-06-23 16:43:45 +0200158 HA_SPIN_LOCK(QUEUE_LOCK, &p->queue->lock);
Willy Tarreau7c6f8a22018-07-26 08:03:14 +0200159}
160
161/* Unlocks the queue the pendconn element belongs to. This relies on both p->px
162 * and p->srv to be properly initialized (which is always the case once the
163 * element has been added).
164 */
165static inline void pendconn_queue_unlock(struct pendconn *p)
166{
Willy Tarreau51c63f02021-06-23 16:43:45 +0200167 HA_SPIN_UNLOCK(QUEUE_LOCK, &p->queue->lock);
Willy Tarreau7c6f8a22018-07-26 08:03:14 +0200168}
169
Willy Tarreau9624fae2018-07-25 08:04:20 +0200170/* Removes the pendconn from the server/proxy queue. At this stage, the
171 * connection is not really dequeued. It will be done during process_stream().
Willy Tarreau9ada0302019-11-14 14:58:39 +0100172 * This function takes all the required locks for the operation. The pendconn
173 * must be valid, though it doesn't matter if it was already unlinked. Prefer
Willy Tarreau87154e32021-08-31 17:21:39 +0200174 * pendconn_cond_unlink() to first check <p>. It also forces a serialization
175 * on p->del_lock to make sure another thread currently waking it up finishes
176 * first.
Willy Tarreau9624fae2018-07-25 08:04:20 +0200177 */
178void pendconn_unlink(struct pendconn *p)
179{
Willy Tarreau51c63f02021-06-23 16:43:45 +0200180 struct queue *q = p->queue;
181 struct proxy *px = q->px;
182 struct server *sv = q->sv;
Willy Tarreaud03adce2021-06-23 16:54:16 +0200183 uint oldidx;
184 int done = 0;
Willy Tarreau96bca332020-10-21 12:01:28 +0200185
Willy Tarreaud03adce2021-06-23 16:54:16 +0200186 oldidx = _HA_ATOMIC_LOAD(&p->queue->idx);
187 HA_SPIN_LOCK(QUEUE_LOCK, &q->lock);
Willy Tarreau87154e32021-08-31 17:21:39 +0200188 HA_SPIN_LOCK(QUEUE_LOCK, &p->del_lock);
189
Willy Tarreaud03adce2021-06-23 16:54:16 +0200190 if (p->node.node.leaf_p) {
191 eb32_delete(&p->node);
192 done = 1;
Willy Tarreau3e3ae252020-10-21 11:20:07 +0200193 }
Willy Tarreau87154e32021-08-31 17:21:39 +0200194
195 HA_SPIN_UNLOCK(QUEUE_LOCK, &p->del_lock);
Willy Tarreaud03adce2021-06-23 16:54:16 +0200196 HA_SPIN_UNLOCK(QUEUE_LOCK, &q->lock);
197
198 if (done) {
199 oldidx -= p->queue_idx;
200 if (sv)
201 p->strm->logs.srv_queue_pos += oldidx;
202 else
203 p->strm->logs.prx_queue_pos += oldidx;
204
205 _HA_ATOMIC_DEC(&q->length);
206 _HA_ATOMIC_DEC(&px->totpend);
Willy Tarreau3e3ae252020-10-21 11:20:07 +0200207 }
Willy Tarreau9624fae2018-07-25 08:04:20 +0200208}
209
Willy Tarreau2bf3f2c2021-06-24 07:20:26 +0200210/* Retrieve the first pendconn from tree <pendconns>. Classes are always
211 * considered first, then the time offset. The time does wrap, so the
212 * lookup is performed twice, one to retrieve the first class and a second
213 * time to retrieve the earliest time in this class.
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400214 */
Willy Tarreau2bf3f2c2021-06-24 07:20:26 +0200215static struct pendconn *pendconn_first(struct eb_root *pendconns)
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400216{
217 struct eb32_node *node, *node2 = NULL;
218 u32 key;
219
Willy Tarreau2bf3f2c2021-06-24 07:20:26 +0200220 node = eb32_first(pendconns);
221 if (!node)
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400222 return NULL;
223
224 key = KEY_CLASS_OFFSET_BOUNDARY(node->key);
Willy Tarreau2bf3f2c2021-06-24 07:20:26 +0200225 node2 = eb32_lookup_ge(pendconns, key);
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400226
227 if (!node2 ||
228 KEY_CLASS(node2->key) != KEY_CLASS(node->key)) {
229 /* no other key in the tree, or in this class */
230 return eb32_entry(node, struct pendconn, node);
231 }
232
233 /* found a better key */
234 return eb32_entry(node2, struct pendconn, node);
235}
236
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100237/* Process the next pending connection from either a server or a proxy, and
Christopher Fauletfd83f0b2018-03-19 15:22:09 +0100238 * returns a strictly positive value on success (see below). If no pending
239 * connection is found, 0 is returned. Note that neither <srv> nor <px> may be
240 * NULL. Priority is given to the oldest request in the queue if both <srv> and
241 * <px> have pending requests. This ensures that no request will be left
242 * unserved. The <px> queue is not considered if the server (or a tracked
243 * server) is not RUNNING, is disabled, or has a null weight (server going
244 * down). The <srv> queue is still considered in this case, because if some
245 * connections remain there, it means that some requests have been forced there
246 * after it was seen down (eg: due to option persist). The stream is
247 * immediately marked as "assigned", and both its <srv> and <srv_conn> are set
248 * to <srv>.
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100249 *
Willy Tarreaua0e9c552021-06-18 19:45:17 +0200250 * The proxy's queue will be consulted only if px_ok is non-zero.
251 *
Willy Tarreau87154e32021-08-31 17:21:39 +0200252 * This function must only be called if the server queue is locked _AND_ the
253 * proxy queue is not. Today it is only called by process_srv_queue.
Willy Tarreaua0e9c552021-06-18 19:45:17 +0200254 * When a pending connection is dequeued, this function returns 1 if a pendconn
255 * is dequeued, otherwise 0.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200256 */
Willy Tarreaua0e9c552021-06-18 19:45:17 +0200257static int pendconn_process_next_strm(struct server *srv, struct proxy *px, int px_ok)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200258{
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100259 struct pendconn *p = NULL;
Patrick Hemmerda282f42018-05-11 12:52:31 -0400260 struct pendconn *pp = NULL;
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400261 u32 pkey, ppkey;
Willy Tarreaud132f742010-08-06 10:08:23 +0200262
Willy Tarreau2bf3f2c2021-06-24 07:20:26 +0200263 p = NULL;
Willy Tarreau90a160a2021-06-24 07:21:59 +0200264 if (srv->queue.length)
Willy Tarreau2bf3f2c2021-06-24 07:20:26 +0200265 p = pendconn_first(&srv->queue.head);
Willy Tarreau2bf3f2c2021-06-24 07:20:26 +0200266
267 pp = NULL;
Willy Tarreau49667c12021-06-24 08:04:24 +0200268 if (px_ok && px->queue.length) {
269 /* the lock only remains held as long as the pp is
270 * in the proxy's queue.
271 */
Willy Tarreau47ee44f2021-06-24 16:00:18 +0200272 HA_SPIN_LOCK(QUEUE_LOCK, &px->queue.lock);
Willy Tarreau2bf3f2c2021-06-24 07:20:26 +0200273 pp = pendconn_first(&px->queue.head);
Willy Tarreau49667c12021-06-24 08:04:24 +0200274 if (!pp)
Willy Tarreau47ee44f2021-06-24 16:00:18 +0200275 HA_SPIN_UNLOCK(QUEUE_LOCK, &px->queue.lock);
Willy Tarreau49667c12021-06-24 08:04:24 +0200276 }
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100277
Willy Tarreau5343d8e2021-06-24 07:22:03 +0200278 if (!p && !pp)
Willy Tarreaua48905b2021-06-24 07:27:01 +0200279 return 0;
Christopher Fauletcd7126b2021-02-11 11:13:33 +0100280 else if (!pp)
281 goto use_p; /* p != NULL */
282 else if (!p)
283 goto use_pp; /* pp != NULL */
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100284
Christopher Fauletcd7126b2021-02-11 11:13:33 +0100285 /* p != NULL && pp != NULL*/
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100286
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400287 if (KEY_CLASS(p->node.key) < KEY_CLASS(pp->node.key))
288 goto use_p;
289
290 if (KEY_CLASS(pp->node.key) < KEY_CLASS(p->node.key))
291 goto use_pp;
292
293 pkey = KEY_OFFSET(p->node.key);
294 ppkey = KEY_OFFSET(pp->node.key);
295
296 if (pkey < NOW_OFFSET_BOUNDARY())
297 pkey += 0x100000; // key in the future
298
299 if (ppkey < NOW_OFFSET_BOUNDARY())
300 ppkey += 0x100000; // key in the future
301
302 if (pkey <= ppkey)
303 goto use_p;
304
305 use_pp:
Willy Tarreau87154e32021-08-31 17:21:39 +0200306 /* we'd like to release the proxy lock ASAP to let other threads
307 * work with other servers. But for this we must first hold the
308 * pendconn alive to prevent a removal from its owning stream.
309 */
310 HA_SPIN_LOCK(QUEUE_LOCK, &pp->del_lock);
311
312 /* now the element won't go, we can release the proxy */
Willy Tarreau3e3ae252020-10-21 11:20:07 +0200313 __pendconn_unlink_prx(pp);
Willy Tarreau87154e32021-08-31 17:21:39 +0200314 HA_SPIN_UNLOCK(QUEUE_LOCK, &px->queue.lock);
315
316 pp->strm_flags |= SF_ASSIGNED;
317 pp->target = srv;
318 stream_add_srv_conn(pp->strm, srv);
319
320 /* we must wake the task up before releasing the lock as it's the only
321 * way to make sure the task still exists. The pendconn cannot vanish
322 * under us since the task will need to take the lock anyway and to wait
323 * if it wakes up on a different thread.
324 */
Willy Tarreau27fab1d2022-04-22 18:37:56 +0200325 task_instant_wakeup(pp->strm->task, TASK_WOKEN_RES);
Willy Tarreau87154e32021-08-31 17:21:39 +0200326 HA_SPIN_UNLOCK(QUEUE_LOCK, &pp->del_lock);
327
Willy Tarreau7f3c1df2021-06-18 09:22:21 +0200328 _HA_ATOMIC_DEC(&px->queue.length);
Willy Tarreau98c89102021-06-18 10:51:58 +0200329 _HA_ATOMIC_INC(&px->queue.idx);
Willy Tarreau87154e32021-08-31 17:21:39 +0200330 return 1;
331
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400332 use_p:
Willy Tarreau87154e32021-08-31 17:21:39 +0200333 /* we don't need the px queue lock anymore, we have the server's lock */
Willy Tarreau49667c12021-06-24 08:04:24 +0200334 if (pp)
Willy Tarreau87154e32021-08-31 17:21:39 +0200335 HA_SPIN_UNLOCK(QUEUE_LOCK, &px->queue.lock);
336
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100337 p->strm_flags |= SF_ASSIGNED;
Willy Tarreau88930dd2018-07-26 07:38:54 +0200338 p->target = srv;
Willy Tarreaua48905b2021-06-24 07:27:01 +0200339 stream_add_srv_conn(p->strm, srv);
340
Willy Tarreau87154e32021-08-31 17:21:39 +0200341 /* we must wake the task up before releasing the lock as it's the only
342 * way to make sure the task still exists. The pendconn cannot vanish
343 * under us since the task will need to take the lock anyway and to wait
344 * if it wakes up on a different thread.
345 */
Willy Tarreau27fab1d2022-04-22 18:37:56 +0200346 task_instant_wakeup(p->strm->task, TASK_WOKEN_RES);
Willy Tarreau87154e32021-08-31 17:21:39 +0200347 __pendconn_unlink_srv(p);
Willy Tarreaua48905b2021-06-24 07:27:01 +0200348
Willy Tarreau87154e32021-08-31 17:21:39 +0200349 _HA_ATOMIC_DEC(&srv->queue.length);
350 _HA_ATOMIC_INC(&srv->queue.idx);
Willy Tarreaua48905b2021-06-24 07:27:01 +0200351 return 1;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200352}
353
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100354/* Manages a server's connection queue. This function will try to dequeue as
Willy Tarreau9ab78292021-06-22 18:47:51 +0200355 * many pending streams as possible, and wake them up.
Christopher Faulet87566c92017-06-06 10:34:51 +0200356 */
Willy Tarreau9ab78292021-06-22 18:47:51 +0200357void process_srv_queue(struct server *s)
Christopher Faulet87566c92017-06-06 10:34:51 +0200358{
Willy Tarreaua0e9c552021-06-18 19:45:17 +0200359 struct server *ref = s->track ? s->track : s;
Christopher Faulet87566c92017-06-06 10:34:51 +0200360 struct proxy *p = s->proxy;
Olivier Houchardecfe6732018-07-26 18:47:27 +0200361 int maxconn;
Willy Tarreau19c55812021-06-24 15:51:12 +0200362 int stop = 0;
Willy Tarreau9cef43a2021-06-24 07:47:08 +0200363 int done = 0;
Willy Tarreaua0e9c552021-06-18 19:45:17 +0200364 int px_ok;
365
366 /* if a server is not usable or backup and must not be used
367 * to dequeue backend requests.
368 */
369 px_ok = srv_currently_usable(ref) &&
370 (!(s->flags & SRV_F_BACKUP) ||
371 (!p->srv_act &&
372 (s == p->lbprm.fbck || (p->options & PR_O_USE_ALL_BK))));
Christopher Faulet87566c92017-06-06 10:34:51 +0200373
Willy Tarreauae0b12e2021-06-24 08:30:07 +0200374 /* let's repeat that under the lock on each round. Threads competing
375 * for the same server will give up, knowing that at least one of
376 * them will check the conditions again before quitting.
377 */
Willy Tarreau19c55812021-06-24 15:51:12 +0200378 while (!stop && s->served < (maxconn = srv_dynamic_maxconn(s))) {
Willy Tarreau47ee44f2021-06-24 16:00:18 +0200379 if (HA_SPIN_TRYLOCK(QUEUE_LOCK, &s->queue.lock) != 0)
Christopher Faulet87566c92017-06-06 10:34:51 +0200380 break;
Willy Tarreauae0b12e2021-06-24 08:30:07 +0200381
382 while (s->served < maxconn) {
Willy Tarreau19c55812021-06-24 15:51:12 +0200383 stop = !pendconn_process_next_strm(s, p, px_ok);
384 if (stop)
Willy Tarreauae0b12e2021-06-24 08:30:07 +0200385 break;
386 _HA_ATOMIC_INC(&s->served);
387 done++;
388 }
Willy Tarreau47ee44f2021-06-24 16:00:18 +0200389 HA_SPIN_UNLOCK(QUEUE_LOCK, &s->queue.lock);
Christopher Faulet87566c92017-06-06 10:34:51 +0200390 }
Willy Tarreau9cef43a2021-06-24 07:47:08 +0200391
392 if (done) {
393 _HA_ATOMIC_SUB(&p->totpend, done);
394 _HA_ATOMIC_ADD(&p->served, done);
395 __ha_barrier_atomic_store();
396 if (p->lbprm.server_take_conn)
397 p->lbprm.server_take_conn(s);
398 }
Christopher Faulet87566c92017-06-06 10:34:51 +0200399}
400
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400401/* Adds the stream <strm> to the pending connection queue of server <strm>->srv
Willy Tarreau87b09662015-04-03 00:22:06 +0200402 * or to the one of <strm>->proxy if srv is NULL. All counters and back pointers
Willy Tarreaubaaee002006-06-26 02:48:02 +0200403 * are updated accordingly. Returns NULL if no memory is available, otherwise the
Willy Tarreau87b09662015-04-03 00:22:06 +0200404 * pendconn itself. If the stream was already marked as served, its flag is
405 * cleared. It is illegal to call this function with a non-NULL strm->srv_conn.
Patrick Hemmerda282f42018-05-11 12:52:31 -0400406 * The stream's queue position is counted with an offset of -1 because we want
407 * to make sure that being at the first position in the queue reports 1.
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100408 *
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400409 * The queue is sorted by the composition of the priority_class, and the current
410 * timestamp offset by strm->priority_offset. The timestamp is in milliseconds
411 * and truncated to 20 bits, so will wrap every 17m28s575ms.
412 * The offset can be positive or negative, and an offset of 0 puts it in the
413 * middle of this range (~ 8 min). Note that this also means if the adjusted
414 * timestamp wraps around, the request will be misinterpreted as being of
Joseph Herlantd8499ec2018-11-25 11:26:48 -0800415 * the highest priority for that priority class.
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400416 *
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100417 * This function must be called by the stream itself, so in the context of
418 * process_stream.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200419 */
Willy Tarreau87b09662015-04-03 00:22:06 +0200420struct pendconn *pendconn_add(struct stream *strm)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200421{
422 struct pendconn *p;
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100423 struct proxy *px;
424 struct server *srv;
Willy Tarreau12529c02021-06-18 10:21:20 +0200425 struct queue *q;
426 unsigned int *max_ptr;
427 unsigned int old_max, new_max;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200428
Willy Tarreaubafbe012017-11-24 17:34:44 +0100429 p = pool_alloc(pool_head_pendconn);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200430 if (!p)
431 return NULL;
432
Willy Tarreau88930dd2018-07-26 07:38:54 +0200433 p->target = NULL;
Patrick Hemmer248cb4c2018-05-11 12:52:31 -0400434 p->node.key = MAKE_KEY(strm->priority_class, strm->priority_offset);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100435 p->strm = strm;
436 p->strm_flags = strm->flags;
Willy Tarreau87154e32021-08-31 17:21:39 +0200437 HA_SPIN_INIT(&p->del_lock);
Willy Tarreau901972e2021-06-18 10:33:47 +0200438 strm->pend_pos = p;
Willy Tarreau7c669d72008-06-20 15:04:11 +0200439
Willy Tarreau51c63f02021-06-23 16:43:45 +0200440 px = strm->be;
441 if (strm->flags & SF_ASSIGNED)
442 srv = objt_server(strm->target);
443 else
444 srv = NULL;
445
Willy Tarreau7c6f8a22018-07-26 08:03:14 +0200446 if (srv) {
Willy Tarreau12529c02021-06-18 10:21:20 +0200447 q = &srv->queue;
448 max_ptr = &srv->counters.nbpend_max;
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100449 }
450 else {
Willy Tarreau12529c02021-06-18 10:21:20 +0200451 q = &px->queue;
452 max_ptr = &px->be_counters.nbpend_max;
453 }
Willy Tarreau3eecdb62021-06-18 10:21:20 +0200454
Willy Tarreau84290972021-06-23 16:33:52 +0200455 p->queue = q;
Willy Tarreau98c89102021-06-18 10:51:58 +0200456 p->queue_idx = _HA_ATOMIC_LOAD(&q->idx) - 1; // for logging only
Willy Tarreau12529c02021-06-18 10:21:20 +0200457 new_max = _HA_ATOMIC_ADD_FETCH(&q->length, 1);
458 old_max = _HA_ATOMIC_LOAD(max_ptr);
459 while (new_max > old_max) {
460 if (likely(_HA_ATOMIC_CAS(max_ptr, &old_max, new_max)))
461 break;
Willy Tarreau58f4dfb2021-06-24 07:22:15 +0200462 }
Willy Tarreau12529c02021-06-18 10:21:20 +0200463 __ha_barrier_atomic_store();
464
465 HA_SPIN_LOCK(QUEUE_LOCK, &q->lock);
Willy Tarreau12529c02021-06-18 10:21:20 +0200466 eb32_insert(&q->head, &p->node);
467 HA_SPIN_UNLOCK(QUEUE_LOCK, &q->lock);
Willy Tarreau7c6f8a22018-07-26 08:03:14 +0200468
Willy Tarreau4781b152021-04-06 13:53:36 +0200469 _HA_ATOMIC_INC(&px->totpend);
Willy Tarreaubaaee002006-06-26 02:48:02 +0200470 return p;
471}
472
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200473/* Redistribute pending connections when a server goes down. The number of
Willy Tarreau16fbdda2021-06-18 09:45:27 +0200474 * connections redistributed is returned. It will take the server queue lock
475 * and does not use nor depend on other locks.
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200476 */
477int pendconn_redistribute(struct server *s)
478{
Patrick Hemmer0355dab2018-05-11 12:52:31 -0400479 struct pendconn *p;
Willy Tarreaubff005a2019-05-27 08:10:11 +0200480 struct eb32_node *node, *nodeb;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200481 int xferred = 0;
482
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100483 /* The REDISP option was specified. We will ignore cookie and force to
484 * balance or use the dispatcher. */
485 if ((s->proxy->options & (PR_O_REDISP|PR_O_PERSIST)) != PR_O_REDISP)
486 return 0;
487
Willy Tarreau47ee44f2021-06-24 16:00:18 +0200488 HA_SPIN_LOCK(QUEUE_LOCK, &s->queue.lock);
Willy Tarreaua0570452021-06-18 09:30:30 +0200489 for (node = eb32_first(&s->queue.head); node; node = nodeb) {
Willy Tarreaubff005a2019-05-27 08:10:11 +0200490 nodeb = eb32_next(node);
491
492 p = eb32_entry(node, struct pendconn, node);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100493 if (p->strm_flags & SF_FORCE_PRST)
494 continue;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200495
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100496 /* it's left to the dispatcher to choose a server */
Willy Tarreau3e3ae252020-10-21 11:20:07 +0200497 __pendconn_unlink_srv(p);
Willy Tarreau03bd3952022-05-02 16:36:47 +0200498 p->strm_flags &= ~(SF_DIRECT | SF_ASSIGNED);
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200499
Willy Tarreau27fab1d2022-04-22 18:37:56 +0200500 task_instant_wakeup(p->strm->task, TASK_WOKEN_RES);
Willy Tarreauef71f012020-10-21 11:54:38 +0200501 xferred++;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200502 }
Willy Tarreau47ee44f2021-06-24 16:00:18 +0200503 HA_SPIN_UNLOCK(QUEUE_LOCK, &s->queue.lock);
Willy Tarreau16fbdda2021-06-18 09:45:27 +0200504
Willy Tarreau96bca332020-10-21 12:01:28 +0200505 if (xferred) {
Willy Tarreaua0570452021-06-18 09:30:30 +0200506 _HA_ATOMIC_SUB(&s->queue.length, xferred);
Willy Tarreau5472aa52020-10-24 12:57:41 +0200507 _HA_ATOMIC_SUB(&s->proxy->totpend, xferred);
Willy Tarreau96bca332020-10-21 12:01:28 +0200508 }
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200509 return xferred;
510}
511
512/* Check for pending connections at the backend, and assign some of them to
513 * the server coming up. The server's weight is checked before being assigned
514 * connections it may not be able to handle. The total number of transferred
Willy Tarreau16fbdda2021-06-18 09:45:27 +0200515 * connections is returned. It will take the proxy's queue lock and will not
516 * use nor depend on other locks.
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200517 */
518int pendconn_grab_from_px(struct server *s)
519{
Patrick Hemmer0355dab2018-05-11 12:52:31 -0400520 struct pendconn *p;
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100521 int maxconn, xferred = 0;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200522
Emeric Brun52a91d32017-08-31 14:41:55 +0200523 if (!srv_currently_usable(s))
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200524 return 0;
525
Willy Tarreaua8694652018-08-07 10:44:58 +0200526 /* if this is a backup server and there are active servers or at
527 * least another backup server was elected, then this one must
528 * not dequeue requests from the proxy.
529 */
530 if ((s->flags & SRV_F_BACKUP) &&
531 (s->proxy->srv_act ||
532 ((s != s->proxy->lbprm.fbck) && !(s->proxy->options & PR_O_USE_ALL_BK))))
533 return 0;
534
Willy Tarreau16fbdda2021-06-18 09:45:27 +0200535 HA_SPIN_LOCK(QUEUE_LOCK, &s->proxy->queue.lock);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100536 maxconn = srv_dynamic_maxconn(s);
Willy Tarreau2bf3f2c2021-06-24 07:20:26 +0200537 while ((p = pendconn_first(&s->proxy->queue.head))) {
538 if (s->maxconn && s->served + xferred >= maxconn)
539 break;
Willy Tarreau772e9682021-06-18 20:32:50 +0200540
Willy Tarreau2bf3f2c2021-06-24 07:20:26 +0200541 __pendconn_unlink_prx(p);
Willy Tarreau88930dd2018-07-26 07:38:54 +0200542 p->target = s;
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100543
Willy Tarreau27fab1d2022-04-22 18:37:56 +0200544 task_instant_wakeup(p->strm->task, TASK_WOKEN_RES);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100545 xferred++;
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200546 }
Willy Tarreau16fbdda2021-06-18 09:45:27 +0200547 HA_SPIN_UNLOCK(QUEUE_LOCK, &s->proxy->queue.lock);
Willy Tarreau96bca332020-10-21 12:01:28 +0200548 if (xferred) {
Willy Tarreau7f3c1df2021-06-18 09:22:21 +0200549 _HA_ATOMIC_SUB(&s->proxy->queue.length, xferred);
Willy Tarreau5472aa52020-10-24 12:57:41 +0200550 _HA_ATOMIC_SUB(&s->proxy->totpend, xferred);
Willy Tarreau96bca332020-10-21 12:01:28 +0200551 }
Willy Tarreau4aac7db2014-05-16 11:48:10 +0200552 return xferred;
553}
554
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100555/* Try to dequeue pending connection attached to the stream <strm>. It must
556 * always exists here. If the pendconn is still linked to the server or the
557 * proxy queue, nothing is done and the function returns 1. Otherwise,
558 * <strm>->flags and <strm>->target are updated, the pendconn is released and 0
559 * is returned.
560 *
561 * This function must be called by the stream itself, so in the context of
562 * process_stream.
Willy Tarreaubaaee002006-06-26 02:48:02 +0200563 */
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100564int pendconn_dequeue(struct stream *strm)
Willy Tarreaubaaee002006-06-26 02:48:02 +0200565{
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100566 struct pendconn *p;
Willy Tarreau3201e4e2018-07-26 08:23:24 +0200567 int is_unlinked;
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100568
Tim Duesterhuscc8348f2022-02-28 19:16:31 +0100569 /* unexpected case because it is called by the stream itself and
570 * only the stream can release a pendconn. So it is only
571 * possible if a pendconn is released by someone else or if the
572 * stream is supposed to be queued but without its associated
573 * pendconn. In both cases it is a bug! */
574 BUG_ON(!strm->pend_pos);
575
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100576 p = strm->pend_pos;
Willy Tarreau3201e4e2018-07-26 08:23:24 +0200577
578 /* note below : we need to grab the queue's lock to check for emptiness
579 * because we don't want a partial _grab_from_px() or _redistribute()
580 * to be called in parallel and show an empty list without having the
581 * time to finish. With this we know that if we see the element
582 * unlinked, these functions were completely done.
583 */
584 pendconn_queue_lock(p);
Patrick Hemmer0355dab2018-05-11 12:52:31 -0400585 is_unlinked = !p->node.node.leaf_p;
Willy Tarreau3201e4e2018-07-26 08:23:24 +0200586 pendconn_queue_unlock(p);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100587
Willy Tarreau87154e32021-08-31 17:21:39 +0200588 /* serialize to make sure the element was finished processing */
589 HA_SPIN_LOCK(QUEUE_LOCK, &p->del_lock);
590 HA_SPIN_UNLOCK(QUEUE_LOCK, &p->del_lock);
591
Willy Tarreau3201e4e2018-07-26 08:23:24 +0200592 if (!is_unlinked)
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100593 return 1;
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100594
Willy Tarreau3201e4e2018-07-26 08:23:24 +0200595 /* the pendconn is not queued anymore and will not be so we're safe
596 * to proceed.
597 */
Willy Tarreau03bd3952022-05-02 16:36:47 +0200598 strm->flags &= ~(SF_DIRECT | SF_ASSIGNED);
599 strm->flags |= p->strm_flags & (SF_DIRECT | SF_ASSIGNED);
Willy Tarreau7867ceb2021-06-16 08:42:23 +0200600
Willy Tarreau266d5402021-12-24 11:27:53 +0100601 /* the entry might have been redistributed to another server */
Willy Tarreau03bd3952022-05-02 16:36:47 +0200602 if (!(strm->flags & SF_ASSIGNED))
Christopher Faulet8da67aa2022-03-29 17:53:09 +0200603 sockaddr_free(&strm->csb->dst);
Willy Tarreau266d5402021-12-24 11:27:53 +0100604
Willy Tarreau7867ceb2021-06-16 08:42:23 +0200605 if (p->target) {
606 /* a server picked this pendconn, it must skip LB */
607 strm->target = &p->target->obj_type;
608 strm->flags |= SF_ASSIGNED;
609 }
610
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100611 strm->pend_pos = NULL;
Willy Tarreaubafbe012017-11-24 17:34:44 +0100612 pool_free(pool_head_pendconn, p);
Christopher Faulet5cd4bbd2018-03-14 16:18:06 +0100613 return 0;
Willy Tarreaubaaee002006-06-26 02:48:02 +0200614}
615
Patrick Hemmer268a7072018-05-11 12:52:31 -0400616static enum act_return action_set_priority_class(struct act_rule *rule, struct proxy *px,
617 struct session *sess, struct stream *s, int flags)
618{
619 struct sample *smp;
620
621 smp = sample_fetch_as_type(px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.expr, SMP_T_SINT);
622 if (!smp)
623 return ACT_RET_CONT;
624
625 s->priority_class = queue_limit_class(smp->data.u.sint);
626 return ACT_RET_CONT;
627}
628
629static enum act_return action_set_priority_offset(struct act_rule *rule, struct proxy *px,
630 struct session *sess, struct stream *s, int flags)
631{
632 struct sample *smp;
633
634 smp = sample_fetch_as_type(px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.expr, SMP_T_SINT);
635 if (!smp)
636 return ACT_RET_CONT;
637
638 s->priority_offset = queue_limit_offset(smp->data.u.sint);
639
640 return ACT_RET_CONT;
641}
642
643static enum act_parse_ret parse_set_priority_class(const char **args, int *arg, struct proxy *px,
644 struct act_rule *rule, char **err)
645{
646 unsigned int where = 0;
647
648 rule->arg.expr = sample_parse_expr((char **)args, arg, px->conf.args.file,
Willy Tarreaue3b57bf2020-02-14 16:50:14 +0100649 px->conf.args.line, err, &px->conf.args, NULL);
Patrick Hemmer268a7072018-05-11 12:52:31 -0400650 if (!rule->arg.expr)
651 return ACT_RET_PRS_ERR;
652
653 if (px->cap & PR_CAP_FE)
654 where |= SMP_VAL_FE_HRQ_HDR;
655 if (px->cap & PR_CAP_BE)
656 where |= SMP_VAL_BE_HRQ_HDR;
657
658 if (!(rule->arg.expr->fetch->val & where)) {
659 memprintf(err,
660 "fetch method '%s' extracts information from '%s', none of which is available here",
661 args[0], sample_src_names(rule->arg.expr->fetch->use));
662 free(rule->arg.expr);
663 return ACT_RET_PRS_ERR;
664 }
665
666 rule->action = ACT_CUSTOM;
667 rule->action_ptr = action_set_priority_class;
668 return ACT_RET_PRS_OK;
669}
670
671static enum act_parse_ret parse_set_priority_offset(const char **args, int *arg, struct proxy *px,
672 struct act_rule *rule, char **err)
673{
674 unsigned int where = 0;
675
676 rule->arg.expr = sample_parse_expr((char **)args, arg, px->conf.args.file,
Willy Tarreaue3b57bf2020-02-14 16:50:14 +0100677 px->conf.args.line, err, &px->conf.args, NULL);
Patrick Hemmer268a7072018-05-11 12:52:31 -0400678 if (!rule->arg.expr)
679 return ACT_RET_PRS_ERR;
680
681 if (px->cap & PR_CAP_FE)
682 where |= SMP_VAL_FE_HRQ_HDR;
683 if (px->cap & PR_CAP_BE)
684 where |= SMP_VAL_BE_HRQ_HDR;
685
686 if (!(rule->arg.expr->fetch->val & where)) {
687 memprintf(err,
688 "fetch method '%s' extracts information from '%s', none of which is available here",
689 args[0], sample_src_names(rule->arg.expr->fetch->use));
690 free(rule->arg.expr);
691 return ACT_RET_PRS_ERR;
692 }
693
694 rule->action = ACT_CUSTOM;
695 rule->action_ptr = action_set_priority_offset;
696 return ACT_RET_PRS_OK;
697}
698
699static struct action_kw_list tcp_cont_kws = {ILH, {
700 { "set-priority-class", parse_set_priority_class },
701 { "set-priority-offset", parse_set_priority_offset },
702 { /* END */ }
703}};
704
Willy Tarreau0108d902018-11-25 19:14:37 +0100705INITCALL1(STG_REGISTER, tcp_req_cont_keywords_register, &tcp_cont_kws);
706
Patrick Hemmer268a7072018-05-11 12:52:31 -0400707static struct action_kw_list http_req_kws = {ILH, {
708 { "set-priority-class", parse_set_priority_class },
709 { "set-priority-offset", parse_set_priority_offset },
710 { /* END */ }
711}};
712
Willy Tarreau0108d902018-11-25 19:14:37 +0100713INITCALL1(STG_REGISTER, http_req_keywords_register, &http_req_kws);
714
Patrick Hemmer268a7072018-05-11 12:52:31 -0400715static int
716smp_fetch_priority_class(const struct arg *args, struct sample *smp, const char *kw, void *private)
717{
718 if (!smp->strm)
719 return 0;
720
721 smp->data.type = SMP_T_SINT;
722 smp->data.u.sint = smp->strm->priority_class;
723
724 return 1;
725}
726
727static int
728smp_fetch_priority_offset(const struct arg *args, struct sample *smp, const char *kw, void *private)
729{
730 if (!smp->strm)
731 return 0;
732
733 smp->data.type = SMP_T_SINT;
734 smp->data.u.sint = smp->strm->priority_offset;
735
736 return 1;
737}
738
739
740static struct sample_fetch_kw_list smp_kws = {ILH, {
741 { "prio_class", smp_fetch_priority_class, 0, NULL, SMP_T_SINT, SMP_USE_INTRN, },
742 { "prio_offset", smp_fetch_priority_offset, 0, NULL, SMP_T_SINT, SMP_USE_INTRN, },
743 { /* END */},
744}};
745
Willy Tarreau0108d902018-11-25 19:14:37 +0100746INITCALL1(STG_REGISTER, sample_register_fetches, &smp_kws);
Patrick Hemmer268a7072018-05-11 12:52:31 -0400747
Willy Tarreaubaaee002006-06-26 02:48:02 +0200748/*
749 * Local variables:
750 * c-indent-level: 8
751 * c-basic-offset: 8
752 * End:
753 */