[libvirt] [PATCH 0/8] storage: separate storage volume creation from building
by Peter Krempa
This series splits the internal storage volume metadata creation from actual
volume building and adds support for deletion of guster volumes.
Peter Krempa (8):
storage: fs: Fix comment for virStorageBackendFileSystemDelete
storage: Support deletion of volumes on gluster pools
storage: lvm: Avoid forward decl of virStorageBackendLogicalDeleteVol
storage: lvm: Separate creating of the volume from building
storage: disk: Separate creating of the volume from building
storage: RBD: Separate creating of the volume from building
storage: Sheepdog: Separate creating of the volume from building
storage: Improve error message when a storage backend is missing
src/storage/storage_backend.c | 3 +-
src/storage/storage_backend_disk.c | 44 ++++++++----
src/storage/storage_backend_fs.c | 6 +-
src/storage/storage_backend_gluster.c | 64 +++++++++++++++++
src/storage/storage_backend_logical.c | 127 ++++++++++++++++++---------------
src/storage/storage_backend_rbd.c | 41 +++++++++--
src/storage/storage_backend_sheepdog.c | 29 +++++++-
7 files changed, 226 insertions(+), 88 deletions(-)
--
1.8.5.2
10 years, 9 months
[libvirt] [PATCH] rbd: Use rbd_create3 to create RBD format 2 images by default
by Wido den Hollander
This new RBD format supports snapshotting and cloning. By having
libvirt create images in format 2 end-users of the created images
can benefit of the new RBD format.
Older versions of libvirt can work with this new RBD format as long
as librbd supports format 2, something that all recent versions of
librbd do.
Signed-off-by: Wido den Hollander <wido(a)widodh.nl>
---
src/storage/storage_backend_rbd.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index 4b6f18c..f3dd7a0 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -435,6 +435,26 @@ cleanup:
return ret;
}
+static int virStorageBackendRBDCreateImage(rados_ioctx_t io,
+ char *name, long capacity)
+{
+ int order = 0;
+ #if LIBRBD_VERSION_CODE > 260
+ uint64_t features = 3;
+ uint64_t stripe_count = 1;
+ uint64_t stripe_unit = 4194304;
+
+ if (rbd_create3(io, name, capacity, features, &order,
+ stripe_count, stripe_unit) < 0) {
+ #else
+ if (rbd_create(io, name, capacity, &order) < 0) {
+ #endif
+ return -1;
+ }
+
+ return 0;
+}
+
static int virStorageBackendRBDCreateVol(virConnectPtr conn,
virStoragePoolObjPtr pool,
virStorageVolDefPtr vol)
@@ -442,7 +462,6 @@ static int virStorageBackendRBDCreateVol(virConnectPtr conn,
virStorageBackendRBDState ptr;
ptr.cluster = NULL;
ptr.ioctx = NULL;
- int order = 0;
int ret = -1;
VIR_DEBUG("Creating RBD image %s/%s with size %llu",
@@ -467,7 +486,7 @@ static int virStorageBackendRBDCreateVol(virConnectPtr conn,
goto cleanup;
}
- if (rbd_create(ptr.ioctx, vol->name, vol->capacity, &order) < 0) {
+ if (virStorageBackendRBDCreateImage(ptr.ioctx, vol->name, vol->capacity) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to create volume '%s/%s'"),
pool->def->source.name,
--
1.7.9.5
10 years, 9 months
[libvirt] [uq/master PATCH 0/7] x86 CPU subclasses, take 7
by Eduardo Habkost
Is there any hope to get this into QEMU 2.0, or it is now too late? I got
almost no feedback on take 6 (submitted November 27).
This is the main blocker to allow libvirt finally implement an equivalent to the
"enforce" flag, finally making the CPU configuration safe and sane (today
libvirt simply ignores GET_SUPPORTED_CPUID information, and features are
silently disabled because "enforce" is not used).
This blocks libvirt because the current available interfaces requires re-running
QEMU for each CPU model to be probed. Having the x86 CPU subclasses allow
libvirt to simply create and destroy CPU objects from each available CPU class,
and query for the results using QMP.
Demonstration of how this can be used, below:
Running QEMU as:
$ qemu-system-x86_64 -enable-kvm -machine none -monitor stdio -qmp unix:/tmp/qmp,server,nowait -nographic
Then running qmp-shell as:
$ ./scripts/qmp/qmp-shell /tmp/qmp
[...]
(QEMU) object-add qom-type=host-x86_64-cpu id=probing-host-cpu-type
{u'return': {}}
(QEMU) object-add qom-type=Nehalem-x86_64-cpu id=probing-cpu-type-Nehalem
{u'return': {}}
(QEMU) object-add qom-type=Westmere-x86_64-cpu id=probing-cpu-type-Westmere
{u'return': {}}
(QEMU) object-add qom-type=Haswell-x86_64-cpu id=probing-cpu-type-Haswell
(QEMU) qom-list path=/objects/
{u'return': [{u'type': u'child<Haswell-x86_64-cpu>', u'name': u'probing-cpu-type-Haswell'}, {u'type': u'child<Westmere-x86_64-cpu>', u'name': u'probing-cpu-type-Westmere'}, {u'type': u'child<Nehalem-x86_64-cpu>', u'name': u'probing-cpu-type-Nehalem'}, {u'type': u'child<host-x86_64-cpu>', u'name': u'probing-host-cpu-type'}, {u'type': u'string', u'name': u'type'}]}
(QEMU) qom-list path=/objects/probing-cpu-type-Haswell/
{u'return': [{u'type': u'X86CPUFeatureWordInfo', u'name': u'filtered-features'}, {u'type': u'X86CPUFeatureWordInfo', u'name': u'feature-words'}, {u'type': u'int', u'name': u'apic-id'}, {u'type': u'int', u'name': u'tsc-frequency'}, {u'type': u'string', u'name': u'model-id'}, {u'type': u'string', u'name': u'vendor'}, {u'type': u'int', u'name': u'xlevel'}, {u'type': u'int', u'name': u'level'}, {u'type': u'int', u'name': u'stepping'}, {u'type': u'int', u'name': u'model'}, {u'type': u'int', u'name': u'family'}, {u'type': u'link<bus>', u'name': u'parent_bus'}, {u'type': u'boolean', u'name': u'enforce'}, {u'type': u'boolean', u'name': u'check'}, {u'type': u'boolean', u'name': u'hv-time'}, {u'type': u'boolean', u'name': u'hv-vapic'}, {u'type': u'boolean', u'name': u'hv-relaxed'}, {u'type': u'int', u'name': u'hv-spinlocks'}, {u'type': u'boolean', u'name': u'pmu'}, {u'type': u'bool', u'name': u'realized'}, {u'type': u'string', u'name': u'type'}]}
(QEMU) qom-get path=/objects/probing-cpu-type-Haswell property=feature-words
{u'return': [{u'cpuid-register': u'EDX', u'cpuid-input-eax': 2147483658, u'features': 0}, {u'cpuid-register': u'EAX', u'cpuid-input-eax': 1073741825, u'features': 16777339}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 3221225473, u'features': 0}, {u'cpuid-register': u'ECX', u'cpuid-input-eax': 2147483649, u'features': 1}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 2147483649, u'features': 672139264}, {u'cpuid-register': u'EBX', u'cpuid-input-eax': 7, u'features': 4025, u'cpuid-input-ecx': 0}, {u'cpuid-register': u'ECX', u'cpuid-input-eax': 1, u'features': 2549756419}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 1, u'features': 126614525}]}
(QEMU) qom-get path=/objects/probing-cpu-type-Haswell property=filtered-features
{u'return': [{u'cpuid-register': u'EDX', u'cpuid-input-eax': 2147483658, u'features': 0}, {u'cpuid-register': u'EAX', u'cpuid-input-eax': 1073741825, u'features': 0}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 3221225473, u'features': 0}, {u'cpuid-register': u'ECX', u'cpuid-input-eax': 2147483649, u'features': 0}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 2147483649, u'features': 0}, {u'cpuid-register': u'EBX', u'cpuid-input-eax': 7, u'features': 0, u'cpuid-input-ecx': 0}, {u'cpuid-register': u'ECX', u'cpuid-input-eax': 1, u'features': 0}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 1, u'features': 0}]}
(QEMU) qom-get path=/objects/probing-host-cpu-type property=feature-words
{u'return': [{u'cpuid-register': u'EDX', u'cpuid-input-eax': 2147483658, u'features': 0}, {u'cpuid-register': u'EAX', u'cpuid-input-eax': 1073741825, u'features': 16777467}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 3221225473, u'features': 0}, {u'cpuid-register': u'ECX', u'cpuid-input-eax': 2147483649, u'features': 1}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 2147483649, u'features': 697564159}, {u'cpuid-register': u'EBX', u'cpuid-input-eax': 7, u'features': 2, u'cpuid-input-ecx': 0}, {u'cpuid-register': u'ECX', u'cpuid-input-eax': 1, u'features': 2193236483}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 1, u'features': 260832255}]}
(QEMU) qom-get path=/objects/probing-host-cpu-type property=filtered-features
{u'return': [{u'cpuid-register': u'EDX', u'cpuid-input-eax': 2147483658, u'features': 0}, {u'cpuid-register': u'EAX', u'cpuid-input-eax': 1073741825, u'features': 0}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 3221225473, u'features': 0}, {u'cpuid-register': u'ECX', u'cpuid-input-eax': 2147483649, u'features': 0}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 2147483649, u'features': 0}, {u'cpuid-register': u'EBX', u'cpuid-input-eax': 7, u'features': 0, u'cpuid-input-ecx': 0}, {u'cpuid-register': u'ECX', u'cpuid-input-eax': 1, u'features': 0}, {u'cpuid-register': u'EDX', u'cpuid-input-eax': 1, u'features': 0}]}
Changes from take 6:
* Rebase against uq/master
* Patch 1/7:
* Check for __i386__ on host_cpuid() so the code compiles properly
on non-x86 hosts.
Suggested-by: Paolo Bonzini <pbonzini(a)redhat.com>
* Don't add assert(kvm_enabled()) line, which is not necessary to help
the compiler (and wouldn't help it if using -DNDEBUG, anyway).
Reported-by: Richard Henderson <rth(a)twiddle.net>
* Commit message update
Eduardo Habkost (7):
target-i386: Eliminate CONFIG_KVM #ifdefs
target-i386: Don't change x86_def_t struct on cpu_x86_register()
target-i386: Move KVM default-vendor hack to instance_init
target-i386: Rename cpu_x86_register() to x86_cpu_load_def()
target-i386: Call x86_cpu_load_def() earlier
target-i386: Rename x86_def_t to X86CPUDefinition
target-i386: CPU model subclasses
target-i386/cpu-qom.h | 13 ++
target-i386/cpu.c | 402 ++++++++++++++++++++++++++++++--------------------
target-i386/cpu.h | 2 -
3 files changed, 256 insertions(+), 161 deletions(-)
--
1.8.4.2
10 years, 9 months
[libvirt] [PATCH RFC 2/2] support configuring the format of dumping memory in qemu.conf
by Qiao Nuohan
This patch is used to add dump_memory_format to qemu.conf and make the
specified format as the default dump format of 'virsh dump --memory-only'.
But when "--compress" is specified with dump command, the format configured
by dump_memory_format will be overrided. dump_memory_format can one of elf,
kdump-zlib, kdump-lzo and kdump-snappy. And elf is the default value.
Signed-off-by: Qiao Nuohan <qiaonuohan(a)cn.fujitsu.com>
---
src/qemu/libvirtd_qemu.aug | 1 +
src/qemu/qemu.conf | 6 ++++++
src/qemu/qemu_conf.c | 2 ++
src/qemu/qemu_conf.h | 1 +
src/qemu/qemu_driver.c | 37 ++++++++++++++++++++++++++++++++++---
src/qemu/test_libvirtd_qemu.aug.in | 1 +
6 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/src/qemu/libvirtd_qemu.aug b/src/qemu/libvirtd_qemu.aug
index a9ff421..25737e8 100644
--- a/src/qemu/libvirtd_qemu.aug
+++ b/src/qemu/libvirtd_qemu.aug
@@ -60,6 +60,7 @@ module Libvirtd_qemu =
let save_entry = str_entry "save_image_format"
| str_entry "dump_image_format"
+ | str_entry "dump_memory_format"
| str_entry "snapshot_image_format"
| str_entry "auto_dump_path"
| bool_entry "auto_dump_bypass_cache"
diff --git a/src/qemu/qemu.conf b/src/qemu/qemu.conf
index 17f1b10..8dc9d29 100644
--- a/src/qemu/qemu.conf
+++ b/src/qemu/qemu.conf
@@ -294,6 +294,11 @@
# the requested compression program can't be found, this falls
# back to "raw" compression.
#
+# dump_memory_format is used when you use 'virsh dump --memory-only' to dump
+# guest memory, and if specifing format with 'virsh dump --memory-only',
+# dump_memory_format will not work. dump_memory_format can be elf, kdump-zlib,
+# kdump-lzo and kdump-snappy.
+#
# snapshot_image_format specifies the compression algorithm of the memory save
# image when an external snapshot of a domain is taken. This does not apply
# on disk image format. It is an error if the specified format isn't valid,
@@ -301,6 +306,7 @@
#
#save_image_format = "raw"
#dump_image_format = "raw"
+#dump_memory_format = "elf"
#snapshot_image_format = "raw"
# When a domain is configured to be auto-dumped when libvirtd receives a
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 4378791..7893e31 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -296,6 +296,7 @@ static void virQEMUDriverConfigDispose(void *obj)
VIR_FREE(cfg->saveImageFormat);
VIR_FREE(cfg->dumpImageFormat);
+ VIR_FREE(cfg->dumpMemoryFormat);
VIR_FREE(cfg->autoDumpPath);
virStringFreeList(cfg->securityDriverNames);
@@ -546,6 +547,7 @@ int virQEMUDriverConfigLoadFile(virQEMUDriverConfigPtr cfg,
GET_VALUE_STR("save_image_format", cfg->saveImageFormat);
GET_VALUE_STR("dump_image_format", cfg->dumpImageFormat);
+ GET_VALUE_STR("dump_memory_format", cfg->dumpMemoryFormat);
GET_VALUE_STR("snapshot_image_format", cfg->snapshotImageFormat);
GET_VALUE_STR("auto_dump_path", cfg->autoDumpPath);
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 1f44a76..3bb1935 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -147,6 +147,7 @@ struct _virQEMUDriverConfig {
char *saveImageFormat;
char *dumpImageFormat;
+ char *dumpMemoryFormat;
char *snapshotImageFormat;
char *autoDumpPath;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c4e1aef..06f39c0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3407,6 +3407,21 @@ static int qemuDumpToFd(virQEMUDriverPtr driver,
virDomainObjPtr vm,
return ret;
}
+typedef enum {
+ QEMU_DUMP_MEMORY_FORMAT_ELF = 0,
+ QEMU_DUMP_MEMORY_FORMAT_KDUMP_ZLIB = 1,
+ QEMU_DUMP_MEMORY_FORMAT_KDUMP_LZO = 2,
+ QEMU_DUMP_MEMORY_FORMAT_KDUMP_SNAPPY = 3,
+ QEMU_DUMP_MEMORY_FORMAT_LAST
+} virQEMUDumpMemoryFormat;
+
+VIR_ENUM_DECL(qemuDumpMemoryCompression)
+VIR_ENUM_IMPL(qemuDumpMemoryCompression, QEMU_DUMP_MEMORY_FORMAT_LAST,
+ "elf",
+ "kdump-zlib",
+ "kdump-lzo",
+ "kdump-snappy")
+
static int
doCoreDump(virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -3419,7 +3434,9 @@ doCoreDump(virQEMUDriverPtr driver,
virFileWrapperFdPtr wrapperFd = NULL;
int directFlag = 0;
unsigned int flags = VIR_FILE_WRAPPER_NON_BLOCKING;
- const char *dump_format;
+ const char *dump_format = "elf";
+ virQEMUDriverConfigPtr cfg = NULL;
+ int dump_memory_format;
/* Create an empty file with appropriate ownership. */
if (dump_flags & VIR_DUMP_BYPASS_CACHE) {
@@ -3449,8 +3466,22 @@ doCoreDump(virQEMUDriverPtr driver,
dump_format = "kdump-lzo";
else if (dump_flags & VIR_DUMP_COMPRESS_SNAPPY)
dump_format = "kdump-snappy";
- else
- dump_format = "elf";
+ else {
+ /* when --compress option is specified, qemu.conf will not work */
+ cfg = virQEMUDriverGetConfig(driver);
+ if (cfg->dumpMemoryFormat) {
+ dump_memory_format = qemuDumpMemoryCompressionTypeFromString(
+ cfg->dumpMemoryFormat);
+ if (dump_memory_format == QEMU_DUMP_MEMORY_FORMAT_KDUMP_ZLIB)
+ dump_format = "kdump-zlib";
+ else if (dump_memory_format ==
+ QEMU_DUMP_MEMORY_FORMAT_KDUMP_LZO)
+ dump_format = "kdump-lzo";
+ else if (dump_memory_format ==
+ QEMU_DUMP_MEMORY_FORMAT_KDUMP_SNAPPY)
+ dump_format = "kdump-snappy";
+ }
+ }
ret = qemuDumpToFd(driver, vm, fd, QEMU_ASYNC_JOB_DUMP,
dump_format);
} else {
diff --git a/src/qemu/test_libvirtd_qemu.aug.in b/src/qemu/test_libvirtd_qemu.aug.in
index 81fedd6..9d0bcec 100644
--- a/src/qemu/test_libvirtd_qemu.aug.in
+++ b/src/qemu/test_libvirtd_qemu.aug.in
@@ -51,6 +51,7 @@ module Test_libvirtd_qemu =
}
{ "save_image_format" = "raw" }
{ "dump_image_format" = "raw" }
+{ "dump_memory_format" = "elf" }
{ "snapshot_image_format" = "raw" }
{ "auto_dump_path" = "/var/lib/libvirt/qemu/dump" }
{ "auto_dump_bypass_cache" = "0" }
--
1.8.3.1
10 years, 9 months
[libvirt] [PATCH v5 0/6] Support keyboard device
by Li Zhang
From: Li Zhang <zhlcindy(a)linux.vnet.ibm.com>
This patchset is to add keyboard input device.
For PPC64, it doesn't support a default keyboard device when the graphic
is enabled. Libvirt supports QEMU command line as "-device VGA" which
won't create any keyboard device for it. So it requires libvirt to add
a default USB keyboard device for it.
This patchset is to add keyboard input device and a default USB keyboard
for PPC64.
The related discussion in QEMU community:
http://lists.nongnu.org/archive/html/qemu-devel/2013-11/msg01734.html
Li Zhang (6):
conf: Add a keyboard input device type
conf: Add one interface to add default input devices.
conf: Remove PS2 mouse device for non-X86 platforms
qemu_cap: Add USB keyboard capability
qemu: parse qemu command line for USB keyboard
Add a default USB keyboard and USB mouse for PPC64
v5 -> v4:
* Add PS/2 KBD definition in XML file. (Daniel.P.Berrange)
* Allow PS/2 KBD devices and set KBD default bus as PS2 for X86, USB for non-x86. (Daniel.P.Berrange)
* Add an implicit PS/2 KBD as PS/2 mouse. (Danniel.P.Berrange)
v4 -> v3:
* Don't remove PS2 mouse device for other virtualization drivers (Jan Tomko).
v3 -> v2:
* Handle the KBD device type in xen and QEMU driver. (Daniel.P.Berrange)
* Remove PS2 mouse device for non-X86 platforms.
* Move virDomainDefMaybeAddInput to a new patch. (Jan Tomko)
* Replace VIR_REALLOC_N with VIR_APPEND_ELEMENT. (Jan Tomoko)
* Fix several typos. (Jan Tomoko)
* Add a virReportError when QEMU_CAPS_DEVICE_USB_KBD can't be gotten. (Jan Tomoko)
v2 -> v1:
* change ifs to switch clause.
* reconstruct the patches
docs/schemas/domaincommon.rng | 1 +
src/conf/domain_conf.c | 92 ++++++++++++++--------
src/conf/domain_conf.h | 5 ++
src/libvirt_private.syms | 1 +
src/qemu/qemu_capabilities.c | 2 +
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 41 +++++++---
src/qemu/qemu_domain.c | 23 +++++-
src/util/virarch.h | 2 +
src/xenxs/xen_sxpr.c | 27 +++++--
src/xenxs/xen_xm.c | 30 +++++--
tests/qemucapabilitiesdata/caps_1.2.2-1.caps | 1 +
tests/qemucapabilitiesdata/caps_1.3.1-1.caps | 1 +
tests/qemucapabilitiesdata/caps_1.4.2-1.caps | 1 +
tests/qemucapabilitiesdata/caps_1.5.3-1.caps | 1 +
tests/qemucapabilitiesdata/caps_1.6.0-1.caps | 2 +
tests/qemucapabilitiesdata/caps_1.6.50-1.caps | 1 +
tests/qemuhelptest.c | 8 ++
.../qemuxml2argvdata/qemuxml2argv-pseries-disk.xml | 3 +-
.../qemuxml2argv-pseries-usb-kbd.args | 9 +++
.../qemuxml2argv-pseries-usb-kbd.xml | 19 +++++
tests/qemuxml2argvtest.c | 3 +
22 files changed, 212 insertions(+), 62 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-pseries-usb-kbd.xml
--
1.8.2.1
10 years, 9 months
[libvirt] [PATCH v2] Add helper program to create custom leases
by Nehal J Wani
Introduce helper program to catch events from dnsmasq and maintain a custom
lease file per network. It supports dhcpv4 and dhcpv6. The file is saved as
"<interface-name>.status".
Each lease contains the following info:
<expiry-time (epoch time)> <mac> <iaid> <ip-address> <hostname> <clientid>
Example of custom leases file content:
[
{
"expiry-time": "1390775837",
"mac-address": "52:54:00:93:8c:63",
"iaid": "*",
"ip-address": "192.168.150.209",
"hostname": "iit-ad885e4aa1",
"client-id": "01:52:54:00:44:7c:d7"
},
{
"expiry-time": "1390775950",
"mac-address": "52:54:00:7b:6f:ba",
"iaid": "8089530",
"ip-address": "2001:db8:ca2:2:1::6d",
"hostname": "*",
"client-id": "00:04:76:00:cf:ae:b3:0b:fc:cd:0e:22:2e:97:76:65:74:ec"
}
]
src/Makefile.am:
* Add options to compile the helper program
src/network/bridge_driver.c:
* Introduce networkDnsmasqLeaseFileNameCustom()
* Invoke helper program along with dnsmasq
* Delete the .status file when corresponding n/w is destroyed.
src/util/leaseshelper.c
* Helper program to create the custom lease file
---
v2:
* Changed format to JSON
v1:
* Refer: https://www.redhat.com/archives/libvir-list/2014-January/msg00626.html
src/Makefile.am | 20 ++++
src/network/bridge_driver.c | 19 ++++
src/util/leaseshelper.c | 271 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 310 insertions(+)
create mode 100644 src/util/leaseshelper.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 7844efa..1fa6263 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -840,6 +840,9 @@ STORAGE_HELPER_DISK_SOURCES = \
UTIL_IO_HELPER_SOURCES = \
util/iohelper.c
+UTIL_LEASES_HELPER_SOURCES = \
+ util/leaseshelper.c
+
# Network filters
NWFILTER_DRIVER_SOURCES = \
nwfilter/nwfilter_driver.h nwfilter/nwfilter_driver.c \
@@ -2410,6 +2413,23 @@ libvirt_iohelper_CFLAGS = \
$(NULL)
endif WITH_LIBVIRTD
+if WITH_LIBVIRTD
+libexec_PROGRAMS += libvirt_leaseshelper
+libvirt_leaseshelper_SOURCES = $(UTIL_LEASES_HELPER_SOURCES)
+libvirt_leaseshelper_LDFLAGS = \
+ $(NULL)
+libvirt_leaseshelper_LDADD = \
+ libvirt_util.la \
+ ../gnulib/lib/libgnu.la
+if WITH_DTRACE_PROBES
+libvirt_leaseshelper_LDADD += libvirt_probes.lo
+endif WITH_DTRACE_PROBES
+
+libvirt_leaseshelper_CFLAGS = \
+ $(PIE_CFLAGS) \
+ $(NULL)
+endif WITH_LIBVIRTD
+
if WITH_STORAGE_DISK
if WITH_LIBVIRTD
libexec_PROGRAMS += libvirt_parthelper
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 0b43a67..5440aef 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -148,6 +148,16 @@ networkDnsmasqLeaseFileNameFunc networkDnsmasqLeaseFileName =
networkDnsmasqLeaseFileNameDefault;
static char *
+networkDnsmasqLeaseFileNameCustom(const char *bridge)
+{
+ char *leasefile;
+
+ ignore_value(virAsprintf(&leasefile, "%s/%s.status",
+ driverState->dnsmasqStateDir, bridge));
+ return leasefile;
+}
+
+static char *
networkDnsmasqConfigFileName(const char *netname)
{
char *conffile;
@@ -183,6 +193,7 @@ networkRemoveInactive(virNetworkDriverStatePtr driver,
virNetworkObjPtr net)
{
char *leasefile = NULL;
+ char *customleasefile = NULL;
char *radvdconfigfile = NULL;
char *configfile = NULL;
char *radvdpidbase = NULL;
@@ -201,6 +212,9 @@ networkRemoveInactive(virNetworkDriverStatePtr driver,
if (!(leasefile = networkDnsmasqLeaseFileName(def->name)))
goto cleanup;
+ if (!(customleasefile = networkDnsmasqLeaseFileNameCustom(def->bridge)))
+ goto cleanup;
+
if (!(radvdconfigfile = networkRadvdConfigFileName(def->name)))
goto cleanup;
@@ -217,6 +231,7 @@ networkRemoveInactive(virNetworkDriverStatePtr driver,
/* dnsmasq */
dnsmasqDelete(dctx);
unlink(leasefile);
+ unlink(customleasefile);
unlink(configfile);
/* radvd */
@@ -1063,6 +1078,10 @@ networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps));
virCommandAddArgFormat(cmd, "--conf-file=%s", configfile);
+
+ /* This helper is used to create cutom leases file for libvirt */
+ virCommandAddArgFormat(cmd, "--dhcp-script=%s", LIBEXECDIR "/libvirt_leaseshelper");
+
*cmdout = cmd;
ret = 0;
cleanup:
diff --git a/src/util/leaseshelper.c b/src/util/leaseshelper.c
new file mode 100644
index 0000000..a9aaf3f
--- /dev/null
+++ b/src/util/leaseshelper.c
@@ -0,0 +1,271 @@
+/*
+ * leasehelper.c: Helper program to create custom leases file
+ *
+ * Copyright (C) 2013 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Author: Nehal J Wani <nehaljw.kkd1(a)gmail.com>
+ *
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "virutil.h"
+#include "virthread.h"
+#include "virfile.h"
+#include "virbuffer.h"
+#include "virstring.h"
+#include "virerror.h"
+#include "viralloc.h"
+#include "virjson.h"
+#include "configmake.h"
+
+#define VIR_FROM_THIS VIR_FROM_NETWORK
+
+/**
+ * VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX:
+ *
+ * Macro providing the upper limit on the size of leases file
+ */
+#define VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX 2097152
+
+/*
+ * Use this when passing possibly-NULL strings to printf-a-likes.
+ */
+# define EMPTY_STR(s) ((s) ? (s) : "*")
+
+int
+main(int argc, char **argv) {
+
+ /* Doesn't hurt to check */
+ if (argc < 4) {
+ /* Refer man page of dnsmasq --dhcp-script for more details */
+ fprintf(stderr, "Usage: $program $action ${mac|clientid} $ip\n");
+ return -1;
+ }
+
+ char *lease_file = NULL;
+ char *lease_entries = NULL;
+ const char *ip = argv[3];
+ const char *mac = argv[2];
+ const char *action = argv[1];
+ const char *program_name = argv[0];
+ const char *iaid = EMPTY_STR(virGetEnvAllowSUID("DNSMASQ_IAID"));
+ const char *clientid = EMPTY_STR(virGetEnvAllowSUID("DNSMASQ_CLIENT_ID"));
+ const char *interface = EMPTY_STR(virGetEnvAllowSUID("DNSMASQ_INTERFACE"));
+ const char *exptime = EMPTY_STR(virGetEnvAllowSUID("DNSMASQ_LEASE_EXPIRES"));
+ const char *hostname = EMPTY_STR(virGetEnvAllowSUID("DNSMASQ_SUPPLIED_HOSTNAME"));
+ const char *leases_str = NULL;
+ size_t i = 0;
+ int rv = -1;
+ int size = 0;
+ int lease_file_len = 0;
+ FILE *fp = NULL;
+ bool add = false;
+ bool delete = false;
+ virJSONValuePtr lease_new;
+ virJSONValuePtr lease_tmp;
+ virJSONValuePtr leases_array;
+ virJSONValuePtr lease_new_tmp;
+ virJSONValuePtr leases_array_new;
+
+ if (setlocale(LC_ALL, "") == NULL ||
+ bindtextdomain(PACKAGE, LOCALEDIR) == NULL ||
+ textdomain(PACKAGE) == NULL) {
+ fprintf(stderr, _("%s: initialization failed\n"), program_name);
+ exit(EXIT_FAILURE);
+ }
+
+ if (virThreadInitialize() < 0 ||
+ virErrorInitialize() < 0) {
+ fprintf(stderr, _("%s: initialization failed\n"), program_name);
+ exit(EXIT_FAILURE);
+ }
+
+ if (virAsprintf(&lease_file, "%s/%s.status", LOCALSTATEDIR
+ "/lib/libvirt/dnsmasq/", interface) < 0)
+ goto cleanup;
+
+ if (virGetEnvAllowSUID("DNSMASQ_IAID")) {
+ mac = EMPTY_STR(virGetEnvAllowSUID("DNSMASQ_MAC"));
+ clientid = argv[2];
+ }
+
+ /* Make sure dnsmasq knows the interface, otherwise something is wrong */
+ if (STREQ(interface, "*"))
+ goto cleanup;
+
+ /* Make sure the file exists. If not, 'touch' it */
+ if (virFileTouch(lease_file, 0644) < 0)
+ goto cleanup;
+
+ /* Read entire contents */
+ if ((lease_file_len = virFileReadAll(lease_file,
+ VIR_NETWORK_DHCP_LEASE_FILE_SIZE_MAX,
+ &lease_entries)) < 0) {
+ goto cleanup;
+ }
+
+ if (STREQ(action, "add") || STREQ(action, "old") || STREQ(action, "del")) {
+ if (mac || STREQ(action, "del")) {
+ /* Delete the corresponding lease */
+ delete = true;
+ if (STREQ(action, "add") || STREQ(action, "old")) {
+ add = true;
+ /* Enter new lease */
+ if (!(lease_new = virJSONValueNewObject())) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+ if (virJSONValueObjectAppendString(lease_new, "expiry-time",
+ exptime) < 0 ||
+ virJSONValueObjectAppendString(lease_new, "mac-address",
+ mac) < 0 ||
+ virJSONValueObjectAppendString(lease_new, "iaid",
+ iaid) < 0 ||
+ virJSONValueObjectAppendString(lease_new, "ip-address",
+ ip) < 0 ||
+ virJSONValueObjectAppendString(lease_new, "hostname",
+ hostname) < 0 ||
+ virJSONValueObjectAppendString(lease_new, "client-id",
+ clientid) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+ }
+ }
+ }
+
+ /* Check for previous leases */
+ if (lease_file_len) {
+ if (!(leases_array = virJSONValueFromString(lease_entries))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("invalid json in file: %s"), lease_file);
+ goto cleanup;
+ }
+
+ if ((size = virJSONValueArraySize(leases_array)) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("couldn't fetch array of leases"));
+ goto cleanup;
+ }
+ }
+
+ if (!(leases_array_new = virJSONValueNewArray())) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+
+ for (i = 0; i < size; i++) {
+ const char *ip_tmp = NULL;
+ const char *mac_tmp = NULL;
+ const char *iaid_tmp = NULL;
+ const char *exptime_tmp = NULL;
+ const char *clientid_tmp = NULL;
+ const char *hostname_tmp = NULL;
+ long long expirytime_tmp = 0;
+
+ if (!(lease_tmp = virJSONValueArrayGet(leases_array, i))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to parse json"));
+ goto cleanup;
+ }
+
+ if (!(iaid_tmp = virJSONValueObjectGetString(lease_tmp, "iaid")) ||
+ !(ip_tmp = virJSONValueObjectGetString(lease_tmp, "ip-address")) ||
+ !(mac_tmp = virJSONValueObjectGetString(lease_tmp, "mac-address")) ||
+ !(hostname_tmp = virJSONValueObjectGetString(lease_tmp, "hostname")) ||
+ !(clientid_tmp = virJSONValueObjectGetString(lease_tmp, "client-id")) ||
+ !(exptime_tmp = virJSONValueObjectGetString(lease_tmp, "expiry-time"))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to parse json"));
+ goto cleanup;
+ }
+
+ if (virStrToLong_ll(exptime_tmp, NULL, 10, &expirytime_tmp) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to convert lease expiry time to integer: %s"),
+ exptime_tmp);
+ goto cleanup;
+ }
+
+ /* Check whether lease has expired or not */
+ if (expirytime_tmp < (long long) time(NULL))
+ continue;
+ else if (delete && STREQ(ip_tmp, ip))
+ continue;
+ else {
+ if (!(lease_new_tmp = virJSONValueNewObject())) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+ if (virJSONValueObjectAppendString(lease_new_tmp, "expiry-time",
+ exptime_tmp) < 0 ||
+ virJSONValueObjectAppendString(lease_new_tmp, "mac-address",
+ mac_tmp) < 0 ||
+ virJSONValueObjectAppendString(lease_new_tmp, "iaid",
+ iaid_tmp) < 0 ||
+ virJSONValueObjectAppendString(lease_new_tmp, "ip-address",
+ ip_tmp) < 0 ||
+ virJSONValueObjectAppendString(lease_new_tmp, "hostname",
+ hostname_tmp) < 0 ||
+ virJSONValueObjectAppendString(lease_new_tmp, "client-id",
+ clientid_tmp) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+ if (virJSONValueArrayAppend(leases_array_new, lease_new_tmp) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+ }
+ }
+
+ if (add) {
+ if (virJSONValueArrayAppend(leases_array_new, lease_new) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("failed to create json"));
+ goto cleanup;
+ }
+ }
+
+ rv = 0;
+
+ /* Write to file */
+ leases_str = virJSONValueToString(leases_array_new, true);
+ if (!leases_str)
+ leases_str = "";
+
+ if (virFileWriteStr(lease_file, leases_str, 0) < 0)
+ rv = -1;
+
+cleanup:
+ VIR_FREE(lease_file);
+ virJSONValueFree(lease_new);
+ virJSONValueFree(leases_array);
+ virJSONValueFree(lease_new_tmp);
+ virJSONValueFree(leases_array_new);
+ return rv;
+}
--
1.8.1.4
10 years, 9 months
[libvirt] [PATCH 0/4] allow OVMF users to disable qemu's "-boot strict=on"
by Laszlo Ersek
Recently,
commit 96fddee322c7d39a57cfdc5e7be71326d597d30a
Author: Laine Stump <laine(a)laine.org>
Date: Mon Dec 2 14:07:12 2013 +0200
qemu: add "-boot strict" to commandline whenever possible
introduced a regression for OVMF guests. The symptoms and causes are
described in patch 3/4, and in
https://bugzilla.redhat.com/show_bug.cgi?id=1056258
Let's allow users to opt-out of "-boot strict=on" while preserving it as
default.
Please review.
Thanks,
Laszlo
Laszlo Ersek (4):
domain: introduce os.bootStrict
domain: parse and format os.bootStrict from/to XML
qemu: parse and format os.bootStrict from/to command line
parallels: reject non-default os.bootStrict
src/conf/domain_conf.h | 11 ++++
src/conf/domain_conf.c | 26 +++++++++
src/parallels/parallels_driver.c | 1 +
src/qemu/qemu_command.c | 17 +++++-
tests/qemuxml2argvtest.c | 4 ++
docs/formatdomain.html.in | 9 +++
docs/schemas/domaincommon.rng | 10 ++++
src/libvirt_private.syms | 2 +
tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-boot-floppy.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-boot-network.xml | 1 +
.../qemuxml2argv-boot-strict-off.args | 36 ++++++++++++
.../qemuxml2argv-boot-strict-off.xml | 67 ++++++++++++++++++++++
.../qemuxml2argv-clock-localtime.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-clock-utc.xml | 1 +
.../qemuxml2argv-console-compat.xml | 1 +
.../qemuxml2argv-disk-cdrom-empty.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom.xml | 1 +
.../qemuxml2argv-disk-drive-boot-cdrom.xml | 1 +
.../qemuxml2argv-disk-drive-boot-disk.xml | 1 +
.../qemuxml2argv-disk-drive-cache-directsync.xml | 1 +
.../qemuxml2argv-disk-drive-cache-unsafe.xml | 1 +
.../qemuxml2argv-disk-drive-cache-v1-none.xml | 1 +
.../qemuxml2argv-disk-drive-cache-v1-wb.xml | 1 +
.../qemuxml2argv-disk-drive-cache-v2-none.xml | 1 +
.../qemuxml2argv-disk-drive-cache-v2-wb.xml | 1 +
.../qemuxml2argv-disk-drive-cache-v2-wt.xml | 1 +
...muxml2argv-disk-drive-error-policy-enospace.xml | 1 +
.../qemuxml2argv-disk-drive-error-policy-stop.xml | 1 +
...rgv-disk-drive-error-policy-wreport-rignore.xml | 1 +
.../qemuxml2argv-disk-drive-fmt-qcow.xml | 1 +
.../qemuxml2argv-disk-drive-network-gluster.xml | 1 +
.../qemuxml2argv-disk-drive-network-iscsi.xml | 1 +
.../qemuxml2argv-disk-drive-network-nbd-export.xml | 1 +
...xml2argv-disk-drive-network-nbd-ipv6-export.xml | 1 +
.../qemuxml2argv-disk-drive-network-nbd-ipv6.xml | 1 +
.../qemuxml2argv-disk-drive-network-nbd-unix.xml | 1 +
.../qemuxml2argv-disk-drive-network-nbd.xml | 1 +
...emuxml2argv-disk-drive-network-rbd-ceph-env.xml | 1 +
.../qemuxml2argv-disk-drive-network-rbd-ipv6.xml | 1 +
.../qemuxml2argv-disk-drive-network-rbd.xml | 1 +
.../qemuxml2argv-disk-drive-network-sheepdog.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-disk-floppy.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-disk-many.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-disk-usb.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-disk-virtio.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-disk-xenvbd.xml | 1 +
.../qemuxml2argv-graphics-sdl-fullscreen.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml | 1 +
.../qemuxml2argv-graphics-vnc-policy.xml | 1 +
.../qemuxml2argv-graphics-vnc-sasl.xml | 1 +
.../qemuxml2argv-graphics-vnc-socket.xml | 1 +
.../qemuxml2argv-graphics-vnc-tls.xml | 1 +
.../qemuxml2argv-graphics-vnc-websocket.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml | 1 +
.../qemuxml2argv-hostdev-pci-address.xml | 1 +
.../qemuxml2argv-hostdev-usb-address.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-hyperv.xml | 1 +
.../qemuxml2argv-input-usbmouse.xml | 1 +
.../qemuxml2argv-input-usbtablet.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-kvmclock.xml | 1 +
.../qemuxml2argv-machine-core-off.xml | 1 +
.../qemuxml2argv-machine-core-on.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-migrate.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-misc-acpi.xml | 1 +
.../qemuxml2argv-misc-disable-s3.xml | 1 +
.../qemuxml2argv-misc-disable-suspends.xml | 1 +
.../qemuxml2argv-misc-enable-s4.xml | 1 +
.../qemuxml2argv-misc-no-reboot.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-misc-uuid.xml | 1 +
.../qemuxml2argv-net-eth-ifname.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-net-eth.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-net-user.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-net-virtio.xml | 1 +
.../qemuxml2argv-nographics-vga.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-nosharepages.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-parallel-tcp.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-pseries-disk.xml | 1 +
.../qemuxml2argv-pseries-nvram.xml | 1 +
.../qemuxml2argv-qemu-ns-no-env.xml | 1 +
.../qemuxml2argv-reboot-timeout-disabled.xml | 1 +
.../qemuxml2argv-reboot-timeout-enabled.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-restore-v1.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-restore-v2.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-serial-dev.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-serial-file.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-serial-many.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-serial-pty.xml | 1 +
.../qemuxml2argv-serial-tcp-telnet.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-serial-tcp.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-serial-udp.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-serial-unix.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-serial-vc.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-smp.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-sound.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-watchdog.xml | 1 +
96 files changed, 268 insertions(+), 1 deletion(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-boot-strict-off.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-boot-strict-off.xml
--
1.8.3.1
10 years, 9 months
[libvirt] [PATCH v3 1/2] BSD: implement nodeGetCPUStats
by Roman Bogorodskiy
Implementation obtains CPU usage information using
kern.cp_time and kern.cp_times sysctl(8)s and reports
CPU utilization.
---
include/libvirt/libvirt.h.in | 8 ++++
src/nodeinfo.c | 104 +++++++++++++++++++++++++++++++++++++++++++
tools/virsh-host.c | 11 ++++-
3 files changed, 121 insertions(+), 2 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index b3ce000..295d551 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -692,6 +692,14 @@ typedef enum {
#define VIR_NODE_CPU_STATS_IOWAIT "iowait"
/**
+ * VIR_NODE_CPU_STATS_INTR:
+ *
+ * The cumulative interrupt CPU time,
+ * since the node booting up (in nanoseconds).
+ */
+#define VIR_NODE_CPU_STATS_INTR "intr"
+
+/**
* VIR_NODE_CPU_STATS_UTILIZATION:
*
* The CPU utilization of a node.
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index 6ebfb4b..9a1548e 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -34,8 +34,10 @@
#include "conf/domain_conf.h"
#if defined(__FreeBSD__) || defined(__APPLE__)
+# include <sys/time.h>
# include <sys/types.h>
# include <sys/sysctl.h>
+# include <sys/resource.h>
#endif
#include "c-ctype.h"
@@ -99,8 +101,108 @@ appleFreebsdNodeGetMemorySize(unsigned long *memory)
#endif /* defined(__FreeBSD__) || defined(__APPLE__) */
#ifdef __FreeBSD__
+# define BSD_CPU_STATS_ALL 4
# define BSD_MEMORY_STATS_ALL 4
+# define TICK_TO_NSEC (1000ull * 1000ull * 1000ull / (stathz ? stathz : hz))
+
+static int
+freebsdNodeGetCPUStats(int cpuNum,
+ virNodeCPUStatsPtr params,
+ int *nparams)
+{
+ const char *sysctl_name;
+ long *cpu_times;
+ struct clockinfo clkinfo;
+ size_t i, j, cpu_times_size, clkinfo_size;
+ int cpu_times_num, offset, hz, stathz, ret = -1;
+ struct field_cpu_map {
+ const char *field;
+ int idx[CPUSTATES];
+ } cpu_map[] = {
+ {VIR_NODE_CPU_STATS_KERNEL, {CP_SYS}},
+ {VIR_NODE_CPU_STATS_USER, {CP_USER, CP_NICE}},
+ {VIR_NODE_CPU_STATS_IDLE, {CP_IDLE}},
+ {VIR_NODE_CPU_STATS_INTR, {CP_INTR}},
+ {NULL, {0}}
+ };
+
+ if ((*nparams) == 0) {
+ *nparams = BSD_CPU_STATS_ALL;
+ return 0;
+ }
+
+ if ((*nparams) != BSD_CPU_STATS_ALL) {
+ virReportInvalidArg(*nparams,
+ _("nparams in %s must be equal to %d"),
+ __FUNCTION__, BSD_CPU_STATS_ALL);
+ return -1;
+ }
+
+ clkinfo_size = sizeof(clkinfo);
+ if (sysctlbyname("kern.clockrate", &clkinfo, &clkinfo_size, NULL, 0) < 0) {
+ virReportSystemError(errno,
+ _("sysctl failed for '%s'"),
+ "kern.clockrate");
+ return -1;
+ }
+
+ stathz = clkinfo.stathz;
+ hz = clkinfo.hz;
+
+ if (cpuNum == VIR_NODE_CPU_STATS_ALL_CPUS) {
+ sysctl_name = "kern.cp_time";
+ cpu_times_num = 1;
+ offset = 0;
+ } else {
+ sysctl_name = "kern.cp_times";
+ cpu_times_num = appleFreebsdNodeGetCPUCount();
+
+ if (cpuNum >= cpu_times_num) {
+ virReportInvalidArg(cpuNum,
+ _("Invalid cpuNum in %s"),
+ __FUNCTION__);
+ return -1;
+ }
+
+ offset = cpu_times_num * CPUSTATES;
+ }
+
+ cpu_times_size = sizeof(long) * cpu_times_num * CPUSTATES;
+
+ if (VIR_ALLOC_N(cpu_times, cpu_times_num * CPUSTATES) < 0)
+ goto cleanup;
+
+ if (sysctlbyname(sysctl_name, cpu_times, &cpu_times_size, NULL, 0) < 0) {
+ virReportSystemError(errno,
+ _("sysctl failed for '%s'"),
+ sysctl_name);
+ goto cleanup;
+ }
+
+ for (i = 0; cpu_map[i].field != NULL; i++) {
+ virNodeCPUStatsPtr param = ¶ms[i];
+
+ if (virStrcpyStatic(param->field, cpu_map[i].field) == NULL) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Field '%s' too long for destination"),
+ cpu_map[i].field);
+ goto cleanup;
+ }
+
+ param->value = 0;
+ for (j = 0; j < ARRAY_CARDINALITY(cpu_map[i].idx); j++)
+ param->value += cpu_times[offset + cpu_map[i].idx[j]] * TICK_TO_NSEC;
+ }
+
+ ret = 0;
+
+cleanup:
+ VIR_FREE(cpu_times);
+
+ return ret;
+}
+
static int
freebsdNodeGetMemoryStats(virNodeMemoryStatsPtr params,
int *nparams)
@@ -1045,6 +1147,8 @@ int nodeGetCPUStats(int cpuNum ATTRIBUTE_UNUSED,
return ret;
}
+#elif defined(__FreeBSD__)
+ return freebsdNodeGetCPUStats(cpuNum, params, nparams);
#else
virReportError(VIR_ERR_NO_SUPPORT, "%s",
_("node CPU stats not implemented on this platform"));
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 3438ae7..f4ca7db 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -347,9 +347,10 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
unsigned long long sys;
unsigned long long idle;
unsigned long long iowait;
+ unsigned long long intr;
unsigned long long util;
} cpu_stats[2];
- double user_time, sys_time, idle_time, iowait_time, total_time;
+ double user_time, sys_time, idle_time, iowait_time, intr_time, total_time;
double usage;
if (vshCommandOptInt(cmd, "cpu", &cpuNum) < 0) {
@@ -390,6 +391,8 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
cpu_stats[i].idle = value;
} else if (STREQ(params[j].field, VIR_NODE_CPU_STATS_IOWAIT)) {
cpu_stats[i].iowait = value;
+ } else if (STREQ(params[j].field, VIR_NODE_CPU_STATS_INTR)) {
+ cpu_stats[i].intr = value;
} else if (STREQ(params[j].field, VIR_NODE_CPU_STATS_UTILIZATION)) {
cpu_stats[i].util = value;
flag_utilization = true;
@@ -406,6 +409,7 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, "%-15s %20llu\n", _("system:"), cpu_stats[0].sys);
vshPrint(ctl, "%-15s %20llu\n", _("idle:"), cpu_stats[0].idle);
vshPrint(ctl, "%-15s %20llu\n", _("iowait:"), cpu_stats[0].iowait);
+ vshPrint(ctl, "%-15s %20llu\n", _("intr:"), cpu_stats[0].intr);
}
} else {
if (flag_utilization) {
@@ -418,7 +422,8 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
sys_time = cpu_stats[1].sys - cpu_stats[0].sys;
idle_time = cpu_stats[1].idle - cpu_stats[0].idle;
iowait_time = cpu_stats[1].iowait - cpu_stats[0].iowait;
- total_time = user_time + sys_time + idle_time + iowait_time;
+ intr_time = cpu_stats[1].intr - cpu_stats[0].intr;
+ total_time = user_time + sys_time + idle_time + iowait_time + intr_time;
usage = (user_time + sys_time) / total_time * 100;
@@ -432,6 +437,8 @@ cmdNodeCpuStats(vshControl *ctl, const vshCmd *cmd)
_("idle:"), idle_time / total_time * 100);
vshPrint(ctl, "%-15s %5.1lf%%\n",
_("iowait:"), iowait_time / total_time * 100);
+ vshPrint(ctl, "%-15s %5.1lf%%\n",
+ _("intr:"), intr_time / total_time * 100);
}
}
--
1.8.4.3
10 years, 9 months
[libvirt] [PATCH v3] bhyve: add a basic driver
by Roman Bogorodskiy
Changes from the previos version, based on Daniel's feedback:
* Moved autoconf driver detection to m4/
* Added driver sources to STATEFUL_DRIVER_SOURCE_FILES
* Dropped unneeded locking from DefineXML
* Initial implemtation of dumpxml/dominfo, stub of state
* Moved command generation to bhyve_command.c
* Attempt to unload VM on errors
Roman Bogorodskiy (1):
bhyve: add a basic driver
configure.ac | 11 +
daemon/libvirtd.c | 9 +
include/libvirt/virterror.h | 1 +
m4/virt-driver-bhyve.m4 | 52 ++++
src/Makefile.am | 38 +++
src/bhyve/bhyve_command.c | 269 +++++++++++++++++++++
src/bhyve/bhyve_command.h | 41 ++++
src/bhyve/bhyve_driver.c | 566 ++++++++++++++++++++++++++++++++++++++++++++
src/bhyve/bhyve_driver.h | 28 +++
src/bhyve/bhyve_process.c | 205 ++++++++++++++++
src/bhyve/bhyve_process.h | 36 +++
src/bhyve/bhyve_utils.h | 48 ++++
src/conf/domain_conf.c | 3 +-
src/conf/domain_conf.h | 1 +
src/driver.h | 1 +
src/libvirt.c | 3 +
src/util/virerror.c | 1 +
17 files changed, 1312 insertions(+), 1 deletion(-)
create mode 100644 m4/virt-driver-bhyve.m4
create mode 100644 src/bhyve/bhyve_command.c
create mode 100644 src/bhyve/bhyve_command.h
create mode 100644 src/bhyve/bhyve_driver.c
create mode 100644 src/bhyve/bhyve_driver.h
create mode 100644 src/bhyve/bhyve_process.c
create mode 100644 src/bhyve/bhyve_process.h
create mode 100644 src/bhyve/bhyve_utils.h
--
1.8.4.3
10 years, 9 months
[libvirt] [v11 0/6] Write separate module for hostdev passthrough
by Chunyan Liu
These patches implements a separate module for hostdev passthrough so that it
could be shared by different drivers and can maintain a global state of a host
device.
patch 1/6: extract hostdev passthrough function from qemu_hostdev.c and make it
reusable by multiple drivers.
patch 2/6: add a unit test for hostdev common library.
patch 3/6: switch qemu driver to use the common library instead of its own
hostdev passthrough APIs.
patch 4/6: switch lxc driver to use the common library instead of its own
hostdev passthrough APIs.
patch 5/6: add a hostdev pci backend type for xen usage.
patch 6/6: add pci passthrough to libxl driver.
---
Changes
* rebase to lastest changes in src/util/virscsi.c, src/qemu/qemu_process.c,
tests/virpcimock.c, etc.
Chunyan Liu (6):
add hostdev passthrough common library
add unit test for hostdev common library
change qemu driver to use hostdev common library
change lxc driver to use hostdev common library
add hostdev pci backend type for xen
add pci passthrough to libxl driver
docs/schemas/domaincommon.rng | 1 +
po/POTFILES.in | 3 +-
src/Makefile.am | 3 +-
src/conf/domain_conf.c | 3 +-
src/conf/domain_conf.h | 1 +
src/libvirt_private.syms | 21 +
src/libxl/libxl_conf.c | 63 +
src/libxl/libxl_conf.h | 4 +
src/libxl/libxl_domain.c | 9 +
src/libxl/libxl_driver.c | 448 +++++-
src/lxc/lxc_conf.h | 4 -
src/lxc/lxc_driver.c | 47 +-
src/lxc/lxc_hostdev.c | 413 -----
src/lxc/lxc_hostdev.h | 43 -
src/lxc/lxc_process.c | 24 +-
src/qemu/qemu_command.c | 4 +-
src/qemu/qemu_conf.h | 9 +-
src/qemu/qemu_domain.c | 22 +
src/qemu/qemu_driver.c | 81 +-
src/qemu/qemu_hostdev.c | 1457 -----------------
src/qemu/qemu_hostdev.h | 76 -
src/qemu/qemu_hotplug.c | 136 +-
src/qemu/qemu_process.c | 40 +-
src/util/virhostdev.c | 1706 ++++++++++++++++++++
src/util/virhostdev.h | 134 ++
src/util/virpci.c | 30 +-
src/util/virpci.h | 9 +-
src/util/virscsi.c | 28 +-
src/util/virscsi.h | 8 +-
src/util/virusb.c | 29 +-
src/util/virusb.h | 8 +-
tests/Makefile.am | 5 +
.../qemuxml2argv-hostdev-pci-address.xml | 1 +
.../qemuxml2argvdata/qemuxml2argv-net-hostdev.xml | 1 +
tests/qemuxml2argvdata/qemuxml2argv-pci-rom.xml | 2 +
tests/virhostdevtest.c | 473 ++++++
36 files changed, 3132 insertions(+), 2214 deletions(-)
delete mode 100644 src/lxc/lxc_hostdev.c
delete mode 100644 src/lxc/lxc_hostdev.h
delete mode 100644 src/qemu/qemu_hostdev.c
delete mode 100644 src/qemu/qemu_hostdev.h
create mode 100644 src/util/virhostdev.c
create mode 100644 src/util/virhostdev.h
create mode 100644 tests/virhostdevtest.c
10 years, 9 months