r403 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Mon Jul 10 12:56:12 CEST 2006
Author: phk
Date: 2006-07-10 12:56:12 +0200 (Mon, 10 Jul 2006)
New Revision: 403
Added:
trunk/varnish-cache/bin/varnishd/common.h
trunk/varnish-cache/bin/varnishd/shmlog.c
Removed:
trunk/varnish-cache/bin/varnishd/cache_shmlog.c
trunk/varnish-cache/bin/varnishd/cache_shmlog.h
Modified:
trunk/varnish-cache/bin/varnishd/Makefile.am
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/mgt.h
Log:
Be more consistent.
cache_shmlog.c contains stuff for both cache and mgt, so remove the
cache_ prefix.
Rename cache_shmlog.h to common.h and put joint stuff there.
Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am 2006-07-10 10:31:49 UTC (rev 402)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am 2006-07-10 10:56:12 UTC (rev 403)
@@ -26,7 +26,6 @@
cache_pass.c \
cache_pipe.c \
cache_response.c \
- cache_shmlog.c \
cache_vcl.c \
cache_vrt.c \
cli_event.c \
@@ -34,6 +33,7 @@
hash_classic.c \
mgt_child.c \
rfc2616.c \
+ shmlog.c \
storage_file.c \
storage_malloc.c \
tcp.c \
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-07-10 10:31:49 UTC (rev 402)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-07-10 10:56:12 UTC (rev 403)
@@ -9,6 +9,7 @@
#include <event.h>
#include "vcl_returns.h"
+#include "common.h"
#define VCA_ADDRBUFSIZE 64 /* Sizeof ascii network address */
@@ -241,7 +242,6 @@
void DealWithSession(void *arg);
/* cache_shmlog.c */
-#include "cache_shmlog.h"
void VSL_Init(void);
#ifdef SHMLOGHEAD_MAGIC
Deleted: trunk/varnish-cache/bin/varnishd/cache_shmlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2006-07-10 10:31:49 UTC (rev 402)
+++ trunk/varnish-cache/bin/varnishd/cache_shmlog.c 2006-07-10 10:56:12 UTC (rev 403)
@@ -1,174 +0,0 @@
-/*
- * $Id$
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdarg.h>
-#include <sys/mman.h>
-
-#include "libvarnish.h"
-#include "shmlog.h"
-#include "cache.h"
-
-#include "heritage.h"
-
-#ifndef MAP_HASSEMAPHORE
-#define MAP_HASSEMAPHORE 0 /* XXX Linux */
-#endif
-
-#ifndef MAP_NOSYNC
-#define MAP_NOSYNC 0 /* XXX Linux */
-#endif
-
-struct varnish_stats *VSL_stats;
-static struct shmloghead *loghead;
-static unsigned char *logstart;
-static pthread_mutex_t vsl_mutex;
-
-/*
- * This variant copies a byte-range directly to the log, without
- * taking the detour over sprintf()
- */
-
-static void
-vsl_wrap(void)
-{
-
- *logstart = SLT_ENDMARKER;
- logstart[loghead->ptr] = SLT_WRAPMARKER;
- loghead->ptr = 0;
-}
-
-void
-VSLR(enum shmlogtag tag, unsigned id, const char *b, const char *e)
-{
- unsigned char *p;
- unsigned l;
-
- assert(b != NULL);
- if (e == NULL)
- e = strchr(b, '\0');
- assert(e != NULL);
-
- /* Truncate */
- l = e - b;
- if (l > 255) {
- l = 255;
- e = b + l;
- }
-
- AZ(pthread_mutex_lock(&vsl_mutex));
- assert(loghead->ptr < loghead->size);
-
- /* Wrap if necessary */
- if (loghead->ptr + 4 + l + 1 > loghead->size)
- vsl_wrap();
- p = logstart + loghead->ptr;
- p[1] = l;
- p[2] = id >> 8;
- p[3] = id & 0xff;
- memcpy(p + 4, b, l);
- p[4 + l] = SLT_ENDMARKER;
- p[0] = tag;
-
- loghead->ptr += 4 + l;
- assert(loghead->ptr < loghead->size);
- AZ(pthread_mutex_unlock(&vsl_mutex));
-}
-
-
-void
-VSL(enum shmlogtag tag, unsigned id, const char *fmt, ...)
-{
- va_list ap;
- unsigned char *p;
- unsigned n;
-
- va_start(ap, fmt);
-
- AZ(pthread_mutex_lock(&vsl_mutex));
- assert(loghead->ptr < loghead->size);
-
- /* Wrap if we cannot fit a full size record */
- if (loghead->ptr + 4 + 255 + 1 > loghead->size)
- vsl_wrap();
-
- p = logstart + loghead->ptr;
- n = 0;
- if (fmt != NULL) {
- n = vsnprintf((char *)(p + 4), 256, fmt, ap);
- if (n > 255)
- n = 255; /* we truncate long fields */
- }
- p[1] = n;
- p[2] = id >> 8;
- p[3] = id & 0xff;
- p[4 + n] = SLT_ENDMARKER;
- p[0] = tag;
-
- loghead->ptr += 4 + n;
- assert(loghead->ptr < loghead->size);
-
- AZ(pthread_mutex_unlock(&vsl_mutex));
-
- va_end(ap);
-}
-
-void
-VSL_Init(void)
-{
-
- loghead = mmap(NULL, heritage.vsl_size,
- PROT_READ|PROT_WRITE,
- MAP_HASSEMAPHORE | MAP_NOSYNC | MAP_SHARED,
- heritage.vsl_fd, 0);
- assert(loghead != MAP_FAILED);
-
- /* XXX check sanity of loghead */
- logstart = (unsigned char *)loghead + loghead->start;
- AZ(pthread_mutex_init(&vsl_mutex, NULL));
- VSL_stats = &loghead->stats;
-}
-
-/*--------------------------------------------------------------------*/
-
-void
-VSL_MgtInit(const char *fn, unsigned size)
-{
- struct shmloghead slh;
- int i;
-
- heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0644);
- if (heritage.vsl_fd < 0) {
- fprintf(stderr, "Could not open %s: %s\n",
- fn, strerror(errno));
- exit (1);
- }
- i = read(heritage.vsl_fd, &slh, sizeof slh);
- if (i != sizeof slh || slh.magic != SHMLOGHEAD_MAGIC) {
- /* XXX more checks */
-
- slh.magic = SHMLOGHEAD_MAGIC;
- slh.size = size;
- slh.ptr = 0;
- slh.start = sizeof slh;
- AZ(lseek(heritage.vsl_fd, 0, SEEK_SET));
- i = write(heritage.vsl_fd, &slh, sizeof slh);
- assert(i == sizeof slh);
- AZ(ftruncate(heritage.vsl_fd, sizeof slh + size));
- }
- heritage.vsl_size = slh.size + slh.start;
-
- /*
- * Call VSL_Init so that we get a VSL_stats pointer in the
- * management process as well.
- */
- VSL_Init();
- memset(VSL_stats, 0, sizeof *VSL_stats);
-}
-
Deleted: trunk/varnish-cache/bin/varnishd/cache_shmlog.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_shmlog.h 2006-07-10 10:31:49 UTC (rev 402)
+++ trunk/varnish-cache/bin/varnishd/cache_shmlog.h 2006-07-10 10:56:12 UTC (rev 403)
@@ -1,6 +0,0 @@
-/*
- * $Id$
- */
-
-void VSL_MgtInit(const char *fn, unsigned size);
-extern struct varnish_stats *VSL_stats;
Copied: trunk/varnish-cache/bin/varnishd/common.h (from rev 396, trunk/varnish-cache/bin/varnishd/cache_shmlog.h)
Modified: trunk/varnish-cache/bin/varnishd/mgt.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt.h 2006-07-10 10:31:49 UTC (rev 402)
+++ trunk/varnish-cache/bin/varnishd/mgt.h 2006-07-10 10:56:12 UTC (rev 403)
@@ -2,6 +2,8 @@
* $Id$
*/
+#include "common.h"
+
extern struct event_base *mgt_eb;
void mgt_child_start(void);
@@ -24,4 +26,3 @@
extern struct hash_slinger hsl_slinger;
extern struct hash_slinger hcl_slinger;
-#include "cache_shmlog.h"
Copied: trunk/varnish-cache/bin/varnishd/shmlog.c (from rev 396, trunk/varnish-cache/bin/varnishd/cache_shmlog.c)
More information about the varnish-commit
mailing list