| | varnish-cache/bin/varnishd/storage/storage.h |
0 |
|
/*- |
1 |
|
* Copyright (c) 2006 Verdens Gang AS |
2 |
|
* Copyright (c) 2006-2011 Varnish Software AS |
3 |
|
* All rights reserved. |
4 |
|
* |
5 |
|
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk> |
6 |
|
* |
7 |
|
* SPDX-License-Identifier: BSD-2-Clause |
8 |
|
* |
9 |
|
* Redistribution and use in source and binary forms, with or without |
10 |
|
* modification, are permitted provided that the following conditions |
11 |
|
* are met: |
12 |
|
* 1. Redistributions of source code must retain the above copyright |
13 |
|
* notice, this list of conditions and the following disclaimer. |
14 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
15 |
|
* notice, this list of conditions and the following disclaimer in the |
16 |
|
* documentation and/or other materials provided with the distribution. |
17 |
|
* |
18 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
19 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
22 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
24 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
25 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
26 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
27 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
28 |
|
* SUCH DAMAGE. |
29 |
|
* |
30 |
|
* This defines the backend interface between the stevedore and the |
31 |
|
* pluggable storage implementations. |
32 |
|
* |
33 |
|
*/ |
34 |
|
|
35 |
|
struct stevedore; |
36 |
|
struct sess; |
37 |
|
struct objcore; |
38 |
|
struct worker; |
39 |
|
struct lru; |
40 |
|
struct vsl_log; |
41 |
|
struct vfp_ctx; |
42 |
|
struct obj_methods; |
43 |
|
|
44 |
|
enum baninfo { |
45 |
|
BI_NEW, |
46 |
|
BI_DROP |
47 |
|
}; |
48 |
|
|
49 |
|
/* Prototypes --------------------------------------------------------*/ |
50 |
|
|
51 |
|
typedef void storage_init_f(struct stevedore *, int ac, char * const *av); |
52 |
|
typedef void storage_open_f(struct stevedore *); |
53 |
|
typedef int storage_allocobj_f(struct worker *, const struct stevedore *, |
54 |
|
struct objcore *, unsigned); |
55 |
|
typedef void storage_close_f(const struct stevedore *, int pass); |
56 |
|
typedef int storage_baninfo_f(const struct stevedore *, enum baninfo event, |
57 |
|
const uint8_t *ban, unsigned len); |
58 |
|
typedef void storage_banexport_f(const struct stevedore *, const uint8_t *bans, |
59 |
|
unsigned len); |
60 |
|
typedef void storage_panic_f(struct vsb *vsb, const struct objcore *oc); |
61 |
|
|
62 |
|
typedef void *storage_allocbuf_f(struct worker *, const struct stevedore *, |
63 |
|
size_t size, uintptr_t *ppriv); |
64 |
|
typedef void storage_freebuf_f(struct worker *, const struct stevedore *, |
65 |
|
uintptr_t priv); |
66 |
|
|
67 |
|
struct storage; |
68 |
|
typedef struct object *sml_getobj_f(struct worker *, struct objcore *); |
69 |
|
typedef struct storage *sml_alloc_f(const struct stevedore *, size_t size); |
70 |
|
typedef void sml_free_f(struct storage *); |
71 |
|
|
72 |
|
/* Prototypes for VCL variable responders */ |
73 |
|
#define VRTSTVVAR(nm,vt,ct,def) \ |
74 |
|
typedef ct stv_var_##nm(const struct stevedore *); |
75 |
|
#include "tbl/vrt_stv_var.h" |
76 |
|
|
77 |
|
/* VAI helpers -------------------------------------------------------*/ |
78 |
|
|
79 |
|
static inline uint64_t |
80 |
2442 |
ptr2lease(const void *ptr) |
81 |
|
{ |
82 |
2442 |
uint64_t r = (uintptr_t)ptr; |
83 |
|
|
84 |
|
if (sizeof(void *) < 8) //lint !e506 !e774 |
85 |
|
r <<= 1; |
86 |
|
|
87 |
2442 |
return (r); |
88 |
|
} |
89 |
|
|
90 |
|
static inline void * |
91 |
3479 |
lease2ptr(uint64_t l) |
92 |
|
{ |
93 |
|
|
94 |
|
if (sizeof(void *) < 8) //lint !e506 !e774 |
95 |
|
l >>= 1; |
96 |
|
|
97 |
3479 |
return ((void *)(uintptr_t)l); |
98 |
|
} |
99 |
|
|
100 |
|
/*--------------------------------------------------------------------*/ |
101 |
|
|
102 |
|
struct stevedore { |
103 |
|
unsigned magic; |
104 |
|
#define STEVEDORE_MAGIC 0x4baf43db |
105 |
|
const char *name; |
106 |
|
|
107 |
|
/* Called in MGT process */ |
108 |
|
storage_init_f *init; |
109 |
|
|
110 |
|
/* Called in cache process |
111 |
|
* only allocobj is required, other callbacks are optional |
112 |
|
*/ |
113 |
|
storage_open_f *open; |
114 |
|
storage_close_f *close; |
115 |
|
storage_allocobj_f *allocobj; |
116 |
|
storage_baninfo_f *baninfo; |
117 |
|
storage_banexport_f *banexport; |
118 |
|
storage_panic_f *panic; |
119 |
|
storage_allocbuf_f *allocbuf; |
120 |
|
storage_freebuf_f *freebuf; |
121 |
|
|
122 |
|
/* Only if SML is used */ |
123 |
|
sml_alloc_f *sml_alloc; |
124 |
|
sml_free_f *sml_free; |
125 |
|
sml_getobj_f *sml_getobj; |
126 |
|
|
127 |
|
const struct obj_methods *methods; |
128 |
|
|
129 |
|
/* Only if LRU is used */ |
130 |
|
struct lru *lru; |
131 |
|
|
132 |
|
#define VRTSTVVAR(nm, vtype, ctype, dval) stv_var_##nm *var_##nm; |
133 |
|
#include "tbl/vrt_stv_var.h" |
134 |
|
|
135 |
|
/* private fields for the stevedore */ |
136 |
|
void *priv; |
137 |
|
|
138 |
|
VTAILQ_ENTRY(stevedore) list; |
139 |
|
char **av; |
140 |
|
const char *ident; |
141 |
|
const char *vclname; |
142 |
|
}; |
143 |
|
|
144 |
|
extern struct stevedore *stv_transient; |
145 |
|
extern struct stevedore *stv_h2_rxbuf; |
146 |
|
|
147 |
|
/*--------------------------------------------------------------------*/ |
148 |
|
|
149 |
|
void STV_Register(const struct stevedore *, const char *altname); |
150 |
|
|
151 |
|
#define STV_Foreach(arg) for (arg = NULL; STV__iter(&arg);) |
152 |
|
|
153 |
|
int STV__iter(struct stevedore ** const ); |
154 |
|
|
155 |
|
/*--------------------------------------------------------------------*/ |
156 |
|
int STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx); |
157 |
|
uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity, |
158 |
|
const char *ctx); |
159 |
|
|
160 |
|
/*--------------------------------------------------------------------*/ |
161 |
|
struct lru *LRU_Alloc(void); |
162 |
|
void LRU_Free(struct lru **); |
163 |
|
void LRU_Add(struct objcore *, vtim_real now); |
164 |
|
void LRU_Remove(struct objcore *); |
165 |
|
int LRU_NukeOne(struct worker *, struct lru *); |
166 |
|
void LRU_Touch(struct worker *, struct objcore *, vtim_real now); |
167 |
|
|
168 |
|
/*--------------------------------------------------------------------*/ |
169 |
|
extern const struct stevedore smu_stevedore; |
170 |
|
extern const struct stevedore sma_stevedore; |
171 |
|
extern const struct stevedore smd_stevedore; |
172 |
|
extern const struct stevedore smf_stevedore; |
173 |
|
extern const struct stevedore smp_stevedore; |