From: phk Date: Wed, 6 Feb 2008 09:47:24 +0000 (+0000) Subject: VBE_AddBackend() needs to always return the backend, so make it a pointer arg X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd2388e6dc17bc08895245e1f497ecacfaf6222f;p=varnish VBE_AddBackend() needs to always return the backend, so make it a pointer arg and use the return int to tell if it was a reuse. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2436 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index 0a73a81c..c2369334 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -443,7 +443,7 @@ void VBE_free_bereq(struct bereq *bereq); extern struct backendlist backendlist; void VBE_DropRef(struct backend *); void VBE_DropRefLocked(struct backend *); -struct backend *VBE_AddBackend(struct backend_method *method, const char *ident); +int VBE_AddBackend(struct backend_method *method, const char *ident, struct backend **be); struct vbe_conn *VBE_NewConn(void); void VBE_ReleaseConn(struct vbe_conn *); void VBE_UpdateHealth(const struct sess *sp, const struct vbe_conn *, int); diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index 77eda246..68450b6e 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -326,13 +326,13 @@ VBE_AddBackendMethod(const struct backend_method *bem) /*-------------------------------------------------------------------- * Add a backend/director instance when loading a VCL. - * If an existing backend is matched, grab a refcount and return NULL. - * Else create a new backend structure and return that with reference - * initialized to one. + * If an existing backend is matched, grab a refcount and return one. + * Else create a new backend structure with reference initialized to one + * and return zero. */ -struct backend * -VBE_AddBackend(struct backend_method *method, const char *ident) +int +VBE_AddBackend(struct backend_method *method, const char *ident, struct backend **be) { struct backend *b; @@ -344,7 +344,8 @@ VBE_AddBackend(struct backend_method *method, const char *ident) if (strcmp(b->ident, ident)) continue; b->refcount++; - return (NULL); + *be = b; + return (1); } b = calloc(sizeof *b, 1); @@ -361,7 +362,8 @@ VBE_AddBackend(struct backend_method *method, const char *ident) b->minute_limit = 1; VTAILQ_INSERT_TAIL(&backendlist, b, list); - return (b); + *be = b; + return (0); } /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_backend_random.c b/varnish-cache/bin/varnishd/cache_backend_random.c index e3799241..f1889133 100644 --- a/varnish-cache/bin/varnishd/cache_backend_random.c +++ b/varnish-cache/bin/varnishd/cache_backend_random.c @@ -439,8 +439,16 @@ struct backend_method backend_method_random = { void VRT_init_random_backend(struct backend **bp, const struct vrt_dir_random *t) { + struct backend *b; (void)bp; (void)t; + + if (VBE_AddBackend(&backend_method_random, t->ident, bp)) + return; /* reuse existing backend */ + + b = *bp; + AN(t->name); + REPLACE(b->vcl_name, t->name); #if 0 struct backend *b; struct ber *ber; diff --git a/varnish-cache/bin/varnishd/cache_backend_simple.c b/varnish-cache/bin/varnishd/cache_backend_simple.c index a9be5def..3fcf56bb 100644 --- a/varnish-cache/bin/varnishd/cache_backend_simple.c +++ b/varnish-cache/bin/varnishd/cache_backend_simple.c @@ -49,7 +49,6 @@ struct bes { #define BES_MAGIC 0x015e17ac char *hostname; char *portname; - char *ident; struct addrinfo *addr; struct addrinfo *last_addr; double dnsttl; @@ -364,10 +363,13 @@ VRT_init_simple_backend(struct backend **bp, const struct vrt_simple_backend *t) struct bes *bes; const char *p; - b = VBE_AddBackend(&backend_method_simple, t->ident); - if (b == NULL) + if (VBE_AddBackend(&backend_method_simple, t->ident, bp)) return; /* ref to existing backend */ + b = *bp; + AN(t->name); + REPLACE(b->vcl_name, t->name); + bes = calloc(sizeof *bes, 1); XXXAN(bes); bes->magic = BES_MAGIC; @@ -376,12 +378,6 @@ VRT_init_simple_backend(struct backend **bp, const struct vrt_simple_backend *t) bes->dnsttl = 300; - AN(t->ident); - REPLACE(bes->ident, t->ident); - - AN(t->name); - REPLACE(b->vcl_name, t->name); - AN(t->host->portname); REPLACE(bes->portname, t->host->portname); @@ -398,6 +394,4 @@ VRT_init_simple_backend(struct backend **bp, const struct vrt_simple_backend *t) if (p != NULL) printf("Warning: could not lookup backend %s (%s:%s): %s", b->vcl_name, bes->hostname, bes->portname, p); - - *bp = b; }