| | vinyl-cache/bin/vinyld/storage/storage_debug.c |
| 0 |
|
/*- |
| 1 |
|
* Copyright 2021,2023 UPLEX - Nils Goroll Systemoptimierung |
| 2 |
|
* All rights reserved. |
| 3 |
|
* |
| 4 |
|
* Author: Nils Goroll <nils.goroll@uplex.de> |
| 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 |
|
* debug helper storage based on malloc |
| 30 |
|
*/ |
| 31 |
|
|
| 32 |
|
#include "config.h" |
| 33 |
|
|
| 34 |
|
#include "cache/cache_int.h" |
| 35 |
|
#include "cache/cache_obj.h" |
| 36 |
|
#include "common/heritage.h" |
| 37 |
|
|
| 38 |
|
#include <stdio.h> |
| 39 |
|
#include <stdlib.h> |
| 40 |
|
|
| 41 |
|
#include "storage/storage.h" |
| 42 |
|
|
| 43 |
|
#include "vtim.h" |
| 44 |
|
#include "vnum.h" |
| 45 |
|
|
| 46 |
|
static vtim_dur dopen = 0.0; |
| 47 |
|
static unsigned count = 0; |
| 48 |
|
|
| 49 |
|
#define dur_arg(a, s, d) \ |
| 50 |
|
(! vstrncmp((a), (s), vstrlen(s)) \ |
| 51 |
|
&& (d = VNUM_duration(a + vstrlen(s))) != nan("")) |
| 52 |
|
|
| 53 |
|
static void |
| 54 |
0 |
smd_close(struct stevedore *stv, int warn) |
| 55 |
|
{ |
| 56 |
|
|
| 57 |
0 |
if (warn) |
| 58 |
0 |
return; |
| 59 |
0 |
LRU_Free(&stv->lru); |
| 60 |
0 |
} |
| 61 |
|
|
| 62 |
|
static void |
| 63 |
42 |
smd_open(struct stevedore *stv) |
| 64 |
|
{ |
| 65 |
|
|
| 66 |
42 |
sma_stevedore.open(stv); |
| 67 |
42 |
fprintf(stderr, "-sdebug open delay %fs\n", dopen); |
| 68 |
42 |
AN(dopen); |
| 69 |
42 |
VTIM_sleep(dopen); |
| 70 |
42 |
stv->lru = LRU_Alloc(); |
| 71 |
42 |
} |
| 72 |
|
|
| 73 |
|
static void v_matchproto_(storage_init_f) |
| 74 |
77 |
smd_init(struct stevedore *parent, int aac, char * const *aav) |
| 75 |
|
{ |
| 76 |
|
const char *ident; |
| 77 |
77 |
int i, ac = 0; |
| 78 |
|
size_t nac; |
| 79 |
77 |
vtim_dur d, dinit = 0.0; |
| 80 |
|
char **av; //lint !e429 |
| 81 |
|
char *a; |
| 82 |
|
|
| 83 |
77 |
if (count++ > 0) |
| 84 |
0 |
ARGV_ERR("Only one -s%s instance supported\n", smd_stevedore.name); |
| 85 |
|
|
| 86 |
77 |
ident = parent->ident; |
| 87 |
77 |
vmemcpy(parent, &sma_stevedore, sizeof *parent); |
| 88 |
77 |
parent->ident = ident; |
| 89 |
77 |
parent->name = smd_stevedore.name; |
| 90 |
|
|
| 91 |
77 |
assert(aac >= 0); |
| 92 |
77 |
nac = aac; |
| 93 |
77 |
nac++; |
| 94 |
77 |
av = calloc(nac, sizeof *av); |
| 95 |
77 |
AN(av); |
| 96 |
154 |
for (i = 0; i < aac; i++) { |
| 97 |
77 |
a = aav[i]; |
| 98 |
77 |
if (a != NULL) { |
| 99 |
77 |
if (dur_arg(a, "dinit=", d)) { |
| 100 |
35 |
dinit = d; |
| 101 |
35 |
continue; |
| 102 |
|
} |
| 103 |
42 |
if (dur_arg(a, "dopen=", d)) { |
| 104 |
42 |
dopen = d; |
| 105 |
42 |
continue; |
| 106 |
|
} |
| 107 |
0 |
} |
| 108 |
0 |
av[ac] = a; |
| 109 |
0 |
ac++; |
| 110 |
0 |
} |
| 111 |
77 |
assert(ac >= 0); |
| 112 |
77 |
assert(ac < (int)nac); |
| 113 |
77 |
AZ(av[ac]); |
| 114 |
|
|
| 115 |
77 |
sma_stevedore.init(parent, ac, av); |
| 116 |
77 |
free(av); |
| 117 |
77 |
if (dinit > 0.0) { |
| 118 |
35 |
fprintf(stderr, "-sdebug init delay %fs\n", dinit); |
| 119 |
35 |
VTIM_sleep(dinit); |
| 120 |
35 |
} |
| 121 |
77 |
if (dopen > 0.0) { |
| 122 |
42 |
parent->open = smd_open; |
| 123 |
42 |
parent->close = smd_close; |
| 124 |
42 |
fprintf(stderr, "-sdebug open delay in init %fs\n", dopen); |
| 125 |
42 |
} |
| 126 |
77 |
} |
| 127 |
|
|
| 128 |
|
|
| 129 |
|
const struct stevedore smd_stevedore = { |
| 130 |
|
.magic = STEVEDORE_MAGIC, |
| 131 |
|
.name = "debug", |
| 132 |
|
.init = smd_init, |
| 133 |
|
// other callbacks initialized in smd_init() |
| 134 |
|
}; |