Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
356d46a8
Commit
356d46a8
authored
Nov 18, 2011
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First part of VSM overhaul, this compiles and varnishd runs,
but varnishapi and users do not work yet.
parent
b40bdeb0
Changes
10
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
321 additions
and
219 deletions
+321
-219
cache.h
bin/varnishd/cache/cache.h
+1
-1
cache_shmlog.c
bin/varnishd/cache/cache_shmlog.c
+24
-15
common.h
bin/varnishd/common/common.h
+7
-0
common_vsm.c
bin/varnishd/common/common_vsm.c
+235
-142
heritage.h
bin/varnishd/common/heritage.h
+4
-0
mgt.h
bin/varnishd/mgt/mgt.h
+2
-3
mgt_cli.c
bin/varnishd/mgt/mgt_cli.c
+5
-5
mgt_main.c
bin/varnishd/mgt/mgt_main.c
+0
-2
mgt_shmem.c
bin/varnishd/mgt/mgt_shmem.c
+37
-47
vsm_int.h
include/vapi/vsm_int.h
+6
-4
No files found.
bin/varnishd/cache/cache.h
View file @
356d46a8
...
@@ -853,7 +853,7 @@ int SES_Schedule(struct sess *sp);
...
@@ -853,7 +853,7 @@ int SES_Schedule(struct sess *sp);
void
VSL_Init
(
void
);
void
VSL_Init
(
void
);
void
*
VSM_Alloc
(
unsigned
size
,
const
char
*
class
,
const
char
*
type
,
void
*
VSM_Alloc
(
unsigned
size
,
const
char
*
class
,
const
char
*
type
,
const
char
*
ident
);
const
char
*
ident
);
void
VSM_Free
(
const
void
*
ptr
);
void
VSM_Free
(
void
*
ptr
);
#ifdef VSL_ENDMARKER
#ifdef VSL_ENDMARKER
void
VSL
(
enum
VSL_tag_e
tag
,
int
id
,
const
char
*
fmt
,
...);
void
VSL
(
enum
VSL_tag_e
tag
,
int
id
,
const
char
*
fmt
,
...);
void
WSLR
(
struct
worker
*
w
,
enum
VSL_tag_e
tag
,
int
id
,
txt
t
);
void
WSLR
(
struct
worker
*
w
,
enum
VSL_tag_e
tag
,
int
id
,
txt
t
);
...
...
bin/varnishd/cache/cache_shmlog.c
View file @
356d46a8
...
@@ -30,8 +30,10 @@
...
@@ -30,8 +30,10 @@
#include "config.h"
#include "config.h"
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include "cache.h"
#include "cache.h"
#include "common/heritage.h"
#include "cache_backend.h" // For w->vbc
#include "cache_backend.h" // For w->vbc
...
@@ -300,25 +302,32 @@ WSLB(struct worker *w, enum VSL_tag_e tag, const char *fmt, ...)
...
@@ -300,25 +302,32 @@ WSLB(struct worker *w, enum VSL_tag_e tag, const char *fmt, ...)
void
void
VSL_Init
(
void
)
VSL_Init
(
void
)
{
{
struct
VSM_chunk
*
vsc
;
uint32_t
*
vsl_log_start
;
AZ
(
pthread_mutex_init
(
&
vsl_mtx
,
NULL
));
AZ
(
pthread_mutex_init
(
&
vsl_mtx
,
NULL
));
AZ
(
pthread_mutex_init
(
&
vsm_mtx
,
NULL
));
AZ
(
pthread_mutex_init
(
&
vsm_mtx
,
NULL
));
VSM__Clean
();
vsl_log_start
=
VSM_Alloc
(
cache_param
->
vsl_space
,
VSL_CLASS
,
""
,
""
);
AN
(
vsl_log_start
);
vsl_log_start
[
1
]
=
VSL_ENDMARKER
;
VWMB
();
do
*
vsl_log_start
=
random
()
&
0xffff
;
while
(
*
vsl_log_start
==
0
);
VWMB
();
VSM_ITER
(
vsc
)
vsl_start
=
vsl_log_start
;
if
(
!
strcmp
(
vsc
->
class
,
VSL_CLASS
))
vsl_end
=
vsl_start
+
cache_param
->
vsl_space
;
break
;
AN
(
vsc
);
vsl_start
=
VSM_PTR
(
vsc
);
vsl_end
=
VSM_NEXT
(
vsc
);
vsl_ptr
=
vsl_start
+
1
;
vsl_ptr
=
vsl_start
+
1
;
VSC_C_main
=
VSM_Alloc
(
sizeof
*
VSC_C_main
,
VSC_CLASS
,
VSC_TYPE_MAIN
,
""
);
AN
(
VSC_C_main
);
vsl_wrap
();
vsl_wrap
();
VSM_head
->
starttime
=
(
intmax_t
)
VTIM_real
();
//
VSM_head->starttime = (intmax_t)VTIM_real();
memset
(
VSC_C_main
,
0
,
sizeof
*
VSC_C_main
);
memset
(
VSC_C_main
,
0
,
sizeof
*
VSC_C_main
);
VSM_head
->
child_pid
=
getpid
();
//
VSM_head->child_pid = getpid();
}
}
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
...
@@ -327,19 +336,19 @@ void *
...
@@ -327,19 +336,19 @@ void *
VSM_Alloc
(
unsigned
size
,
const
char
*
class
,
const
char
*
type
,
VSM_Alloc
(
unsigned
size
,
const
char
*
class
,
const
char
*
type
,
const
char
*
ident
)
const
char
*
ident
)
{
{
void
*
p
;
vo
latile
vo
id
*
p
;
AZ
(
pthread_mutex_lock
(
&
vsm_mtx
));
AZ
(
pthread_mutex_lock
(
&
vsm_mtx
));
p
=
VSM_
_Alloc
(
size
,
class
,
type
,
ident
);
p
=
VSM_
common_alloc
(
heritage
.
vsm
,
size
,
class
,
type
,
ident
);
AZ
(
pthread_mutex_unlock
(
&
vsm_mtx
));
AZ
(
pthread_mutex_unlock
(
&
vsm_mtx
));
return
(
p
);
return
(
TRUST_ME
(
p
)
);
}
}
void
void
VSM_Free
(
const
void
*
ptr
)
VSM_Free
(
void
*
ptr
)
{
{
AZ
(
pthread_mutex_lock
(
&
vsm_mtx
));
AZ
(
pthread_mutex_lock
(
&
vsm_mtx
));
VSM_
_Free
(
ptr
);
VSM_
common_free
(
heritage
.
vsm
,
ptr
);
AZ
(
pthread_mutex_unlock
(
&
vsm_mtx
));
AZ
(
pthread_mutex_unlock
(
&
vsm_mtx
));
}
}
bin/varnishd/common/common.h
View file @
356d46a8
...
@@ -74,6 +74,13 @@ void mgt_child_inherit(int fd, const char *what);
...
@@ -74,6 +74,13 @@ void mgt_child_inherit(int fd, const char *what);
/* vsm.c */
/* vsm.c */
struct
vsm_sc
;
struct
vsm_sc
*
VSM_common_new
(
void
*
ptr
,
unsigned
len
);
void
*
VSM_common_alloc
(
struct
vsm_sc
*
sc
,
unsigned
size
,
const
char
*
class
,
const
char
*
type
,
const
char
*
ident
);
void
VSM_common_free
(
struct
vsm_sc
*
sc
,
void
*
ptr
);
void
VSM_common_delete
(
struct
vsm_sc
*
sc
);
// extern struct VSM_head *VSM_head;
// extern struct VSM_head *VSM_head;
// extern const struct VSM_chunk *vsm_end;
// extern const struct VSM_chunk *vsm_end;
...
...
bin/varnishd/common/common_vsm.c
View file @
356d46a8
This diff is collapsed.
Click to expand it.
bin/varnishd/common/heritage.h
View file @
356d46a8
...
@@ -29,6 +29,8 @@
...
@@ -29,6 +29,8 @@
* This file contains the heritage passed when mgt forks cache
* This file contains the heritage passed when mgt forks cache
*/
*/
struct
vsm_sc
;
struct
listen_sock
{
struct
listen_sock
{
unsigned
magic
;
unsigned
magic
;
#define LISTEN_SOCK_MAGIC 0x999e4b57
#define LISTEN_SOCK_MAGIC 0x999e4b57
...
@@ -56,6 +58,8 @@ struct heritage {
...
@@ -56,6 +58,8 @@ struct heritage {
/* Hash method */
/* Hash method */
const
struct
hash_slinger
*
hash
;
const
struct
hash_slinger
*
hash
;
struct
vsm_sc
*
vsm
;
char
*
name
;
char
*
name
;
char
identity
[
1024
];
char
identity
[
1024
];
};
};
...
...
bin/varnishd/mgt/mgt.h
View file @
356d46a8
...
@@ -110,9 +110,8 @@ extern unsigned mgt_vcc_err_unref;
...
@@ -110,9 +110,8 @@ extern unsigned mgt_vcc_err_unref;
syslog(pri, fmt, __VA_ARGS__); \
syslog(pri, fmt, __VA_ARGS__); \
} while (0)
} while (0)
#define VSM_Alloc(a, b, c, d) VSM__Alloc(a,b,c,d)
#define VSM_Alloc(a, b, c, d) VSM_common_alloc(heritage.vsm, a,b,c,d)
#define VSM_Free(a) VSM__Free(a)
#define VSM_Free(a) VSM_common_free(heritage.vsm, a)
#define VSM_Clean() VSM__Clean()
#if defined(PTHREAD_CANCELED) || defined(PTHREAD_MUTEX_DEFAULT)
#if defined(PTHREAD_CANCELED) || defined(PTHREAD_MUTEX_DEFAULT)
#error "Keep pthreads out of in manager process"
#error "Keep pthreads out of in manager process"
...
...
bin/varnishd/mgt/mgt_cli.c
View file @
356d46a8
...
@@ -493,15 +493,15 @@ mgt_cli_secret(const char *S_arg)
...
@@ -493,15 +493,15 @@ mgt_cli_secret(const char *S_arg)
{
{
int
i
,
fd
;
int
i
,
fd
;
char
buf
[
BUFSIZ
];
char
buf
[
BUFSIZ
];
char
*
p
;
volatile
char
*
p
;
/* Save in shmem */
/* Save in shmem */
i
=
strlen
(
S_arg
);
i
=
strlen
(
S_arg
);
p
=
VSM_Alloc
(
i
+
1
,
"Arg"
,
"-S"
,
""
);
p
=
VSM_Alloc
(
i
+
1
,
"Arg"
,
"-S"
,
""
);
AN
(
p
);
AN
(
p
);
strcpy
(
p
,
S_arg
);
memcpy
(
TRUST_ME
(
p
),
S_arg
,
i
+
1
);
srandomdev
();
srandomdev
();
/* XXX: why here ??? */
fd
=
open
(
S_arg
,
O_RDONLY
);
fd
=
open
(
S_arg
,
O_RDONLY
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
fprintf
(
stderr
,
"Can not open secret-file
\"
%s
\"\n
"
,
S_arg
);
fprintf
(
stderr
,
"Can not open secret-file
\"
%s
\"\n
"
,
S_arg
);
...
@@ -527,7 +527,7 @@ mgt_cli_telnet(const char *T_arg)
...
@@ -527,7 +527,7 @@ mgt_cli_telnet(const char *T_arg)
struct
vss_addr
**
ta
;
struct
vss_addr
**
ta
;
int
i
,
n
,
sock
,
good
;
int
i
,
n
,
sock
,
good
;
struct
telnet
*
tn
;
struct
telnet
*
tn
;
char
*
p
;
volatile
char
*
p
;
struct
vsb
*
vsb
;
struct
vsb
*
vsb
;
char
abuf
[
VTCP_ADDRBUFSIZE
];
char
abuf
[
VTCP_ADDRBUFSIZE
];
char
pbuf
[
VTCP_PORTBUFSIZE
];
char
pbuf
[
VTCP_PORTBUFSIZE
];
...
@@ -566,7 +566,7 @@ mgt_cli_telnet(const char *T_arg)
...
@@ -566,7 +566,7 @@ mgt_cli_telnet(const char *T_arg)
/* Save in shmem */
/* Save in shmem */
p
=
VSM_Alloc
(
VSB_len
(
vsb
)
+
1
,
"Arg"
,
"-T"
,
""
);
p
=
VSM_Alloc
(
VSB_len
(
vsb
)
+
1
,
"Arg"
,
"-T"
,
""
);
AN
(
p
);
AN
(
p
);
strcpy
(
p
,
VSB_data
(
vsb
)
);
memcpy
(
TRUST_ME
(
p
),
VSB_data
(
vsb
),
VSB_len
(
vsb
)
+
1
);
VSB_delete
(
vsb
);
VSB_delete
(
vsb
);
}
}
...
...
bin/varnishd/mgt/mgt_main.c
View file @
356d46a8
...
@@ -654,8 +654,6 @@ main(int argc, char * const *argv)
...
@@ -654,8 +654,6 @@ main(int argc, char * const *argv)
if
(
T_arg
!=
NULL
)
if
(
T_arg
!=
NULL
)
mgt_cli_telnet
(
T_arg
);
mgt_cli_telnet
(
T_arg
);
AN
(
VSM_Alloc
(
0
,
VSM_CLASS_MARK
,
""
,
""
));
MGT_Run
();
MGT_Run
();
if
(
pfh
!=
NULL
)
if
(
pfh
!=
NULL
)
...
...
bin/varnishd/mgt/mgt_shmem.c
View file @
356d46a8
...
@@ -169,9 +169,8 @@ vsl_n_check(int fd)
...
@@ -169,9 +169,8 @@ vsl_n_check(int fd)
*/
*/
static
void
static
void
vsl_buildnew
(
const
char
*
fn
,
unsigned
size
,
int
fill
)
vsl_buildnew
(
const
char
*
fn
,
ssize_t
size
)
{
{
struct
VSM_head
slh
;
int
i
;
int
i
;
unsigned
u
;
unsigned
u
;
char
buf
[
64
*
1024
];
char
buf
[
64
*
1024
];
...
@@ -189,16 +188,8 @@ vsl_buildnew(const char *fn, unsigned size, int fill)
...
@@ -189,16 +188,8 @@ vsl_buildnew(const char *fn, unsigned size, int fill)
flags
&=
~
O_NONBLOCK
;
flags
&=
~
O_NONBLOCK
;
AZ
(
fcntl
(
vsl_fd
,
F_SETFL
,
flags
));
AZ
(
fcntl
(
vsl_fd
,
F_SETFL
,
flags
));
memset
(
&
slh
,
0
,
sizeof
slh
);
slh
.
magic
=
VSM_HEAD_MAGIC
;
slh
.
hdrsize
=
sizeof
slh
;
slh
.
shm_size
=
size
;
i
=
write
(
vsl_fd
,
&
slh
,
sizeof
slh
);
xxxassert
(
i
==
sizeof
slh
);
if
(
fill
)
{
memset
(
buf
,
0
,
sizeof
buf
);
memset
(
buf
,
0
,
sizeof
buf
);
for
(
u
=
sizeof
slh
;
u
<
size
;
)
{
for
(
u
=
0
;
u
<
size
;
)
{
i
=
write
(
vsl_fd
,
buf
,
sizeof
buf
);
i
=
write
(
vsl_fd
,
buf
,
sizeof
buf
);
if
(
i
<=
0
)
{
if
(
i
<=
0
)
{
fprintf
(
stderr
,
"Write error %s: %s
\n
"
,
fprintf
(
stderr
,
"Write error %s: %s
\n
"
,
...
@@ -207,8 +198,6 @@ vsl_buildnew(const char *fn, unsigned size, int fill)
...
@@ -207,8 +198,6 @@ vsl_buildnew(const char *fn, unsigned size, int fill)
}
}
u
+=
i
;
u
+=
i
;
}
}
}
AZ
(
ftruncate
(
vsl_fd
,
(
off_t
)
size
));
AZ
(
ftruncate
(
vsl_fd
,
(
off_t
)
size
));
}
}
...
@@ -220,8 +209,10 @@ static
...
@@ -220,8 +209,10 @@ static
void
void
mgt_shm_atexit
(
void
)
mgt_shm_atexit
(
void
)
{
{
#if 0
if (getpid() == VSM_head->master_pid)
if (getpid() == VSM_head->master_pid)
VSM_head->master_pid = 0;
VSM_head->master_pid = 0;
#endif
}
}
void
void
...
@@ -229,7 +220,10 @@ mgt_SHM_Init(void)
...
@@ -229,7 +220,10 @@ mgt_SHM_Init(void)
{
{
int
i
,
fill
;
int
i
,
fill
;
uintmax_t
size
,
ps
;
uintmax_t
size
,
ps
;
void
*
p
;
#if 0
uint32_t *vsl_log_start;
uint32_t *vsl_log_start;
#endif
fill
=
1
;
fill
=
1
;
...
@@ -243,55 +237,49 @@ mgt_SHM_Init(void)
...
@@ -243,55 +237,49 @@ mgt_SHM_Init(void)
vsl_n_check
(
i
);
vsl_n_check
(
i
);
(
void
)
close
(
i
);
(
void
)
close
(
i
);
}
}
vsl_buildnew
(
VSM_FILENAME
,
size
,
fill
);
vsl_buildnew
(
VSM_FILENAME
,
size
);
VSM_head
=
(
void
*
)
mmap
(
NULL
,
size
,
p
=
(
void
*
)
mmap
(
NULL
,
size
,
PROT_READ
|
PROT_WRITE
,
PROT_READ
|
PROT_WRITE
,
MAP_HASSEMAPHORE
|
MAP_NOSYNC
|
MAP_SHARED
,
MAP_HASSEMAPHORE
|
MAP_NOSYNC
|
MAP_SHARED
,
vsl_fd
,
0
);
vsl_fd
,
0
);
VSM_head
->
master_pid
=
getpid
();
xxxassert
(
p
!=
MAP_FAILED
);
AZ
(
atexit
(
mgt_shm_atexit
));
xxxassert
(
VSM_head
!=
MAP_FAILED
);
(
void
)
mlock
((
void
*
)
VSM_head
,
size
);
memset
(
&
VSM_head
->
head
,
0
,
sizeof
VSM_head
->
head
);
heritage
.
vsm
=
VSM_common_new
(
p
,
size
);
VSM_head
->
head
.
magic
=
VSM_CHUNK_MAGIC
;
VSM_head
->
head
.
len
=
(
uint8_t
*
)(
VSM_head
)
+
size
-
(
uint8_t
*
)
&
VSM_head
->
head
;
bprintf
(
VSM_head
->
head
.
class
,
"%s"
,
VSM_CLASS_FREE
);
VWMB
();
vsm_end
=
(
void
*
)((
uint8_t
*
)
VSM_head
+
size
);
(
void
)
mlock
(
p
,
size
);
AZ
(
atexit
(
mgt_shm_atexit
));
VSC_C_main
=
VSM_Alloc
(
sizeof
*
VSC_C_main
,
VSC_CLASS
,
VSC_TYPE_MAIN
,
""
);
AN
(
VSC_C_main
);
/* XXX: We need to zero params if we dealloc/clean/wash */
/* XXX: We need to zero params if we dealloc/clean/wash */
cache_param
=
VSM_Alloc
(
sizeof
*
cache_param
,
VSM_CLASS_PARAM
,
""
,
""
);
cache_param
=
VSM_Alloc
(
sizeof
*
cache_param
,
VSM_CLASS_PARAM
,
""
,
""
);
AN
(
cache_param
);
AN
(
cache_param
);
*
cache_param
=
mgt_param
;
*
cache_param
=
mgt_param
;
vsl_log_start
=
VSM_Alloc
(
mgt_param
.
vsl_space
,
VSL_CLASS
,
""
,
""
);
AN
(
vsl_log_start
);
vsl_log_start
[
1
]
=
VSL_ENDMARKER
;
VWMB
();
PAN_panicstr_len
=
64
*
1024
;
PAN_panicstr_len
=
64
*
1024
;
PAN_panicstr
=
VSM_Alloc
(
PAN_panicstr_len
,
PAN_CLASS
,
""
,
""
);
PAN_panicstr
=
VSM_Alloc
(
PAN_panicstr_len
,
PAN_CLASS
,
""
,
""
);
AN
(
PAN_panicstr
);
AN
(
PAN_panicstr
);
/* XXX: shouldn't VSM_Alloc zero ? */
memset
(
PAN_panicstr
,
'\0'
,
PAN_panicstr_len
);
do
#if 0
*
vsl_log_start
=
random
()
&
0xffff
;
while
(
*
vsl_log_start
==
0
);
VSM_head->master_pid = getpid(
);
memset(&VSM_head->head, 0, sizeof VSM_head->head);
VSM_head->head.magic = VSM_CHUNK_MAGIC;
VSM_head->head.len =
(uint8_t*)(VSM_head) + size - (uint8_t*)&VSM_head->head;
bprintf(VSM_head->head.class, "%s", VSM_CLASS_FREE);
VWMB();
VWMB();
vsm_end = (void*)((uint8_t*)VSM_head + size);
VSC_C_main = VSM_Alloc(sizeof *VSC_C_main,
VSC_CLASS, VSC_TYPE_MAIN, "");
AN(VSC_C_main);
do
do
VSM_head->alloc_seq = random();
VSM_head->alloc_seq = random();
while (VSM_head->alloc_seq == 0);
while (VSM_head->alloc_seq == 0);
#endif
}
}
...
@@ -299,5 +287,7 @@ void
...
@@ -299,5 +287,7 @@ void
mgt_SHM_Pid
(
void
)
mgt_SHM_Pid
(
void
)
{
{
#if 0
VSM_head->master_pid = getpid();
VSM_head->master_pid = getpid();
#endif
}
}
include/vapi/vsm_int.h
View file @
356d46a8
...
@@ -41,10 +41,11 @@
...
@@ -41,10 +41,11 @@
*/
*/
struct
VSM_chunk
{
struct
VSM_chunk
{
#define VSM_CHUNK_MAGIC 0x
43907b6e
/* From /dev/random */
#define VSM_CHUNK_MAGIC 0x
a15712e5
/* From /dev/random */
unsigned
magic
;
unsigned
magic
;
unsigned
len
;
unsigned
len
;
/* Incl VSM_chunk */
unsigned
state
;
unsigned
next
;
/* Offset in shmem */
unsigned
state
;
/* XXX remove */
char
class
[
8
];
char
class
[
8
];
char
type
[
8
];
char
type
[
8
];
char
ident
[
64
];
char
ident
[
64
];
...
@@ -54,10 +55,11 @@ struct VSM_chunk {
...
@@ -54,10 +55,11 @@ struct VSM_chunk {
#define VSM_PTR(sha) ((void*)((uintptr_t)((sha) + 1)))
#define VSM_PTR(sha) ((void*)((uintptr_t)((sha) + 1)))
struct
VSM_head
{
struct
VSM_head
{
#define VSM_HEAD_MAGIC
4185512502U
/* From /dev/random */
#define VSM_HEAD_MAGIC
0xe75f7e91
/* From /dev/random */
unsigned
magic
;
unsigned
magic
;
unsigned
hdrsize
;
unsigned
hdrsize
;
unsigned
first
;
/* Offset, first chunk */
uint64_t
starttime
;
uint64_t
starttime
;
int64_t
master_pid
;
int64_t
master_pid
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment