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
83ea35df
Commit
83ea35df
authored
Mar 24, 2011
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Segregate the WRW related fields in their own structure for code
clarity.
parent
d9037ddf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
68 deletions
+85
-68
cache.h
bin/varnishd/cache.h
+13
-7
cache_center.c
bin/varnishd/cache_center.c
+4
-4
cache_http.c
bin/varnishd/cache_http.c
+8
-7
cache_pool.c
bin/varnishd/cache_pool.c
+3
-3
cache_wrw.c
bin/varnishd/cache_wrw.c
+57
-47
No files found.
bin/varnishd/cache.h
View file @
83ea35df
...
...
@@ -248,6 +248,16 @@ struct exp {
/*--------------------------------------------------------------------*/
/* WRW related fields */
struct
wrw
{
int
*
wfd
;
unsigned
werr
;
/* valid after WRK_Flush() */
struct
iovec
*
iov
;
unsigned
siov
;
unsigned
niov
;
ssize_t
liov
;
};
struct
worker
{
unsigned
magic
;
#define WORKER_MAGIC 0x6391adcf
...
...
@@ -259,18 +269,13 @@ struct worker {
double
lastused
;
struct
wrw
wrw
;
pthread_cond_t
cond
;
VTAILQ_ENTRY
(
worker
)
list
;
struct
workreq
*
wrq
;
int
*
wfd
;
unsigned
werr
;
/* valid after WRK_Flush() */
struct
iovec
*
iov
;
unsigned
siov
;
unsigned
niov
;
ssize_t
liov
;
struct
VCL_conf
*
vcl
;
uint32_t
*
wlb
,
*
wlp
,
*
wle
;
...
...
@@ -781,6 +786,7 @@ int WRK_Queue(struct workreq *wrq);
int
WRK_QueueSession
(
struct
sess
*
sp
);
void
WRK_SumStat
(
struct
worker
*
w
);
#define WRW_IsReleased(w) ((w)->wrw.wfd == NULL)
void
WRW_Reserve
(
struct
worker
*
w
,
int
*
fd
);
unsigned
WRW_Flush
(
struct
worker
*
w
);
unsigned
WRW_FlushRelease
(
struct
worker
*
w
);
...
...
bin/varnishd/cache_center.c
View file @
83ea35df
...
...
@@ -240,7 +240,7 @@ cnt_deliver(struct sess *sp)
RES_WriteObj
(
sp
);
AZ
(
sp
->
wrk
->
wfd
);
assert
(
WRW_IsReleased
(
sp
->
wrk
)
);
(
void
)
HSH_Deref
(
sp
->
wrk
,
NULL
,
&
sp
->
obj
);
http_Setup
(
sp
->
wrk
->
resp
,
NULL
);
sp
->
step
=
STP_DONE
;
...
...
@@ -749,7 +749,7 @@ cnt_fetchbody(struct sess *sp)
http_Setup
(
sp
->
wrk
->
bereq
,
NULL
);
http_Setup
(
sp
->
wrk
->
beresp
,
NULL
);
sp
->
wrk
->
vfp
=
NULL
;
AZ
(
sp
->
wrk
->
wfd
);
assert
(
WRW_IsReleased
(
sp
->
wrk
)
);
AZ
(
sp
->
vbc
);
AN
(
sp
->
director
);
...
...
@@ -1121,7 +1121,7 @@ cnt_pipe(struct sess *sp)
assert
(
sp
->
handling
==
VCL_RET_PIPE
);
PipeSession
(
sp
);
AZ
(
sp
->
wrk
->
wfd
);
assert
(
WRW_IsReleased
(
sp
->
wrk
)
);
http_Setup
(
sp
->
wrk
->
bereq
,
NULL
);
sp
->
step
=
STP_DONE
;
return
(
0
);
...
...
@@ -1396,7 +1396,7 @@ CNT_Session(struct sess *sp)
CHECK_OBJ_ORNULL
(
w
->
nobjhead
,
OBJHEAD_MAGIC
);
}
WSL_Flush
(
w
,
0
);
AZ
(
w
->
wfd
);
assert
(
WRW_IsReleased
(
w
)
);
}
/*
...
...
bin/varnishd/cache_http.c
View file @
83ea35df
...
...
@@ -1054,10 +1054,11 @@ unsigned
http_Write
(
struct
worker
*
w
,
const
struct
http
*
hp
,
int
resp
)
{
unsigned
u
,
l
;
int
fd
=
*
(
w
->
wrw
.
wfd
);
if
(
resp
)
{
l
=
WRW_WriteH
(
w
,
&
hp
->
hd
[
HTTP_HDR_PROTO
],
" "
);
WSLH
(
w
,
*
w
->
w
fd
,
hp
,
HTTP_HDR_PROTO
);
WSLH
(
w
,
fd
,
hp
,
HTTP_HDR_PROTO
);
hp
->
hd
[
HTTP_HDR_STATUS
].
b
=
WS_Alloc
(
w
->
ws
,
4
);
AN
(
hp
->
hd
[
HTTP_HDR_STATUS
].
b
);
...
...
@@ -1066,18 +1067,18 @@ http_Write(struct worker *w, const struct http *hp, int resp)
hp
->
hd
[
HTTP_HDR_STATUS
].
e
=
hp
->
hd
[
HTTP_HDR_STATUS
].
b
+
3
;
l
+=
WRW_WriteH
(
w
,
&
hp
->
hd
[
HTTP_HDR_STATUS
],
" "
);
WSLH
(
w
,
*
w
->
w
fd
,
hp
,
HTTP_HDR_STATUS
);
WSLH
(
w
,
fd
,
hp
,
HTTP_HDR_STATUS
);
l
+=
WRW_WriteH
(
w
,
&
hp
->
hd
[
HTTP_HDR_RESPONSE
],
"
\r\n
"
);
WSLH
(
w
,
*
w
->
w
fd
,
hp
,
HTTP_HDR_RESPONSE
);
WSLH
(
w
,
fd
,
hp
,
HTTP_HDR_RESPONSE
);
}
else
{
AN
(
hp
->
hd
[
HTTP_HDR_URL
].
b
);
l
=
WRW_WriteH
(
w
,
&
hp
->
hd
[
HTTP_HDR_REQ
],
" "
);
WSLH
(
w
,
*
w
->
w
fd
,
hp
,
HTTP_HDR_REQ
);
WSLH
(
w
,
fd
,
hp
,
HTTP_HDR_REQ
);
l
+=
WRW_WriteH
(
w
,
&
hp
->
hd
[
HTTP_HDR_URL
],
" "
);
WSLH
(
w
,
*
w
->
w
fd
,
hp
,
HTTP_HDR_URL
);
WSLH
(
w
,
fd
,
hp
,
HTTP_HDR_URL
);
l
+=
WRW_WriteH
(
w
,
&
hp
->
hd
[
HTTP_HDR_PROTO
],
"
\r\n
"
);
WSLH
(
w
,
*
w
->
w
fd
,
hp
,
HTTP_HDR_PROTO
);
WSLH
(
w
,
fd
,
hp
,
HTTP_HDR_PROTO
);
}
for
(
u
=
HTTP_HDR_FIRST
;
u
<
hp
->
nhd
;
u
++
)
{
if
(
hp
->
hd
[
u
].
b
==
NULL
)
...
...
@@ -1085,7 +1086,7 @@ http_Write(struct worker *w, const struct http *hp, int resp)
AN
(
hp
->
hd
[
u
].
b
);
AN
(
hp
->
hd
[
u
].
e
);
l
+=
WRW_WriteH
(
w
,
&
hp
->
hd
[
u
],
"
\r\n
"
);
WSLH
(
w
,
*
w
->
w
fd
,
hp
,
u
);
WSLH
(
w
,
fd
,
hp
,
u
);
}
l
+=
WRW_Write
(
w
,
"
\r\n
"
,
-
1
);
return
(
l
);
...
...
bin/varnishd/cache_pool.c
View file @
83ea35df
...
...
@@ -143,8 +143,8 @@ wrk_thread_real(struct wq *qp, unsigned shm_workspace, unsigned sess_workspace,
w
->
bereq
=
HTTP_create
(
http0
,
nhttp
);
w
->
beresp
=
HTTP_create
(
http1
,
nhttp
);
w
->
resp
=
HTTP_create
(
http2
,
nhttp
);
w
->
iov
=
iov
;
w
->
siov
=
siov
;
w
->
wrw
.
iov
=
iov
;
w
->
wrw
.
siov
=
siov
;
AZ
(
pthread_cond_init
(
&
w
->
cond
,
NULL
));
WS_Init
(
w
->
ws
,
"wrk"
,
ws
,
sess_workspace
);
...
...
@@ -189,7 +189,7 @@ wrk_thread_real(struct wq *qp, unsigned shm_workspace, unsigned sess_workspace,
AZ
(
w
->
bereq
->
ws
);
AZ
(
w
->
beresp
->
ws
);
AZ
(
w
->
resp
->
ws
);
AZ
(
w
->
wfd
);
AZ
(
w
->
w
rw
.
w
fd
);
AZ
(
w
->
storage_hint
);
assert
(
w
->
wlp
==
w
->
wlb
);
w
->
wrq
=
NULL
;
...
...
bin/varnishd/cache_wrw.c
View file @
83ea35df
...
...
@@ -72,45 +72,51 @@ SVNID("$Id$")
void
WRW_Reserve
(
struct
worker
*
w
,
int
*
fd
)
{
struct
wrw
*
wrw
;
CHECK_OBJ_NOTNULL
(
w
,
WORKER_MAGIC
);
AZ
(
w
->
wfd
);
w
->
werr
=
0
;
w
->
liov
=
0
;
w
->
niov
=
0
;
w
->
wfd
=
fd
;
wrw
=
&
w
->
wrw
;
AZ
(
wrw
->
wfd
);
wrw
->
werr
=
0
;
wrw
->
liov
=
0
;
wrw
->
niov
=
0
;
wrw
->
wfd
=
fd
;
}
static
void
WRW_Release
(
struct
worker
*
w
)
{
struct
wrw
*
wrw
;
CHECK_OBJ_NOTNULL
(
w
,
WORKER_MAGIC
);
w
->
werr
=
0
;
w
->
liov
=
0
;
w
->
niov
=
0
;
w
->
wfd
=
NULL
;
wrw
=
&
w
->
wrw
;
wrw
->
werr
=
0
;
wrw
->
liov
=
0
;
wrw
->
niov
=
0
;
wrw
->
wfd
=
NULL
;
}
unsigned
WRW_Flush
(
struct
worker
*
w
)
{
ssize_t
i
;
struct
wrw
*
wrw
;
CHECK_OBJ_NOTNULL
(
w
,
WORKER_MAGIC
);
AN
(
w
->
wfd
);
if
(
*
w
->
wfd
>=
0
&&
w
->
niov
>
0
&&
w
->
werr
==
0
)
{
i
=
writev
(
*
w
->
wfd
,
w
->
iov
,
w
->
niov
);
if
(
i
!=
w
->
liov
)
{
w
->
werr
++
;
WSL
(
w
,
SLT_Debug
,
*
w
->
wfd
,
wrw
=
&
w
->
wrw
;
AN
(
wrw
->
wfd
);
if
(
*
wrw
->
wfd
>=
0
&&
wrw
->
niov
>
0
&&
wrw
->
werr
==
0
)
{
i
=
writev
(
*
wrw
->
wfd
,
wrw
->
iov
,
wrw
->
niov
);
if
(
i
!=
wrw
->
liov
)
{
wrw
->
werr
++
;
WSL
(
w
,
SLT_Debug
,
*
wrw
->
wfd
,
"Write error, retval = %d, len = %d, errno = %s"
,
i
,
w
->
liov
,
strerror
(
errno
));
i
,
w
rw
->
liov
,
strerror
(
errno
));
}
}
w
->
liov
=
0
;
w
->
niov
=
0
;
return
(
w
->
werr
);
w
rw
->
liov
=
0
;
w
rw
->
niov
=
0
;
return
(
w
rw
->
werr
);
}
unsigned
...
...
@@ -119,7 +125,7 @@ WRW_FlushRelease(struct worker *w)
unsigned
u
;
CHECK_OBJ_NOTNULL
(
w
,
WORKER_MAGIC
);
AN
(
w
->
wfd
);
AN
(
w
->
w
rw
.
w
fd
);
u
=
WRW_Flush
(
w
);
WRW_Release
(
w
);
return
(
u
);
...
...
@@ -131,7 +137,7 @@ WRW_WriteH(struct worker *w, const txt *hh, const char *suf)
unsigned
u
;
CHECK_OBJ_NOTNULL
(
w
,
WORKER_MAGIC
);
AN
(
w
->
wfd
);
AN
(
w
->
w
rw
.
w
fd
);
AN
(
w
);
AN
(
hh
);
AN
(
hh
->
b
);
...
...
@@ -145,19 +151,21 @@ WRW_WriteH(struct worker *w, const txt *hh, const char *suf)
unsigned
WRW_Write
(
struct
worker
*
w
,
const
void
*
ptr
,
int
len
)
{
struct
wrw
*
wrw
;
CHECK_OBJ_NOTNULL
(
w
,
WORKER_MAGIC
);
AN
(
w
->
wfd
);
if
(
len
==
0
||
*
w
->
wfd
<
0
)
wrw
=
&
w
->
wrw
;
AN
(
wrw
->
wfd
);
if
(
len
==
0
||
*
wrw
->
wfd
<
0
)
return
(
0
);
if
(
len
==
-
1
)
len
=
strlen
(
ptr
);
if
(
w
->
niov
==
w
->
siov
)
if
(
w
rw
->
niov
==
wr
w
->
siov
)
(
void
)
WRW_Flush
(
w
);
w
->
iov
[
w
->
niov
].
iov_base
=
TRUST_ME
(
ptr
);
w
->
iov
[
w
->
niov
].
iov_len
=
len
;
w
->
liov
+=
len
;
w
->
niov
++
;
w
rw
->
iov
[
wr
w
->
niov
].
iov_base
=
TRUST_ME
(
ptr
);
w
rw
->
iov
[
wr
w
->
niov
].
iov_len
=
len
;
w
rw
->
liov
+=
len
;
w
rw
->
niov
++
;
return
(
len
);
}
...
...
@@ -165,9 +173,11 @@ WRW_Write(struct worker *w, const void *ptr, int len)
void
WRW_Sendfile
(
struct
worker
*
w
,
int
fd
,
off_t
off
,
unsigned
len
)
{
struct
wrw
*
wrw
;
CHECK_OBJ_NOTNULL
(
w
,
WORKER_MAGIC
);
AN
(
w
->
wfd
);
wrw
=
&
w
->
wrw
;
AN
(
wrw
->
wfd
);
assert
(
fd
>=
0
);
assert
(
len
>
0
);
...
...
@@ -175,31 +185,31 @@ WRW_Sendfile(struct worker *w, int fd, off_t off, unsigned len)
do
{
struct
sf_hdtr
sfh
;
memset
(
&
sfh
,
0
,
sizeof
sfh
);
if
(
w
->
niov
>
0
)
{
sfh
.
headers
=
w
->
iov
;
sfh
.
hdr_cnt
=
w
->
niov
;
if
(
w
rw
->
niov
>
0
)
{
sfh
.
headers
=
w
rw
->
iov
;
sfh
.
hdr_cnt
=
w
rw
->
niov
;
}
if
(
sendfile
(
fd
,
*
w
->
wfd
,
off
,
len
,
&
sfh
,
NULL
,
0
)
!=
0
)
w
->
werr
++
;
w
->
liov
=
0
;
w
->
niov
=
0
;
if
(
sendfile
(
fd
,
*
w
rw
->
wfd
,
off
,
len
,
&
sfh
,
NULL
,
0
)
!=
0
)
w
rw
->
werr
++
;
w
rw
->
liov
=
0
;
w
rw
->
niov
=
0
;
}
while
(
0
);
#elif defined(__linux__)
do
{
if
(
WRK_Flush
(
w
)
==
0
&&
sendfile
(
*
w
->
wfd
,
fd
,
&
off
,
len
)
!=
len
)
w
->
werr
++
;
sendfile
(
*
w
rw
->
wfd
,
fd
,
&
off
,
len
)
!=
len
)
w
rw
->
werr
++
;
}
while
(
0
);
#elif defined(__sun) && defined(HAVE_SENDFILEV)
do
{
sendfilevec_t
svvec
[
params
->
http_headers
*
2
+
1
];
size_t
xferred
=
0
,
expected
=
0
;
int
i
;
for
(
i
=
0
;
i
<
w
->
niov
;
i
++
)
{
for
(
i
=
0
;
i
<
w
rw
->
niov
;
i
++
)
{
svvec
[
i
].
sfv_fd
=
SFV_FD_SELF
;
svvec
[
i
].
sfv_flag
=
0
;
svvec
[
i
].
sfv_off
=
(
off_t
)
w
->
iov
[
i
].
iov_base
;
svvec
[
i
].
sfv_len
=
w
->
iov
[
i
].
iov_len
;
svvec
[
i
].
sfv_off
=
(
off_t
)
w
rw
->
iov
[
i
].
iov_base
;
svvec
[
i
].
sfv_len
=
w
rw
->
iov
[
i
].
iov_len
;
expected
+=
svvec
[
i
].
sfv_len
;
}
svvec
[
i
].
sfv_fd
=
fd
;
...
...
@@ -207,17 +217,17 @@ WRW_Sendfile(struct worker *w, int fd, off_t off, unsigned len)
svvec
[
i
].
sfv_off
=
off
;
svvec
[
i
].
sfv_len
=
len
;
expected
+=
svvec
[
i
].
sfv_len
;
if
(
sendfilev
(
*
w
->
wfd
,
svvec
,
i
,
&
xferred
)
==
-
1
||
if
(
sendfilev
(
*
w
rw
->
wfd
,
svvec
,
i
,
&
xferred
)
==
-
1
||
xferred
!=
expected
)
w
->
werr
++
;
w
->
liov
=
0
;
w
->
niov
=
0
;
w
rw
->
werr
++
;
w
rw
->
liov
=
0
;
w
rw
->
niov
=
0
;
}
while
(
0
);
#elif defined(__sun) && defined(HAVE_SENDFILE)
do
{
if
(
WRK_Flush
(
w
)
==
0
&&
sendfile
(
*
w
->
wfd
,
fd
,
&
off
,
len
)
!=
len
)
w
->
werr
++
;
sendfile
(
*
w
rw
->
wfd
,
fd
,
&
off
,
len
)
!=
len
)
w
rw
->
werr
++
;
}
while
(
0
);
#else
#error Unknown sendfile() implementation
...
...
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