Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/varnishd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ varnishd_SOURCES = \
storage/storage_malloc.c \
storage/storage_debug.c \
storage/storage_simple.c \
storage/storage_synth.c \
storage/storage_umem.c \
waiter/cache_waiter.c \
waiter/cache_waiter_epoll.c \
Expand Down
35 changes: 35 additions & 0 deletions bin/varnishd/cache/cache_req.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@

#include "cache_varnishd.h"
#include "cache_filter.h"
#include "cache_objhead.h"
#include "cache_pool.h"
#include "cache_transport.h"
#include "storage/storage.h" // stv_default

#include "common/heritage.h"
#include "vtim.h"
Expand Down Expand Up @@ -325,6 +327,39 @@ Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req)
VDP_Fini(req->vdc);
}

/*----------------------------------------------------------------------
* response body for vcl_synth {}
*/

static void
resp_u_storage(struct req *req)
{

CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
HSH_DerefBoc(req->wrk, req->objcore);
(void)HSH_DerefObjCore(req->wrk, &req->objcore, 0);
}

int
Resp_l_storage(struct req *req, const struct stevedore *stv)
{
int r;

CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);

if (req->objcore != NULL)
resp_u_storage(req);
AZ(req->objcore);
req->objcore = HSH_Private(req->wrk);
CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
r = STV_NewObject(req->wrk, req->objcore, stv, 0);
if (r == 0)
resp_u_storage(req);
return (r);
}


/*----------------------------------------------------------------------
*/

Expand Down
14 changes: 8 additions & 6 deletions bin/varnishd/cache/cache_req_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ cnt_synth(struct worker *wrk, struct req *req)

/* Discard any lingering request body before delivery */
(void)VRB_Ignore(req);

req->objcore = HSH_Private(wrk);
CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
szl = -1;
if (STV_NewObject(wrk, req->objcore, stv_transient, 0)) {

if (req->objcore != NULL ||
Resp_l_storage(req, stv_transient)) {
CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
body = VSB_data(synth_body);
szl = VSB_len(synth_body);
assert(szl >= 0);
Expand All @@ -406,14 +406,16 @@ cnt_synth(struct worker *wrk, struct req *req)

if (szl >= 0)
AZ(ObjSetU64(wrk, req->objcore, OA_LEN, VSB_len(synth_body)));
HSH_DerefBoc(wrk, req->objcore);
if (req->objcore != NULL)
HSH_DerefBoc(wrk, req->objcore);
VSB_destroy(&synth_body);

if (szl < 0) {
VSLb(req->vsl, SLT_Error, "Could not get storage");
req->doclose = SC_OVERLOAD;
VSLb_ts_req(req, "Resp", W_TIM_real(wrk));
(void)HSH_DerefObjCore(wrk, &req->objcore, 1);
if (req->objcore != NULL)
(void)HSH_DerefObjCore(wrk, &req->objcore, 1);
http_Teardown(req->resp);
return (REQ_FSM_DONE);
}
Expand Down
1 change: 1 addition & 0 deletions bin/varnishd/cache/cache_varnishd.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ void Req_Fail(struct req *req, stream_close_t reason);
void Req_AcctLogCharge(struct VSC_main_wrk *, struct req *);
void Req_LogHit(struct worker *, struct req *, struct objcore *, intmax_t);
const char *Req_LogStart(const struct worker *, struct req *);
int Resp_l_storage(struct req *req, const struct stevedore *stv);

/* cache_req_body.c */
int VRB_Ignore(struct req *);
Expand Down
105 changes: 102 additions & 3 deletions bin/varnishd/cache/cache_vrt_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "cache_varnishd.h"
#include "cache_objhead.h"
#include "cache_transport.h"
#include "storage/storage.h"
#include "common/heritage.h"

#include "vcl.h"
Expand Down Expand Up @@ -473,6 +474,34 @@ VRT_l_req_storage(VRT_CTX, VCL_STEVEDORE stv)

/*--------------------------------------------------------------------*/

VCL_STEVEDORE
VRT_r_resp_storage(VRT_CTX)
{
struct objcore *oc;

CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
oc = ctx->req->objcore;
if (oc == NULL)
VRT_l_resp_storage(ctx, NULL);
oc = ctx->req->objcore;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
return (oc->stobj->stevedore);
}

VCL_VOID
VRT_l_resp_storage(VRT_CTX, VCL_STEVEDORE stv)
{

CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (stv == NULL)
stv = stv_transient;
if (! Resp_l_storage(ctx->req, stv))
VRT_fail(ctx, "Storage %s failed", stv->vclname);
}

/*--------------------------------------------------------------------*/

VCL_STEVEDORE
VRT_r_beresp_storage(VRT_CTX)
{
Expand All @@ -493,8 +522,6 @@ VRT_l_beresp_storage(VRT_CTX, VCL_STEVEDORE stv)
* VCL <= 4.0 ONLY
*/

#include "storage/storage.h"

VCL_STRING
VRT_r_beresp_storage_hint(VRT_CTX)
{
Expand Down Expand Up @@ -1093,7 +1120,79 @@ VRT_l_##which##_body(VRT_CTX, enum lbody_e type, \
}

VRT_BODY_L(beresp)
VRT_BODY_L(resp)
static VRT_BODY_L(resp_vsb)

VCL_VOID
VRT_l_resp_body(VRT_CTX, enum lbody_e type,
const char *str, VCL_BODY body)
{
struct vscarab *scarab;
struct viov *viov;
struct req *req;
ssize_t sz = 0;
VCL_STRANDS s;
VCL_BLOB b;
int n;


CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(body);
req = ctx->req;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);

if (req->objcore != NULL &&
req->objcore->stobj->stevedore != &ssy_stevedore) {
VRT_l_resp_vsb_body(ctx, type, str, body);
return;
}

if (req->objcore == NULL ||
type == LBODY_SET_STRING || type == LBODY_SET_BLOB)
VRT_l_resp_storage(ctx, &ssy_stevedore);

if (! ObjGetSpace(req->wrk, req->objcore, &sz, (uint8_t **)(void*)&scarab)) {
VRT_fail(ctx, "Synth storage failed");
return;
}

VSCARAB_CHECK_NOTNULL(scarab);

if (type == LBODY_SET_BLOB || type == LBODY_ADD_BLOB) {
AZ(str);
b = body;
viov = VSCARAB_GET(scarab);
AN(viov); // ObjGetSpace ensures
viov->iov.iov_base = TRUST_ME(b->blob);
viov->iov.iov_len = b->len;
return;
}
if (str != NULL) {
viov = VSCARAB_GET(scarab);
AN(viov); // ObjGetSpace ensures
viov->iov.iov_base = TRUST_ME(str);
viov->iov.iov_len = strlen(str);
}

s = body;
for (n = 0; s != NULL && n < s->n; n++) {
if (s->p[n] == NULL || *s->p[n] == '\0')
continue;

viov = VSCARAB_GET(scarab);
if (viov == NULL) {
if (! ObjGetSpace(req->wrk, req->objcore, &sz,
(uint8_t **)(void*)&scarab)) {
VRT_fail(ctx, "Synth storage failed");
return;
}
viov = VSCARAB_GET(scarab);
}
AN(viov);
viov->iov.iov_base = TRUST_ME(s->p[n]);
viov->iov.iov_len = strlen(s->p[n]);
}
}


/*--------------------------------------------------------------------*/

Expand Down
1 change: 1 addition & 0 deletions bin/varnishd/storage/mgt_stevedore.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ STV_Register_The_Usual_Suspects(void)
STV_Register(&smf_stevedore, NULL);
STV_Register(&sma_stevedore, NULL);
STV_Register(&smd_stevedore, NULL);
STV_Register(&ssy_stevedore, NULL);
#ifdef WITH_PERSISTENT_STORAGE
STV_Register(&smp_stevedore, NULL);
STV_Register(&smp_fake_stevedore, NULL);
Expand Down
1 change: 1 addition & 0 deletions bin/varnishd/storage/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void LRU_Touch(struct worker *, struct objcore *, vtim_real now);
/*--------------------------------------------------------------------*/
extern const struct stevedore smu_stevedore;
extern const struct stevedore sma_stevedore;
extern const struct stevedore ssy_stevedore;
extern const struct stevedore smd_stevedore;
extern const struct stevedore smf_stevedore;
extern const struct stevedore smp_stevedore;
6 changes: 3 additions & 3 deletions bin/varnishd/storage/storage_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@ sml_notify_wait(struct sml_notify *sn)
AZ(pthread_mutex_unlock(&sn->mtx));
}

static int v_matchproto_(objiterator_f)
sml_iterator(struct worker *wrk, struct objcore *oc,
int v_matchproto_(objiterator_f)
SML_iterator(struct worker *wrk, struct objcore *oc,
void *priv, objiterate_f *func, int final)
{
struct sml_notify sn;
Expand Down Expand Up @@ -1144,7 +1144,7 @@ sml_setattr(struct worker *wrk, struct objcore *oc, enum obj_attr attr,

const struct obj_methods SML_methods = {
.objfree = sml_objfree,
.objiterator = sml_iterator,
.objiterator = SML_iterator,
.objgetspace = sml_getspace,
.objextend = sml_extend,
.objtrimstore = sml_trimstore,
Expand Down
2 changes: 2 additions & 0 deletions bin/varnishd/storage/storage_simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ struct object *SML_MkObject(const struct stevedore *, struct objcore *,
void *SML_AllocBuf(struct worker *, const struct stevedore *, size_t,
uintptr_t *);
void SML_FreeBuf(struct worker *, const struct stevedore *, uintptr_t);
int SML_iterator(struct worker *wrk, struct objcore *oc,
void *priv, objiterate_f *func, int final);

storage_allocobj_f SML_allocobj;
storage_panic_f SML_panic;
Loading