[libvirt] [PATCH 0/2] Remove calls that just clear alias
by John Ferlan
Based off review of :
http://www.redhat.com/archives/libvir-list/2016-July/msg00672.html
Rather than add the ignore_value, just remove the unused / unnecessary code
Patch 1 has no callers any more and from inspection patch 2 is essentially
redone again as each device is handled during domain def deletion.
Ran make -C tests valgrind with no errors too
John Ferlan (2):
conf: Remove CCW,PCI clear address helpers
Remove unnecessary virDomainDefClearDeviceAliases
src/conf/domain_conf.c | 50 ------------------------------------------------
src/conf/domain_conf.h | 3 ---
src/libvirt_private.syms | 3 ---
src/qemu/qemu_process.c | 2 --
4 files changed, 58 deletions(-)
--
2.5.5
8 years, 5 months
[libvirt] [RFC] Switch to nftables from netfilter
by Michal Privoznik
Dear list,
I've came across nftables [1]. They look very promising, more than old
netfilter. It offers new features [2], from which I'd pick:
- better performance under high traffic workloads
- atomic filter/chain replacements
- transactions
I haven't investigated how much work will be required on our side if we
try to implement the switch (well, for starters, we can have two
subsystems living next to each other). I want to check what do you guys
think before actually digging into the code.
The nftables was merged into 3.13 Linux kernel and thus should be
available on all major distros. Well, since we will have both subsystems
available, we should be good to go.
BTW: it's a bit shame that this nifty project hasn't received much more
advertising. Looks cool so far.
Michal
1: https://en.wikipedia.org/wiki/Nftables
2: http://people.netfilter.org/kaber/nfws2008/nftables.odp
8 years, 5 months
[libvirt] [PATCH] qemu: Fix backwards compatibility of S390 guests
by Boris Fiuczynski
This patch reverts commit 73e4e10e62e4b1aea64b317be96af5e5488007d7
and thereby disabling the panic device autogeneration for S390 guests.
In addition tests are patched as well.
The reverted commit breaks backwards compatibility of S390 guests.
As an example: A domain xml without a panic device can successfully
be used to define on two hosts with different libvirt versions.
Using this domain xml to define a domain on a host with libivrt v1.3.5
makes it impossible to migrate the domain to a host with libvirt v1.3.4
or older since libvirt v1.3.5 automatically added a panic device with
model s390 which libvirt v1.3.4 or older rejects as unknown model.
Signed-off-by: Boris Fiuczynski <fiuczy(a)linux.vnet.ibm.com>
Tested-by: Bjoern Walk <bwalk(a)linux.vnet.ibm.com>
---
src/qemu/qemu_domain.c | 6 +-----
tests/qemuargv2xmldata/qemuargv2xml-machine-aeskeywrap-off-argv.xml | 1 -
tests/qemuargv2xmldata/qemuargv2xml-machine-aeskeywrap-on-argv.xml | 1 -
tests/qemuargv2xmldata/qemuargv2xml-machine-deakeywrap-off-argv.xml | 1 -
tests/qemuargv2xmldata/qemuargv2xml-machine-deakeywrap-on-argv.xml | 1 -
tests/qemuargv2xmldata/qemuargv2xml-machine-keywrap-none-argv.xml | 1 -
.../qemuxml2xmloutdata/qemuxml2xmlout-iothreads-disk-virtio-ccw.xml | 1 -
.../qemuxml2xmloutdata/qemuxml2xmlout-iothreads-virtio-scsi-ccw.xml | 1 -
tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml | 1 -
tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-panic-missing.xml | 1 -
10 files changed, 1 insertion(+), 14 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 6372080..1d63066 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2009,7 +2009,6 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def,
case VIR_ARCH_S390:
case VIR_ARCH_S390X:
addDefaultUSB = false;
- addPanicDevice = true;
break;
case VIR_ARCH_SPARC:
@@ -2114,10 +2113,7 @@ qemuDomainDefAddDefaultDevices(virDomainDefPtr def,
size_t j;
for (j = 0; j < def->npanics; j++) {
if (def->panics[j]->model == VIR_DOMAIN_PANIC_MODEL_DEFAULT ||
- (ARCH_IS_PPC64(def->os.arch) &&
- def->panics[j]->model == VIR_DOMAIN_PANIC_MODEL_PSERIES) ||
- (ARCH_IS_S390(def->os.arch) &&
- def->panics[j]->model == VIR_DOMAIN_PANIC_MODEL_S390))
+ def->panics[j]->model == VIR_DOMAIN_PANIC_MODEL_PSERIES)
break;
}
diff --git a/tests/qemuargv2xmldata/qemuargv2xml-machine-aeskeywrap-off-argv.xml b/tests/qemuargv2xmldata/qemuargv2xml-machine-aeskeywrap-off-argv.xml
index 7c100a7..fa25f44 100644
--- a/tests/qemuargv2xmldata/qemuargv2xml-machine-aeskeywrap-off-argv.xml
+++ b/tests/qemuargv2xmldata/qemuargv2xml-machine-aeskeywrap-off-argv.xml
@@ -15,7 +15,6 @@
<devices>
<emulator>/usr/bin/qemu-system-s390x</emulator>
<memballoon model='none'/>
- <panic model='s390'/>
</devices>
<keywrap>
<cipher name='aes' state='off'/>
diff --git a/tests/qemuargv2xmldata/qemuargv2xml-machine-aeskeywrap-on-argv.xml b/tests/qemuargv2xmldata/qemuargv2xml-machine-aeskeywrap-on-argv.xml
index 94bb6b2..cfb4dd1 100644
--- a/tests/qemuargv2xmldata/qemuargv2xml-machine-aeskeywrap-on-argv.xml
+++ b/tests/qemuargv2xmldata/qemuargv2xml-machine-aeskeywrap-on-argv.xml
@@ -15,7 +15,6 @@
<devices>
<emulator>/usr/bin/qemu-system-s390x</emulator>
<memballoon model='none'/>
- <panic model='s390'/>
</devices>
<keywrap>
<cipher name='aes' state='on'/>
diff --git a/tests/qemuargv2xmldata/qemuargv2xml-machine-deakeywrap-off-argv.xml b/tests/qemuargv2xmldata/qemuargv2xml-machine-deakeywrap-off-argv.xml
index a707ce3..78e44c5 100644
--- a/tests/qemuargv2xmldata/qemuargv2xml-machine-deakeywrap-off-argv.xml
+++ b/tests/qemuargv2xmldata/qemuargv2xml-machine-deakeywrap-off-argv.xml
@@ -15,7 +15,6 @@
<devices>
<emulator>/usr/bin/qemu-system-s390x</emulator>
<memballoon model='none'/>
- <panic model='s390'/>
</devices>
<keywrap>
<cipher name='dea' state='off'/>
diff --git a/tests/qemuargv2xmldata/qemuargv2xml-machine-deakeywrap-on-argv.xml b/tests/qemuargv2xmldata/qemuargv2xml-machine-deakeywrap-on-argv.xml
index 41c464a..c85d1c5 100644
--- a/tests/qemuargv2xmldata/qemuargv2xml-machine-deakeywrap-on-argv.xml
+++ b/tests/qemuargv2xmldata/qemuargv2xml-machine-deakeywrap-on-argv.xml
@@ -15,7 +15,6 @@
<devices>
<emulator>/usr/bin/qemu-system-s390x</emulator>
<memballoon model='none'/>
- <panic model='s390'/>
</devices>
<keywrap>
<cipher name='dea' state='on'/>
diff --git a/tests/qemuargv2xmldata/qemuargv2xml-machine-keywrap-none-argv.xml b/tests/qemuargv2xmldata/qemuargv2xml-machine-keywrap-none-argv.xml
index 0b0ce70..5640544 100644
--- a/tests/qemuargv2xmldata/qemuargv2xml-machine-keywrap-none-argv.xml
+++ b/tests/qemuargv2xmldata/qemuargv2xml-machine-keywrap-none-argv.xml
@@ -15,6 +15,5 @@
<devices>
<emulator>/usr/bin/qemu-system-s390x</emulator>
<memballoon model='none'/>
- <panic model='s390'/>
</devices>
</domain>
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-iothreads-disk-virtio-ccw.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-iothreads-disk-virtio-ccw.xml
index f6d1039..b6f7d30 100644
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-iothreads-disk-virtio-ccw.xml
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-iothreads-disk-virtio-ccw.xml
@@ -31,6 +31,5 @@
<memballoon model='virtio'>
<address type='ccw' cssid='0xfe' ssid='0x0' devno='0x000a'/>
</memballoon>
- <panic model='s390'/>
</devices>
</domain>
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-iothreads-virtio-scsi-ccw.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-iothreads-virtio-scsi-ccw.xml
index 5e91f1c..2499782 100644
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-iothreads-virtio-scsi-ccw.xml
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-iothreads-virtio-scsi-ccw.xml
@@ -35,6 +35,5 @@
<memballoon model='virtio'>
<address type='ccw' cssid='0xfe' ssid='0x0' devno='0x000a'/>
</memballoon>
- <panic model='s390'/>
</devices>
</domain>
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml
index 42ad4e4..3f349b2 100644
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-defaultconsole.xml
@@ -20,6 +20,5 @@
<target type='virtio' port='0'/>
</console>
<memballoon model='none'/>
- <panic model='s390'/>
</devices>
</domain>
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-panic-missing.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-panic-missing.xml
index 8864157..0f40eb0 100644
--- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-panic-missing.xml
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-s390-panic-missing.xml
@@ -24,6 +24,5 @@
<memballoon model='virtio'>
<address type='ccw' cssid='0xfe' ssid='0x0' devno='0x0002'/>
</memballoon>
- <panic model='s390'/>
</devices>
</domain>
--
2.9.0
8 years, 5 months
[libvirt] [PATCH v3] util: systemd: Define MSG_NOSIGNAL if needed
by Andrea Bolognani
The symbol being missing has been reported as causing build
failures on OS X. If it's not already defined, define it to
zero so that it won't have any effect.
---
Changes from v2:
* define MSG_NOSIGNAL to zero if not already defined
instead of conditionally compiling the code depending
on it
src/util/virsystemd.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 969cd68..7d6985b 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -41,6 +41,10 @@
VIR_LOG_INIT("util.systemd");
+#ifndef MSG_NOSIGNAL
+# define MSG_NOSIGNAL 0
+#endif
+
static void virSystemdEscapeName(virBufferPtr buf,
const char *name)
{
--
2.7.4
8 years, 5 months
[libvirt] Schedule for next release
by Daniel Veillard
About time to roll that one.
I think we need to enter freese on Wednesday, then I can make rc2 on Friday,
and hopefully we can push 2.1.0 on Monday or Tuesday next week.
Raise a flag if that doesn't work :-)
thanks,
Daniel
--
Daniel Veillard | Open Source and Standards, Red Hat
veillard(a)redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | virtualization library http://libvirt.org/
8 years, 5 months
[libvirt] [PATCH v4] libxl: implement virDomainBlockStats
by Joao Martins
Introduce initial support for domainBlockStats API call that
allow us to query block device statistics. openstack nova
uses this API call to query block statistics, alongside
virDomainMemoryStats and virDomainInterfaceStats. Note that
this patch only introduces it for VBD for starters. QDisk
would come in a separate patch series.
A new statistics data structure is introduced to fit common
statistics among others specific to the underlying block
backends. For the VBD statistics on linux these are exported
via sysfs on the path:
"/sys/bus/xen-backend/devices/vbd-<domid>-<devid>/statistics"
To calculate the block devno libxlDiskPathToID is introduced.
Each backend implements its own function to extract statistics
and let there be handled the different platforms.
VBD stats are exposed in reqs and number of sectors from
blkback, and it's up to us to convert it to sector sizes.
The sector size is gathered through xenstore in the device
backend entry "physical-sector-size".
BlockStatsFlags variant is also implemented which has the
added benefit of getting the number of flush requests.
Signed-off-by: Joao Martins <joao.m.martins(a)oracle.com>
---
Changes since v3:
- No need for error in libxlDiskSectorSize()
- Fix an identation issue.
- Rework cleanup paths on libxlDiskSectorSize()
- Do not unlock vm if libxlDomainObjEndJob() returns false and
adjust to the newly introduced virDomainObjEndAPI()
- Bump version to 2.1.0
Changes since v1:
- Fix identation issues
- Set ret to LIBXL_VBD_SECTOR_SIZE
- Reuse VIR_STRDUP error instead of doing virReportError
when we fail to set stats->backend
- Change virAsprintf(...) error checking
- Change error to VIR_ERR_OPERATION_FAILED when xenstore path
does not exist and when failing to read stat.
- Resolve issues with 'make syntax-check' with cppi installed.
- Remove libxlDiskPathMatches in favor of using virutil
virDiskNameParse to fetch disk and partition index.
- Rename libxlDiskPathParse to libxlDiskPathToID and rework
function to just convert disk and partition index to devno.
- Bump version to 1.2.22
---
src/libxl/libxl_driver.c | 364 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 364 insertions(+)
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index f153f69..189bfb5 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -30,6 +30,7 @@
#include <math.h>
#include <libxl.h>
#include <libxl_utils.h>
+#include <xenstore.h>
#include <fcntl.h>
#include <regex.h>
@@ -72,6 +73,7 @@ VIR_LOG_INIT("libxl.libxl_driver");
#define LIBXL_DOM_REQ_HALT 4
#define LIBXL_NB_TOTAL_CPU_STAT_PARAM 1
+#define LIBXL_NB_TOTAL_BLK_STAT_PARAM 6
#define HYPERVISOR_CAPABILITIES "/proc/xen/capabilities"
#define HYPERVISOR_XENSTORED "/dev/xen/xenstored"
@@ -100,6 +102,25 @@ struct _libxlOSEventHookInfo {
int id;
};
+/* Object used to store disk statistics across multiple xen backends */
+typedef struct _libxlBlockStats libxlBlockStats;
+typedef libxlBlockStats *libxlBlockStatsPtr;
+struct _libxlBlockStats {
+ long long rd_req;
+ long long rd_bytes;
+ long long wr_req;
+ long long wr_bytes;
+ long long f_req;
+
+ char *backend;
+ union {
+ struct {
+ long long ds_req;
+ long long oo_req;
+ } vbd;
+ } u;
+};
+
/* Function declarations */
static int
libxlDomainManagedSaveLoad(virDomainObjPtr vm,
@@ -5031,6 +5052,347 @@ libxlDomainGetJobStats(virDomainPtr dom,
}
static int
+libxlDiskPathToID(const char *virtpath)
+{
+ static char const* drive_prefix[] = {"xvd", "hd", "sd"};
+ int disk, partition, chrused;
+ int fmt, id;
+ char *r;
+ size_t i;
+
+ fmt = id = -1;
+
+ /* Find any disk prefixes we know about */
+ for (i = 0; i < ARRAY_CARDINALITY(drive_prefix); i++) {
+ if (STRPREFIX(virtpath, drive_prefix[i]) &&
+ !virDiskNameParse(virtpath, &disk, &partition)) {
+ fmt = i;
+ break;
+ }
+ }
+
+ /* Handle it same way as xvd */
+ if (fmt < 0 &&
+ (sscanf(virtpath, "d%ip%i%n", &disk, &partition, &chrused) >= 2
+ && chrused == strlen(virtpath)))
+ fmt = 0;
+
+ /* Test indexes ranges and calculate the device id */
+ switch (fmt) {
+ case 0: /* xvd */
+ if (disk <= 15 && partition <= 15)
+ id = (202 << 8) | (disk << 4) | partition;
+ else if ((disk <= ((1<<20)-1)) || partition <= 255)
+ id = (1 << 28) | (disk << 8) | partition;
+ break;
+ case 1: /* hd */
+ if (disk <= 3 && partition <= 63)
+ id = ((disk < 2 ? 3 : 22) << 8) | ((disk & 1) << 6) | partition;
+ break;
+ case 2: /* sd */
+ if (disk <= 15 && (partition <= 15))
+ id = (8 << 8) | (disk << 4) | partition;
+ break;
+ default:
+ errno = virStrToLong_i(virtpath, &r, 0, &id);
+ if (errno || *r || id > INT_MAX)
+ id = -1;
+ break;
+ }
+ return id;
+}
+
+#define LIBXL_VBD_SECTOR_SIZE 512
+
+static int
+libxlDiskSectorSize(int domid, int devno)
+{
+ char *path, *val;
+ struct xs_handle *handle;
+ int ret = LIBXL_VBD_SECTOR_SIZE;
+ unsigned int len;
+
+ handle = xs_daemon_open_readonly();
+ if (!handle) {
+ VIR_WARN("cannot read sector size");
+ return ret;
+ }
+
+ path = val = NULL;
+ if (virAsprintf(&path, "/local/domain/%d/device/vbd/%d/backend",
+ domid, devno) < 0)
+ goto cleanup;
+
+ if ((val = xs_read(handle, XBT_NULL, path, &len)) == NULL)
+ goto cleanup;
+
+ VIR_FREE(path);
+ if (virAsprintf(&path, "%s/physical-sector-size", val) < 0)
+ goto cleanup;
+
+ VIR_FREE(val);
+ if ((val = xs_read(handle, XBT_NULL, path, &len)) == NULL)
+ goto cleanup;
+
+ if (sscanf(val, "%d", &ret) != 1)
+ ret = LIBXL_VBD_SECTOR_SIZE;
+
+ cleanup:
+ VIR_FREE(val);
+ VIR_FREE(path);
+ xs_daemon_close(handle);
+ return ret;
+}
+
+static int
+libxlDomainBlockStatsVBD(virDomainObjPtr vm,
+ const char *dev,
+ libxlBlockStatsPtr stats)
+{
+ int ret = -1;
+ int devno = libxlDiskPathToID(dev);
+ int size = libxlDiskSectorSize(vm->def->id, devno);
+#ifdef __linux__
+ char *path, *name, *val;
+ unsigned long long stat;
+
+ path = name = val = NULL;
+ if (devno < 0) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("cannot find device number"));
+ return ret;
+ }
+ if (VIR_STRDUP(stats->backend, "vbd") < 0)
+ return ret;
+
+ if (virAsprintf(&path, "/sys/bus/xen-backend/devices/vbd-%d-%d/statistics",
+ vm->def->id, devno) < 0)
+ return ret;
+
+ if (!virFileExists(path)) {
+ virReportError(VIR_ERR_OPERATION_FAILED,
+ "%s", _("cannot open bus path"));
+ goto cleanup;
+ }
+
+# define LIBXL_SET_VBDSTAT(FIELD, VAR, MUL) \
+ if ((virAsprintf(&name, "%s/"FIELD, path) < 0) || \
+ (virFileReadAll(name, 256, &val) < 0) || \
+ (sscanf(val, "%llu", &stat) != 1)) { \
+ virReportError(VIR_ERR_OPERATION_FAILED, \
+ _("cannot read %s"), name); \
+ goto cleanup; \
+ } \
+ VAR += (stat * MUL); \
+ VIR_FREE(name); \
+ VIR_FREE(val);
+
+ LIBXL_SET_VBDSTAT("f_req", stats->f_req, 1)
+ LIBXL_SET_VBDSTAT("wr_req", stats->wr_req, 1)
+ LIBXL_SET_VBDSTAT("rd_req", stats->rd_req, 1)
+ LIBXL_SET_VBDSTAT("wr_sect", stats->wr_bytes, size)
+ LIBXL_SET_VBDSTAT("rd_sect", stats->rd_bytes, size)
+
+ LIBXL_SET_VBDSTAT("ds_req", stats->u.vbd.ds_req, size)
+ LIBXL_SET_VBDSTAT("oo_req", stats->u.vbd.oo_req, 1)
+ ret = 0;
+
+ cleanup:
+ VIR_FREE(name);
+ VIR_FREE(path);
+ VIR_FREE(val);
+
+# undef LIBXL_SET_VBDSTAT
+
+#else
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ "%s", _("platform unsupported"));
+#endif
+ return ret;
+}
+
+static int
+libxlDomainBlockStatsGatherSingle(virDomainObjPtr vm,
+ const char *path,
+ libxlBlockStatsPtr stats)
+{
+ virDomainDiskDefPtr disk;
+ const char *disk_drv;
+ int ret = -1, disk_fmt;
+
+ if (!(disk = virDomainDiskByName(vm->def, path, false))) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("invalid path: %s"), path);
+ return ret;
+ }
+
+ disk_fmt = virDomainDiskGetFormat(disk);
+ if (!(disk_drv = virDomainDiskGetDriver(disk)))
+ disk_drv = "qemu";
+
+ if (STREQ(disk_drv, "phy")) {
+ if (disk_fmt != VIR_STORAGE_FILE_RAW &&
+ disk_fmt != VIR_STORAGE_FILE_NONE) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("unsupported format %s"),
+ virStorageFileFormatTypeToString(disk_fmt));
+ return ret;
+ }
+
+ ret = libxlDomainBlockStatsVBD(vm, path, stats);
+ } else {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("unsupported disk driver %s"),
+ disk_drv);
+ }
+ return ret;
+}
+
+static int
+libxlDomainBlockStatsGather(virDomainObjPtr vm,
+ const char *path,
+ libxlBlockStatsPtr stats)
+{
+ int ret = -1;
+
+ if (*path) {
+ if (libxlDomainBlockStatsGatherSingle(vm, path, stats) < 0)
+ return ret;
+ } else {
+ size_t i;
+
+ for (i = 0; i < vm->def->ndisks; ++i) {
+ if (libxlDomainBlockStatsGatherSingle(vm, vm->def->disks[i]->dst,
+ stats) < 0)
+ return ret;
+ }
+ }
+ return 0;
+}
+
+static int
+libxlDomainBlockStats(virDomainPtr dom,
+ const char *path,
+ virDomainBlockStatsPtr stats)
+{
+ libxlDriverPrivatePtr driver = dom->conn->privateData;
+ virDomainObjPtr vm;
+ libxlBlockStats blkstats;
+ int ret = -1;
+
+ if (!(vm = libxlDomObjFromDomain(dom)))
+ goto cleanup;
+
+ if (virDomainBlockStatsEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_QUERY) < 0)
+ goto cleanup;
+
+ if (!virDomainObjIsActive(vm)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("domain is not running"));
+ goto endjob;
+ }
+
+ memset(&blkstats, 0, sizeof(libxlBlockStats));
+ if ((ret = libxlDomainBlockStatsGather(vm, path, &blkstats)) < 0)
+ goto endjob;
+
+ stats->rd_req = blkstats.rd_req;
+ stats->rd_bytes = blkstats.rd_bytes;
+ stats->wr_req = blkstats.wr_req;
+ stats->wr_bytes = blkstats.wr_bytes;
+ if (STREQ_NULLABLE(blkstats.backend, "vbd"))
+ stats->errs = blkstats.u.vbd.oo_req;
+ else
+ stats->errs = -1;
+
+ endjob:
+ libxlDomainObjEndJob(driver, vm);
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
+
+static int
+libxlDomainBlockStatsFlags(virDomainPtr dom,
+ const char *path,
+ virTypedParameterPtr params,
+ int *nparams,
+ unsigned int flags)
+{
+ libxlDriverPrivatePtr driver = dom->conn->privateData;
+ virDomainObjPtr vm;
+ libxlBlockStats blkstats;
+ int nstats;
+ int ret = -1;
+
+ virCheckFlags(VIR_TYPED_PARAM_STRING_OKAY, -1);
+
+ flags &= ~VIR_TYPED_PARAM_STRING_OKAY;
+
+ if (!(vm = libxlDomObjFromDomain(dom)))
+ goto cleanup;
+
+ if (virDomainBlockStatsFlagsEnsureACL(dom->conn, vm->def) < 0)
+ goto cleanup;
+
+ if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_QUERY) < 0)
+ goto cleanup;
+
+ if (!virDomainObjIsActive(vm)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ "%s", _("domain is not running"));
+ goto endjob;
+ }
+
+ /* return count of supported stats */
+ if (*nparams == 0) {
+ *nparams = LIBXL_NB_TOTAL_BLK_STAT_PARAM;
+ ret = 0;
+ goto endjob;
+ }
+
+ memset(&blkstats, 0, sizeof(libxlBlockStats));
+ if ((ret = libxlDomainBlockStatsGather(vm, path, &blkstats)) < 0)
+ goto endjob;
+
+ nstats = 0;
+
+#define LIBXL_BLKSTAT_ASSIGN_PARAM(VAR, NAME) \
+ if (nstats < *nparams && (blkstats.VAR) != -1) { \
+ if (virTypedParameterAssign(params + nstats, NAME, \
+ VIR_TYPED_PARAM_LLONG, (blkstats.VAR)) < 0) \
+ goto endjob; \
+ nstats++; \
+ }
+
+ LIBXL_BLKSTAT_ASSIGN_PARAM(wr_bytes, VIR_DOMAIN_BLOCK_STATS_WRITE_BYTES);
+ LIBXL_BLKSTAT_ASSIGN_PARAM(wr_req, VIR_DOMAIN_BLOCK_STATS_WRITE_REQ);
+
+ LIBXL_BLKSTAT_ASSIGN_PARAM(rd_bytes, VIR_DOMAIN_BLOCK_STATS_READ_BYTES);
+ LIBXL_BLKSTAT_ASSIGN_PARAM(rd_req, VIR_DOMAIN_BLOCK_STATS_READ_REQ);
+
+ LIBXL_BLKSTAT_ASSIGN_PARAM(f_req, VIR_DOMAIN_BLOCK_STATS_FLUSH_REQ);
+
+ if (STREQ_NULLABLE(blkstats.backend, "vbd"))
+ LIBXL_BLKSTAT_ASSIGN_PARAM(u.vbd.oo_req, VIR_DOMAIN_BLOCK_STATS_ERRS);
+
+ *nparams = nstats;
+
+#undef LIBXL_BLKSTAT_ASSIGN_PARAM
+
+ endjob:
+ libxlDomainObjEndJob(driver, vm);
+
+ cleanup:
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
+
+static int
libxlConnectDomainEventRegisterAny(virConnectPtr conn, virDomainPtr dom, int eventID,
virConnectDomainEventGenericCallback callback,
void *opaque, virFreeCallback freecb)
@@ -5847,6 +6209,8 @@ static virHypervisorDriver libxlHypervisorDriver = {
.domainMemoryStats = libxlDomainMemoryStats, /* 1.3.0 */
.domainGetCPUStats = libxlDomainGetCPUStats, /* 1.3.0 */
.domainInterfaceStats = libxlDomainInterfaceStats, /* 1.3.2 */
+ .domainBlockStats = libxlDomainBlockStats, /* 2.1.0 */
+ .domainBlockStatsFlags = libxlDomainBlockStatsFlags, /* 2.1.0 */
.connectDomainEventRegister = libxlConnectDomainEventRegister, /* 0.9.0 */
.connectDomainEventDeregister = libxlConnectDomainEventDeregister, /* 0.9.0 */
.domainManagedSave = libxlDomainManagedSave, /* 0.9.2 */
--
2.1.4
8 years, 5 months
[libvirt] [gconfig v2 1/2] config: Add spice listen setter
by Visarion Alexandru
Learn to set the address that spice is listening on.
---
.../libvirt-gconfig-domain-graphics-spice.c | 18 ++++++++++++++++++
.../libvirt-gconfig-domain-graphics-spice.h | 3 +++
libvirt-gconfig/libvirt-gconfig.sym | 1 +
3 files changed, 22 insertions(+)
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
index 079ea27..a773084 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.c
@@ -165,3 +165,21 @@ void gvir_config_domain_graphics_spice_set_gl(GVirConfigDomainGraphicsSpice *gra
gvir_config_object_replace_child_with_attribute_enum
(GVIR_CONFIG_OBJECT(graphics), "gl", "enable", G_TYPE_BOOLEAN, gl);
}
+
+void gvir_config_domain_graphics_spice_set_listen_address(GVirConfigDomainGraphicsSpice *graphics,
+ const char *address)
+{
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_SPICE(graphics));
+
+ gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(graphics), "listen", address, NULL);
+
+ gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(graphics),
+ "listen",
+ "address",
+ address);
+
+ gvir_config_object_add_child_with_attribute(GVIR_CONFIG_OBJECT(graphics),
+ "listen",
+ "type",
+ "address");
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h
index 25c132e..4bca850 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h
+++ b/libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h
@@ -95,6 +95,9 @@ gvir_config_domain_graphics_spice_get_image_compression
void gvir_config_domain_graphics_spice_set_gl(GVirConfigDomainGraphicsSpice *graphics,
gboolean gl);
+void gvir_config_domain_graphics_spice_set_listen_address(GVirConfigDomainGraphicsSpice *graphics,
+ const char *address);
+
G_END_DECLS
#endif /* __LIBVIRT_GCONFIG_DOMAIN_GRAPHICS_SPICE_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index f11f97a..86768ae 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -736,6 +736,7 @@ global:
LIBVIRT_GCONFIG_0.2.4 {
gvir_config_domain_graphics_spice_set_gl;
gvir_config_domain_video_set_accel3d;
+ gvir_config_domain_graphics_spice_set_listen_address;
} LIBVIRT_GCONFIG_0.2.2;
# .... define new API here using predicted next version number ....
--
2.5.5
8 years, 5 months
[libvirt] [libvirt-glib v8 5/5] tests: Add test for GVirConfigDomainHostdevPci API
by Zeeshan Ali (Khattak)
---
tests/test-gconfig.c | 43 +++++++++++++++++++++++++
tests/xml/gconfig-domain-device-pci-hostdev.xml | 11 +++++++
2 files changed, 54 insertions(+)
create mode 100644 tests/xml/gconfig-domain-device-pci-hostdev.xml
diff --git a/tests/test-gconfig.c b/tests/test-gconfig.c
index be55ef9..a26bb5f 100644
--- a/tests/test-gconfig.c
+++ b/tests/test-gconfig.c
@@ -709,6 +709,47 @@ static void test_domain_device_usb_redir(void)
g_object_unref(G_OBJECT(domain));
}
+static void test_domain_device_pci_hostdev(void)
+{
+ GVirConfigDomain *domain;
+ GVirConfigDomainAddressPci *address;
+ GVirConfigDomainHostdevPci *hostdev;
+
+ domain = gvir_config_domain_new();
+
+ hostdev = gvir_config_domain_hostdev_pci_new();
+ gvir_config_domain_hostdev_set_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev), 1);
+ g_assert_cmpint(gvir_config_domain_hostdev_get_boot_order(GVIR_CONFIG_DOMAIN_HOSTDEV(hostdev)), ==, 1);
+ gvir_config_domain_hostdev_pci_set_managed(hostdev, TRUE);
+ g_assert(gvir_config_domain_hostdev_pci_get_managed(hostdev) == TRUE);
+ gvir_config_domain_hostdev_pci_set_rom_bar(hostdev, TRUE);
+ gvir_config_domain_hostdev_pci_set_rom_file(hostdev, "/etc/fake/boot.bin");
+ g_assert_cmpstr(gvir_config_domain_hostdev_pci_get_rom_file(hostdev), ==, "/etc/fake/boot.bin");
+ g_assert(gvir_config_domain_hostdev_pci_get_rom_bar(hostdev));
+
+ address = gvir_config_domain_address_pci_new();
+ gvir_config_domain_address_pci_set_domain(address, 1);
+ gvir_config_domain_address_pci_set_bus(address, 2);
+ gvir_config_domain_address_pci_set_slot(address, 3);
+ gvir_config_domain_address_pci_set_function(address, 4);
+ gvir_config_domain_hostdev_pci_set_address(hostdev, address);
+ g_object_unref(G_OBJECT(address));
+
+ address = gvir_config_domain_hostdev_pci_get_address(hostdev);
+ g_assert(address != NULL);
+ g_assert_cmpint(gvir_config_domain_address_pci_get_domain(address), ==, 1);
+ g_assert_cmpint(gvir_config_domain_address_pci_get_bus(address), ==, 2);
+ g_assert_cmpint(gvir_config_domain_address_pci_get_slot(address), ==, 3);
+ g_assert_cmpint(gvir_config_domain_address_pci_get_function(address), ==, 4);
+ g_object_unref(G_OBJECT(address));
+
+ gvir_config_domain_add_device(domain, GVIR_CONFIG_DOMAIN_DEVICE (hostdev));
+ g_object_unref(G_OBJECT(hostdev));
+
+ check_xml(domain, "gconfig-domain-device-pci-hostdev.xml");
+
+ g_object_unref(G_OBJECT(domain));
+}
int main(int argc, char **argv)
{
@@ -739,6 +780,8 @@ int main(int argc, char **argv)
test_domain_device_channel);
g_test_add_func("/libvirt-gconfig/domain-device-usb-redir",
test_domain_device_usb_redir);
+ g_test_add_func("/libvirt-gconfig/domain-device-pci-hostdev",
+ test_domain_device_pci_hostdev);
return g_test_run();
}
diff --git a/tests/xml/gconfig-domain-device-pci-hostdev.xml b/tests/xml/gconfig-domain-device-pci-hostdev.xml
new file mode 100644
index 0000000..70e32ac
--- /dev/null
+++ b/tests/xml/gconfig-domain-device-pci-hostdev.xml
@@ -0,0 +1,11 @@
+<domain>
+ <devices>
+ <hostdev mode="subsystem" type="pci" managed="yes">
+ <boot order="1"/>
+ <rom bar="on" file="/etc/fake/boot.bin"/>
+ <source>
+ <address domain="0x0001" bus="0x02" slot="0x03" function="0x4"/>
+ </source>
+ </hostdev>
+ </devices>
+</domain>
--
2.7.4
8 years, 5 months
[libvirt] [libvirt-glib v8 3/5] gconfig: Add GVirConfigDomainHostdevPci
by Zeeshan Ali (Khattak)
Add API to read and write PCI hostdev nodes.
---
libvirt-gconfig/Makefile.am | 2 +
.../libvirt-gconfig-domain-hostdev-pci.c | 222 +++++++++++++++++++++
.../libvirt-gconfig-domain-hostdev-pci.h | 81 ++++++++
libvirt-gconfig/libvirt-gconfig-domain-hostdev.c | 2 +-
libvirt-gconfig/libvirt-gconfig.h | 1 +
libvirt-gconfig/libvirt-gconfig.sym | 11 +
6 files changed, 318 insertions(+), 1 deletion(-)
create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c
create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h
diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am
index a7c6c4e..0400343 100644
--- a/libvirt-gconfig/Makefile.am
+++ b/libvirt-gconfig/Makefile.am
@@ -51,6 +51,7 @@ GCONFIG_HEADER_FILES = \
libvirt-gconfig-domain-graphics-spice.h \
libvirt-gconfig-domain-graphics-vnc.h \
libvirt-gconfig-domain-hostdev.h \
+ libvirt-gconfig-domain-hostdev-pci.h \
libvirt-gconfig-domain-input.h \
libvirt-gconfig-domain-interface.h \
libvirt-gconfig-domain-interface-bridge.h \
@@ -143,6 +144,7 @@ GCONFIG_SOURCE_FILES = \
libvirt-gconfig-domain-graphics-spice.c \
libvirt-gconfig-domain-graphics-vnc.c \
libvirt-gconfig-domain-hostdev.c \
+ libvirt-gconfig-domain-hostdev-pci.c \
libvirt-gconfig-domain-input.c \
libvirt-gconfig-domain-interface.c \
libvirt-gconfig-domain-interface-bridge.c \
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c
new file mode 100644
index 0000000..c789c9c
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.c
@@ -0,0 +1,222 @@
+/*
+ * libvirt-gconfig-domain-hostdev.c: libvirt domain hostdev configuration
+ *
+ * Copyright (C) 2016 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/>.
+ *
+ * Authors: Zeeshan Ali (Khattak) <zeeshanak(a)gnome.org>
+ * Christophe Fergeau <cfergeau(a)redhat.com>
+ */
+
+#include <config.h>
+
+#include "libvirt-gconfig/libvirt-gconfig.h"
+#include "libvirt-gconfig/libvirt-gconfig-private.h"
+
+#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPciPrivate))
+
+struct _GVirConfigDomainHostdevPciPrivate
+{
+ gboolean unused;
+};
+
+G_DEFINE_TYPE(GVirConfigDomainHostdevPci, gvir_config_domain_hostdev_pci, GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV);
+
+static void gvir_config_domain_hostdev_pci_class_init(GVirConfigDomainHostdevPciClass *klass)
+{
+ g_type_class_add_private(klass, sizeof(GVirConfigDomainHostdevPciPrivate));
+}
+
+
+static void gvir_config_domain_hostdev_pci_init(GVirConfigDomainHostdevPci *hostdev)
+{
+ hostdev->priv = GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_PRIVATE(hostdev);
+}
+
+/**
+ * gvir_config_domain_hostdev_pci_new:
+ *
+ * Creates a new #GVirConfigDomainHostdevPci.
+ *
+ * Returns: (transfer full): a new #GVirConfigDomainHostdevPci. The returned
+ * object should be unreffed with g_object_unref() when no longer needed.
+ */
+GVirConfigDomainHostdevPci *gvir_config_domain_hostdev_pci_new(void)
+{
+ GVirConfigObject *object;
+
+ object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI,
+ "hostdev", NULL);
+ gvir_config_object_set_attribute(object, "mode", "subsystem", NULL);
+ gvir_config_object_set_attribute(object, "type", "pci", NULL);
+
+ return GVIR_CONFIG_DOMAIN_HOSTDEV_PCI(object);
+}
+
+/**
+ * gvir_config_domain_hostdev_pci_new_from_xml:
+ * @xml: xml data to create the host device from
+ * @error: return location for a #GError, or NULL
+ *
+ * Creates a new #GVirConfigDomainHostdevPci. The host device object will be
+ * created using the XML description stored in @xml. This is a fragment of
+ * libvirt domain XML whose root node is <hostdev>.
+ *
+ * Returns: (transfer full): a new #GVirConfigDomainHostdevPci, or NULL if @xml
+ * failed to be parsed. The returned object should be unreffed with
+ * g_object_unref() when no longer needed.
+ */
+GVirConfigDomainHostdevPci *gvir_config_domain_hostdev_pci_new_from_xml(const gchar *xml,
+ GError **error)
+{
+ GVirConfigObject *object;
+
+ object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI,
+ "hostdev", NULL, xml, error);
+ if (object == NULL)
+ return NULL;
+
+ if (g_strcmp0(gvir_config_object_get_attribute(object, NULL, "type"), "pci") != 0) {
+ g_object_unref(G_OBJECT(object));
+ g_return_val_if_reached(NULL);
+ }
+
+ return GVIR_CONFIG_DOMAIN_HOSTDEV_PCI(object);
+}
+
+void gvir_config_domain_hostdev_pci_set_address(GVirConfigDomainHostdevPci *hostdev,
+ GVirConfigDomainAddressPci *address)
+{
+ GVirConfigObject *source;
+ xmlNodePtr node;
+ xmlAttrPtr attr;
+
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(hostdev));
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address));
+ node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(address));
+ g_return_if_fail(node != NULL);
+
+ source = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(hostdev),
+ "source");
+ /* Because of https://bugzilla.redhat.com/show_bug.cgi?id=1327577, we can't
+ * just use GVirConfigDomainAddressPci's node, as is, since it contains
+ * a 'type' attribute, which is not accepted by libvirt. So we create a
+ * copy for our use and just delete the 'type' attribute from it.
+ */
+ node = xmlCopyNode(node, 1);
+ for (attr = node->properties; attr; attr = attr->next) {
+ if (g_strcmp0 ("type", (char *)attr->name) == 0) {
+ xmlRemoveProp (attr);
+ break;
+ }
+ }
+ gvir_config_object_set_child(source, node);
+ g_object_unref(source);
+}
+
+/**
+ * gvir_config_domain_hostdev_pci_get_address:
+ * @hostdev: A #GVirConfigDomainHostdevPci object.
+ *
+ * Gets the address associated with @hostdev.
+ *
+ * Returns: (transfer full): a new #GVirConfigDomainAddressPci, or NULL if no
+ * address is associated with @hostdev. The returned object should be unreffed
+ * with g_object_unref() when no longer needed.
+ */
+GVirConfigDomainAddressPci *gvir_config_domain_hostdev_pci_get_address(GVirConfigDomainHostdevPci *hostdev)
+{
+ GVirConfigObject *source;
+ GVirConfigObject* address;
+
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(hostdev), NULL);
+
+ source = gvir_config_object_get_child(GVIR_CONFIG_OBJECT(hostdev), "source");
+ if (source == NULL)
+ return NULL;
+
+ address = gvir_config_object_get_child_with_type(source,
+ "address",
+ GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI);
+ g_object_unref(source);
+ return GVIR_CONFIG_DOMAIN_ADDRESS_PCI(address);
+}
+
+void gvir_config_domain_hostdev_pci_set_managed(GVirConfigDomainHostdevPci *hostdev,
+ gboolean managed)
+{
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(hostdev));
+
+ gvir_config_object_set_attribute_with_type(GVIR_CONFIG_OBJECT(hostdev),
+ "managed",
+ G_TYPE_BOOLEAN,
+ managed,
+ NULL);
+}
+
+gboolean gvir_config_domain_hostdev_pci_get_managed(GVirConfigDomainHostdevPci *hostdev)
+{
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(hostdev), FALSE);
+
+ return gvir_config_object_get_attribute_boolean(GVIR_CONFIG_OBJECT(hostdev),
+ NULL,
+ "managed",
+ FALSE);
+}
+
+void gvir_config_domain_hostdev_pci_set_rom_file(GVirConfigDomainHostdevPci *hostdev,
+ const gchar *file)
+{
+ GVirConfigObject *rom;
+
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(hostdev));
+
+ rom = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(hostdev), "rom");
+ gvir_config_object_set_attribute(rom,
+ "file", file,
+ NULL);
+ g_object_unref(rom);
+}
+
+void gvir_config_domain_hostdev_pci_set_rom_bar(GVirConfigDomainHostdevPci *hostdev,
+ gboolean bar)
+{
+ GVirConfigObject *rom;
+
+ g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(hostdev));
+
+ rom = gvir_config_object_add_child(GVIR_CONFIG_OBJECT(hostdev), "rom");
+ gvir_config_object_set_attribute(rom,
+ "bar", bar? "on" : "off",
+ NULL);
+ g_object_unref(rom);
+}
+
+const gchar *gvir_config_domain_hostdev_pci_get_rom_file(GVirConfigDomainHostdevPci *hostdev)
+{
+ return gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(hostdev), "rom", "file");
+}
+
+gboolean gvir_config_domain_hostdev_pci_get_rom_bar(GVirConfigDomainHostdevPci *hostdev)
+{
+ const gchar *bar_str;
+
+ g_return_val_if_fail(GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(hostdev), FALSE);
+
+ bar_str = gvir_config_object_get_attribute(GVIR_CONFIG_OBJECT(hostdev), "rom", "bar");
+ return (g_strcmp0(bar_str, "on") == 0);
+}
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h
new file mode 100644
index 0000000..51378aa
--- /dev/null
+++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h
@@ -0,0 +1,81 @@
+/*
+ * libvirt-gconfig-domain-hostdev.h: libvirt domain hostdev configuration
+ *
+ * Copyright (C) 2016 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/>.
+ *
+ * Authors: Zeeshan Ali (Khattak) <zeeshanak(a)gnome.org>
+ * Christophe Fergeau <cfergeau(a)redhat.com>
+ */
+
+#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD)
+#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly."
+#endif
+
+#ifndef __LIBVIRT_GCONFIG_DOMAIN_HOSTDEV_PCI_H__
+#define __LIBVIRT_GCONFIG_DOMAIN_HOSTDEV_PCI_H__
+
+G_BEGIN_DECLS
+
+#define GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI (gvir_config_domain_hostdev_pci_get_type ())
+#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPci))
+#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPciClass))
+#define GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI))
+#define GVIR_CONFIG_IS_DOMAIN_HOSTDEV_PCI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI))
+#define GVIR_CONFIG_DOMAIN_HOSTDEV_PCI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI, GVirConfigDomainHostdevPciClass))
+
+typedef struct _GVirConfigDomainHostdevPci GVirConfigDomainHostdevPci;
+typedef struct _GVirConfigDomainHostdevPciPrivate GVirConfigDomainHostdevPciPrivate;
+typedef struct _GVirConfigDomainHostdevPciClass GVirConfigDomainHostdevPciClass;
+
+struct _GVirConfigDomainHostdevPci
+{
+ GVirConfigDomainHostdev parent;
+
+ GVirConfigDomainHostdevPciPrivate *priv;
+
+ /* Do not add fields to this struct */
+};
+
+struct _GVirConfigDomainHostdevPciClass
+{
+ GVirConfigDomainHostdevClass parent_class;
+
+ gpointer padding[20];
+};
+
+GType gvir_config_domain_hostdev_pci_get_type(void);
+
+GVirConfigDomainHostdevPci *gvir_config_domain_hostdev_pci_new(void);
+GVirConfigDomainHostdevPci *gvir_config_domain_hostdev_pci_new_from_xml(const gchar *xml,
+ GError **error);
+void gvir_config_domain_hostdev_pci_set_address(GVirConfigDomainHostdevPci *hostdev,
+ GVirConfigDomainAddressPci *address);
+GVirConfigDomainAddressPci *gvir_config_domain_hostdev_pci_get_address(GVirConfigDomainHostdevPci *hostdev);
+
+void gvir_config_domain_hostdev_pci_set_managed(GVirConfigDomainHostdevPci *hostdev,
+ gboolean managed);
+gboolean gvir_config_domain_hostdev_pci_get_managed(GVirConfigDomainHostdevPci *hostdev);
+void gvir_config_domain_hostdev_pci_set_rom_file(GVirConfigDomainHostdevPci *hostdev,
+ const gchar *file);
+const gchar *gvir_config_domain_hostdev_pci_get_rom_file(GVirConfigDomainHostdevPci *hostdev);
+void gvir_config_domain_hostdev_pci_set_rom_bar(GVirConfigDomainHostdevPci *hostdev,
+ gboolean bar);
+gboolean gvir_config_domain_hostdev_pci_get_rom_bar(GVirConfigDomainHostdevPci *hostdev);
+
+G_END_DECLS
+
+#endif /* __LIBVIRT_GCONFIG_DOMAIN_HOSTDEV_PCI_H__ */
diff --git a/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c
index ce5f8aa..459674d 100644
--- a/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c
+++ b/libvirt-gconfig/libvirt-gconfig-domain-hostdev.c
@@ -62,7 +62,7 @@ gvir_config_domain_hostdev_new_from_tree(GVirConfigXmlDoc *doc,
if (g_str_equal(type, "usb")) {
goto unimplemented;
} else if (g_str_equal(type, "pci")) {
- goto unimplemented;
+ gtype = GVIR_CONFIG_TYPE_DOMAIN_HOSTDEV_PCI;
} else if (g_str_equal(type, "scsi")) {
goto unimplemented;
} else {
diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h
index cfa9dd3..6462154 100644
--- a/libvirt-gconfig/libvirt-gconfig.h
+++ b/libvirt-gconfig/libvirt-gconfig.h
@@ -68,6 +68,7 @@
#include <libvirt-gconfig/libvirt-gconfig-domain-graphics-spice.h>
#include <libvirt-gconfig/libvirt-gconfig-domain-graphics-vnc.h>
#include <libvirt-gconfig/libvirt-gconfig-domain-hostdev.h>
+#include <libvirt-gconfig/libvirt-gconfig-domain-hostdev-pci.h>
#include <libvirt-gconfig/libvirt-gconfig-domain-input.h>
#include <libvirt-gconfig/libvirt-gconfig-domain-interface.h>
#include <libvirt-gconfig/libvirt-gconfig-domain-interface-bridge.h>
diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym
index 3607554..4d080b9 100644
--- a/libvirt-gconfig/libvirt-gconfig.sym
+++ b/libvirt-gconfig/libvirt-gconfig.sym
@@ -741,6 +741,17 @@ global:
gvir_config_domain_hostdev_get_readonly;
gvir_config_domain_hostdev_get_shareable;
gvir_config_domain_hostdev_get_type;
+ gvir_config_domain_hostdev_pci_get_address;
+ gvir_config_domain_hostdev_pci_get_managed;
+ gvir_config_domain_hostdev_pci_get_rom_bar;
+ gvir_config_domain_hostdev_pci_get_rom_file;
+ gvir_config_domain_hostdev_pci_get_type;
+ gvir_config_domain_hostdev_pci_new;
+ gvir_config_domain_hostdev_pci_new_from_xml;
+ gvir_config_domain_hostdev_pci_set_address;
+ gvir_config_domain_hostdev_pci_set_managed;
+ gvir_config_domain_hostdev_pci_set_rom_bar;
+ gvir_config_domain_hostdev_pci_set_rom_file;
gvir_config_domain_hostdev_set_boot_order;
gvir_config_domain_hostdev_set_readonly;
gvir_config_domain_hostdev_set_shareable;
--
2.7.4
8 years, 5 months
[libvirt] [PATCH] qemu_monitor: search memballoon QOM device path using alias
by Pavel Hrdina
Commit 4a585a88 introduced searching QOM device path by alias, let's use it for
memballoon too. This may speedup the search because in most cases we will find
the correct QOM device path directly by using alias without the need for the
recursion code.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/qemu/qemu_driver.c | 5 +++--
src/qemu/qemu_monitor.c | 29 ++++++++++++++++++-----------
src/qemu/qemu_monitor.h | 2 ++
src/qemu/qemu_process.c | 10 ++++------
4 files changed, 27 insertions(+), 19 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d5ba3b8..0501003 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2455,7 +2455,7 @@ static int qemuDomainSetMemoryStatsPeriod(virDomainPtr dom, int period,
}
qemuDomainObjEnterMonitor(driver, vm);
- r = qemuMonitorSetMemoryStatsPeriod(priv->mon, period);
+ r = qemuMonitorSetMemoryStatsPeriod(priv->mon, def->memballoon, period);
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto endjob;
if (r < 0) {
@@ -11003,7 +11003,8 @@ qemuDomainMemoryStats(virDomainPtr dom,
if (vm->def->memballoon &&
vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO) {
qemuDomainObjEnterMonitor(driver, vm);
- ret = qemuMonitorGetMemoryStats(qemuDomainGetMonitor(vm), stats, nr_stats);
+ ret = qemuMonitorGetMemoryStats(qemuDomainGetMonitor(vm),
+ vm->def->memballoon, stats, nr_stats);
if (qemuDomainObjExitMonitor(driver, vm) < 0)
ret = -1;
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 1fac4de..58c04d5 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1068,11 +1068,12 @@ qemuMonitorSetOptions(qemuMonitorPtr mon, virJSONValuePtr options)
* This feature was added to QEMU 1.5.
*/
static void
-qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon)
+qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon,
+ virDomainMemballoonDefPtr balloon)
{
ssize_t i, nprops = 0;
- int flp_ret = 0;
char *path = NULL;
+ const char *name;
qemuMonitorJSONListPathPtr *bprops = NULL;
if (mon->balloonpath) {
@@ -1084,16 +1085,20 @@ qemuMonitorInitBalloonObjectPath(qemuMonitorPtr mon)
}
mon->ballooninit = true;
- flp_ret = qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-pci", NULL, &path);
- if (flp_ret == -2) {
- /* pci object was not found retry search for ccw object */
- if (qemuMonitorJSONFindLinkPath(mon, "virtio-balloon-ccw",
- NULL, &path) < 0)
- return;
- } else if (flp_ret < 0) {
+ switch (balloon->info.type) {
+ case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI:
+ name = "virtio-balloon-pci";
+ break;
+ case VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW:
+ name = "virtio-balloon-ccw";
+ break;
+ default:
return;
}
+ if (qemuMonitorJSONFindLinkPath(mon, name, balloon->info.alias, &path) < 0)
+ return;
+
nprops = qemuMonitorJSONGetObjectListPaths(mon, path, &bprops);
if (nprops < 0)
goto cleanup;
@@ -1718,6 +1723,7 @@ qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
int
qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
+ virDomainMemballoonDefPtr balloon,
virDomainMemoryStatPtr stats,
unsigned int nr_stats)
{
@@ -1726,7 +1732,7 @@ qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
QEMU_CHECK_MONITOR(mon);
if (mon->json) {
- qemuMonitorInitBalloonObjectPath(mon);
+ qemuMonitorInitBalloonObjectPath(mon, balloon);
return qemuMonitorJSONGetMemoryStats(mon, mon->balloonpath,
stats, nr_stats);
} else {
@@ -1744,6 +1750,7 @@ qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
*/
int
qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
+ virDomainMemballoonDefPtr balloon,
int period)
{
int ret = -1;
@@ -1758,7 +1765,7 @@ qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
if (period < 0)
return -1;
- qemuMonitorInitBalloonObjectPath(mon);
+ qemuMonitorInitBalloonObjectPath(mon, balloon);
if (mon->balloonpath) {
ret = qemuMonitorJSONSetMemoryStatsPeriod(mon, mon->balloonpath,
period);
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index cb4cca8..ae0954d 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -397,9 +397,11 @@ int qemuMonitorGetVirtType(qemuMonitorPtr mon,
int qemuMonitorGetBalloonInfo(qemuMonitorPtr mon,
unsigned long long *currmem);
int qemuMonitorGetMemoryStats(qemuMonitorPtr mon,
+ virDomainMemballoonDefPtr balloon,
virDomainMemoryStatPtr stats,
unsigned int nr_stats);
int qemuMonitorSetMemoryStatsPeriod(qemuMonitorPtr mon,
+ virDomainMemballoonDefPtr balloon,
int period);
int qemuMonitorBlockIOStatusToError(const char *status);
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 4adb14e..c7639c1 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4268,19 +4268,17 @@ qemuProcessSetupBalloon(virQEMUDriverPtr driver,
{
unsigned long long balloon = vm->def->mem.cur_balloon;
qemuDomainObjPrivatePtr priv = vm->privateData;
- int period;
int ret = -1;
if (!virDomainDefHasMemballoon(vm->def))
return 0;
- period = vm->def->memballoon->period;
-
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
goto cleanup;
- if (period)
- qemuMonitorSetMemoryStatsPeriod(priv->mon, period);
+ if (vm->def->memballoon->period)
+ qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon,
+ vm->def->memballoon->period);
if (qemuMonitorSetBalloon(priv->mon, balloon) < 0)
goto cleanup;
@@ -6022,7 +6020,7 @@ int qemuProcessAttach(virConnectPtr conn ATTRIBUTE_UNUSED,
vm->def->memballoon->model == VIR_DOMAIN_MEMBALLOON_MODEL_VIRTIO &&
vm->def->memballoon->period) {
qemuDomainObjEnterMonitor(driver, vm);
- qemuMonitorSetMemoryStatsPeriod(priv->mon,
+ qemuMonitorSetMemoryStatsPeriod(priv->mon, vm->def->memballoon,
vm->def->memballoon->period);
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto error;
--
2.9.2
8 years, 5 months