[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/…
[View More]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;
}
[View Less]
16 years, 7 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 …
[View More]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);
[View Less]
16 years, 7 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
…
[View More]@@ -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);
[View Less]
16 years, 7 months
[libvirt] [PATCH] introducing <source> <name> (for logical storage pools)
by David Lively
Hi Folks -
This small patch is a proposed prerequisite for the storage pool
discovery patch I submitted last week.
Daniel B proposed having storage pool discovery return a bunch of XML
storage <source> elements, rather than full <pool> elements (which
contain "target-dependent" details like the local pool name and device
or mount path -- things which don't need to be decided unless/until the
pool is defined).
I like his suggestion a lot, and I think it addresses the …
[View More]final
API-definition problem keeping storage pool discovery out of libvirt.
But ... it doesn't quite work for logical storage pools because those
are created from the <pool> <name> element (which is the same as the
volume group name).
This patch introduces a new <source> element <name>, which is
distinct
from the pool name. <name> is used only by the logical storage
backend, and represents the volume group name. For convenience and
back-compatibility, <source> <name> defaults to the pool name if not
specified when the pool is defined, and <pool> <name> defaults to the
source name if not specified. There is no requirement that pool and
source name be the same, though.
While admittedly it seems a little weird, it does allow more
flexibility (pool name not tied to vol group name), and allows <source>
to fully specify a logical pool source, as it does for the other pool
types[*]. Defaulting the source name from the pool name means all
existing pool XML definitions continue to work. Defaulting the pool
name from the source name is simply a matter of convenience (but perhaps
a step too far?)
If this is accepted, logical pool discovery can then return a bunch of
sources like:
<source><name>VolGroup00</name></source>
<source><name>VolGroup01</name></source>
Please note I'll be on vacation next week (Aug 11-15), so I may not be
responding until the following week.
Thanks,
Dave
[*] Well ... almost. Note that directory pools have a similar issue --
the "source" of the pool is given by the <target> <path> -- there's no
<source>. I suppose implementing directory pool discovery (for the sake
of completeness) means addressing this as well, maybe via some similar
mechanism ...
[View Less]
16 years, 7 months
[libvirt] libvir: Xen error
by mantra UNIX
Hello everyone,
I get the following error when i try to redtart a domain;
# virsh list
libvir: Xen error : Domain not found: xenUnifiedDomainLookupByID
I am using RHEL5.2 on i386, I have searched for the error on web
and on RedHat but could not find any.
--
Regards,
mantra - Instrument of Thought
16 years, 7 months
[libvirt] [PATCH] Set correct device type when parsing input devices
by Cole Robinson
In virDomainDeviceDefParse, parsing an input device
was actually setting it's type as DEVICE_DISK. The
attached patch fixes this.
Thanks,
Cole
commit 75150ac2536c427f74875fc563abf2fc06595dda
Author: Cole Robinson <crobinso(a)dhcp-100-19-219.bos.redhat.com>
Date: Thu Aug 21 13:27:38 2008 -0400
Fix setting input device type in virDomainDeviceDefParse.
diff --git a/src/domain_conf.c b/src/domain_conf.c
index d482e68..6b23474 100644
--- a/src/domain_conf.c
+++ b/src/domain_conf.c
@@…
[View More] -1656,7 +1656,7 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virConnectPtr conn,
if (!(dev->data.net = virDomainNetDefParseXML(conn, node)))
goto error;
} else if (xmlStrEqual(node->name, BAD_CAST "input")) {
- dev->type = VIR_DOMAIN_DEVICE_DISK;
+ dev->type = VIR_DOMAIN_DEVICE_INPUT;
if (!(dev->data.input = virDomainInputDefParseXML(conn, def->os.type, node)))
goto error;
} else if (xmlStrEqual(node->name, BAD_CAST "sound")) {
[View Less]
16 years, 7 months
[libvirt] [PATCH] Don't list capabilities entries if emulators can't be accessed
by Cole Robinson
The patch below fixes capabilities xml generation for
the qemu driver if the emulators aren't found in the
hardcoded paths. Current behavior will add a <guest>
entry for the emulator even if it does not exist, patch
fixes this to check that we actually have access.
This brings up another issue, that hardcoded paths
aren't exactly distro friendly. I'm not really familiar
with what options we have to allow specifying these
at build time (or something else). Anyone have an
idea?
Thanks,
…
[View More]Cole
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index dc9e42a..0328cc1 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -230,6 +230,10 @@ qemudCapsInitGuest(virCapsPtr caps,
virCapsGuestPtr guest;
int i;
+ /* Check for existance of base emulator */
+ if (access(info->binary, X_OK) == -1)
+ return 0;
+
if ((guest = virCapabilitiesAddGuest(caps,
hvm ? "hvm" : "xen",
info->arch,
@@ -241,9 +245,7 @@ qemudCapsInitGuest(virCapsPtr caps,
return -1;
if (hvm) {
- /* Check for existance of base emulator */
- if (access(info->binary, X_OK) == 0 &&
- virCapabilitiesAddGuestDomain(guest,
+ if (virCapabilitiesAddGuestDomain(guest,
"qemu",
NULL,
NULL,
@@ -263,6 +265,7 @@ qemudCapsInitGuest(virCapsPtr caps,
return -1;
if (access("/dev/kvm", F_OK) == 0 &&
+ access("/usr/bin/qemu-kvm", X_OK) == 0 &&
virCapabilitiesAddGuestDomain(guest,
"kvm",
"/usr/bin/qemu-kvm",
[View Less]
16 years, 7 months
[libvirt] console not working anymore
by Stefan de Konink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
I have reopenend the <bootloader /> bug, because with this fix I was
unable to start any host again with respect to console allocation.
Did anyone see this problem too?
Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEAREKAAYFAki69PsACgkQYH1+F2Rqwn2X4QCgkHxpu0WDDCKgoRn02P6F3hxw
ncIAn09ahmzjjp3LHGuzVZ8LQREOnsoL
=WVQk
-----END PGP SIGNATURE-----
16 years, 7 months
[libvirt] ANNOUNCE: virt-what 1.0 - a shell script to detect if you are running in a virtual machine
by Richard W.M. Jones
I'm pleased to announce the first release of 'virt-what', which is a
simple shell script that detects if you are running inside a virtual
machine, and prints some "facts" about that virtual machine. This is
a frequently requested feature.
Home page: http://et.redhat.com/~rjones/virt-what/
Source and RPMs: http://et.redhat.com/~rjones/virt-what/files/
So far we can detect:
- Xen
- QEMU and KVM (but not distinguish between them)
- VMware
- Microsoft VirtualPC
I'm hoping that …
[View More]people who run or develop other virtualization
technology will be able to contribute snippets to detect those.
It's worth saying (before Dan Berrange says it anyway) that although
people often think they need this sort of feature, in most cases using
this script is the WRONG THING. If you need a specific virtualization
feature, then add code to your application to detect that feature.
eg. If you need to make Xen hypervisor calls, your application should
try to open /proc/xen/privcmd. As Dan once put it:
A shell script just printing out 'native', 'dom0' or 'domU' is too
simplistic to be broadly useful to management applications. The
concepts are also ill-defined, eg 'native' as a concept can be a
baremetal kernel, or a fully-virtualized guest, or both. 'DomU' does
not distinguish full or paravirt. The distinction of 'dom0' vs
'native' is irrelevant in non-Xen virtualization systems (eg KVM).
Rich.
--
Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
[View Less]
16 years, 7 months