Code Coverage: vinyl-cache/bin/vinyld/storage/storage.h
 
82217aa4fc7094b3610340078afaf78cd95a8ec9
 
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(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
/*--------------------------------------------------------------------*/
78
79
struct stevedore {
80
        unsigned                        magic;
81 1
#define STEVEDORE_MAGIC                 0x4baf43db
82
        const char                      *name;
83
84
        /* Called in MGT process */
85
        storage_init_f                  *init;
86
87
        /* Called in cache process
88
         * only allocobj is required, other callbacks are optional
89
         */
90
        storage_open_f                  *open;
91
        storage_close_f                 *close;
92
        storage_allocobj_f              *allocobj;      // XXX add ws ptr or VRT_CTX?
93
        storage_baninfo_f               *baninfo;
94
        storage_banexport_f             *banexport;
95
        storage_panic_f                 *panic;
96
        storage_allocbuf_f              *allocbuf;
97
        storage_freebuf_f               *freebuf;
98
99
        /* Only if SML is used */
100
        sml_alloc_f                     *sml_alloc;
101
        sml_free_f                      *sml_free;
102
        sml_getobj_f                    *sml_getobj;
103
104
        const struct obj_methods        *methods;
105
106
        /* Only if LRU is used */
107
        struct lru                      *lru;
108
109
#define VRTSTVVAR(nm, vtype, ctype, dval) stv_var_##nm *var_##nm;
110
#include "tbl/vrt_stv_var.h"
111
112
        /* private fields for the stevedore */
113
        void                            *priv;
114
115
        VTAILQ_ENTRY(stevedore) list;
116
        char                            **av;
117
        const char                      *ident;
118
        const char                      *vclname;
119
};
120
121
extern struct stevedore *stv_transient;
122
extern struct stevedore *stv_synth;
123
extern struct stevedore *stv_h2_rxbuf;
124
125
/*--------------------------------------------------------------------*/
126
127
void STV_Register(const struct stevedore *, const char *altname);
128
129 34199
#define STV_Foreach(arg) for (arg = NULL; STV__iter(&arg);)
130
131
int STV__iter(struct stevedore ** const );
132
133
/*--------------------------------------------------------------------*/
134
int STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx);
135
uintmax_t STV_FileSize(int fd, const char *size, unsigned *granularity,
136
    const char *ctx);
137
138
/*--------------------------------------------------------------------*/
139
struct lru *LRU_Alloc(void);
140
void LRU_Free(struct lru **);
141
void LRU_Add(struct objcore *, vtim_real now);
142
void LRU_Remove(struct objcore *);
143
int LRU_NukeOne(struct worker *, struct lru *);
144
void LRU_Touch(struct worker *, struct objcore *, vtim_real now);
145
146
/*--------------------------------------------------------------------*/
147
extern const struct stevedore smu_stevedore;
148
extern const struct stevedore sma_stevedore;
149
extern const struct stevedore ssy_stevedore;
150
extern const struct stevedore smd_stevedore;
151
extern const struct stevedore smf_stevedore;
152
extern const struct stevedore smp_stevedore;