]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: cache/filters: Initialize the cache filter when stream is created
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 6 Mar 2020 13:52:06 +0000 (14:52 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 6 Mar 2020 14:36:04 +0000 (15:36 +0100)
Since the HTX mode is the only mode to process HTTP messages, the stream is
created for a uniq transaction. The keep-alive is handled at the mux level. So,
the cache filter can be initialized when the stream is created and released with
the stream. Concretly, .channel_start_analyze and .channel_end_analyze callback
functions are replaced by .attach and .detach ones.

With this change, it is no longer necessary to call FLT_START_FE/BE and FLT_END
analysers for the cache filter.

src/cache.c

index 4a0051f00a507da0a622fc892310046884a0b214..7d53b2d5d8c746435d839b1221eebee5b40fa9a3 100644 (file)
@@ -200,55 +200,41 @@ cache_store_check(struct proxy *px, struct flt_conf *fconf)
 }
 
 static int
-cache_store_chn_start_analyze(struct stream *s, struct filter *filter, struct channel *chn)
+cache_store_strm_init(struct stream *s, struct filter *filter)
 {
-       if (!(chn->flags & CF_ISRESP))
-               return 1;
-
-       if (filter->ctx == NULL) {
-               struct cache_st *st;
+       struct cache_st *st;
 
-               st = pool_alloc_dirty(pool_head_cache_st);
-               if (st == NULL)
-                       return -1;
+       st = pool_alloc_dirty(pool_head_cache_st);
+       if (st == NULL)
+               return -1;
 
-               st->first_block = NULL;
-               filter->ctx     = st;
-
-               /* Register post-analyzer on AN_RES_WAIT_HTTP */
-               filter->post_analyzers |= AN_RES_WAIT_HTTP;
-       }
+       st->first_block = NULL;
+       filter->ctx     = st;
 
+       /* Register post-analyzer on AN_RES_WAIT_HTTP */
+       filter->post_analyzers |= AN_RES_WAIT_HTTP;
        return 1;
 }
 
-static int
-cache_store_chn_end_analyze(struct stream *s, struct filter *filter, struct channel *chn)
+static void
+cache_store_strm_deinit(struct stream *s, struct filter *filter)
 {
        struct cache_st *st = filter->ctx;
        struct cache_flt_conf *cconf = FLT_CONF(filter);
        struct cache *cache = cconf->c.cache;
        struct shared_context *shctx = shctx_ptr(cache);
 
-       if (!(chn->flags & CF_ISRESP))
-               return 1;
-
        /* Everything should be released in the http_end filter, but we need to do it
         * there too, in case of errors */
-
        if (st && st->first_block) {
-
                shctx_lock(shctx);
                shctx_row_dec_hot(shctx, st->first_block);
                shctx_unlock(shctx);
-
        }
        if (st) {
                pool_free(pool_head_cache_st, st);
                filter->ctx = NULL;
        }
-
-       return 1;
 }
 
 static int
@@ -1401,9 +1387,11 @@ struct flt_ops cache_ops = {
        .check  = cache_store_check,
        .deinit = cache_store_deinit,
 
+       /* Handle stream init/deinit */
+       .attach = cache_store_strm_init,
+       .detach = cache_store_strm_deinit,
+
        /* Handle channels activity */
-       .channel_start_analyze = cache_store_chn_start_analyze,
-       .channel_end_analyze = cache_store_chn_end_analyze,
        .channel_post_analyze = cache_store_post_analyze,
 
        /* Filter HTTP requests and responses */