[libvirt] [PATCH] xen_xs: name xendConfigVersion magic numbers
by Philipp Hahn
libvirt supports 4 different versions of the user-land XenD daemon. When
queried the daemon just returns its generation number, which is hard to
match to the version of the Xen tools.
Replace the magic generation numbers by named macro definitions to
improve code readability.
Signed-off-by: Philipp Hahn <hahn(a)univention.de>
---
.../0013-improve-getting-xen-vcpu-counts.patch | 2 +-
.../0014-improve-setting-xen-vcpu-counts.patch | 6 +-
docs/api_extension/0015-remove-dead-xen-code.patch | 2 +-
src/xen/xen_driver.c | 14 ++--
src/xen/xend_internal.c | 70 ++++++++++----------
src/xenxs/xen_sxpr.c | 24 ++++----
src/xenxs/xen_sxpr.h | 5 ++
src/xenxs/xen_xm.c | 14 ++--
src/xenxs/xenxs_private.h | 7 +-
9 files changed, 75 insertions(+), 69 deletions(-)
diff --git a/docs/api_extension/0013-improve-getting-xen-vcpu-counts.patch b/docs/api_extension/0013-improve-getting-xen-vcpu-counts.patch
index 047bc7b..c1aad03 100644
--- a/docs/api_extension/0013-improve-getting-xen-vcpu-counts.patch
+++ b/docs/api_extension/0013-improve-getting-xen-vcpu-counts.patch
@@ -100,7 +100,7 @@ index dfc6415..3642296 100644
+ /* If xendConfigVersion is 2, then we can only report _LIVE (and
+ * xm_internal reports _CONFIG). If it is 3, then _LIVE and
+ * _CONFIG are always in sync for a running system. */
-+ if (domain->id < 0 && priv->xendConfigVersion < 3)
++ if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
+ return -2;
+ if (domain->id < 0 && (flags & VIR_DOMAIN_VCPU_LIVE)) {
+ virXendError(VIR_ERR_OPERATION_INVALID, "%s",
diff --git a/docs/api_extension/0014-improve-setting-xen-vcpu-counts.patch b/docs/api_extension/0014-improve-setting-xen-vcpu-counts.patch
index 76dc948..3adbd75 100644
--- a/docs/api_extension/0014-improve-setting-xen-vcpu-counts.patch
+++ b/docs/api_extension/0014-improve-setting-xen-vcpu-counts.patch
@@ -110,7 +110,7 @@ index fe2ff86..66e8518 100644
+ * depends on xendConfigVersion. */
+ if (dom) {
+ priv = dom->conn->privateData;
-+ if (priv->xendConfigVersion >= 3)
++ if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
+ flags |= VIR_DOMAIN_VCPU_CONFIG;
+ }
+ return xenUnifiedDomainSetVcpusFlags(dom, nvcpus, flags);
@@ -163,14 +163,14 @@ index 3642296..55c2cc4 100644
+
+ priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
+
-+ if ((domain->id < 0 && priv->xendConfigVersion < 3) ||
++ if ((domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) ||
+ (flags & VIR_DOMAIN_VCPU_MAXIMUM))
+ return -2;
+
+ /* With xendConfigVersion 2, only _LIVE is supported. With
+ * xendConfigVersion 3, only _LIVE|_CONFIG is supported for
+ * running domains, or _CONFIG for inactive domains. */
-+ if (priv->xendConfigVersion < 3) {
++ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
+ if (flags & VIR_DOMAIN_VCPU_CONFIG) {
+ virXendError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("Xend version does not support modifying "
diff --git a/docs/api_extension/0015-remove-dead-xen-code.patch b/docs/api_extension/0015-remove-dead-xen-code.patch
index 56b99a3..64e0d98 100644
--- a/docs/api_extension/0015-remove-dead-xen-code.patch
+++ b/docs/api_extension/0015-remove-dead-xen-code.patch
@@ -122,7 +122,7 @@ index 55c2cc4..b90c331 100644
-
- priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
-
-- if (domain->id < 0 && priv->xendConfigVersion < 3)
+- if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
- return(-1);
-
- snprintf(buf, sizeof(buf), "%d", vcpus);
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 12d7eb0..94cafde 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -354,7 +354,7 @@ xenUnifiedOpen (virConnectPtr conn, virConnectAuthPtr auth, unsigned int flags)
/* XenD is active, so try the xm & xs drivers too, both requird to
* succeed if root, optional otherwise */
- if (priv->xendConfigVersion <= 2) {
+ if (priv->xendConfigVersion <= XEND_CONFIG_VERSION_3_0_3) {
VIR_DEBUG("Trying XM sub-driver");
if (xenXMOpen(conn, auth, flags) == VIR_DRV_OPEN_SUCCESS) {
VIR_DEBUG("Activated XM sub-driver");
@@ -1161,7 +1161,7 @@ xenUnifiedDomainSetVcpus (virDomainPtr dom, unsigned int nvcpus)
* depends on xendConfigVersion. */
if (dom) {
priv = dom->conn->privateData;
- if (priv->xendConfigVersion >= 3)
+ if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
flags |= VIR_DOMAIN_VCPU_CONFIG;
}
return xenUnifiedDomainSetVcpusFlags(dom, nvcpus, flags);
@@ -1239,7 +1239,7 @@ xenUnifiedDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
{
GET_PRIVATE(dom->conn);
- if (dom->id == -1 && priv->xendConfigVersion < 3 ) {
+ if (dom->id == -1 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
if (priv->opened[XEN_UNIFIED_XM_OFFSET])
return xenXMDomainGetXMLDesc(dom, flags);
} else {
@@ -1561,7 +1561,7 @@ xenUnifiedDomainAttachDevice (virDomainPtr dom, const char *xml)
* to make this API work
*/
if (priv->opened[XEN_UNIFIED_XEND_OFFSET] &&
- priv->xendConfigVersion >= 3)
+ priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
@@ -1600,7 +1600,7 @@ xenUnifiedDomainDetachDevice (virDomainPtr dom, const char *xml)
* to make this API work
*/
if (priv->opened[XEN_UNIFIED_XEND_OFFSET] &&
- priv->xendConfigVersion >= 3)
+ priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4)
flags |= VIR_DOMAIN_DEVICE_MODIFY_CONFIG;
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; ++i)
@@ -1642,7 +1642,7 @@ xenUnifiedDomainGetAutostart (virDomainPtr dom, int *autostart)
{
GET_PRIVATE(dom->conn);
- if (priv->xendConfigVersion < 3) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
if (priv->opened[XEN_UNIFIED_XM_OFFSET])
return xenXMDomainGetAutostart(dom, autostart);
} else {
@@ -1659,7 +1659,7 @@ xenUnifiedDomainSetAutostart (virDomainPtr dom, int autostart)
{
GET_PRIVATE(dom->conn);
- if (priv->xendConfigVersion < 3) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
if (priv->opened[XEN_UNIFIED_XM_OFFSET])
return xenXMDomainSetAutostart(dom, autostart);
} else {
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index b754eca..5c3838f 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -954,7 +954,7 @@ xend_detect_config_version(virConnectPtr conn) {
} else {
/* Xen prior to 3.0.3 did not have the xend_config_format
field, and is implicitly version 1. */
- priv->xendConfigVersion = 1;
+ priv->xendConfigVersion = XEND_CONFIG_VERSION_3_0_2;
}
sexpr_free(root);
return (0);
@@ -1224,7 +1224,7 @@ sexpr_to_domain(virConnectPtr conn, const struct sexpr *root)
/* New 3.0.4 XenD will not report a domid for inactive domains,
* so only error out for old XenD
*/
- if (!tmp && priv->xendConfigVersion < 3)
+ if (!tmp && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
goto error;
if (tmp)
@@ -1512,7 +1512,7 @@ xenDaemonDomainGetOSType(virDomainPtr domain)
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (domain->id < 0 && priv->xendConfigVersion < 3)
+ if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(NULL);
/* can we ask for a subset ? worth it ? */
@@ -1652,7 +1652,7 @@ xenDaemonDomainGetMaxMemory(virDomainPtr domain)
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (domain->id < 0 && priv->xendConfigVersion < 3)
+ if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(-1);
/* can we ask for a subset ? worth it ? */
@@ -1691,7 +1691,7 @@ xenDaemonDomainSetMaxMemory(virDomainPtr domain, unsigned long memory)
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (domain->id < 0 && priv->xendConfigVersion < 3)
+ if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(-1);
snprintf(buf, sizeof(buf), "%lu", VIR_DIV_UP(memory, 1024));
@@ -1728,7 +1728,7 @@ xenDaemonDomainSetMemory(virDomainPtr domain, unsigned long memory)
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (domain->id < 0 && priv->xendConfigVersion < 3)
+ if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(-1);
snprintf(buf, sizeof(buf), "%lu", VIR_DIV_UP(memory, 1024));
@@ -1808,7 +1808,7 @@ xenDaemonDomainGetXMLDesc(virDomainPtr domain, unsigned int flags,
}
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (domain->id < 0 && priv->xendConfigVersion < 3) {
+ if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
/* fall-through to the next driver to handle */
return(NULL);
}
@@ -1852,7 +1852,7 @@ xenDaemonDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info)
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (domain->id < 0 && priv->xendConfigVersion < 3)
+ if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(-1);
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
@@ -1887,7 +1887,7 @@ xenDaemonDomainGetState(virDomainPtr domain,
virCheckFlags(0, -1);
- if (domain->id < 0 && priv->xendConfigVersion < 3)
+ if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return -1;
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
@@ -2186,14 +2186,14 @@ xenDaemonDomainSetVcpusFlags(virDomainPtr domain, unsigned int vcpus,
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if ((domain->id < 0 && priv->xendConfigVersion < 3) ||
+ if ((domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) ||
(flags & VIR_DOMAIN_VCPU_MAXIMUM))
return -2;
/* With xendConfigVersion 2, only _LIVE is supported. With
* xendConfigVersion 3, only _LIVE|_CONFIG is supported for
* running domains, or _CONFIG for inactive domains. */
- if (priv->xendConfigVersion < 3) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
if (flags & VIR_DOMAIN_VCPU_CONFIG) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
_("Xend version does not support modifying "
@@ -2267,7 +2267,7 @@ xenDaemonDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
}
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (priv->xendConfigVersion < 3) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
mapstr[0] = '[';
mapstr[1] = 0;
} else {
@@ -2280,7 +2280,7 @@ xenDaemonDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
snprintf(buf, sizeof(buf), "%d,", (8 * i) + j);
strcat(mapstr, buf);
}
- if (priv->xendConfigVersion < 3)
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
mapstr[strlen(mapstr) - 1] = ']';
else
mapstr[strlen(mapstr) - 1] = 0;
@@ -2343,7 +2343,7 @@ xenDaemonDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
/* If xendConfigVersion is 2, then we can only report _LIVE (and
* xm_internal reports _CONFIG). If it is 3, then _LIVE and
* _CONFIG are always in sync for a running system. */
- if (domain->id < 0 && priv->xendConfigVersion < 3)
+ if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return -2;
if (domain->id < 0 && (flags & VIR_DOMAIN_VCPU_LIVE)) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -2477,7 +2477,7 @@ xenDaemonLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
/* Old approach for xen <= 3.0.3 */
- if (priv->xendConfigVersion < 3) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
char **names, **tmp;
unsigned char ident[VIR_UUID_BUFLEN];
names = xenDaemonListDomainsOld(conn);
@@ -2648,7 +2648,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
return -1;
}
/* If xendConfigVersion < 3 only live config can be changed */
- if (priv->xendConfigVersion < 3) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
_("Xend version does not support modifying "
"persistent config"));
@@ -2656,7 +2656,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
}
} else {
/* Only live config can be changed if xendConfigVersion < 3 */
- if (priv->xendConfigVersion < 3 &&
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4 &&
(flags != VIR_DOMAIN_DEVICE_MODIFY_CURRENT &&
flags != VIR_DOMAIN_DEVICE_MODIFY_LIVE)) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -2667,7 +2667,7 @@ xenDaemonAttachDeviceFlags(virDomainPtr domain, const char *xml,
/* Xen only supports modifying both live and persistent config if
* xendConfigVersion >= 3
*/
- if (priv->xendConfigVersion >= 3 &&
+ if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4 &&
(flags != (VIR_DOMAIN_DEVICE_MODIFY_LIVE |
VIR_DOMAIN_DEVICE_MODIFY_CONFIG))) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -2816,7 +2816,7 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain, const char *xml,
return -1;
}
/* If xendConfigVersion < 3 only live config can be changed */
- if (priv->xendConfigVersion < 3) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
_("Xend version does not support modifying "
"persistent config"));
@@ -2824,7 +2824,7 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain, const char *xml,
}
} else {
/* Only live config can be changed if xendConfigVersion < 3 */
- if (priv->xendConfigVersion < 3 &&
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4 &&
(flags != VIR_DOMAIN_DEVICE_MODIFY_CURRENT &&
flags != VIR_DOMAIN_DEVICE_MODIFY_LIVE)) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -2835,7 +2835,7 @@ xenDaemonUpdateDeviceFlags(virDomainPtr domain, const char *xml,
/* Xen only supports modifying both live and persistent config if
* xendConfigVersion >= 3
*/
- if (priv->xendConfigVersion >= 3 &&
+ if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4 &&
(flags != (VIR_DOMAIN_DEVICE_MODIFY_LIVE |
VIR_DOMAIN_DEVICE_MODIFY_CONFIG))) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -2929,7 +2929,7 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain, const char *xml,
return -1;
}
/* If xendConfigVersion < 3 only live config can be changed */
- if (priv->xendConfigVersion < 3) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
_("Xend version does not support modifying "
"persistent config"));
@@ -2937,7 +2937,7 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain, const char *xml,
}
} else {
/* Only live config can be changed if xendConfigVersion < 3 */
- if (priv->xendConfigVersion < 3 &&
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4 &&
(flags != VIR_DOMAIN_DEVICE_MODIFY_CURRENT &&
flags != VIR_DOMAIN_DEVICE_MODIFY_LIVE)) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -2948,7 +2948,7 @@ xenDaemonDetachDeviceFlags(virDomainPtr domain, const char *xml,
/* Xen only supports modifying both live and persistent config if
* xendConfigVersion >= 3
*/
- if (priv->xendConfigVersion >= 3 &&
+ if (priv->xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4 &&
(flags != (VIR_DOMAIN_DEVICE_MODIFY_LIVE |
VIR_DOMAIN_DEVICE_MODIFY_CONFIG))) {
virXendError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -3016,7 +3016,7 @@ xenDaemonDomainGetAutostart(virDomainPtr domain,
* config files used by old Xen) will handle this.
*/
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (priv->xendConfigVersion < 3)
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(-1);
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
@@ -3056,7 +3056,7 @@ xenDaemonDomainSetAutostart(virDomainPtr domain,
* config files used by old Xen) will handle this.
*/
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (priv->xendConfigVersion < 3)
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(-1);
root = sexpr_get(domain->conn, "/xend/domain/%s?detail=1", domain->name);
@@ -3318,7 +3318,7 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
priv = (xenUnifiedPrivatePtr) conn->privateData;
- if (priv->xendConfigVersion < 3)
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(NULL);
if (!(def = virDomainDefParseString(priv->caps, xmlDesc,
@@ -3367,7 +3367,7 @@ int xenDaemonDomainCreate(virDomainPtr domain)
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (priv->xendConfigVersion < 3)
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(-1);
ret = xend_op(domain->conn, domain->name, "op", "start", NULL);
@@ -3394,7 +3394,7 @@ int xenDaemonDomainUndefine(virDomainPtr domain)
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (priv->xendConfigVersion < 3)
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(-1);
return xend_op(domain->conn, domain->name, "op", "delete", NULL);
@@ -3419,7 +3419,7 @@ xenDaemonNumOfDefinedDomains(virConnectPtr conn)
/* xm_internal.c (the support for defined domains from /etc/xen
* config files used by old Xen) will handle this.
*/
- if (priv->xendConfigVersion < 3)
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(-1);
root = sexpr_get(conn, "/xend/domain?state=halted");
@@ -3447,7 +3447,7 @@ xenDaemonListDefinedDomains(virConnectPtr conn, char **const names, int maxnames
struct sexpr *_for_i, *node;
xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
- if (priv->xendConfigVersion < 3)
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return(-1);
if ((names == NULL) || (maxnames < 0))
@@ -3513,7 +3513,7 @@ xenDaemonGetSchedulerType(virDomainPtr domain, int *nparams)
/* Support only xendConfigVersion >=4 */
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (priv->xendConfigVersion < 4) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) {
virXendError(VIR_ERR_OPERATION_INVALID,
"%s", _("unsupported in xendConfigVersion < 4"));
return NULL;
@@ -3586,7 +3586,7 @@ xenDaemonGetSchedulerParameters(virDomainPtr domain,
/* Support only xendConfigVersion >=4 */
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (priv->xendConfigVersion < 4) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) {
virXendError(VIR_ERR_OPERATION_INVALID,
"%s", _("unsupported in xendConfigVersion < 4"));
return (-1);
@@ -3694,7 +3694,7 @@ xenDaemonSetSchedulerParameters(virDomainPtr domain,
/* Support only xendConfigVersion >=4 and active domains */
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (priv->xendConfigVersion < 4) {
+ if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) {
virXendError(VIR_ERR_OPERATION_INVALID,
"%s", _("unsupported in xendConfigVersion < 4"));
return (-1);
@@ -3802,7 +3802,7 @@ xenDaemonDomainBlockPeek (virDomainPtr domain, const char *path,
priv = (xenUnifiedPrivatePtr) domain->conn->privateData;
- if (domain->id < 0 && priv->xendConfigVersion < 3)
+ if (domain->id < 0 && priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4)
return -2; /* Decline, allow XM to handle it. */
/* Security check: The path must correspond to a block device. */
diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c
index 8c04596..756eb77 100644
--- a/src/xenxs/xen_sxpr.c
+++ b/src/xenxs/xen_sxpr.c
@@ -55,7 +55,7 @@ int xenGetDomIdFromSxpr(const struct sexpr *root, int xendConfigVersion)
{
int id = -1;
const char * tmp = sexpr_node(root, "domain/domid");
- if (tmp == NULL && xendConfigVersion < 3) { /* Old XenD, domid was mandatory */
+ if (tmp == NULL && xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { /* domid was mandatory */
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
"%s", _("domain information incomplete, missing id"));
} else {
@@ -468,7 +468,7 @@ xenParseSxprDisks(virDomainDefPtr def,
disk->device = VIR_DOMAIN_DISK_DEVICE_DISK;
/* New style disk config from Xen >= 3.0.3 */
- if (xendConfigVersion > 1) {
+ if (xendConfigVersion >= XEND_CONFIG_VERSION_3_0_3) {
offset = strrchr(dst, ':');
if (offset) {
if (STREQ (offset, ":cdrom")) {
@@ -814,7 +814,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def,
* present yet. Subsquent dumps of the XML will eventually
* find the port in XenStore once VNC server has started
*/
- if (port == -1 && xendConfigVersion < 2)
+ if (port == -1 && xendConfigVersion < XEND_CONFIG_VERSION_3_0_3)
port = 5900 + def->id;
if ((unused && STREQ(unused, "1")) || port == -1)
@@ -1132,7 +1132,7 @@ xenParseSxpr(const struct sexpr *root,
goto no_memory;
tmp = sexpr_node(root, "domain/domid");
- if (tmp == NULL && xendConfigVersion < 3) { /* Old XenD, domid was mandatory */
+ if (tmp == NULL && xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { /* domid was mandatory */
XENXS_ERROR(VIR_ERR_INTERNAL_ERROR,
"%s", _("domain information incomplete, missing id"));
goto error;
@@ -1318,7 +1318,7 @@ xenParseSxpr(const struct sexpr *root,
/* Old style cdrom config from Xen <= 3.0.2 */
if (hvm &&
- xendConfigVersion == 1) {
+ xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) {
tmp = sexpr_node(root, "domain/image/hvm/cdrom");
if ((tmp != NULL) && (tmp[0] != 0)) {
virDomainDiskDefPtr disk;
@@ -1617,7 +1617,7 @@ xenFormatSxprGraphicsOld(virDomainGraphicsDefPtr def,
virBufferAsprintf(buf, "(xauthority '%s')", def->data.sdl.xauth);
} else if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
virBufferAddLit(buf, "(vnc 1)");
- if (xendConfigVersion >= 2) {
+ if (xendConfigVersion >= XEND_CONFIG_VERSION_3_0_3) {
if (def->data.vnc.autoport) {
virBufferAddLit(buf, "(vncunused 1)");
} else {
@@ -1762,7 +1762,7 @@ xenFormatSxprDisk(virDomainDiskDefPtr def,
/* Xend <= 3.0.2 doesn't include cdrom config here */
if (hvm &&
def->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
- xendConfigVersion == 1) {
+ xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) {
if (isAttach) {
XENXS_ERROR(VIR_ERR_INVALID_ARG,
_("Cannot directly attach CDROM %s"), def->src);
@@ -1787,7 +1787,7 @@ xenFormatSxprDisk(virDomainDiskDefPtr def,
if (hvm) {
/* Xend <= 3.0.2 wants a ioemu: prefix on devices for HVM */
- if (xendConfigVersion == 1) {
+ if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) {
virBufferEscapeSexpr(buf, "(dev 'ioemu:%s')", def->dst);
} else {
/* But newer does not */
@@ -2338,7 +2338,7 @@ xenFormatSxpr(virConnectPtr conn,
switch (def->disks[i]->device) {
case VIR_DOMAIN_DISK_DEVICE_CDROM:
/* Only xend <= 3.0.2 wants cdrom config here */
- if (xendConfigVersion != 1)
+ if (xendConfigVersion != XEND_CONFIG_VERSION_3_0_2)
break;
if (!STREQ(def->disks[i]->dst, "hdc") ||
def->disks[i]->src == NULL)
@@ -2437,7 +2437,7 @@ xenFormatSxpr(virConnectPtr conn,
}
/* get the device emulation model */
- if (def->emulator && (hvm || xendConfigVersion >= 3))
+ if (def->emulator && (hvm || xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4))
virBufferEscapeSexpr(&buf, "(device_model '%s')", def->emulator);
/* look for HPET in order to override the hypervisor/xend default */
@@ -2452,7 +2452,7 @@ xenFormatSxpr(virConnectPtr conn,
/* PV graphics for xen <= 3.0.4, or HVM graphics for xen <= 3.1.0 */
if ((!hvm && xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF) ||
- (hvm && xendConfigVersion < 4)) {
+ (hvm && xendConfigVersion < XEND_CONFIG_VERSION_3_1_0)) {
if ((def->ngraphics == 1) &&
xenFormatSxprGraphicsOld(def->graphics[0],
&buf, xendConfigVersion) < 0)
@@ -2484,7 +2484,7 @@ xenFormatSxpr(virConnectPtr conn,
/* New style PV graphics config xen >= 3.0.4,
* or HVM graphics config xen >= 3.0.5 */
if ((xendConfigVersion >= XEND_CONFIG_MIN_VERS_PVFB_NEWCONF && !hvm) ||
- (xendConfigVersion >= 4 && hvm)) {
+ (xendConfigVersion >= XEND_CONFIG_VERSION_3_1_0 && hvm)) {
if ((def->ngraphics == 1) &&
xenFormatSxprGraphicsNew(def->graphics[0], &buf) < 0)
goto error;
diff --git a/src/xenxs/xen_sxpr.h b/src/xenxs/xen_sxpr.h
index a66c60a..4f96d2b 100644
--- a/src/xenxs/xen_sxpr.h
+++ b/src/xenxs/xen_sxpr.h
@@ -32,6 +32,11 @@
# include "domain_conf.h"
# include "sexpr.h"
+#define XEND_CONFIG_VERSION_3_0_2 1
+#define XEND_CONFIG_VERSION_3_0_3 2
+#define XEND_CONFIG_VERSION_3_0_4 3
+#define XEND_CONFIG_VERSION_3_1_0 4
+
/* 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);
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c
index a0d4806..e580a3e 100644
--- a/src/xenxs/xen_xm.c
+++ b/src/xenxs/xen_xm.c
@@ -570,7 +570,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
}
}
- if (hvm && xendConfigVersion == 1) {
+ if (hvm && xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) {
if (xenXMConfigGetString(conf, "cdrom", &str, NULL) < 0)
goto cleanup;
if (str) {
@@ -858,7 +858,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
}
/* HVM guests, or old PV guests use this config format */
- if (hvm || xendConfigVersion < 3) {
+ if (hvm || xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) {
if (xenXMConfigGetBool(conf, "vnc", &val, 0) < 0)
goto cleanup;
@@ -1169,7 +1169,7 @@ static int xenFormatXMDisk(virConfValuePtr list,
virBufferAdd(&buf, disk->src, -1);
}
virBufferAddLit(&buf, ",");
- if (hvm && xendConfigVersion == 1)
+ if (hvm && xendConfigVersion == XEND_CONFIG_VERSION_3_0_2)
virBufferAddLit(&buf, "ioemu:");
virBufferAdd(&buf, disk->dst, -1);
@@ -1545,7 +1545,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
(1 << VIR_DOMAIN_FEATURE_APIC)) ? 1 : 0) < 0)
goto no_memory;
- if (xendConfigVersion >= 3) {
+ if (xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4) {
if (xenXMConfigSetInt(conf, "hap",
(def->features &
(1 << VIR_DOMAIN_FEATURE_HAP)) ? 1 : 0) < 0)
@@ -1584,7 +1584,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
break;
}
- if (xendConfigVersion == 1) {
+ if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) {
for (i = 0 ; i < def->ndisks ; i++) {
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
def->disks[i]->dst &&
@@ -1665,7 +1665,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
}
if (def->ngraphics == 1) {
- if (xendConfigVersion < (hvm ? 4 : XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
+ if (xendConfigVersion < (hvm ? XEND_CONFIG_VERSION_3_1_0 : XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
if (xenXMConfigSetInt(conf, "sdl", 1) < 0)
goto no_memory;
@@ -1772,7 +1772,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
diskVal->list = NULL;
for (i = 0 ; i < def->ndisks ; i++) {
- if (xendConfigVersion == 1 &&
+ if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2 &&
def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
def->disks[i]->dst &&
STREQ(def->disks[i]->dst, "hdc")) {
diff --git a/src/xenxs/xenxs_private.h b/src/xenxs/xenxs_private.h
index 60d27d2..bc903f5 100644
--- a/src/xenxs/xenxs_private.h
+++ b/src/xenxs/xenxs_private.h
@@ -29,6 +29,7 @@
# include <stdint.h>
# include <xen/xen.h>
+# include "xen_sxpr.h"
/* xen-unstable changeset 19788 removed MAX_VIRT_CPUS from public
* headers. Its semantic was retained with XEN_LEGACY_MAX_VCPUS.
@@ -40,10 +41,10 @@
# ifdef WITH_RHEL5_API
# define XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU 0
-# define XEND_CONFIG_MIN_VERS_PVFB_NEWCONF 2
+# define XEND_CONFIG_MIN_VERS_PVFB_NEWCONF XEND_CONFIG_VERSION_3_0_3
# else
-# define XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU 3
-# define XEND_CONFIG_MIN_VERS_PVFB_NEWCONF 3
+# define XEND_CONFIG_MAX_VERS_NET_TYPE_IOEMU XEND_CONFIG_VERSION_3_0_4
+# define XEND_CONFIG_MIN_VERS_PVFB_NEWCONF XEND_CONFIG_VERSION_3_0_4
# endif
# define MIN_XEN_GUEST_SIZE 64 /* 64 megabytes */
--
1.7.1
12 years, 9 months
[libvirt] [PATCH v2] tests: dynamically replace dnsmasq path
by Philipp Hahn
The path to the dnsmasq binary can be configured while in the test data
the path is hard-coded to /usr/bin/. This break the test suite if a the
binary is located in a different location, like /usr/local/sbin/.
Replace the hard coded path in the test data by a token, which is
dynamically replaced in networkxml2argvtest with the configured path
after the test data has been loaded.
(Another option would have been to modify configure.ac to generate the
test data during configure, but I do not know of an easy way do trick
configure into mass-generate those test files without listing every
single one, which I consider less flexible.)
v2:
- Use VIR_REALLOC_N() instead of realloc()
- Use memcpy() for replacement
- Skip shrinking buffer
- Add missing update of token_end
- simplify code after the changes above
- unit-test the unit-test:
#include <assert.h>
#define TEST(in,token,rep,out) { char *buf = strdup(in); assert(!replaceTokens(&buf, token, rep) && !strcmp(buf, out)); free(buf); }
TEST("", "AA", "B", "");
TEST("A", "AA", "B", "A");
TEST("AA", "AA", "B", "B");
TEST("AAA", "AA", "B", "BA");
TEST("AA", "AA", "BB", "BB");
TEST("AA", "AA", "BBB", "BBB");
TEST("<AA", "AA", "B", "<B");
TEST("<AA", "AA", "BB", "<BB");
TEST("<AA", "AA", "BBB", "<BBB");
TEST("AA>", "AA", "B", "B>");
TEST("AA>", "AA", "BB", "BB>");
TEST("AA>", "AA", "BBB", "BBB>");
TEST("<AA>", "AA", "B", "<B>");
TEST("<AA>", "AA", "BB", "<BB>");
TEST("<AA>", "AA", "BBB", "<BBB>");
TEST("<AA|AA>", "AA", "B", "<B|B>");
TEST("<AA|AA>", "AA", "BB", "<BB|BB>");
TEST("<AA|AA>", "AA", "BBB", "<BBB|BBB>");
TEST("<AAAA>", "AA", "B", "<BB>");
TEST("<AAAA>", "AA", "BB", "<BBBB>");
TEST("<AAAA>", "AA", "BBB", "<BBBBBB>");
TEST("AAAA>", "AA", "B", "BB>");
TEST("AAAA>", "AA", "BB", "BBBB>");
TEST("AAAA>", "AA", "BBB", "BBBBBB>");
TEST("<AAAA", "AA", "B", "<BB");
TEST("<AAAA", "AA", "BB", "<BBBB");
TEST("<AAAA", "AA", "BBB", "<BBBBBB");
alarm(1); /* no infinit loop */
TEST("A", "A", "A", "A");
TEST("AA", "A", "A", "AA");
alarm(0);
Signed-off-by: Philipp Hahn <hahn(a)univention.de>
---
tests/networkxml2argvdata/isolated-network.argv | 2 +-
.../networkxml2argvdata/nat-network-dns-hosts.argv | 2 +-
.../nat-network-dns-srv-record-minimal.argv | 2 +-
.../nat-network-dns-srv-record.argv | 2 +-
.../nat-network-dns-txt-record.argv | 2 +-
tests/networkxml2argvdata/nat-network.argv | 2 +-
tests/networkxml2argvdata/netboot-network.argv | 2 +-
.../networkxml2argvdata/netboot-proxy-network.argv | 2 +-
tests/networkxml2argvdata/routed-network.argv | 2 +-
tests/networkxml2argvtest.c | 33 ++++++++++++++++++++
10 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/tests/networkxml2argvdata/isolated-network.argv b/tests/networkxml2argvdata/isolated-network.argv
index 7ea2e94..a9beb05 100644
--- a/tests/networkxml2argvdata/isolated-network.argv
+++ b/tests/networkxml2argvdata/isolated-network.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= \
+@DNSMASQ@ --strict-order --bind-interfaces --conf-file= \
--except-interface lo --dhcp-option=3 --no-resolv \
--listen-address 192.168.152.1 \
--dhcp-range 192.168.152.2,192.168.152.254 \
diff --git a/tests/networkxml2argvdata/nat-network-dns-hosts.argv b/tests/networkxml2argvdata/nat-network-dns-hosts.argv
index 2158df8..c7e4967 100644
--- a/tests/networkxml2argvdata/nat-network-dns-hosts.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-hosts.argv
@@ -1,3 +1,3 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --domain example.com \
+@DNSMASQ@ --strict-order --bind-interfaces --domain example.com \
--conf-file= --except-interface lo --listen-address 192.168.122.1 \
--expand-hosts --addn-hosts=/var/lib/libvirt/dnsmasq/default.addnhosts\
diff --git a/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv b/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv
index 021e8f0..ea1da6d 100644
--- a/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-srv-record-minimal.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq \
+@DNSMASQ@ \
--strict-order \
--bind-interfaces \
--conf-file= \
diff --git a/tests/networkxml2argvdata/nat-network-dns-srv-record.argv b/tests/networkxml2argvdata/nat-network-dns-srv-record.argv
index 85afbba..84c2d2f 100644
--- a/tests/networkxml2argvdata/nat-network-dns-srv-record.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-srv-record.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq \
+@DNSMASQ@ \
--strict-order \
--bind-interfaces \
--conf-file= \
diff --git a/tests/networkxml2argvdata/nat-network-dns-txt-record.argv b/tests/networkxml2argvdata/nat-network-dns-txt-record.argv
index be6ba4b..bed309f 100644
--- a/tests/networkxml2argvdata/nat-network-dns-txt-record.argv
+++ b/tests/networkxml2argvdata/nat-network-dns-txt-record.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= \
+@DNSMASQ@ --strict-order --bind-interfaces --conf-file= \
--except-interface lo --txt-record=example,example value \
--listen-address 192.168.122.1 --listen-address 192.168.123.1 \
--listen-address 2001:db8:ac10:fe01::1 \
diff --git a/tests/networkxml2argvdata/nat-network.argv b/tests/networkxml2argvdata/nat-network.argv
index d7faee2..80878a8 100644
--- a/tests/networkxml2argvdata/nat-network.argv
+++ b/tests/networkxml2argvdata/nat-network.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= \
+@DNSMASQ@ --strict-order --bind-interfaces --conf-file= \
--except-interface lo --listen-address 192.168.122.1 \
--listen-address 192.168.123.1 --listen-address 2001:db8:ac10:fe01::1 \
--listen-address 2001:db8:ac10:fd01::1 --listen-address 10.24.10.1 \
diff --git a/tests/networkxml2argvdata/netboot-network.argv b/tests/networkxml2argvdata/netboot-network.argv
index 78e873c..7ae5b75 100644
--- a/tests/networkxml2argvdata/netboot-network.argv
+++ b/tests/networkxml2argvdata/netboot-network.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --domain example.com \
+@DNSMASQ@ --strict-order --bind-interfaces --domain example.com \
--conf-file= --except-interface lo --listen-address 192.168.122.1 \
--dhcp-range 192.168.122.2,192.168.122.254 \
--dhcp-leasefile=/var/lib/libvirt/dnsmasq/netboot.leases \
diff --git a/tests/networkxml2argvdata/netboot-proxy-network.argv b/tests/networkxml2argvdata/netboot-proxy-network.argv
index 5fe1b8e..2c5a0d5 100644
--- a/tests/networkxml2argvdata/netboot-proxy-network.argv
+++ b/tests/networkxml2argvdata/netboot-proxy-network.argv
@@ -1,4 +1,4 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --domain example.com \
+@DNSMASQ@ --strict-order --bind-interfaces --domain example.com \
--conf-file= --except-interface lo --listen-address 192.168.122.1 \
--dhcp-range 192.168.122.2,192.168.122.254 \
--dhcp-leasefile=/var/lib/libvirt/dnsmasq/netboot.leases \
diff --git a/tests/networkxml2argvdata/routed-network.argv b/tests/networkxml2argvdata/routed-network.argv
index d059630..75303e6 100644
--- a/tests/networkxml2argvdata/routed-network.argv
+++ b/tests/networkxml2argvdata/routed-network.argv
@@ -1,2 +1,2 @@
-/usr/sbin/dnsmasq --strict-order --bind-interfaces --conf-file= \
+@DNSMASQ@ --strict-order --bind-interfaces --conf-file= \
--except-interface lo --listen-address 192.168.122.1\
diff --git a/tests/networkxml2argvtest.c b/tests/networkxml2argvtest.c
index 2dd9b7f..f2e9086 100644
--- a/tests/networkxml2argvtest.c
+++ b/tests/networkxml2argvtest.c
@@ -15,6 +15,36 @@
#include "memory.h"
#include "network/bridge_driver.h"
+/* Replace all occurrences of @token in @buf by @replacement and adjust size of
+ * @buf accordingly. Returns 0 on success and -1 on out-of-memory errors. */
+static int replaceTokens(char **buf, const char *token, const char *replacement) {
+ char *token_start, *token_end;
+ size_t buf_len, rest_len;
+ const size_t token_len = strlen(token);
+ const size_t replacement_len = strlen(replacement);
+ const int diff = replacement_len - token_len;
+
+ buf_len = rest_len = strlen(*buf) + 1;
+ token_end = *buf;
+ for (;;) {
+ token_start = strstr(token_end, token);
+ if (token_start == NULL)
+ break;
+ rest_len -= token_start + token_len - token_end;
+ token_end = token_start + token_len;
+ buf_len += diff;
+ if (diff > 0)
+ if (VIR_REALLOC_N(*buf, buf_len) < 0)
+ return -1;
+ if (diff != 0)
+ memmove(token_end + diff, token_end, rest_len);
+ memcpy(token_start, replacement, replacement_len);
+ token_end += diff;
+ }
+ /* if diff < 0, we could shrinkt the buffer here... */
+ return 0;
+}
+
static int testCompareXMLToArgvFiles(const char *inxml, const char *outargv) {
char *inXmlData = NULL;
char *outArgvData = NULL;
@@ -32,6 +62,9 @@ static int testCompareXMLToArgvFiles(const char *inxml, const char *outargv) {
if (virtTestLoadFile(outargv, &outArgvData) < 0)
goto fail;
+ if (replaceTokens(&outArgvData, "@DNSMASQ@", DNSMASQ))
+ goto fail;
+
if (!(dev = virNetworkDefParseString(inXmlData)))
goto fail;
--
1.7.1
12 years, 9 months
[libvirt] [PATCH v2] tests: virnettlscontexttest needs gnutls-2.6.0
by Philipp Hahn
virnettlscontexttest uses gnutls_x509_crt_set_subject_alt_name() and
GNUTLS_FSAN_APPEND, which - according to
<http://www.gnu.org/software/gnutls/manual/gnutls.html> - are only
available since 2.6.0.
Since libvirt still works fine with gnutls-1.0.25 from RHEL5, only
enable the test when the version of GNUTLS is at least 2.6.0.
v2: greater-equal 2.6.0 instead of strictly greater.
Signed-off-by: Philipp Hahn <hahn(a)univention.de>
---
tests/virnettlscontexttest.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tests/virnettlscontexttest.c b/tests/virnettlscontexttest.c
index 51f75b4..508617a 100644
--- a/tests/virnettlscontexttest.c
+++ b/tests/virnettlscontexttest.c
@@ -36,7 +36,7 @@
#include "virsocketaddr.h"
#include "gnutls_1_0_compat.h"
-#if !defined WIN32 && HAVE_LIBTASN1_H && !defined GNUTLS_1_0_COMPAT
+#if !defined WIN32 && HAVE_LIBTASN1_H && !defined GNUTLS_1_0_COMPAT && LIBGNUTLS_VERSION_NUMBER >= 0x020600
# include <libtasn1.h>
# include "rpc/virnettlscontext.h"
--
1.7.1
12 years, 9 months
[libvirt] [PATCH 0/2][RFC] netlink events
by D. Herrendoerfer
From: "D. Herrendoerfer" <d.herrendoerfer(a)herrendoerfer.name>
I'd like to put this up for discussion.
This is the prototype for netlink events as discussed before,
it follows the design of the event_poll functions.
Included is the unfinished prototype netlink event callback for
virnetdevmacvtap.c as reference. We are still working with lldpad
to get the message finalized and tested.
Regards,
Dirk H.
D. Herrendoerfer (2):
Add netlink message event service
macvtap: listen for netlink messages from lldpad
daemon/Makefile.am | 3 +-
daemon/libvirtd.c | 7 +
src/Makefile.am | 1 +
src/libvirt_private.syms | 7 +
src/util/netlink-event.c | 363 +++++++++++++++++++++++++++++++++++++++++++
src/util/netlink-event.h | 63 ++++++++
src/util/netlink.c | 1 +
src/util/virnetdevmacvlan.c | 161 +++++++++++++++++++-
src/util/virnetdevmacvlan.h | 1 +
9 files changed, 605 insertions(+), 2 deletions(-)
create mode 100644 src/util/netlink-event.c
create mode 100644 src/util/netlink-event.h
--
1.7.7.5
12 years, 9 months
[libvirt] [PATCH] daemon: Allow overriding NOFILES ulimit for the daemon as well
by Michal Privoznik
One of my latest patches (d8db0f9690) created support for setting
the limit for the maximum of opened files by qemu user. However,
since libvirtd keeps one FD opened per domain (well, for qemu at least)
it will likely hit this limit on huge scenarios.
---
daemon/libvirtd.aug | 1 +
daemon/libvirtd.c | 37 +++++++++++++++++++++++++++++++++++++
daemon/libvirtd.conf | 9 +++++++++
3 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/daemon/libvirtd.aug b/daemon/libvirtd.aug
index 9d78bd7..278099b 100644
--- a/daemon/libvirtd.aug
+++ b/daemon/libvirtd.aug
@@ -58,6 +58,7 @@ module Libvirtd =
| int_entry "max_requests"
| int_entry "max_client_requests"
| int_entry "prio_workers"
+ | int_entry "max_files"
let logging_entry = int_entry "log_level"
| str_entry "log_filters"
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index b1b542b..34bdd39 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -139,6 +139,8 @@ struct daemonConfig {
int max_requests;
int max_client_requests;
+ int max_files;
+
int log_level;
char *log_filters;
char *log_outputs;
@@ -1081,6 +1083,8 @@ daemonConfigLoad(struct daemonConfig *data,
GET_CONF_INT (conf, filename, max_requests);
GET_CONF_INT (conf, filename, max_client_requests);
+ GET_CONF_INT (conf, filename, max_files);
+
GET_CONF_INT (conf, filename, audit_level);
GET_CONF_INT (conf, filename, audit_logging);
@@ -1198,6 +1202,34 @@ static int daemonStateInit(virNetServerPtr srv)
return 0;
}
+/*
+ * daemonSetProcessLimits:
+ * @config: where to take limits from
+ *
+ * Set both soft and hard limits set in config file.
+ *
+ * Returns 0 on success, -1 otherwise.
+ */
+static int
+daemonSetProcessLimits(struct daemonConfig *config)
+{
+ struct rlimit rlim;
+
+ if (config->max_files > 0) {
+ /* Max number of opened files is one greater than
+ * actual limit. See man setrlimit */
+ rlim.rlim_cur = rlim.rlim_max = config->max_files + 1;
+ if (setrlimit(RLIMIT_NOFILE, &rlim) < 0) {
+ virReportSystemError(errno,
+ _("cannot set max opened files to %d"),
+ config->max_files);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
/* Print command-line usage. */
static void
daemonUsage(const char *argv0, bool privileged)
@@ -1429,6 +1461,11 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
+ if (daemonSetProcessLimits(config) < 0) {
+ /* Helper reported error */
+ exit(EXIT_FAILURE);
+ }
+
if (godaemon) {
char ebuf[1024];
diff --git a/daemon/libvirtd.conf b/daemon/libvirtd.conf
index 3eab2be..70d5294 100644
--- a/daemon/libvirtd.conf
+++ b/daemon/libvirtd.conf
@@ -279,6 +279,15 @@
# and max_workers parameter
#max_client_requests = 5
+# If max_files is set to positive integer, the maximum number
+# of opened files for the daemon is set to given value. This
+# can be used to override host system default value.
+# Please keep in mind that in some drivers (like qemu) this
+# will affect the upper bound of domains which can run simultaneously.
+# That's because the daemon keeps one file opened per domain - monitor.
+# Well, at least one.
+#max_files = 0
+
#################################################################
#
# Logging controls
--
1.7.3.4
12 years, 9 months
[libvirt] virDomainNetGetActualBridgeName doesn't return the actual bridge
by Hendrik Schwartke
Hi,
calling virDomainNetGetActualBridgeName on a bridge with type
VIR_DOMAIN_NET_TYPE_NETWORK seems to return NULL in any case, because
iface->data.network.actual is NULL. Is that intented?
What is the best way to determine the bridge the interface is connected to?
Hendrik Schwartke
12 years, 9 months
[libvirt] [PATCH v3 0/5] Add virDomainGetDiskErrors API
by Jiri Denemark
We already provide ways to detect when a domain has been paused as a
result of I/O error, but there was no way of getting the exact error or
even the device that experienced it. This new API may be used for both.
Changes in version 3:
- special case errors == NULL, maxerrors == 0 returns size of the array
the caller should pass
- explicitly document that disks with no error are not returned and that
the caller must free disk names
- explicitly document what happens when maxerrors is lower then the
actual number of disk errors
- maxerrors turned unsigned
- the first patch was split into two (public API and RPC)
- python binding is back
Changes in version 2:
- the API is now called virDomainGetDiskErrors
- it returns a list (allocated by caller) of disks with errors instead
so that users don't have to call it multiple times to get all errors
- there's no python API yet since it can't be autogenerated; I'll send
a patch for it tomorrow
Jiri Denemark (5):
virDomainGetDiskErrors public API
Remote protocol for virDomainGetDiskErrors
qemu: Implement virDomainGetDiskErrors
virsh: Implement domblkerror command
python: Add binding for virDomainGetDiskErrors
daemon/remote.c | 103 +++++++++++++++++++++++++++++++++++++++
include/libvirt/libvirt.h.in | 32 ++++++++++++
python/generator.py | 3 +-
python/libvirt-override-api.xml | 6 ++
python/libvirt-override.c | 50 +++++++++++++++++++
src/driver.h | 7 +++
src/libvirt.c | 65 ++++++++++++++++++++++++
src/libvirt_public.syms | 1 +
src/qemu/qemu_conf.h | 1 +
src/qemu/qemu_driver.c | 86 ++++++++++++++++++++++++++++++++
src/qemu/qemu_monitor.c | 40 +++++++++++++++
src/qemu/qemu_monitor.h | 1 +
src/qemu/qemu_monitor_json.c | 8 +++
src/qemu/qemu_monitor_text.c | 15 ++++++
src/remote/remote_driver.c | 77 +++++++++++++++++++++++++++++
src/remote/remote_protocol.x | 23 ++++++++-
src/remote_protocol-structs | 17 ++++++
tools/virsh.c | 78 +++++++++++++++++++++++++++++
tools/virsh.pod | 7 +++
19 files changed, 618 insertions(+), 2 deletions(-)
--
1.7.8.4
12 years, 9 months
[libvirt] [PATCH] qemu: Clenup qemuDomainSetInterfaceParameters
by Michal Privoznik
which contained some useless lines, copied code, NULL
dereference.
---
src/libvirt.c | 4 ++--
src/qemu/qemu_driver.c | 44 ++++++++++++++++----------------------------
2 files changed, 18 insertions(+), 30 deletions(-)
diff --git a/src/libvirt.c b/src/libvirt.c
index e702a34..433ae0a 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -7226,8 +7226,8 @@ error:
*
* Change a subset or all parameters of interface; currently this
* includes bandwidth parameters. The value of @flags should be
- * either VIR_DOMAIN_AFFECT_CURRENT, or a bitwise-or of values from
- * VIR_DOMAIN_AFFECT_LIVE and VIR_DOMAIN_AFFECT_CURRENT, although
+ * either VIR_DOMAIN_AFFECT_CURRENT, or a bitwise-or of values
+ * VIR_DOMAIN_AFFECT_LIVE and VIR_DOMAIN_AFFECT_CONFIG, although
* hypervisors vary in which flags are supported.
*
* This function may require privileged access to the hypervisor.
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1b147a9..b1d0b7f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7779,20 +7779,12 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
}
}
- if (VIR_ALLOC(bandwidth) < 0) {
+ if ((VIR_ALLOC(bandwidth) < 0) ||
+ (VIR_ALLOC(bandwidth->in) < 0) ||
+ (VIR_ALLOC(bandwidth->out) < 0)) {
virReportOOMError();
goto cleanup;
}
- if (VIR_ALLOC(bandwidth->in) < 0) {
- virReportOOMError();
- goto cleanup;
- }
- memset(bandwidth->in, 0, sizeof(*bandwidth->in));
- if (VIR_ALLOC(bandwidth->out) < 0) {
- virReportOOMError();
- goto cleanup;
- }
- memset(bandwidth->out, 0, sizeof(*bandwidth->out));
for (i = 0; i < nparams; i++) {
virTypedParameterPtr param = ¶ms[i];
@@ -7817,11 +7809,9 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
* inbound/outbound to not be set. */
if (!bandwidth->in->average) {
VIR_FREE(bandwidth->in);
- bandwidth->in = NULL;
}
if (!bandwidth->out->average) {
VIR_FREE(bandwidth->out);
- bandwidth->out = NULL;
}
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
@@ -7833,29 +7823,27 @@ qemuDomainSetInterfaceParameters(virDomainPtr dom,
/* virNetDevBandwidthSet() will clear any previous value of
* bandwidth parameters, so merge with old bandwidth parameters
* here to prevent them from being lost. */
- if (bandwidth->in || net->bandwidth->in) {
+ if (bandwidth->in ||
+ (net->bandwidth && net->bandwidth->in)) {
if (VIR_ALLOC(newBandwidth->in) < 0) {
virReportOOMError();
goto cleanup;
}
- if (bandwidth->in)
- memcpy(newBandwidth->in, bandwidth->in,
- sizeof(*newBandwidth->in));
- else if (net->bandwidth->in)
- memcpy(newBandwidth->in, net->bandwidth->in,
- sizeof(*newBandwidth->in));
- }
- if (bandwidth->out || net->bandwidth->out) {
+
+ memcpy(newBandwidth->in,
+ bandwidth->in ? bandwidth->in : net->bandwidth->in,
+ sizeof(*newBandwidth->in));
+ }
+ if (bandwidth->out ||
+ (net->bandwidth && net->bandwidth->out)) {
if (VIR_ALLOC(newBandwidth->out) < 0) {
virReportOOMError();
goto cleanup;
}
- if (bandwidth->out)
- memcpy(newBandwidth->out, bandwidth->out,
- sizeof(*newBandwidth->out));
- else if (net->bandwidth->out)
- memcpy(newBandwidth->out, net->bandwidth->out,
- sizeof(*newBandwidth->out));
+
+ memcpy(newBandwidth->out,
+ bandwidth->out ? bandwidth->out : net->bandwidth->out,
+ sizeof(*newBandwidth->out));
}
if (virNetDevBandwidthSet(net->ifname, newBandwidth) < 0) {
--
1.7.3.4
12 years, 9 months
[libvirt] [PATCH] qemu: Don't jump to endjob if no job was even started
by Michal Privoznik
In qemuDomainShutdownFlags if we try to use guest agent,
which has error or is not configured, we jump go endjob
label even if we haven't started any job yet. This may
lead to the daemon crash:
1) virsh shutdown --mode agent on a domain without agent configured
2) wait until domain quits
3) virsh edit
---
src/qemu/qemu_driver.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1b147a9..7945c5d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -1546,12 +1546,12 @@ static int qemuDomainShutdownFlags(virDomainPtr dom, unsigned int flags) {
if (priv->agentError) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("QEMU guest agent is not available due to an error"));
- goto endjob;
+ goto cleanup;
}
if (!priv->agent) {
qemuReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, "%s",
_("QEMU guest agent is not configured"));
- goto endjob;
+ goto cleanup;
}
}
--
1.7.3.4
12 years, 9 months
[libvirt] [test-API][PATCH 1/2] Add 2 new functions in storageAPI
by Wayne Sun
* download(self, poolname, volname, stream, offset, length, flags = 0)
* upload(self, poolname, volname, stream, offset, length, flags = 0)
---
lib/storageAPI.py | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/lib/storageAPI.py b/lib/storageAPI.py
index 6c9d286..b0733f8 100644
--- a/lib/storageAPI.py
+++ b/lib/storageAPI.py
@@ -466,3 +466,20 @@ class StorageAPI(object):
code = e.get_error_code()
raise exception.LibvirtAPI(message, code)
+ def download(self, poolname, volname, stream, offset, length, flags = 0):
+ try:
+ volobj = self.get_volume_obj(poolname, volname)
+ return volobj.download(stream, offset, length, flags)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
+
+ def upload(self, poolname, volname, stream, offset, length, flags = 0):
+ try:
+ volobj = self.get_volume_obj(poolname, volname)
+ return volobj.upload(stream, offset, length, flags)
+ except libvirt.libvirtError, e:
+ message = e.get_error_message()
+ code = e.get_error_code()
+ raise exception.LibvirtAPI(message, code)
--
1.7.1
12 years, 9 months