pthread_mutex_t mtx;
struct backend_method *method;
+ const char *ident;
void *priv;
int health;
extern struct backendlist backendlist;
void VBE_DropRef(struct backend *);
void VBE_DropRefLocked(struct backend *);
-struct backend *VBE_NewBackend(struct backend_method *method);
+struct backend *VBE_AddBackend(struct backend_method *method, const char *ident);
struct vbe_conn *VBE_NewConn(void);
void VBE_ReleaseConn(struct vbe_conn *);
void VBE_UpdateHealth(const struct sess *sp, const struct vbe_conn *, int);
/* cache_cli.c [CLI] */
void CLI_Init(void);
extern pthread_t cli_thread;
-#define ASSERT_CLI() do {assert(phtread_self() == cli_thread);} while (0)
+#define ASSERT_CLI() do {assert(pthread_self() == cli_thread);} while (0)
/* cache_expiry.c */
void EXP_Insert(struct object *o);
UNLOCK(&VBE_mtx);
}
-/*--------------------------------------------------------------------*/
-
-struct backend *
-VBE_NewBackend(struct backend_method *method)
-{
- struct backend *b;
-
- b = calloc(sizeof *b, 1);
- XXXAN(b);
- b->magic = BACKEND_MAGIC;
- b->method = method;
-
- MTX_INIT(&b->mtx);
- b->refcount = 1;
-
- b->last_check = TIM_mono();
- b->minute_limit = 1;
-
- VTAILQ_INSERT_TAIL(&backendlist, b, list);
- return (b);
-}
/*--------------------------------------------------------------------*/
bem->init();
}
+/*--------------------------------------------------------------------
+ * 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.
+ */
+
+struct backend *
+VBE_AddBackend(struct backend_method *method, const char *ident)
+{
+ struct backend *b;
+
+ ASSERT_CLI();
+ VTAILQ_FOREACH(b, &backendlist, list) {
+ CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
+ if (b->method != method)
+ continue;
+ if (strcmp(b->ident, ident))
+ continue;
+ b->refcount++;
+ return (NULL);
+ }
+
+ b = calloc(sizeof *b, 1);
+ XXXAN(b);
+ b->magic = BACKEND_MAGIC;
+ b->method = method;
+ b->ident = strdup(ident);
+ XXXAN(b->ident);
+
+ MTX_INIT(&b->mtx);
+ b->refcount = 1;
+
+ b->last_check = TIM_mono();
+ b->minute_limit = 1;
+
+ VTAILQ_INSERT_TAIL(&backendlist, b, list);
+ return (b);
+}
+
/*--------------------------------------------------------------------*/
void
MTX_INIT(&VBE_mtx);
VBE_AddBackendMethod(&backend_method_simple);
VBE_AddBackendMethod(&backend_method_random);
+#if 0
VBE_AddBackendMethod(&backend_method_round_robin);
+#endif
}
struct bes *bes;
const char *p;
- /*
- * Scan existing backends to see if we can recycle one of them.
- */
- VTAILQ_FOREACH(b, &backendlist, list) {
- CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC);
- if (b->method != &backend_method_simple)
- continue;
- CAST_OBJ_NOTNULL(bes, b->priv, BES_MAGIC);
- if (strcmp(bes->ident, t->ident))
- continue;
- b->refcount++;
- *bp = b;
- return;
- }
-
- b = VBE_NewBackend(&backend_method_simple);
+ b = VBE_AddBackend(&backend_method_simple, t->ident);
+ if (b == NULL)
+ return; /* ref to existing backend */
bes = calloc(sizeof *bes, 1);
XXXAN(bes);