[master] 9f996c1fe Refactor bereq/beresp flag tables

Nils Goroll nils.goroll at uplex.de
Mon Aug 29 16:40:07 UTC 2022


commit 9f996c1fee4c736feb2f15ff07d7d3e7bf403f06
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Aug 29 17:38:53 2022 +0200

    Refactor bereq/beresp flag tables
    
    The filter check does not make sense in the context of bereq
    and the macros became overloaded with two different cases.
    
    Motivated by and in preparation of #3826

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 424067abb..7b4d8f9a7 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -394,8 +394,10 @@ struct busyobj {
 
 	struct pool_task	fetch_task[1];
 
-#define BO_FLAG(l, r, rr, rw, f, d) unsigned	l:1;
-#include "tbl/bo_flags.h"
+#define BERESP_FLAG(l, r, w, f, d) unsigned	l:1;
+#define BEREQ_FLAG(l, r, w, d) BERESP_FLAG(l, r, w, 0, d)
+#include "tbl/bereq_flags.h"
+#include "tbl/beresp_flags.h"
 
 	/* Timeouts */
 	vtim_dur		connect_timeout;
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index b93fdb7b1..45384a0bb 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -390,9 +390,11 @@ pan_busyobj(struct vsb *vsb, const struct busyobj *bo)
 	VSB_cat(vsb, "flags = {");
 	p = "";
 /*lint -save -esym(438,p) -e539 */
-#define BO_FLAG(l, r, rr, rw, f, d)				\
+#define BERESP_FLAG(l, r, w, f, d)				\
 	if (bo->l) { VSB_printf(vsb, "%s" #l, p); p = ", "; }
-#include "tbl/bo_flags.h"
+#define BEREQ_FLAG(l, r, w, d) BERESP_FLAG(l, r, w, 0, d)
+#include "tbl/bereq_flags.h"
+#include "tbl/beresp_flags.h"
 /*lint -restore */
 	VSB_cat(vsb, "},\n");
 
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index f508dc709..7a12df235 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -181,7 +181,7 @@ VRT_r_obj_reason(VRT_CTX)
 }
 
 /*--------------------------------------------------------------------
- * bool-fields (.do_*)
+ * beresp bool-fields
  */
 
 static inline int
@@ -228,21 +228,10 @@ VRT_r_beresp_##field(VRT_CTX)						\
 	return (ctx->bo->field);					\
 }
 
-#define VBEREQR0(field, str, fltchk)
-#define VBEREQR1(field, str, fltchk)					\
-VCL_BOOL								\
-VRT_r_bereq_##field(VRT_CTX)						\
-{									\
-	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);				\
-	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);			\
-	return (ctx->bo->field);					\
-}
-
-#define BO_FLAG(l, r, rr, rw, f, d)		\
-	VBEREQR##r(l, #l, f)			\
-	VBERESPR##rr(l, #l, f)			\
-	VBERESPW##rw(l, #l, f)
-#include "tbl/bo_flags.h"
+#define BERESP_FLAG(l, r, w, f, d)		\
+	VBERESPR##r(l, #l, f)			\
+	VBERESPW##w(l, #l, f)
+#include "tbl/beresp_flags.h"
 
 #undef VBERESPWF0
 #undef VBERESPWF1
@@ -254,6 +243,27 @@ VRT_r_bereq_##field(VRT_CTX)						\
 #undef VBERESPR0
 #undef VBERESPR1
 
+/*--------------------------------------------------------------------
+ * bereq bool-fields
+ */
+
+#define VBEREQR0(field, str)
+#define VBEREQR1(field, str)						\
+VCL_BOOL								\
+VRT_r_bereq_##field(VRT_CTX)						\
+{									\
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);				\
+	CHECK_OBJ_NOTNULL(ctx->bo, BUSYOBJ_MAGIC);			\
+	return (ctx->bo->field);					\
+}
+
+// w is unused
+#define VBEREQW0(ctx, str) (void) 0
+
+#define BEREQ_FLAG(l, r, w, d)		\
+	VBEREQR##r(l, #l)
+#include "tbl/bereq_flags.h"
+
 #undef VBEREQR0
 #undef VBEREQR1
 /*--------------------------------------------------------------------*/
diff --git a/include/Makefile.am b/include/Makefile.am
index a7a77310d..81d05d96e 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -8,8 +8,8 @@ nobase_pkginclude_HEADERS = \
 	tbl/ban_arg_oper.h \
 	tbl/ban_oper.h \
 	tbl/ban_vars.h \
-	tbl/bo_flags.h \
-	tbl/boc_state.h \
+	tbl/bereq_flags.h \
+	tbl/beresp_flags.h \
 	tbl/body_status.h \
 	tbl/cli_cmds.h \
 	tbl/debug_bits.h \
diff --git a/include/tbl/bereq_flags.h b/include/tbl/bereq_flags.h
new file mode 100644
index 000000000..c7831fec4
--- /dev/null
+++ b/include/tbl/bereq_flags.h
@@ -0,0 +1,41 @@
+/*-
+ * Copyright (c) 2014-2015 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * 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.
+ *
+ */
+
+/*lint -save -e525 -e539 */
+
+/* lower, vcl_r, vcl_w, doc */
+BEREQ_FLAG(uncacheable,	0, 0, "")	// also beresp
+BEREQ_FLAG(is_bgfetch,	1, 0, "")
+BEREQ_FLAG(is_hitmiss,	1, 0, "")
+BEREQ_FLAG(is_hitpass,	1, 0, "")
+#undef BEREQ_FLAG
+
+/*lint -restore */
diff --git a/include/tbl/bo_flags.h b/include/tbl/beresp_flags.h
similarity index 80%
rename from include/tbl/bo_flags.h
rename to include/tbl/beresp_flags.h
index 4a4f1dd4b..b4eb789b3 100644
--- a/include/tbl/bo_flags.h
+++ b/include/tbl/beresp_flags.h
@@ -34,16 +34,12 @@
 /*
  * filters: whether this flag determines beresp.filters default
  *
- * lower, vcl_r, vcl_beresp_r, vcl_beresp_w, filters, doc */
-BO_FLAG(do_esi,		0, 1, 1, 1, "")
-BO_FLAG(do_gzip,	0, 1, 1, 1, "")
-BO_FLAG(do_gunzip,	0, 1, 1, 1, "")
-BO_FLAG(do_stream,	0, 1, 1, 0, "")
-BO_FLAG(uncacheable,	0, 0, 0, 0, "")
-BO_FLAG(was_304,	0, 1, 0, 0, "")
-BO_FLAG(is_bgfetch,	1, 0, 0, 0, "")
-BO_FLAG(is_hitmiss,	1, 0, 0, 0, "")
-BO_FLAG(is_hitpass,	1, 0, 0, 0, "")
-#undef BO_FLAG
+ * lower, vcl_r, vcl_w, filters, doc */
+BERESP_FLAG(do_esi,		1, 1, 1, "")
+BERESP_FLAG(do_gzip,	1, 1, 1, "")
+BERESP_FLAG(do_gunzip,	1, 1, 1, "")
+BERESP_FLAG(do_stream,	1, 1, 0, "")
+BERESP_FLAG(was_304,	1, 0, 0, "")
+#undef BERESP_FLAG
 
 /*lint -restore */


More information about the varnish-commit mailing list