should be adjustable at runtime.
We need to make adjustments in such a way that a restart of the child also
uses the new paramters.
We can either do this by parsing the CLI in both mgt+child and have both
update their private copy, or we can parse it only in one of them and
update a shared copy.
We opt for the latter method.
Add a "struct params" which holds the adjustable parameters and put on
in the shmlog segment, between struct shmloghead and the round-robin
buffer.
Move parameters from heritage to params.
We put it there without exposing it in struct shmloghead which is
the public view of the shared memory because we do not want to make
it a public API or even to tempt people to think that it is one.
Now I just need to add the CLI functions to actually twiddle the
parameters.
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@835
d4fa192b-c00b-0410-8231-
f00ffab90ce4
struct vbe_conn *vbc;
unsigned char *p;
- vbc = calloc(sizeof *vbc + heritage.mem_workspace * 2, 1);
+ vbc = calloc(sizeof *vbc + params->mem_workspace * 2, 1);
if (vbc == NULL)
return (NULL);
VSL_stats->n_vbe_conn++;
vbc->http2 = &vbc->http_mem[1];
vbc->fd = -1;
p = (void *)(vbc + 1);
- http_Setup(vbc->http, p, heritage.mem_workspace);
- p += heritage.mem_workspace;
- http_Setup(vbc->http2, p, heritage.mem_workspace);
+ http_Setup(vbc->http, p, params->mem_workspace);
+ p += params->mem_workspace;
+ http_Setup(vbc->http2, p, params->mem_workspace);
return (vbc);
}
} else {
/* If we are a dynamic thread, time out and die */
AZ(clock_gettime(CLOCK_REALTIME, &ts));
- ts.tv_sec += heritage.wthread_timeout;
+ ts.tv_sec += params->wthread_timeout;
if (pthread_cond_timedwait(&w->cv, &wrk_mtx, &ts)) {
VSL_stats->n_wrk--;
TAILQ_REMOVE(&wrk_idle, w, list);
wrk_overflow++;
/* Can we create more threads ? */
- if (VSL_stats->n_wrk >= heritage.wthread_max) {
+ if (VSL_stats->n_wrk >= params->wthread_max) {
VSL_stats->n_wrk_max++;
AZ(pthread_mutex_unlock(&wrk_mtx));
return;
AZ(pthread_mutex_init(&wrk_mtx, NULL));
- VSL(SLT_Debug, 0, "Starting %u worker threads", heritage.wthread_min);
- for (i = 0; i < heritage.wthread_min; i++) {
+ VSL(SLT_Debug, 0, "Starting %u worker threads", params->wthread_min);
+ for (i = 0; i < params->wthread_min; i++) {
VSL_stats->n_wrk++;
AZ(pthread_create(&tp, NULL, wrk_thread, &i));
AZ(pthread_detach(tp));
struct sessmem *sm;
sm = calloc(
- sizeof *sm + heritage.mem_workspace,
+ sizeof *sm + params->mem_workspace,
1);
if (sm == NULL)
return (NULL);
sm->sess.sockaddrlen = len;
}
- http_Setup(&sm->http, (void *)(sm + 1), heritage.mem_workspace);
+ http_Setup(&sm->http, (void *)(sm + 1), params->mem_workspace);
sm->sess.acct.first = time(NULL);
/* Hash method */
struct hash_slinger *hash;
+};
+
+struct params {
+
+ /* TTL used for lack of anything better */
unsigned default_ttl;
/* Worker threads */
unsigned mem_workspace;
};
+extern struct params *params;
extern struct heritage heritage;
void child_main(void);
retirement_age = h_expires - h_date;
}
if (retirement_age == INT_MAX)
- retirement_age = heritage.default_ttl;
+ retirement_age = params->default_ttl;
ttd = obj->entered + retirement_age;
}
/*--------------------------------------------------------------------*/
-void
-VSL_MgtInit(const char *fn, unsigned size)
+static int
+vsl_goodold(int fd)
{
struct shmloghead slh;
- int i = 0;
+ int i;
memset(&slh, 0, sizeof slh); /* XXX: for flexelint */
- heritage.vsl_fd = open(fn, O_RDWR, 0644);
- if (heritage.vsl_fd >= 0)
- i = read(heritage.vsl_fd, &slh, sizeof slh);
- if (heritage.vsl_fd < 0 || i != sizeof slh ||
- slh.magic != SHMLOGHEAD_MAGIC ||
- slh.hdrsize != sizeof slh) {
- /* XXX more checks */
+ i = read(fd, &slh, sizeof slh);
+ if (i != sizeof slh)
+ return (0);
+ if (slh.magic != SHMLOGHEAD_MAGIC)
+ return (0);
+ if (slh.hdrsize != sizeof slh)
+ return (0);
+ if (slh.start != sizeof slh + sizeof *params)
+ return (0);
+ /* XXX more checks */
+ heritage.vsl_size = slh.size + slh.start;
+ return (1);
+}
+static void
+vsl_buildnew(const char *fn, unsigned size)
+{
+ struct shmloghead slh;
+ int i;
+
+ (void)unlink(fn);
+ heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0644);
+ if (heritage.vsl_fd < 0) {
+ fprintf(stderr, "Could not open %s: %s\n",
+ fn, strerror(errno));
+ exit (1);
+ }
+
+ memset(&slh, 0, sizeof slh);
+ slh.magic = SHMLOGHEAD_MAGIC;
+ slh.hdrsize = sizeof slh;
+ slh.size = size;
+ slh.ptr = 0;
+ slh.start = sizeof slh + sizeof *params;
+ i = write(heritage.vsl_fd, &slh, sizeof slh);
+ assert(i == sizeof slh);
+ heritage.vsl_size = slh.start + size;
+ AZ(ftruncate(heritage.vsl_fd, (off_t)heritage.vsl_size));
+}
+
+void
+VSL_MgtInit(const char *fn, unsigned size)
+{
+ int i;
+ struct params *pp;
+
+ i = open(fn, O_RDWR, 0644);
+ if (i >= 0 && vsl_goodold(i)) {
+ fprintf(stderr, "Using old SHMFILE\n");
+ heritage.vsl_fd = i;
+ } else {
fprintf(stderr, "Creating new SHMFILE\n");
- if (heritage.vsl_fd >= 0)
- close(heritage.vsl_fd);
- (void)unlink(fn);
- heritage.vsl_fd = open(fn, O_RDWR | O_CREAT, 0644);
- if (heritage.vsl_fd < 0) {
- fprintf(stderr, "Could not open %s: %s\n",
- fn, strerror(errno));
- exit (1);
- }
-
- memset(&slh, 0, sizeof slh);
- slh.magic = SHMLOGHEAD_MAGIC;
- slh.hdrsize = sizeof slh;
- slh.size = size;
- slh.ptr = 0;
- slh.start = sizeof slh;
- AZ(lseek(heritage.vsl_fd, 0, SEEK_SET));
- i = write(heritage.vsl_fd, &slh, sizeof slh);
- assert(i == sizeof slh);
- AZ(ftruncate(heritage.vsl_fd, (off_t)sizeof slh + (off_t)size));
+ (void)close(i);
+ vsl_buildnew(fn, size);
}
- heritage.vsl_size = slh.size + slh.start;
loghead = mmap(NULL, heritage.vsl_size,
PROT_READ|PROT_WRITE,
heritage.vsl_fd, 0);
assert(loghead != MAP_FAILED);
VSL_stats = &loghead->stats;
+ pp = (void *)(loghead + 1);
+ memcpy(pp, params, sizeof *pp);
+ params = pp;
}
#endif
struct heritage heritage;
+struct params *params;
/*--------------------------------------------------------------------*/
usage();
if (ua < 1)
usage();
- heritage.wthread_min = ua;
- heritage.wthread_max = ua;
- heritage.wthread_timeout = 10;
+ params->wthread_min = ua;
+ params->wthread_max = ua;
+ params->wthread_timeout = 10;
if (i >= 2)
- heritage.wthread_max = ub;
+ params->wthread_max = ub;
if (i >= 3)
- heritage.wthread_timeout = uc;
+ params->wthread_timeout = uc;
}
/*--------------------------------------------------------------------
const char *sflag = "file";
const char *hflag = "classic";
const char *Tflag = NULL;
+ struct params param;
setbuf(stdout, NULL);
setbuf(stderr, NULL);
+ memset(¶m, 0, sizeof param);
+ params = ¶m;
mgt_vcc_init();
- heritage.default_ttl = 120;
- heritage.wthread_min = 1;
- heritage.wthread_max = UINT_MAX;
- heritage.wthread_timeout = 10;
- heritage.mem_workspace = 4096;
+ params->default_ttl = 120;
+ params->wthread_min = 1;
+ params->wthread_max = UINT_MAX;
+ params->wthread_timeout = 10;
+ params->mem_workspace = 4096;
while ((o = getopt(argc, argv, "b:df:h:p:s:t:T:Vw:")) != -1)
switch (o) {
sflag = optarg;
break;
case 't':
- heritage.default_ttl = strtoul(optarg, NULL, 0);
+ params->default_ttl = strtoul(optarg, NULL, 0);
break;
case 'T':
Tflag = optarg;