Commit dc84bde0 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move the stats into an allocated chunk of shmem.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4803 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent ede6a6dd
......@@ -77,7 +77,7 @@ mgt_SHM_Alloc(unsigned size, const char *type, const char *ident)
CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
if (strcmp(sha->type, "Free")) {
sha = (void*)((uintptr_t)sha + sha->len);
sha = SHA_NEXT(sha);
continue;
}
assert(size <= sha->len);
......@@ -288,7 +288,6 @@ mgt_SHM_Init(const char *fn, const char *l_arg)
loghead->master_pid = getpid();
xxxassert(loghead != MAP_FAILED);
(void)mlock((void*)loghead, size);
VSL_stats = &loghead->stats;
/* Initialize pool */
loghead->alloc_seq = 0;
......@@ -300,7 +299,11 @@ mgt_SHM_Init(const char *fn, const char *l_arg)
bprintf(loghead->head.type, "%s", "Free");
MEMORY_BARRIER();
VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, VSL_STAT_TYPE, "");
AN(VSL_stats);
pp = mgt_SHM_Alloc(sizeof *pp, "Params", "");
AN(pp);
*pp = *params;
params = pp;
......
......@@ -55,6 +55,9 @@ struct shmalloc {
char ident[8];
};
#define SHA_NEXT(sha) ((void*)((uintptr_t)(sha) + (sha)->len))
#define SHA_PTR(sha) ((void*)((uintptr_t)((sha) + 1)))
struct shmloghead {
#define SHMLOGHEAD_MAGIC 4185512500U /* From /dev/random */
unsigned magic;
......@@ -77,8 +80,6 @@ struct shmloghead {
/* Current write position relative to the beginning of start */
unsigned ptr;
struct varnish_stats stats;
/* Panic message buffer */
char panicstr[64 * 1024];
......
......@@ -31,6 +31,8 @@
#include <stdint.h>
#define VSL_STAT_TYPE "Stats"
struct varnish_stats {
#define MAC_STAT(n, t, l, f, e) t n;
#include "stat_field.h"
......
......@@ -57,6 +57,7 @@ int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv);
int VSL_NextLog(struct VSL_data *lh, unsigned char **pp);
int VSL_Arg(struct VSL_data *vd, int arg, const char *opt);
void VSL_Close(struct VSL_data *vd);
int VSL_Open(struct VSL_data *vd);
void VSL_Delete(struct VSL_data *vd);
struct varnish_stats *VSL_OpenStats(struct VSL_data *vd);
const char *VSL_Name(struct VSL_data *vd);
......
......@@ -123,8 +123,8 @@ const char *VSL_tags[256] = {
/*--------------------------------------------------------------------*/
static int
vsl_shmem_map(struct VSL_data *vd)
int
VSL_Open(struct VSL_data *vd)
{
int i;
struct shmloghead slh;
......@@ -180,7 +180,6 @@ VSL_New(void)
vd->magic = VSL_MAGIC;
vd->vsl_fd = -1;
/* XXX: Allocate only if log access */
vd->vbm_client = vbit_init(4096);
vd->vbm_backend = vbit_init(4096);
......@@ -233,7 +232,7 @@ VSL_OpenLog(struct VSL_data *vd)
if (vd->r_fd != -1)
return (0);
if (vsl_shmem_map(vd))
if (VSL_Open(vd))
return (-1);
vd->head = vd->vsl_lh;
......@@ -611,13 +610,36 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt)
}
}
/*--------------------------------------------------------------------*/
static
struct shmalloc *
vsl_find_alloc(struct VSL_data *vd, const char *type, const char *ident)
{
struct shmalloc *sha;
assert (vd->vsl_lh != NULL);
for(sha = &vd->vsl_lh->head; ; sha = SHA_NEXT(sha)) {
CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
if (strcmp(sha->type, type))
continue;
if (ident != NULL && strcmp(sha->ident, ident))
continue;
return (sha);
}
return (NULL);
}
struct varnish_stats *
VSL_OpenStats(struct VSL_data *vd)
{
struct shmalloc *sha;
if (vsl_shmem_map(vd))
if (VSL_Open(vd))
return (NULL);
return (&vd->vsl_lh->stats);
sha = vsl_find_alloc(vd, VSL_STAT_TYPE, "");
assert(sha != NULL);
return (SHA_PTR(sha));
}
void
......
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