Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Server management functions. |
| 3 | * |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 4 | * Copyright 2000-2007 Willy Tarreau <w@1wt.eu> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <stdlib.h> |
Willy Tarreau | e3ba5f0 | 2006-06-29 18:54:54 +0200 | [diff] [blame] | 14 | |
| 15 | #include <common/config.h> |
Willy Tarreau | 2dd0d47 | 2006-06-29 17:53:05 +0200 | [diff] [blame] | 16 | #include <common/memory.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 17 | |
| 18 | #include <types/backend.h> |
| 19 | #include <types/capture.h> |
| 20 | #include <types/log.h> |
| 21 | #include <types/proxy.h> |
| 22 | #include <types/server.h> |
| 23 | |
Willy Tarreau | 7341d94 | 2007-05-13 19:56:02 +0200 | [diff] [blame] | 24 | #include <proto/buffers.h> |
Willy Tarreau | 8d5d7f2 | 2007-01-21 19:16:41 +0100 | [diff] [blame] | 25 | #include <proto/hdr_idx.h> |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 26 | #include <proto/log.h> |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 27 | #include <proto/session.h> |
| 28 | #include <proto/queue.h> |
| 29 | |
| 30 | |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 31 | struct pool_head *pool2_session; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * frees the context associated to a session. It must have been removed first. |
| 35 | */ |
| 36 | void session_free(struct session *s) |
| 37 | { |
Willy Tarreau | 4dbc4a2 | 2007-03-03 16:23:22 +0100 | [diff] [blame] | 38 | struct http_txn *txn = &s->txn; |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 39 | struct proxy *fe = s->fe; |
Willy Tarreau | 0f7562b | 2007-01-07 15:46:13 +0100 | [diff] [blame] | 40 | |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 41 | if (s->pend_pos) |
| 42 | pendconn_free(s->pend_pos); |
| 43 | if (s->req) |
Willy Tarreau | 7341d94 | 2007-05-13 19:56:02 +0200 | [diff] [blame] | 44 | pool_free2(pool2_buffer, s->req); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 45 | if (s->rep) |
Willy Tarreau | 7341d94 | 2007-05-13 19:56:02 +0200 | [diff] [blame] | 46 | pool_free2(pool2_buffer, s->rep); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 47 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 48 | if (fe) { |
| 49 | if (txn->hdr_idx.v != NULL) |
| 50 | pool_free2(fe->hdr_idx_pool, txn->hdr_idx.v); |
Willy Tarreau | 41dff82 | 2007-01-01 23:32:30 +0100 | [diff] [blame] | 51 | |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 52 | if (txn->rsp.cap != NULL) { |
| 53 | struct cap_hdr *h; |
| 54 | for (h = fe->rsp_cap; h; h = h->next) { |
| 55 | if (txn->rsp.cap[h->index] != NULL) |
| 56 | pool_free2(h->pool, txn->rsp.cap[h->index]); |
| 57 | } |
| 58 | pool_free2(fe->rsp_cap_pool, txn->rsp.cap); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 59 | } |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 60 | if (txn->req.cap != NULL) { |
| 61 | struct cap_hdr *h; |
| 62 | for (h = fe->req_cap; h; h = h->next) { |
| 63 | if (txn->req.cap[h->index] != NULL) |
| 64 | pool_free2(h->pool, txn->req.cap[h->index]); |
| 65 | } |
| 66 | pool_free2(fe->req_cap_pool, txn->req.cap); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 67 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 68 | } |
Willy Tarreau | 3bac9ff | 2007-03-18 17:31:28 +0100 | [diff] [blame] | 69 | if (txn->uri) |
Willy Tarreau | 332f8bf | 2007-05-13 21:36:56 +0200 | [diff] [blame] | 70 | pool_free2(pool2_requri, txn->uri); |
Willy Tarreau | 3bac9ff | 2007-03-18 17:31:28 +0100 | [diff] [blame] | 71 | if (txn->cli_cookie) |
Willy Tarreau | 086b3b4 | 2007-05-13 21:45:51 +0200 | [diff] [blame] | 72 | pool_free2(pool2_capture, txn->cli_cookie); |
Willy Tarreau | 3bac9ff | 2007-03-18 17:31:28 +0100 | [diff] [blame] | 73 | if (txn->srv_cookie) |
Willy Tarreau | 086b3b4 | 2007-05-13 21:45:51 +0200 | [diff] [blame] | 74 | pool_free2(pool2_capture, txn->srv_cookie); |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 75 | |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 76 | pool_free2(pool2_session, s); |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 77 | |
| 78 | /* We may want to free the maximum amount of pools if the proxy is stopping */ |
Willy Tarreau | 92fb983 | 2007-10-16 17:34:28 +0200 | [diff] [blame] | 79 | if (fe && unlikely(fe->state == PR_STSTOPPED)) { |
Willy Tarreau | 632f5a7 | 2007-07-11 10:42:35 +0200 | [diff] [blame] | 80 | if (pool2_buffer) |
| 81 | pool_flush2(pool2_buffer); |
| 82 | if (fe->hdr_idx_pool) |
| 83 | pool_flush2(fe->hdr_idx_pool); |
| 84 | if (pool2_requri) |
| 85 | pool_flush2(pool2_requri); |
| 86 | if (pool2_capture) |
| 87 | pool_flush2(pool2_capture); |
| 88 | if (pool2_session) |
| 89 | pool_flush2(pool2_session); |
| 90 | if (fe->req_cap_pool) |
| 91 | pool_flush2(fe->req_cap_pool); |
| 92 | if (fe->rsp_cap_pool) |
| 93 | pool_flush2(fe->rsp_cap_pool); |
| 94 | } |
Willy Tarreau | c6ca1a0 | 2007-05-13 19:43:47 +0200 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | |
| 98 | /* perform minimal intializations, report 0 in case of error, 1 if OK. */ |
| 99 | int init_session() |
| 100 | { |
| 101 | pool2_session = create_pool("session", sizeof(struct session), MEM_F_SHARED); |
| 102 | return pool2_session != NULL; |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 103 | } |
| 104 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 105 | void session_process_counters(struct session *s) |
| 106 | { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 107 | unsigned long long bytes; |
| 108 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 109 | if (s->req) { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 110 | bytes = s->req->total - s->logs.bytes_in; |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 111 | s->logs.bytes_in = s->req->total; |
| 112 | if (bytes) { |
| 113 | s->fe->bytes_in += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 114 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 115 | if (s->be != s->fe) |
| 116 | s->be->bytes_in += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 117 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 118 | if (s->srv) |
| 119 | s->srv->bytes_in += bytes; |
| 120 | } |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 121 | } |
| 122 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 123 | if (s->rep) { |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 124 | bytes = s->rep->total - s->logs.bytes_out; |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 125 | s->logs.bytes_out = s->rep->total; |
| 126 | if (bytes) { |
| 127 | s->fe->bytes_out += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 128 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 129 | if (s->be != s->fe) |
| 130 | s->be->bytes_out += bytes; |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 131 | |
Willy Tarreau | 30e7101 | 2007-11-26 20:15:35 +0100 | [diff] [blame] | 132 | if (s->srv) |
| 133 | s->srv->bytes_out += bytes; |
| 134 | } |
Krzysztof Piotr Oledzki | 583bc96 | 2007-11-24 22:12:47 +0100 | [diff] [blame] | 135 | } |
| 136 | } |
Willy Tarreau | baaee00 | 2006-06-26 02:48:02 +0200 | [diff] [blame] | 137 | |
| 138 | /* |
| 139 | * Local variables: |
| 140 | * c-indent-level: 8 |
| 141 | * c-basic-offset: 8 |
| 142 | * End: |
| 143 | */ |