Skip to content

Commit

Permalink
List the VSM clusters in the index file
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdphk committed Jan 17, 2018
1 parent 2410591 commit ae25a64
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
3 changes: 1 addition & 2 deletions bin/varnishd/cache/cache_vrt.c
Expand Up @@ -650,8 +650,7 @@ VRT_VSM_Cluster_Destroy(VRT_CTX, struct vsmw_cluster **vcp)

CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(vcp);
AN(*vcp);
*vcp = NULL;
VSMW_DestroyCluster(heritage.proc_vsmw, vcp);
}

/*--------------------------------------------------------------------
Expand Down
48 changes: 41 additions & 7 deletions bin/varnishd/common/common_vsmw.c
Expand Up @@ -72,6 +72,7 @@ struct vsmw_cluster {
#define VSMW_CLUSTER_MAGIC 0x28b74c00

VTAILQ_ENTRY(vsmw_cluster) list;
struct vsmwseg *cseg;
char *fn;
size_t len;
void *ptr;
Expand Down Expand Up @@ -182,9 +183,6 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx)
CHECK_OBJ_NOTNULL(vsmw, VSMW_MAGIC);
CHECK_OBJ_NOTNULL(seg, VSMWSEG_MAGIC);

if (!--seg->cluster->refs)
VSMW_DestroyCluster(vsmw, &seg->cluster);

VTAILQ_REMOVE(&vsmw->segs, seg, list);
REPLACE(seg->class, NULL);
REPLACE(seg->id, NULL);
Expand All @@ -208,8 +206,8 @@ vsmw_delseg(struct vsmw *vsmw, struct vsmwseg *seg, int fixidx)

/*--------------------------------------------------------------------*/

struct vsmw_cluster *
VSMW_NewCluster(struct vsmw *vsmw, size_t len, const char *pfx)
static struct vsmw_cluster *
vsmw_newcluster(struct vsmw *vsmw, size_t len, const char *pfx)
{
struct vsmw_cluster *vc;
int fd;
Expand Down Expand Up @@ -245,6 +243,26 @@ VSMW_NewCluster(struct vsmw *vsmw, size_t len, const char *pfx)
return (vc);
}

struct vsmw_cluster *
VSMW_NewCluster(struct vsmw *vsmw, size_t len, const char *pfx)
{
struct vsmw_cluster *vc;
struct vsmwseg *seg;

vc = vsmw_newcluster(vsmw, len, pfx);

ALLOC_OBJ(seg, VSMWSEG_MAGIC);
AN(seg);
vc->cseg = seg;
seg->len = len;
seg->cluster = vc;
REPLACE(seg->class, "");
REPLACE(seg->id, "");
vsmw_addseg(vsmw, seg);

return (vc);
}

void
VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vcp)
{
Expand All @@ -255,10 +273,22 @@ VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vcp)
vc = *vcp;
*vcp = NULL;
CHECK_OBJ_NOTNULL(vc, VSMW_CLUSTER_MAGIC);
AZ(vc->refs);

if (vc->cseg != NULL) {
/*
* Backends go on the cool list, so the VGC cluster is
* destroyed before they are. Solve this by turning the
* cluster into an anonymous cluster which dies with the
* refcount on it.
*/
vsmw_delseg(vsmw, vc->cseg, 1);
vc->cseg = NULL;
if (vc->refs > 0)
return;
}
AZ(munmap(vc->ptr, vc->len));

AZ(vc->refs);
VTAILQ_REMOVE(&vsmw->clusters, vc, list);
if (unlinkat(vsmw->vdirfd, vc->fn, 0))
assert (errno == ENOENT);
Expand Down Expand Up @@ -289,7 +319,7 @@ VSMW_Allocv(struct vsmw *vsmw, struct vsmw_cluster *vc,
REPLACE(seg->id, VSB_data(vsmw->vsb));

if (vc == NULL)
vc = VSMW_NewCluster(vsmw, seg->len, class);
vc = vsmw_newcluster(vsmw, seg->len, class);
AN(vc);
vc->refs++;

Expand Down Expand Up @@ -334,6 +364,10 @@ VSMW_Free(struct vsmw *vsmw, void **pp)
if (seg->ptr == p)
break;
AN(seg);

if (!--seg->cluster->refs && seg->cluster->cseg == NULL)
VSMW_DestroyCluster(vsmw, &seg->cluster);

vsmw_delseg(vsmw, seg, 1);
}

Expand Down
1 change: 1 addition & 0 deletions bin/varnishd/flint.lnt
Expand Up @@ -96,6 +96,7 @@

+libh mgt_event.h

-sem(vsmw_addseg, custodial(2))
-sem(BAN_Free, custodial(1))
-sem(EXP_Inject, custodial(1))
-sem(HSH_Insert, custodial(3))
Expand Down
12 changes: 7 additions & 5 deletions lib/libvarnishapi/vsm.c
Expand Up @@ -418,9 +418,7 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs, struct vsb *vsb)
return (retval|VSM_NUKE_ALL);

/*
* Examine the ident line
* XXX: for now ignore that one of the ID's is a pid which could
* XXX: be kill(pid,0)'ed for more rapid abandonment detection.
* First line is ident comment
*/
i = sscanf(VSB_data(vsb), "# %ju %ju\n%n", &id1, &id2, &ac);
if (i != 2) {
Expand All @@ -445,7 +443,7 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs, struct vsb *vsb)
vg->markscan = 0;

/*
* Efficient comparison walking the two lists side-by-side is ok because
* Efficient comparison by walking the two lists side-by-side because
* segment inserts always happen at the tail (VSMW_Allocv()). So, as
* soon as vg is exhausted, we only insert.
*
Expand All @@ -465,13 +463,17 @@ vsm_refresh_set2(struct vsm *vd, struct vsm_set *vs, struct vsb *vsb)
av = VAV_Parse(p, &ac, 0);
p = e + 1;

if (av[0] != NULL || ac < 5 || ac > 6) {
if (av[0] != NULL || ac < 4 || ac > 6) {
(void)(vsm_diag(vd,
"vsm_refresh_set2: bad index (%d/%s)",
ac, av[0]));
VAV_Free(av);
break;
}
if (ac == 4) {
VAV_Free(av);
continue;
}

if (vg == NULL) {
ALLOC_OBJ(vg2, VSM_SEG_MAGIC);
Expand Down
2 changes: 1 addition & 1 deletion lib/libvcc/vcc_backend.c
Expand Up @@ -506,5 +506,5 @@ vcc_Backend_Init(struct vcc *tl)
VSB_printf(ifp->ini, "\tvsc_cluster = VRT_VSM_Cluster_New(ctx,\n"
"\t ndirector * VRT_backend_vsm_need(ctx));\n");
VSB_printf(ifp->ini, "\tif (vsc_cluster == 0)\n\t\treturn(1);");
VSB_printf(ifp->fin, "\tVRT_VSM_Cluster_Destroy(ctx, &vsc_cluster);");
VSB_printf(ifp->fin, "\t\tVRT_VSM_Cluster_Destroy(ctx, &vsc_cluster);");
}

0 comments on commit ae25a64

Please sign in to comment.