[master] 355351f34 vsmw: introduce an optional prefix to segment ids in VSMW_Allocv()

Nils Goroll nils.goroll at uplex.de
Mon Jun 3 13:20:05 UTC 2024


commit 355351f34c050487fa3eb2922fdb7f63904b2252
Author: Stephane Cance <stephane.cance at varnish-software.com>
Date:   Mon May 13 10:55:07 2024 +0200

    vsmw: introduce an optional prefix to segment ids in VSMW_Allocv()
    
    This facility allows intermediate layers to set a prefix without
    meddling with the provided format string.

diff --git a/bin/varnishd/common/common_vsc.c b/bin/varnishd/common/common_vsc.c
index 7df98b836..98b420b70 100644
--- a/bin/varnishd/common/common_vsc.c
+++ b/bin/varnishd/common/common_vsc.c
@@ -91,7 +91,7 @@ vrt_vsc_mksegv(struct vsmw_cluster *vc, const char *category,
 	ALLOC_OBJ(vsg, VSC_SEG_MAGIC);
 	AN(vsg);
 	vsg->seg = VSMW_Allocv(heritage.proc_vsmw, vc, category,
-	    VRT_VSC_Overhead(payload), fmt, va);
+	    VRT_VSC_Overhead(payload), NULL, fmt, va);
 	AN(vsg->seg);
 	vsg->vsm = heritage.proc_vsmw;
 	vsg->head = (void*)vsg->seg;
diff --git a/bin/varnishd/common/common_vsmw.c b/bin/varnishd/common/common_vsmw.c
index 275d8f05c..2ca388b06 100644
--- a/bin/varnishd/common/common_vsmw.c
+++ b/bin/varnishd/common/common_vsmw.c
@@ -377,7 +377,7 @@ VSMW_DestroyCluster(struct vsmw *vsmw, struct vsmw_cluster **vsmcp)
 
 void *
 VSMW_Allocv(struct vsmw *vsmw, struct vsmw_cluster *vc,
-    const char *category, size_t payload,
+    const char *category, size_t payload, const char *prefix,
     const char *fmt, va_list va)
 {
 	struct vsmwseg *seg;
@@ -391,6 +391,10 @@ VSMW_Allocv(struct vsmw *vsmw, struct vsmw_cluster *vc,
 	seg->len = PRNDUP(payload);
 
 	VSB_clear(vsmw->vsb);
+	if (prefix != NULL)
+		VSB_cat(vsmw->vsb, prefix);
+	if (prefix != NULL && fmt[0] != '\0')
+		VSB_cat(vsmw->vsb, ".");
 	VSB_vprintf(vsmw->vsb, fmt, va);
 	AZ(VSB_finish(vsmw->vsb));
 	REPLACE(seg->id, VSB_data(vsmw->vsb));
@@ -420,7 +424,7 @@ VSMW_Allocf(struct vsmw *vsmw, struct vsmw_cluster *vc,
 	void *p;
 
 	va_start(ap, fmt);
-	p = VSMW_Allocv(vsmw, vc, category, len, fmt, ap);
+	p = VSMW_Allocv(vsmw, vc, category, len, NULL, fmt, ap);
 	va_end(ap);
 	return (p);
 }
diff --git a/bin/varnishd/common/vsmw.h b/bin/varnishd/common/vsmw.h
index 07d46b19e..e879edaf4 100644
--- a/bin/varnishd/common/vsmw.h
+++ b/bin/varnishd/common/vsmw.h
@@ -40,7 +40,7 @@ struct vsmw_cluster *VSMW_NewCluster(struct vsmw *, size_t , const char *);
 void VSMW_DestroyCluster(struct vsmw *, struct vsmw_cluster **);
 
 void *VSMW_Allocv(struct vsmw *, struct vsmw_cluster *,
-    const char *, size_t, const char *, va_list);
+    const char *, size_t, const char *, const char *, va_list);
 void *VSMW_Allocf(struct vsmw *, struct vsmw_cluster *,
     const char *, size_t, const char *, ...);
 void VSMW_Free(struct vsmw *, void **);


More information about the varnish-commit mailing list