Commit 36c6e1a9 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Add support for changing autodestroy behaviour

Service containers need to exist across libvirtd restarts, so
they should not be set to auto-destroy
Signed-off-by: 's avatarDaniel P. Berrange <berrange@redhat.com>
parent 8afce4d9
......@@ -139,5 +139,6 @@ GVirSandboxContextService *gvir_sandbox_context_service_new(GVirConnection *conn
return GVIR_SANDBOX_CONTEXT_SERVICE(g_object_new(GVIR_SANDBOX_TYPE_CONTEXT_SERVICE,
"connection", connection,
"config", config,
"autodestroy", FALSE,
NULL));
}
......@@ -53,6 +53,7 @@ struct _GVirSandboxContextPrivate
GVirSandboxConfig *config;
GVirSandboxConsole *console;
gboolean active;
gboolean autodestroy;
GVirSandboxBuilder *builder;
};
......@@ -66,6 +67,7 @@ enum {
PROP_CONFIG,
PROP_DOMAIN,
PROP_CONNECTION,
PROP_AUTODESTROY,
};
enum {
......@@ -87,9 +89,9 @@ static gboolean gvir_sandbox_context_prestart(GVirSandboxContext *ctxt,
GError **error);
static void gvir_sandbox_context_get_property(GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GVirSandboxContext *ctxt = GVIR_SANDBOX_CONTEXT(object);
GVirSandboxContextPrivate *priv = ctxt->priv;
......@@ -107,6 +109,10 @@ static void gvir_sandbox_context_get_property(GObject *object,
g_value_set_object(value, priv->connection);
break;
case PROP_AUTODESTROY:
g_value_set_boolean(value, priv->autodestroy);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
......@@ -114,9 +120,9 @@ static void gvir_sandbox_context_get_property(GObject *object,
static void gvir_sandbox_context_set_property(GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GVirSandboxContext *ctxt = GVIR_SANDBOX_CONTEXT(object);
GVirSandboxContextPrivate *priv = ctxt->priv;
......@@ -140,6 +146,10 @@ static void gvir_sandbox_context_set_property(GObject *object,
priv->connection = g_value_dup_object(value);
break;
case PROP_AUTODESTROY:
priv->autodestroy = g_value_get_boolean(value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
}
......@@ -210,13 +220,28 @@ static void gvir_sandbox_context_class_init(GVirSandboxContextClass *klass)
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_object_class_install_property(object_class,
PROP_AUTODESTROY,
g_param_spec_boolean("autodestroy",
"Auto destroy",
"Automatically destroy sandbox on exit",
TRUE,
G_PARAM_READABLE |
G_PARAM_WRITABLE |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_NICK |
G_PARAM_STATIC_BLURB));
g_type_class_add_private(klass, sizeof(GVirSandboxContextPrivate));
}
static void gvir_sandbox_context_init(GVirSandboxContext *ctxt)
{
ctxt->priv = GVIR_SANDBOX_CONTEXT_GET_PRIVATE(ctxt);
GVirSandboxContextPrivate *priv;
priv = ctxt->priv = GVIR_SANDBOX_CONTEXT_GET_PRIVATE(ctxt);
priv->autodestroy = TRUE;
}
......@@ -275,6 +300,42 @@ GVirConnection *gvir_sandbox_context_get_connection(GVirSandboxContext *ctxt)
}
/**
* gvir_sandbox_context_set_autodestroy:
* @ctxt: (transfer none): the sandbox context
* @state: the autodestroy flag state
*
* Control whether the sandbox should be automatically
* destroyed when the client which started it closes its
* connection to libvirtd. If @state is true, then the
* sandbox will be automatically destroyed upon client
* close/exit
*/
void gvir_sandbox_context_set_autodestroy(GVirSandboxContext *ctxt,
gboolean state)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
priv->autodestroy = state;
}
/**
* gvir_sandbox_context_get_autodestroy:
* @ctxt: (transfer none): the sandbox context
*
* Determine whether the sandbox will be automatically
* destroyed when the client which started it closes its
* connection to libvirtd
*
* Returns: the autodestroy flag state
*/
gboolean gvir_sandbox_context_get_autodestroy(GVirSandboxContext *ctxt)
{
GVirSandboxContextPrivate *priv = ctxt->priv;
return priv->autodestroy;
}
static gboolean gvir_sandbox_context_prestart(GVirSandboxContext *ctxt,
const gchar *configdir,
GError **error)
......@@ -388,6 +449,7 @@ gboolean gvir_sandbox_context_start(GVirSandboxContext *ctxt, GError **error)
gchar *configdir;
gboolean ret = FALSE;
const gchar *devname;
int flags = 0;
if (priv->domain) {
*error = g_error_new(GVIR_SANDBOX_CONTEXT_ERROR, 0,
......@@ -419,9 +481,12 @@ gboolean gvir_sandbox_context_start(GVirSandboxContext *ctxt, GError **error)
goto error;
}
if (priv->autodestroy)
flags |= GVIR_DOMAIN_START_AUTODESTROY;
if (!(priv->domain = gvir_connection_start_domain(priv->connection,
config,
GVIR_DOMAIN_START_AUTODESTROY,
flags,
error)))
goto error;
......
......@@ -66,6 +66,10 @@ GType gvir_sandbox_context_get_type(void);
GVirSandboxConfig *gvir_sandbox_context_get_config(GVirSandboxContext *ctxt);
void gvir_sandbox_context_set_autodestroy(GVirSandboxContext *ctxt,
gboolean state);
gboolean gvir_sandbox_context_get_autodestroy(GVirSandboxContext *ctxt);
gboolean gvir_sandbox_context_start(GVirSandboxContext *ctxt, GError **error);
gboolean gvir_sandbox_context_stop(GVirSandboxContext *ctxt, GError **error);
gboolean gvir_sandbox_context_attach(GVirSandboxContext *ctxt, GError **error);
......
......@@ -156,6 +156,8 @@ LIBVIRT_SANDBOX_0.2.1 {
gvir_sandbox_context_get_connection;
gvir_sandbox_context_get_log_console;
gvir_sandbox_context_get_shell_console;
gvir_sandbox_context_get_autodestroy;
gvir_sandbox_context_set_autodestroy;
gvir_sandbox_context_start;
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