提交 31699915 编写于 作者: D Daniel P. Berrange

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: NDaniel P. Berrange <berrange@redhat.com>
上级 d508f70d
...@@ -1604,7 +1604,8 @@ xenUnifiedConnectDomainXMLFromNative(virConnectPtr conn, ...@@ -1604,7 +1604,8 @@ xenUnifiedConnectDomainXMLFromNative(virConnectPtr conn,
def = xenParseXM(conf, priv->xendConfigVersion, priv->caps); def = xenParseXM(conf, priv->xendConfigVersion, priv->caps);
} else if (STREQ(format, XEN_CONFIG_FORMAT_SEXPR)) { } else if (STREQ(format, XEN_CONFIG_FORMAT_SEXPR)) {
id = xenGetDomIdFromSxprString(config, priv->xendConfigVersion); if (xenGetDomIdFromSxprString(config, priv->xendConfigVersion, &id) < 0)
goto cleanup;
xenUnifiedLock(priv); xenUnifiedLock(priv);
tty = xenStoreDomainGetConsolePath(conn, id); tty = xenStoreDomainGetConsolePath(conn, id);
vncport = xenStoreDomainGetVNCPort(conn, id); vncport = xenStoreDomainGetVNCPort(conn, id);
......
...@@ -1561,7 +1561,7 @@ xenDaemonDomainFetch(virConnectPtr conn, int domid, const char *name, ...@@ -1561,7 +1561,7 @@ xenDaemonDomainFetch(virConnectPtr conn, int domid, const char *name,
{ {
struct sexpr *root; struct sexpr *root;
xenUnifiedPrivatePtr priv = conn->privateData; xenUnifiedPrivatePtr priv = conn->privateData;
virDomainDefPtr def; virDomainDefPtr def = NULL;
int id; int id;
char * tty; char * tty;
int vncport; int vncport;
...@@ -1573,7 +1573,8 @@ xenDaemonDomainFetch(virConnectPtr conn, int domid, const char *name, ...@@ -1573,7 +1573,8 @@ xenDaemonDomainFetch(virConnectPtr conn, int domid, const char *name,
if (root == NULL) if (root == NULL)
return NULL; return NULL;
id = xenGetDomIdFromSxpr(root, priv->xendConfigVersion); if (xenGetDomIdFromSxpr(root, priv->xendConfigVersion, &id) < 0)
goto cleanup;
xenUnifiedLock(priv); xenUnifiedLock(priv);
if (sexpr_lookup(root, "domain/image/hvm")) if (sexpr_lookup(root, "domain/image/hvm"))
tty = xenStoreDomainGetSerialConsolePath(conn, id); tty = xenStoreDomainGetSerialConsolePath(conn, id);
...@@ -3224,7 +3225,7 @@ xenDaemonDomainBlockPeek(virConnectPtr conn, ...@@ -3224,7 +3225,7 @@ xenDaemonDomainBlockPeek(virConnectPtr conn,
xenUnifiedPrivatePtr priv = conn->privateData; xenUnifiedPrivatePtr priv = conn->privateData;
struct sexpr *root = NULL; struct sexpr *root = NULL;
int fd = -1, ret = -1; int fd = -1, ret = -1;
virDomainDefPtr def; virDomainDefPtr def = NULL;
int id; int id;
char * tty; char * tty;
int vncport; int vncport;
...@@ -3249,7 +3250,8 @@ xenDaemonDomainBlockPeek(virConnectPtr conn, ...@@ -3249,7 +3250,8 @@ xenDaemonDomainBlockPeek(virConnectPtr conn,
return -1; return -1;
} }
id = xenGetDomIdFromSxpr(root, priv->xendConfigVersion); if (xenGetDomIdFromSxpr(root, priv->xendConfigVersion, &id) < 0)
goto cleanup;
xenUnifiedLock(priv); xenUnifiedLock(priv);
tty = xenStoreDomainGetConsolePath(conn, id); tty = xenStoreDomainGetConsolePath(conn, id);
vncport = xenStoreDomainGetVNCPort(conn, id); vncport = xenStoreDomainGetVNCPort(conn, id);
......
...@@ -40,30 +40,33 @@ ...@@ -40,30 +40,33 @@
#include "virstring.h" #include "virstring.h"
/* Get a domain id from a S-expression string */ /* 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); struct sexpr *root = string2sexpr(sexpr);
int ret;
*id = -1;
if (!root) if (!root)
return -1; return -1;
int id = xenGetDomIdFromSxpr(root, xendConfigVersion); ret = xenGetDomIdFromSxpr(root, xendConfigVersion, id);
sexpr_free(root); sexpr_free(root);
return id; return ret;
} }
/* Get a domain id from a S-expression */ /* 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"); const char * tmp = sexpr_node(root, "domain/domid");
if (tmp == NULL && xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { /* domid was mandatory */ if (tmp == NULL && xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { /* domid was mandatory */
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("domain information incomplete, missing id")); "%s", _("domain information incomplete, missing id"));
return -1;
} else { } 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 { ...@@ -40,8 +40,8 @@ typedef enum {
} xenConfigVersionEnum; } xenConfigVersionEnum;
/* helper functions to get the dom id from a sexpr */ /* helper functions to get the dom id from a sexpr */
int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion); int xenGetDomIdFromSxprString(const char *sexpr, int xendConfigVersion, int *id);
int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion); int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion, int *id);
virDomainDefPtr xenParseSxprString(const char *sexpr, int xendConfigVersion, virDomainDefPtr xenParseSxprString(const char *sexpr, int xendConfigVersion,
char *tty, int vncport); char *tty, int vncport);
......
...@@ -50,7 +50,8 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion) ...@@ -50,7 +50,8 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
if (virMutexInit(&priv.lock) < 0) if (virMutexInit(&priv.lock) < 0)
goto fail; goto fail;
id = xenGetDomIdFromSxprString(sexprData, xendConfigVersion); if (xenGetDomIdFromSxprString(sexprData, xendConfigVersion, &id) < 0)
goto fail;
xenUnifiedLock(&priv); xenUnifiedLock(&priv);
tty = xenStoreDomainGetConsolePath(conn, id); tty = xenStoreDomainGetConsolePath(conn, id);
vncport = xenStoreDomainGetVNCPort(conn, id); vncport = xenStoreDomainGetVNCPort(conn, id);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册