[master] 445ba2b Implement VSL_ResetCursor
Martin Blix Grydeland
martin at varnish-cache.org
Wed May 15 14:46:14 CEST 2013
commit 445ba2bbf59e5bae7b1df283471d9de8d1251481
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Mon Apr 29 17:12:17 2013 +0200
Implement VSL_ResetCursor
diff --git a/include/vapi/vsl.h b/include/vapi/vsl.h
index 6ee0e33..54014cd 100644
--- a/include/vapi/vsl.h
+++ b/include/vapi/vsl.h
@@ -121,6 +121,17 @@ void VSL_DeleteCursor(struct VSL_cursor *c);
* Delete the cursor pointed to by c
*/
+int VSL_ResetCursor(struct VSL_cursor *c);
+ /*
+ * Reset the cursor position to the head, so that the next call to
+ * VSL_Next returns the first record. For VSM cursor, it will
+ * point close to the head of the log, but at least 2 segments away
+ * from the tail.
+ *
+ * Return values:
+ * -1: Operation not supported
+ */
+
int VSL_Next(struct VSL_cursor *c);
/*
* Return raw pointer to next VSL record.
diff --git a/lib/libvarnishapi/vsl_api.h b/lib/libvarnishapi/vsl_api.h
index 8b70098..f03812e 100644
--- a/lib/libvarnishapi/vsl_api.h
+++ b/lib/libvarnishapi/vsl_api.h
@@ -40,6 +40,7 @@ int vsl_diag(struct VSL_data *vsl, const char *fmt, ...)
typedef void vslc_delete_f(void *);
typedef int vslc_next_f(void *);
+typedef int vslc_reset_f(void *);
struct vslc {
struct VSL_cursor c;
@@ -48,6 +49,7 @@ struct vslc {
vslc_delete_f *delete;
vslc_next_f *next;
+ vslc_reset_f *reset;
};
struct VSL_data {
diff --git a/lib/libvarnishapi/vsl_cursor.c b/lib/libvarnishapi/vsl_cursor.c
index 65262d1..f0d535b 100644
--- a/lib/libvarnishapi/vsl_cursor.c
+++ b/lib/libvarnishapi/vsl_cursor.c
@@ -144,13 +144,37 @@ vslc_vsm_next(void *cursor)
}
}
+static int
+vslc_vsm_reset(void *cursor)
+{
+ struct vslc_vsm *c;
+ unsigned segment;
+
+ CAST_OBJ_NOTNULL(c, cursor, VSLC_VSM_MAGIC);
+
+ /*
+ * Starting (VSL_SEGMENTS - 3) behind varnishd. This way
+ * even if varnishd wraps immediately, we'll still have a
+ * full segment worth of log before the general constraint
+ * of at least 2 segments apart will be broken
+ */
+ segment = (c->head->segment + 3) % VSL_SEGMENTS;
+ if (c->head->segments[segment] < 0)
+ segment = 0;
+ assert(c->head->segments[segment] >= 0);
+ c->next = c->head->log + c->head->segments[segment];
+ c->seq = c->head->seq;
+ c->c.c.ptr = NULL;
+
+ return (0);
+}
+
struct VSL_cursor *
VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, int tail)
{
struct vslc_vsm *c;
struct VSM_fantom vf;
struct VSL_head *head;
- unsigned segment;
CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
CHECK_OBJ_NOTNULL(vsm, VSM_MAGIC);
@@ -178,6 +202,7 @@ VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, int tail)
c->c.magic = VSLC_MAGIC;
c->c.delete = vslc_vsm_delete;
c->c.next = vslc_vsm_next;
+ c->c.reset = vslc_vsm_reset;
c->vsm = vsm;
c->vf = vf;
@@ -190,20 +215,9 @@ VSL_CursorVSM(struct VSL_data *vsl, struct VSM_data *vsm, int tail)
c->next = c->head->log + c->head->segments[c->head->segment];
while (c->next < c->end && *c->next != VSL_ENDMARKER)
c->next = VSL_NEXT(c->next);
- } else {
- /*
- * Starting (VSL_SEGMENTS - 3) behind varnishd. This way
- * even if varnishd wraps immediately, we'll still have a
- * full segment worth of log before the general constraint
- * of at least 2 segments apart will be broken
- */
- segment = (c->head->segment + 3) % VSL_SEGMENTS;
- if (c->head->segments[segment] < 0)
- segment = 0;
- assert(c->head->segments[segment] >= 0);
- c->next = c->head->log + c->head->segments[segment];
- }
- c->seq = c->head->seq;
+ c->seq = c->head->seq;
+ } else
+ AZ(vslc_vsm_reset(&c->c));
return (&c->c.c);
}
@@ -284,6 +298,14 @@ vslc_file_next(void *cursor)
return (1);
}
+static int
+vslc_file_reset(void *cursor)
+{
+ (void)cursor;
+ /* XXX: Implement me */
+ return (-1);
+}
+
struct VSL_cursor *
VSL_CursorFile(struct VSL_data *vsl, const char *name)
{
@@ -328,6 +350,7 @@ VSL_CursorFile(struct VSL_data *vsl, const char *name)
c->c.magic = VSLC_MAGIC;
c->c.delete = vslc_file_delete;
c->c.next = vslc_file_next;
+ c->c.reset = vslc_file_reset;
c->fd = fd;
c->buflen = BUFSIZ;
@@ -349,6 +372,17 @@ VSL_DeleteCursor(struct VSL_cursor *cursor)
}
int
+VSL_ResetCursor(struct VSL_cursor *cursor)
+{
+ struct vslc *c;
+
+ CAST_OBJ_NOTNULL(c, (void *)cursor, VSLC_MAGIC);
+ if (c->reset == NULL)
+ return (-1);
+ return ((c->reset)(c));
+}
+
+int
VSL_Next(struct VSL_cursor *cursor)
{
struct vslc *c;
More information about the varnish-commit
mailing list