[master] fee476a Move another batch of stuff from cache.h to cache_varnishd.h

Poul-Henning Kamp phk at FreeBSD.org
Mon Mar 12 10:23:08 UTC 2018


commit fee476acc085e6563225d35fd8e19f1b10f04139
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Mar 12 09:35:36 2018 +0000

    Move another batch of stuff from cache.h to cache_varnishd.h

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index eb1c43d..9490129 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -90,12 +90,11 @@ struct backend;
 struct ban;
 struct ban_proto;
 struct cli;
-struct cli_proto;
+struct http_conn;
 struct mempool;
 struct objcore;
 struct objhead;
 struct pool;
-struct poolparam;
 struct sess;
 struct transport;
 struct worker;
@@ -125,6 +124,7 @@ enum fetch_step {
 };
 
 /*--------------------------------------------------------------------*/
+
 struct lock { void *priv; };	// Opaque
 
 /*--------------------------------------------------------------------
@@ -166,34 +166,6 @@ struct http {
 	uint8_t			conds;		/* If-* headers present */
 };
 
-/*--------------------------------------------------------------------
- * HTTP Protocol connection structure
- *
- * This is the protocol independent object for a HTTP connection, used
- * both for backend and client sides.
- *
- */
-
-struct http_conn {
-	unsigned		magic;
-#define HTTP_CONN_MAGIC		0x3e19edd1
-
-	int			*rfd;
-	enum sess_close		doclose;
-	enum body_status	body_status;
-	struct ws		*ws;
-	char			*rxbuf_b;
-	char			*rxbuf_e;
-	char			*pipeline_b;
-	char			*pipeline_e;
-	ssize_t			content_length;
-	void			*priv;
-
-	/* Timeouts */
-	double			first_byte_timeout;
-	double			between_bytes_timeout;
-};
-
 /*--------------------------------------------------------------------*/
 
 struct acct_req {
@@ -211,9 +183,9 @@ struct acct_bereq {
 /*--------------------------------------------------------------------*/
 
 struct vsl_log {
-	uint32_t		*wlb, *wlp, *wle;
-	unsigned		wlr;
-	unsigned		wid;
+	uint32_t                *wlb, *wlp, *wle;
+	unsigned                wlr;
+	unsigned                wid;
 };
 
 /*--------------------------------------------------------------------*/
@@ -512,7 +484,7 @@ struct req {
 	double			t_prev;		/* Previous timestamp logged */
 	double			t_req;		/* Headers complete */
 
-	struct http_conn	htc[1];
+	struct http_conn	*htc;
 	struct vfp_ctx		*vfc;
 	const char		*client_identity;
 
@@ -591,9 +563,6 @@ struct sess {
 
 /* Prototypes etc ----------------------------------------------------*/
 
-/* Cross file typedefs */
-
-typedef enum htc_status_e htc_complete_f(struct http_conn *);
 
 /* cache_ban.c */
 
@@ -608,47 +577,6 @@ void BAN_Abandon(struct ban_proto *b);
 extern pthread_t cli_thread;
 #define ASSERT_CLI() do {assert(pthread_self() == cli_thread);} while (0)
 
-/* cache_expire.c */
-
-/*
- * The set of variables which control object expiry are inconveniently
- * 24 bytes long (double+3*float) and this causes alignment waste if
- * we put then in a struct.
- * These three macros operate on the struct we don't use.
- */
-
-#define EXP_ZERO(xx)							\
-	do {								\
-		(xx)->t_origin = 0.0;					\
-		(xx)->ttl = 0.0;					\
-		(xx)->grace = 0.0;					\
-		(xx)->keep = 0.0;					\
-	} while (0)
-
-#define EXP_COPY(to,fm)							\
-	do {								\
-		(to)->t_origin = (fm)->t_origin;			\
-		(to)->ttl = (fm)->ttl;					\
-		(to)->grace = (fm)->grace;				\
-		(to)->keep = (fm)->keep;				\
-	} while (0)
-
-#define EXP_WHEN(to)							\
-	((to)->t_origin + (to)->ttl + (to)->grace + (to)->keep)
-
-/* cache_exp.c */
-void EXP_Rearm(struct objcore *, double now, double ttl, double grace,
-    double keep);
-
-/* cache_fetch.c */
-enum vbf_fetch_mode_e {
-	VBF_NORMAL = 0,
-	VBF_PASS = 1,
-	VBF_BACKGROUND = 2,
-};
-void VBF_Fetch(struct worker *wrk, struct req *req,
-    struct objcore *oc, struct objcore *oldoc, enum vbf_fetch_mode_e);
-
 /* cache_http.c */
 unsigned HTTP_estimate(unsigned nhttp);
 void HTTP_Copy(struct http *to, const struct http * const fm);
@@ -696,14 +624,6 @@ int HTTP_IterHdrPack(struct worker *, struct objcore *, const char **);
 const char *HTTP_GetHdrPack(struct worker *, struct objcore *, const char *hdr);
 enum sess_close http_DoConnection(struct http *hp);
 
-/* cache_http1_proto.c */
-
-htc_complete_f HTTP1_Complete;
-uint16_t HTTP1_DissectRequest(struct http_conn *, struct http *);
-uint16_t HTTP1_DissectResponse(struct http_conn *, struct http *resp,
-    const struct http *req);
-unsigned HTTP1_Write(const struct worker *w, const struct http *hp, const int*);
-
 #define HTTPH_R_PASS	(1 << 0)	/* Request (c->b) in pass mode */
 #define HTTPH_R_FETCH	(1 << 1)	/* Request (c->b) for fetch */
 #define HTTPH_A_INS	(1 << 2)	/* Response (b->o) for insert */
@@ -719,7 +639,6 @@ extern const char H__Reason[];
 /* cache_main.c */
 #define VXID(u) ((u) & VSL_IDENTMASK)
 uint32_t VXID_Get(struct worker *, uint32_t marker);
-extern volatile struct params * cache_param;
 extern pthread_key_t witness_key;
 
 /* cache_lck.c */
@@ -752,91 +671,28 @@ void Lck_DestroyClass(struct vsc_seg **);
 #define LOCK(nam) extern struct VSC_lck *lck_##nam;
 #include "tbl/locks.h"
 
-/* cache_mempool.c */
-void MPL_AssertSane(const void *item);
-struct mempool * MPL_New(const char *name, volatile struct poolparam *pp,
-    volatile unsigned *cur_size);
-void MPL_Destroy(struct mempool **mpp);
-void *MPL_Get(struct mempool *mpl, unsigned *size);
-void MPL_Free(struct mempool *mpl, void *item);
-
 /* cache_obj.c */
-struct objcore * ObjNew(const struct worker *);
-void ObjDestroy(const struct worker *, struct objcore **);
-typedef int objiterate_f(void *priv, int flush, const void *ptr, ssize_t len);
-int ObjIterate(struct worker *, struct objcore *,
-    void *priv, objiterate_f *func, int final);
-int ObjGetSpace(struct worker *, struct objcore *, ssize_t *sz, uint8_t **ptr);
-void ObjExtend(struct worker *, struct objcore *, ssize_t l);
-uint64_t ObjWaitExtend(const struct worker *, const struct objcore *,
-    uint64_t l);
-void ObjSetState(struct worker *, const struct objcore *,
-    enum boc_state_e next);
-void ObjWaitState(const struct objcore *, enum boc_state_e want);
-void ObjTrimStore(struct worker *, struct objcore *);
-void ObjTouch(struct worker *, struct objcore *, double now);
-unsigned ObjGetXID(struct worker *, struct objcore *);
-uint64_t ObjGetLen(struct worker *, struct objcore *);
-void ObjFreeObj(struct worker *, struct objcore *);
-void ObjSlim(struct worker *, struct objcore *);
+
 int ObjHasAttr(struct worker *, struct objcore *, enum obj_attr);
 const void *ObjGetAttr(struct worker *, struct objcore *, enum obj_attr,
     ssize_t *len);
-void *ObjSetAttr(struct worker *, struct objcore *, enum obj_attr,
-    ssize_t len, const void *);
-int ObjCopyAttr(struct worker *, struct objcore *, struct objcore *,
-    enum obj_attr attr);
-void ObjBocDone(struct worker *, struct objcore *, struct boc **);
 
-int ObjSetDouble(struct worker *, struct objcore *, enum obj_attr, double);
-int ObjSetU32(struct worker *, struct objcore *, enum obj_attr, uint32_t);
-int ObjSetU64(struct worker *, struct objcore *, enum obj_attr, uint64_t);
+typedef int objiterate_f(void *priv, int flush, const void *ptr, ssize_t len);
 
+int ObjIterate(struct worker *, struct objcore *,
+    void *priv, objiterate_f *func, int final);
+
+unsigned ObjGetXID(struct worker *, struct objcore *);
+uint64_t ObjGetLen(struct worker *, struct objcore *);
 int ObjGetDouble(struct worker *, struct objcore *, enum obj_attr, double *);
 int ObjGetU32(struct worker *, struct objcore *, enum obj_attr, uint32_t *);
 int ObjGetU64(struct worker *, struct objcore *, enum obj_attr, uint64_t *);
-
 int ObjCheckFlag(struct worker *, struct objcore *, enum obj_flags of);
-void ObjSetFlag(struct worker *, struct objcore *, enum obj_flags of, int val);
-
-#define OEV_INSERT	(1U<<1)
-#define OEV_BANCHG	(1U<<2)
-#define OEV_TTLCHG	(1U<<3)
-#define OEV_EXPIRE	(1U<<4)
-
-#define OEV_MASK (OEV_INSERT|OEV_BANCHG|OEV_TTLCHG|OEV_EXPIRE)
-
-typedef void obj_event_f(struct worker *, void *priv, struct objcore *,
-    unsigned);
-
-uintptr_t ObjSubscribeEvents(obj_event_f *, void *, unsigned mask);
-void ObjUnsubscribeEvents(uintptr_t *);
-void ObjSendEvent(struct worker *, struct objcore *oc, unsigned event);
-
-/* cache_panic.c */
-const char *body_status_2str(enum body_status e);
-const char *sess_close_2str(enum sess_close sc, int want_desc);
-
-/* cache_req_body.c */
-int VRB_Ignore(struct req *);
-ssize_t VRB_Cache(struct req *, ssize_t maxsize);
-ssize_t VRB_Iterate(struct req *, objiterate_f *func, void *priv);
-void VRB_Free(struct req *);
-
 /* cache_session.c [SES] */
 
-void HTC_RxInit(struct http_conn *htc, struct ws *ws);
-void HTC_RxPipeline(struct http_conn *htc, void *);
-enum htc_status_e HTC_RxStuff(struct http_conn *, htc_complete_f *,
-    double *t1, double *t2, double ti, double tn, int maxbytes);
-
 #define SESS_ATTR(UP, low, typ, len)					\
-	int SES_Set_##low(const struct sess *sp, const typ *src);	\
-	int SES_Get_##low(const struct sess *sp, typ **dst);		\
-	void SES_Reserve_##low(struct sess *sp, typ **dst);
+	int SES_Get_##low(const struct sess *sp, typ **dst);
 #include "tbl/sess_attr.h"
-
-void SES_Set_String_Attr(struct sess *sp, enum sess_attr a, const char *src);
 const char *SES_Get_String_Attr(const struct sess *sp, enum sess_attr a);
 
 /* cache_shmlog.c */
diff --git a/bin/varnishd/cache/cache_req.c b/bin/varnishd/cache/cache_req.c
index 4ced78a..a6b9ee0 100644
--- a/bin/varnishd/cache/cache_req.c
+++ b/bin/varnishd/cache/cache_req.c
@@ -95,8 +95,6 @@ Req_New(const struct worker *wrk, struct sess *sp)
 	req->sp = sp;
 	req->top = req;	// esi overrides
 
-	INIT_OBJ(req->htc, HTTP_CONN_MAGIC);
-
 	e = (char*)req + sz;
 	p = (char*)(req + 1);
 	p = (void*)PRNDUP(p);
@@ -129,11 +127,18 @@ Req_New(const struct worker *wrk, struct sess *sp)
 	INIT_OBJ(req->vfc, VFP_CTX_MAGIC);
 	p = (void*)PRNDUP(p + sizeof(*req->vfc));
 
+	req->htc = (void*)p;
+	p = (void*)PRNDUP(p + sizeof(*req->htc));
+
 	req->vdc = (void*)p;
 	INIT_OBJ(req->vdc, VDP_CTX_MAGIC);
 	VTAILQ_INIT(&req->vdc->vdp);
 	p = (void*)PRNDUP(p + sizeof(*req->vdc));
 
+	req->htc = (void*)p;
+	INIT_OBJ(req->htc, HTTP_CONN_MAGIC);
+	p = (void*)PRNDUP(p + sizeof(*req->htc));
+
 	assert(p < e);
 
 	WS_Init(req->ws, "req", p, e - p);
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index bad6380..31a0694 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -46,6 +46,42 @@
 /* -------------------------------------------------------------------*/
 
 struct vfp;
+struct cli_proto;
+struct poolparam;
+
+/*--------------------------------------------------------------------
+ * HTTP Protocol connection structure
+ *
+ * This is the protocol independent object for a HTTP connection, used
+ * both for backend and client sides.
+ *
+ */
+
+struct http_conn {
+	unsigned		magic;
+#define HTTP_CONN_MAGIC		0x3e19edd1
+
+	int			*rfd;
+	enum sess_close		doclose;
+	enum body_status	body_status;
+	struct ws		*ws;
+	char			*rxbuf_b;
+	char			*rxbuf_e;
+	char			*pipeline_b;
+	char			*pipeline_e;
+	ssize_t			content_length;
+	void			*priv;
+
+	/* Timeouts */
+	double			first_byte_timeout;
+	double			between_bytes_timeout;
+};
+
+typedef enum htc_status_e htc_complete_f(struct http_conn *);
+
+/* -------------------------------------------------------------------*/
+
+extern volatile struct params * cache_param;
 
 /* Prototypes etc ----------------------------------------------------*/
 
@@ -94,6 +130,39 @@ void EXP_Remove(struct objcore *);
 
 #define EXP_Dttl(req, oc) (oc->ttl - (req->t_req - oc->t_origin))
 
+/* cache_expire.c */
+
+/*
+ * The set of variables which control object expiry are inconveniently
+ * 24 bytes long (double+3*float) and this causes alignment waste if
+ * we put then in a struct.
+ * These three macros operate on the struct we don't use.
+ */
+
+#define EXP_ZERO(xx)							\
+	do {								\
+		(xx)->t_origin = 0.0;					\
+		(xx)->ttl = 0.0;					\
+		(xx)->grace = 0.0;					\
+		(xx)->keep = 0.0;					\
+	} while (0)
+
+#define EXP_COPY(to,fm)							\
+	do {								\
+		(to)->t_origin = (fm)->t_origin;			\
+		(to)->ttl = (fm)->ttl;					\
+		(to)->grace = (fm)->grace;				\
+		(to)->keep = (fm)->keep;				\
+	} while (0)
+
+#define EXP_WHEN(to)							\
+	((to)->t_origin + (to)->ttl + (to)->grace + (to)->keep)
+
+/* cache_exp.c */
+void EXP_Rearm(struct objcore *, double now, double ttl, double grace,
+    double keep);
+
+
 /* From cache_main.c */
 void BAN_Init(void);
 void BAN_Compile(void);
@@ -122,6 +191,15 @@ extern const struct vdp VDP_esi;
 /* cache_expire.c */
 void EXP_Init(void);
 
+/* cache_fetch.c */
+enum vbf_fetch_mode_e {
+	VBF_NORMAL = 0,
+	VBF_PASS = 1,
+	VBF_BACKGROUND = 2,
+};
+void VBF_Fetch(struct worker *wrk, struct req *req,
+    struct objcore *oc, struct objcore *oldoc, enum vbf_fetch_mode_e);
+
 /* cache_fetch_proc.c */
 void VFP_Init(void);
 enum vfp_status VFP_GetStorage(struct vfp_ctx *, ssize_t *sz, uint8_t **ptr);
@@ -140,6 +218,14 @@ extern const struct vfp VFP_esi_gzip;
 /* cache_http.c */
 void HTTP_Init(void);
 
+/* cache_http1_proto.c */
+
+htc_complete_f HTTP1_Complete;
+uint16_t HTTP1_DissectRequest(struct http_conn *, struct http *);
+uint16_t HTTP1_DissectResponse(struct http_conn *, struct http *resp,
+    const struct http *req);
+unsigned HTTP1_Write(const struct worker *w, const struct http *hp, const int*);
+
 /* cache_main.c */
 void THR_SetName(const char *name);
 const char* THR_GetName(void);
@@ -152,12 +238,63 @@ void THR_Init(void);
 /* cache_lck.c */
 void LCK_Init(void);
 
+/* cache_mempool.c */
+void MPL_AssertSane(const void *item);
+struct mempool * MPL_New(const char *name, volatile struct poolparam *pp,
+    volatile unsigned *cur_size);
+void MPL_Destroy(struct mempool **mpp);
+void *MPL_Get(struct mempool *mpl, unsigned *size);
+void MPL_Free(struct mempool *mpl, void *item);
+
 /* cache_obj.c */
 void ObjInit(void);
+struct objcore * ObjNew(const struct worker *);
+void ObjDestroy(const struct worker *, struct objcore **);
+int ObjGetSpace(struct worker *, struct objcore *, ssize_t *sz, uint8_t **ptr);
+void ObjExtend(struct worker *, struct objcore *, ssize_t l);
+uint64_t ObjWaitExtend(const struct worker *, const struct objcore *,
+    uint64_t l);
+void ObjSetState(struct worker *, const struct objcore *,
+    enum boc_state_e next);
+void ObjWaitState(const struct objcore *, enum boc_state_e want);
+void ObjTrimStore(struct worker *, struct objcore *);
+void ObjTouch(struct worker *, struct objcore *, double now);
+void ObjFreeObj(struct worker *, struct objcore *);
+void ObjSlim(struct worker *, struct objcore *);
+void *ObjSetAttr(struct worker *, struct objcore *, enum obj_attr,
+    ssize_t len, const void *);
+int ObjCopyAttr(struct worker *, struct objcore *, struct objcore *,
+    enum obj_attr attr);
+void ObjBocDone(struct worker *, struct objcore *, struct boc **);
+
+int ObjSetDouble(struct worker *, struct objcore *, enum obj_attr, double);
+int ObjSetU32(struct worker *, struct objcore *, enum obj_attr, uint32_t);
+int ObjSetU64(struct worker *, struct objcore *, enum obj_attr, uint64_t);
+
+void ObjSetFlag(struct worker *, struct objcore *, enum obj_flags of, int val);
+
+void ObjSendEvent(struct worker *, struct objcore *oc, unsigned event);
+
+#define OEV_INSERT	(1U<<1)
+#define OEV_BANCHG	(1U<<2)
+#define OEV_TTLCHG	(1U<<3)
+#define OEV_EXPIRE	(1U<<4)
+
+#define OEV_MASK (OEV_INSERT|OEV_BANCHG|OEV_TTLCHG|OEV_EXPIRE)
+
+typedef void obj_event_f(struct worker *, void *priv, struct objcore *,
+    unsigned);
+
+uintptr_t ObjSubscribeEvents(obj_event_f *, void *, unsigned mask);
+void ObjUnsubscribeEvents(uintptr_t *);
+
+
 
 /* cache_panic.c */
 void PAN_Init(void);
 int PAN_already(struct vsb *, const void *);
+const char *body_status_2str(enum body_status e);
+const char *sess_close_2str(enum sess_close sc, int want_desc);
 
 /* cache_pool.c */
 void Pool_Init(void);
@@ -179,6 +316,12 @@ void Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req);
 void Req_Fail(struct req *req, enum sess_close reason);
 void Req_AcctLogCharge(struct VSC_main *, struct req *);
 
+/* cache_req_body.c */
+int VRB_Ignore(struct req *);
+ssize_t VRB_Cache(struct req *, ssize_t maxsize);
+ssize_t VRB_Iterate(struct req *, objiterate_f *func, void *priv);
+void VRB_Free(struct req *);
+
 /* cache_req_fsm.c [CNT] */
 
 enum req_fsm_nxt {
@@ -197,6 +340,18 @@ void SES_Ref(struct sess *sp);
 void SES_Rel(struct sess *sp);
 int SES_Reschedule_Req(struct req *, enum task_prio);
 
+void HTC_RxInit(struct http_conn *htc, struct ws *ws);
+void HTC_RxPipeline(struct http_conn *htc, void *);
+enum htc_status_e HTC_RxStuff(struct http_conn *, htc_complete_f *,
+    double *t1, double *t2, double ti, double tn, int maxbytes);
+
+#define SESS_ATTR(UP, low, typ, len)					\
+	int SES_Set_##low(const struct sess *sp, const typ *src);	\
+	void SES_Reserve_##low(struct sess *sp, typ **dst);
+#include "tbl/sess_attr.h"
+void SES_Set_String_Attr(struct sess *sp, enum sess_attr a, const char *src);
+
+
 enum htc_status_e {
 	HTC_S_JUNK =		-5,
 	HTC_S_CLOSE =		-4,
@@ -289,4 +444,3 @@ void SMP_Ready(void);
 		if (DO_DEBUG(debug_bit))			\
 			VSL(SLT_Debug, (id), __VA_ARGS__);	\
 	} while (0)
-
diff --git a/bin/varnishd/http1/cache_http1.h b/bin/varnishd/http1/cache_http1.h
index 7dd0c62..a6558a2 100644
--- a/bin/varnishd/http1/cache_http1.h
+++ b/bin/varnishd/http1/cache_http1.h
@@ -50,7 +50,7 @@ struct v1p_acct {
 	uint64_t        out;
 };
 
-void V1P_Process(struct req *, int fd, struct v1p_acct *);
+void V1P_Process(const struct req *, int fd, struct v1p_acct *);
 void V1P_Charge(struct req *, const struct v1p_acct *, struct VSC_vbe *);
 
 /* cache_http1_line.c */
diff --git a/bin/varnishd/http1/cache_http1_pipe.c b/bin/varnishd/http1/cache_http1_pipe.c
index cb7de49..6f8828a 100644
--- a/bin/varnishd/http1/cache_http1_pipe.c
+++ b/bin/varnishd/http1/cache_http1_pipe.c
@@ -84,7 +84,7 @@ V1P_Charge(struct req *req, const struct v1p_acct *a, struct VSC_vbe *b)
 }
 
 void
-V1P_Process(struct req *req, int fd, struct v1p_acct *v1a)
+V1P_Process(const struct req *req, int fd, struct v1p_acct *v1a)
 {
 	struct pollfd fds[2];
 	int i, j;
diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index d165281..a0f76fe 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -46,7 +46,7 @@
 static const char vpx1_sig[] = {'P', 'R', 'O', 'X', 'Y'};
 
 static int
-vpx_proto1(const struct worker *wrk, struct req *req)
+vpx_proto1(const struct worker *wrk, const struct req *req)
 {
 	const char *fld[5];
 	int i;
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 3ee5a0e..4de4947 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -35,16 +35,13 @@
 #include <sys/socket.h>
 #include <unistd.h>
 
-#include "cache/cache.h"
+#include "cache/cache_varnishd.h"
 
 #include "vsa.h"
-#include "vsb.h"
 #include "vtim.h"
 #include "vcc_if.h"
 #include "VSC_debug.h"
 
-#include "common/common_param.h"
-
 struct priv_vcl {
 	unsigned		magic;
 #define PRIV_VCL_MAGIC		0x8E62FA9D


More information about the varnish-commit mailing list