r4940 - in trunk/varnish-cache: bin/varnishhist bin/varnishlog bin/varnishncsa bin/varnishreplay bin/varnishsizes bin/varnishtop include lib/libvarnishapi
phk at varnish-cache.org
phk at varnish-cache.org
Wed Jun 9 11:34:55 CEST 2010
Author: phk
Date: 2010-06-09 11:34:55 +0200 (Wed, 09 Jun 2010)
New Revision: 4940
Added:
trunk/varnish-cache/lib/libvarnishapi/vsm_api.h
Removed:
trunk/varnish-cache/lib/libvarnishapi/vslapi.h
Modified:
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/varnishtop/varnishtop.c
trunk/varnish-cache/include/varnishapi.h
trunk/varnish-cache/lib/libvarnishapi/Makefile.am
trunk/varnish-cache/lib/libvarnishapi/vsc.c
trunk/varnish-cache/lib/libvarnishapi/vsl.c
trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c
trunk/varnish-cache/lib/libvarnishapi/vsm.c
Log:
Delaminate the VSL api from the VSM api
Modified: trunk/varnish-cache/bin/varnishhist/varnishhist.c
===================================================================
--- trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-08 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/bin/varnishhist/varnishhist.c 2010-06-09 09:34:55 UTC (rev 4940)
@@ -322,6 +322,7 @@
struct VSM_data *vd;
vd = VSM_New();
+ VSL_Setup(vd);
while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) {
switch (o) {
@@ -338,7 +339,7 @@
}
}
- if (VSM_OpenLog(vd))
+ if (VSL_Open(vd, 1))
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 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c 2010-06-09 09:34:55 UTC (rev 4940)
@@ -41,7 +41,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <limits.h>
#include "compat/daemon.h"
@@ -80,7 +79,7 @@
#define F_MATCH (1 << 1)
static int match_tag = -1;
-static vre_t *match_re;
+static const vre_t *match_re;
static void
h_order_finish(int fd)
@@ -195,7 +194,7 @@
}
static void
-do_order(struct VSM_data *vd, int argc, char * const *argv)
+do_order(const struct VSM_data *vd, int argc, char * const *argv)
{
int i;
const char *error;
@@ -268,7 +267,7 @@
}
static void
-do_write(struct VSM_data *vd, const char *w_arg, int a_flag)
+do_write(const struct VSM_data *vd, const char *w_arg, int a_flag)
{
int fd, i, l;
uint32_t *p;
@@ -282,7 +281,7 @@
break;
if (i > 0) {
l = VSL_LEN(p);
- i = write(fd, p, 8 + VSL_WORDS(l) * 4);
+ i = write(fd, p, 8L + VSL_WORDS(l) * 4L);
if (i < 0) {
perror(w_arg);
exit(1);
@@ -319,6 +318,7 @@
struct VSM_data *vd;
vd = VSM_New();
+ VSL_Setup(vd);
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 (VSM_OpenLog(vd))
+ if (VSL_Open(vd, 1))
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 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/bin/varnishncsa/varnishncsa.c 2010-06-09 09:34:55 UTC (rev 4940)
@@ -528,6 +528,7 @@
FILE *of;
vd = VSM_New();
+ VSL_Setup(vd);
while ((c = getopt(argc, argv, VSL_LOG_ARGS "aDP:Vw:f")) != -1) {
switch (c) {
@@ -565,7 +566,7 @@
VSL_Log_Arg(vd, 'c', optarg);
- if (VSM_OpenLog(vd))
+ if (VSL_Open(vd, 1))
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 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/bin/varnishreplay/varnishreplay.c 2010-06-09 09:34:55 UTC (rev 4940)
@@ -721,6 +721,7 @@
const char *address = NULL;
vd = VSM_New();
+ VSL_Setup(vd);
debug = 0;
VSL_Log_Arg(vd, 'c', NULL);
@@ -743,7 +744,7 @@
usage();
}
- if (VSM_OpenLog(vd))
+ if (VSL_Open(vd, 1))
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 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/bin/varnishsizes/varnishsizes.c 2010-06-09 09:34:55 UTC (rev 4940)
@@ -323,6 +323,7 @@
struct VSM_data *vd;
vd = VSM_New();
+ VSL_Setup(vd);
while ((o = getopt(argc, argv, VSL_LOG_ARGS "Vw:")) != -1) {
switch (o) {
@@ -339,7 +340,7 @@
}
}
- if (VSM_OpenLog(vd))
+ if (VSL_Open(vd, 1))
exit(1);
log_ten = log(10.0);
Modified: trunk/varnish-cache/bin/varnishtop/varnishtop.c
===================================================================
--- trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-08 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/bin/varnishtop/varnishtop.c 2010-06-09 09:34:55 UTC (rev 4940)
@@ -308,6 +308,7 @@
int o, once = 0;
vd = VSM_New();
+ VSL_Setup(vd);
while ((o = getopt(argc, argv, VSL_LOG_ARGS "1fV")) != -1) {
switch (o) {
@@ -328,7 +329,7 @@
}
}
- if (VSM_OpenLog(vd))
+ if (VSL_Open(vd, 1))
exit (1);
if (once) {
Modified: trunk/varnish-cache/include/varnishapi.h
===================================================================
--- trunk/varnish-cache/include/varnishapi.h 2010-06-08 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/include/varnishapi.h 2010-06-09 09:34:55 UTC (rev 4940)
@@ -188,6 +188,21 @@
* VSL level access functions
*/
+void VSL_Setup(struct VSM_data *vd);
+ /*
+ * Setup vd for use with VSL functions.
+ */
+
+int VSL_Open(struct VSM_data *vd, int diag);
+ /*
+ * Attempt to open and map the shared memory file.
+ * If diag is non-zero, diagnostics are emitted.
+ * Returns:
+ * 0 on success
+ * != 0 on failure
+ */
+
+
typedef int vsl_handler(void *priv, enum vsl_tag tag, unsigned fd,
unsigned len, unsigned spec, const char *ptr);
#define VSL_S_CLIENT (1 << 0)
@@ -199,10 +214,9 @@
vsl_handler VSL_H_Print;
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);
+void VSL_NonBlocking(const struct VSM_data *vd, int nb);
+int VSL_Dispatch(const struct VSM_data *vd, vsl_handler *func, void *priv);
+int VSL_NextLog(const struct VSM_data *lh, uint32_t **pp);
int VSL_Log_Arg(struct VSM_data *vd, int arg, const char *opt);
extern const char *VSL_tags[256];
Modified: trunk/varnish-cache/lib/libvarnishapi/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-08 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/lib/libvarnishapi/Makefile.am 2010-06-09 09:34:55 UTC (rev 4940)
@@ -7,7 +7,8 @@
libvarnishapi_la_LDFLAGS = -version-info 1:0:0
libvarnishapi_la_SOURCES = \
- vslapi.h \
+ vsm_api.h \
+ vsl_api.h \
\
../libvarnish/assert.c \
../libvarnish/argv.c \
Modified: trunk/varnish-cache/lib/libvarnishapi/vsc.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-08 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/lib/libvarnishapi/vsc.c 2010-06-09 09:34:55 UTC (rev 4940)
@@ -40,13 +40,12 @@
#include "vas.h"
#include "vsm.h"
#include "vsc.h"
-#include "vre.h"
#include "argv.h"
#include "vqueue.h"
#include "miniobj.h"
#include "varnishapi.h"
-#include "vslapi.h"
+#include "vsm_api.h"
struct vsc_sf {
unsigned magic;
@@ -80,18 +79,23 @@
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
AZ(vd->vsc);
- // XXX: AZ(vd->vsm);
+ AZ(vd->vsl);
ALLOC_OBJ(vd->vsc, VSC_MAGIC);
AN(vd->vsc);
VTAILQ_INIT(&vd->vsc->sf_list);
}
+/*--------------------------------------------------------------------*/
+
void
-vsc_delete(const struct VSM_data *vd)
+vsc_delete(struct VSM_data *vd)
{
struct vsc_sf *sf;
- struct vsc *vsc = vd->vsc;
+ struct vsc *vsc;
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ vsc = vd->vsc;
+ vd->vsc = NULL;
CHECK_OBJ_NOTNULL(vsc, VSC_MAGIC);
while(!VTAILQ_EMPTY(&vsc->sf_list)) {
sf = VTAILQ_FIRST(&vsc->sf_list);
@@ -99,7 +103,7 @@
free(sf->class);
free(sf->ident);
free(sf->name);
- free(sf);
+ FREE_OBJ(sf);
}
}
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-08 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl.c 2010-06-09 09:34:55 UTC (rev 4940)
@@ -45,15 +45,13 @@
#include "vsl.h"
#include "vre.h"
#include "vbm.h"
-#include "vqueue.h"
#include "miniobj.h"
#include "varnishapi.h"
-#include "vslapi.h"
+#include "vsm_api.h"
+#include "vsl_api.h"
#include "vmb.h"
-static int vsl_nextlog(struct VSM_data *vd, uint32_t **pp);
-
/*--------------------------------------------------------------------*/
const char *VSL_tags[256] = {
@@ -65,72 +63,132 @@
/*--------------------------------------------------------------------*/
void
+VSL_Setup(struct VSM_data *vd)
+{
+ struct vsl *vsl;
+
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ AZ(vd->vsc);
+ AZ(vd->vsl);
+ ALLOC_OBJ(vsl, VSL_MAGIC);
+ AN(vsl);
+
+ vd->vsl = vsl;
+
+ vsl->regflags = 0;
+
+ /* XXX: Allocate only if log access */
+ vsl->vbm_client = vbit_init(4096);
+ vsl->vbm_backend = vbit_init(4096);
+ vsl->vbm_supress = vbit_init(256);
+ vsl->vbm_select = vbit_init(256);
+
+ vsl->r_fd = -1;
+ /* XXX: Allocate only if -r option given ? */
+ vsl->rbuflen = 256; /* XXX ?? */
+ vsl->rbuf = malloc(vsl->rbuflen * 4L);
+ assert(vsl->rbuf != NULL);
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+vsl_delete(struct VSM_data *vd)
+{
+ struct vsl *vsl;
+
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ vsl = vd->vsl;
+ vd->vsl = NULL;
+ CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
+
+ vbit_destroy(vsl->vbm_client);
+ vbit_destroy(vsl->vbm_backend);
+ vbit_destroy(vsl->vbm_supress);
+ vbit_destroy(vsl->vbm_select);
+ free(vsl->rbuf);
+
+ FREE_OBJ(vsl);
+}
+
+/*--------------------------------------------------------------------*/
+
+void
VSL_Select(const struct VSM_data *vd, unsigned tag)
{
+ struct vsl *vsl;
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
- vbit_set(vd->vbm_select, tag);
+ vsl = vd->vsl;
+ CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
+ vbit_set(vsl->vbm_select, tag);
}
/*--------------------------------------------------------------------*/
void
-VSL_NonBlocking(struct VSM_data *vd, int nb)
+VSL_NonBlocking(const struct VSM_data *vd, int nb)
{
+ struct vsl *vsl;
+
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ vsl = vd->vsl;
+ CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
if (nb)
- vd->flags |= F_NON_BLOCKING;
+ vsl->flags |= F_NON_BLOCKING;
else
- vd->flags &= ~F_NON_BLOCKING;
+ vsl->flags &= ~F_NON_BLOCKING;
}
/*--------------------------------------------------------------------*/
static int
-vsl_nextlog(struct VSM_data *vd, uint32_t **pp)
+vsl_nextlog(struct vsl *vsl, uint32_t **pp)
{
unsigned w, l;
uint32_t t;
int i;
- CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
- if (vd->r_fd != -1) {
- assert(vd->rbuflen >= 8);
- i = read(vd->r_fd, vd->rbuf, 8);
+ CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
+
+ if (vsl->r_fd != -1) {
+ assert(vsl->rbuflen >= 8);
+ i = read(vsl->r_fd, vsl->rbuf, 8);
if (i != 8)
return (-1);
- l = 2 + VSL_WORDS(VSL_LEN(vd->rbuf));
- if (vd->rbuflen < l) {
+ l = 2 + VSL_WORDS(VSL_LEN(vsl->rbuf));
+ if (vsl->rbuflen < l) {
l += 256;
- vd->rbuf = realloc(vd->rbuf, l * 4);
- assert(vd->rbuf != NULL);
- vd->rbuflen = l;
+ vsl->rbuf = realloc(vsl->rbuf, l * 4L);
+ assert(vsl->rbuf != NULL);
+ vsl->rbuflen = l;
}
- i = read(vd->r_fd, vd->rbuf + 2, l * 4 - 8);
+ i = read(vsl->r_fd, vsl->rbuf + 2, l * 4L - 8L);
if (i != l)
return (-1);
- *pp = vd->rbuf;
+ *pp = vsl->rbuf;
return (1);
}
for (w = 0; w < TIMEOUT_USEC;) {
- t = *vd->log_ptr;
+ t = *vsl->log_ptr;
if (t == VSL_WRAPMARKER ||
- (t == VSL_ENDMARKER && vd->last_seq != vd->log_start[0])) {
- vd->log_ptr = vd->log_start + 1;
- vd->last_seq = vd->log_start[0];
+ (t == VSL_ENDMARKER && vsl->last_seq != vsl->log_start[0])) {
+ vsl->log_ptr = vsl->log_start + 1;
+ vsl->last_seq = vsl->log_start[0];
VRMB();
continue;
}
if (t == VSL_ENDMARKER) {
- if (vd->flags & F_NON_BLOCKING)
+ if (vsl->flags & F_NON_BLOCKING)
return (-1);
w += SLEEP_USEC;
AZ(usleep(SLEEP_USEC));
continue;
}
- *pp = (void*)(uintptr_t)vd->log_ptr; /* Loose volatile */
- vd->log_ptr = VSL_NEXT(vd->log_ptr);
+ *pp = (void*)(uintptr_t)vsl->log_ptr; /* Loose volatile */
+ vsl->log_ptr = VSL_NEXT(vsl->log_ptr);
return (1);
}
*pp = NULL;
@@ -138,16 +196,20 @@
}
int
-VSL_NextLog(struct VSM_data *vd, uint32_t **pp)
+VSL_NextLog(const struct VSM_data *vd, uint32_t **pp)
{
+ struct vsl *vsl;
uint32_t *p;
unsigned char t;
unsigned u;
int i;
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ vsl = vd->vsl;
+ CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
+
while (1) {
- i = vsl_nextlog(vd, &p);
+ i = vsl_nextlog(vsl, &p);
if (i != 1)
return (i);
u = VSL_ID(p);
@@ -155,43 +217,43 @@
switch(t) {
case SLT_SessionOpen:
case SLT_ReqStart:
- vbit_set(vd->vbm_client, u);
- vbit_clr(vd->vbm_backend, u);
+ vbit_set(vsl->vbm_client, u);
+ vbit_clr(vsl->vbm_backend, u);
break;
case SLT_BackendOpen:
case SLT_BackendXID:
- vbit_clr(vd->vbm_client, u);
- vbit_set(vd->vbm_backend, u);
+ vbit_clr(vsl->vbm_client, u);
+ vbit_set(vsl->vbm_backend, u);
break;
default:
break;
}
- if (vd->skip) {
- --vd->skip;
+ if (vsl->skip) {
+ --vsl->skip;
continue;
- } else if (vd->keep) {
- if (--vd->keep == 0)
+ } else if (vsl->keep) {
+ if (--vsl->keep == 0)
return (-1);
}
- if (vbit_test(vd->vbm_select, t)) {
+ if (vbit_test(vsl->vbm_select, t)) {
*pp = p;
return (1);
}
- if (vbit_test(vd->vbm_supress, t))
+ if (vbit_test(vsl->vbm_supress, t))
continue;
- if (vd->b_opt && !vbit_test(vd->vbm_backend, u))
+ if (vsl->b_opt && !vbit_test(vsl->vbm_backend, u))
continue;
- if (vd->c_opt && !vbit_test(vd->vbm_client, u))
+ if (vsl->c_opt && !vbit_test(vsl->vbm_client, u))
continue;
- if (vd->regincl != NULL) {
- i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p),
+ if (vsl->regincl != NULL) {
+ i = VRE_exec(vsl->regincl, VSL_DATA(p), VSL_LEN(p),
0, 0, NULL, 0);
if (i == VRE_ERROR_NOMATCH)
continue;
}
- if (vd->regexcl != NULL) {
- i = VRE_exec(vd->regincl, VSL_DATA(p), VSL_LEN(p),
+ if (vsl->regexcl != NULL) {
+ i = VRE_exec(vsl->regincl, VSL_DATA(p), VSL_LEN(p),
0, 0, NULL, 0);
if (i != VRE_ERROR_NOMATCH)
continue;
@@ -204,13 +266,17 @@
/*--------------------------------------------------------------------*/
int
-VSL_Dispatch(struct VSM_data *vd, vsl_handler *func, void *priv)
+VSL_Dispatch(const struct VSM_data *vd, vsl_handler *func, void *priv)
{
+ struct vsl *vsl;
int i;
unsigned u, l, s;
uint32_t *p;
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ vsl = vd->vsl;
+ CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
+
while (1) {
i = VSL_NextLog(vd, &p);
if (i != 1)
@@ -218,9 +284,9 @@
u = VSL_ID(p);
l = VSL_LEN(p);
s = 0;
- if (vbit_test(vd->vbm_backend, u))
+ if (vbit_test(vsl->vbm_backend, u))
s |= VSL_S_BACKEND;
- if (vbit_test(vd->vbm_client, u))
+ if (vbit_test(vsl->vbm_client, u))
s |= VSL_S_CLIENT;
if (func(priv, VSL_TAG(p), u, l, s, VSL_DATA(p)))
return (1);
@@ -260,23 +326,32 @@
/*--------------------------------------------------------------------*/
int
-VSM_OpenLog(struct VSM_data *vd)
+VSL_Open(struct VSM_data *vd, int diag)
{
+ struct vsl *vsl;
struct vsm_chunk *sha;
+ int i;
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ vsl = vd->vsl;
+ CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
+
+ i = VSM_Open(vd, diag);
+ if (i)
+ return (i);
+
sha = vsm_find_alloc(vd, VSL_CLASS, "", "");
assert(sha != NULL);
- vd->log_start = VSM_PTR(sha);
- vd->log_end = VSM_NEXT(sha);
- vd->log_ptr = vd->log_start + 1;
+ vsl->log_start = VSM_PTR(sha);
+ vsl->log_end = VSM_NEXT(sha);
+ vsl->log_ptr = vsl->log_start + 1;
- vd->last_seq = vd->log_start[0];
+ vsl->last_seq = vsl->log_start[0];
VRMB();
- if (!vd->d_opt && vd->r_fd == -1) {
- while (*vd->log_ptr != VSL_ENDMARKER)
- vd->log_ptr = VSL_NEXT(vd->log_ptr);
+ if (!vsl->d_opt && vsl->r_fd == -1) {
+ while (*vsl->log_ptr != VSL_ENDMARKER)
+ vsl->log_ptr = VSL_NEXT(vsl->log_ptr);
}
return (0);
}
Modified: trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-08 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/lib/libvarnishapi/vsl_arg.c 2010-06-09 09:34:55 UTC (rev 4940)
@@ -44,28 +44,27 @@
#include <unistd.h>
#include "vas.h"
-#include "argv.h"
#include "vin.h"
#include "vre.h"
#include "vbm.h"
-#include "vqueue.h"
#include "miniobj.h"
#include "varnishapi.h"
-#include "vslapi.h"
+#include "vsm_api.h"
+#include "vsl_api.h"
/*--------------------------------------------------------------------*/
static int
-vsl_r_arg(struct VSM_data *vd, const char *opt)
+vsl_r_arg(const struct VSM_data *vd, const char *opt)
{
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
if (!strcmp(opt, "-"))
- vd->r_fd = STDIN_FILENO;
+ vd->vsl->r_fd = STDIN_FILENO;
else
- vd->r_fd = open(opt, O_RDONLY);
- if (vd->r_fd < 0) {
+ vd->vsl->r_fd = open(opt, O_RDONLY);
+ if (vd->vsl->r_fd < 0) {
perror(opt);
return (-1);
}
@@ -75,7 +74,7 @@
/*--------------------------------------------------------------------*/
static int
-vsl_IX_arg(struct VSM_data *vd, const char *opt, int arg)
+vsl_IX_arg(const struct VSM_data *vd, const char *opt, int arg)
{
vre_t **rp;
const char *error;
@@ -83,14 +82,14 @@
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
if (arg == 'I')
- rp = &vd->regincl;
+ rp = &vd->vsl->regincl;
else
- rp = &vd->regexcl;
+ rp = &vd->vsl->regexcl;
if (*rp != NULL) {
fprintf(stderr, "Option %c can only be given once", arg);
return (-1);
}
- *rp = VRE_compile(opt, vd->regflags, &error, &erroroffset);
+ *rp = VRE_compile(opt, vd->vsl->regflags, &error, &erroroffset);
if (*rp == NULL) {
fprintf(stderr, "Illegal regex: %s\n", error);
return (-1);
@@ -101,17 +100,17 @@
/*--------------------------------------------------------------------*/
static int
-vsl_ix_arg(struct VSM_data *vd, const char *opt, int arg)
+vsl_ix_arg(const struct VSM_data *vd, const char *opt, int arg)
{
int i, j, l;
const char *b, *e, *p, *q;
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
/* If first option is 'i', set all bits for supression */
- if (arg == 'i' && !(vd->flags & F_SEEN_IX))
+ if (arg == 'i' && !(vd->vsl->flags & F_SEEN_IX))
for (i = 0; i < 256; i++)
- vbit_set(vd->vbm_supress, i);
- vd->flags |= F_SEEN_IX;
+ vbit_set(vd->vsl->vbm_supress, i);
+ vd->vsl->flags |= F_SEEN_IX;
for (b = opt; *b; b = e) {
while (isspace(*b))
@@ -136,9 +135,9 @@
continue;
if (arg == 'x')
- vbit_set(vd->vbm_supress, i);
+ vbit_set(vd->vsl->vbm_supress, i);
else
- vbit_clr(vd->vbm_supress, i);
+ vbit_clr(vd->vsl->vbm_supress, i);
break;
}
if (i == 256) {
@@ -153,7 +152,7 @@
/*--------------------------------------------------------------------*/
static int
-vsl_s_arg(struct VSM_data *vd, const char *opt)
+vsl_s_arg(const struct VSM_data *vd, const char *opt)
{
char *end;
@@ -162,7 +161,7 @@
fprintf(stderr, "number required for -s\n");
return (-1);
}
- vd->skip = strtoul(opt, &end, 10);
+ vd->vsl->skip = strtoul(opt, &end, 10);
if (*end != '\0') {
fprintf(stderr, "invalid number for -s\n");
return (-1);
@@ -173,7 +172,7 @@
/*--------------------------------------------------------------------*/
static int
-vsl_k_arg(struct VSM_data *vd, const char *opt)
+vsl_k_arg(const struct VSM_data *vd, const char *opt)
{
char *end;
@@ -182,7 +181,7 @@
fprintf(stderr, "number required for -k\n");
return (-1);
}
- vd->keep = strtoul(opt, &end, 10);
+ vd->vsl->keep = strtoul(opt, &end, 10);
if (*end != '\0') {
fprintf(stderr, "invalid number for -k\n");
return (-1);
@@ -198,11 +197,11 @@
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);
+ case 'b': vd->vsl->b_opt = !vd->vsl->b_opt; return (1);
+ case 'c': vd->vsl->c_opt = !vd->vsl->c_opt; return (1);
case 'd':
- vd->d_opt = !vd->d_opt;
- vd->flags |= F_NON_BLOCKING;
+ vd->vsl->d_opt = !vd->vsl->d_opt;
+ vd->vsl->flags |= F_NON_BLOCKING;
return (1);
case 'i': case 'x': return (vsl_ix_arg(vd, opt, arg));
case 'k': return (vsl_k_arg(vd, opt));
@@ -210,15 +209,15 @@
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));
- case 'C': vd->regflags = VRE_CASELESS; return (1);
+ case 'C': vd->vsl->regflags = VRE_CASELESS; return (1);
case 'L':
- vd->L_opt = strtoul(opt, NULL, 0);
- if (vd->L_opt < 1024 || vd->L_opt > 65000) {
+ vd->vsl->L_opt = strtoul(opt, NULL, 0);
+ if (vd->vsl->L_opt < 1024 || vd->vsl->L_opt > 65000) {
fprintf(stderr, "%s\n", VIN_L_MSG);
exit (1);
}
free(vd->n_opt);
- vd->n_opt = vin_L_arg(vd->L_opt);
+ vd->n_opt = vin_L_arg(vd->vsl->L_opt);
assert(vd->n_opt != NULL);
return (1);
default:
Deleted: trunk/varnish-cache/lib/libvarnishapi/vslapi.h
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-08 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/lib/libvarnishapi/vslapi.h 2010-06-09 09:34:55 UTC (rev 4940)
@@ -1,111 +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.
- *
- * $Id$
- */
-
-/* Parameters */
-#define SLEEP_USEC (50*1000)
-#define TIMEOUT_USEC (5*1000*1000)
-
-struct vsc;
-
-struct VSM_data {
- unsigned magic;
-#define VSM_MAGIC 0x6e3bd69b
-
- vsm_diag_f *diag;
- void *priv;
-
- char *n_opt;
- char *fname;
-
-
- struct stat fstat;
-
- int vsl_fd;
- struct vsm_head *vsl_lh;
- void *vsl_end;
- unsigned alloc_seq;
-
- /* Stuff relating the stats fields start here */
-
- struct vsc *vsc;
-
- /* Stuff relating the log records below here */
-
- volatile uint32_t *log_start;
- volatile uint32_t *log_end;
- volatile uint32_t *log_ptr;
-
- volatile uint32_t last_seq;
-
- /* for -r option */
- int r_fd;
- unsigned rbuflen;
- uint32_t *rbuf;
-
- unsigned L_opt;
- int b_opt;
- int c_opt;
- int d_opt;
-
- unsigned flags;
-#define F_SEEN_IX (1 << 0)
-#define F_NON_BLOCKING (1 << 1)
-
- /*
- * These two bitmaps mark fd's as belonging to client or backend
- * transactions respectively.
- */
- struct vbitmap *vbm_client;
- struct vbitmap *vbm_backend;
-
- /*
- * Bit map of programatically selected tags, that cannot be suppressed.
- * This way programs can make sure they will see certain tags, even
- * if the user tries to supress them with -x/-X
- */
- struct vbitmap *vbm_select; /* index: tag */
-
- /* Bit map of tags selected/supressed with -[iIxX] options */
- struct vbitmap *vbm_supress; /* index: tag */
-
- int regflags;
- vre_t *regincl;
- vre_t *regexcl;
-
- unsigned long skip;
- unsigned long keep;
-};
-
-struct vsm_chunk *vsm_find_alloc(const struct VSM_data *vd, const char *class,
- const char *type, const char *ident);
-
-void vsc_delete(const struct VSM_data *vd);
-
Modified: trunk/varnish-cache/lib/libvarnishapi/vsm.c
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-08 12:07:47 UTC (rev 4939)
+++ trunk/varnish-cache/lib/libvarnishapi/vsm.c 2010-06-09 09:34:55 UTC (rev 4940)
@@ -46,12 +46,11 @@
#include "vas.h"
#include "vin.h"
#include "vsm.h"
-#include "vre.h"
#include "vbm.h"
#include "miniobj.h"
#include "varnishapi.h"
-#include "vslapi.h"
+#include "vsm_api.h"
#ifndef MAP_HASSEMAPHORE
#define MAP_HASSEMAPHORE 0 /* XXX Linux */
@@ -72,20 +71,6 @@
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 * 4L);
- assert(vd->rbuf != NULL);
-
CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
return (vd);
}
@@ -138,16 +123,16 @@
{
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);
- vsc_delete(vd);
+ if (vd->vsc != NULL)
+ vsc_delete(vd);
+ if (vd->vsl != NULL)
+ vsl_delete(vd);
free(vd);
}
Copied: trunk/varnish-cache/lib/libvarnishapi/vsm_api.h (from rev 4939, trunk/varnish-cache/lib/libvarnishapi/vslapi.h)
===================================================================
--- trunk/varnish-cache/lib/libvarnishapi/vsm_api.h (rev 0)
+++ trunk/varnish-cache/lib/libvarnishapi/vsm_api.h 2010-06-09 09:34:55 UTC (rev 4940)
@@ -0,0 +1,66 @@
+/*-
+ * 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.
+ *
+ * $Id$
+ */
+
+/* Parameters */
+#define SLEEP_USEC (50*1000)
+#define TIMEOUT_USEC (5*1000*1000)
+
+struct vsc;
+
+struct VSM_data {
+ unsigned magic;
+#define VSM_MAGIC 0x6e3bd69b
+
+ vsm_diag_f *diag;
+ void *priv;
+
+ char *n_opt;
+ char *fname;
+
+
+ struct stat fstat;
+
+ int vsl_fd;
+ struct vsm_head *vsl_lh;
+ void *vsl_end;
+ unsigned alloc_seq;
+
+ /* Stuff relating the stats fields start here */
+
+ struct vsc *vsc;
+ struct vsl *vsl;
+};
+
+struct vsm_chunk *vsm_find_alloc(const struct VSM_data *vd, const char *class,
+ const char *type, const char *ident);
+
+void vsc_delete(struct VSM_data *vd);
+void vsl_delete(struct VSM_data *vd);
More information about the varnish-commit
mailing list