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
0f13e7eb
Commit
0f13e7eb
authored
Nov 15, 2011
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split stevedore.c in a cache and a worker source file.
parent
5cfe903c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
182 additions
and
133 deletions
+182
-133
Makefile.am
bin/varnishd/Makefile.am
+1
-0
cache.h
bin/varnishd/cache/cache.h
+0
-3
common.h
bin/varnishd/common/common.h
+3
-7
mgt.h
bin/varnishd/mgt/mgt.h
+7
-3
stevedore.c
bin/varnishd/storage/stevedore.c
+8
-120
stevedore_mgt.c
bin/varnishd/storage/stevedore_mgt.c
+156
-0
storage.h
bin/varnishd/storage/storage.h
+7
-0
No files found.
bin/varnishd/Makefile.am
View file @
0f13e7eb
...
...
@@ -64,6 +64,7 @@ varnishd_SOURCES = \
mgt/mgt_shmem.c
\
mgt/mgt_vcc.c
\
storage/stevedore.c
\
storage/stevedore_mgt.c
\
storage/stevedore_utils.c
\
storage/storage_file.c
\
storage/storage_malloc.c
\
...
...
bin/varnishd/cache/cache.h
View file @
0f13e7eb
...
...
@@ -114,9 +114,6 @@ struct worker;
#define DIGEST_LEN 32
/* Name of transient storage */
#define TRANSIENT_STORAGE "Transient"
/*--------------------------------------------------------------------
* Pointer aligment magic
*/
...
...
bin/varnishd/common/common.h
View file @
0f13e7eb
...
...
@@ -42,6 +42,9 @@
struct
cli
;
/* Name of transient storage */
#define TRANSIENT_STORAGE "Transient"
extern
pid_t
mgt_pid
;
#define ASSERT_MGT() do { assert(getpid() == mgt_pid);} while (0)
...
...
@@ -68,13 +71,6 @@ void mgt_child_inherit(int fd, const char *what);
exit(2); \
} while (0);
/* A tiny helper for choosing hash/storage modules */
struct
choice
{
const
char
*
name
;
const
void
*
ptr
;
};
const
void
*
pick
(
const
struct
choice
*
cp
,
const
char
*
which
,
const
char
*
kind
);
#define NEEDLESS_RETURN(foo) return (foo)
/* stevedore.c */
...
...
bin/varnishd/mgt/mgt.h
View file @
0f13e7eb
...
...
@@ -57,13 +57,19 @@ void mgt_cli_master(const char *M_arg);
void
mgt_cli_secret
(
const
char
*
S_arg
);
void
mgt_cli_close_all
(
void
);
/* mgt_main.c */
struct
choice
{
const
char
*
name
;
const
void
*
ptr
;
};
const
void
*
pick
(
const
struct
choice
*
cp
,
const
char
*
which
,
const
char
*
kind
);
/* mgt_param.c */
void
MCF_ParamInit
(
struct
cli
*
);
void
MCF_ParamSet
(
struct
cli
*
,
const
char
*
param
,
const
char
*
val
);
void
MCF_DumpRst
(
void
);
extern
struct
params
mgt_param
;
/* mgt_sandbox.c */
void
mgt_sandbox
(
void
);
...
...
@@ -88,7 +94,6 @@ extern const char *mgt_vcl_dir;
extern
const
char
*
mgt_vmod_dir
;
extern
unsigned
mgt_vcc_err_unref
;
#define REPORT0(pri, fmt) \
do { \
fprintf(stderr, fmt "\n"); \
...
...
@@ -105,7 +110,6 @@ extern unsigned mgt_vcc_err_unref;
#define VSM_Free(a) VSM__Free(a)
#define VSM_Clean() VSM__Clean()
#if defined(PTHREAD_CANCELED) || defined(PTHREAD_MUTEX_DEFAULT)
#error "Keep pthreads out of in manager process"
#endif
bin/varnishd/storage/stevedore.c
View file @
0f13e7eb
...
...
@@ -39,18 +39,12 @@
#include "cache/cache.h"
#include "storage/storage.h"
#include "vav.h"
#include "vcli_priv.h"
#include "vrt.h"
#include "vrt_obj.h"
static
VTAILQ_HEAD
(,
stevedore
)
stevedores
=
VTAILQ_HEAD_INITIALIZER
(
stevedores
);
static
const
struct
stevedore
*
volatile
stv_next
;
static
struct
stevedore
*
stv_transient
;
/*---------------------------------------------------------------------
* Default objcore methods
*/
...
...
@@ -130,7 +124,7 @@ stv_pick_stevedore(const struct sess *sp, const char **hint)
AN
(
hint
);
if
(
*
hint
!=
NULL
&&
**
hint
!=
'\0'
)
{
VTAILQ_FOREACH
(
stv
,
&
stevedores
,
list
)
{
VTAILQ_FOREACH
(
stv
,
&
st
v_st
evedores
,
list
)
{
if
(
!
strcmp
(
stv
->
ident
,
*
hint
))
return
(
stv
);
}
...
...
@@ -144,7 +138,7 @@ stv_pick_stevedore(const struct sess *sp, const char **hint)
/* pick a stevedore and bump the head along */
stv
=
VTAILQ_NEXT
(
stv_next
,
list
);
if
(
stv
==
NULL
)
stv
=
VTAILQ_FIRST
(
&
stevedores
);
stv
=
VTAILQ_FIRST
(
&
st
v_st
evedores
);
AN
(
stv
);
AN
(
stv
->
name
);
stv_next
=
stv
;
...
...
@@ -271,7 +265,7 @@ STV_MkObject(struct sess *sp, void *ptr, unsigned ltot,
* implement persistent storage can rely on.
*/
st
atic
st
ruct
object
*
struct
object
*
stv_default_allocobj
(
struct
stevedore
*
stv
,
struct
sess
*
sp
,
unsigned
ltot
,
const
struct
stv_objsecrets
*
soc
)
{
...
...
@@ -402,7 +396,7 @@ STV_open(void)
{
struct
stevedore
*
stv
;
VTAILQ_FOREACH
(
stv
,
&
stevedores
,
list
)
{
VTAILQ_FOREACH
(
stv
,
&
st
v_st
evedores
,
list
)
{
stv
->
lru
=
LRU_Alloc
();
if
(
stv
->
open
!=
NULL
)
stv
->
open
(
stv
);
...
...
@@ -412,6 +406,7 @@ STV_open(void)
stv
->
lru
=
LRU_Alloc
();
stv
->
open
(
stv
);
}
stv_next
=
VTAILQ_FIRST
(
&
stv_stevedores
);
}
void
...
...
@@ -419,7 +414,7 @@ STV_close(void)
{
struct
stevedore
*
stv
;
VTAILQ_FOREACH
(
stv
,
&
stevedores
,
list
)
VTAILQ_FOREACH
(
stv
,
&
st
v_st
evedores
,
list
)
if
(
stv
->
close
!=
NULL
)
stv
->
close
(
stv
);
stv
=
stv_transient
;
...
...
@@ -427,113 +422,6 @@ STV_close(void)
stv
->
close
(
stv
);
}
/*--------------------------------------------------------------------
* Parse a stevedore argument on the form:
* [ name '=' ] strategy [ ',' arg ] *
*/
static
const
struct
choice
STV_choice
[]
=
{
{
"file"
,
&
smf_stevedore
},
{
"malloc"
,
&
sma_stevedore
},
{
"persistent"
,
&
smp_stevedore
},
#ifdef HAVE_LIBUMEM
{
"umem"
,
&
smu_stevedore
},
#endif
{
NULL
,
NULL
}
};
void
STV_Config
(
const
char
*
spec
)
{
char
**
av
;
const
char
*
p
,
*
q
;
struct
stevedore
*
stv
;
const
struct
stevedore
*
stv2
;
int
ac
,
l
;
static
unsigned
seq
=
0
;
ASSERT_MGT
();
p
=
strchr
(
spec
,
'='
);
q
=
strchr
(
spec
,
','
);
if
(
p
!=
NULL
&&
(
q
==
NULL
||
q
>
p
))
{
av
=
VAV_Parse
(
p
+
1
,
NULL
,
ARGV_COMMA
);
}
else
{
av
=
VAV_Parse
(
spec
,
NULL
,
ARGV_COMMA
);
p
=
NULL
;
}
AN
(
av
);
if
(
av
[
0
]
!=
NULL
)
ARGV_ERR
(
"%s
\n
"
,
av
[
0
]);
if
(
av
[
1
]
==
NULL
)
ARGV_ERR
(
"-s argument lacks strategy {malloc, file, ...}
\n
"
);
for
(
ac
=
0
;
av
[
ac
+
2
]
!=
NULL
;
ac
++
)
continue
;
stv2
=
pick
(
STV_choice
,
av
[
1
],
"storage"
);
AN
(
stv2
);
/* Append strategy to ident string */
VSB_printf
(
vident
,
",-s%s"
,
av
[
1
]);
av
+=
2
;
CHECK_OBJ_NOTNULL
(
stv2
,
STEVEDORE_MAGIC
);
ALLOC_OBJ
(
stv
,
STEVEDORE_MAGIC
);
AN
(
stv
);
*
stv
=
*
stv2
;
AN
(
stv
->
name
);
AN
(
stv
->
alloc
);
if
(
stv
->
allocobj
==
NULL
)
stv
->
allocobj
=
stv_default_allocobj
;
if
(
p
==
NULL
)
bprintf
(
stv
->
ident
,
"s%u"
,
seq
++
);
else
{
l
=
p
-
spec
;
if
(
l
>
sizeof
stv
->
ident
-
1
)
l
=
sizeof
stv
->
ident
-
1
;
bprintf
(
stv
->
ident
,
"%.*s"
,
l
,
spec
);
}
VTAILQ_FOREACH
(
stv2
,
&
stevedores
,
list
)
{
if
(
strcmp
(
stv2
->
ident
,
stv
->
ident
))
continue
;
ARGV_ERR
(
"(-s%s=%s) already defined once
\n
"
,
stv
->
ident
,
stv
->
name
);
}
if
(
stv
->
init
!=
NULL
)
stv
->
init
(
stv
,
ac
,
av
);
else
if
(
ac
!=
0
)
ARGV_ERR
(
"(-s%s) too many arguments
\n
"
,
stv
->
name
);
if
(
!
strcmp
(
stv
->
ident
,
TRANSIENT_STORAGE
))
{
stv
->
transient
=
1
;
AZ
(
stv_transient
);
stv_transient
=
stv
;
}
else
{
VTAILQ_INSERT_TAIL
(
&
stevedores
,
stv
,
list
);
if
(
!
stv_next
)
stv_next
=
VTAILQ_FIRST
(
&
stevedores
);
}
}
/*--------------------------------------------------------------------*/
void
STV_Config_Transient
(
void
)
{
ASSERT_MGT
();
if
(
stv_transient
==
NULL
)
STV_Config
(
TRANSIENT_STORAGE
"=malloc"
);
}
/*--------------------------------------------------------------------*/
static
void
...
...
@@ -547,7 +435,7 @@ stv_cli_list(struct cli *cli, const char * const *av, void *priv)
VCLI_Out
(
cli
,
"Storage devices:
\n
"
);
stv
=
stv_transient
;
VCLI_Out
(
cli
,
"
\t
storage.%s = %s
\n
"
,
stv
->
ident
,
stv
->
name
);
VTAILQ_FOREACH
(
stv
,
&
stevedores
,
list
)
VTAILQ_FOREACH
(
stv
,
&
st
v_st
evedores
,
list
)
VCLI_Out
(
cli
,
"
\t
storage.%s = %s
\n
"
,
stv
->
ident
,
stv
->
name
);
}
...
...
@@ -568,7 +456,7 @@ stv_find(const char *nm)
{
const
struct
stevedore
*
stv
;
VTAILQ_FOREACH
(
stv
,
&
stevedores
,
list
)
VTAILQ_FOREACH
(
stv
,
&
st
v_st
evedores
,
list
)
if
(
!
strcmp
(
stv
->
ident
,
nm
))
return
(
stv
);
if
(
!
strcmp
(
TRANSIENT_STORAGE
,
nm
))
...
...
bin/varnishd/storage/stevedore_mgt.c
0 → 100644
View file @
0f13e7eb
/*-
* Copyright (c) 2007-2011 Varnish Software AS
* All rights reserved.
*
* Author: Dag-Erling Smørgav <des@des.no>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* STEVEDORE: one who works at or is responsible for loading and
* unloading ships in port. Example: "on the wharves, stevedores were
* unloading cargo from the far corners of the world." Origin: Spanish
* estibador, from estibar to pack. First Known Use: 1788
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "mgt/mgt.h"
#include "storage/storage.h"
#include "vav.h"
struct
stevedore_head
stv_stevedores
=
VTAILQ_HEAD_INITIALIZER
(
stv_stevedores
);
struct
stevedore
*
stv_transient
;
/*--------------------------------------------------------------------
* Parse a stevedore argument on the form:
* [ name '=' ] strategy [ ',' arg ] *
*/
static
const
struct
choice
STV_choice
[]
=
{
{
"file"
,
&
smf_stevedore
},
{
"malloc"
,
&
sma_stevedore
},
{
"persistent"
,
&
smp_stevedore
},
#ifdef HAVE_LIBUMEM
{
"umem"
,
&
smu_stevedore
},
#endif
{
NULL
,
NULL
}
};
void
STV_Config
(
const
char
*
spec
)
{
char
**
av
;
const
char
*
p
,
*
q
;
struct
stevedore
*
stv
;
const
struct
stevedore
*
stv2
;
int
ac
,
l
;
static
unsigned
seq
=
0
;
ASSERT_MGT
();
p
=
strchr
(
spec
,
'='
);
q
=
strchr
(
spec
,
','
);
if
(
p
!=
NULL
&&
(
q
==
NULL
||
q
>
p
))
{
av
=
VAV_Parse
(
p
+
1
,
NULL
,
ARGV_COMMA
);
}
else
{
av
=
VAV_Parse
(
spec
,
NULL
,
ARGV_COMMA
);
p
=
NULL
;
}
AN
(
av
);
if
(
av
[
0
]
!=
NULL
)
ARGV_ERR
(
"%s
\n
"
,
av
[
0
]);
if
(
av
[
1
]
==
NULL
)
ARGV_ERR
(
"-s argument lacks strategy {malloc, file, ...}
\n
"
);
for
(
ac
=
0
;
av
[
ac
+
2
]
!=
NULL
;
ac
++
)
continue
;
stv2
=
pick
(
STV_choice
,
av
[
1
],
"storage"
);
AN
(
stv2
);
/* Append strategy to ident string */
VSB_printf
(
vident
,
",-s%s"
,
av
[
1
]);
av
+=
2
;
CHECK_OBJ_NOTNULL
(
stv2
,
STEVEDORE_MAGIC
);
ALLOC_OBJ
(
stv
,
STEVEDORE_MAGIC
);
AN
(
stv
);
*
stv
=
*
stv2
;
AN
(
stv
->
name
);
AN
(
stv
->
alloc
);
if
(
stv
->
allocobj
==
NULL
)
stv
->
allocobj
=
stv_default_allocobj
;
if
(
p
==
NULL
)
bprintf
(
stv
->
ident
,
"s%u"
,
seq
++
);
else
{
l
=
p
-
spec
;
if
(
l
>
sizeof
stv
->
ident
-
1
)
l
=
sizeof
stv
->
ident
-
1
;
bprintf
(
stv
->
ident
,
"%.*s"
,
l
,
spec
);
}
VTAILQ_FOREACH
(
stv2
,
&
stv_stevedores
,
list
)
{
if
(
strcmp
(
stv2
->
ident
,
stv
->
ident
))
continue
;
ARGV_ERR
(
"(-s%s=%s) already defined once
\n
"
,
stv
->
ident
,
stv
->
name
);
}
if
(
stv
->
init
!=
NULL
)
stv
->
init
(
stv
,
ac
,
av
);
else
if
(
ac
!=
0
)
ARGV_ERR
(
"(-s%s) too many arguments
\n
"
,
stv
->
name
);
if
(
!
strcmp
(
stv
->
ident
,
TRANSIENT_STORAGE
))
{
stv
->
transient
=
1
;
AZ
(
stv_transient
);
stv_transient
=
stv
;
}
else
{
VTAILQ_INSERT_TAIL
(
&
stv_stevedores
,
stv
,
list
);
}
}
/*--------------------------------------------------------------------*/
void
STV_Config_Transient
(
void
)
{
ASSERT_MGT
();
if
(
stv_transient
==
NULL
)
STV_Config
(
TRANSIENT_STORAGE
"=malloc"
);
}
/*--------------------------------------------------------------------*/
bin/varnishd/storage/storage.h
View file @
0f13e7eb
...
...
@@ -50,6 +50,8 @@ typedef void storage_close_f(const struct stevedore *);
#include "tbl/vrt_stv_var.h"
#undef VRTSTVTYPE
extern
storage_allocobj_f
stv_default_allocobj
;
/*--------------------------------------------------------------------*/
struct
stevedore
{
...
...
@@ -78,6 +80,11 @@ struct stevedore {
char
ident
[
16
];
/* XXX: match VSM_chunk.ident */
};
VTAILQ_HEAD
(
stevedore_head
,
stevedore
);
extern
struct
stevedore_head
stv_stevedores
;
extern
struct
stevedore
*
stv_transient
;
/*--------------------------------------------------------------------*/
int
STV_GetFile
(
const
char
*
fn
,
int
*
fdp
,
const
char
**
fnp
,
const
char
*
ctx
);
uintmax_t
STV_FileSize
(
int
fd
,
const
char
*
size
,
unsigned
*
granularity
,
...
...
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