mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 21:34:54 +03:00
Fix handling of OOM when getting Xen dom ID
The methods for obtaining the Xen dom ID cannot distinguish between returning -1 due to an error and returning -1 due to the domain being shutoff. Change them to return the dom ID via an output parameter. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
d508f70df0
commit
3169991555
@ -1604,7 +1604,8 @@ xenUnifiedConnectDomainXMLFromNative(virConnectPtr conn,
|
||||
|
||||
def = xenParseXM(conf, priv->xendConfigVersion, priv->caps);
|
||||
} else if (STREQ(format, XEN_CONFIG_FORMAT_SEXPR)) {
|
||||
id = xenGetDomIdFromSxprString(config, priv->xendConfigVersion);
|
||||
if (xenGetDomIdFromSxprString(config, priv->xendConfigVersion, &id) < 0)
|
||||
goto cleanup;
|
||||
xenUnifiedLock(priv);
|
||||
tty = xenStoreDomainGetConsolePath(conn, id);
|
||||
vncport = xenStoreDomainGetVNCPort(conn, id);
|
||||
|
@ -1561,7 +1561,7 @@ xenDaemonDomainFetch(virConnectPtr conn, int domid, const char *name,
|
||||
{
|
||||
struct sexpr *root;
|
||||
xenUnifiedPrivatePtr priv = conn->privateData;
|
||||
virDomainDefPtr def;
|
||||
virDomainDefPtr def = NULL;
|
||||
int id;
|
||||
char * tty;
|
||||
int vncport;
|
||||
@ -1573,7 +1573,8 @@ xenDaemonDomainFetch(virConnectPtr conn, int domid, const char *name,
|
||||
if (root == NULL)
|
||||
return NULL;
|
||||
|
||||
id = xenGetDomIdFromSxpr(root, priv->xendConfigVersion);
|
||||
if (xenGetDomIdFromSxpr(root, priv->xendConfigVersion, &id) < 0)
|
||||
goto cleanup;
|
||||
xenUnifiedLock(priv);
|
||||
if (sexpr_lookup(root, "domain/image/hvm"))
|
||||
tty = xenStoreDomainGetSerialConsolePath(conn, id);
|
||||
@ -3224,7 +3225,7 @@ xenDaemonDomainBlockPeek(virConnectPtr conn,
|
||||
xenUnifiedPrivatePtr priv = conn->privateData;
|
||||
struct sexpr *root = NULL;
|
||||
int fd = -1, ret = -1;
|
||||
virDomainDefPtr def;
|
||||
virDomainDefPtr def = NULL;
|
||||
int id;
|
||||
char * tty;
|
||||
int vncport;
|
||||
@ -3249,7 +3250,8 @@ xenDaemonDomainBlockPeek(virConnectPtr conn,
|
||||
return -1;
|
||||
}
|
||||
|
||||
id = xenGetDomIdFromSxpr(root, priv->xendConfigVersion);
|
||||
if (xenGetDomIdFromSxpr(root, priv->xendConfigVersion, &id) < 0)
|
||||
goto cleanup;
|
||||
xenUnifiedLock(priv);
|
||||
tty = xenStoreDomainGetConsolePath(conn, id);
|
||||
vncport = xenStoreDomainGetVNCPort(conn, id);
|
||||
|
@ -40,30 +40,33 @@
|
||||
#include "virstring.h"
|
||||
|
||||
/* Get a domain id from a S-expression string */
|
||||
int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion)
|
||||
int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion, int *id)
|
||||
{
|
||||
struct sexpr *root = string2sexpr(sexpr);
|
||||
int ret;
|
||||
|
||||
*id = -1;
|
||||
|
||||
if (!root)
|
||||
return -1;
|
||||
|
||||
int id = xenGetDomIdFromSxpr(root, xendConfigVersion);
|
||||
ret = xenGetDomIdFromSxpr(root, xendConfigVersion, id);
|
||||
sexpr_free(root);
|
||||
return id;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get a domain id from a S-expression */
|
||||
int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion)
|
||||
int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion, int *id)
|
||||
{
|
||||
int id = -1;
|
||||
const char * tmp = sexpr_node(root, "domain/domid");
|
||||
if (tmp == NULL && xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { /* domid was mandatory */
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("domain information incomplete, missing id"));
|
||||
return -1;
|
||||
} else {
|
||||
id = tmp ? sexpr_int(root, "domain/domid") : -1;
|
||||
*id = tmp ? sexpr_int(root, "domain/domid") : -1;
|
||||
return 0;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
|
@ -40,8 +40,8 @@ typedef enum {
|
||||
} xenConfigVersionEnum;
|
||||
|
||||
/* helper functions to get the dom id from a sexpr */
|
||||
int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion);
|
||||
int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion);
|
||||
int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion, int *id);
|
||||
int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion, int *id);
|
||||
|
||||
virDomainDefPtr xenParseSxprString(const char *sexpr, int xendConfigVersion,
|
||||
char *tty, int vncport);
|
||||
|
@ -50,7 +50,8 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
|
||||
if (virMutexInit(&priv.lock) < 0)
|
||||
goto fail;
|
||||
|
||||
id = xenGetDomIdFromSxprString(sexprData, xendConfigVersion);
|
||||
if (xenGetDomIdFromSxprString(sexprData, xendConfigVersion, &id) < 0)
|
||||
goto fail;
|
||||
xenUnifiedLock(&priv);
|
||||
tty = xenStoreDomainGetConsolePath(conn, id);
|
||||
vncport = xenStoreDomainGetVNCPort(conn, id);
|
||||
|
Loading…
Reference in New Issue
Block a user