r1640 - in trunk/varnish-cache: bin/varnishd lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Wed Jul 4 00:24:09 CEST 2007


Author: phk
Date: 2007-07-04 00:24:09 +0200 (Wed, 04 Jul 2007)
New Revision: 1640

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_response.c
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
   trunk/varnish-cache/lib/libvcl/vcc_obj.c
Log:
Implement vcl_deliver() and change variable visibility to match.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2007-07-03 22:00:26 UTC (rev 1639)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2007-07-03 22:24:09 UTC (rev 1640)
@@ -471,6 +471,7 @@
 #endif
 
 /* cache_response.c */
+void RES_BuildHttp(struct sess *sp);
 void RES_Error(struct sess *sp, int code, const char *reason);
 void RES_WriteObj(struct sess *sp);
 

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2007-07-03 22:00:26 UTC (rev 1639)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2007-07-03 22:24:09 UTC (rev 1640)
@@ -119,7 +119,7 @@
 DOT	]
 DOT	vcl_deliver [
 DOT		shape=record
-DOT		label="vcl_deliver()|req.\nresp."
+DOT		label="vcl_deliver()|resp."
 DOT	]
 DOT	deliver2 [
 DOT		shape=ellipse
@@ -131,12 +131,29 @@
 DOT     errdeliver [label="ERROR",shape=plaintext]
 DOT }
 DOT deliver2 -> DONE [style=bold,color=green,weight=4]
+ *
+ * XXX: Ideally we should make the req. available in vcl_deliver() but for
+ * XXX: reasons of economy we don't, since that allows us to reuse the space
+ * XXX: in sp->req for the response.
+ * 
+ * XXX: Rather than allocate two http's and workspaces for all sessions to
+ * XXX: address this deficiency, we could make the VCL compiler set a flag
+ * XXX: if req. is used in vcl_deliver().  When the flag is set we would
+ * XXX: take the memory overhead, for instance by borrowing a struct bereq
+ * XXX: or similar.
+ *
+ * XXX: For now, wait until somebody asks for it.
  */
 
 static int
 cnt_deliver(struct sess *sp)
 {
 
+	RES_BuildHttp(sp);
+	VCL_deliver_method(sp);
+	if (sp->handling != VCL_RET_DELIVER) 
+		INCOMPL();
+
 	RES_WriteObj(sp);
 	HSH_Deref(sp->obj);
 	sp->obj = NULL;
@@ -171,6 +188,7 @@
 	double dh, dp, da;
 
 	AZ(sp->obj);
+	AZ(sp->bereq);
 	sp->backend = NULL;
 	if (sp->vcl != NULL) {
 		if (sp->wrk->vcl != NULL)

Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c	2007-07-03 22:00:26 UTC (rev 1639)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c	2007-07-03 22:24:09 UTC (rev 1640)
@@ -114,13 +114,9 @@
 /*--------------------------------------------------------------------*/
 
 void
-RES_WriteObj(struct sess *sp)
+RES_BuildHttp(struct sess *sp)
 {
-	struct storage *st;
-	unsigned u = 0;
-
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	clock_gettime(CLOCK_REALTIME, &sp->t_resp);
 
 	if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp))
 		return;
@@ -136,12 +132,26 @@
 		http_PrintfHeader(sp->wrk, sp->fd, sp->http,
 		    "X-Varnish: %u %u", sp->xid, sp->obj->xid);
 	else
-		http_PrintfHeader(sp->wrk, sp->fd, sp->http, "X-Varnish: %u", sp->xid);
+		http_PrintfHeader(sp->wrk, sp->fd, sp->http,
+		    "X-Varnish: %u", sp->xid);
 	http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Age: %u",
 	    sp->obj->age + sp->t_resp.tv_sec - sp->obj->entered);
 	http_SetHeader(sp->wrk, sp->fd, sp->http, "Via: 1.1 varnish");
 	if (sp->doclose != NULL)
 		http_SetHeader(sp->wrk, sp->fd, sp->http, "Connection: close");
+}
+
+/*--------------------------------------------------------------------*/
+
+void
+RES_WriteObj(struct sess *sp)
+{
+	struct storage *st;
+	unsigned u = 0;
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+
+	clock_gettime(CLOCK_REALTIME, &sp->t_resp);
 	WRK_Reset(sp->wrk, &sp->fd);
 	sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2007-07-03 22:00:26 UTC (rev 1639)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2007-07-03 22:24:09 UTC (rev 1640)
@@ -483,10 +483,12 @@
 	vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n");
 	vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n");
+	vsb_cat(sb, "double VRT_r_obj_lastuse(struct sess *);\n");
 	vsb_cat(sb, "const char * VRT_r_resp_proto(struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_resp_proto(struct sess *, const char *);\n");
 	vsb_cat(sb, "int VRT_r_resp_status(struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_resp_status(struct sess *, int);\n");
 	vsb_cat(sb, "const char * VRT_r_resp_response(struct sess *);\n");
 	vsb_cat(sb, "void VRT_l_resp_response(struct sess *, const char *);\n");
+	vsb_cat(sb, "double VRT_r_now(struct sess *);\n");
 }

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2007-07-03 22:00:26 UTC (rev 1639)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_obj.tcl	2007-07-03 22:24:09 UTC (rev 1640)
@@ -44,14 +44,14 @@
 	# Connection related parameters
 	{ client.ip
 		RO IP
-		{recv pipe pass hash miss hit fetch                        }
+		{recv pipe pass hash miss hit fetch deliver                }
 	}
 	{ client.bandwidth				 # Not implemented yet
 		NO
 	}
 	{ server.ip
 		RO IP
-		{recv pipe pass hash miss hit fetch                        }
+		{recv pipe pass hash miss hit fetch deliver                }
 	}
 
 	# Request paramters
@@ -103,7 +103,7 @@
 	# The (possibly) cached object
 	{ obj.proto
 		RW STRING
-		{                         hit fetch deliver                }
+		{                         hit fetch                        }
 	}
 	{ obj.status
 		RW INT
@@ -115,7 +115,7 @@
 	}
 	{ obj.http.
 		RW HEADER
-		{                         hit fetch deliver                }
+		{                         hit fetch 			   }
 	}
 
 	{ obj.valid
@@ -138,22 +138,24 @@
 	# The response we send back
 	{ resp.proto
 		RW STRING
-		{                             fetch                        }
+		{                                   deliver                }
 	}
 	{ resp.status
 		RW INT
-		{                             fetch                        }
+		{                                   deliver                }
 	}
 	{ resp.response
 		RW STRING
-		{                             fetch                        }
+		{                                   deliver                }
 	}
 	{ resp.http.
 		RW HEADER
-		{                             fetch                        }
+		{                                   deliver                }
 	}
 
 	# Miscellaneous
+	# XXX: I'm not happy about this one.  All times should be relative
+	# XXX: or delta times in VCL programs, so this shouldn't be needed /phk
 	{ now
 		RO TIME
 		{recv pipe pass hash miss hit fetch deliver discard timeout}

Modified: trunk/varnish-cache/lib/libvcl/vcc_obj.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_obj.c	2007-07-03 22:00:26 UTC (rev 1639)
+++ trunk/varnish-cache/lib/libvcl/vcc_obj.c	2007-07-03 22:24:09 UTC (rev 1640)
@@ -36,13 +36,13 @@
 	    "VRT_r_client_ip(sp)",
 	    NULL,
 	    V_RO,
-	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
+	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
 	},
 	{ "server.ip", IP, 9,
 	    "VRT_r_server_ip(sp)",
 	    NULL,
 	    V_RO,
-	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
+	    VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
 	},
 	{ "req.request", STRING, 11,
 	    "VRT_r_req_request(sp)",
@@ -108,7 +108,7 @@
 	    "VRT_r_obj_proto(sp)",
 	    "VRT_l_obj_proto(sp, ",
 	    V_RW,
-	    VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
+	    VCL_MET_HIT | VCL_MET_FETCH
 	},
 	{ "obj.status", INT, 10,
 	    "VRT_r_obj_status(sp)",
@@ -126,7 +126,7 @@
 	    "VRT_r_obj_http_(sp)",
 	    "VRT_l_obj_http_(sp, ",
 	    V_RW,
-	    VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
+	    VCL_MET_HIT | VCL_MET_FETCH
 	},
 	{ "obj.valid", BOOL, 9,
 	    "VRT_r_obj_valid(sp)",
@@ -156,25 +156,25 @@
 	    "VRT_r_resp_proto(sp)",
 	    "VRT_l_resp_proto(sp, ",
 	    V_RW,
-	    VCL_MET_FETCH
+	    VCL_MET_DELIVER
 	},
 	{ "resp.status", INT, 11,
 	    "VRT_r_resp_status(sp)",
 	    "VRT_l_resp_status(sp, ",
 	    V_RW,
-	    VCL_MET_FETCH
+	    VCL_MET_DELIVER
 	},
 	{ "resp.response", STRING, 13,
 	    "VRT_r_resp_response(sp)",
 	    "VRT_l_resp_response(sp, ",
 	    V_RW,
-	    VCL_MET_FETCH
+	    VCL_MET_DELIVER
 	},
 	{ "resp.http.", HEADER, 10,
 	    "VRT_r_resp_http_(sp)",
 	    "VRT_l_resp_http_(sp, ",
 	    V_RW,
-	    VCL_MET_FETCH
+	    VCL_MET_DELIVER
 	},
 	{ "now", TIME, 3,
 	    "VRT_r_now(sp)",




More information about the varnish-commit mailing list