[libvirt] [PATCH 0/4] Assorted bool cleanups
by Ján Tomko
Found by: git grep '= 1'
Ján Tomko (4):
Replace two-state local integers with bool
Remove redundant two-state integers
nwfilter: change two-state int parameters to bool
qemu: change two-state int parameters to bool
src/conf/domain_conf.c | 18 +++++-----
src/conf/network_conf.c | 5 ++-
src/conf/nwfilter_conf.c | 56 +++++++++++++++----------------
src/conf/storage_conf.c | 5 ++-
src/lxc/lxc_controller.c | 4 +--
src/lxc/lxc_process.c | 4 +--
src/nwfilter/nwfilter_dhcpsnoop.c | 8 +----
src/nwfilter/nwfilter_ebiptables_driver.c | 36 ++++++++++----------
src/nwfilter/nwfilter_gentech_driver.c | 4 +--
src/qemu/qemu_agent.c | 6 ++--
src/qemu/qemu_capabilities.c | 21 ++++++------
src/qemu/qemu_capabilities.h | 2 +-
src/qemu/qemu_command.c | 39 ++++++++++-----------
src/qemu/qemu_driver.c | 6 ++--
src/qemu/qemu_hostdev.c | 6 ++--
src/qemu/qemu_migration.c | 20 +++++------
src/qemu/qemu_monitor.c | 6 ++--
src/qemu/qemu_monitor_json.c | 8 ++---
src/qemu/qemu_monitor_text.c | 16 ++++-----
src/qemu/qemu_process.c | 23 +++++--------
src/remote/remote_driver.c | 5 ++-
src/rpc/virnetserver.c | 6 ++--
src/storage/storage_backend.c | 4 +--
src/util/vircgroup.c | 4 +--
src/util/virlog.c | 15 +++++----
src/util/virnetdev.c | 19 +++++------
src/util/virpci.c | 12 +++----
src/util/viruri.c | 5 +--
src/util/virutil.c | 12 +++----
tests/qemuhelptest.c | 5 +--
tests/reconnect.c | 6 ++--
tests/ssh.c | 8 ++---
32 files changed, 192 insertions(+), 202 deletions(-)
--
1.8.1.5
11 years, 6 months
[libvirt] [PATCH 1/2] virsocket: Introduce virSocketAddrIsAny
by Michal Privoznik
This internal API checks, if passed address is ANYCAST address.
---
src/libvirt_private.syms | 1 +
src/util/virsocketaddr.c | 22 ++++++++++++++++++++++
src/util/virsocketaddr.h | 1 +
tests/sockettest.c | 38 ++++++++++++++++++++++++++++++++++++++
4 files changed, 62 insertions(+)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b93629f..0b2ce42 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1780,6 +1780,7 @@ virSocketAddrFormatFull;
virSocketAddrGetIpPrefix;
virSocketAddrGetPort;
virSocketAddrGetRange;
+virSocketAddrIsAny;
virSocketAddrIsNetmask;
virSocketAddrIsPrivate;
virSocketAddrMask;
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 1071b00..4bfc86d 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -227,6 +227,28 @@ virSocketAddrIsPrivate(const virSocketAddrPtr addr)
}
/*
+ * virSocketAddrIsAny:
+ * @addr: address to check
+ *
+ * Check if passed address is a variant of ANYCAST address.
+ */
+bool
+virSocketAddrIsAny(const virSocketAddrPtr addr)
+{
+ unsigned long tmp;
+ switch (addr->data.stor.ss_family) {
+ case AF_INET:
+ tmp = INADDR_ANY;
+ return memcmp(&addr->data.inet4.sin_addr.s_addr, &tmp,
+ sizeof(addr->data.inet4.sin_addr.s_addr)) == 0;
+ case AF_INET6:
+ return memcmp(addr->data.inet6.sin6_addr.s6_addr, &in6addr_any,
+ sizeof(addr->data.inet6.sin6_addr.s6_addr)) == 0;
+ }
+ return false;
+}
+
+/*
* virSocketAddrFormat:
* @addr: an initialized virSocketAddrPtr
*
diff --git a/src/util/virsocketaddr.h b/src/util/virsocketaddr.h
index 1c9e54a..d4d7ccf 100644
--- a/src/util/virsocketaddr.h
+++ b/src/util/virsocketaddr.h
@@ -123,4 +123,5 @@ bool virSocketAddrEqual(const virSocketAddrPtr s1,
const virSocketAddrPtr s2);
bool virSocketAddrIsPrivate(const virSocketAddrPtr addr);
+bool virSocketAddrIsAny(const virSocketAddrPtr addr);
#endif /* __VIR_SOCKETADDR_H__ */
diff --git a/tests/sockettest.c b/tests/sockettest.c
index 5b36a6c..e4a998b 100644
--- a/tests/sockettest.c
+++ b/tests/sockettest.c
@@ -157,6 +157,28 @@ static int testNetmaskHelper(const void *opaque)
return testNetmask(data->addr1, data->addr2, data->netmask, data->pass);
}
+static int testAnycast(const char *addrstr,
+ bool pass)
+{
+ virSocketAddr addr;
+
+ if (virSocketAddrParse(&addr, addrstr, AF_UNSPEC) < 0)
+ return -1;
+
+ if (virSocketAddrIsAny(&addr))
+ return pass ? 0 : -1;
+ return pass ? -1 : 0;
+}
+
+struct testAnycastData {
+ const char *addr;
+ bool pass;
+};
+static int testAnycastHelper(const void *opaque)
+{
+ const struct testAnycastData *data = opaque;
+ return testAnycast(data->addr, data->pass);
+}
static int
mymain(void)
@@ -223,6 +245,14 @@ mymain(void)
ret = -1; \
} while (0)
+#define DO_TEST_ANYCAST(addr, pass) \
+ do { \
+ struct testAnycastData data = { addr, pass}; \
+ if (virtTestRun("Test anycast " addr, 1, \
+ testAnycastHelper, &data) < 0) \
+ ret = -1; \
+ } while (0)
+
DO_TEST_PARSE_AND_FORMAT("127.0.0.1", AF_UNSPEC, true);
DO_TEST_PARSE_AND_FORMAT("127.0.0.1", AF_INET, true);
@@ -276,6 +306,14 @@ mymain(void)
DO_TEST_NETMASK("2000::1:1", "9000::1:1",
"ffff:ffff:ffff:ffff:ffff:ffff:ffff:0", false);
+ DO_TEST_ANYCAST("0.0.0.0", true);
+ DO_TEST_ANYCAST("::", true);
+ DO_TEST_ANYCAST("0", true);
+ DO_TEST_ANYCAST("0.0", true);
+ DO_TEST_ANYCAST("0.0.0", true);
+ DO_TEST_ANYCAST("1", false);
+ DO_TEST_ANYCAST("0.1", false);
+
return ret==0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
--
1.8.2.1
11 years, 6 months
[libvirt] [PATCH] tool/virsh-domain.c: Fix the display of Affinity in function cmdVcpuinfo.
by yangdongsheng
(1).Introduce a symbol 'x' to mean the physical cpu on host is offline.
(2).And the symbol '-' means the physical cpu on host is online but the
affinity of domain for this cpu is not set.
There was no diffrence in display between the two kinds of cpu state
before this patch, both are '-'.
Signed-off-by: yangdongsheng <yangds.fnst(a)cn.fujitsu.com>
---
I have removed the vshNodeGetCPUMap patch from this patchset.
So this patch will only fix the display of virsh vcpuinfo, please
give me your comment. Thanx~
tools/virsh-domain.c | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 0402aef..6e13076 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -5271,6 +5271,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom;
virVcpuInfoPtr cpuinfo;
unsigned char *cpumaps;
+ unsigned char *hostcpumap;
int ncpus, maxcpu;
size_t cpumaplen;
bool ret = true;
@@ -5284,6 +5285,11 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
return false;
}
+ if ((virNodeGetCPUMap(ctl->conn, &hostcpumap, NULL, 0)) < 0) {
+ virDomainFree(dom);
+ return false;
+ }
+
if (virDomainGetInfo(dom, &info) != 0) {
virDomainFree(dom);
return false;
@@ -5310,7 +5316,13 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
}
vshPrint(ctl, "%-15s ", _("CPU Affinity:"));
for (m = 0; m < maxcpu; m++) {
- vshPrint(ctl, "%c", VIR_CPU_USABLE(cpumaps, cpumaplen, n, m) ? 'y' : '-');
+ if VIR_CPU_USED(hostcpumap, m) {
+ vshPrint(ctl, "%c", VIR_CPU_USABLE(cpumaps,
+ cpumaplen, n, m) ? 'y' : '-');
+ }
+ else {
+ vshPrint(ctl, "%c", 'x');
+ }
}
vshPrint(ctl, "\n");
if (n < (ncpus - 1)) {
@@ -5332,8 +5344,13 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, "%-15s %s\n", _("CPU time"), _("N/A"));
vshPrint(ctl, "%-15s ", _("CPU Affinity:"));
for (m = 0; m < maxcpu; m++) {
- vshPrint(ctl, "%c",
- VIR_CPU_USABLE(cpumaps, cpumaplen, n, m) ? 'y' : '-');
+ if VIR_CPU_USED(hostcpumap, m) {
+ vshPrint(ctl, "%c", VIR_CPU_USABLE(cpumaps,
+ cpumaplen, n, m) ? 'y' : '-');
+ }
+ else {
+ vshPrint(ctl, "%c", 'x');
+ }
}
vshPrint(ctl, "\n");
if (n < (ncpus - 1)) {
@@ -5346,6 +5363,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
}
VIR_FREE(cpumaps);
+ VIR_FREE(hostcpumap);
VIR_FREE(cpuinfo);
virDomainFree(dom);
return ret;
--
1.7.10.1
11 years, 6 months
[libvirt] [PATCH] storage: Refresh pool after creating volume
by Osier Yang
https://bugzilla.redhat.com/show_bug.cgi?id=965442
One has to refresh the pool to get the correct pool info, this
patch refreshes the pool after creating a volume in code instead.
Pool refreshing failure is fine to ignore with a warning.
---
src/storage/storage_driver.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index a2b0c21..2a55095 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1443,6 +1443,9 @@ storageVolCreateXML(virStoragePoolPtr obj,
}
+ if (backend->refreshPool && backend->refreshPool(obj->conn, pool) < 0)
+ VIR_WARN("Failed to refresh pool after creating volume");
+
VIR_INFO("Creating volume '%s' in storage pool '%s'",
volobj->name, pool->def->name);
ret = volobj;
@@ -1606,6 +1609,9 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
goto cleanup;
}
+ if (backend->refreshPool && backend->refreshPool(obj->conn, pool) < 0)
+ VIR_WARN("Failed to refresh pool after creating volume");
+
VIR_INFO("Creating volume '%s' in storage pool '%s'",
volobj->name, pool->def->name);
ret = volobj;
--
1.8.1.4
11 years, 6 months
[libvirt] [PATCHv2] storage: Avoid unnecessary ternary operators and refactor the code
by Peter Krempa
Setting of local variables in virStorageBackendCreateQemuImgCmd was
unnecessarily cluttered with ternary operators and repeated testing of
of conditions.
This patch refactors the function to use if statements and improves
error reporting in case inputvol is specified but does not contain
target path. Previously we would complain about "unknown storage vol
type 0" instead of the actual problem.
---
Notes:
Version 2:
- retured preallocation check that was removed by mistake
- returned backing store check to the correct condition
- improve error reporting
src/storage/storage_backend.c | 69 ++++++++++++++++++++++---------------------
1 file changed, 36 insertions(+), 33 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 5a61381..4d90d52 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -663,53 +663,58 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
virCommandPtr cmd = NULL;
bool do_encryption = (vol->target.encryption != NULL);
unsigned long long int size_arg;
- bool preallocate = false;
-
- /* Treat output block devices as 'raw' format */
- const char *type =
- virStorageFileFormatTypeToString(vol->type == VIR_STORAGE_VOL_BLOCK ?
- VIR_STORAGE_FILE_RAW :
- vol->target.format);
-
- const char *backingType = vol->backingStore.path ?
- virStorageFileFormatTypeToString(vol->backingStore.format) : NULL;
-
- const char *inputBackingPath = (inputvol ? inputvol->backingStore.path
- : NULL);
- const char *inputPath = inputvol ? inputvol->target.path : NULL;
- /* Treat input block devices as 'raw' format */
- const char *inputType = inputPath ?
- virStorageFileFormatTypeToString(inputvol->type == VIR_STORAGE_VOL_BLOCK ?
- VIR_STORAGE_FILE_RAW :
- inputvol->target.format) :
- NULL;
+ bool preallocate = !!(flags & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA);
+ const char *type;
+ const char *backingType = NULL;
+ const char *inputPath = NULL;
+ const char *inputType = NULL;
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
- preallocate = !!(flags & VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA);
+ /* Treat output block devices as 'raw' format */
+ type = virStorageFileFormatTypeToString(vol->type == VIR_STORAGE_VOL_BLOCK ?
+ VIR_STORAGE_FILE_RAW :
+ vol->target.format);
- if (type == NULL) {
+ if (!type) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown storage vol type %d"),
vol->target.format);
return NULL;
}
- if (inputvol && inputType == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unknown storage vol type %d"),
- inputvol->target.format);
- return NULL;
- }
+
if (preallocate && vol->target.format != VIR_STORAGE_FILE_QCOW2) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("metadata preallocation only available with qcow2"));
return NULL;
}
+ if (inputvol) {
+ if (!(inputPath = inputvol->target.path)) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("missing target volume path"));
+ return NULL;
+ }
+
+ inputType = virStorageFileFormatTypeToString(inputvol->type == VIR_STORAGE_VOL_BLOCK ?
+ VIR_STORAGE_FILE_RAW :
+ inputvol->target.format);
+
+ if (!inputType) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unknown storage vol type %d"),
+ inputvol->target.format);
+ return NULL;
+ }
+
+ }
+
if (vol->backingStore.path) {
int accessRetCode = -1;
char *absolutePath = NULL;
+ backingType = virStorageFileFormatTypeToString(vol->backingStore.format);
+
if (preallocate) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("metadata preallocation conflicts with backing"
@@ -722,11 +727,9 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
* may cause issues with lvm. Untested essentially.
*/
if (inputvol &&
- (!inputBackingPath ||
- STRNEQ(inputBackingPath, vol->backingStore.path))) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("a different backing store cannot "
- "be specified."));
+ STRNEQ_NULLABLE(inputvol->backingStore.path, vol->backingStore.path)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("a different backing store cannot be specified."));
return NULL;
}
--
1.8.2.1
11 years, 6 months
[libvirt] [PATCH] iscsi: support IPv6 targets
by Ján Tomko
Instead of resolving the host as IPv4 and only using the first result,
resolve it as IPv6 as well and use the first address we've succesfully
connected to as the portal name.
---
src/libvirt_private.syms | 1 +
src/storage/storage_backend_iscsi.c | 64 +++++----------------------
src/util/virutil.c | 87 +++++++++++++++++++++++++++++++++++++
src/util/virutil.h | 4 ++
4 files changed, 102 insertions(+), 54 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9d5f74b..26c4553 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1931,6 +1931,7 @@ virEnumFromString;
virEnumToString;
virFindFCHostCapableVport;
virFormatIntDecimal;
+virGetConnectableIPAsString;
virGetDeviceID;
virGetDeviceUnprivSGIO;
virGetFCHostNameByWWN;
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index ad38ab2..f98fbce 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -1,7 +1,7 @@
/*
* storage_backend_iscsi.c: storage backend for iSCSI handling
*
- * Copyright (C) 2007-2008, 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2007-2008, 2010-2013 Red Hat, Inc.
* Copyright (C) 2007-2008 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -44,58 +44,16 @@
#include "vircommand.h"
#include "virrandom.h"
#include "virstring.h"
+#include "virutil.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
-static int
-virStorageBackendISCSITargetIP(const char *hostname,
- char *ipaddr,
- size_t ipaddrlen)
-{
- struct addrinfo hints;
- struct addrinfo *result = NULL;
- int ret;
-
- memset(&hints, 0, sizeof(hints));
- hints.ai_flags = AI_ADDRCONFIG;
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_protocol = 0;
-
- ret = getaddrinfo(hostname, NULL, &hints, &result);
- if (ret != 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("host lookup failed %s"),
- gai_strerror(ret));
- return -1;
- }
-
- if (result == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("no IP address for target %s"),
- hostname);
- return -1;
- }
-
- if (getnameinfo(result->ai_addr, result->ai_addrlen,
- ipaddr, ipaddrlen, NULL, 0,
- NI_NUMERICHOST) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("cannot format ip addr for %s"),
- hostname);
- freeaddrinfo(result);
- return -1;
- }
-
- freeaddrinfo(result);
- return 0;
-}
-
static char *
virStorageBackendISCSIPortal(virStoragePoolSourcePtr source)
{
- char ipaddr[NI_MAXHOST];
- char *portal;
+ char *ip;
+ char *portal = NULL;
+ int port;
if (source->nhost != 1) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@@ -103,17 +61,15 @@ virStorageBackendISCSIPortal(virStoragePoolSourcePtr source)
return NULL;
}
- if (virStorageBackendISCSITargetIP(source->hosts[0].name,
- ipaddr, sizeof(ipaddr)) < 0)
+ port = source->hosts[0].port ? source->hosts[0].port : 3260;
+
+ if (!(ip = virGetConnectableIPAsString(source->hosts[0].name, port)))
return NULL;
- if (virAsprintf(&portal, "%s:%d,1", ipaddr,
- source->hosts[0].port ?
- source->hosts[0].port : 3260) < 0) {
+ if (virAsprintf(&portal, "%s,1", ip) < 0)
virReportOOMError();
- return NULL;
- }
+ VIR_FREE(ip);
return portal;
}
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 028f1d1..d8400db 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -650,6 +650,93 @@ cleanup:
return result;
}
+/*
+ * Resolve 'host' and return the first address we've connected to
+ * as a string:
+ * address:port
+ * for IPv4 addresses and
+ * [address]:port
+ * for IPv6 addresses.
+ */
+char *
+virGetConnectableIPAsString(const char *host,
+ int port)
+{
+ struct addrinfo hints;
+ struct addrinfo *res, *rp;
+ int saved_errno = EINVAL;
+ char *ret = NULL;
+ char *buf = NULL;
+ char *portstr = NULL;
+ int rc;
+
+ if (VIR_ALLOC_N(buf, NI_MAXHOST) < 0)
+ goto no_memory;
+
+ if (virAsprintf(&portstr, "%d", port) < 0)
+ goto no_memory;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_ADDRCONFIG;
+
+ if ((rc = getaddrinfo(host, portstr, &hints, &res))) {
+ virReportError(VIR_ERR_UNKNOWN_HOST,
+ _("unable to resolve '%s': %s"),
+ host, gai_strerror(rc));
+ goto cleanup;
+ }
+
+ for (rp = res; rp; rp = rp->ai_next) {
+ int sockfd;
+
+ sockfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
+ if (sockfd == -1) {
+ saved_errno = errno;
+ continue;
+ }
+ if (connect(sockfd, rp->ai_addr, rp->ai_addrlen) != -1) {
+ VIR_FORCE_CLOSE(sockfd);
+ break;
+ }
+ saved_errno = errno;
+ VIR_FORCE_CLOSE(sockfd);
+ }
+
+ if (!rp) {
+ virReportSystemError(saved_errno,
+ _("unable to connect to '%s:%s'"),
+ host, portstr);
+ goto cleanup;
+ }
+
+ if ((rc = getnameinfo(rp->ai_addr, rp->ai_addrlen, buf, NI_MAXHOST,
+ NULL, 0, NI_NUMERICHOST)) < 0) {
+ virReportError(VIR_ERR_SYSTEM_ERROR,
+ _("Cannot convert IP address to string: %s"),
+ gai_strerror(rc));
+ goto cleanup;
+ }
+
+ if (rp->ai_family == AF_INET6) {
+ if (virAsprintf(&ret, "[%s]:%d", buf, port) < 0)
+ goto no_memory;
+ } else if (virAsprintf(&ret, "%s:%d", buf, port) < 0) {
+ goto no_memory;
+ }
+
+cleanup:
+ if (res)
+ freeaddrinfo(res);
+ VIR_FREE(buf);
+ VIR_FREE(portstr);
+ return ret;
+
+no_memory:
+ virReportOOMError();
+ goto cleanup;
+}
+
#ifdef HAVE_GETPWUID_R
enum {
VIR_USER_ENT_DIRECTORY,
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 280a18d..93f4007 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -27,8 +27,10 @@
# include "verify.h"
# include "internal.h"
+# include <netdb.h>
# include <unistd.h>
# include <sys/select.h>
+# include <sys/socket.h>
# include <sys/types.h>
# ifndef MIN
@@ -108,6 +110,8 @@ static inline int getgid (void) { return 0; }
# endif
char *virGetHostname(void);
+char *virGetConnectableIPAsString(const char *host,
+ int port);
char *virGetUserDirectory(void);
char *virGetUserConfigDirectory(void);
--
1.8.1.5
11 years, 6 months
[libvirt] [PATCH] Fix code coverage issue in OpenVZ driver
by Alvaro Polo
After fixing an invalid usage of virDomainNetDef in OpenVZ driver,
a coverage issue appeared. This was caused by a still invalid usage
of net->data.ethernet.dev for non ethernet networking.
---
src/openvz/openvz_driver.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index db738a4..d8abe9c 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -859,7 +859,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
/* if user doesn't specified host interface name,
* than we need to generate it */
if (net->ifname == NULL) {
- net->ifname = openvzGenerateVethName(veid, net->data.ethernet.dev);
+ net->ifname = openvzGenerateVethName(veid, guest_ifname);
if (net->ifname == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Could not generate veth name"));
--
1.7.12.4 (Apple Git-37)
11 years, 6 months
[libvirt] [PATCH] LXC: fix order in virProcessGetNamespaces
by Richard Weinberger
virProcessGetNamespaces() opens files in /proc/XXX/ns/ which will
later be passed to setns().
We have to make sure that the file descriptors in the array are in the correct
order. Otherwise setns() may fail.
The order has been taken from util-linux's sys-utils/nsenter.c
Signed-off-by: Richard Weinberger <richard(a)nod.at>
---
src/util/virprocess.c | 33 ++++++++++-----------------------
1 file changed, 10 insertions(+), 23 deletions(-)
diff --git a/src/util/virprocess.c b/src/util/virprocess.c
index bc028d7..fce0d46 100644
--- a/src/util/virprocess.c
+++ b/src/util/virprocess.c
@@ -513,11 +513,11 @@ int virProcessGetNamespaces(pid_t pid,
int **fdlist)
{
int ret = -1;
- DIR *dh = NULL;
struct dirent *de;
char *nsdir = NULL;
char *nsfile = NULL;
- size_t i;
+ char *ns_files[] = { "user", "ipc", "uts", "net", "pid", "mnt", NULL };
+ size_t i = 0;
*nfdlist = 0;
*fdlist = NULL;
@@ -528,45 +528,32 @@ int virProcessGetNamespaces(pid_t pid,
goto cleanup;
}
- if (!(dh = opendir(nsdir))) {
- virReportSystemError(errno,
- _("Cannot read directory %s"),
- nsdir);
- goto cleanup;
- }
-
- while ((de = readdir(dh))) {
+ while (ns_files[i]) {
int fd;
- if (de->d_name[0] == '.')
- continue;
-
- if (VIR_EXPAND_N(*fdlist, *nfdlist, 1) < 0) {
+ if (virAsprintf(&nsfile, "%s/%s", nsdir, ns_files[i]) < 0) {
virReportOOMError();
goto cleanup;
}
- if (virAsprintf(&nsfile, "%s/%s", nsdir, de->d_name) < 0) {
- virReportOOMError();
- goto cleanup;
+ if ((fd = open(nsfile, O_RDWR)) < 0) {
+ goto next;
}
- if ((fd = open(nsfile, O_RDWR)) < 0) {
- virReportSystemError(errno,
- _("Unable to open %s"),
- nsfile);
+ if (VIR_EXPAND_N(*fdlist, *nfdlist, 1) < 0) {
+ virReportOOMError();
goto cleanup;
}
(*fdlist)[(*nfdlist)-1] = fd;
+next:
VIR_FREE(nsfile);
+ i++;
}
ret = 0;
cleanup:
- if (dh)
- closedir(dh);
VIR_FREE(nsdir);
VIR_FREE(nsfile);
if (ret < 0) {
--
1.8.3
11 years, 6 months
[libvirt] [PATCH v2] qemu: Report the offset from host UTC for RTC_CHANGE event
by Osier Yang
https://bugzilla.redhat.com/show_bug.cgi?id=964177
Though both libvirt and QEMU's document say RTC_CHANGE returns
the offset from the host UTC, qemu actually returns the offset
from the specified date instead when specific date is provided
(-rtc base=$date).
It's not safe for qemu to fix it in code, it worked like that
for 3 years, changing it now may break other QEMU use cases.
What qemu tries to do is to fix the document:
http://lists.gnu.org/archive/html/qemu-devel/2013-05/msg04782.html
And in libvirt side, instead of reply on the qemu, this convert
the offset returned from qemu to the offset from host UTC, by:
/*
* a: the offset from qemu RTC_CHANGE event
* b: The specified date (-rtc base=$date)
* c: the host date when libvirt gets the RTC_CHANGE event
* offset: What libvirt will report
*/
offset = a + (b - c);
The specified date (-rtc base=$date) is recorded in clock's def as
an internal only member (may be useful to exposed outside?).
Internal only XML tag "starttime" is introduced to not lose the
domain process's starttime after libvirt restarting/reloading:
<clock offset='variable' adjustment='304' basis='utc' starttime='1370423588'/>
---
src/conf/domain_conf.c | 27 +++++++++++++++++++++++----
src/conf/domain_conf.h | 3 +++
src/qemu/qemu_command.c | 3 +++
src/qemu/qemu_process.c | 13 +++++++++++++
4 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a16ebd1..7773abf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -96,6 +96,7 @@ typedef enum {
VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES = (1<<18),
VIR_DOMAIN_XML_INTERNAL_ALLOW_ROM = (1<<19),
VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT = (1<<20),
+ VIR_DOMAIN_XML_INTERNAL_STARTTIME = (1 << 21)
} virDomainXMLInternalFlags;
VIR_ENUM_IMPL(virDomainTaint, VIR_DOMAIN_TAINT_LAST,
@@ -11193,6 +11194,16 @@ virDomainDefParseXML(xmlDocPtr xml,
break;
}
+ if (def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_VARIABLE &&
+ flags & VIR_DOMAIN_XML_INTERNAL_STARTTIME) {
+ if (virXPathULongLong("number(./clock/@starttime)", ctxt,
+ &def->clock.data.variable.starttime) < 0) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("invalid starttime"));
+ goto error;
+ }
+ }
+
if ((n = virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0)
goto error;
@@ -15788,7 +15799,8 @@ virDomainResourceDefFormat(virBufferPtr buf,
verify(((VIR_DOMAIN_XML_INTERNAL_STATUS |
VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET |
- VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES)
+ VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES |
+ VIR_DOMAIN_XML_INTERNAL_STARTTIME)
& DUMPXML_FLAGS) == 0);
/* This internal version can accept VIR_DOMAIN_XML_INTERNAL_*,
@@ -15810,7 +15822,8 @@ virDomainDefFormatInternal(virDomainDefPtr def,
virCheckFlags(DUMPXML_FLAGS |
VIR_DOMAIN_XML_INTERNAL_STATUS |
VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET |
- VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES,
+ VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES |
+ VIR_DOMAIN_XML_INTERNAL_STARTTIME,
-1);
if (!(type = virDomainVirtTypeToString(def->virtType))) {
@@ -16208,6 +16221,10 @@ virDomainDefFormatInternal(virDomainDefPtr def,
virBufferAsprintf(buf, " adjustment='%lld' basis='%s'",
def->clock.data.variable.adjustment,
virDomainClockBasisTypeToString(def->clock.data.variable.basis));
+
+ if (flags & VIR_DOMAIN_XML_INTERNAL_STARTTIME)
+ virBufferAsprintf(buf, " starttime='%llu'",
+ def->clock.data.variable.starttime);
break;
case VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE:
virBufferEscapeString(buf, " timezone='%s'", def->clock.data.timezone);
@@ -16586,7 +16603,8 @@ virDomainSaveStatus(virDomainXMLOptionPtr xmlopt,
unsigned int flags = (VIR_DOMAIN_XML_SECURE |
VIR_DOMAIN_XML_INTERNAL_STATUS |
VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET |
- VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES);
+ VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES |
+ VIR_DOMAIN_XML_INTERNAL_STARTTIME);
int ret = -1;
char *xml;
@@ -16674,7 +16692,8 @@ virDomainObjListLoadStatus(virDomainObjListPtr doms,
if (!(obj = virDomainObjParseFile(statusFile, caps, xmlopt, expectedVirtTypes,
VIR_DOMAIN_XML_INTERNAL_STATUS |
VIR_DOMAIN_XML_INTERNAL_ACTUAL_NET |
- VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES)))
+ VIR_DOMAIN_XML_INTERNAL_PCI_ORIG_STATES |
+ VIR_DOMAIN_XML_INTERNAL_STARTTIME)))
goto error;
virUUIDFormat(obj->def->uuid, uuidstr);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 3a71d6c..cca92b4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1767,6 +1767,9 @@ struct _virDomainClockDef {
struct {
long long adjustment;
int basis;
+
+ /* Store the start time of guest process, internal only */
+ unsigned long long starttime;
} variable;
/* Timezone name, when
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index c4a162a..9254525 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5518,6 +5518,9 @@ qemuBuildClockArgStr(virDomainClockDefPtr def)
now += def->data.variable.adjustment;
gmtime_r(&now, &nowbits);
+ /* Store the starttime of qemu process */
+ def->data.variable.starttime = now;
+
virBufferAsprintf(&buf, "base=%d-%02d-%02dT%02d:%02d:%02d",
nowbits.tm_year + 1900,
nowbits.tm_mon + 1,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index d4fd4fb..39c62b3 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -796,6 +796,19 @@ qemuProcessHandleRTCChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virObjectLock(vm);
+
+ /* QEMU's RTC_CHANGE event returns the offset from the specified
+ * date instead of the host UTC if a specific date is provided
+ * (-rtc base=$date). We need to convert it to be offset from
+ * host UTC.
+ */
+ if (vm->def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_VARIABLE) {
+ time_t now = time(NULL);
+
+ offset += vm->def->clock.data.variable.starttime -
+ (unsigned long long)now;
+ }
+
event = virDomainEventRTCChangeNewFromObj(vm, offset);
if (vm->def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_VARIABLE)
--
1.8.1.4
11 years, 6 months