@@ -77,6 +77,8 @@ typedef struct {
77
77
78
78
ngx_pid_t owner ;
79
79
80
+ ngx_str_t * upstream_name ;
81
+
80
82
ngx_msec_t access_time ;
81
83
82
84
ngx_uint_t fall_count ;
@@ -90,7 +92,7 @@ typedef struct {
90
92
91
93
ngx_atomic_t down ;
92
94
93
- u_char padding [64 ];
95
+ u_char padding [56 ];
94
96
} ngx_http_upstream_check_peer_shm_t ;
95
97
96
98
@@ -222,6 +224,7 @@ typedef struct {
222
224
223
225
224
226
struct ngx_http_upstream_check_srv_conf_s {
227
+ ngx_http_upstream_srv_conf_t * upstream_srv_conf ;
225
228
ngx_uint_t port ;
226
229
ngx_uint_t fall_count ;
227
230
ngx_uint_t rise_count ;
@@ -482,7 +485,8 @@ static ngx_int_t ngx_http_upstream_check_get_shm_name(ngx_str_t *shm_name,
482
485
static ngx_shm_zone_t * ngx_shared_memory_find (ngx_cycle_t * cycle ,
483
486
ngx_str_t * name , void * tag );
484
487
static ngx_http_upstream_check_peer_shm_t *
485
- ngx_http_upstream_check_find_shm_peer (ngx_http_upstream_check_peers_shm_t * peers_shm ,
488
+ ngx_http_upstream_check_find_shm_peer (
489
+ ngx_http_upstream_check_peers_shm_t * peers_shm , ngx_str_t * us_name ,
486
490
ngx_addr_t * addr );
487
491
488
492
static ngx_int_t ngx_http_upstream_check_init_shm_peer (
@@ -3728,6 +3732,7 @@ ngx_http_upstream_check_create_srv_conf(ngx_conf_t *cf)
3728
3732
return NULL ;
3729
3733
}
3730
3734
3735
+ ucscf -> upstream_srv_conf = NGX_CONF_UNSET_PTR ;
3731
3736
ucscf -> port = NGX_CONF_UNSET_UINT ;
3732
3737
ucscf -> fall_count = NGX_CONF_UNSET_UINT ;
3733
3738
ucscf -> rise_count = NGX_CONF_UNSET_UINT ;
@@ -3770,6 +3775,10 @@ ngx_http_upstream_check_init_srv_conf(ngx_conf_t *cf, void *conf)
3770
3775
3771
3776
ucscf = ngx_http_conf_upstream_srv_conf (us , ngx_http_upstream_check_module );
3772
3777
3778
+ if (ucscf -> upstream_srv_conf == NGX_CONF_UNSET_PTR ) {
3779
+ ucscf -> upstream_srv_conf = us ;
3780
+ }
3781
+
3773
3782
if (ucscf -> port == NGX_CONF_UNSET_UINT ) {
3774
3783
ucscf -> port = 0 ;
3775
3784
}
@@ -4028,10 +4037,14 @@ ngx_http_upstream_check_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data)
4028
4037
ngx_memcpy (peer_shm -> sockaddr , peer [i ].peer_addr -> sockaddr ,
4029
4038
peer_shm -> socklen );
4030
4039
4040
+ ucscf = peer [i ].conf ;
4041
+
4042
+ peer_shm -> upstream_name = & ucscf -> upstream_srv_conf -> host ;
4043
+
4031
4044
if (opeers_shm ) {
4032
4045
4033
- opeer_shm = ngx_http_upstream_check_find_shm_peer (opeers_shm ,
4034
- peer [i ].peer_addr );
4046
+ opeer_shm = ngx_http_upstream_check_find_shm_peer (
4047
+ opeers_shm , peer [ i ]. upstream_name , peer [i ].peer_addr );
4035
4048
if (opeer_shm ) {
4036
4049
ngx_log_debug1 (NGX_LOG_DEBUG_HTTP , shm_zone -> shm .log , 0 ,
4037
4050
"http upstream check, inherit opeer: %V " ,
@@ -4047,7 +4060,6 @@ ngx_http_upstream_check_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data)
4047
4060
}
4048
4061
}
4049
4062
4050
- ucscf = peer [i ].conf ;
4051
4063
rc = ngx_http_upstream_check_init_shm_peer (peer_shm , NULL ,
4052
4064
ucscf -> default_down , pool ,
4053
4065
& peer [i ].peer_addr -> name );
@@ -4112,14 +4124,22 @@ ngx_shared_memory_find(ngx_cycle_t *cycle, ngx_str_t *name, void *tag)
4112
4124
4113
4125
static ngx_http_upstream_check_peer_shm_t *
4114
4126
ngx_http_upstream_check_find_shm_peer (ngx_http_upstream_check_peers_shm_t * p ,
4115
- ngx_addr_t * addr )
4127
+ ngx_str_t * us_name , ngx_addr_t * addr )
4116
4128
{
4117
4129
ngx_uint_t i ;
4118
4130
ngx_http_upstream_check_peer_shm_t * peer_shm ;
4131
+ ngx_str_t * shm_us_name ;
4132
+
4119
4133
4120
4134
for (i = 0 ; i < p -> number ; i ++ ) {
4121
4135
4122
4136
peer_shm = & p -> peers [i ];
4137
+ shm_us_name = peer_shm -> upstream_name ;
4138
+
4139
+ if (us_name -> len != shm_us_name -> len ||
4140
+ ngx_strncmp (us_name , shm_us_name , us_name -> len ) != 0 ) {
4141
+ continue ;
4142
+ }
4123
4143
4124
4144
if (addr -> socklen != peer_shm -> socklen ) {
4125
4145
continue ;
0 commit comments