[libvirt] [RFC] API vs XML
by Stefan de Konink
Hi,
In my previous email Daniel made clear that for many functions it is
preferable to have access to the XML output. I would like to know what the
general opinion is about defining a domain.
I can understand that people don't mind to define a domain manually or
with tools and pump it inside libvirt with the virDomainDefineXML call.
But why are the XML tree manipulating features not incorporated into the
API? Slightly more 'semantics based' than Attach/Detach Device. Allowing
to specify the information that is going into the XML.
So for example:
domainptr = virDomainDefine(name)
virDomainSetName(domainptr, name)
virDomainSetBootloader(domainptr, path)
virDomainSetOS(domainptr, type)
virDomainSetMemory(domainptr, amount, live)
virDomainSetVCPU(domainptr, amount, live)
virDomainAttachDisk(domainptr, type, sourceptr, targetptr, live)
virDomainDetachDevice(domainptr, deviceptr, live)
I know there are people that love XML here, but can someone give a
reasonable statement why not to support the above? (More clean, less
parsing)
Stefan
16 years, 5 months
[libvirt] PATCH: Pass -name argument to QEMU
by Daniel P. Berrange
This patch makes libvirt pass the -name argumet to QEMU it if it supported
by the QEMU binary in question. THis allows QEMU to set the VNC title and
allows Xenner to set the Xen guest name in xenstore.
src/qemu_conf.c | 19 ++++++++++++++-----
src/qemu_conf.h | 5 +++--
tests/qemuxml2argvdata/qemuxml2argv-minimal.args | 2 +-
tests/qemuxml2argvtest.c | 23 +++++++++++------------
4 files changed, 29 insertions(+), 20 deletions(-)
Dan.
diff -r aab96c0c6974 src/qemu_conf.c
--- a/src/qemu_conf.c Fri May 09 19:24:37 2008 -0400
+++ b/src/qemu_conf.c Fri May 09 19:30:26 2008 -0400
@@ -492,10 +492,12 @@
*flags |= QEMUD_CMD_FLAG_KQEMU;
if (strstr(help, "-no-reboot"))
*flags |= QEMUD_CMD_FLAG_NO_REBOOT;
- if (strstr(help, "\n-drive"))
- *flags |= QEMUD_CMD_FLAG_DRIVE_OPT;
+ if (strstr(help, "-name"))
+ *flags |= QEMUD_CMD_FLAG_NAME;
+ if (strstr(help, "-drive"))
+ *flags |= QEMUD_CMD_FLAG_DRIVE;
if (strstr(help, "boot=on"))
- *flags |= QEMUD_CMD_FLAG_DRIVE_BOOT_OPT;
+ *flags |= QEMUD_CMD_FLAG_DRIVE_BOOT;
if (*version >= 9000)
*flags |= QEMUD_CMD_FLAG_VNC_COLON;
ret = 0;
@@ -2348,6 +2350,7 @@
len = 1 + /* qemu */
2 + /* machine type */
disableKQEMU + /* Disable kqemu */
+ (vm->qemuCmdFlags & QEMUD_CMD_FLAG_NAME ? 2 : 0) + /* -name XXX */
2 * vm->def->ndisks + /* disks*/
(vm->def->nnets > 0 ? (4 * vm->def->nnets) : 2) + /* networks */
1 + /* usb */
@@ -2394,6 +2397,12 @@
if (!((*argv)[++n] = strdup(vcpus)))
goto no_memory;
+ if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_NAME) {
+ if (!((*argv)[++n] = strdup("-name")))
+ goto no_memory;
+ if (!((*argv)[++n] = strdup(vm->def->name)))
+ goto no_memory;
+ }
/*
* NB, -nographic *MUST* come before any serial, or monitor
* or parallel port flags due to QEMU craziness, where it
@@ -2472,11 +2481,11 @@
}
/* If QEMU supports -drive param instead of old -hda, -hdb, -cdrom .. */
- if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_DRIVE_OPT) {
+ if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_DRIVE) {
int bootCD = 0, bootFloppy = 0, bootDisk = 0;
/* If QEMU supports boot=on for -drive param... */
- if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_DRIVE_BOOT_OPT) {
+ if (vm->qemuCmdFlags & QEMUD_CMD_FLAG_DRIVE_BOOT) {
for (i = 0 ; i < vm->def->os.nBootDevs ; i++) {
switch (vm->def->os.bootDevs[i]) {
case QEMUD_BOOT_CDROM:
diff -r aab96c0c6974 src/qemu_conf.h
--- a/src/qemu_conf.h Fri May 09 19:24:37 2008 -0400
+++ b/src/qemu_conf.h Fri May 09 19:30:26 2008 -0400
@@ -249,8 +249,9 @@
QEMUD_CMD_FLAG_KQEMU = (1 << 0),
QEMUD_CMD_FLAG_VNC_COLON = (1 << 1),
QEMUD_CMD_FLAG_NO_REBOOT = (1 << 2),
- QEMUD_CMD_FLAG_DRIVE_OPT = (1 << 3),
- QEMUD_CMD_FLAG_DRIVE_BOOT_OPT = (1 << 4),
+ QEMUD_CMD_FLAG_DRIVE = (1 << 3),
+ QEMUD_CMD_FLAG_DRIVE_BOOT = (1 << 4),
+ QEMUD_CMD_FLAG_NAME = (1 << 5),
};
diff -r aab96c0c6974 tests/qemuxml2argvdata/qemuxml2argv-minimal.args
--- a/tests/qemuxml2argvdata/qemuxml2argv-minimal.args Fri May 09 19:24:37 2008 -0400
+++ b/tests/qemuxml2argvdata/qemuxml2argv-minimal.args Fri May 09 19:30:26 2008 -0400
@@ -1,1 +1,1 @@
-/usr/bin/qemu -M pc -m 214 -smp 1 -nographic -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb
\ No newline at end of file
+/usr/bin/qemu -M pc -m 214 -smp 1 -name QEMUGuest1 -nographic -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial none -parallel none -usb
\ No newline at end of file
diff -r aab96c0c6974 tests/qemuxml2argvtest.c
--- a/tests/qemuxml2argvtest.c Fri May 09 19:24:37 2008 -0400
+++ b/tests/qemuxml2argvtest.c Fri May 09 19:30:26 2008 -0400
@@ -20,7 +20,7 @@
#define MAX_FILE 4096
-static int testCompareXMLToArgvFiles(const char *xml, const char *cmd, int driveFlag) {
+static int testCompareXMLToArgvFiles(const char *xml, const char *cmd, int extraFlags) {
char xmlData[MAX_FILE];
char argvData[MAX_FILE];
char *xmlPtr = &(xmlData[0]);
@@ -47,10 +47,7 @@
vm.qemuVersion = 0 * 1000 * 100 + (8 * 1000) + 1;
vm.qemuCmdFlags = QEMUD_CMD_FLAG_VNC_COLON |
QEMUD_CMD_FLAG_NO_REBOOT;
- if (driveFlag) {
- vm.qemuCmdFlags |= QEMUD_CMD_FLAG_DRIVE_OPT;
- vm.qemuCmdFlags |= QEMUD_CMD_FLAG_DRIVE_BOOT_OPT;
- }
+ vm.qemuCmdFlags |= extraFlags;
vm.migrateFrom[0] = '\0';
vmdef->vncActivePort = vmdef->vncPort;
@@ -100,7 +97,7 @@
struct testInfo {
const char *name;
- int driveFlag;
+ int extraFlags;
};
static int testCompareXMLToArgvHelper(const void *data) {
@@ -111,7 +108,7 @@
abs_srcdir, info->name);
snprintf(args, PATH_MAX, "%s/qemuxml2argvdata/qemuxml2argv-%s.args",
abs_srcdir, info->name);
- return testCompareXMLToArgvFiles(xml, args, info->driveFlag);
+ return testCompareXMLToArgvFiles(xml, args, info->extraFlags);
}
@@ -135,15 +132,15 @@
driver.caps = qemudCapsInit();
-#define DO_TEST(name, driveFlag) \
+#define DO_TEST(name, extraFlags) \
do { \
- struct testInfo info = { name, driveFlag }; \
+ struct testInfo info = { name, extraFlags }; \
if (virtTestRun("QEMU XML-2-ARGV " name, \
1, testCompareXMLToArgvHelper, &info) < 0) \
ret = -1; \
} while (0)
- DO_TEST("minimal", 0);
+ DO_TEST("minimal", QEMUD_CMD_FLAG_NAME);
DO_TEST("boot-cdrom", 0);
DO_TEST("boot-network", 0);
DO_TEST("boot-floppy", 0);
@@ -152,8 +149,10 @@
DO_TEST("disk-cdrom", 0);
DO_TEST("disk-floppy", 0);
DO_TEST("disk-many", 0);
- DO_TEST("disk-virtio", 1);
- DO_TEST("disk-xenvbd", 1);
+ DO_TEST("disk-virtio", QEMUD_CMD_FLAG_DRIVE |
+ QEMUD_CMD_FLAG_DRIVE_BOOT);
+ DO_TEST("disk-xenvbd", QEMUD_CMD_FLAG_DRIVE |
+ QEMUD_CMD_FLAG_DRIVE_BOOT);
DO_TEST("graphics-vnc", 0);
DO_TEST("graphics-sdl", 0);
DO_TEST("input-usbmouse", 0);
--
|: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
16 years, 5 months
[Libvir] How to get the memory used by a guest domin
by Pranay Prasoon
Hi,
It appears to be no API available to provide the memory used by a guest
domin.
I looked at the availble libvirt api called "virNodeGetCellsFreeMemory"
using which it is possible to get the free mem. But looking further I found
that this is free memory of the "whole box" rather than based upon the guest
domain.
How can I get the memory used by a guest domin.
Thanks n Regards,
-Pranay.
16 years, 5 months
[libvirt] [virt-manager] PATCH: Support nonstandard ssh-port for tunnels
by ClaesBas
If you have ssh moved/hidden somewhere else then port 22 this patch
makes it possible to open the vnc/console.
I have to add the entry from commandline like this:
virt-manager -c qemu+ssh://username@some_machine:22222/system
If ssh is running on port 22222.
I've also submitet this on bugzilla:
https://bugzilla.redhat.com/show_bug.cgi?id=447070
Regards
Claes
--- a/src/virtManager/details.py Tue May 13 15:59:25 2008 -0400
+++ b/src/virtManager/details.py Sun May 18 23:07:37 2008 +0200
@@ -975,7 +975,11 @@ class vmmDetails(gobject.GObject):
os.close(1)
os.dup(fds[1].fileno())
os.dup(fds[1].fileno())
- argv = ["ssh", "ssh", "-p", "22"]
+ if not server.count(":"):
+ sshport = 22
+ else:
+ (server, sshport) = server.split(":")
+ argv = ["ssh", "ssh", "-p", sshport]
if username:
argv += ['-l', username]
argv += [ server, "nc", vncaddr, str(vncport) ]
16 years, 5 months
[libvirt] PATCH: Use -help arg with QEMU probing
by Daniel P. Berrange
This patch makes the code that probes QEMU args explicitly add the -help
argument. This works around a problem with certain KVM builds which refuse
to run if executed without -help, and no KVM modules are present.
It also removes the set of setenv() since that changes libvirtd's environ
and instead uses execle() to set the child's environment
Dan
Index: src/qemu_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_conf.c,v
retrieving revision 1.64
diff -u -p -r1.64 qemu_conf.c
--- src/qemu_conf.c 15 May 2008 20:07:34 -0000 1.64
+++ src/qemu_conf.c 16 May 2008 14:34:42 -0000
@@ -447,6 +447,8 @@ static int qemudExtractVersionInfo(const
}
if (child == 0) { /* Kid */
+ const char *const qemuenv[] = { "LANG=C", NULL };
+
if (close(STDIN_FILENO) < 0)
goto cleanup1;
if (close(STDERR_FILENO) < 0)
@@ -457,8 +459,7 @@ static int qemudExtractVersionInfo(const
goto cleanup1;
/* Just in case QEMU is translated someday.. */
- setenv("LANG", "C", 1);
- execl(qemu, qemu, (char*)NULL);
+ execle(qemu, qemu, "-help", (char*)NULL, qemuenv);
cleanup1:
_exit(-1); /* Just in case */
--
|: Red Hat, Engineering, Boston -o- http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|
16 years, 5 months
[libvirt] [PATCH] plug two leaks
by Jim Meyering
Running "make check" under valgrind exposed at least
the first. Then, I spotted the other.
* src/qemu_conf.c (qemudParseXML): Free "obj" unconditionally.
---
src/qemu_conf.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index ff7c63e..47d49a2 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1716,11 +1716,11 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
(obj->stringval != NULL) && (obj->stringval[0] != 0)) {
strncpy(def->os.bootloader, (const char*)obj->stringval, sizeof(def->os.bootloader));
NUL_TERMINATE(def->os.bootloader);
- xmlXPathFreeObject(obj);
/* Set a default OS type, since <type> is optional with bootloader */
strcpy(def->os.type, "xen");
}
+ xmlXPathFreeObject(obj);
/* Extract OS type info */
obj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1])", ctxt);
@@ -1733,9 +1733,9 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
}
} else {
strcpy(def->os.type, (const char *)obj->stringval);
- xmlXPathFreeObject(obj);
- obj = NULL;
}
+ xmlXPathFreeObject(obj);
+ obj = NULL;
if (!virCapabilitiesSupportsGuestOSType(driver->caps, def->os.type)) {
qemudReportError(conn, NULL, NULL, VIR_ERR_OS_TYPE,
--
1.5.5.1.249.g26848
16 years, 5 months
[libvirt] how to pass qemu options?
by David Abrahams
I normally launch my kvm VM from the command line with "-redir tcp:3389:3389"
but have been unable to find a way to set up virt-manager to launch it the same
way. Ditto for other qemu options such as "-soundhw all". Is there a way?
TIA,
--
Dave Abrahams
BoostPro Computing
http://www.boostpro.com
16 years, 5 months
[libvirt] Question about more finer access control permission on libvirt
by Atsushi SAKAI
Hi, Dan
I have a question of libvirt with Polkit.
Currently, the libvirt w/ Polkit has 2 access control permissions.
(Read Only and Read Write)
Have you planned to expand the access control more finer?
In my use case, Policy should define by domain, operation, operator.
Of course, operator is already considered on current libvirt w/ Polkit.
So at this point, it needs to add domain and operation policy.
The use case is for many(about 100 or more) domain operation.
I just want to know
how to minimize granting access control permission of each user
on libvirt in future.
Any comment appreciated.
Thanks
Atsushi SAKAI
16 years, 5 months