From: Aurelien DARRAGON Date: Thu, 5 Dec 2024 11:02:38 +0000 (+0100) Subject: CLEANUP: stktable: replace nopurge attribute with flag X-Git-Tag: v3.2-dev1~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9f44c5f9be5b59eeafc225701be937290f8b41c9;p=thirdparty%2Fhaproxy.git CLEANUP: stktable: replace nopurge attribute with flag Thanks to previous commit stktable struct now have a "flags" struct member Let's take this opportunity to remove the isolated "nopurge" attribute in stktable struct and rely on a flag named STK_FL_NOPURGE instead. This helps to better organize stktable struct members. --- diff --git a/include/haproxy/stick_table-t.h b/include/haproxy/stick_table-t.h index fcc79ceb63..43b6e5e8f7 100644 --- a/include/haproxy/stick_table-t.h +++ b/include/haproxy/stick_table-t.h @@ -159,6 +159,7 @@ struct stksess { #define STK_FL_RECV_ONLY 0x01 /* table is assumed to be remotely updated only * (never updated locally) */ +#define STK_FL_NOPURGE 0x02 /* if non-zero, don't purge sticky sessions when full */ /* stick table */ struct stktable { @@ -183,12 +184,13 @@ struct stktable { size_t key_size; /* size of a key, maximum size in case of string */ unsigned int server_key_type; /* What type of key is used to identify servers */ unsigned int size; /* maximum number of sticky sessions in table */ - int nopurge; /* if non-zero, don't purge sticky sessions when full */ int expire; /* time to live for sticky sessions (milliseconds) */ int data_size; /* the size of the data that is prepended *before* stksess */ int data_ofs[STKTABLE_DATA_TYPES]; /* negative offsets of present data types, or 0 if absent */ unsigned int data_nbelem[STKTABLE_DATA_TYPES]; /* to store nb_elem in case of array types */ unsigned int brates_factor; /* Factor used for IN/OUT bytes rates */ + uint16_t flags; + /* 2-bytes hole */ union { int i; unsigned int u; @@ -201,8 +203,6 @@ struct stktable { void *ptr; /* generic ptr to check if set or not */ } write_to; /* updates received on the source table will also update write_to */ - uint16_t flags; - THREAD_ALIGN(64); struct { diff --git a/src/hlua_fcn.c b/src/hlua_fcn.c index b6252fbf1c..e14004b65d 100644 --- a/src/hlua_fcn.c +++ b/src/hlua_fcn.c @@ -823,7 +823,7 @@ int hlua_stktable_info(lua_State *L) lua_settable(L, -3); lua_pushstring(L, "nopurge"); - lua_pushboolean(L, tbl->nopurge > 0); + lua_pushboolean(L, (tbl->flags & STK_FL_NOPURGE)); lua_settable(L, -3); lua_pushstring(L, "expire"); diff --git a/src/stick_table.c b/src/stick_table.c index a18d89309c..1da4296b85 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -396,7 +396,8 @@ struct stksess *stksess_new(struct stktable *t, struct stktable_key *key) if (unlikely(current >= t->size)) { /* the table was already full, we may have to purge entries */ - if (t->nopurge || !stktable_trash_oldest(t, (t->size >> 8) + 1)) { + if ((t->flags & STK_FL_NOPURGE) || + !stktable_trash_oldest(t, (t->size >> 8) + 1)) { HA_ATOMIC_DEC(&t->current); return NULL; } @@ -1248,7 +1249,7 @@ int parse_stick_table(const char *file, int linenum, char **args, idx++; } else if (strcmp(args[idx], "nopurge") == 0) { - t->nopurge = 1; + t->flags |= STK_FL_NOPURGE; idx++; } else if (strcmp(args[idx], "type") == 0) {