[master] c259f85 Add a -N option for use with utilities. This takes a VSM filename as argument, and will also disable the abandonment checks.
Tollef Fog Heen
tfheen at varnish-cache.org
Fri May 24 12:23:36 CEST 2013
commit c259f855945a6e0097956e1095ff85f8d40312d2
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Thu May 23 15:12:28 2013 +0200
Add a -N option for use with utilities. This takes a VSM filename as argument, and will also disable the abandonment checks.
This allows reading a stale VSM file (e.g. _VSM.keep saved from a
panic) for forensics gathering.
diff --git a/doc/sphinx/reference/varnishstat.rst b/doc/sphinx/reference/varnishstat.rst
index 3c5d541..703df32 100644
--- a/doc/sphinx/reference/varnishstat.rst
+++ b/doc/sphinx/reference/varnishstat.rst
@@ -19,7 +19,7 @@ Varnish Cache statistics
SYNOPSIS
========
-varnishstat [-1] [-x] [-j] [-f field_list] [-l] [-n varnish_name] [-V] [-w delay]
+varnishstat [-1] [-x] [-j] [-f field_list] [-l] [-n varnish_name] [-N filename] [-V] [-w delay]
DESCRIPTION
===========
@@ -38,6 +38,9 @@ The following options are available:
-n Specifies the name of the varnishd instance to get logs from. If -n is not specified, the host name
is used.
+-N Specify a the filename of a stale VSM instance. When using this
+ option the abandonment checking is disabled.
+
-V Display the version number and exit.
-w delay Wait delay seconds between updates. The default is 1. Can also be used with -1, -x or -j for repeated output.
diff --git a/include/vapi/vsc.h b/include/vapi/vsc.h
index e77ef64..ad5ee26 100644
--- a/include/vapi/vsc.h
+++ b/include/vapi/vsc.h
@@ -44,8 +44,8 @@ struct VSM_fantom;
* VSC level access functions
*/
-#define VSC_ARGS "f:n:"
-#define VSC_n_USAGE VSM_n_USAGE
+#define VSC_ARGS "f:n:N:"
+#define VSC_n_USAGE VSM_n_USAGE " " VSM_N_USAGE
#define VSC_f_USAGE "[-f field_name,...]"
#define VSC_USAGE VSC_n_USAGE \
VSC_f_USAGE
diff --git a/include/vapi/vsm.h b/include/vapi/vsm.h
index aa58835..caddcb9 100644
--- a/include/vapi/vsm.h
+++ b/include/vapi/vsm.h
@@ -96,6 +96,20 @@ int VSM_n_Arg(struct VSM_data *vd, const char *n_arg);
* <0 on failure, VSM_Error() returns diagnostic string
*/
+#define VSM_N_USAGE "[-N filename]"
+
+int VSM_N_Arg(struct VSM_data *vd, const char *N_arg);
+ /*
+ * Configure the library to use the specified VSM file name. This
+ * bypasses abandonment checks and allows looking at stale VSM
+ * files without a running Varnish instance.
+ *
+ * Can also be, and normally is done through VSC_Arg()/VSL_Arg().
+ *
+ * Returns:
+ * 1 on success
+ */
+
const char *VSM_Name(const struct VSM_data *vd);
/*
* Return the instance name.
diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c
index 06c11ce..ec4b385 100644
--- a/lib/libvarnishapi/vsc.c
+++ b/lib/libvarnishapi/vsc.c
@@ -253,6 +253,7 @@ VSC_Arg(struct VSM_data *vd, int arg, const char *opt)
switch (arg) {
case 'f': return (vsc_f_arg(vd, opt));
case 'n': return (VSM_n_Arg(vd, opt));
+ case 'N': return (VSM_N_Arg(vd, opt));
default:
return (0);
}
diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c
index ec73a98..f0b2602 100644
--- a/lib/libvarnishapi/vsm.c
+++ b/lib/libvarnishapi/vsm.c
@@ -141,6 +141,20 @@ VSM_n_Arg(struct VSM_data *vd, const char *opt)
/*--------------------------------------------------------------------*/
+int
+VSM_N_Arg(struct VSM_data *vd, const char *opt)
+{
+
+ CHECK_OBJ_NOTNULL(vd, VSM_MAGIC);
+ AN(opt);
+
+ REPLACE(vd->fname, opt);
+ vd->N_opt = 1;
+ return (1);
+}
+
+/*--------------------------------------------------------------------*/
+
const char *
VSM_Name(const struct VSM_data *vd)
{
@@ -191,7 +205,7 @@ VSM_Open(struct VSM_data *vd)
/* Already open */
return (0);
- if (!vd->n_opt)
+ if (!vd->n_opt && !vd->N_opt)
(void)VSM_n_Arg(vd, "");
AZ(vd->head);
@@ -224,7 +238,7 @@ VSM_Open(struct VSM_data *vd)
return (vsm_diag(vd, "Not a VSM file %s\n", vd->fname));
}
- if (slh.alloc_seq == 0) {
+ if (!vd->N_opt && slh.alloc_seq == 0) {
AZ(close(vd->vsm_fd));
vd->vsm_fd = -1;
return (vsm_diag(vd,
@@ -282,6 +296,9 @@ VSM_Abandoned(struct VSM_data *vd)
if (vd->head == NULL)
/* Not open */
return (1);
+ if (vd->N_opt)
+ /* No abandonment check should be done */
+ return (0);
if (!vd->head->alloc_seq)
/* Flag of abandonment set by mgt */
return (1);
@@ -328,11 +345,11 @@ VSM__itern(const struct VSM_data *vd, struct VSM_fantom *vf)
if (!vd->head)
return (0); /* Not open */
- if (vd->head->alloc_seq == 0)
+ if (!vd->N_opt && vd->head->alloc_seq == 0)
return (0); /* abandoned VSM */
- else if (vf->priv != 0) {
+ else if (vf->chunk != NULL) {
/* get next chunk */
- if (vf->priv != vd->head->alloc_seq)
+ if (!vd->N_opt && vf->priv != vd->head->alloc_seq)
return (0); /* changes during iteration */
if (vf->chunk->len == 0)
return (0); /* free'd during iteration */
@@ -376,7 +393,9 @@ VSM_StillValid(const struct VSM_data *vd, struct VSM_fantom *vf)
AN(vf);
if (!vd->head)
return (VSM_invalid);
- if (!vd->head->alloc_seq)
+ if (!vd->N_opt && !vd->head->alloc_seq)
+ return (VSM_invalid);
+ if (vf->chunk == NULL)
return (VSM_invalid);
if (vf->priv == vd->head->alloc_seq)
return (VSM_valid);
diff --git a/lib/libvarnishapi/vsm_api.h b/lib/libvarnishapi/vsm_api.h
index 04ebd7f..0c2dbd4 100644
--- a/lib/libvarnishapi/vsm_api.h
+++ b/lib/libvarnishapi/vsm_api.h
@@ -39,6 +39,7 @@ struct VSM_data {
char *n_opt;
char *fname;
+ int N_opt;
struct stat fstat;
More information about the varnish-commit
mailing list