Commit df0a067d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make the VSC-set create/destroy functions part of VRT

parent cf3c9d92
......@@ -139,7 +139,6 @@ nobase_pkginclude_HEADERS = \
cache/cache_filter.h \
cache/cache_backend.h \
cache/cache_director.h \
common/common_vsm.h \
common/common_param.h \
waiter/waiter.h
......
......@@ -36,7 +36,6 @@
#include <stdlib.h>
#include "common/heritage.h"
#include "common/common_vsm.h"
#include "vend.h"
#include "vgz.h"
......@@ -501,8 +500,8 @@ VSM_Init(void)
VSC_C_main = VSC_main_New("");
AN(VSC_C_main);
AN(proc_vsmw);
vsl_head = VSMW_Allocf(proc_vsmw, VSL_CLASS,
AN(heritage.proc_vsmw);
vsl_head = VSMW_Allocf(heritage.proc_vsmw, VSL_CLASS,
cache_param->vsl_space, VSL_CLASS);
AN(vsl_head);
vsl_segsize = ((cache_param->vsl_space - sizeof *vsl_head) /
......
......@@ -36,19 +36,18 @@
#include <string.h>
#include <stdlib.h>
#include "common/common_vsm.h"
#include "vdef.h"
#include "miniobj.h"
#include "vas.h"
#include "vend.h"
#include "vsmw.h"
#include "vgz.h"
#include "vmb.h"
#include "vrt.h"
#include "vsmw.h"
#include "vqueue.h"
#include "vapi/vsc_int.h"
struct vsmw *proc_vsmw;
#include "common/heritage.h"
/*--------------------------------------------------------------------*/
......@@ -69,7 +68,7 @@ vsc_callback_f *vsc_lock;
vsc_callback_f *vsc_unlock;
void *
VSC_Alloc(const char *nm, size_t sd, size_t sj, const unsigned char *zj,
VRT_VSC_Alloc(const char *nm, size_t sd, size_t sj, const unsigned char *zj,
size_t szj, const char *fmt, va_list va)
{
char *p;
......@@ -85,8 +84,8 @@ VSC_Alloc(const char *nm, size_t sd, size_t sj, const unsigned char *zj,
else
bprintf(buf, "%s.%s", nm, fmt);
AN(proc_vsmw);
p = VSMW_Allocv(proc_vsmw, VSC_CLASS, 8 + sd + sj, buf, va);
AN(heritage.proc_vsmw);
p = VSMW_Allocv(heritage.proc_vsmw, VSC_CLASS, 8 + sd + sj, buf, va);
AN(p);
memset(&vz, 0, sizeof vz);
......@@ -111,19 +110,19 @@ VSC_Alloc(const char *nm, size_t sd, size_t sj, const unsigned char *zj,
}
void
VSC_Destroy(const char *nm, const void *p)
VRT_VSC_Destroy(const char *nm, const void *p)
{
struct vsc_segs *vsg;
if (vsc_lock != NULL)
vsc_lock();
AN(proc_vsmw);
AN(heritage.proc_vsmw);
VTAILQ_FOREACH(vsg, &vsc_seglist, list) {
if (vsg->ptr != p)
continue;
assert(vsg->nm == nm);
VSMW_Free(proc_vsmw, &vsg->seg);
VSMW_Free(heritage.proc_vsmw, &vsg->seg);
VTAILQ_REMOVE(&vsc_seglist, vsg, list);
FREE_OBJ(vsg);
break;
......
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2017 Varnish Software AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#ifdef COMMON_COMMON_VSM_H
#error "Multiple includes of common/common_vsm.h"
#endif
#define COMMON_COMMON_VSM_H
struct vsmw;
extern struct vsmw *proc_vsmw;
typedef void vsc_callback_f(void);
extern vsc_callback_f *vsc_lock;
extern vsc_callback_f *vsc_unlock;
void *VSC_Alloc(const char *, size_t, size_t, const unsigned char *, size_t,
const char *, va_list);
void VSC_Destroy(const char *, const void *);
......@@ -89,6 +89,8 @@ struct heritage {
const char *ident;
long mgt_pid;
struct vsmw *proc_vsmw;
};
extern struct heritage heritage;
......@@ -116,3 +118,9 @@ int VCL_TestLoad(const char *);
struct transport;
void XPORT_Init(void);
const struct transport *XPORT_Find(const char *name);
/* common/common_vsc.c */
typedef void vsc_callback_f(void);
extern vsc_callback_f *vsc_lock;
extern vsc_callback_f *vsc_unlock;
......@@ -46,7 +46,6 @@
#include "mgt/mgt.h"
#include "common/heritage.h"
#include "common/common_vsm.h"
#include "vbm.h"
#include "vcli_serve.h"
......@@ -397,8 +396,8 @@ mgt_launch_child(struct cli *cli)
VJ_subproc(JAIL_SUBPROC_WORKER);
proc_vsmw = VSMW_New(heritage.vsm_fd, 0640, "_.index");
AN(proc_vsmw);
heritage.proc_vsmw = VSMW_New(heritage.vsm_fd, 0640, "_.index");
AN(heritage.proc_vsmw);
child_main();
......
......@@ -42,7 +42,6 @@
#include "mgt/mgt.h"
#include "common/heritage.h"
#include "common/common_vsm.h"
#include "vsm_priv.h"
#include "vsmw.h"
......@@ -101,7 +100,7 @@ mgt_SHM_Init(void)
mgt_vsmw = VSMW_New(fd, 0640, "_.index");
AN(mgt_vsmw);
proc_vsmw = mgt_vsmw;
heritage.proc_vsmw = mgt_vsmw;
/* Setup atexit handler */
AZ(atexit(mgt_shm_atexit));
......
......@@ -50,6 +50,8 @@
*
* 6.2 (scheduled for: 2018-03-15)
* VRT_Healthy() added
* VRT_VSC_Alloc() added
* VRT_VSC_Destroy() added
* 6.1 (2017-09-15 aka 5.2)
* http_CollectHdrSep added
* VRT_purge modified (may fail a transaction, signature changed)
......@@ -411,3 +413,9 @@ typedef int vcl_init_f(VRT_CTX);
typedef void vcl_fini_f(VRT_CTX);
typedef void vcl_func_f(VRT_CTX);
typedef int vmod_event_f(VRT_CTX, struct vmod_priv *, enum vcl_event_e);
#ifdef va_start // XXX: hackish
void *VRT_VSC_Alloc(const char *, size_t, size_t, const unsigned char *, size_t,
const char *, va_list);
void VRT_VSC_Destroy(const char *, const void *);
#endif
......@@ -162,7 +162,7 @@ class vscset(object):
fo.write('#include <stdint.h>\n')
fo.write('#include "vdef.h"\n')
fo.write('#include "vas.h"\n')
fo.write('#include "common/common_vsm.h"\n')
fo.write('#include "vrt.h"\n')
fo.write('#include "VSC_%s.h"\n' % self.name)
fo.write("\n")
......@@ -187,7 +187,7 @@ class vscset(object):
fo.write("\t" + self.struct + " *retval;\n")
fo.write("\n")
fo.write("\tva_start(ap, fmt);\n")
fo.write("\tretval = VSC_Alloc")
fo.write("\tretval = VRT_VSC_Alloc")
fo.write("(vsc_" + self.name + "_name, ")
fo.write("sizeof(" + self.struct + "),\n\t ")
fo.write("vsc_" + self.name + "_jsonlen, ")
......@@ -205,7 +205,7 @@ class vscset(object):
fo.write("{\n")
fo.write("\n")
fo.write("\tAN(pp);\n")
fo.write('\tVSC_Destroy(vsc_%s_name, *pp);\n' % self.name)
fo.write('\tVRT_VSC_Destroy(vsc_%s_name, *pp);\n' % self.name)
fo.write("\t*pp = NULL;\n")
fo.write("}\n")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment