r2436 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Wed Feb 6 10:47:24 CET 2008
Author: phk
Date: 2008-02-06 10:47:24 +0100 (Wed, 06 Feb 2008)
New Revision: 2436
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_backend.c
trunk/varnish-cache/bin/varnishd/cache_backend_random.c
trunk/varnish-cache/bin/varnishd/cache_backend_simple.c
Log:
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.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2008-02-06 09:43:22 UTC (rev 2435)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2008-02-06 09:47:24 UTC (rev 2436)
@@ -443,7 +443,7 @@
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);
Modified: trunk/varnish-cache/bin/varnishd/cache_backend.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-02-06 09:43:22 UTC (rev 2435)
+++ trunk/varnish-cache/bin/varnishd/cache_backend.c 2008-02-06 09:47:24 UTC (rev 2436)
@@ -326,13 +326,13 @@
/*--------------------------------------------------------------------
* 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 @@
if (strcmp(b->ident, ident))
continue;
b->refcount++;
- return (NULL);
+ *be = b;
+ return (1);
}
b = calloc(sizeof *b, 1);
@@ -361,7 +362,8 @@
b->minute_limit = 1;
VTAILQ_INSERT_TAIL(&backendlist, b, list);
- return (b);
+ *be = b;
+ return (0);
}
/*--------------------------------------------------------------------*/
Modified: trunk/varnish-cache/bin/varnishd/cache_backend_random.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_random.c 2008-02-06 09:43:22 UTC (rev 2435)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_random.c 2008-02-06 09:47:24 UTC (rev 2436)
@@ -439,8 +439,16 @@
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;
Modified: trunk/varnish-cache/bin/varnishd/cache_backend_simple.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2008-02-06 09:43:22 UTC (rev 2435)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_simple.c 2008-02-06 09:47:24 UTC (rev 2436)
@@ -49,7 +49,6 @@
#define BES_MAGIC 0x015e17ac
char *hostname;
char *portname;
- char *ident;
struct addrinfo *addr;
struct addrinfo *last_addr;
double dnsttl;
@@ -364,10 +363,13 @@
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 @@
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 @@
if (p != NULL)
printf("Warning: could not lookup backend %s (%s:%s): %s",
b->vcl_name, bes->hostname, bes->portname, p);
-
- *bp = b;
}
More information about the varnish-commit
mailing list