Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_upstream_zone_module.c @ 7524:deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
This ensures that correct ctx is always available, including after
filter finalization. In particular, this fixes a segmentation fault
with the following configuration:
location / {
image_filter test;
perl 'sub {
my $r = shift;
$r->send_http_header();
$r->print("foo\n");
$r->print("bar\n");
}';
}
This also seems to be the only way to correctly handle filter finalization
in various complex cases, for example, when embedded perl is used both
in the original handler and in an error page called after filter
finalization.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 12 Jul 2019 11:29:22 +0300 |
parents | 3b1b81e248bc |
children |
rev | line source |
---|---|
6103 | 1 |
2 /* | |
3 * Copyright (C) Ruslan Ermilov | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
13 static char *ngx_http_upstream_zone(ngx_conf_t *cf, ngx_command_t *cmd, | |
14 void *conf); | |
15 static ngx_int_t ngx_http_upstream_init_zone(ngx_shm_zone_t *shm_zone, | |
16 void *data); | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
17 static ngx_http_upstream_rr_peers_t *ngx_http_upstream_zone_copy_peers( |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
18 ngx_slab_pool_t *shpool, ngx_http_upstream_srv_conf_t *uscf); |
7080
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
19 static ngx_http_upstream_rr_peer_t *ngx_http_upstream_zone_copy_peer( |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
20 ngx_http_upstream_rr_peers_t *peers, ngx_http_upstream_rr_peer_t *src); |
6103 | 21 |
22 | |
23 static ngx_command_t ngx_http_upstream_zone_commands[] = { | |
24 | |
25 { ngx_string("zone"), | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
26 NGX_HTTP_UPS_CONF|NGX_CONF_TAKE12, |
6103 | 27 ngx_http_upstream_zone, |
28 0, | |
29 0, | |
30 NULL }, | |
31 | |
32 ngx_null_command | |
33 }; | |
34 | |
35 | |
36 static ngx_http_module_t ngx_http_upstream_zone_module_ctx = { | |
37 NULL, /* preconfiguration */ | |
38 NULL, /* postconfiguration */ | |
39 | |
40 NULL, /* create main configuration */ | |
41 NULL, /* init main configuration */ | |
42 | |
43 NULL, /* create server configuration */ | |
44 NULL, /* merge server configuration */ | |
45 | |
46 NULL, /* create location configuration */ | |
47 NULL /* merge location configuration */ | |
48 }; | |
49 | |
50 | |
51 ngx_module_t ngx_http_upstream_zone_module = { | |
52 NGX_MODULE_V1, | |
53 &ngx_http_upstream_zone_module_ctx, /* module context */ | |
54 ngx_http_upstream_zone_commands, /* module directives */ | |
55 NGX_HTTP_MODULE, /* module type */ | |
56 NULL, /* init master */ | |
57 NULL, /* init module */ | |
58 NULL, /* init process */ | |
59 NULL, /* init thread */ | |
60 NULL, /* exit thread */ | |
61 NULL, /* exit process */ | |
62 NULL, /* exit master */ | |
63 NGX_MODULE_V1_PADDING | |
64 }; | |
65 | |
66 | |
67 static char * | |
68 ngx_http_upstream_zone(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
69 { | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
70 ssize_t size; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
71 ngx_str_t *value; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
72 ngx_http_upstream_srv_conf_t *uscf; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
73 ngx_http_upstream_main_conf_t *umcf; |
6103 | 74 |
75 uscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_upstream_module); | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
76 umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module); |
6103 | 77 |
78 value = cf->args->elts; | |
79 | |
80 if (!value[1].len) { | |
81 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
82 "invalid zone name \"%V\"", &value[1]); | |
83 return NGX_CONF_ERROR; | |
84 } | |
85 | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
86 if (cf->args->nelts == 3) { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
87 size = ngx_parse_size(&value[2]); |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
88 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
89 if (size == NGX_ERROR) { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
90 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
91 "invalid zone size \"%V\"", &value[2]); |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
92 return NGX_CONF_ERROR; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
93 } |
6103 | 94 |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
95 if (size < (ssize_t) (8 * ngx_pagesize)) { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
96 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
97 "zone \"%V\" is too small", &value[1]); |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
98 return NGX_CONF_ERROR; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
99 } |
6103 | 100 |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
101 } else { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
102 size = 0; |
6103 | 103 } |
104 | |
105 uscf->shm_zone = ngx_shared_memory_add(cf, &value[1], size, | |
106 &ngx_http_upstream_module); | |
107 if (uscf->shm_zone == NULL) { | |
108 return NGX_CONF_ERROR; | |
109 } | |
110 | |
111 uscf->shm_zone->init = ngx_http_upstream_init_zone; | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
112 uscf->shm_zone->data = umcf; |
6103 | 113 |
114 uscf->shm_zone->noreuse = 1; | |
115 | |
116 return NGX_CONF_OK; | |
117 } | |
118 | |
119 | |
120 static ngx_int_t | |
121 ngx_http_upstream_init_zone(ngx_shm_zone_t *shm_zone, void *data) | |
122 { | |
123 size_t len; | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
124 ngx_uint_t i; |
6103 | 125 ngx_slab_pool_t *shpool; |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
126 ngx_http_upstream_rr_peers_t *peers, **peersp; |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
127 ngx_http_upstream_srv_conf_t *uscf, **uscfp; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
128 ngx_http_upstream_main_conf_t *umcf; |
6103 | 129 |
130 shpool = (ngx_slab_pool_t *) shm_zone->shm.addr; | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
131 umcf = shm_zone->data; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
132 uscfp = umcf->upstreams.elts; |
6103 | 133 |
134 if (shm_zone->shm.exists) { | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
135 peers = shpool->data; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
136 |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
137 for (i = 0; i < umcf->upstreams.nelts; i++) { |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
138 uscf = uscfp[i]; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
139 |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
140 if (uscf->shm_zone != shm_zone) { |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
141 continue; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
142 } |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
143 |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
144 uscf->peer.data = peers; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
145 peers = peers->zone_next; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
146 } |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
147 |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
148 return NGX_OK; |
6103 | 149 } |
150 | |
151 len = sizeof(" in upstream zone \"\"") + shm_zone->shm.name.len; | |
152 | |
153 shpool->log_ctx = ngx_slab_alloc(shpool, len); | |
154 if (shpool->log_ctx == NULL) { | |
155 return NGX_ERROR; | |
156 } | |
157 | |
158 ngx_sprintf(shpool->log_ctx, " in upstream zone \"%V\"%Z", | |
159 &shm_zone->shm.name); | |
160 | |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
161 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
162 /* copy peers to shared memory */ |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
163 |
6214
341e4303d25b
Fixed strict aliasing warnings with old GCC versions.
Ruslan Ermilov <ru@nginx.com>
parents:
6198
diff
changeset
|
164 peersp = (ngx_http_upstream_rr_peers_t **) (void *) &shpool->data; |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
165 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
166 for (i = 0; i < umcf->upstreams.nelts; i++) { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
167 uscf = uscfp[i]; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
168 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
169 if (uscf->shm_zone != shm_zone) { |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
170 continue; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
171 } |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
172 |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
173 peers = ngx_http_upstream_zone_copy_peers(shpool, uscf); |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
174 if (peers == NULL) { |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
175 return NGX_ERROR; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
176 } |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
177 |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
178 *peersp = peers; |
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
179 peersp = &peers->zone_next; |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
180 } |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
181 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
182 return NGX_OK; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
183 } |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
184 |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
185 |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
186 static ngx_http_upstream_rr_peers_t * |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
187 ngx_http_upstream_zone_copy_peers(ngx_slab_pool_t *shpool, |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
188 ngx_http_upstream_srv_conf_t *uscf) |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
189 { |
7078
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
190 ngx_str_t *name; |
6123
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
191 ngx_http_upstream_rr_peer_t *peer, **peerp; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
192 ngx_http_upstream_rr_peers_t *peers, *backup; |
caa103acf180
Upstream: allow multiple upstreams to use the same shared zone.
Ruslan Ermilov <ru@nginx.com>
parents:
6103
diff
changeset
|
193 |
6103 | 194 peers = ngx_slab_alloc(shpool, sizeof(ngx_http_upstream_rr_peers_t)); |
195 if (peers == NULL) { | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
196 return NULL; |
6103 | 197 } |
198 | |
199 ngx_memcpy(peers, uscf->peer.data, sizeof(ngx_http_upstream_rr_peers_t)); | |
200 | |
7078
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
201 name = ngx_slab_alloc(shpool, sizeof(ngx_str_t)); |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
202 if (name == NULL) { |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
203 return NULL; |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
204 } |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
205 |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
206 name->data = ngx_slab_alloc(shpool, peers->name->len); |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
207 if (name->data == NULL) { |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
208 return NULL; |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
209 } |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
210 |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
211 ngx_memcpy(name->data, peers->name->data, peers->name->len); |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
212 name->len = peers->name->len; |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
213 |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
214 peers->name = name; |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
215 |
6103 | 216 peers->shpool = shpool; |
217 | |
218 for (peerp = &peers->peer; *peerp; peerp = &peer->next) { | |
219 /* pool is unlocked */ | |
7080
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
220 peer = ngx_http_upstream_zone_copy_peer(peers, *peerp); |
6103 | 221 if (peer == NULL) { |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
222 return NULL; |
6103 | 223 } |
224 | |
225 *peerp = peer; | |
226 } | |
227 | |
228 if (peers->next == NULL) { | |
229 goto done; | |
230 } | |
231 | |
232 backup = ngx_slab_alloc(shpool, sizeof(ngx_http_upstream_rr_peers_t)); | |
233 if (backup == NULL) { | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
234 return NULL; |
6103 | 235 } |
236 | |
237 ngx_memcpy(backup, peers->next, sizeof(ngx_http_upstream_rr_peers_t)); | |
238 | |
7078
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
239 backup->name = name; |
1eb753aa8e5e
Upstream zone: store peers->name and its data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
6214
diff
changeset
|
240 |
6103 | 241 backup->shpool = shpool; |
242 | |
243 for (peerp = &backup->peer; *peerp; peerp = &peer->next) { | |
244 /* pool is unlocked */ | |
7080
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
245 peer = ngx_http_upstream_zone_copy_peer(backup, *peerp); |
6103 | 246 if (peer == NULL) { |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
247 return NULL; |
6103 | 248 } |
249 | |
250 *peerp = peer; | |
251 } | |
252 | |
253 peers->next = backup; | |
254 | |
255 done: | |
256 | |
257 uscf->peer.data = peers; | |
258 | |
6198
311d232ad803
Upstream: fixed shared upstreams on win32.
Ruslan Ermilov <ru@nginx.com>
parents:
6123
diff
changeset
|
259 return peers; |
6103 | 260 } |
7080
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
261 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
262 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
263 static ngx_http_upstream_rr_peer_t * |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
264 ngx_http_upstream_zone_copy_peer(ngx_http_upstream_rr_peers_t *peers, |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
265 ngx_http_upstream_rr_peer_t *src) |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
266 { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
267 ngx_slab_pool_t *pool; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
268 ngx_http_upstream_rr_peer_t *dst; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
269 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
270 pool = peers->shpool; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
271 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
272 dst = ngx_slab_calloc_locked(pool, sizeof(ngx_http_upstream_rr_peer_t)); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
273 if (dst == NULL) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
274 return NULL; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
275 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
276 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
277 if (src) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
278 ngx_memcpy(dst, src, sizeof(ngx_http_upstream_rr_peer_t)); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
279 dst->sockaddr = NULL; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
280 dst->name.data = NULL; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
281 dst->server.data = NULL; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
282 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
283 |
7110
3b1b81e248bc
Do not use the obsolete NGX_SOCKADDRLEN macro.
Ruslan Ermilov <ru@nginx.com>
parents:
7080
diff
changeset
|
284 dst->sockaddr = ngx_slab_calloc_locked(pool, sizeof(ngx_sockaddr_t)); |
7080
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
285 if (dst->sockaddr == NULL) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
286 goto failed; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
287 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
288 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
289 dst->name.data = ngx_slab_calloc_locked(pool, NGX_SOCKADDR_STRLEN); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
290 if (dst->name.data == NULL) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
291 goto failed; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
292 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
293 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
294 if (src) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
295 ngx_memcpy(dst->sockaddr, src->sockaddr, src->socklen); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
296 ngx_memcpy(dst->name.data, src->name.data, src->name.len); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
297 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
298 dst->server.data = ngx_slab_alloc_locked(pool, src->server.len); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
299 if (dst->server.data == NULL) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
300 goto failed; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
301 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
302 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
303 ngx_memcpy(dst->server.data, src->server.data, src->server.len); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
304 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
305 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
306 return dst; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
307 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
308 failed: |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
309 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
310 if (dst->server.data) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
311 ngx_slab_free_locked(pool, dst->server.data); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
312 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
313 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
314 if (dst->name.data) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
315 ngx_slab_free_locked(pool, dst->name.data); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
316 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
317 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
318 if (dst->sockaddr) { |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
319 ngx_slab_free_locked(pool, dst->sockaddr); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
320 } |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
321 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
322 ngx_slab_free_locked(pool, dst); |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
323 |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
324 return NULL; |
ac120e797d28
Upstream: copy peer data in shared memory.
Ruslan Ermilov <ru@nginx.com>
parents:
7078
diff
changeset
|
325 } |