Commit 1c2b28f8 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make the shmlog-alloc's id threepart: class+type+ident to make things

simpler down the road.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4837 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 8d2a450e
......@@ -247,13 +247,13 @@ main(int argc, char * const *argv)
assert(VSL_Arg(vsd, 'n', n_arg));
if (!VSL_Open(vsd)) {
if (T_arg == NULL) {
p = VSL_Find_Alloc(vsd, "Arg", "-T", NULL);
p = VSL_Find_Alloc(vsd, "Arg", "-T", "", NULL);
if (p != NULL) {
T_arg = strdup(p);
}
}
if (S_arg == NULL) {
p = VSL_Find_Alloc(vsd, "Arg", "-S", NULL);
p = VSL_Find_Alloc(vsd, "Arg", "-S", "", NULL);
if (p != NULL) {
S_arg = strdup(p);
}
......
......@@ -39,7 +39,7 @@ extern pid_t mgt_pid;
void VCA_tweak_waiter(struct cli *cli, const char *arg);
/* mgt_shmem.c */
void *mgt_SHM_Alloc(unsigned size, const char *type, const char *ident);
void *mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident);
extern struct varnish_stats *VSL_stats;
extern struct shmloghead *loghead;
extern uint8_t *vsl_log_start;
......
......@@ -511,7 +511,7 @@ mgt_cli_secret(const char *S_arg)
/* Save in shmem */
i = strlen(S_arg);
p = mgt_SHM_Alloc(i + 1, "Arg", "-S");
p = mgt_SHM_Alloc(i + 1, "Arg", "-S", "");
AN(p);
strcpy(p, S_arg);
......@@ -546,7 +546,7 @@ mgt_cli_telnet(const char *T_arg)
/* Save in shmem */
i = strlen(T_arg);
p = mgt_SHM_Alloc(i + 1, "Arg", "-T");
p = mgt_SHM_Alloc(i + 1, "Arg", "-T", "");
AN(p);
strcpy(p, T_arg);
......
......@@ -64,7 +64,7 @@ static int vsl_fd = -1;
/*--------------------------------------------------------------------*/
void *
mgt_SHM_Alloc(unsigned size, const char *type, const char *ident)
mgt_SHM_Alloc(unsigned size, const char *class, const char *type, const char *ident)
{
struct shmalloc *sha, *sha2;
unsigned seq;
......@@ -99,6 +99,7 @@ mgt_SHM_Alloc(unsigned size, const char *type, const char *ident)
MEMORY_BARRIER();
sha->len = size;
bprintf(sha->class, "%s", class);
bprintf(sha->type, "%s", type);
bprintf(sha->ident, "%s", ident);
MEMORY_BARRIER();
......@@ -300,15 +301,15 @@ 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_TYPE_STAT, "");
VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, VSL_CLASS_STAT, "", "");
AN(VSL_stats);
pp = mgt_SHM_Alloc(sizeof *pp, "Params", "");
pp = mgt_SHM_Alloc(sizeof *pp, "Params", "", "");
AN(pp);
*pp = *params;
params = pp;
vsl_log_start = mgt_SHM_Alloc(s1, VSL_TYPE_LOG, "");
vsl_log_start = mgt_SHM_Alloc(s1, VSL_CLASS_LOG, "", "");
AN(vsl_log_start);
vsl_log_end = vsl_log_start + s1;
vsl_log_nxt = vsl_log_start + 1;
......
......@@ -51,15 +51,16 @@ struct shmalloc {
#define SHMALLOC_MAGIC 0x43907b6e /* From /dev/random */
unsigned magic;
unsigned len;
char class[8];
char type[8];
char ident[8];
char ident[16];
};
#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 */
#define SHMLOGHEAD_MAGIC 4185512501U /* From /dev/random */
unsigned magic;
unsigned hdrsize;
......@@ -78,7 +79,8 @@ struct shmloghead {
struct shmalloc head;
};
#define VSL_TYPE_LOG "Log"
#define VSL_CLASS_LOG "Log"
#define VSL_CLASS_STAT "Stat"
/*
* Record format is as follows:
......
......@@ -62,8 +62,7 @@ void VSL_Delete(struct VSL_data *vd);
struct varnish_stats *VSL_OpenStats(struct VSL_data *vd);
const char *VSL_Name(struct VSL_data *vd);
extern const char *VSL_tags[256];
void *VSL_Find_Alloc(struct VSL_data *vd, const char *type, const char *ident,
unsigned *lenp);
void *VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type,
const char *ident, unsigned *lenp);
#endif
......@@ -165,14 +165,16 @@ VSL_Close(struct VSL_data *vd)
/*--------------------------------------------------------------------*/
static struct shmalloc *
vsl_find_alloc(struct VSL_data *vd, const char *type, const char *ident)
vsl_find_alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident)
{
struct shmalloc *sha;
assert (vd->vsl_lh != NULL);
for(sha = &vd->vsl_lh->head; (void*)sha < vd->vsl_end; sha = SHA_NEXT(sha)) {
CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
if (strcmp(sha->type, type))
if (strcmp(sha->class, class))
continue;
if (type != NULL && strcmp(sha->type, type))
continue;
if (ident != NULL && strcmp(sha->ident, ident))
continue;
......@@ -184,7 +186,7 @@ vsl_find_alloc(struct VSL_data *vd, const char *type, const char *ident)
/*--------------------------------------------------------------------*/
void *
VSL_Find_Alloc(struct VSL_data *vd, const char *type, const char *ident,
VSL_Find_Alloc(struct VSL_data *vd, const char *class, const char *type, const char *ident,
unsigned *lenp)
{
struct shmalloc *sha;
......@@ -192,7 +194,7 @@ VSL_Find_Alloc(struct VSL_data *vd, const char *type, const char *ident,
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (VSL_Open(vd))
return (NULL);
sha = vsl_find_alloc(vd, type, ident);
sha = vsl_find_alloc(vd, class, type, ident);
if (sha == NULL)
return (NULL);
if (lenp != NULL)
......@@ -210,7 +212,7 @@ VSL_OpenStats(struct VSL_data *vd)
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (VSL_Open(vd))
return (NULL);
sha = vsl_find_alloc(vd, VSL_TYPE_STAT, "");
sha = vsl_find_alloc(vd, VSL_CLASS_STAT, "", "");
assert(sha != NULL);
return (SHA_PTR(sha));
}
......@@ -226,7 +228,7 @@ VSL_OpenLog(struct VSL_data *vd)
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (VSL_Open(vd))
return (-1);
sha = vsl_find_alloc(vd, VSL_TYPE_LOG, "");
sha = vsl_find_alloc(vd, VSL_CLASS_LOG, "", "");
assert(sha != NULL);
vd->log_start = SHA_PTR(sha);
......
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