Code Coverage: vinyl-cache/vmod/vmod_vtc_storage.c
 
82217aa4fc7094b3610340078afaf78cd95a8ec9
 
0
/*-
1
 * Copyright 2021,2023,2026 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
 * interpose storage methods for testing purposes
30
 */
31
32
#include "config.h"
33
34
#include <stdlib.h>
35
36
#include "cache/cache_int.h"
37
#include "cache/cache_obj.h"
38
#include "storage/storage.h"
39
40
#include "vcc_vtc_if.h"
41
42
/* ----------------------------------------
43
 * stvi
44
 */
45
// override parameters
46
struct stvi_param {
47
        ssize_t                 maxspace;
48
        ssize_t                 frag;
49
};
50
51
// created once, only freed when the vmod goes cold
52
// i for interposer
53
struct stvi {
54
        unsigned                        magic;
55
#define STVI_MAGIC                      0x85ff17c0
56
        VRBT_ENTRY(stvi)                tree;
57
        uintptr_t                       stv;
58
59
        // original contents, copied on stvi creation
60
        struct stevedore                stv_save;
61
        struct obj_methods              om_save;
62
        // original methods pointer, for revert()
63
        const struct obj_methods        *om;
64
        void                            *freeme;
65
66
        struct stvi_param               param;
67
};
68
69
static inline int
70
stvi_cmp(const struct stvi *s1, const struct stvi *s2)
71 122
{
72 122
        if (s1->stv < s2->stv)
73 0
                return (-1);
74 122
        if (s1->stv > s2->stv)
75 12
                return (1);
76 110
        return (0);
77 122
}
78
79
VRBT_HEAD(stvi_head, stvi);
80 0
VRBT_GENERATE_REMOVE_COLOR(stvi_head, stvi, tree, static)
81 0
VRBT_GENERATE_REMOVE(stvi_head, stvi, tree, static)
82 124
VRBT_GENERATE_FIND(stvi_head, stvi, tree, stvi_cmp, static)
83 2
VRBT_GENERATE_INSERT_COLOR(stvi_head, stvi, tree, static)
84 14
VRBT_GENERATE_INSERT_FINISH(stvi_head, stvi, tree, static)
85 14
VRBT_GENERATE_INSERT(stvi_head, stvi, tree, stvi_cmp, static)
86
VRBT_GENERATE_NEXT(stvi_head, stvi, tree, static)
87 1
VRBT_GENERATE_MINMAX(stvi_head, stvi, tree, static)
88
89
static struct stvi_head stvi_head = VRBT_INITIALIZER(stvi);
90
static pthread_mutex_t stvi_mtx = PTHREAD_MUTEX_INITIALIZER;
91
92
// only return if exists
93
static struct stvi *
94
stvi_find(VCL_STEVEDORE stv)
95 124
{
96 124
        struct stvi needle;
97 124
        struct stvi *si;
98
99 124
        CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
100 124
        needle.stv = (uintptr_t)TRUST_ME(stv);
101
102 124
        PTOK(pthread_mutex_lock(&stvi_mtx));
103 124
        si = VRBT_FIND(stvi_head, &stvi_head, &needle);
104 124
        PTOK(pthread_mutex_unlock(&stvi_mtx));
105
106 124
        CHECK_OBJ_ORNULL(si, STVI_MAGIC);
107 124
        return (si);
108 124
}
109
110
// create if does not exist
111
static struct stvi *
112
stvi_get(VCL_STEVEDORE stv)
113 120
{
114 120
        struct stevedore *wstv;
115 120
        struct obj_methods *wom;
116 120
        struct stvi *si, *old;
117
118 120
        si = stvi_find(stv);
119 120
        if (si)
120 106
                return (si);
121
122 14
        ALLOC_OBJ(si, STVI_MAGIC);
123 14
        AN(si);
124 14
        si->stv = (uintptr_t)TRUST_ME(stv);
125
126 14
        PTOK(pthread_mutex_lock(&stvi_mtx));
127 14
        old = VRBT_INSERT(stvi_head, &stvi_head, si);
128
        // copy under the mutex to make sure that only the first _get() copies
129 14
        if (old == NULL) {
130 14
                si->stv_save = *stv;
131 14
                si->om_save = *stv->methods;
132 14
        }
133 14
        PTOK(pthread_mutex_unlock(&stvi_mtx));
134
135 14
        if (old) {
136 0
                FREE_OBJ(si);
137 0
                CHECK_OBJ(old, STVI_MAGIC);
138 0
                return (old);
139 0
        }
140
141
        // ensure methods are writable
142 14
        si->om = stv->methods;
143 14
        wom = malloc(sizeof *wom);
144 14
        AN(wom);
145 14
        *wom = *stv->methods;
146
147 14
        wstv = TRUST_ME(stv);
148 14
        wstv->methods = wom;
149
150 14
        return (si);
151 14
}
152
153
/* ----------------------------------------
154
 * obji
155
 */
156
// freed via objfree
157
struct obji {
158
        unsigned                magic;
159
#define OBJI_MAGIC              0x65fc7452
160
        VRBT_ENTRY(obji)        tree;
161
        uintptr_t               oc;
162
163
        // remaining maxspace
164
        ssize_t                 canalloc;
165
};
166
167
static inline int
168
obji_cmp(const struct obji *oi1, const struct obji *oi2)
169 17
{
170 17
        if (oi1->oc < oi2->oc)
171 0
                return (-1);
172 17
        if (oi1->oc > oi2->oc)
173 0
                return (1);
174 17
        return (0);
175 17
}
176
177
VRBT_HEAD(obji_head, obji);
178 0
VRBT_GENERATE_REMOVE_COLOR(obji_head, obji, tree, static)
179 4
VRBT_GENERATE_REMOVE(obji_head, obji, tree, static)
180 21
VRBT_GENERATE_FIND(obji_head, obji, tree, obji_cmp, static)
181 0
VRBT_GENERATE_INSERT_COLOR(obji_head, obji, tree, static)
182 4
VRBT_GENERATE_INSERT_FINISH(obji_head, obji, tree, static)
183 4
VRBT_GENERATE_INSERT(obji_head, obji, tree, obji_cmp, static)
184
//VRBT_GENERATE_NEXT(obji_head, obji, tree, static)
185
//VRBT_GENERATE_MINMAX(obji_head, obji, tree, static)
186
187
static struct obji_head obji_head = VRBT_INITIALIZER(obji);
188
static pthread_mutex_t obji_mtx = PTHREAD_MUTEX_INITIALIZER;
189
190
// only return if exists
191
static struct obji *
192
obji_find(const struct objcore *oc)
193 17
{
194 17
        struct obji needle;
195 17
        struct obji *oi;
196
197 17
        needle.oc = (uintptr_t)oc;
198
199 17
        PTOK(pthread_mutex_lock(&obji_mtx));
200 17
        oi = VRBT_FIND(obji_head, &obji_head, &needle);
201 17
        PTOK(pthread_mutex_unlock(&obji_mtx));
202
203 17
        CHECK_OBJ_ORNULL(oi, OBJI_MAGIC);
204 17
        return (oi);
205 17
}
206
207
// creat if does not exist
208
static struct obji *
209
obji_get(const struct objcore *oc)
210 17
{
211 17
        struct obji *oi, *old;
212
213 17
        oi = obji_find(oc);
214 17
        if (oi)
215 13
                return (oi);
216
217 4
        ALLOC_OBJ(oi, OBJI_MAGIC);
218 4
        AN(oi);
219 4
        oi->oc = (uintptr_t)TRUST_ME(oc);
220
221 4
        PTOK(pthread_mutex_lock(&obji_mtx));
222 4
        old = VRBT_INSERT(obji_head, &obji_head, oi);
223 4
        PTOK(pthread_mutex_unlock(&obji_mtx));
224
225 4
        if (old) {
226 0
                FREE_OBJ(oi);
227 0
                CHECK_OBJ(old, OBJI_MAGIC);
228 0
                return (old);
229 0
        }
230 4
        return (oi);
231 4
}
232
233
static void
234
obji_free(const struct objcore *oc)
235 4
{
236 4
        struct obji needle;
237 4
        struct obji *oi;
238
239 4
        needle.oc = (uintptr_t)oc;
240
241 4
        PTOK(pthread_mutex_lock(&obji_mtx));
242 4
        oi = VRBT_FIND(obji_head, &obji_head, &needle);
243 4
        if (oi)
244 4
                VRBT_REMOVE(obji_head, &obji_head, oi);
245 4
        PTOK(pthread_mutex_unlock(&obji_mtx));
246
247 4
        if (oi == NULL)
248 0
                return;
249
250 4
        FREE_OBJ(oi);
251 4
}
252
253
// copy all stv pointers we are modifying
254
static void
255
stvcpy(struct stevedore *dst, const struct stevedore *src)
256 14
{
257
258 14
        CHECK_OBJ_NOTNULL(dst, STEVEDORE_MAGIC);
259 14
        CHECK_OBJ_NOTNULL(src, STEVEDORE_MAGIC);
260 14
        dst->allocobj = src->allocobj;
261 14
        dst->allocbuf = src->allocbuf;
262 14
}
263
264
// copy all om ponters we are modifying
265
static void
266
omcpy(struct obj_methods *dst, const struct obj_methods *src)
267 14
{
268
269 14
        dst->objfree = src->objfree;
270 14
        dst->objgetspace = src->objgetspace;
271 14
        dst->objextend = src->objextend;
272 14
}
273
274
// whenever we hack the stv & om pointers, we first
275
// restore the original state
276
#define REVERT(si, stv, wstv, wom)              \
277 14
        wstv = TRUST_ME(stv);                   \
278 14
        stvcpy(wstv, &si->stv_save);            \
279 14
        wom = TRUST_ME(stv->methods);           \
280 14
        omcpy(wom, &si->om_save)
281
282
#define PATCH_BEGIN(si, stv, wstv, wom)         \
283 14
        PTOK(pthread_mutex_lock(&stvi_mtx));    \
284 14
        REVERT(si, stv, wstv, wom)
285
286
#define PATCH_END()                             \
287 14
        PTOK(pthread_mutex_unlock(&stvi_mtx))
288
289
// when the last vcl using us goes cold, remove ourselves from all stevedores
290
// and objects. This is a bit racy, because the updated method pointers do not
291
// get visible immediately, and the methods assert that their stvi exists. Also,
292
// we had replaced obj_method with a malloc'ed copy, so we need to wait until we
293
// can assume safely that no code is using that pointer any more.
294
//
295
// Hence, do this in passes: First, restore all the stv methods, then destroy
296
// all the objis and finally destroy the stvis.
297
static void
298
revert(void)
299 1
{
300 1
        struct stevedore *stv;
301 1
        struct obji *oi;
302 1
        struct stvi *si;
303 1
        int check = 0;
304
305
        // pass 1: restore all pointers
306 1
        PTOK(pthread_mutex_lock(&stvi_mtx));
307 1
        VRBT_FOREACH(si, stvi_head, &stvi_head) {
308 0
                CHECK_OBJ(si, STVI_MAGIC);
309 0
                check++;
310 0
                CAST_OBJ_NOTNULL(stv, (void *)si->stv, STEVEDORE_MAGIC);
311 0
                stvcpy(stv, &si->stv_save);
312 0
                AZ(si->freeme);
313 0
                si->freeme = TRUST_ME(stv->methods);
314 0
                AN(si->om);
315 0
                stv->methods = si->om;
316 0
        }
317 1
        PTOK(pthread_mutex_unlock(&stvi_mtx));
318
319 1
        if (check > 0)
320 0
                sleep (1);
321
322
        // pass 2: free all objis: No interposer callback should run any more
323 1
        PTOK(pthread_mutex_lock(&obji_mtx));
324 1
        while ((oi = VRBT_ROOT(&obji_head)) != NULL) {
325 0
                CHECK_OBJ(oi, OBJI_MAGIC);
326 0
                VRBT_REMOVE(obji_head, &obji_head, oi);
327 0
                FREE_OBJ(oi);
328 0
        }
329 1
        PTOK(pthread_mutex_unlock(&obji_mtx));
330
331
        // pass 3: free
332 1
        PTOK(pthread_mutex_lock(&stvi_mtx));
333 1
        while ((si = VRBT_ROOT(&stvi_head)) != NULL) {
334 0
                CHECK_OBJ(si, STVI_MAGIC);
335 0
                check--;
336 0
                VRBT_REMOVE(stvi_head, &stvi_head, si);
337 0
                AN(si->freeme);
338 0
                free(si->freeme);
339 0
                FREE_OBJ(si);
340 0
        }
341 1
        PTOK(pthread_mutex_unlock(&stvi_mtx));
342 1
        assert(check == 0);
343 1
}
344
345
static unsigned ref = 0;
346
347
int v_matchproto_(vmod_event_f)
348
vmod_vcl_event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
349 214
{
350
351 214
        (void)ctx;
352 214
        (void)priv;
353
354 214
        switch (e) {
355 103
        case VCL_EVENT_WARM:
356 103
                ref++;
357 103
                return (0);
358 2
        case VCL_EVENT_COLD:
359 2
                AN(ref);
360 2
                if (--ref == 0)
361 1
                        revert();
362 2
                return (0);
363 109
        default:
364 109
                return (0);
365 214
        }
366 214
}
367
368
VCL_VOID
369
vmod_storage_revert(VRT_CTX, VCL_STEVEDORE stv)
370 0
{
371 0
        struct stevedore *wstv;
372 0
        struct obj_methods *wom;
373 0
        struct stvi *si;
374
375 0
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
376 0
        CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
377
378 0
        si = stvi_find(stv);
379 0
        if (si == NULL)
380 0
                return;
381
382 0
        PATCH_BEGIN(si, stv, wstv, wom);
383 0
        PATCH_END();
384 0
}
385
386
/* ----------------------------------------
387
 * storage_full
388
 */
389
390
static int v_matchproto_(objgetspace_f)
391
vtcstv_full_getspace(struct worker *wrk, struct objcore *oc, ssize_t *sz,
392
    uint8_t **ptr)
393 0
{
394 0
        (void)wrk;
395 0
        (void)oc;
396 0
        (void)sz;
397 0
        (void)ptr;
398
399 0
        return (0);
400 0
}
401
402
static int v_matchproto_(storage_allocobj_f)
403
vtcstv_full_allocobj(struct worker *wrk, const struct stevedore *stv,
404
    struct objcore *oc, unsigned len)
405 1
{
406 1
        (void)wrk;
407 1
        (void)stv;
408 1
        (void)oc;
409 1
        (void)len;
410
411 1
        return (0);
412 1
}
413
414
static void * v_matchproto_(storage_allocbuf_t)
415
vtcstv_full_allocbuf(struct worker *wrk, const struct stevedore *stv, size_t size,
416
    uintptr_t *ppriv)
417 0
{
418 0
        (void)wrk;
419 0
        (void)stv;
420 0
        (void)size;
421 0
        (void)ppriv;
422 0
        return (NULL);
423 0
}
424
425
VCL_VOID
426
vmod_storage_full(VRT_CTX, VCL_STEVEDORE stv)
427 1
{
428 1
        struct stevedore *wstv;
429 1
        struct obj_methods *wom;
430 1
        struct stvi *si;
431
432 1
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
433 1
        CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
434
435 1
        si = stvi_get(stv);
436 1
        AN(si);
437
438 2
        PATCH_BEGIN(si, stv, wstv, wom);
439 2
        wom->objgetspace = vtcstv_full_getspace;
440 2
        wstv->allocobj = vtcstv_full_allocobj;
441 2
        wstv->allocbuf = vtcstv_full_allocbuf;
442 2
        PATCH_END();
443 2
}
444
445
/* ----------------------------------------
446
 * storage_lessspace
447
 */
448
449
/* returns one byte less than requested */
450
static int v_matchproto_(objgetspace_f)
451
vtcstv_lessspace_getspace(struct worker *wrk, struct objcore *oc, ssize_t *sz,
452
    uint8_t **ptr)
453 36
{
454 36
        struct stvi *si;
455 36
        ssize_t less;
456
457 36
        CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
458 36
        si = stvi_get(oc->stobj->stevedore);
459 36
        AN(si);
460
461 36
        AN(sz);
462 36
        less = (*sz > 2) ? *sz - 1 : *sz;
463 36
        VSLb(wrk->vsl, SLT_Debug, "vtc.storage_lessspace: want %zd give %zd",
464 36
            *sz, less);
465 36
        *sz = less;
466 36
        return (si->om_save.objgetspace(wrk, oc, sz, ptr));
467 36
}
468
469
VCL_VOID
470
vmod_storage_lessspace(VRT_CTX, VCL_STEVEDORE stv)
471 3
{
472 3
        struct stevedore *wstv;
473 3
        struct obj_methods *wom;
474 3
        struct stvi *si;
475
476 3
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
477 3
        CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
478
479 3
        si = stvi_get(stv);
480 3
        AN(si);
481
482 6
        PATCH_BEGIN(si, stv, wstv, wom);
483 6
        wom->objgetspace = vtcstv_lessspace_getspace;
484 6
        PATCH_END();
485 6
}
486
487
/* ----------------------------------------
488
 * storage_maxspace
489
 */
490
491
static void v_matchproto_(objfree_f)
492
vtcstv_obji_objfree(struct worker *wrk, struct objcore *oc)
493 4
{
494 4
        struct stvi *si;
495
496 4
        CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
497 4
        si = stvi_find(oc->stobj->stevedore);
498 4
        AN(si);
499
500 4
        obji_free(oc);
501 4
        si->om_save.objfree(wrk, oc);
502 4
}
503
504
static int v_matchproto_(storage_allocobj_f)
505
vtcstv_maxspace_allocobj(struct worker *wrk, const struct stevedore *stv,
506
    struct objcore *oc, unsigned len)
507 4
{
508 4
        struct stvi *si;
509 4
        struct obji *oi;
510
511 4
        CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
512 4
        si = stvi_get(stv);
513 4
        AN(si);
514
515 4
        oi = obji_get(oc);
516 4
        AN(oi);
517 4
        oi->canalloc = si->param.maxspace;
518
519 4
        return (si->stv_save.allocobj(wrk, stv, oc, len));
520 4
}
521
522
static int v_matchproto_(objgetspace_f)
523
vtcstv_maxspace_getspace(struct worker *wrk, struct objcore *oc, ssize_t *sz,
524
    uint8_t **ptr)
525 8
{
526 8
        struct stvi *si;
527 8
        struct obji *oi;
528 8
        int r;
529
530 8
        AN(sz);
531
532 8
        si = stvi_get(oc->stobj->stevedore);
533 8
        AN(si);
534 8
        oi = obji_get(oc);
535 8
        AN(oi);
536
537 8
        VSLb(wrk->vsl, SLT_Debug, "vtc.storage_maxspace: want %zd canalloc %zd",
538 8
            *sz, oi->canalloc);
539
540 8
        assert(oi->canalloc >= 0);
541 8
        if (oi->canalloc == 0)
542 3
                return (0);
543
544 5
        if (*sz == 0)
545 0
                *sz = oi->canalloc;
546 5
        else
547 5
                *sz = vmin_t(ssize_t, *sz, oi->canalloc);
548
549 5
        r = si->om_save.objgetspace(wrk, oc, sz, ptr);
550 5
        return (r);
551 8
}
552
553
static void v_matchproto_(objextend_f)
554
vtcstv_maxspace_extend(struct worker *wrk, struct objcore *oc, ssize_t l)
555 5
{
556 5
        struct stvi *si;
557 5
        struct obji *oi;
558
559 5
        si = stvi_get(oc->stobj->stevedore);
560 5
        AN(si);
561 5
        oi = obji_get(oc);
562 5
        AN(oi);
563
564 5
        VSLb(wrk->vsl, SLT_Debug, "vtc.storage_maxspace: extend %zd canalloc %zd",
565 5
            l, oi->canalloc);
566
567 5
        if (l > oi->canalloc)
568 0
                oi->canalloc = 0;
569 5
        else
570 5
                oi->canalloc -= l;
571
572 5
        assert(l > 0);
573 5
        oc->stobj->priv2 += (uint64_t)l;
574 5
        si->om_save.objextend(wrk, oc, l);
575 5
}
576
577
VCL_VOID
578
vmod_storage_maxspace(VRT_CTX, VCL_STEVEDORE stv, VCL_BYTES b)
579 4
{
580 4
        struct stevedore *wstv;
581 4
        struct obj_methods *wom;
582 4
        struct stvi *si;
583
584 4
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
585 4
        CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
586
587 4
        if (b <= 0) {
588 1
                VRT_fail(ctx, "storage_maxspace: BYTES must be positive");
589 1
                return;
590 1
        }
591
592 3
        si = stvi_get(stv);
593 3
        AN(si);
594 3
        si->param.maxspace = b;
595
596 3
        PATCH_BEGIN(si, stv, wstv, wom);
597 3
        wom->objfree = vtcstv_obji_objfree;
598 3
        wom->objgetspace = vtcstv_maxspace_getspace;
599 3
        wom->objextend = vtcstv_maxspace_extend;
600 3
        wstv->allocobj = vtcstv_maxspace_allocobj;
601 3
        PATCH_END();
602 3
}
603
604
/* ----------------------------------------
605
 * storage_frag
606
 */
607
static int v_matchproto_(objgetspace_f)
608
vtcstv_frag_getspace(struct worker *wrk, struct objcore *oc, ssize_t *sz,
609
    uint8_t **ptr)
610 53
{
611 53
        struct stvi *si;
612 53
        int r;
613
614 53
        AN(sz);
615
616 53
        si = stvi_get(oc->stobj->stevedore);
617 53
        AN(si);
618
619 53
        VSLb(wrk->vsl, SLT_Debug, "vtc.storage_frag: want %zd frag %zd",
620 53
            *sz, si->param.frag);
621
622 53
        *sz = si->param.frag;
623
624 53
        r = si->om_save.objgetspace(wrk, oc, sz, ptr);
625 53
        return (r);
626 53
}
627
628
VCL_VOID
629
vmod_storage_frag(VRT_CTX, VCL_STEVEDORE stv, VCL_BYTES b)
630 8
{
631 8
        struct stevedore *wstv;
632 8
        struct obj_methods *wom;
633 8
        struct stvi *si;
634
635 8
        CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
636 8
        CHECK_OBJ_NOTNULL(stv, STEVEDORE_MAGIC);
637
638 8
        if (b <= 0) {
639 1
                VRT_fail(ctx, "storage_frag: BYTES must be postive");
640 1
                return;
641 1
        }
642
643 7
        si = stvi_get(stv);
644 7
        AN(si);
645 7
        si->param.frag = b;
646
647 7
        PATCH_BEGIN(si, stv, wstv, wom);
648 7
        wom->objgetspace = vtcstv_frag_getspace;
649
        PATCH_END();
650 7
}