diff --git a/include/haproxy/session.h b/include/haproxy/session.h index 9fd540a6d..f0731c711 100644 --- a/include/haproxy/session.h +++ b/include/haproxy/session.h @@ -78,7 +78,7 @@ static inline void session_store_counters(struct session *sess) } stkctr_set_entry(stkctr, NULL); - stksess_kill_if_expired(stkctr->table, ts, 1); + stksess_kill_if_expired(stkctr->table, ts); } } diff --git a/include/haproxy/stick_table.h b/include/haproxy/stick_table.h index 3e10db107..4132af129 100644 --- a/include/haproxy/stick_table.h +++ b/include/haproxy/stick_table.h @@ -45,7 +45,7 @@ struct stktable *stktable_find_by_name(const char *name); struct stksess *stksess_new(struct stktable *t, struct stktable_key *key); void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key); void stksess_free(struct stktable *t, struct stksess *ts); -int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcount); +int stksess_kill(struct stktable *t, struct stksess *ts); int stktable_get_key_shard(struct stktable *t, const void *key, size_t len); int stktable_init(struct stktable *t, char **err_msg); @@ -215,7 +215,15 @@ static inline int __stksess_kill_if_expired(struct stktable *t, struct stksess * return 0; } -static inline void stksess_kill_if_expired(struct stktable *t, struct stksess *ts, int decrefcnt) +/* + * Decrease the refcount of a stksess and relase it if the refcount falls to 0 + * _AND_ if the session expired. Note,, the refcount is always decremented. + * + * This function locks the corresponding table shard to proceed. When this + * function is called, the caller must be sure it owns a reference on the + * stksess (refcount >= 1). + */ +static inline void stksess_kill_if_expired(struct stktable *t, struct stksess *ts) { uint shard; size_t len; @@ -232,11 +240,11 @@ static inline void stksess_kill_if_expired(struct stktable *t, struct stksess *t ALREADY_CHECKED(shard); HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock); - if (!decrefcnt || !HA_ATOMIC_SUB_FETCH(&ts->ref_cnt, 1)) + if (!HA_ATOMIC_SUB_FETCH(&ts->ref_cnt, 1)) __stksess_kill_if_expired(t, ts); HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock); } - else if (decrefcnt) + else HA_ATOMIC_SUB_FETCH(&ts->ref_cnt, 1); } diff --git a/include/haproxy/stream.h b/include/haproxy/stream.h index 12c58b891..6781249e8 100644 --- a/include/haproxy/stream.h +++ b/include/haproxy/stream.h @@ -140,7 +140,7 @@ static inline void stream_store_counters(struct stream *s) stktable_touch_local(s->stkctr[i].table, ts, 0); } stkctr_set_entry(&s->stkctr[i], NULL); - stksess_kill_if_expired(s->stkctr[i].table, ts, 1); + stksess_kill_if_expired(s->stkctr[i].table, ts); } } @@ -182,7 +182,7 @@ static inline void stream_stop_content_counters(struct stream *s) stktable_touch_local(s->stkctr[i].table, ts, 0); } stkctr_set_entry(&s->stkctr[i], NULL); - stksess_kill_if_expired(s->stkctr[i].table, ts, 1); + stksess_kill_if_expired(s->stkctr[i].table, ts); } } diff --git a/src/stick_table.c b/src/stick_table.c index 2b5eddd7b..f562a62a2 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -162,11 +162,14 @@ int __stksess_kill(struct stktable *t, struct stksess *ts) } /* - * Decrease the refcount if decrefcnt is not 0, and try to kill the stksess. + * Decrease the refcount of a stksess and relase it if the refcount falls to 0. * Returns non-zero if deleted, zero otherwise. - * This function locks the table + * + * This function locks the corresponding table shard to proceed. When this + * function is called, the caller must be sure it owns a reference on the + * stksess (refcount >= 1). */ -int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcnt) +int stksess_kill(struct stktable *t, struct stksess *ts) { uint shard; size_t len; @@ -183,7 +186,7 @@ int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcnt) ALREADY_CHECKED(shard); HA_RWLOCK_WRLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock); - if (!decrefcnt || !HA_ATOMIC_SUB_FETCH(&ts->ref_cnt, 1)) + if (!HA_ATOMIC_SUB_FETCH(&ts->ref_cnt, 1)) ret = __stksess_kill(t, ts); HA_RWLOCK_WRUNLOCK(STK_TABLE_LOCK, &t->shards[shard].sh_lock); @@ -5268,7 +5271,7 @@ static int table_process_entry(struct appctx *appctx, struct stksess *ts, char * break; case STK_CLI_ACT_CLR: - if (!stksess_kill(t, ts, 1)) { + if (!stksess_kill(t, ts)) { /* don't delete an entry which is currently referenced */ return cli_err(appctx, "Entry currently in use, cannot remove\n"); } @@ -5685,7 +5688,7 @@ static void cli_release_show_table(struct appctx *appctx) struct show_table_ctx *ctx = appctx->svcctx; if (ctx->state == STATE_DUMP) { - stksess_kill_if_expired(ctx->t, ctx->entry, 1); + stksess_kill_if_expired(ctx->t, ctx->entry); } }