[libvirt] Java bindings
by Alejandro Berna Juan
Hi all, I'm Alejandro Berna from i2CAT (a non-profit foundation in
Barcelona, Spain, www.i2cat.net). I'm collaborating in a Europena project
called Federica ( www.fp7-*federica*.eu ). One of the branch of this project
is to permit virtualization of different hosts in the Federica test-bed. We
are doing some studies about the different management interfaces of Xen. Our
objective is to create a software remote client for Xen tool (in java if
it's possible) that can do (general functionalities):
- Create virtual machines assigning virtual interfaces.
- Permit choose the OS assigned to this virtual machine
- Install new applications to be tested in the virtual machines
- Configure a vm to become a router and permit to configure this router as
it was a physical router.
All these actions have to be performed remotelly. I have not found too much
information about libvrt but I think that can be usefull for our achieves.
If you agree that with libvrt we can perform these actions, maybe I can
build the java bindings for libvrt inside the Federica work. I'm waiting for
your opinions, thank you,
--
Alejandro Berna Juan
alejandro.berna(a)i2cat.net
16 years, 2 months
[libvirt] [PATCH] xen: fix domain lookup after define
by Cole Robinson
Defining a xen domain will succeed, but report
error because we weren't properly passing the
domain's name to the post-define lookup.
Attached patch fixes this, and also adds a
debug statement to show the sexpr we create
from the passed xml.
Thanks,
Cole
diff --git a/src/xend_internal.c b/src/xend_internal.c
index 2a687c3..124ee8b 100644
--- a/src/xend_internal.c
+++ b/src/xend_internal.c
@@ -4270,7 +4270,6 @@ xenDaemonDomainMigratePerform (virDomainPtr domain,
virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
int ret;
char *sexpr;
- char *name = NULL;
virDomainPtr dom;
xenUnifiedPrivatePtr priv;
virDomainDefPtr def;
@@ -4292,15 +4291,17 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
goto error;
}
+ DEBUG("Defining w/ sexpr: \n%s", sexpr);
+
ret = xend_op(conn, "", "op", "new", "config", sexpr, NULL);
VIR_FREE(sexpr);
if (ret != 0) {
virXendError(conn, VIR_ERR_XEN_CALL,
- _("Failed to create inactive domain %s\n"), name);
+ _("Failed to create inactive domain %s\n"), def->name);
goto error;
}
- dom = virDomainLookupByName(conn, name);
+ dom = virDomainLookupByName(conn, def->name);
if (dom == NULL) {
goto error;
}
16 years, 2 months
[libvirt] [PATCH] [LXC] Add version implementation
by Dan Smith
This patch adds an implementation of the version function to the LXC driver.
The providers use the hypervisor version in a field of one of the instances,
so we need to have something meaningful here. AFAICT, the only real option
we have (considering the limitations of the libvirt version information) is
to use the kernel version.
diff -r be3be31c94a2 -r 0cabead40d65 src/lxc_driver.c
--- a/src/lxc_driver.c Fri Aug 29 07:11:15 2008 +0000
+++ b/src/lxc_driver.c Fri Aug 29 09:10:41 2008 -0700
@@ -1110,6 +1110,29 @@
return 0;
}
+static int lxcVersion(virConnectPtr conn, unsigned long *version)
+{
+ struct utsname ver;
+ int maj;
+ int min;
+ int rev;
+
+ if (uname(&ver) != 0) {
+ lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("uname(): %m"));
+ return -1;
+ }
+
+ if (sscanf(ver.release, "%i.%i.%i", &maj, &min, &rev) != 3) {
+ lxcError(conn, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("Unknown release: %s"), ver.release);
+ return -1;
+ }
+
+ *version = (maj * 1000 * 1000) + (min * 1000) + rev;
+
+ return 0;
+}
/* Function Tables */
static virDriver lxcDriver = {
@@ -1121,7 +1144,7 @@
lxcClose, /* close */
NULL, /* supports_feature */
NULL, /* type */
- NULL, /* version */
+ lxcVersion, /* version */
NULL, /* getHostname */
NULL, /* getURI */
NULL, /* getMaxVcpus */
16 years, 2 months
[libvirt] [PATCH] Fix ejecting cdroms with latest qemu syntax
by Cole Robinson
Originally, ejecting a cdrom from a qemu guest entailed
passing 'eject cdrom' to the monitor. But since qemu
added the -drive option, more than one cdrom can be
specified, so just using 'cdrom' isn't explicit enough.
The attached patch updates media change/eject to use
the current qemu syntax. The new generated commands
look something like "eject ide0-cd1", with the name
derived from device target and bus type.
While I was in there I added support for inserting/
ejecting media from scsi cdroms and floppy devices.
This is built around my previous two patches:
- Fix cd eject segfault
- Attempt to detect cdrom change failures
Thanks,
Cole
16 years, 2 months
[libvirt] [PATCH] virConnectListAllDomains (version 3, still no Xen)
by Richard W.M. Jones
This is a third version of the virConnectListAllDomains patch. The
API is now slightly different from previous proposals. We only allow
filtering on All/Active/Inactive, and not by a long list of
fine-grained states. The reason is twofold: (1) a simpler
implementation and (2) doubtful that anyone would actually use the
fine-grained filtering feature.
The new API is shown below.
I have tested this out with mlvirsh and virt-top and of course in the
remote case there is a substantial saving in terms of round-trip
times, although it's hard to precisely measure what the difference is
when I've got only a couple of guests running.
There is still no Xen-specific implementation, but note that in the
remote case you get some of the benefit anyway.
Rich.
----------------------------------------------------------------------
/**
* virConnectListAllDomains:
* @conn: pointer to the hypervisor connection
* @domains: pointer to returned array of domain pointers (must not be NULL)
* @infos: pointer to returned array of virDomainInfo structures (may be NULL)
* @stateflags: state of domains of interest
* @flags: other flags (always 0)
*
* This call returns the list of all domains, active or inactive,
* and their virDomainInfo structures.
*
* This call is usually more efficient than using the old method
* of calling virConnectListDomains and virConnectListDefinedDomains
* and then loading each domain and its info. This call is supported
* for all hypervisor types. (If the backend driver doesn't support it
* directly, then the call is emulated for you).
*
* @stateflags allows only the domains of interest to be
* returned. Callers must pass one of:
* VIR_DOMAIN_LIST_ACTIVE to return running domains,
* VIR_DOMAIN_LIST_INACTIVE to return defined but not running domains,
* VIR_DOMAIN_LIST_ALL to return all domains,
* 0 to return no domains.
*
* @flags may be used in the future. Always pass 0 for this parameter.
*
* If there is no error then @domains will be updated to point to an
* array of virDomainPtr.
*
* If there is no error and @infos is not NULL, then @infos will be
* updated to point to an array of virDomainInfo structures, with
* the same length as the array of domains.
*
* Returns the number of domains in the @domains array, or -1 in
* case of error.
*
* If there was no error then the caller must free each domain
* with virDomainFree, free the array of @domains pointers,
* and if necessary free the array of @infos structures.
*/
int
virConnectListAllDomains(virConnectPtr conn,
virDomainPtr **domains,
virDomainInfo **infos,
unsigned long stateflags,
unsigned long flags);
----------------------------------------------------------------------
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
Read my OCaml programming blog: http://camltastic.blogspot.com/
Fedora now supports 64 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
16 years, 2 months
[libvirt] [PATCH] Attempt to detect cdrom change failures
by Cole Robinson
If a 'change' or 'eject' qemu monitor command fails,
an error message is printed to the monitor of the
form "device {not found, is locked, is not
removable"}. This is really the only indication we
have that the command errored out, so scrape the
monitor reply for "\ndevice " and fail if it is
found.
Thanks,
Cole
commit 8caba367b62b4fb961722cd641d8172bb441b84e
Author: Cole Robinson <crobinso(a)dhcp-100-19-219.bos.redhat.com>
Date: Fri Aug 22 16:35:24 2008 -0400
Scrape cdrom attach/eject monitor output to try and determine failure.
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 9a26375..05e7402 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -2994,6 +2994,19 @@ static int qemudDomainChangeCDROM(virDomainPtr dom,
VIR_FREE(newsrc);
return -1;
}
+
+ /* If the command failed qemu prints:
+ * device not found, device is locked ...
+ * No message is printed on success it seems */
+ DEBUG ("cdrom change reply: %s", reply);
+ if (strstr(reply, "\ndevice ")) {
+ qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+ "%s", _("changing cdrom media failed));
+ VIR_FREE(reply);
+ VIR_FREE(cmd);
+ return -1;
+ }
+
VIR_FREE(reply);
VIR_FREE(cmd);
16 years, 2 months
[libvirt] [PATCH] Update domain xml after usb hotplug
by Cole Robinson
The recently added usb hostdev and mass storage device
hotplug code doesn't append the devices to the running
guests xml if the hotplug succeeds. The attached patch
fixes this.
Thanks,
Cole
commit 8df17db8b36a2c1e8efa430a0493f66825b6b80e
Author: Cole (Work Acct) <crobinso(a)localhost.localdomain>
Date: Thu Aug 21 23:08:04 2008 -0400
Add hotplugged usb devices to running domain xml.
diff --git a/src/domain_conf.c b/src/domain_conf.c
index 3c61039..dc5eb0c 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -481,8 +481,8 @@ void virDomainRemoveInactive(virDomainObjPtr *doms,
}
#ifndef PROXY
-static int virDomainDiskCompare(virDomainDiskDefPtr a,
- virDomainDiskDefPtr b) {
+int virDomainDiskCompare(virDomainDiskDefPtr a,
+ virDomainDiskDefPtr b) {
if (a->bus == b->bus)
return virDiskNameToIndex(a->dst) - virDiskNameToIndex(b->dst);
else
diff --git a/src/domain_conf.h b/src/domain_conf.h
index b98f7f3..cfa2a90 100644
--- a/src/domain_conf.h
+++ b/src/domain_conf.h
@@ -526,6 +526,8 @@ char *virDomainCpuSetFormat(virConnectPtr conn,
char *cpuset,
int maxcpu);
+int virDomainDiskCompare(virDomainDiskDefPtr a,
+ virDomainDiskDefPtr b);
int virDomainSaveConfig(virConnectPtr conn,
const char *configDir,
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 769f34f..9a26375 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -62,6 +62,7 @@
#include "capabilities.h"
#include "memory.h"
#include "uuid.h"
+#include "domain_conf.h"
/* For storing short-lived temporary files. */
#define TEMPDIR LOCAL_STATE_DIR "/cache/libvirt"
@@ -3044,6 +3045,7 @@ static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDevi
virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid);
int ret;
char *cmd, *reply;
+ virDomainDiskDefPtr *dest, *prev, ptr;
if (!vm) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
@@ -3051,6 +3053,28 @@ static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDevi
return -1;
}
+ /* Find spot in domain definition where we will put the disk */
+ ptr = vm->def->disks;
+ prev = &(vm->def->disks);
+ while (ptr) {
+ if (STREQ(dev->data.disk->dst, ptr->dst)) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_INTERNAL_ERROR,
+ _("duplicate disk target '%s'"),
+ dev->data.disk->dst);
+ return -1;
+ }
+ if (virDomainDiskCompare(dev->data.disk, ptr) < 0) {
+ dest = &(ptr);
+ break;
+ }
+ prev = &(ptr->next);
+ ptr = ptr->next;
+ }
+
+ if (!ptr) {
+ dest = prev;
+ }
+
ret = asprintf(&cmd, "usb_add disk:%s", dev->data.disk->src);
if (ret == -1) {
qemudReportError(dom->conn, NULL, NULL, VIR_ERR_NO_MEMORY, NULL);
@@ -3059,7 +3083,7 @@ static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDevi
if (qemudMonitorCommand(driver, vm, cmd, &reply) < 0) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
- "%s", _("cannot attach usb device"));
+ "%s", _("cannot attach usb disk"));
VIR_FREE(cmd);
return -1;
}
@@ -3070,11 +3094,16 @@ static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDevi
if (strstr(reply, "Could not add ")) {
qemudReportError (dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
"%s",
- _("adding usb device failed"));
+ _("adding usb disk failed"));
VIR_FREE(reply);
VIR_FREE(cmd);
return -1;
}
+
+ /* Actually update the xml */
+ dev->data.disk->next = *dest;
+ *prev = dev->data.disk;
+
VIR_FREE(reply);
VIR_FREE(cmd);
return 0;
@@ -3125,6 +3154,11 @@ static int qemudDomainAttachHostDevice(virDomainPtr dom, virDomainDeviceDefPtr d
VIR_FREE(cmd);
return -1;
}
+
+ /* Update xml */
+ dev->data.hostdev->next = vm->def->hostdevs;
+ vm->def->hostdevs = dev->data.hostdev;
+
VIR_FREE(reply);
VIR_FREE(cmd);
return 0;
@@ -3167,7 +3201,7 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
ret = qemudDomainAttachHostDevice(dom, dev);
} else {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
- "%s", _("this devicetype cannot be attached"));
+ "%s", _("this device type cannot be attached"));
ret = -1;
}
16 years, 2 months
[libvirt] [PATCH] Fix disk device ordering
by Cole Robinson
When parsing the domain xml, disks are supposed to be
rearranged in an alphabetic order based on bus type
and target. The reordering code had a flaw though, in
that it would always put the first disk it encountered
at the head of the list, and had no way of putting
new entries in front of it.
The attached patch reworks the code to compare the new
disk against the current disk entry (rather than the
next entry like the existing code). Seems to pass all
my tests.
Thanks,
Cole
commit ce3abbb62327672f756848efec7c95275fa797d6
Author: Cole (Work Acct) <crobinso(a)localhost.localdomain>
Date: Thu Aug 21 23:04:11 2008 -0400
Fix disk ordering when parsing domain xml.
diff --git a/src/domain_conf.c b/src/domain_conf.c
index ed6cc8b..3c61039 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@ -1949,25 +1949,27 @@ static virDomainDefPtr virDomainDefParseXML(virConnectPtr conn,
goto error;
/* Maintain list in sorted order according to target device name */
- if (def->disks == NULL) {
- disk->next = def->disks;
- def->disks = disk;
- } else {
- virDomainDiskDefPtr ptr = def->disks;
- while (ptr) {
- if (ptr->next && STREQ(disk->dst, ptr->next->dst)) {
- virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
- _("duplicate disk target '%s'"),
- disk->dst);
- goto error;
- }
- if (!ptr->next || virDomainDiskCompare(disk, ptr->next) < 0) {
- disk->next = ptr->next;
- ptr->next = disk;
- break;
- }
- ptr = ptr->next;
+ virDomainDiskDefPtr ptr = def->disks;
+ virDomainDiskDefPtr *prev = &(def->disks);
+ while (ptr) {
+ if (STREQ(disk->dst, ptr->dst)) {
+ virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR,
+ _("duplicate disk target '%s'"),
+ disk->dst);
+ goto error;
+ }
+ if (virDomainDiskCompare(disk, ptr) < 0) {
+ disk->next = ptr;
+ *prev = disk;
+ break;
}
+ prev = &(ptr->next);
+ ptr = ptr->next;
+ }
+
+ if (!ptr) {
+ disk->next = ptr;
+ *prev = disk;
}
}
VIR_FREE(nodes);
16 years, 2 months
[libvirt] [PATCH] Add success output to virsh attach/detach commands
by Cole Robinson
The virsh attach-* and detach-* commands don't say
anything if the operation succeeds, which doesn't
seem very polite. The attached adds some simple
feedback.
Thanks,
Cole
commit eda28c5de3d367d001ca89ffc969fcc3c0185abb
Author: Cole Robinson <crobinso(a)dhcp-100-19-219.bos.redhat.com>
Date: Thu Aug 21 17:59:13 2008 -0400
Report success message for virsh attach-* and detach-*
diff --git a/src/virsh.c b/src/virsh.c
index 67d9658..c22cdc4 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -4490,6 +4490,8 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, FALSE, _("Failed to attach device from %s"), from);
virDomainFree(dom);
return FALSE;
+ } else {
+ vshPrint(ctl, _("Device attached successfully\n"));
}
virDomainFree(dom);
@@ -4547,6 +4549,8 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, FALSE, _("Failed to detach device from %s"), from);
virDomainFree(dom);
return FALSE;
+ } else {
+ vshPrint(ctl, _("Device detached successfully\n"));
}
virDomainFree(dom);
@@ -4655,8 +4659,11 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
if (!buf) goto cleanup;
strcat(buf, " </interface>\n");
- if (virDomainAttachDevice(dom, buf))
+ if (virDomainAttachDevice(dom, buf)) {
goto cleanup;
+ } else {
+ vshPrint(ctl, _("Interface attached successfully\n"));
+ }
ret = TRUE;
@@ -4772,8 +4779,10 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
ret = virDomainDetachDevice(dom, (char *)xmlBufferContent(xml_buf));
if (ret != 0)
ret = FALSE;
- else
+ else {
+ vshPrint(ctl, _("Interface detached successfully\n"));
ret = TRUE;
+ }
cleanup:
if (dom)
@@ -4939,6 +4948,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
if (virDomainAttachDevice(dom, buf))
goto cleanup;
+ else
+ vshPrint(ctl, _("Disk attached successfully\n"));
ret = TRUE;
@@ -5046,8 +5057,10 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
ret = virDomainDetachDevice(dom, (char *)xmlBufferContent(xml_buf));
if (ret != 0)
ret = FALSE;
- else
+ else {
+ vshPrint(ctl, _("Disk detached successfully\n"));
ret = TRUE;
+ }
cleanup:
xmlXPathFreeObject(obj);
16 years, 2 months