| Code Coverage: vinyl-cache/bin/vinyld/cache/cache_obj.h |
| |
| 82217aa4fc7094b3610340078afaf78cd95a8ec9 |
| |
| 0 |
|
/*- |
| 1 |
|
* Copyright (c) 2015-2016 Varnish Software AS |
| 2 |
|
* All rights reserved. |
| 3 |
|
* |
| 4 |
|
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk> |
| 5 |
|
* |
| 6 |
|
* SPDX-License-Identifier: BSD-2-Clause |
| 7 |
|
* |
| 8 |
|
* Redistribution and use in source and binary forms, with or without |
| 9 |
|
* modification, are permitted provided that the following conditions |
| 10 |
|
* are met: |
| 11 |
|
* 1. Redistributions of source code must retain the above copyright |
| 12 |
|
* notice, this list of conditions and the following disclaimer. |
| 13 |
|
* 2. Redistributions in binary form must reproduce the above copyright |
| 14 |
|
* notice, this list of conditions and the following disclaimer in the |
| 15 |
|
* documentation and/or other materials provided with the distribution. |
| 16 |
|
* |
| 17 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 18 |
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 |
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 |
|
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
| 21 |
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 |
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 23 |
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 24 |
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 25 |
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 26 |
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 |
|
* SUCH DAMAGE. |
| 28 |
|
* |
| 29 |
|
*/ |
| 30 |
|
|
| 31 |
|
/* Methods on objcore ------------------------------------------------*/ |
| 32 |
|
|
| 33 |
|
typedef void objfree_f(struct worker *, struct objcore *); |
| 34 |
|
|
| 35 |
|
typedef void objsetstate_f(struct worker *, const struct objcore *, |
| 36 |
|
enum boc_state_e); |
| 37 |
|
|
| 38 |
|
typedef int objiterator_f(struct worker *, struct objcore *, |
| 39 |
|
void *priv, objiterate_f *func, int final); |
| 40 |
|
typedef int objgetspace_f(struct worker *, struct objcore *, |
| 41 |
|
ssize_t *sz, uint8_t **ptr); |
| 42 |
|
typedef void objextend_f(struct worker *, struct objcore *, ssize_t l); |
| 43 |
|
typedef void objtrimstore_f(struct worker *, struct objcore *); |
| 44 |
|
typedef void objbocdone_f(struct worker *, struct objcore *, struct boc *); |
| 45 |
|
typedef void objslim_f(struct worker *, struct objcore *); |
| 46 |
|
typedef const void *objgetattr_f(struct worker *, struct objcore *, |
| 47 |
|
enum obj_attr attr, ssize_t *len); |
| 48 |
|
typedef void *objsetattr_f(struct worker *, struct objcore *, |
| 49 |
|
enum obj_attr attr, ssize_t len, const void *ptr); |
| 50 |
|
typedef void objtouch_f(struct worker *, struct objcore *, vtim_real now); |
| 51 |
|
|
| 52 |
|
/* called by Obj/storage to notify that the lease function (vai_lease_f) or |
| 53 |
|
* buffer function (vai_buffer_f) can be called again after return of |
| 54 |
|
* -EAGAIN or -ENOBUFS |
| 55 |
|
* NOTE: |
| 56 |
|
* - the callback gets executed by an arbitrary thread |
| 57 |
|
* - WITH the boc mtx held |
| 58 |
|
* so it should never block and be efficient |
| 59 |
|
*/ |
| 60 |
|
|
| 61 |
|
/* notify entry added to struct boc::vai_q_head */ |
| 62 |
|
struct vai_qe { |
| 63 |
|
unsigned magic; |
| 64 |
5151 |
#define VAI_Q_MAGIC 0x573e27eb |
| 65 |
|
unsigned flags; |
| 66 |
9690 |
#define VAI_QF_INQUEUE (1U<<0) |
| 67 |
|
VSLIST_ENTRY(vai_qe) list; |
| 68 |
|
vai_notify_cb *cb; |
| 69 |
|
vai_hdl hdl; |
| 70 |
|
void *priv; |
| 71 |
|
}; |
| 72 |
|
|
| 73 |
7327 |
#define VAI_ASSERT_LEASE(x) AZ((x) & 0x7) |
| 74 |
|
|
| 75 |
|
/* |
| 76 |
|
* start an iteration. the ws can we used (reserved) by storage |
| 77 |
|
* the void * will be passed as the second argument to vai_notify_cb |
| 78 |
|
*/ |
| 79 |
|
typedef vai_hdl vai_init_f(struct worker *, struct objcore *, struct ws *, |
| 80 |
|
vai_notify_cb *, void *); |
| 81 |
|
|
| 82 |
|
/* |
| 83 |
|
* lease io vectors from storage |
| 84 |
|
* |
| 85 |
|
* vai_hdl is from vai_init_f |
| 86 |
|
* the vscarab is provided by the caller to return leases |
| 87 |
|
* |
| 88 |
|
* return: |
| 89 |
|
* -EAGAIN: nothing available at the moment, storage will notify, no use to |
| 90 |
|
* call again until notification |
| 91 |
|
* -ENOBUFS: caller needs to return leases, storage will notify |
| 92 |
|
* -EPIPE: BOS_FAILED for busy object |
| 93 |
|
* -(errno): other problem, fatal |
| 94 |
|
* >= 0: number of viovs added |
| 95 |
|
*/ |
| 96 |
|
typedef int vai_lease_f(struct worker *, vai_hdl, struct vscarab *); |
| 97 |
|
|
| 98 |
|
/* |
| 99 |
|
* get io vectors with temporary buffers from storage |
| 100 |
|
* |
| 101 |
|
* vai_hdl is from vai_init_f |
| 102 |
|
* the vscarab needs to be initialized with the number of requested elements |
| 103 |
|
* and each iov.iov_len contings the requested sizes. all iov_base need to be |
| 104 |
|
* zero. |
| 105 |
|
* |
| 106 |
|
* after return, the vscarab can be smaller than requested if only some |
| 107 |
|
* allocation requests could be fulfilled |
| 108 |
|
* |
| 109 |
|
* return: |
| 110 |
|
* -EAGAIN: allocation can not be fulfilled immediately, storage will notify, |
| 111 |
|
* no use to call again until notification |
| 112 |
|
* -(errno): other problem, fatal |
| 113 |
|
* n: n > 0, number of viovs filled |
| 114 |
|
*/ |
| 115 |
|
typedef int vai_buffer_f(struct worker *, vai_hdl, struct vscarab *); |
| 116 |
|
|
| 117 |
|
/* |
| 118 |
|
* return leases from vai_lease_f or vai_buffer_f |
| 119 |
|
*/ |
| 120 |
|
typedef void vai_return_f(struct worker *, vai_hdl, struct vscaret *); |
| 121 |
|
|
| 122 |
|
/* |
| 123 |
|
* call the notify function (from a VDP) |
| 124 |
|
*/ |
| 125 |
|
typedef void vai_notify_f(struct worker *, vai_hdl); |
| 126 |
|
|
| 127 |
|
/* |
| 128 |
|
* finish iteration, vai_return_f must have been called on all leases |
| 129 |
|
*/ |
| 130 |
|
typedef void vai_fini_f(struct worker *, vai_hdl *); |
| 131 |
|
|
| 132 |
|
/* |
| 133 |
|
* vai_hdl must start with this preamble such that when cast to it, cache_obj.c |
| 134 |
|
* has access to the methods. |
| 135 |
|
* |
| 136 |
|
* The first magic is owned by storage, the second magic is owned by cache_obj.c |
| 137 |
|
* and must be initialized to VAI_HDL_PREAMBLE_MAGIC2 |
| 138 |
|
* |
| 139 |
|
*/ |
| 140 |
|
|
| 141 |
|
//lint -esym(768, vai_hdl_preamble::reserve) |
| 142 |
|
struct vai_hdl_preamble { |
| 143 |
|
unsigned magic; // owned by storage |
| 144 |
|
unsigned magic2; |
| 145 |
7128 |
#define VAI_HDL_PREAMBLE_MAGIC2 0x7a15d162 |
| 146 |
|
vai_lease_f *vai_lease; |
| 147 |
|
vai_buffer_f *vai_buffer; |
| 148 |
|
vai_return_f *vai_return; |
| 149 |
|
vai_notify_f *vai_notify; |
| 150 |
|
uintptr_t reserve[3]; // abi fwd compat |
| 151 |
|
vai_fini_f *vai_fini; |
| 152 |
|
}; |
| 153 |
|
|
| 154 |
7128 |
#define INIT_VAI_HDL(to, x) do { \ |
| 155 |
7128 |
(void)memset(to, 0, sizeof *(to)); \ |
| 156 |
7128 |
(to)->preamble.magic = (x); \ |
| 157 |
7128 |
(to)->preamble.magic2 = VAI_HDL_PREAMBLE_MAGIC2; \ |
| 158 |
7128 |
} while (0) |
| 159 |
|
|
| 160 |
33338 |
#define CHECK_VAI_HDL(obj, x) do { \ |
| 161 |
33338 |
assert(obj->preamble.magic == (x)); \ |
| 162 |
33338 |
assert(obj->preamble.magic2 == VAI_HDL_PREAMBLE_MAGIC2);\ |
| 163 |
33338 |
} while (0) |
| 164 |
|
|
| 165 |
33338 |
#define CAST_VAI_HDL_NOTNULL(obj, ptr, x) do { \ |
| 166 |
33338 |
AN(ptr); \ |
| 167 |
33338 |
(obj) = (ptr); \ |
| 168 |
33338 |
CHECK_VAI_HDL(obj, x); \ |
| 169 |
33338 |
} while (0) |
| 170 |
|
|
| 171 |
|
struct obj_methods { |
| 172 |
|
/* required */ |
| 173 |
|
objfree_f *objfree; |
| 174 |
|
objiterator_f *objiterator; |
| 175 |
|
objgetspace_f *objgetspace; // XXX add variant for synth |
| 176 |
|
objextend_f *objextend; |
| 177 |
|
objgetattr_f *objgetattr; |
| 178 |
|
objsetattr_f *objsetattr; |
| 179 |
|
/* optional */ |
| 180 |
|
objtrimstore_f *objtrimstore; |
| 181 |
|
objbocdone_f *objbocdone; |
| 182 |
|
objslim_f *objslim; |
| 183 |
|
objtouch_f *objtouch; |
| 184 |
|
objsetstate_f *objsetstate; |
| 185 |
|
/* async iteration (VAI) */ |
| 186 |
|
vai_init_f *vai_init; |
| 187 |
|
}; |