Commit f637f06a authored by Nils Goroll's avatar Nils Goroll

varnish now has event workspace, use it. Fail gracefully for out-of-workspace

parent 3b72a3bd
...@@ -61,7 +61,6 @@ struct shard_change { ...@@ -61,7 +61,6 @@ struct shard_change {
#define SHARD_CHANGE_MAGIC 0xdff5c9a6 #define SHARD_CHANGE_MAGIC 0xdff5c9a6
const struct sharddir *shardd; const struct sharddir *shardd;
void *space; void *space;
struct ws *ws;
VSTAILQ_HEAD(,shard_change_task) tasks; VSTAILQ_HEAD(,shard_change_task) tasks;
}; };
...@@ -82,15 +81,6 @@ struct backend_reconfig { ...@@ -82,15 +81,6 @@ struct backend_reconfig {
* for now, we allow to only reconfigure one shard director at a time. * for now, we allow to only reconfigure one shard director at a time.
*/ */
static void
shard_change_free_ws(void *priv)
{
struct shard_change *f;
CAST_OBJ_NOTNULL(f, priv, SHARD_CHANGE_MAGIC);
AN(f->space);
free(f->space);
}
static struct shard_change * static struct shard_change *
shard_change_get(VRT_CTX, struct vmod_priv *priv, shard_change_get(VRT_CTX, struct vmod_priv *priv,
const struct sharddir * const shardd) const struct sharddir * const shardd)
...@@ -111,28 +101,14 @@ shard_change_get(VRT_CTX, struct vmod_priv *priv, ...@@ -111,28 +101,14 @@ shard_change_get(VRT_CTX, struct vmod_priv *priv,
return (change); return (change);
} }
if (ctx->ws) {
change = WS_Alloc(ctx->ws, sizeof(*change)); change = WS_Alloc(ctx->ws, sizeof(*change));
AN(change); if (change == NULL) {
shard_err0(ctx, shardd, "could not get workspace");
return NULL;
}
INIT_OBJ(change, SHARD_CHANGE_MAGIC); INIT_OBJ(change, SHARD_CHANGE_MAGIC);
change->space = NULL; change->space = NULL;
change->ws = ctx->ws;
} else {
// XXX should be default in core #2063
struct ws *ws;
char *space = malloc(cache_param->workspace_client);
AN(space);
ws = (void *)space;
WS_Init(ws, "shd", space + sizeof(*ws),
cache_param->workspace_client - sizeof(*ws));
change = WS_Alloc(ws, sizeof(*change));
AN(change);
INIT_OBJ(change, SHARD_CHANGE_MAGIC);
change->space = space;
change->ws = ws;
priv->free = shard_change_free_ws;
}
change->shardd = shardd; change->shardd = shardd;
VSTAILQ_INIT(&change->tasks); VSTAILQ_INIT(&change->tasks);
priv->priv = change; priv->priv = change;
...@@ -150,15 +126,19 @@ shard_change_finish(struct shard_change *change) ...@@ -150,15 +126,19 @@ shard_change_finish(struct shard_change *change)
} }
static void static void
shard_change_task_add(struct shard_change *change, shard_change_task_add(VRT_CTX, struct shard_change *change,
enum shard_change_task_e task_e, void *priv) enum shard_change_task_e task_e, void *priv)
{ {
struct shard_change_task *task; struct shard_change_task *task;
CHECK_OBJ_NOTNULL(change, SHARD_CHANGE_MAGIC); CHECK_OBJ_NOTNULL(change, SHARD_CHANGE_MAGIC);
task = WS_Alloc(change->ws, sizeof(*task)); task = WS_Alloc(ctx->ws, sizeof(*task));
AN(task); if (task == NULL) {
shard_err0(ctx, change->shardd,
"could not get workspace for task");
return;
}
INIT_OBJ(task, SHARD_CHANGE_TASK_MAGIC); INIT_OBJ(task, SHARD_CHANGE_TASK_MAGIC);
task->task = task_e; task->task = task_e;
task->priv = priv; task->priv = priv;
...@@ -181,7 +161,7 @@ shard_change_task_backend(VRT_CTX, ...@@ -181,7 +161,7 @@ shard_change_task_backend(VRT_CTX,
if (change == NULL) if (change == NULL)
return 0; return 0;
b = WS_Alloc(change->ws, sizeof(*b)); b = WS_Alloc(ctx->ws, sizeof(*b));
if (b == NULL) { if (b == NULL) {
shard_err(ctx, shardd, ".%s_backend() WS_Alloc() failed", shard_err(ctx, shardd, ".%s_backend() WS_Alloc() failed",
task_e == ADD_BE ? "add" : "remove"); task_e == ADD_BE ? "add" : "remove");
...@@ -192,7 +172,7 @@ shard_change_task_backend(VRT_CTX, ...@@ -192,7 +172,7 @@ shard_change_task_backend(VRT_CTX,
b->ident = ident != NULL && *ident != '\0' ? ident : NULL; b->ident = ident != NULL && *ident != '\0' ? ident : NULL;
b->rampup = rampup; b->rampup = rampup;
shard_change_task_add(change, task_e, b); shard_change_task_add(ctx, change, task_e, b);
return 1; return 1;
} }
...@@ -229,7 +209,7 @@ shardcfg_clear(VRT_CTX, struct vmod_priv *priv, struct sharddir *shardd) ...@@ -229,7 +209,7 @@ shardcfg_clear(VRT_CTX, struct vmod_priv *priv, struct sharddir *shardd)
if (change == NULL) if (change == NULL)
return 0; return 0;
shard_change_task_add(change, CLEAR, NULL); shard_change_task_add(ctx, change, CLEAR, NULL);
return 1; return 1;
} }
......
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