[master] 99e5297 Allow VSLQ to not have a cursor set

Martin Blix Grydeland martin at varnish-software.com
Thu Apr 9 15:16:28 CEST 2015


commit 99e52973e465c234b83787d307c3113926730a4e
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Mar 31 17:24:39 2015 +0200

    Allow VSLQ to not have a cursor set
    
    This is to avoid having to delete the VSLQ context during VSM reopen.
    
    Also allows parsing of the query without having to open the VSM first,
    to facilitate early error messages.

diff --git a/include/vapi/vsl.h b/include/vapi/vsl.h
index 19daecd..3a09054 100644
--- a/include/vapi/vsl.h
+++ b/include/vapi/vsl.h
@@ -463,12 +463,14 @@ VSLQ_dispatch_f VSL_WriteTransactions;
 struct VSLQ *VSLQ_New(struct VSL_data *vsl, struct VSL_cursor **cp,
     enum VSL_grouping_e grouping, const char *query);
 	/*
-	 * Create a new query context using cp. On success cp is NULLed,
-	 * and will be deleted when deleting the query.
+	 * Create a new query context.
+	 *
+	 * If cp is not NULL, the cursor pointed to by cp will be
+	 * transferred to the query, and *cp set to NULL.
 	 *
 	 * Arguments:
 	 *       vsl: The VSL_data context
-	 *        cp: The cursor to use
+	 *        cp: Pointer to the cursor to use or NULL
 	 *  grouping: VXID grouping to report on
 	 *     query: Query match expression
 	 *
diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c
index 2594691..0aa68a9 100644
--- a/lib/libvarnishapi/vsl_dispatch.c
+++ b/lib/libvarnishapi/vsl_dispatch.c
@@ -1054,7 +1054,6 @@ VSLQ_New(struct VSL_data *vsl, struct VSL_cursor **cp,
 	struct VSLQ *vslq;
 
 	CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
-	AN(cp);
 	if (grouping > VSL_g_session) {
 		(void)vsl_diag(vsl, "Illegal query grouping");
 		return (NULL);
@@ -1069,8 +1068,10 @@ VSLQ_New(struct VSL_data *vsl, struct VSL_cursor **cp,
 	ALLOC_OBJ(vslq, VSLQ_MAGIC);
 	AN(vslq);
 	vslq->vsl = vsl;
-	vslq->c = *cp;
-	*cp = NULL;
+	if (cp != NULL) {
+		vslq->c = *cp;
+		*cp = NULL;
+	}
 	vslq->grouping = grouping;
 	vslq->query = query;
 
@@ -1109,8 +1110,10 @@ VSLQ_Delete(struct VSLQ **pvslq)
 	(void)VSLQ_Flush(vslq, NULL, NULL);
 	AZ(vslq->n_outstanding);
 
-	VSL_DeleteCursor(vslq->c);
-	vslq->c = NULL;
+	if (vslq->c != NULL) {
+		VSL_DeleteCursor(vslq->c);
+		vslq->c = NULL;
+	}
 
 	if (vslq->query != NULL)
 		vslq_deletequery(&vslq->query);
@@ -1290,6 +1293,10 @@ VSLQ_Dispatch(struct VSLQ *vslq, VSLQ_dispatch_f *func, void *priv)
 
 	CHECK_OBJ_NOTNULL(vslq, VSLQ_MAGIC);
 
+	/* Check that we have a cursor */
+	if (vslq->c == NULL)
+		return (-2);
+
 	if (vslq->grouping == VSL_g_raw)
 		return (vslq_raw(vslq, func, priv));
 



More information about the varnish-commit mailing list