Mailing List Archive

r2477 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2008-02-15 12:52:41 +0100 (Fri, 15 Feb 2008)
New Revision: 2477

Modified:
trunk/varnish-cache/bin/varnishd/cache_cli.c
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/mgt.h
trunk/varnish-cache/bin/varnishd/mgt_child.c
trunk/varnish-cache/bin/varnishd/mgt_cli.c
trunk/varnish-cache/bin/varnishd/mgt_param.c
Log:
Add a paramter for maximum CLI buffer size and use it both in child
and manager. To take effect, it must be specified with -p on the
command line.

Use VLU for managers CLI handling.

Note CLI connection events on stderr.



Modified: trunk/varnish-cache/bin/varnishd/cache_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_cli.c 2008-02-15 11:27:25 UTC (rev 2476)
+++ trunk/varnish-cache/bin/varnishd/cache_cli.c 2008-02-15 11:52:41 UTC (rev 2477)
@@ -144,7 +144,7 @@
cli_thread = pthread_self();
cli->sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
XXXAN(cli->sb);
- vlu = VLU_New(cli, cli_vlu, 0);
+ vlu = VLU_New(cli, cli_vlu, params->cli_buffer);
XXXAN(vlu);
printf("Ready\n");
while (1) {

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h 2008-02-15 11:27:25 UTC (rev 2476)
+++ trunk/varnish-cache/bin/varnishd/heritage.h 2008-02-15 11:52:41 UTC (rev 2477)
@@ -138,6 +138,9 @@

/* Cache vbe_conns */
unsigned cache_vbe_conns;
+
+ /* CLI buffer size */
+ unsigned cli_buffer;
};

extern volatile struct params *params;

Modified: trunk/varnish-cache/bin/varnishd/mgt.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt.h 2008-02-15 11:27:25 UTC (rev 2476)
+++ trunk/varnish-cache/bin/varnishd/mgt.h 2008-02-15 11:52:41 UTC (rev 2477)
@@ -45,7 +45,7 @@
/* mgt_cli.c */

void mgt_cli_init(void);
-void mgt_cli_setup(int fdi, int fdo, int verbose);
+void mgt_cli_setup(int fdi, int fdo, int verbose, const char *ident);
int mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...);
void mgt_cli_start_child(int fdi, int fdo);
void mgt_cli_stop_child(void);

Modified: trunk/varnish-cache/bin/varnishd/mgt_child.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-02-15 11:27:25 UTC (rev 2476)
+++ trunk/varnish-cache/bin/varnishd/mgt_child.c 2008-02-15 11:52:41 UTC (rev 2477)
@@ -392,7 +392,7 @@
XXXAN(mgt_evb);

if (dflag)
- mgt_cli_setup(0, 1, 1);
+ mgt_cli_setup(0, 1, 1, "debug");

if (T_arg)
mgt_cli_telnet(T_arg);

Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2008-02-15 11:27:25 UTC (rev 2476)
+++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2008-02-15 11:52:41 UTC (rev 2477)
@@ -57,6 +57,7 @@
#include "mgt_event.h"
#include "shmlog.h"

+#include "vlu.h"
#include "vss.h"

static int cli_i = -1, cli_o = -1;
@@ -288,19 +289,20 @@
int fdi;
int fdo;
int verbose;
- char *buf;
- int nbuf; /* next free position in buf */
- int lbuf; /* length of buf */
+ struct vlu *vlu;
struct cli cli[1];
- char name[30];
+ char *name;
};

static int
mgt_cli_close(const struct cli_port *cp)
{

+ CHECK_OBJ_NOTNULL(cp, CLI_PORT_MAGIC);
+ fprintf(stderr, "CLI closing: %s\n", cp->name);
vsb_delete(cp->cli->sb);
- free(cp->buf);
+ VLU_Destroy(cp->vlu);
+ free(cp->name);
(void)close(cp->fdi);
if (cp->fdi == 0)
assert(open("/dev/null", O_RDONLY) == 0);
@@ -314,10 +316,26 @@
}

static int
+mgt_cli_vlu(void *priv, const char *p)
+{
+ struct cli_port *cp;
+
+ CAST_OBJ_NOTNULL(cp, priv, CLI_PORT_MAGIC);
+ vsb_clear(cp->cli->sb);
+ cli_dispatch(cp->cli, cli_proto, p);
+ vsb_finish(cp->cli->sb);
+ AZ(vsb_overflowed(cp->cli->sb));
+
+ /* send the result back */
+ if (cli_writeres(cp->fdo, cp->cli))
+ return (mgt_cli_close(cp));
+ return (0);
+}
+
+static int
mgt_cli_callback(const struct ev *e, int what)
{
struct cli_port *cp;
- char *p, *q;
int i;

CAST_OBJ_NOTNULL(cp, e->priv, CLI_PORT_MAGIC);
@@ -325,66 +343,32 @@
if (what & (EV_ERR | EV_HUP | EV_GONE))
return (mgt_cli_close(cp));

- /* grow the buffer if it is full */
- if (cp->nbuf == cp->lbuf) {
- cp->lbuf += cp->lbuf;
- cp->buf = realloc(cp->buf, cp->lbuf);
- XXXAN(cp->buf);
+ i = VLU_Fd(cp->fdi, cp->vlu);
+ if (i != 0) {
+ mgt_cli_close(cp);
+ return (1);
}
-
- /* read more data into the buffer */
- i = read(cp->fdi, cp->buf + cp->nbuf, cp->lbuf - cp->nbuf);
- if (i <= 0)
- return (mgt_cli_close(cp));
- cp->nbuf += i;
-
- for (p = q = cp->buf; q < cp->buf + cp->nbuf; ++q) {
- if (*q != '\n')
- continue;
- /* got a newline == got a command */
- *q = '\0';
- vsb_clear(cp->cli->sb);
- cli_dispatch(cp->cli, cli_proto, p);
- vsb_finish(cp->cli->sb);
- AZ(vsb_overflowed(cp->cli->sb));
-
- /* send the result back */
- if (cli_writeres(cp->fdo, cp->cli))
- return (mgt_cli_close(cp));
-
- /* ready for next command */
- p = q + 1;
- }
-
- /* see if there's any data left in the buffer */
- if (p != q) {
- assert(q == cp->buf + cp->nbuf);
- cp->nbuf -= (p - cp->buf);
- memmove(cp->buf, p, cp->nbuf);
- } else
- cp->nbuf = 0;
return (0);
}

void
-mgt_cli_setup(int fdi, int fdo, int verbose)
+mgt_cli_setup(int fdi, int fdo, int verbose, const char *ident)
{
struct cli_port *cp;

cp = calloc(sizeof *cp, 1);
XXXAN(cp);
+ cp->vlu = VLU_New(cp, mgt_cli_vlu, params->cli_buffer);

- sprintf(cp->name, "cli %d->%d", fdi, fdo);
+ asprintf(&cp->name, "cli %s fds{%d,%d}", ident, fdi, fdo);
+ XXXAN(cp->name);
+ fprintf(stderr, "CLI opened: %s\n", cp->name);
cp->magic = CLI_PORT_MAGIC;

cp->fdi = fdi;
cp->fdo = fdo;
cp->verbose = verbose;

- cp->lbuf = 4096;
- cp->buf = malloc(cp->lbuf);
- XXXAN(cp->buf);
-
cp->cli->sb = vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND);
XXXAN(cp->cli->sb);

@@ -403,6 +387,9 @@
struct sockaddr_storage addr;
socklen_t addrlen;
int i;
+ char abuf1[TCP_ADDRBUFSIZE], abuf2[TCP_ADDRBUFSIZE];
+ char pbuf1[TCP_PORTBUFSIZE], pbuf2[TCP_PORTBUFSIZE];
+ char *p;

(void)what;
addrlen = sizeof addr;
@@ -410,7 +397,14 @@
if (i < 0)
return (0);

- mgt_cli_setup(i, i, 0);
+ TCP_myname(ev->fd, abuf1, sizeof abuf1, pbuf1, sizeof pbuf1);
+ TCP_name((void*)&addr, addrlen, abuf2, sizeof abuf2,
+ pbuf2, sizeof pbuf2);
+ asprintf(&p, "telnet{%s:%s,%s:%s}", abuf2, pbuf2, abuf1, pbuf1);
+ XXXAN(p);
+
+ mgt_cli_setup(i, i, 0, p);
+ free(p);
return (0);
}


Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-02-15 11:27:25 UTC (rev 2476)
+++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2008-02-15 11:52:41 UTC (rev 2477)
@@ -613,6 +613,13 @@
"Cache vbe_conn's or rely on malloc, that's the question.",
EXPERIMENTAL,
"off", "bool" },
+ { "cli_buffer", tweak_uint, &master.cli_buffer, 4096, UINT_MAX,
+ "Size of buffer for CLI input."
+ "\nYou may need to increase this if you have big VCL files "
+ "and use the vcl.inline CLI command.\n"
+ "NB: Must be specified with -p to have effect.\n",
+ 0,
+ "8192", "bytes" },
{ NULL, NULL, NULL }
};