From bddf4f33b865f00d24af6ad0d5fafe66028ab80d Mon Sep 17 00:00:00 2001 From: Alexander K Date: Sun, 4 Oct 2015 23:22:02 +0300 Subject: [PATCH] Unlink server response message from the connection when the response is cached --- tempesta_fw/cache.c | 11 +++++++++-- tempesta_fw/http.c | 8 ++++---- tempesta_fw/http.h | 1 - tempesta_fw/http_msg.c | 12 +++++++++--- tempesta_fw/http_msg.h | 1 + 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tempesta_fw/cache.c b/tempesta_fw/cache.c index 89219cb0b..3d90efc8d 100644 --- a/tempesta_fw/cache.c +++ b/tempesta_fw/cache.c @@ -162,7 +162,7 @@ tfw_cache_copy_str(char **p, TdbVRec **trec, TfwStr *src, size_t tot_len) TFW_DBG3("copy [%.*s](%u) to rec=%p(len=%u), p=%p" " tot_len=%lu room=%d copied=%ld\n", min(10, (int)src->len), (char *)src->ptr, src->len, - *trec, (*trec)->len, p, tot_len, room, copied); + *trec, (*trec)->len, *p, tot_len, room, copied); if (!room) { BUG_ON(tot_len < copied); @@ -269,6 +269,7 @@ tfw_cache_copy_resp(struct work_struct *work) TFW_ERR("Cache: cannot copy HTTP body\n"); goto err; } + tot_len -= n; ce->body_len += n; }); @@ -317,8 +318,14 @@ tfw_cache_add(TfwHttpResp *resp, TfwHttpReq *req) queue_work_on(tfw_cache_sched_work_cpu(numa_node_id()), cache_wq, (struct work_struct *)cw); - /* Request isn't needed anymore, response is cached. */ + /* + * Request isn't needed anymore, response is cached: + * free the first one and unlink from the connection the second one, + * so the server connection will create a new message when a new + * data arrives. + */ tfw_http_conn_msg_free((TfwHttpMsg *)req); + tfw_http_conn_msg_unlink((TfwHttpMsg *)resp); return; out: /* Now we don't need the request and the reponse anymore. */ diff --git a/tempesta_fw/http.c b/tempesta_fw/http.c index dd796235c..309154a98 100644 --- a/tempesta_fw/http.c +++ b/tempesta_fw/http.c @@ -545,8 +545,8 @@ tfw_http_req_process(TfwConnection *conn, struct sk_buff *skb, unsigned int off) BUG_ON(!conn->msg); BUG_ON(off >= skb_len); - TFW_DBG2("Received %u client data bytes on conn=%p\n", - skb_len - off, conn); + TFW_DBG2("Received %u client data bytes on conn=%p msg=%p\n", + skb_len - off, conn, conn->msg); /* * Process pipelined requests in a loop * until all data in the SKB is processed. @@ -676,8 +676,8 @@ tfw_http_resp_process(TfwConnection *conn, struct sk_buff *skb, BUG_ON(!hmresp); - TFW_DBG2("received %u server data bytes on conn=%p\n", - skb->len - off, conn); + TFW_DBG2("received %u server data bytes on conn=%p msg=%p\n", + skb->len - off, conn, hmresp); r = ss_skb_process(skb, &data_off, tfw_http_parse_resp, hmresp); hmresp->msg.len += data_off - off; diff --git a/tempesta_fw/http.h b/tempesta_fw/http.h index 7be0ac489..6da9bd3ec 100644 --- a/tempesta_fw/http.h +++ b/tempesta_fw/http.h @@ -277,7 +277,6 @@ typedef struct { #define FOR_EACH_HDR_FIELD_FROM(pos, end, msg, soff) \ __FOR_EACH_HDR_FIELD(pos, end, msg, soff, (msg)->h_tbl->off) - typedef void (*tfw_http_req_cache_cb_t)(TfwHttpReq *, TfwHttpResp *, void *); /* Internal (parser) HTTP functions. */ diff --git a/tempesta_fw/http_msg.c b/tempesta_fw/http_msg.c index 04894d33f..397891e78 100644 --- a/tempesta_fw/http_msg.c +++ b/tempesta_fw/http_msg.c @@ -669,16 +669,22 @@ tfw_http_msg_write(TfwMsgIter *it, TfwHttpMsg *hm, const TfwStr *data) return 0; } +void +tfw_http_conn_msg_unlink(TfwHttpMsg *m) +{ + if (m->conn && m->conn->msg == (TfwMsg *)m) + m->conn->msg = NULL; +} + void tfw_http_msg_free(TfwHttpMsg *m) { - TFW_DBG3("Free msg: %p\n", m); + TFW_DBG3("Free msg=%p\n", m); if (!m) return; - if (m->conn && m->conn->msg == (TfwMsg *)m) - m->conn->msg = NULL; + tfw_http_conn_msg_unlink(m); while (1) { /* diff --git a/tempesta_fw/http_msg.h b/tempesta_fw/http_msg.h index f4bc66e60..862584bd8 100644 --- a/tempesta_fw/http_msg.h +++ b/tempesta_fw/http_msg.h @@ -62,5 +62,6 @@ int tfw_http_msg_grow_hdr_tbl(TfwHttpMsg *hm); TfwHttpMsg *tfw_http_msg_alloc(int type); void tfw_http_msg_free(TfwHttpMsg *m); +void tfw_http_conn_msg_unlink(TfwHttpMsg *m); #endif /* __TFW_HTTP_MSG_H__ */