Code Coverage: vinyl-cache/include/vapi/vsl_int.h
 
82217aa4fc7094b3610340078afaf78cd95a8ec9
 
0
/*-
1
 * Copyright (c) 2006 Verdens Gang AS
2
 * Copyright (c) 2006-2015 Varnish Software AS
3
 * All rights reserved.
4
 *
5
 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
6
 * Author: Martin Blix Grydeland <martin@varnish-software.com>
7
 *
8
 * SPDX-License-Identifier: BSD-2-Clause
9
 *
10
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions
12
 * are met:
13
 * 1. Redistributions of source code must retain the above copyright
14
 *    notice, this list of conditions and the following disclaimer.
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in the
17
 *    documentation and/or other materials provided with the distribution.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
23
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29
 * SUCH DAMAGE.
30
 *
31
 * Define the layout of the shared memory log segment.
32
 *
33
 * This file SHALL only be included from:
34
 *      bin/vinyld/cache/cache.h
35
 *      include/vsl_priv.h
36
 *      include/vapi/vsl.h
37
 *
38
 */
39
40
#ifndef VAPI_VSL_INT_H_INCLUDED
41
#define VAPI_VSL_INT_H_INCLUDED
42
43 8194
#define VSL_CLASS               "Log"
44 2490097
#define VSL_SEGMENTS            8U      // power of two
45
46
/*
47
 * Shared memory log format
48
 *
49
 * The log member points to an array of 32bit unsigned integers containing
50
 * log records.
51
 *
52
 * Each logrecord consist of four or more 32 bit words, stored in
53
 * native endianness:
54
 *
55
 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56
 *   |     TAG       |  unused   |ver|          length               |
57
 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
58
 *   |                   32 lower bits of VXID                       |
59
 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60
 *   |B|C|    unused (zero)    |        19 upper bits of VXID        |
61
 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
62
 *   | content ... (NUL-terminated)                                  |
63
 *   +-+-+                                                       +-+-+
64
 *   | ...                                                           |
65
 *   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66
 *
67
 * Logrecords are NUL-terminated so that string functions can be run
68
 * directly on the shmlog data.
69
 *
70
 * Notice that the constants in these macros cannot be changed without
71
 * changing corresponding magic numbers in vinyld/cache/cache_shmlog.c
72
 */
73
74 396657
#define VSL_CLIENTMARKER        (1ULL<<62)
75 147919
#define VSL_BACKENDMARKER       (1ULL<<63)
76 503312
#define VSL_IDENTMASK           ((1ULL<<51)-1)
77
78 388935
#define VSL_LENMASK             0xffff
79
#define VSL_VERMASK             0x3
80 355133
#define VSL_VERSHIFT            16
81 355133
#define VSL_IDMASK              0xff
82 1759899
#define VSL_IDSHIFT             24
83 2963619
#define VSL_OVERHEAD            3U
84
#define VSL_VERSION_2           0x0
85 355133
#define VSL_VERSION_3           0x1
86 2043107
#define VSL_WORDS(len)          (((len) + 3) / 4)
87 105635
#define VSL_BYTES(words)        ((words) * 4)
88 2027889
#define VSL_END(ptr, len)       ((ptr) + VSL_OVERHEAD + VSL_WORDS(len))
89 882284
#define VSL_NEXT(ptr)           VSL_END(ptr, VSL_LEN(ptr))
90 388935
#define VSL_LEN(ptr)            ((uint16_t)((ptr)[0] & VSL_LENMASK))
91
#define VSL_VER(ptr)            (((ptr)[0] >> VSL_VERSHIFT) & VSL_VERMASK)
92 1367209
#define VSL_TAG(ptr)            ((enum VSL_tag_e)((ptr)[0] >> VSL_IDSHIFT))
93 458013
#define VSL_ID64(ptr)           (((uint64_t)((ptr)[2])<<32) | ((ptr)[1]))
94 458013
#define VSL_ID(ptr)             (VSL_ID64(ptr) & VSL_IDENTMASK)
95 385318
#define VSL_CLIENT(ptr)         (((ptr)[2]) & (VSL_CLIENTMARKER >> 32))
96 144877
#define VSL_BACKEND(ptr)        (((ptr)[2]) & (VSL_BACKENDMARKER >> 32))
97 372627
#define VSL_DATA(ptr)           ((char*)((ptr)+VSL_OVERHEAD))
98 393200
#define VSL_CDATA(ptr)          ((const char*)((ptr)+VSL_OVERHEAD))
99
#define VSL_BATCHLEN(ptr)       ((ptr)[1])
100 4402
#define VSL_BATCHID(ptr)        (VSL_ID((ptr) + VSL_OVERHEAD))
101
102 917132
#define VSL_ENDMARKER   (((uint32_t)SLT__Reserved << 24) | 0x454545) /* "EEE" */
103 763980
#define VSL_WRAPMARKER  (((uint32_t)SLT__Reserved << 24) | 0x575757) /* "WWW" */
104
105
/*
106
 * The identifiers in shmlogtag are "SLT_" + VSL tag.  A script may be run
107
 * on this file to extract the table rather than handcode it
108
 */
109 117388
#define SLT__MAX 256
110
enum VSL_tag_e {
111
        SLT__Bogus = 0,
112
#define SLTM(foo,flags,sdesc,ldesc)     SLT_##foo,
113
#include "tbl/vsl_tags.h"
114
        SLT__Reserved = 254,
115
        SLT__Batch = 255
116
};
117
118
/* VSL tag flags */
119
#define SLT_F_UNUSED            (1 << 0)
120 353278
#define SLT_F_UNSAFE            (1 << 1)
121 354711
#define SLT_F_BINARY            (1 << 2)
122
123
#endif /* VAPI_VSL_INT_H_INCLUDED */