[master] a88cef8 Add an option argument to the cursors

Martin Blix Grydeland martin at varnish-cache.org
Wed Oct 9 16:03:04 CEST 2013


commit a88cef86ff8da2d2da5264bf2b54904f393c5421
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Wed Oct 9 13:25:41 2013 +0200

    Add an option argument to the cursors

diff --git a/include/vapi/vsl.h b/include/vapi/vsl.h
index f88e20f..5f30c0c 100644
--- a/include/vapi/vsl.h
+++ b/include/vapi/vsl.h
@@ -201,24 +201,30 @@ void VSL_ResetError(struct VSL_data *vsl);
 	 * Reset any error message.
 	 */
 
+#define VSL_COPT_TAIL	(1 << 0)
 struct VSL_cursor *VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm,
-    int tail);
+    unsigned options);
        /*
         * Set the cursor pointed to by cursor up as a raw cursor in the
-        * log. If tail is non-zero, it will point to the tail of the
-        * log. Is tail is zero, it will point close to the head of the
-        * log, at least 2 segments away from the head.
+        * log. Cursor points at the current log head.
+	*
+	* Options:
+	*   VSL_COPT_TAIL	Start cursor at log tail
 	*
 	* Return values:
 	* non-NULL: Pointer to cursor
 	*     NULL: Error, see VSL_Error
         */
 
-struct VSL_cursor *VSL_CursorFile(struct VSL_data *vsl, const char *name);
+struct VSL_cursor *VSL_CursorFile(struct VSL_data *vsl, const char *name,
+    unsigned options);
 	/*
 	 * Create a cursor pointing to the beginning of the binary VSL log
 	 * in file name. If name is '-' reads from stdin.
 	 *
+	 * Options:
+	 *   NONE
+	 *
 	 * Return values:
 	 * non-NULL: Pointer to cursor
 	 *     NULL: Error, see VSL_Error
diff --git a/lib/libvarnishapi/vsl_cursor.c b/lib/libvarnishapi/vsl_cursor.c
index fe1f82e..e030776 100644
--- a/lib/libvarnishapi/vsl_cursor.c
+++ b/lib/libvarnishapi/vsl_cursor.c
@@ -53,6 +53,8 @@ struct vslc_vsm {
 
 	struct VSL_cursor		cursor;
 
+	unsigned			options;
+
 	struct VSM_data			*vsm;
 	struct VSM_fantom		vf;
 
@@ -228,7 +230,7 @@ static const struct vslc_tbl vslc_vsm_tbl = {
 };
 
 struct VSL_cursor *
-VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, int tail)
+VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, unsigned options)
 {
 	struct vslc_vsm *c;
 	struct VSM_fantom vf;
@@ -260,13 +262,14 @@ VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, int tail)
 	c->cursor.priv_tbl = &vslc_vsm_tbl;
 	c->cursor.priv_data = c;
 
+	c->options = options;
 	c->vsm = vsm;
 	c->vf = vf;
 	c->head = head;
 	c->end = vf.e;
 	c->segsize = (c->end - c->head->log) / VSL_SEGMENTS;
 
-	if (tail) {
+	if (c->options & VSL_COPT_TAIL) {
 		/* Locate tail of log */
 		c->next.ptr = c->head->log +
 		    c->head->segments[c->head->segment];
@@ -384,7 +387,7 @@ static const struct vslc_tbl vslc_file_tbl = {
 };
 
 struct VSL_cursor *
-VSL_CursorFile(struct VSL_data *vsl, const char *name)
+VSL_CursorFile(struct VSL_data *vsl, const char *name, unsigned options)
 {
 	struct vslc_file *c;
 	int fd;
@@ -392,6 +395,10 @@ VSL_CursorFile(struct VSL_data *vsl, const char *name)
 	char buf[] = VSL_FILE_ID;
 	ssize_t i;
 
+	CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
+	AN(name);
+	(void)options;
+
 	if (!strcmp(name, "-"))
 		fd = STDIN_FILENO;
 	else {
diff --git a/lib/libvarnishtools/vut.c b/lib/libvarnishtools/vut.c
index 5e24af4..6510256 100644
--- a/lib/libvarnishtools/vut.c
+++ b/lib/libvarnishtools/vut.c
@@ -181,7 +181,7 @@ VUT_Setup(void)
 	if (VUT.r_arg && VUT.vsm)
 		VUT_Error(1, "Can't have both -n and -r options");
 	if (VUT.r_arg)
-		c = VSL_CursorFile(VUT.vsl, VUT.r_arg);
+		c = VSL_CursorFile(VUT.vsl, VUT.r_arg, 0);
 	else {
 		if (VUT.vsm == NULL)
 			/* Default uses VSM with n=hostname */
@@ -190,7 +190,8 @@ VUT_Setup(void)
 		if (VSM_Open(VUT.vsm))
 			VUT_Error(1, "Can't open VSM file (%s)",
 			    VSM_Error(VUT.vsm));
-		c = VSL_CursorVSM(VUT.vsl, VUT.vsm, !VUT.d_opt);
+		c = VSL_CursorVSM(VUT.vsl, VUT.vsm,
+		    VUT.d_opt ? 0 : VSL_COPT_TAIL);
 	}
 	if (c == NULL)
 		VUT_Error(1, "Can't open log (%s)", VSL_Error(VUT.vsl));
@@ -294,7 +295,7 @@ VUT_Main(VSLQ_dispatch_f *func, void *priv)
 				VSM_ResetError(VUT.vsm);
 				continue;
 			}
-			c = VSL_CursorVSM(VUT.vsl, VUT.vsm, 1);
+			c = VSL_CursorVSM(VUT.vsl, VUT.vsm, VSL_COPT_TAIL);
 			if (c == NULL) {
 				VSL_ResetError(VUT.vsl);
 				VSM_Close(VUT.vsm);



More information about the varnish-commit mailing list