Commit 2ea23705 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Remove use of 'active' flag in sandbox context

Instead of using a 'gboolean active' flag to track if the
sandbox is active, just rely on 'domain != NULL'. This
facilitates overriding start/stop methods in subclasses
Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent a2638a59
...@@ -50,7 +50,6 @@ struct _GVirSandboxContextPrivate ...@@ -50,7 +50,6 @@ struct _GVirSandboxContextPrivate
GVirConnection *connection; GVirConnection *connection;
GVirDomain *domain; GVirDomain *domain;
GVirSandboxConfig *config; GVirSandboxConfig *config;
gboolean active;
gboolean autodestroy; gboolean autodestroy;
}; };
...@@ -159,11 +158,9 @@ static void gvir_sandbox_context_finalize(GObject *object) ...@@ -159,11 +158,9 @@ static void gvir_sandbox_context_finalize(GObject *object)
GVirSandboxContext *ctxt = GVIR_SANDBOX_CONTEXT(object); GVirSandboxContext *ctxt = GVIR_SANDBOX_CONTEXT(object);
GVirSandboxContextPrivate *priv = ctxt->priv; GVirSandboxContextPrivate *priv = ctxt->priv;
if (priv->active) if (priv->domain)
gvir_sandbox_context_stop(ctxt, NULL); gvir_sandbox_context_stop(ctxt, NULL);
if (priv->domain)
g_object_unref(priv->domain);
if (priv->connection) if (priv->connection)
g_object_unref(priv->connection); g_object_unref(priv->connection);
if (priv->config) if (priv->config)
...@@ -473,7 +470,6 @@ static gboolean gvir_sandbox_context_start_default(GVirSandboxContext *ctxt, GEr ...@@ -473,7 +470,6 @@ static gboolean gvir_sandbox_context_start_default(GVirSandboxContext *ctxt, GEr
if (!gvir_sandbox_context_clean_post_start(ctxt, builder, error)) if (!gvir_sandbox_context_clean_post_start(ctxt, builder, error))
goto error; goto error;
priv->active = TRUE;
ret = TRUE; ret = TRUE;
cleanup: cleanup:
g_free(statedir); g_free(statedir);
...@@ -502,7 +498,7 @@ static gboolean gvir_sandbox_context_attach_default(GVirSandboxContext *ctxt, GE ...@@ -502,7 +498,7 @@ static gboolean gvir_sandbox_context_attach_default(GVirSandboxContext *ctxt, GE
{ {
GVirSandboxContextPrivate *priv = ctxt->priv; GVirSandboxContextPrivate *priv = ctxt->priv;
if (priv->active) { if (priv->domain) {
*error = g_error_new(GVIR_SANDBOX_CONTEXT_ERROR, 0, *error = g_error_new(GVIR_SANDBOX_CONTEXT_ERROR, 0,
"%s", "A previously built sandbox still exists"); "%s", "A previously built sandbox still exists");
return FALSE; return FALSE;
...@@ -520,8 +516,6 @@ static gboolean gvir_sandbox_context_attach_default(GVirSandboxContext *ctxt, GE ...@@ -520,8 +516,6 @@ static gboolean gvir_sandbox_context_attach_default(GVirSandboxContext *ctxt, GE
return FALSE; return FALSE;
} }
priv->active = TRUE;
return TRUE; return TRUE;
} }
...@@ -530,15 +524,11 @@ static gboolean gvir_sandbox_context_detach_default(GVirSandboxContext *ctxt, GE ...@@ -530,15 +524,11 @@ static gboolean gvir_sandbox_context_detach_default(GVirSandboxContext *ctxt, GE
{ {
GVirSandboxContextPrivate *priv = ctxt->priv; GVirSandboxContextPrivate *priv = ctxt->priv;
if (!priv->active) if (!priv->domain)
return TRUE; return TRUE;
if (priv->domain) { g_object_unref(priv->domain);
g_object_unref(priv->domain); priv->domain = NULL;
priv->domain = NULL;
}
priv->active = FALSE;
return TRUE; return TRUE;
} }
...@@ -550,16 +540,14 @@ static gboolean gvir_sandbox_context_stop_default(GVirSandboxContext *ctxt, GErr ...@@ -550,16 +540,14 @@ static gboolean gvir_sandbox_context_stop_default(GVirSandboxContext *ctxt, GErr
GVirSandboxBuilder *builder; GVirSandboxBuilder *builder;
gboolean ret = TRUE; gboolean ret = TRUE;
if (!priv->active) if (!priv->domain)
return TRUE; return TRUE;
if (priv->domain) { if (!gvir_domain_stop(priv->domain, 0, error))
if (!gvir_domain_stop(priv->domain, 0, error)) ret = FALSE;
ret = FALSE;
g_object_unref(priv->domain); g_object_unref(priv->domain);
priv->domain = NULL; priv->domain = NULL;
}
if (!(builder = gvir_sandbox_builder_for_connection(priv->connection, if (!(builder = gvir_sandbox_builder_for_connection(priv->connection,
error))) error)))
...@@ -572,8 +560,6 @@ static gboolean gvir_sandbox_context_stop_default(GVirSandboxContext *ctxt, GErr ...@@ -572,8 +560,6 @@ static gboolean gvir_sandbox_context_stop_default(GVirSandboxContext *ctxt, GErr
if (builder) if (builder)
g_object_unref(builder); g_object_unref(builder);
priv->active = FALSE;
return ret; return ret;
} }
...@@ -663,3 +649,9 @@ gboolean gvir_sandbox_context_detach(GVirSandboxContext *ctxt, GError **error) ...@@ -663,3 +649,9 @@ gboolean gvir_sandbox_context_detach(GVirSandboxContext *ctxt, GError **error)
{ {
return GVIR_SANDBOX_CONTEXT_GET_CLASS(ctxt)->detach(ctxt, error); return GVIR_SANDBOX_CONTEXT_GET_CLASS(ctxt)->detach(ctxt, error);
} }
gboolean gvir_sandbox_context_is_attached(GVirSandboxContext *ctxt)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
return priv->domain != NULL;
}
...@@ -77,6 +77,8 @@ gboolean gvir_sandbox_context_stop(GVirSandboxContext *ctxt, GError **error); ...@@ -77,6 +77,8 @@ gboolean gvir_sandbox_context_stop(GVirSandboxContext *ctxt, GError **error);
gboolean gvir_sandbox_context_attach(GVirSandboxContext *ctxt, GError **error); gboolean gvir_sandbox_context_attach(GVirSandboxContext *ctxt, GError **error);
gboolean gvir_sandbox_context_detach(GVirSandboxContext *ctxt, GError **error); gboolean gvir_sandbox_context_detach(GVirSandboxContext *ctxt, GError **error);
gboolean gvir_sandbox_context_is_attached(GVirSandboxContext *ctxt);
GVirDomain *gvir_sandbox_context_get_domain(GVirSandboxContext *ctxt, GVirDomain *gvir_sandbox_context_get_domain(GVirSandboxContext *ctxt,
GError **error); GError **error);
GVirConnection *gvir_sandbox_context_get_connection(GVirSandboxContext *ctxt); GVirConnection *gvir_sandbox_context_get_connection(GVirSandboxContext *ctxt);
......
...@@ -153,6 +153,7 @@ LIBVIRT_SANDBOX_0.2.1 { ...@@ -153,6 +153,7 @@ LIBVIRT_SANDBOX_0.2.1 {
gvir_sandbox_context_get_log_console; gvir_sandbox_context_get_log_console;
gvir_sandbox_context_get_shell_console; gvir_sandbox_context_get_shell_console;
gvir_sandbox_context_get_autodestroy; gvir_sandbox_context_get_autodestroy;
gvir_sandbox_context_is_attached;
gvir_sandbox_context_set_autodestroy; gvir_sandbox_context_set_autodestroy;
gvir_sandbox_context_start; gvir_sandbox_context_start;
gvir_sandbox_context_stop; gvir_sandbox_context_stop;
......
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