]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pools: move the fault injector to __pool_alloc()
authorWilly Tarreau <w@1wt.eu>
Sat, 17 Apr 2021 14:00:08 +0000 (16:00 +0200)
committerWilly Tarreau <w@1wt.eu>
Mon, 19 Apr 2021 13:24:33 +0000 (15:24 +0200)
Till now it was limited to objects allocated from the OS which means
it had little use as soon as pools were enabled. Let's move it upper
in the layers so that any code can benefit from fault injection. In
addition this allows to pass a new flag POOL_F_NO_FAIL to disable it
if some callers prefer a no-failure approach.

include/haproxy/pool-t.h
include/haproxy/pool.h
src/pool.c

index 073fe3251a5aed9b066984df489317c8a9a72bbf..bbdc5365a0e0333c818785af4c04d0ff0a30f746 100644 (file)
@@ -80,6 +80,7 @@
 /* possible flags for __pool_alloc() */
 #define POOL_F_NO_POISON    0x00000001  // do not poison the area
 #define POOL_F_MUST_ZERO    0x00000002  // zero the returned area
+#define POOL_F_NO_FAIL      0x00000004  // do not randomly fail
 
 
 struct pool_cache_head {
index 6f0197115440086a147275661c5333b673cdbf25..0f76b9658338aa4d1c51e7a4f331f491a945b1df 100644 (file)
@@ -275,6 +275,11 @@ static inline void *__pool_alloc(struct pool_head *pool, unsigned int flags)
 {
        void *p;
 
+#ifdef DEBUG_FAIL_ALLOC
+       if (!(flags & POOL_F_NO_FAIL) && mem_should_fail(pool))
+               return NULL;
+#endif
+
 #ifdef CONFIG_HAP_POOLS
        if (likely(p = pool_get_from_local_cache(pool)))
                goto ret;
index 48cc46788bf788b1e024021332654d53177ca4c0..5939d961d192a5bc6cf51ac6dc331293e27ad974 100644 (file)
@@ -158,10 +158,6 @@ void *pool_alloc_nocache(struct pool_head *pool)
        int limit = pool->limit;
        void *ptr = NULL;
 
-#ifdef DEBUG_FAIL_ALLOC
-       if (mem_should_fail(pool))
-               return NULL;
-#endif
        if (limit && allocated >= limit) {
                activity[tid].pool_fail++;
                return NULL;