r4933 - in trunk/varnish-cache: bin/varnishadm bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishsizes bin/varnishstat bin/varnishtest bin/varnishtop include lib/libvarnishapi

phk at varnish-cache.org phk at varnish-cache.org
Tue Jun 8 12:15:00 CEST 2010


Author: phk
Date: 2010-06-08 12:15:00 +0200 (Tue, 08 Jun 2010)
New Revision: 4933

Added:
   trunk/varnish-cache/lib/libvarnishapi/vsm.c
Removed:
   trunk/varnish-cache/lib/libvarnishapi/vsl.c
Modified:
   trunk/varnish-cache/bin/varnishadm/varnishadm.c
   trunk/varnish-cache/bin/varnishhist/varnishhist.c
   trunk/varnish-cache/bin/varnishlog/varnishlog.c
   trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
   trunk/varnish-cache/bin/varnishreplay/varnishreplay.c
   trunk/varnish-cache/bin/varnishsizes/varnishsizes.c
   trunk/varnish-cache/bin/varnishstat/varnishstat.c
   trunk/varnish-cache/bin/varnishstat/varnishstat.h
   trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
   trunk/varnish-cache/bin/varnishtop/varnishtop.c
   trunk/varnish-cache/include/varnishapi.h
   trunk/varnish-cache/lib/libvarnishapi/Makefile.am
   trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c
   trunk/varnish-cache/lib/libvarnishapi/vsl_log.c
   trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
   trunk/varnish-cache/lib/libvarnishapi/vslapi.h
Log:
Wanton renaming in libvarnishapi



Modified: trunk/varnish-cache/bin/varnishadm/varnishadm.c
===================================================================
--- trunk/varnish-cache/bin/varnishadm/varnishadm.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishadm/varnishadm.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -216,7 +216,7 @@
 	const char *T_arg = NULL;
 	const char *S_arg = NULL;
 	const char *n_arg = NULL;
-	struct VSL_data *vsd;
+	struct VSM_data *vsd;
 	char *p;
 	int opt, sock;
 
@@ -243,17 +243,17 @@
 	argv += optind;
 
 	if (n_arg != NULL) {
-		vsd = VSL_New();
+		vsd = VSM_New();
 		assert(VSL_Log_Arg(vsd, 'n', n_arg));
-		if (!VSL_Open(vsd, 1)) {
+		if (!VSM_Open(vsd, 1)) {
 			if (T_arg == NULL) {
-				p = VSL_Find_Alloc(vsd, "Arg", "-T", "", NULL);
+				p = VSM_Find_Chunk(vsd, "Arg", "-T", "", NULL);
 				if (p != NULL) {
 					T_arg = strdup(p);
 				}
 			}
 			if (S_arg == NULL) {
-				p = VSL_Find_Alloc(vsd, "Arg", "-S", "", NULL);
+				p = VSM_Find_Chunk(vsd, "Arg", "-S", "", NULL);
 				if (p != NULL) {
 					S_arg = strdup(p);
 				}

Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c
===================================================================
--- trunk/varnish-cache/bin/varnishhist/varnishhist.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishhist/varnishhist.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -96,7 +96,7 @@
 };
 
 static void
-update(struct VSL_data *vd)
+update(struct VSM_data *vd)
 {
 	int w = COLS / HIST_RANGE;
 	int n = w * HIST_RANGE;
@@ -116,7 +116,7 @@
 		mvprintw(LINES - 1, w * i, "|1e%d", j);
 	}
 
-	mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd));
+	mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd));
 
 	/* count our flock */
 	for (i = 0; i < n; ++i)
@@ -224,7 +224,7 @@
 static void *
 accumulate_thread(void *arg)
 {
-	struct VSL_data *vd = arg;
+	struct VSM_data *vd = arg;
 	int i;
 
 	for (;;) {
@@ -238,7 +238,7 @@
 }
 
 static void
-do_curses(struct VSL_data *vd)
+do_curses(struct VSM_data *vd)
 {
 	pthread_t thr;
 	int ch;
@@ -319,9 +319,9 @@
 main(int argc, char **argv)
 {
 	int o;
-	struct VSL_data *vd;
+	struct VSM_data *vd;
 
-	vd = VSL_New();
+	vd = VSM_New();
 
 	while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) {
 		switch (o) {
@@ -338,7 +338,7 @@
 		}
 	}
 
-	if (VSL_OpenLog(vd))
+	if (VSM_OpenLog(vd))
 		exit(1);
 
 	log_ten = log(10.0);

Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -195,7 +195,7 @@
 }
 
 static void
-do_order(struct VSL_data *vd, int argc, char * const *argv)
+do_order(struct VSM_data *vd, int argc, char * const *argv)
 {
 	int i;
 	const char *error;
@@ -268,7 +268,7 @@
 }
 
 static void
-do_write(struct VSL_data *vd, const char *w_arg, int a_flag)
+do_write(struct VSM_data *vd, const char *w_arg, int a_flag)
 {
 	int fd, i, l;
 	uint32_t *p;
@@ -316,9 +316,9 @@
 	const char *P_arg = NULL;
 	const char *w_arg = NULL;
 	struct pidfh *pfh = NULL;
-	struct VSL_data *vd;
+	struct VSM_data *vd;
 
-	vd = VSL_New();
+	vd = VSM_New();
 
 	while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDoP:uVw:")) != -1) {
 		switch (c) {
@@ -361,7 +361,7 @@
 	if (o_flag && w_arg != NULL)
 		usage();
 
-	if (VSL_OpenLog(vd))
+	if (VSM_OpenLog(vd))
 		exit(1);
 
 	if (P_arg && (pfh = vpf_open(P_arg, 0644, NULL)) == NULL) {

Modified: trunk/varnish-cache/bin/varnishncsa/varnishncsa.c
===================================================================
--- trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -524,10 +524,10 @@
 	const char *P_arg = NULL;
 	const char *w_arg = NULL;
 	struct pidfh *pfh = NULL;
-	struct VSL_data *vd;
+	struct VSM_data *vd;
 	FILE *of;
 
-	vd = VSL_New();
+	vd = VSM_New();
 
 	while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDP:Vw:f")) != -1) {
 		switch (c) {
@@ -565,7 +565,7 @@
 
 	VSL_Log_Arg(vd, 'c', optarg);
 
-	if (VSL_OpenLog(vd))
+	if (VSM_OpenLog(vd))
 		exit(1);
 
 	if (P_arg && (pfh = vpf_open(P_arg, 0644, NULL)) == NULL) {

Modified: trunk/varnish-cache/bin/varnishreplay/varnishreplay.c
===================================================================
--- trunk/varnish-cache/bin/varnishreplay/varnishreplay.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -717,10 +717,10 @@
 main(int argc, char *argv[])
 {
 	int c;
-	struct VSL_data *vd;
+	struct VSM_data *vd;
 	const char *address = NULL;
 
-	vd = VSL_New();
+	vd = VSM_New();
 	debug = 0;
 
 	VSL_Log_Arg(vd, 'c', NULL);
@@ -743,7 +743,7 @@
 		usage();
 	}
 
-	if (VSL_OpenLog(vd))
+	if (VSM_OpenLog(vd))
 		exit(1);
 
 	addr_info = init_connection(address);

Modified: trunk/varnish-cache/bin/varnishsizes/varnishsizes.c
===================================================================
--- trunk/varnish-cache/bin/varnishsizes/varnishsizes.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishsizes/varnishsizes.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -96,7 +96,7 @@
 };
 
 static void
-update(struct VSL_data *vd)
+update(struct VSM_data *vd)
 {
 	int w = COLS / HIST_RANGE;
 	int n = w * HIST_RANGE;
@@ -116,7 +116,7 @@
 		mvprintw(LINES - 1, w * i, "|1e%d", j);
 	}
 
-	mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd));
+	mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd));
 
 	/* count our flock */
 	for (i = 0; i < n; ++i)
@@ -225,7 +225,7 @@
 static void *
 accumulate_thread(void *arg)
 {
-	struct VSL_data *vd = arg;
+	struct VSM_data *vd = arg;
 	int i;
 
 	for (;;) {
@@ -239,7 +239,7 @@
 }
 
 static void
-do_curses(struct VSL_data *vd)
+do_curses(struct VSM_data *vd)
 {
 	pthread_t thr;
 	int ch;
@@ -320,9 +320,9 @@
 main(int argc, char **argv)
 {
 	int o;
-	struct VSL_data *vd;
+	struct VSM_data *vd;
 
-	vd = VSL_New();
+	vd = VSM_New();
 
 	while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) {
 		switch (o) {
@@ -339,7 +339,7 @@
 		}
 	}
 
-	if (VSL_OpenLog(vd))
+	if (VSM_OpenLog(vd))
 		exit(1);
 
 	log_ten = log(10.0);

Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -74,7 +74,7 @@
 }
 
 static void
-do_xml(const struct VSL_data *vd)
+do_xml(const struct VSM_data *vd)
 {
 	char time_stamp[20];
 	time_t now;
@@ -121,7 +121,7 @@
 }
 
 static void
-do_once(const struct VSL_data *vd, const struct vsc_main *VSL_stats)
+do_once(const struct VSM_data *vd, const struct vsc_main *VSL_stats)
 {
 	struct once_priv op;
 
@@ -153,7 +153,7 @@
 }
 
 static void
-list_fields(const struct VSL_data *vd)
+list_fields(const struct VSM_data *vd)
 {
 	fprintf(stderr, "Varnishstat -f option fields:\n");
 	fprintf(stderr, "Field name                     Description\n");
@@ -192,11 +192,11 @@
 main(int argc, char * const *argv)
 {
 	int c;
-	struct VSL_data *vd;
+	struct VSM_data *vd;
 	const struct vsc_main *VSL_stats;
 	int delay = 1, once = 0, xml = 0;
 
-	vd = VSL_New();
+	vd = VSM_New();
 
 	while ((c = getopt(argc, argv, VSL_STAT_ARGS "1f:lVw:x")) != -1) {
 		switch (c) {
@@ -207,7 +207,7 @@
 			(void)VSL_Stat_Arg(vd, c, optarg);
 			break;
 		case 'l':
-			if (VSL_Open(vd, 1))
+			if (VSM_Open(vd, 1))
 				exit(1);
 			list_fields(vd);
 			exit(0);
@@ -227,10 +227,10 @@
 		}
 	}
 
-	if (VSL_Open(vd, 1))
+	if (VSM_Open(vd, 1))
 		exit(1);
 
-	if ((VSL_stats = VSL_OpenStats(vd)) == NULL)
+	if ((VSL_stats = VSM_OpenStats(vd)) == NULL)
 		exit(1);
 
 	if (xml)

Modified: trunk/varnish-cache/bin/varnishstat/varnishstat.h
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat.h	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat.h	2010-06-08 10:15:00 UTC (rev 4933)
@@ -27,4 +27,4 @@
  *
  */
 
-void do_curses(struct VSL_data *vd, const struct vsc_main *VSL_stats, int delay);
+void do_curses(struct VSM_data *vd, const struct vsc_main *VSL_stats, int delay);

Modified: trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c
===================================================================
--- trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishstat/varnishstat_curses.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -100,7 +100,7 @@
 }
 
 static void
-prep_pts(const struct VSL_data *vd)
+prep_pts(const struct VSM_data *vd)
 {
 	struct pt *pt, *pt2;
 
@@ -123,7 +123,7 @@
 }
 
 void
-do_curses(struct VSL_data *vd, const struct vsc_main *VSL_stats,
+do_curses(struct VSM_data *vd, const struct vsc_main *VSL_stats,
     int delay)
 {
 	intmax_t ju;
@@ -164,7 +164,7 @@
 			 * Only check if it looks like nothing is happening.
 			 */
 			act = VSL_stats->cache_hit + VSL_stats->cache_miss + 1;
-			if (act == lact && VSL_ReOpen(vd, 1))
+			if (act == lact && VSM_ReOpen(vd, 1))
 				break;
 			lact = act;
 
@@ -175,7 +175,7 @@
 			rt = VSL_stats->uptime;
 			up = rt;
 
-			AC(mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd)));
+			AC(mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd)));
 			AC(mvprintw(0, 0, "%d+%02d:%02d:%02d", rt / 86400,
 			    (rt % 86400) / 3600, (rt % 3600) / 60, rt % 60));
 

Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -81,7 +81,7 @@
 	int			vcl_nbr;
 	char			*workdir;
 
-	struct VSL_data		*vd;
+	struct VSM_data		*vd;
 };
 
 static VTAILQ_HEAD(, varnish)	varnishes =
@@ -200,7 +200,7 @@
 	vtc_logclose(v->vl);
 	free(v->name);
 	free(v->workdir);
-	VSL_Delete(v->vd);
+	VSM_Delete(v->vd);
 
 	/*
 	 * We do not delete the workdir, it may contain stuff people
@@ -261,7 +261,7 @@
 	enum cli_status_e u;
 	char *r;
 
-	v->vd = VSL_New();
+	v->vd = VSM_New();
 
 	/* Create listener socket */
 	nap = VSS_resolve("127.0.0.1", "0", &ap);
@@ -363,10 +363,10 @@
 	free(r);
 
 	if (v->stats != NULL)
-		VSL_Close(v->vd);
+		VSM_Close(v->vd);
 	(void)VSL_Log_Arg(v->vd, 'n', v->workdir);
-	AZ(VSL_Open(v->vd, 1));
-	v->stats = VSL_OpenStats(v->vd);
+	AZ(VSM_Open(v->vd, 1));
+	v->stats = VSM_OpenStats(v->vd);
 }
 
 /**********************************************************************

Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c
===================================================================
--- trunk/varnish-cache/bin/varnishtop/varnishtop.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/bin/varnishtop/varnishtop.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -143,7 +143,7 @@
 }
 
 static void
-update(const struct VSL_data *vd)
+update(const struct VSM_data *vd)
 {
 	struct top *tp, *tp2;
 	int l, len;
@@ -158,7 +158,7 @@
 
 	l = 1;
 	AC(erase());
-	AC(mvprintw(0, 0, "%*s", COLS - 1, VSL_Name(vd)));
+	AC(mvprintw(0, 0, "%*s", COLS - 1, VSM_Name(vd)));
 	AC(mvprintw(0, 0, "list length %u", ntop));
 	VTAILQ_FOREACH_SAFE(tp, &top_head, list, tp2) {
 		if (++l < LINES) {
@@ -185,7 +185,7 @@
 static void *
 accumulate_thread(void *arg)
 {
-	struct VSL_data *vd = arg;
+	struct VSM_data *vd = arg;
 	uint32_t *p;
 	int i;
 
@@ -207,7 +207,7 @@
 }
 
 static void
-do_curses(struct VSL_data *vd)
+do_curses(struct VSM_data *vd)
 {
 	pthread_t thr;
 	int i;
@@ -284,7 +284,7 @@
 }
 
 static void
-do_once(struct VSL_data *vd)
+do_once(struct VSM_data *vd)
 {
 	uint32_t *p;
 
@@ -304,10 +304,10 @@
 int
 main(int argc, char **argv)
 {
-	struct VSL_data *vd;
+	struct VSM_data *vd;
 	int o, once = 0;
 
-	vd = VSL_New();
+	vd = VSM_New();
 
 	while ((o = getopt(argc, argv, VSL_LOG_ARGS "1fV")) != -1) {
 		switch (o) {
@@ -328,7 +328,7 @@
 		}
 	}
 
-	if (VSL_OpenLog(vd))
+	if (VSM_OpenLog(vd))
 		exit (1);
 
 	if (once) {

Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/include/varnishapi.h	2010-06-08 10:15:00 UTC (rev 4933)
@@ -42,10 +42,10 @@
 
 
 /*---------------------------------------------------------------------
- * Level 0:  Create and destroy the VSL_data handle structure
+ * VSM level access functions
  */
 
-struct VSL_data *VSL_New(void);
+struct VSM_data *VSM_New(void);
 	/*
 	 * Allocate and initialize a VSL_data handle structure.
 	 * This is the first thing you will have to do, always.
@@ -55,16 +55,16 @@
 	 * 	Pointer to usable VSL_data handle.
 	 */
 
-typedef void vsl_diag_f(void *priv, const char *fmt, ...);
+typedef void vsm_diag_f(void *priv, const char *fmt, ...);
 
-void VSL_Diag(struct VSL_data *vd, vsl_diag_f *func, void *priv);
+void VSM_Diag(struct VSM_data *vd, vsm_diag_f *func, void *priv);
 	/*
 	 * Set the diagnostics reporting function.
 	 * Default is fprintf(stderr, ...)
 	 * If func is NULL, diagnostics are disabled.
 	 */
 
-int VSL_n_Arg(struct VSL_data *vd, const char *n_arg);
+int VSM_n_Arg(struct VSM_data *vd, const char *n_arg);
 	/*
 	 * Configure which varnishd instance to access.
 	 * Can also be, and normally is done through the VSL_Log_arg()
@@ -74,23 +74,19 @@
 	 *	 -1 on failure, with diagnostic on stderr.
 	 */
 
-const char *VSL_Name(const struct VSL_data *vd);
+const char *VSM_Name(const struct VSM_data *vd);
 	/*
 	 * Return the instance name.
 	 */
 
-void VSL_Delete(struct VSL_data *vd);
+void VSM_Delete(struct VSM_data *vd);
 	/*
 	 * Close and deallocate all storage and mappings.
 	 */
 
 /* XXX: extension:  Patience argument for sleeps */
 
-/*---------------------------------------------------------------------
- * Level 1:  Open/Close and find allocation in shared memory segment
- */
-
-int VSL_Open(struct VSL_data *vd, int diag);
+int VSM_Open(struct VSM_data *vd, int diag);
 	/*
 	 * Attempt to open and map the shared memory file.
 	 * If diag is non-zero, diagnostics are emitted.
@@ -99,22 +95,33 @@
 	 * 	!= 0 on failure
 	 */
 
-int VSL_ReOpen(struct VSL_data *vd, int diag);
+int VSM_ReOpen(struct VSM_data *vd, int diag);
 	/*
 	 * Check if shared memory segment needs to be reopened/remapped
 	 * typically when the varnishd master process restarts.
-	 * diag is passed to VSL_Open()
+	 * diag is passed to VSM_Open()
 	 * Returns:
 	 *	0  No reopen needed.
 	 *	1  shared memory reopened/remapped.
 	 *	-1 failure to reopen.
 	 */
 
-void *VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type,
+struct vsm_head *VSM_Head(struct VSM_data *vd);
+	/*
+	 * Return the head of the VSM.
+	 */
+
+void *VSM_Find_Chunk(struct VSM_data *vd, const char *class, const char *type,
     const char *ident, unsigned *lenp);
-void VSL_Close(struct VSL_data *vd);
+void VSM_Close(struct VSM_data *vd);
 
+struct vsm_chunk *vsm_iter0(const struct VSM_data *vd);
+void vsm_itern(const struct VSM_data *vd, struct vsm_chunk **pp);
 
+#define VSM_FOREACH(var, vd) \
+	for((var) = vsm_iter0((vd)); (var) != NULL; vsm_itern((vd), &(var)))
+
+
 /* shmlog.c */
 typedef int vsl_handler(void *priv, enum vsl_tag tag, unsigned fd,
     unsigned len, unsigned spec, const char *ptr);
@@ -125,24 +132,18 @@
 #define VSL_USAGE	"[-bCcd] [-i tag] [-I regexp] [-k keep]" \
 			" [-r file] [-s skip] [-X regexp] [-x tag]"
 vsl_handler VSL_H_Print;
-struct VSL_data;
-void VSL_Select(const struct VSL_data *vd, unsigned tag);
-int VSL_OpenLog(struct VSL_data *vd);
-void VSL_NonBlocking(struct VSL_data *vd, int nb);
-int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv);
-int VSL_NextLog(struct VSL_data *lh, uint32_t **pp);
-int VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt);
-int VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt);
-struct vsc_main *VSL_OpenStats(struct VSL_data *vd);
+struct VSM_data;
+void VSL_Select(const struct VSM_data *vd, unsigned tag);
+int VSM_OpenLog(struct VSM_data *vd);
+void VSL_NonBlocking(struct VSM_data *vd, int nb);
+int VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv);
+int VSL_NextLog(struct VSM_data *lh, uint32_t **pp);
+int VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt);
+int VSL_Stat_Arg(struct VSM_data *vd, int arg, const char *opt);
+struct vsc_main *VSM_OpenStats(struct VSM_data *vd);
 extern const char *VSL_tags[256];
 
 
-struct vsm_chunk *vsl_iter0(const struct VSL_data *vd);
-void vsl_itern(const struct VSL_data *vd, struct vsm_chunk **pp);
-
-#define VSL_FOREACH(var, vd) \
-	for((var) = vsl_iter0((vd)); (var) != NULL; vsl_itern((vd), &(var)))
-
 struct vsl_statpt {
 	const char *class;	/* stat struct type			*/
 	const char *ident;	/* stat struct ident			*/
@@ -155,7 +156,7 @@
 
 typedef int vsl_stat_f(void *priv, const struct vsl_statpt *const pt);
 
-int VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv);
+int VSL_IterStat(const struct VSM_data *vd, vsl_stat_f *func, void *priv);
 
 /* base64.c */
 void base64_init(void);

Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/Makefile.am	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am	2010-06-08 10:15:00 UTC (rev 4933)
@@ -17,7 +17,7 @@
 	../libvarnish/vmb.c \
 	../libvarnish/vre.c \
 	base64.c \
-	vsl.c \
+	vsm.c \
 	vsl_arg.c \
 	vsl_log.c \
 	vsl_stat.c

Deleted: trunk/varnish-cache/lib/libvarnishapi/vsl.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -1,340 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2010 Redpill Linpro AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include "config.h"
-
-#include "svnid.h"
-SVNID("$Id$")
-
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "vas.h"
-#include "vin.h"
-#include "vsm.h"
-#include "vre.h"
-#include "vbm.h"
-#include "vqueue.h"
-#include "miniobj.h"
-#include "varnishapi.h"
-
-#include "vslapi.h"
-
-#ifndef MAP_HASSEMAPHORE
-#define MAP_HASSEMAPHORE 0 /* XXX Linux */
-#endif
-
-/*--------------------------------------------------------------------*/
-
-struct VSL_data *
-VSL_New(void)
-{
-	struct VSL_data *vd;
-
-	ALLOC_OBJ(vd, VSL_MAGIC);
-	AN(vd);
-
-	vd->diag = (vsl_diag_f*)fprintf;
-	vd->priv = stderr;
-
-	vd->vsl_fd = -1;
-
-	vd->regflags = 0;
-
-	/* XXX: Allocate only if log access */
-	vd->vbm_client = vbit_init(4096);
-	vd->vbm_backend = vbit_init(4096);
-	vd->vbm_supress = vbit_init(256);
-	vd->vbm_select = vbit_init(256);
-
-	vd->r_fd = -1;
-	/* XXX: Allocate only if -r option given ? */
-	vd->rbuflen = 256;	/* XXX ?? */
-	vd->rbuf = malloc(vd->rbuflen * 4);
-	assert(vd->rbuf != NULL);
-
-	VTAILQ_INIT(&vd->sf_list);
-
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
-	return (vd);
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-VSL_Diag(struct VSL_data *vd, vsl_diag_f *func, void *priv)
-{
-
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
-	if (func == NULL)
-		vd->diag = (vsl_diag_f*)getpid;
-	else
-		vd->diag = func;
-	vd->priv = priv;
-}
-
-/*--------------------------------------------------------------------*/
-
-int
-VSL_n_Arg(struct VSL_data *vd, const char *opt)
-{
-
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
-	REPLACE(vd->n_opt, opt);
-	AN(vd->n_opt);
-	if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) {
-		vd->diag(vd->priv, "Invalid instance name: %s\n",
-		    strerror(errno));
-		return (-1);
-	}
-	return (1);
-}
-
-/*--------------------------------------------------------------------*/
-
-const char *
-VSL_Name(const struct VSL_data *vd)
-{
-
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
-	return (vd->n_opt);
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-VSL_Delete(struct VSL_data *vd)
-{
-	struct vsl_sf *sf;
-
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
-	VSL_Close(vd);
-	vbit_destroy(vd->vbm_client);
-	vbit_destroy(vd->vbm_backend);
-	vbit_destroy(vd->vbm_supress);
-	vbit_destroy(vd->vbm_select);
-	free(vd->n_opt);
-	free(vd->rbuf);
-	free(vd->fname);
-
-	while(!VTAILQ_EMPTY(&vd->sf_list)) {
-		sf = VTAILQ_FIRST(&vd->sf_list);
-		VTAILQ_REMOVE(&vd->sf_list, sf, next);
-		free(sf->class);
-		free(sf->ident);
-		free(sf->name);
-		free(sf);
-	}
-
-	free(vd);
-}
-
-/*--------------------------------------------------------------------*/
-
-static int
-vsl_open(struct VSL_data *vd, int diag)
-{
-	int i;
-	struct vsm_head slh;
-
-	if (vd->vsl_lh != NULL)
-		return (0);
-
-	vd->vsl_fd = open(vd->fname, O_RDONLY);
-	if (vd->vsl_fd < 0) {
-		if (diag)
-			vd->diag(vd->priv, "Cannot open %s: %s\n",
-			    vd->fname, strerror(errno));
-		return (1);
-	}
-
-	assert(fstat(vd->vsl_fd, &vd->fstat) == 0);
-	if (!S_ISREG(vd->fstat.st_mode)) {
-		if (diag)
-			vd->diag(vd->priv, "%s is not a regular file\n",
-			    vd->fname);
-		return (1);
-	}
-
-	i = read(vd->vsl_fd, &slh, sizeof slh);
-	if (i != sizeof slh) {
-		if (diag)
-			vd->diag(vd->priv, "Cannot read %s: %s\n",
-			    vd->fname, strerror(errno));
-		return (1);
-	}
-	if (slh.magic != VSM_HEAD_MAGIC) {
-		if (diag)
-			vd->diag(vd->priv, "Wrong magic number in file %s\n",
-			    vd->fname);
-		return (1);
-	}
-
-	vd->vsl_lh = (void *)mmap(NULL, slh.shm_size,
-	    PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsl_fd, 0);
-	if (vd->vsl_lh == MAP_FAILED) {
-		if (diag)
-			vd->diag(vd->priv, "Cannot mmap %s: %s\n",
-			    vd->fname, strerror(errno));
-		return (1);
-	}
-	vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size;
-
-	while(slh.alloc_seq == 0)
-		usleep(50000);			/* XXX limit total sleep */
-	vd->alloc_seq = slh.alloc_seq;
-	return (0);
-}
-
-/*--------------------------------------------------------------------*/
-
-int
-VSL_Open(struct VSL_data *vd, int diag)
-
-{
-
-	return (vsl_open(vd, diag));
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-VSL_Close(struct VSL_data *vd)
-{
-	if (vd->vsl_lh == NULL)
-		return;
-	assert(0 == munmap((void*)vd->vsl_lh, vd->vsl_lh->shm_size));
-	vd->vsl_lh = NULL;
-	assert(vd->vsl_fd >= 0);
-	assert(0 == close(vd->vsl_fd));
-	vd->vsl_fd = -1;
-}
-
-/*--------------------------------------------------------------------*/
-
-int
-VSL_ReOpen(struct VSL_data *vd, int diag)
-{
-	struct stat st;
-	int i;
-
-	AN(vd->vsl_lh);
-
-	if (stat(vd->fname, &st))
-		return (0);
-
-	if (st.st_dev == vd->fstat.st_dev && st.st_ino == vd->fstat.st_ino)
-		return (0);
-
-	VSL_Close(vd);
-	for (i = 0; i < 5; i++) {		/* XXX param */
-		if (!vsl_open(vd, 0))
-			return (1);
-	}
-	if (vsl_open(vd, diag))
-		return (-1);
-	return (1);
-}
-
-/*--------------------------------------------------------------------*/
-
-struct vsm_chunk *
-vsl_iter0(const struct VSL_data *vd)
-{
-
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
-	if (vd->alloc_seq != vd->vsl_lh->alloc_seq)
-		return(NULL);
-	CHECK_OBJ_NOTNULL(&vd->vsl_lh->head, VSM_CHUNK_MAGIC);
-	return (&vd->vsl_lh->head);
-}
-
-void
-vsl_itern(const struct VSL_data *vd, struct vsm_chunk **pp)
-{
-
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
-	if (vd->alloc_seq != vd->vsl_lh->alloc_seq) {
-		*pp = NULL;
-		return;
-	}
-	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
-	*pp = VSM_NEXT(*pp);
-	if ((void*)(*pp) >= vd->vsl_end) {
-		*pp = NULL;
-		return;
-	}
-	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
-}
-
-/*--------------------------------------------------------------------*/
-
-struct vsm_chunk *
-vsl_find_alloc(const struct VSL_data *vd, const char *class, const char *type, const char *ident)
-{
-	struct vsm_chunk *sha;
-
-	assert (vd->vsl_lh != NULL);
-	VSL_FOREACH(sha, vd) {
-		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
-		if (strcmp(sha->class, class))
-			continue;
-		if (type != NULL && strcmp(sha->type, type))
-			continue;
-		if (ident != NULL && strcmp(sha->ident, ident))
-			continue;
-		return (sha);
-	}
-	return (NULL);
-}
-
-/*--------------------------------------------------------------------*/
-
-void *
-VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident,
-    unsigned *lenp)
-{
-	struct vsm_chunk *sha;
-
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
-	sha = vsl_find_alloc(vd, class, type, ident);
-	if (sha == NULL)
-		return (NULL);
-	if (lenp != NULL)
-		*lenp = sha->len - sizeof *sha;
-	return (VSM_PTR(sha));
-}

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -57,10 +57,10 @@
 /*--------------------------------------------------------------------*/
 
 static int
-vsl_r_arg(struct VSL_data *vd, const char *opt)
+vsl_r_arg(struct VSM_data *vd, const char *opt)
 {
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	if (!strcmp(opt, "-"))
 		vd->r_fd = STDIN_FILENO;
 	else
@@ -75,13 +75,13 @@
 /*--------------------------------------------------------------------*/
 
 static int
-vsl_IX_arg(struct VSL_data *vd, const char *opt, int arg)
+vsl_IX_arg(struct VSM_data *vd, const char *opt, int arg)
 {
 	vre_t **rp;
 	const char *error;
 	int erroroffset;
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	if (arg == 'I')
 		rp = &vd->regincl;
 	else
@@ -101,12 +101,12 @@
 /*--------------------------------------------------------------------*/
 
 static int
-vsl_ix_arg(struct VSL_data *vd, const char *opt, int arg)
+vsl_ix_arg(struct VSM_data *vd, const char *opt, int arg)
 {
 	int i, j, l;
 	const char *b, *e, *p, *q;
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	/* If first option is 'i', set all bits for supression */
 	if (arg == 'i' && !(vd->flags & F_SEEN_IX))
 		for (i = 0; i < 256; i++)
@@ -153,11 +153,11 @@
 /*--------------------------------------------------------------------*/
 
 static int
-vsl_s_arg(struct VSL_data *vd, const char *opt)
+vsl_s_arg(struct VSM_data *vd, const char *opt)
 {
 	char *end;
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	if (*opt == '\0') {
 		fprintf(stderr, "number required for -s\n");
 		return (-1);
@@ -173,11 +173,11 @@
 /*--------------------------------------------------------------------*/
 
 static int
-vsl_k_arg(struct VSL_data *vd, const char *opt)
+vsl_k_arg(struct VSM_data *vd, const char *opt)
 {
 	char *end;
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	if (*opt == '\0') {
 		fprintf(stderr, "number required for -k\n");
 		return (-1);
@@ -193,10 +193,10 @@
 /*--------------------------------------------------------------------*/
 
 int
-VSL_Log_Arg(struct VSL_data *vd, int arg, const char *opt)
+VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt)
 {
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	switch (arg) {
 	case 'b': vd->b_opt = !vd->b_opt; return (1);
 	case 'c': vd->c_opt = !vd->c_opt; return (1);
@@ -206,7 +206,7 @@
 		return (1);
 	case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg));
 	case 'k': return (vsl_k_arg(vd, opt));
-	case 'n': return (VSL_n_Arg(vd, opt));
+	case 'n': return (VSM_n_Arg(vd, opt));
 	case 'r': return (vsl_r_arg(vd, opt));
 	case 's': return (vsl_s_arg(vd, opt));
 	case 'I': case 'X': return (vsl_IX_arg(vd, opt, arg));
@@ -229,13 +229,13 @@
 /*--------------------------------------------------------------------*/
 
 static int
-vsl_sf_arg(struct VSL_data *vd, const char *opt)
+vsl_sf_arg(struct VSM_data *vd, const char *opt)
 {
 	struct vsl_sf *sf;
 	char **av, *q, *p;
 	int i;
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 
 	if (VTAILQ_EMPTY(&vd->sf_list)) {
 		if (*opt == '^')
@@ -309,13 +309,13 @@
 /*--------------------------------------------------------------------*/
 
 int
-VSL_Stat_Arg(struct VSL_data *vd, int arg, const char *opt)
+VSL_Stat_Arg(struct VSM_data *vd, int arg, const char *opt)
 {
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	switch (arg) {
 	case 'f': return (vsl_sf_arg(vd, opt));
-	case 'n': return (VSL_n_Arg(vd, opt));
+	case 'n': return (VSM_n_Arg(vd, opt));
 	default:
 		return (0);
 	}

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_log.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_log.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_log.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -52,7 +52,7 @@
 #include "vslapi.h"
 #include "vmb.h"
 
-static int vsl_nextlog(struct VSL_data *vd, uint32_t **pp);
+static int vsl_nextlog(struct VSM_data *vd, uint32_t **pp);
 
 /*--------------------------------------------------------------------*/
 
@@ -65,10 +65,10 @@
 /*--------------------------------------------------------------------*/
 
 void
-VSL_Select(const struct VSL_data *vd, unsigned tag)
+VSL_Select(const struct VSM_data *vd, unsigned tag)
 {
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	vbit_set(vd->vbm_select, tag);
 }
 
@@ -76,7 +76,7 @@
 /*--------------------------------------------------------------------*/
 
 void
-VSL_NonBlocking(struct VSL_data *vd, int nb)
+VSL_NonBlocking(struct VSM_data *vd, int nb)
 {
 	if (nb)
 		vd->flags |= F_NON_BLOCKING;
@@ -87,13 +87,13 @@
 /*--------------------------------------------------------------------*/
 
 static int
-vsl_nextlog(struct VSL_data *vd, uint32_t **pp)
+vsl_nextlog(struct VSM_data *vd, uint32_t **pp)
 {
 	unsigned w, l;
 	uint32_t t;
 	int i;
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	if (vd->r_fd != -1) {
 		assert(vd->rbuflen >= 8);
 		i = read(vd->r_fd, vd->rbuf, 8);
@@ -138,14 +138,14 @@
 }
 
 int
-VSL_NextLog(struct VSL_data *vd, uint32_t **pp)
+VSL_NextLog(struct VSM_data *vd, uint32_t **pp)
 {
 	uint32_t *p;
 	unsigned char t;
 	unsigned u;
 	int i;
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	while (1) {
 		i = vsl_nextlog(vd, &p);
 		if (i != 1)
@@ -204,13 +204,13 @@
 /*--------------------------------------------------------------------*/
 
 int
-VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv)
+VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv)
 {
 	int i;
 	unsigned u, l, s;
 	uint32_t *p;
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 	while (1) {
 		i = VSL_NextLog(vd, &p);
 		if (i != 1)
@@ -260,12 +260,12 @@
 /*--------------------------------------------------------------------*/
 
 int
-VSL_OpenLog(struct VSL_data *vd)
+VSM_OpenLog(struct VSM_data *vd)
 {
 	struct vsm_chunk *sha;
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
-	sha = vsl_find_alloc(vd, VSL_CLASS, "", "");
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	sha = vsm_find_alloc(vd, VSL_CLASS, "", "");
 	assert(sha != NULL);
 
 	vd->log_start = VSM_PTR(sha);

Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_stat.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -49,13 +49,13 @@
 /*--------------------------------------------------------------------*/
 
 struct vsc_main *
-VSL_OpenStats(struct VSL_data *vd)
+VSM_OpenStats(struct VSM_data *vd)
 {
 	struct vsm_chunk *sha;
 
-	CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
 
-	sha = vsl_find_alloc(vd, VSC_CLASS, "", "");
+	sha = vsm_find_alloc(vd, VSC_CLASS, "", "");
 	assert(sha != NULL);
 	return (VSM_PTR(sha));
 }
@@ -78,7 +78,7 @@
 }
 
 static int
-iter_call(const struct VSL_data *vd, vsl_stat_f *func, void *priv,
+iter_call(const struct VSM_data *vd, vsl_stat_f *func, void *priv,
     const struct vsl_statpt *const sp)
 {
 	struct vsl_sf *sf;
@@ -105,7 +105,7 @@
 }
 
 static int
-iter_main(const struct VSL_data *vd, struct vsm_chunk *sha, vsl_stat_f *func,
+iter_main(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func,
     void *priv)
 {
 	struct vsc_main *st = VSM_PTR(sha);
@@ -129,7 +129,7 @@
 }
 
 static int
-iter_sma(const struct VSL_data *vd, struct vsm_chunk *sha, vsl_stat_f *func,
+iter_sma(const struct VSM_data *vd, struct vsm_chunk *sha, vsl_stat_f *func,
     void *priv)
 {
 	struct vsc_sma *st = VSM_PTR(sha);
@@ -153,13 +153,13 @@
 }
 
 int
-VSL_IterStat(const struct VSL_data *vd, vsl_stat_f *func, void *priv)
+VSL_IterStat(const struct VSM_data *vd, vsl_stat_f *func, void *priv)
 {
 	struct vsm_chunk *sha;
 	int i;
 
 	i = 0;
-	VSL_FOREACH(sha, vd) {
+	VSM_FOREACH(sha, vd) {
 		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
 		if (strcmp(sha->class, VSC_CLASS))
 			continue;

Modified: trunk/varnish-cache/lib/libvarnishapi/vslapi.h
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vslapi.h	2010-06-08 10:01:46 UTC (rev 4932)
+++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h	2010-06-08 10:15:00 UTC (rev 4933)
@@ -47,11 +47,11 @@
 	char			*name;
 };
 
-struct VSL_data {
+struct VSM_data {
 	unsigned		magic;
-#define VSL_MAGIC		0x6e3bd69b
+#define VSM_MAGIC		0x6e3bd69b
 
-	vsl_diag_f		*diag;
+	vsm_diag_f		*diag;
 	void			*priv;
 
 	char			*n_opt;
@@ -117,5 +117,5 @@
 	unsigned long		keep;
 };
 
-struct vsm_chunk *vsl_find_alloc(const struct VSL_data *vd, const char *class,
+struct vsm_chunk *vsm_find_alloc(const struct VSM_data *vd, const char *class,
     const char *type, const char *ident);

Copied: trunk/varnish-cache/lib/libvarnishapi/vsm.c (from rev 4928, trunk/varnish-cache/lib/libvarnishapi/vsl.c)
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsm.c	                        (rev 0)
+++ trunk/varnish-cache/lib/libvarnishapi/vsm.c	2010-06-08 10:15:00 UTC (rev 4933)
@@ -0,0 +1,358 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2010 Redpill Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "svnid.h"
+SVNID("$Id$")
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "vas.h"
+#include "vin.h"
+#include "vsm.h"
+#include "vre.h"
+#include "vbm.h"
+#include "vqueue.h"
+#include "miniobj.h"
+#include "varnishapi.h"
+
+#include "vslapi.h"
+
+#ifndef MAP_HASSEMAPHORE
+#define MAP_HASSEMAPHORE 0 /* XXX Linux */
+#endif
+
+/*--------------------------------------------------------------------*/
+
+struct VSM_data *
+VSM_New(void)
+{
+	struct VSM_data *vd;
+
+	ALLOC_OBJ(vd, VSM_MAGIC);
+	AN(vd);
+
+	vd->diag = (vsm_diag_f*)fprintf;
+	vd->priv = stderr;
+
+	vd->vsl_fd = -1;
+
+	vd->regflags = 0;
+
+	/* XXX: Allocate only if log access */
+	vd->vbm_client = vbit_init(4096);
+	vd->vbm_backend = vbit_init(4096);
+	vd->vbm_supress = vbit_init(256);
+	vd->vbm_select = vbit_init(256);
+
+	vd->r_fd = -1;
+	/* XXX: Allocate only if -r option given ? */
+	vd->rbuflen = 256;	/* XXX ?? */
+	vd->rbuf = malloc(vd->rbuflen * 4);
+	assert(vd->rbuf != NULL);
+
+	VTAILQ_INIT(&vd->sf_list);
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	return (vd);
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+VSM_Diag(struct VSM_data *vd, vsm_diag_f *func, void *priv)
+{
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	if (func == NULL)
+		vd->diag = (vsm_diag_f*)getpid;
+	else
+		vd->diag = func;
+	vd->priv = priv;
+}
+
+/*--------------------------------------------------------------------*/
+
+int
+VSM_n_Arg(struct VSM_data *vd, const char *opt)
+{
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	REPLACE(vd->n_opt, opt);
+	AN(vd->n_opt);
+	if (vin_n_arg(vd->n_opt, NULL, NULL, &vd->fname)) {
+		vd->diag(vd->priv, "Invalid instance name: %s\n",
+		    strerror(errno));
+		return (-1);
+	}
+	return (1);
+}
+
+/*--------------------------------------------------------------------*/
+
+const char *
+VSM_Name(const struct VSM_data *vd)
+{
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	return (vd->n_opt);
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+VSM_Delete(struct VSM_data *vd)
+{
+	struct vsl_sf *sf;
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	VSM_Close(vd);
+	vbit_destroy(vd->vbm_client);
+	vbit_destroy(vd->vbm_backend);
+	vbit_destroy(vd->vbm_supress);
+	vbit_destroy(vd->vbm_select);
+	free(vd->n_opt);
+	free(vd->rbuf);
+	free(vd->fname);
+
+	while(!VTAILQ_EMPTY(&vd->sf_list)) {
+		sf = VTAILQ_FIRST(&vd->sf_list);
+		VTAILQ_REMOVE(&vd->sf_list, sf, next);
+		free(sf->class);
+		free(sf->ident);
+		free(sf->name);
+		free(sf);
+	}
+
+	free(vd);
+}
+
+/*--------------------------------------------------------------------*/
+
+static int
+vsl_open(struct VSM_data *vd, int diag)
+{
+	int i;
+	struct vsm_head slh;
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	if (vd->vsl_lh != NULL)
+		return (0);
+
+	vd->vsl_fd = open(vd->fname, O_RDONLY);
+	if (vd->vsl_fd < 0) {
+		if (diag)
+			vd->diag(vd->priv, "Cannot open %s: %s\n",
+			    vd->fname, strerror(errno));
+		return (1);
+	}
+
+	assert(fstat(vd->vsl_fd, &vd->fstat) == 0);
+	if (!S_ISREG(vd->fstat.st_mode)) {
+		if (diag)
+			vd->diag(vd->priv, "%s is not a regular file\n",
+			    vd->fname);
+		return (1);
+	}
+
+	i = read(vd->vsl_fd, &slh, sizeof slh);
+	if (i != sizeof slh) {
+		if (diag)
+			vd->diag(vd->priv, "Cannot read %s: %s\n",
+			    vd->fname, strerror(errno));
+		return (1);
+	}
+	if (slh.magic != VSM_HEAD_MAGIC) {
+		if (diag)
+			vd->diag(vd->priv, "Wrong magic number in file %s\n",
+			    vd->fname);
+		return (1);
+	}
+
+	vd->vsl_lh = (void *)mmap(NULL, slh.shm_size,
+	    PROT_READ, MAP_SHARED|MAP_HASSEMAPHORE, vd->vsl_fd, 0);
+	if (vd->vsl_lh == MAP_FAILED) {
+		if (diag)
+			vd->diag(vd->priv, "Cannot mmap %s: %s\n",
+			    vd->fname, strerror(errno));
+		return (1);
+	}
+	vd->vsl_end = (uint8_t *)vd->vsl_lh + slh.shm_size;
+
+	while(slh.alloc_seq == 0)
+		usleep(50000);			/* XXX limit total sleep */
+	vd->alloc_seq = slh.alloc_seq;
+	return (0);
+}
+
+/*--------------------------------------------------------------------*/
+
+int
+VSM_Open(struct VSM_data *vd, int diag)
+
+{
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	return (vsl_open(vd, diag));
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+VSM_Close(struct VSM_data *vd)
+{
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	if (vd->vsl_lh == NULL)
+		return;
+	assert(0 == munmap((void*)vd->vsl_lh, vd->vsl_lh->shm_size));
+	vd->vsl_lh = NULL;
+	assert(vd->vsl_fd >= 0);
+	assert(0 == close(vd->vsl_fd));
+	vd->vsl_fd = -1;
+}
+
+/*--------------------------------------------------------------------*/
+
+int
+VSM_ReOpen(struct VSM_data *vd, int diag)
+{
+	struct stat st;
+	int i;
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	AN(vd->vsl_lh);
+
+	if (stat(vd->fname, &st))
+		return (0);
+
+	if (st.st_dev == vd->fstat.st_dev && st.st_ino == vd->fstat.st_ino)
+		return (0);
+
+	VSM_Close(vd);
+	for (i = 0; i < 5; i++) {		/* XXX param */
+		if (!vsl_open(vd, 0))
+			return (1);
+	}
+	if (vsl_open(vd, diag))
+		return (-1);
+	return (1);
+}
+
+/*--------------------------------------------------------------------*/
+
+struct vsm_head *
+VSM_Head(struct VSM_data *vd)
+{
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	AN(vd->vsl_lh);
+	return(vd->vsl_lh);
+}
+
+
+/*--------------------------------------------------------------------*/
+
+struct vsm_chunk *
+vsm_find_alloc(const struct VSM_data *vd, const char *class, const char *type, const char *ident)
+{
+	struct vsm_chunk *sha;
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	assert (vd->vsl_lh != NULL);
+	VSM_FOREACH(sha, vd) {
+		CHECK_OBJ_NOTNULL(sha, VSM_CHUNK_MAGIC);
+		if (strcmp(sha->class, class))
+			continue;
+		if (type != NULL && strcmp(sha->type, type))
+			continue;
+		if (ident != NULL && strcmp(sha->ident, ident))
+			continue;
+		return (sha);
+	}
+	return (NULL);
+}
+
+/*--------------------------------------------------------------------*/
+
+void *
+VSM_Find_Chunk(struct VSM_data *vd, const char *class, const char *type, const char *ident,
+    unsigned *lenp)
+{
+	struct vsm_chunk *sha;
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	sha = vsm_find_alloc(vd, class, type, ident);
+	if (sha == NULL)
+		return (NULL);
+	if (lenp != NULL)
+		*lenp = sha->len - sizeof *sha;
+	return (VSM_PTR(sha));
+}
+
+/*--------------------------------------------------------------------*/
+
+struct vsm_chunk *
+vsm_iter0(const struct VSM_data *vd)
+{
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	if (vd->alloc_seq != vd->vsl_lh->alloc_seq)
+		return(NULL);
+	CHECK_OBJ_NOTNULL(&vd->vsl_lh->head, VSM_CHUNK_MAGIC);
+	return (&vd->vsl_lh->head);
+}
+
+void
+vsm_itern(const struct VSM_data *vd, struct vsm_chunk **pp)
+{
+
+	CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+	if (vd->alloc_seq != vd->vsl_lh->alloc_seq) {
+		*pp = NULL;
+		return;
+	}
+	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
+	*pp = VSM_NEXT(*pp);
+	if ((void*)(*pp) >= vd->vsl_end) {
+		*pp = NULL;
+		return;
+	}
+	CHECK_OBJ_NOTNULL(*pp, VSM_CHUNK_MAGIC);
+}




More information about the varnish-commit mailing list