router_add_server: perform instance check for all servers
@@ -476,7 +476,7 @@ router_add_server(
char hnbuf[256];
char errbuf[512];
server *newserver;
- servers *w;
+ servers *w = NULL;
walk = saddrs; /* NULL if file */
do {
@@ -539,27 +539,7 @@ router_add_server(
s->server = newserver;
}
- if (cl->type == CARBON_CH ||
- cl->type == FNV1A_CH ||
- cl->type == JUMP_CH)
- {
- if (w == NULL) {
- cl->members.ch->servers = w =
- ra_malloc(ret, sizeof(servers));
- } else {
- w = w->next = ra_malloc(ret, sizeof(servers));
- }
- if (w == NULL) {
- snprintf(errbuf, sizeof(errbuf), "malloc failed for %s_ch %s",
- cl->type == CARBON_CH ? "carbon" :
- cl->type == FNV1A_CH ? "fnv1a" :
- "jump_fnv1a", ip);
- freeaddrinfo(saddrs);
- if (hint)
- free(hint);
- return ra_strdup(ret, errbuf);
- }
- w->next = NULL;
+ /* check instance matches the existing server */
if (s->refcnt > 1) {
char *sinst = server_instance(newserver);
if (sinst == NULL && inst != NULL) {
@@ -601,6 +581,28 @@ router_add_server(
}
if (inst != NULL)
server_set_instance(newserver, inst);
+
+ if (cl->type == CARBON_CH ||
+ cl->type == FNV1A_CH ||
+ cl->type == JUMP_CH)
+ {
+ if (w == NULL) {
+ cl->members.ch->servers = w =
+ ra_malloc(ret, sizeof(servers));
+ } else {
+ w = w->next = ra_malloc(ret, sizeof(servers));
+ }
+ if (w == NULL) {
+ snprintf(errbuf, sizeof(errbuf), "malloc failed for %s_ch %s",
+ cl->type == CARBON_CH ? "carbon" :
+ cl->type == FNV1A_CH ? "fnv1a" :
+ "jump_fnv1a", ip);
+ freeaddrinfo(saddrs);
+ if (hint)
+ free(hint);
+ return ra_strdup(ret, errbuf);
+ }
+ w->next = NULL;
w->server = newserver;
cl->members.ch->ring = ch_addnode(
cl->members.ch->ring,
