From: phk Date: Mon, 4 Feb 2008 09:51:23 +0000 (+0000) Subject: Complete the VCC part of random directors, runtime code next. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50278757b69dac317b16ffb323796f6f989b0353;p=varnish Complete the VCC part of random directors, runtime code next. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2423 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_backend_random.c b/varnish-cache/bin/varnishd/cache_backend_random.c index 8527a918..e3799241 100644 --- a/varnish-cache/bin/varnishd/cache_backend_random.c +++ b/varnish-cache/bin/varnishd/cache_backend_random.c @@ -437,8 +437,11 @@ struct backend_method backend_method_random = { /*--------------------------------------------------------------------*/ void -VRT_init_random_backend(struct backend **bp, const struct vrt_random_backend *t) +VRT_init_random_backend(struct backend **bp, const struct vrt_dir_random *t) { + (void)bp; + (void)t; +#if 0 struct backend *b; struct ber *ber; struct vrt_backend_entry *be; @@ -508,5 +511,6 @@ VRT_init_random_backend(struct backend **bp, const struct vrt_random_backend *t) ber->blist = bs; *bp = b; +#endif } diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index f56b725f..45c8b83d 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -72,7 +72,7 @@ struct vrt_dir_random_entry { struct vrt_dir_random { unsigned nmember; - struct vrt_dir_random_entry *members; + const struct vrt_dir_random_entry *members; const char *ident; }; @@ -135,7 +135,7 @@ void VRT_Rollback(struct sess *sp); /* Backend related */ void VRT_init_simple_backend(struct backend **, const struct vrt_simple_backend *); void VRT_init_round_robin_backend(struct backend **, const struct vrt_round_robin_backend *); -void VRT_init_random_backend(struct backend **, const struct vrt_random_backend *); +void VRT_init_random_backend(struct backend **, const struct vrt_dir_random *); void VRT_fini_backend(struct backend *); char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa); diff --git a/varnish-cache/lib/libvcl/vcc_backend.c b/varnish-cache/lib/libvcl/vcc_backend.c index e5e28d69..7936112e 100644 --- a/varnish-cache/lib/libvcl/vcc_backend.c +++ b/varnish-cache/lib/libvcl/vcc_backend.c @@ -217,7 +217,6 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh) fs = vcc_FldSpec(tl, "!host", "?port", NULL); t_first = tl->t; - *nbh = tl->nbackend_host++; if (tl->t->tok == ID) { VTAILQ_FOREACH(h, &tl->hosts, list) { @@ -240,8 +239,8 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh) ExpectErr(tl, '{'); vcc_NextToken(tl); - Fh(tl, 0, "\nstatic const struct vrt_backend_host bh_%d = {\n", - *nbh); + *nbh = tl->nbackend_host++; + Fh(tl, 0, "\nstatic const struct vrt_backend_host bh_%d = {\n", *nbh); /* Check for old syntax */ if (tl->t->tok == ID && vcc_IdIs(tl->t, "set")) { @@ -376,6 +375,9 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_first, const int nbh, nelem; struct fld_spec *fs; + Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.backend[%d])\n", + PF(t_dir), tl->nbackend); + fs = vcc_FldSpec(tl, "!backend", "?weight", NULL); vcc_NextToken(tl); /* ID: policy (= random) */ @@ -418,14 +420,18 @@ vcc_ParseRandomDirector(struct tokenlist *tl, const struct token *t_first, const vcc_NextToken(tl); } Fc(tl, 0, "\t{ .host = 0 }\n"); - Fc(tl, 0, "}\n"); + Fc(tl, 0, "};\n"); Fc(tl, 0, - "\nstatic const struct vrt_dir_random vdr_%.*s[] = {\n", + "\nstatic const struct vrt_dir_random vdr_%.*s = {\n", PF(t_dir)); Fc(tl, 0, "\t.nmember = %d,\n", nelem); Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(t_dir)); vcc_EmitBeIdent(tl->fc, t_first, tl->t); + Fc(tl, 0, "};\n"); vcc_NextToken(tl); + Fi(tl, 0, "\tVRT_init_random_backend(&VGC_backend_%.*s , &vdr_%.*s);\n", + PF(t_dir), PF(t_dir)); + Ff(tl, 0, "\tVRT_fini_random_backend(VGC_backend_%.*s);\n", PF(t_dir)); } /*-------------------------------------------------------------------- diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 0b82433b..d49f2656 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -423,7 +423,7 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, "\n"); vsb_cat(sb, "struct vrt_dir_random {\n"); vsb_cat(sb, " unsigned nmember;\n"); - vsb_cat(sb, " struct vrt_dir_random_entry *members;\n"); + vsb_cat(sb, " const struct vrt_dir_random_entry *members;\n"); vsb_cat(sb, " const char *ident;\n"); vsb_cat(sb, "};\n"); vsb_cat(sb, "\n"); @@ -486,7 +486,7 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, "/* Backend related */\n"); vsb_cat(sb, "void VRT_init_simple_backend(struct backend **, const struct vrt_simple_backend *);\n"); vsb_cat(sb, "void VRT_init_round_robin_backend(struct backend **, const struct vrt_round_robin_backend *);\n"); - vsb_cat(sb, "void VRT_init_random_backend(struct backend **, const struct vrt_random_backend *);\n"); + vsb_cat(sb, "void VRT_init_random_backend(struct backend **, const struct vrt_dir_random *);\n"); vsb_cat(sb, "void VRT_fini_backend(struct backend *);\n"); vsb_cat(sb, "\n"); vsb_cat(sb, "char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);\n");