Commit c259f855 authored by Martin Blix Grydeland's avatar Martin Blix Grydeland Committed by Tollef Fog Heen

Add a -N option for use with utilities. This takes a VSM filename as argument,...

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.
parent 22035ff1
...@@ -19,7 +19,7 @@ Varnish Cache statistics ...@@ -19,7 +19,7 @@ Varnish Cache statistics
SYNOPSIS 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 DESCRIPTION
=========== ===========
...@@ -38,6 +38,9 @@ The following options are available: ...@@ -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 -n Specifies the name of the varnishd instance to get logs from. If -n is not specified, the host name
is used. 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. -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. -w delay Wait delay seconds between updates. The default is 1. Can also be used with -1, -x or -j for repeated output.
......
...@@ -44,8 +44,8 @@ struct VSM_fantom; ...@@ -44,8 +44,8 @@ struct VSM_fantom;
* VSC level access functions * VSC level access functions
*/ */
#define VSC_ARGS "f:n:" #define VSC_ARGS "f:n:N:"
#define VSC_n_USAGE VSM_n_USAGE #define VSC_n_USAGE VSM_n_USAGE " " VSM_N_USAGE
#define VSC_f_USAGE "[-f field_name,...]" #define VSC_f_USAGE "[-f field_name,...]"
#define VSC_USAGE VSC_n_USAGE \ #define VSC_USAGE VSC_n_USAGE \
VSC_f_USAGE VSC_f_USAGE
......
...@@ -96,6 +96,20 @@ int VSM_n_Arg(struct VSM_data *vd, const char *n_arg); ...@@ -96,6 +96,20 @@ int VSM_n_Arg(struct VSM_data *vd, const char *n_arg);
* <0 on failure, VSM_Error() returns diagnostic string * <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); const char *VSM_Name(const struct VSM_data *vd);
/* /*
* Return the instance name. * Return the instance name.
......
...@@ -253,6 +253,7 @@ VSC_Arg(struct VSM_data *vd, int arg, const char *opt) ...@@ -253,6 +253,7 @@ VSC_Arg(struct VSM_data *vd, int arg, const char *opt)
switch (arg) { switch (arg) {
case 'f': return (vsc_f_arg(vd, opt)); case 'f': return (vsc_f_arg(vd, opt));
case 'n': return (VSM_n_Arg(vd, opt)); case 'n': return (VSM_n_Arg(vd, opt));
case 'N': return (VSM_N_Arg(vd, opt));
default: default:
return (0); return (0);
} }
......
...@@ -141,6 +141,20 @@ VSM_n_Arg(struct VSM_data *vd, const char *opt) ...@@ -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 * const char *
VSM_Name(const struct VSM_data *vd) VSM_Name(const struct VSM_data *vd)
{ {
...@@ -191,7 +205,7 @@ VSM_Open(struct VSM_data *vd) ...@@ -191,7 +205,7 @@ VSM_Open(struct VSM_data *vd)
/* Already open */ /* Already open */
return (0); return (0);
if (!vd->n_opt) if (!vd->n_opt && !vd->N_opt)
(void)VSM_n_Arg(vd, ""); (void)VSM_n_Arg(vd, "");
AZ(vd->head); AZ(vd->head);
...@@ -224,7 +238,7 @@ VSM_Open(struct VSM_data *vd) ...@@ -224,7 +238,7 @@ VSM_Open(struct VSM_data *vd)
return (vsm_diag(vd, "Not a VSM file %s\n", vd->fname)); 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)); AZ(close(vd->vsm_fd));
vd->vsm_fd = -1; vd->vsm_fd = -1;
return (vsm_diag(vd, return (vsm_diag(vd,
...@@ -282,6 +296,9 @@ VSM_Abandoned(struct VSM_data *vd) ...@@ -282,6 +296,9 @@ VSM_Abandoned(struct VSM_data *vd)
if (vd->head == NULL) if (vd->head == NULL)
/* Not open */ /* Not open */
return (1); return (1);
if (vd->N_opt)
/* No abandonment check should be done */
return (0);
if (!vd->head->alloc_seq) if (!vd->head->alloc_seq)
/* Flag of abandonment set by mgt */ /* Flag of abandonment set by mgt */
return (1); return (1);
...@@ -328,11 +345,11 @@ VSM__itern(const struct VSM_data *vd, struct VSM_fantom *vf) ...@@ -328,11 +345,11 @@ VSM__itern(const struct VSM_data *vd, struct VSM_fantom *vf)
if (!vd->head) if (!vd->head)
return (0); /* Not open */ return (0); /* Not open */
if (vd->head->alloc_seq == 0) if (!vd->N_opt && vd->head->alloc_seq == 0)
return (0); /* abandoned VSM */ return (0); /* abandoned VSM */
else if (vf->priv != 0) { else if (vf->chunk != NULL) {
/* get next chunk */ /* 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 */ return (0); /* changes during iteration */
if (vf->chunk->len == 0) if (vf->chunk->len == 0)
return (0); /* free'd during iteration */ return (0); /* free'd during iteration */
...@@ -376,7 +393,9 @@ VSM_StillValid(const struct VSM_data *vd, struct VSM_fantom *vf) ...@@ -376,7 +393,9 @@ VSM_StillValid(const struct VSM_data *vd, struct VSM_fantom *vf)
AN(vf); AN(vf);
if (!vd->head) if (!vd->head)
return (VSM_invalid); 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); return (VSM_invalid);
if (vf->priv == vd->head->alloc_seq) if (vf->priv == vd->head->alloc_seq)
return (VSM_valid); return (VSM_valid);
......
...@@ -39,6 +39,7 @@ struct VSM_data { ...@@ -39,6 +39,7 @@ struct VSM_data {
char *n_opt; char *n_opt;
char *fname; char *fname;
int N_opt;
struct stat fstat; struct stat fstat;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment