Commit 1e5d8632 authored by Geoff Simmons's avatar Geoff Simmons

first version for which 'make check' succeeds. So far just testing

DATA_Init and strfTIM, still quite a bit of commented-out code and
temporary tricks.
parent af4c3599
......@@ -64,6 +64,7 @@ AC_SUBST(VARNISH_LIBS)
AC_SUBST(VARNISH_PKG_INCLUDE, $ac_varnish_pkgincludedir)
AC_SUBST(VARNISH_SHARE_INCLUDE, "$ac_varnish_pkgdatadir/include")
AC_SUBST(VARNISH_PKG_LIB, $ac_varnish_libdir)
AC_SUBST(VARNISH_LIBVARNISH_LIB, "-L$ac_varnish_libdir/varnish")
# Checks for header files.
AC_HEADER_STDC
......
......@@ -19,11 +19,12 @@ varnishevent_SOURCES = \
writer.c \
config.c \
log.c \
monitor.c
monitor.c \
strfTIM.h \
strfTIM.c
# format.c \
# handler.c \
# strfTIM.h \
# strfTIM.c
# handler.c
varnishevent_LDADD = \
${PTHREAD_LIBS} ${RT_LIBS} ${LIBM} @VARNISH_LIBS@ \
......
......@@ -91,6 +91,8 @@ conf_getUnsignedInt(const char *rval, unsigned *i)
return(0); \
}
/* XXX: need confNonNegative for chunk.size */
#define confUnsigned(name,fld) \
if (strcmp(lval, name) == 0) { \
unsigned int i; \
......@@ -214,6 +216,7 @@ CONF_Init(void)
config.max_vcl_call = DEFAULT_MAX_HEADERS;
config.max_fd = DEFAULT_MAX_FD;
config.max_data = DEFAULT_MAX_DATA;
config.chunk_size = DEFAULT_CHUNK_SIZE;
config.housekeep_interval = DEFAULT_HOUSEKEEP_INTERVAL;
config.ttl = DEFAULT_TTL;
......
/*-
* Copyright (c) 2013 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2013 Otto Gmbh & Co KG
* Copyright (c) 2013-2015 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2013-2015 Otto Gmbh & Co KG
* All rights reserved
* Use only with permission
*
......@@ -48,6 +48,10 @@ static const char *statename[3] = { "EMPTY", "OPEN", "DONE" };
static pthread_mutex_t freelist_lock = PTHREAD_MUTEX_INITIALIZER;
static char *bufptr;
static txhead_t freetxhead;
static linehead_t freerechead;
static chunkhead_t freechunkhead;
static int lines_per_tx = FAKE_DEFAULT_LINES_PER_TX;
#if 0
......@@ -81,58 +85,81 @@ DATA_Clear_Logline(tx_t *tx)
/* XXX: etc. ... */
}
#define INIT_HDR_RECORDS(tag, hdr, max) do { \
if (FMT_Read_Hdr(tag)) { \
hdr = (hdr_t *) malloc(sizeof(hdr_t)); \
if (hdr == NULL) \
return errno; \
hdr->record \
= (record_t *) calloc(max, sizeof(record_t)); \
if (hdr->record == NULL) \
return errno; \
for (int j = 0; j < max; j++) { \
hdr->record[j].magic = RECORD_MAGIC; \
hdr->record[j].data = &bufptr[bufidx++ * config.max_reclen]; \
} \
} \
else { \
hdr = NULL; \
} \
} while(0)
int
DATA_Init(void)
{
int bufidx = 0;
int nrecords;
int bufidx = 0, nrecords, nchunks, chunks_per_rec;
#if 0
lines_per_tx = FMT_Get_nTags();
lines_per_tx = FMT_Get_LinesPerTx();
#endif
nrecords = config.max_data * lines_per_tx;
/* XXX: set up tables of txen, lines & chunks, set/estimate sizes */
nrecords = config.max_data * lines_per_tx;
AN(config.chunk_size);
chunks_per_rec
= (config.max_reclen + config.chunk_size - 1) / config.chunk_size;
nchunks = nrecords * chunks_per_rec;
LOG_Log(LOG_DEBUG, "Allocating space for %d records (%d bytes)", nrecords,
nrecords * config.max_reclen);
bufptr = (char *) calloc(nrecords, config.max_reclen);
LOG_Log(LOG_DEBUG, "Allocating space for %d chunks (%d bytes)",
nchunks, nchunks * config.chunk_size);
bufptr = (char *) calloc(nchunks, config.chunk_size);
if (bufptr == NULL)
return errno;
txn = (tx_t *) calloc(config.max_data, sizeof(tx_t));
if (txn == NULL)
LOG_Log(LOG_DEBUG, "Allocating table for %d chunks (%d bytes)", nchunks,
nchunks * sizeof(chunk_t));
chunks = (chunk_t *) calloc(nchunks, sizeof(chunk_t));
if (chunks == NULL) {
free(bufptr);
return errno;
}
VSTAILQ_INIT(&freechunkhead);
for (int i = 0; i < nchunks; i++) {
chunks[i].magic = CHUNK_MAGIC;
chunks[i].state = DATA_EMPTY;
chunks[i].data = &bufptr[bufidx++ * config.chunk_size];
VSTAILQ_INSERT_TAIL(&freechunkhead, &chunks[i], freelist);
}
assert(bufidx == nchunks);
LOG_Log(LOG_DEBUG, "Allocating table for %d records (%d bytes)", nrecords,
nrecords * sizeof(logline_t));
lines = (logline_t *) calloc(nrecords, sizeof(logline_t));
if (lines == NULL) {
free(bufptr);
free(chunks);
return errno;
}
VSTAILQ_INIT(&freerechead);
for (int i = 0; i < nrecords; i++) {
lines[i].magic = LOGLINE_MAGIC;
lines[i].state = DATA_EMPTY;
lines[i].tag = SLT__Bogus;
lines[i].len = 0;
VSTAILQ_INIT(&lines[i].chunks);
VSTAILQ_INSERT_TAIL(&freechunkhead, &chunks[i], freelist);
}
LOG_Log(LOG_DEBUG, "Allocating table for %d transactions (%d bytes)",
config.max_data, config.max_data * sizeof(tx_t));
txn = (tx_t *) calloc(config.max_data, sizeof(tx_t));
if (txn == NULL) {
free(bufptr);
free(chunks);
free(lines);
return errno;
}
VSTAILQ_INIT(&freetxhead);
for (int i = 0; i < config.max_data; i++) {
/* XXX: init */
txn[i].magic = TX_MAGIC;
DATA_Clear_Logline(&txn[i]);
txn[i].state = TX_EMPTY;
txn[i].vxid = -1;
txn[i].type = VSL_t_unknown;
VSTAILQ_INIT(&txn[i].lines);
VSTAILQ_INSERT_TAIL(&freetxhead, &txn[i], freelist);
}
assert(bufidx == nrecords);
data_open = data_done = data_occ_hi = 0;
global_nfree = config.max_data;
......
......@@ -30,11 +30,27 @@
*/
#include <time.h>
#include <sys/types.h>
#include <errno.h>
#include <math.h>
#include "strfTIM.h"
#include "vas.h"
#include "vsb.h"
#include "libvarnish.h"
/*
* cf. vtim.c/VTIM:timespec in libvarnish
*/
static struct timespec
double2timespec(double t)
{
struct timespec tv;
tv.tv_sec = (time_t)trunc(t);
tv.tv_nsec = (int)(1e9 * (t - tv.tv_sec));
return (tv);
}
size_t
strfTIM(char *s, size_t max, const char *fmt, struct tm *tm, long nsec)
......@@ -77,7 +93,7 @@ strfTIM(char *s, size_t max, const char *fmt, struct tm *tm, long nsec)
size_t \
strfTIM##tz(char *s, size_t max, const char *fmt, double t) \
{ \
struct timespec tim = TIM_timespec(t); \
struct timespec tim = double2timespec(t); \
struct tm tm; \
\
AN(tz##time_r((time_t *) &tim.tv_sec, &tm)); \
......
AM_CPPFLAGS = @VARNISH_CFLAGS@ -I ${ac_varnish_pkgdataincludedir}
TESTS = test_data test_writer test_strfTIM regress.sh ncsa.sh vslarg.sh
TESTS = test_data test_strfTIM # test_writer regress.sh ncsa.sh vslarg.sh
check_PROGRAMS = test_data test_strfTIM test_writer
check_PROGRAMS = test_data test_strfTIM # test_writer
test_data_SOURCES = \
minunit.h \
......@@ -11,10 +11,9 @@ test_data_SOURCES = \
test_data_LDADD = \
../base64.$(OBJEXT) \
../config.$(OBJEXT) \
../format.$(OBJEXT) \
../log.$(OBJEXT) \
../data.$(OBJEXT) \
@VARNISH_LIBS@ -lvarnish
@VARNISH_LIBS@ @VARNISH_LIBVARNISH_LIB@ -lm -lvarnish
test_writer_SOURCES = \
minunit.h \
......@@ -38,4 +37,4 @@ test_strfTIM_SOURCES = \
test_strfTIM_LDADD = \
../strfTIM.$(OBJEXT) \
@VARNISH_LIBS@ -lvarnish
@VARNISH_LIBS@ @VARNISH_LIBVARNISH_LIB@ -lm -lvarnish
......@@ -141,6 +141,8 @@ static int waiting = 0;
static char cli_config_filename[BUFSIZ] = "";
static char tx_type_name[VSL_t__MAX];
int
RDR_Waiting(void)
{
......@@ -231,9 +233,9 @@ static inline tx_t
}
static inline void
take_chunks(linehead_t *lines, unsigned nchunks)
take_chunks(linehead_t *lineh, unsigned nchunks)
{
(void) lines;
(void) lineh;
(void) nchunks;
}
......@@ -291,25 +293,14 @@ event(struct VSL_data *_vsl, struct VSL_transaction * const pt[], void *priv)
tx = take_tx();
CHECK_OBJ_NOTNULL(tx, TX_MAGIC);
assert(tx->state == TX_EMPTY);
assert(!VSTAILQ_EMPTY(tx->lines));
assert(!VSTAILQ_EMPTY(&tx->lines));
switch(t->type) {
case VSL_t_req:
tx->spec = 'c';
break;
case VSL_t_bereq:
tx->spec = 'b';
break;
case VSL_t_raw:
tx->spec = '-';
break;
default:
WRONG("Unexpected transaction type");
}
assert(t->type == VSL_t_req || t->type == VSL_t_bereq
|| t->type == VSL_t_raw);
LOG_Log(LOG_DEBUG, "Tx: [%u %c]", t->vxid, tx->spec);
LOG_Log(LOG_DEBUG, "Tx: [%u %c]", t->vxid, tx_type_name[tx->type]);
logline_t *line = VSTAILQ_FIRST(tx->lines);
logline_t *line = VSTAILQ_FIRST(&tx->lines);
while (1) {
int len;
......@@ -339,16 +330,15 @@ event(struct VSL_data *_vsl, struct VSL_transaction * const pt[], void *priv)
line->len = len;
if (len != 0) {
/* Copy the payload into chunks */
AN(line->chunks);
assert(!VSTAILQ_EMPTY(line->chunks));
assert(VSTAILQ_EMPTY(&line->chunks));
int nchunks = (len + config.chunk_size - 1) / config.chunk_size;
if (nchunks > 1)
/* XXX: increment counter */
take_chunks(tx->lines, nchunks);
take_chunks(&tx->lines, nchunks);
int n = len;
chunk_t *chunk = VSTAILQ_FIRST(line->chunks);
chunk_t *chunk = VSTAILQ_FIRST(&line->chunks);
const char *p = (const char *) VSL_CDATA(t->c->rec.ptr);
while (n > 0) {
CHECK_OBJ_NOTNULL(chunk, CHUNK_MAGIC);
......@@ -695,6 +685,12 @@ main(int argc, char *argv[])
#endif
}
for (int i = 0; i < VSL_t__MAX; i++)
tx_type_name[i] = 'X';
tx_type_name[VSL_t_req] = 'c';
tx_type_name[VSL_t_bereq] = 'b';
tx_type_name[VSL_t_raw] = '-';
/* Main loop */
term = 0;
/* XXX: TERM not noticed until request received */
......
/*-
* Copyright (c) 2013 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2013 Otto Gmbh & Co KG
* Copyright (c) 2013-2015 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2013-2015 Otto Gmbh & Co KG
* All rights reserved.
* Use only with permission
*
......@@ -49,6 +49,7 @@
#define DEFAULT_MAX_RECLEN 255 /* shm_reclen */
#define DEFAULT_MAX_HEADERS 64 /* http_max_hdr */
#define DEFAULT_CHUNK_SIZE 64
#define DEFAULT_MAX_FD 1024
#define DEFAULT_MAX_DATA 4096
#define DEFAULT_PID_FILE "/var/run/varnishevent.pid"
......@@ -90,12 +91,13 @@ typedef struct {
typedef struct chunk_t {
unsigned magic;
#define CHUNK_MAGIC 0x676e0d19
data_state_e state;
char *data;
VSTAILQ_ENTRY(chunk_t) freelist;
VSTAILQ_ENTRY(chunk_t) chunklist;
} chunk_t;
VSTAILQ_HEAD(chunkhead_s, chunk_t);
typedef VSTAILQ_HEAD(chunkhead_s, chunk_t) chunkhead_t;
chunk_t *chunks;
......@@ -104,27 +106,30 @@ typedef struct logline_t {
#define LOGLINE_MAGIC 0xf427a374
enum VSL_tag_e tag;
data_state_e state;
struct chunkhead_s *chunks;
chunkhead_t chunks;
unsigned len;
VSTAILQ_ENTRY(logline_t) freelist;
VSTAILQ_ENTRY(logline_t) linelist;
} logline_t;
logline_t *lines;
typedef VSTAILQ_HEAD(linehead_s, logline_t) linehead_t;
typedef struct tx_t {
unsigned magic;
#define TX_MAGIC 0xff463e42
tx_state_e state;
char spec; /* 'b'/'c'/'-' */
linehead_t *lines;
int32_t vxid;
enum VSL_transaction_e type;
linehead_t lines;
VSTAILQ_ENTRY(tx_t) freelist;
VSTAILQ_ENTRY(tx_t) spscq;
} tx_t;
tx_t *txn;
VSTAILQ_HEAD(txhead_s, tx_t);
typedef VSTAILQ_HEAD(txhead_s, tx_t) txhead_t;
unsigned data_open;
unsigned data_done;
......@@ -135,7 +140,6 @@ enum VSL_tag_e idx2tag[MAX_VSL_TAG];
VSTAILQ_HEAD(freehead_s, logline_t);
struct txhead_s freetxhead;
unsigned global_nfree;
/* Reader waits for this condition when the freelist is exhausted.
......@@ -180,6 +184,8 @@ struct config {
/* varnishd param shm_reclen */
unsigned max_reclen;
unsigned chunk_size;
/* varnishd param http_max_hdr */
unsigned max_headers;
......@@ -187,7 +193,6 @@ struct config {
unsigned max_vcl_call;
unsigned max_fd;
unsigned chunk_size;
unsigned max_data;
unsigned housekeep_interval;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment