mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
Convert Xen domain autostart driver methods to use virDomainDefPtr
Introduce use of a virDomainDefPtr in the domain autostart APIs to simplify introduction of ACL security checks. The virDomainPtr cannot be safely used, since the app may have supplied mis-matching name/uuid/id fields. eg the name points to domain X, while the uuid points to domain Y. Resolving the virDomainPtr to a virDomainDefPtr ensures a consistent name/uuid/id set. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
21213a4b13
commit
d305e8691e
@ -1809,22 +1809,40 @@ static int
|
||||
xenUnifiedDomainGetAutostart(virDomainPtr dom, int *autostart)
|
||||
{
|
||||
xenUnifiedPrivatePtr priv = dom->conn->privateData;
|
||||
virDomainDefPtr def = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!(def = xenGetDomainDefForDom(dom)))
|
||||
goto cleanup;
|
||||
|
||||
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
|
||||
return xenXMDomainGetAutostart(dom, autostart);
|
||||
ret = xenXMDomainGetAutostart(def, autostart);
|
||||
else
|
||||
return xenDaemonDomainGetAutostart(dom, autostart);
|
||||
ret = xenDaemonDomainGetAutostart(dom->conn, def, autostart);
|
||||
|
||||
cleanup:
|
||||
virDomainDefFree(def);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
xenUnifiedDomainSetAutostart(virDomainPtr dom, int autostart)
|
||||
{
|
||||
xenUnifiedPrivatePtr priv = dom->conn->privateData;
|
||||
virDomainDefPtr def = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!(def = xenGetDomainDefForDom(dom)))
|
||||
goto cleanup;
|
||||
|
||||
if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
|
||||
return xenXMDomainSetAutostart(dom, autostart);
|
||||
ret = xenXMDomainSetAutostart(def, autostart);
|
||||
else
|
||||
return xenDaemonDomainSetAutostart(dom, autostart);
|
||||
ret = xenDaemonDomainSetAutostart(dom->conn, def, autostart);
|
||||
|
||||
cleanup:
|
||||
virDomainDefFree(def);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -2562,12 +2562,14 @@ cleanup:
|
||||
}
|
||||
|
||||
int
|
||||
xenDaemonDomainGetAutostart(virDomainPtr domain, int *autostart)
|
||||
xenDaemonDomainGetAutostart(virConnectPtr conn,
|
||||
virDomainDefPtr def,
|
||||
int *autostart)
|
||||
{
|
||||
struct sexpr *root;
|
||||
const char *tmp;
|
||||
|
||||
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
|
||||
root = sexpr_get(conn, "/xend/domain/%s?detail=1", def->name);
|
||||
if (root == NULL) {
|
||||
virReportError(VIR_ERR_XEN_CALL,
|
||||
"%s", _("xenDaemonGetAutostart failed to find this domain"));
|
||||
@ -2586,14 +2588,16 @@ xenDaemonDomainGetAutostart(virDomainPtr domain, int *autostart)
|
||||
}
|
||||
|
||||
int
|
||||
xenDaemonDomainSetAutostart(virDomainPtr domain, int autostart)
|
||||
xenDaemonDomainSetAutostart(virConnectPtr conn,
|
||||
virDomainDefPtr def,
|
||||
int autostart)
|
||||
{
|
||||
struct sexpr *root, *autonode;
|
||||
virBuffer buffer = VIR_BUFFER_INITIALIZER;
|
||||
char *content = NULL;
|
||||
int ret = -1;
|
||||
|
||||
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
|
||||
root = sexpr_get(conn, "/xend/domain/%s?detail=1", def->name);
|
||||
if (root == NULL) {
|
||||
virReportError(VIR_ERR_XEN_CALL,
|
||||
"%s", _("xenDaemonSetAutostart failed to find this domain"));
|
||||
@ -2632,7 +2636,7 @@ xenDaemonDomainSetAutostart(virDomainPtr domain, int autostart)
|
||||
|
||||
content = virBufferContentAndReset(&buffer);
|
||||
|
||||
if (xend_op(domain->conn, "", "op", "new", "config", content, NULL) != 0) {
|
||||
if (xend_op(conn, "", "op", "new", "config", content, NULL) != 0) {
|
||||
virReportError(VIR_ERR_XEN_CALL,
|
||||
"%s", _("Failed to redefine sexpr"));
|
||||
goto error;
|
||||
|
@ -174,10 +174,12 @@ int xenDaemonUpdateDeviceFlags(virConnectPtr conn,
|
||||
virDomainDefPtr def,
|
||||
const char *xml,
|
||||
unsigned int flags);
|
||||
int xenDaemonDomainGetAutostart (virDomainPtr dom,
|
||||
int *autostart);
|
||||
int xenDaemonDomainSetAutostart (virDomainPtr domain,
|
||||
int autostart);
|
||||
int xenDaemonDomainGetAutostart(virConnectPtr conn,
|
||||
virDomainDefPtr def,
|
||||
int *autostart);
|
||||
int xenDaemonDomainSetAutostart(virConnectPtr conn,
|
||||
virDomainDefPtr def,
|
||||
int autostart);
|
||||
|
||||
int xenDaemonCreateXML(virConnectPtr conn, virDomainDefPtr def);
|
||||
virDomainDefPtr xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid);
|
||||
|
@ -1423,28 +1423,29 @@ xenXMDomainBlockPeek(virDomainPtr dom ATTRIBUTE_UNUSED,
|
||||
|
||||
|
||||
static char *
|
||||
xenXMAutostartLinkName(virDomainPtr dom)
|
||||
xenXMAutostartLinkName(virDomainDefPtr def)
|
||||
{
|
||||
char *ret;
|
||||
if (virAsprintf(&ret, "/etc/xen/auto/%s", dom->name) < 0)
|
||||
if (virAsprintf(&ret, "/etc/xen/auto/%s", def->name) < 0)
|
||||
return NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static char *
|
||||
xenXMDomainConfigName(virDomainPtr dom)
|
||||
xenXMDomainConfigName(virDomainDefPtr def)
|
||||
{
|
||||
char *ret;
|
||||
if (virAsprintf(&ret, "/etc/xen/%s", dom->name) < 0)
|
||||
if (virAsprintf(&ret, "/etc/xen/%s", def->name) < 0)
|
||||
return NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
xenXMDomainGetAutostart(virDomainPtr dom, int *autostart)
|
||||
xenXMDomainGetAutostart(virDomainDefPtr def,
|
||||
int *autostart)
|
||||
{
|
||||
char *linkname = xenXMAutostartLinkName(dom);
|
||||
char *config = xenXMDomainConfigName(dom);
|
||||
char *linkname = xenXMAutostartLinkName(def);
|
||||
char *config = xenXMDomainConfigName(def);
|
||||
int ret = -1;
|
||||
|
||||
if (!linkname || !config) {
|
||||
@ -1470,10 +1471,11 @@ cleanup:
|
||||
|
||||
|
||||
int
|
||||
xenXMDomainSetAutostart(virDomainPtr dom, int autostart)
|
||||
xenXMDomainSetAutostart(virDomainDefPtr def,
|
||||
int autostart)
|
||||
{
|
||||
char *linkname = xenXMAutostartLinkName(dom);
|
||||
char *config = xenXMDomainConfigName(dom);
|
||||
char *linkname = xenXMAutostartLinkName(def);
|
||||
char *config = xenXMDomainConfigName(def);
|
||||
int ret = -1;
|
||||
|
||||
if (!linkname || !config) {
|
||||
|
@ -82,8 +82,10 @@ int xenXMDomainUndefine(virConnectPtr conn, virDomainDefPtr def);
|
||||
|
||||
int xenXMDomainBlockPeek (virDomainPtr dom, const char *path, unsigned long long offset, size_t size, void *buffer);
|
||||
|
||||
int xenXMDomainGetAutostart(virDomainPtr dom, int *autostart);
|
||||
int xenXMDomainSetAutostart(virDomainPtr dom, int autostart);
|
||||
int xenXMDomainGetAutostart(virDomainDefPtr def,
|
||||
int *autostart);
|
||||
int xenXMDomainSetAutostart(virDomainDefPtr def,
|
||||
int autostart);
|
||||
|
||||
int xenXMDomainAttachDeviceFlags(virConnectPtr conn,
|
||||
virDomainDefPtr def,
|
||||
|
Loading…
Reference in New Issue
Block a user