[Libvir] [PATCH] Check a value in vshCommandOptInt()
by Masayuki Sunou
Hi
When the option which should set a number is set a character
which is not a number, the value is changed into 0 in libvirt.
It causes the movement not expected.
ex)
# virsh vcpupin dom_name A 0,1
=> VCPU0 is pinned without the command becoming the error.
This patch fixes it by checking the value in vshCommandOptInt().
Signed-off-by: Masayuki Sunou <fj1826dm(a)aa.jp.fujitsu.com>
Thanks,
Masayuki Sunou.
----------------------------------------------------------------------
Index: src/virsh.c
===================================================================
RCS file: /data/cvs/libvirt/src/virsh.c,v
retrieving revision 1.95
diff -u -p -r1.95 virsh.c
--- src/virsh.c 14 Aug 2007 07:07:57 -0000 1.95
+++ src/virsh.c 16 Aug 2007 07:13:46 -0000
@@ -3699,12 +3699,16 @@ static int
vshCommandOptInt(vshCmd * cmd, const char *name, int *found)
{
vshCmdOpt *arg = vshCommandOpt(cmd, name);
- int res = 0;
+ int res = 0, num_found = TRUE;
+ char *end_p=NULL;
if (arg)
- res = atoi(arg->data);
+ res = strtol(arg->data, &end_p, 10);
+ if (arg->data == end_p) {
+ num_found = FALSE;
+ }
if (found)
- *found = arg ? TRUE : FALSE;
+ *found = (arg && num_found) ? TRUE : FALSE;
return res;
}
----------------------------------------------------------------------
17 years, 4 months
[Libvir] Networking functions in libvirt
by Bruce Evans
Hello,
I am now starting to investigate the networking driver callback
functions in libvirt.
struct _virNetworkDriver {
virDrvOpen open;
virDrvClose close;
virDrvNumOfNetworks numOfNetworks;
virDrvListNetworks listNetworks;
virDrvNumOfDefinedNetworks numOfDefinedNetworks;
virDrvListDefinedNetworks listDefinedNetworks;
virDrvNetworkLookupByUUID networkLookupByUUID;
virDrvNetworkLookupByName networkLookupByName;
virDrvNetworkCreateXML networkCreateXML;
virDrvNetworkDefineXML networkDefineXML;
virDrvNetworkUndefine networkUndefine;
virDrvNetworkCreate networkCreate;
virDrvNetworkDestroy networkDestroy;
virDrvNetworkDumpXML networkDumpXML;
virDrvNetworkGetBridgeName networkGetBridgeName;
virDrvNetworkGetAutostart networkGetAutostart;
virDrvNetworkSetAutostart networkSetAutostart;
};
My question is from the point of view of the Virtual Manager GUI.
From the controls available in the GUI, what actions are intended
to be done, via the network callback functions?
Are the actions only client related? Create a vnet, vdisk, etc?
Or are they also intended for server actions, create a switch service,
disk service, etc?
There is no example in the test.c program, so I don't have any example
to look at.
Also, is there any documentation describing the network callback functions?
TIA,
-Bruce Evans
Sun Microsystems
Systems Virtualization
17 years, 4 months
[Libvir] [patch] virsh setvcpus range check for negative value case
by Atsushi SAKAI
Hi,
This patch adds virsh setvcpus range check for negative value case.
for example
to the inactive domain
virsh setvcpus -1
sets vcpus=4294967295
And cannot boot the inactive domain.
Signed-off-by: Atsushi SAKAI <sakaia(a)jp.fujitsu.com>
Thanks
Atsushi SAKAI
17 years, 4 months
[Libvir] several typo fixes on man virsh
by Atsushi SAKAI
Hi,
several typo fixes on man virsh
(uses ispell)
interract -> interact
suports -> supports
privledges -> privileges
synoposis -> synopsis
documetnation -> documentation
runable -> runnable
Ouput -> Output
guaruntee -> guarantee
processus -> processes (2 typo)
Detatch -> Detach
dvices -> devices
instanciated -> instantiated
Thanks
Atsushi SAKAI
17 years, 4 months
[Libvir] [PATCH 0/7] QEMU/KVM save/restore support, take 3
by Jim Paris
Here's take 3 of the QEMU/KVM save/restore support. Thanks for your
input.
Changes since last time:
- Remove escape sequence filtering, it's not necessary.
- Clean up stdin handling in virExec, use -1 to signify unused
- Add signal-safe read/write wrappers that handle EINTR and use them.
- Add version and padding to image header, and check version on restore.
- Include null-termination in XML data & length
- Show name of conflicting domain in error message
Everything seems to work well in my tests. I've run into a few rare
cases where the migration doesn't work correctly (causing segfaults in
the guest, or kvm to crash), but it's not libvirt's fault, and libvirt
handles the failures well.
(I suspect it's related to
http://article.gmane.org/gmane.comp.emulators.kvm.devel/5583)
Thanks,
-jim
17 years, 4 months
[Libvir] save/restore support for KVM
by Jim Paris
Hi,
I've implemented save/restore support for KVM using the live migration
feature. First, a few patches to KVM to fix bugs:
Subject: [PATCH 1/3] qemu: fix freed pointer dereference
http://article.gmane.org/gmane.comp.emulators.kvm.devel/5572
Subject: [PATCH 2/3] qemu: don't start a new migration if one is already in progress
http://article.gmane.org/gmane.comp.emulators.kvm.devel/5575
Subject: [PATCH 3/3] qemu: reset buffer pointers after CR/LF
http://article.gmane.org/gmane.comp.emulators.kvm.devel/5573
(If compatibility with old KVM is wanted, it might be possible to work
around the kvm bugs in other ways, but I'm not sure).
Then, another patch to KVM to support inbound migration from a
filename. It already supports migration from stdin, but adding this
seemed easier from a libvirt perspective.
Subject: [PATCH] qemu: accept filename for incoming migration
http://article.gmane.org/gmane.comp.emulators.kvm.devel/5590
Finally, the libvirt side. Some notes:
- Arbitrary decisions about VM status: I pause the VM before starting
migration, and destroy it once it's finished. Neither is required
by KVM but I'd be concerned about the disk image state otherwise.
Also, after resuming, the VM is still paused. I don't know how Xen
behaves in this regard but the behavior here is easy enough to
change.
- I append the domain's UUID at the end of the migration image.
This doesn't affect KVM at all (it ignores the extra data).
Does that seem reasonable? It's unclear how the saved image
is supposed to get associated with a particular VM configuration
without doing something like this.
- I added the migrateFrom field to the qemu_vm struct. Dunno
if that's the best place. Could also add put it in qemu_vm_def,
or add parameters to qemudStartVMDaemon, etc..
Patch against current CVS is below.
Signed-off-by: Jim Paris <jim(a)jtan.com>
-jim
Index: src/qemu_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_conf.c,v
retrieving revision 1.10
diff -u -r1.10 qemu_conf.c
--- src/qemu_conf.c 7 Aug 2007 13:02:35 -0000 1.10
+++ src/qemu_conf.c 9 Aug 2007 21:15:10 -0000
@@ -1518,7 +1518,8 @@
(vm->def->os.initrd[0] ? 2 : 0) + /* initrd */
(vm->def->os.cmdline[0] ? 2 : 0) + /* cmdline */
(vm->def->graphicsType == QEMUD_GRAPHICS_VNC ? 2 :
- (vm->def->graphicsType == QEMUD_GRAPHICS_SDL ? 0 : 1)); /* graphics */
+ (vm->def->graphicsType == QEMUD_GRAPHICS_SDL ? 0 : 1)) + /* graphics */
+ (vm->migrateFrom[0] ? 3 : 0); /* migrateFrom */
snprintf(memory, sizeof(memory), "%d", vm->def->memory/1024);
snprintf(vcpus, sizeof(vcpus), "%d", vm->def->vcpus);
@@ -1767,6 +1768,15 @@
/* SDL is the default. no args needed */
}
+ if (vm->migrateFrom[0]) {
+ if (!((*argv)[++n] = strdup("-S")))
+ goto no_memory;
+ if (!((*argv)[++n] = strdup("-incoming")))
+ goto no_memory;
+ if (!((*argv)[++n] = strdup(vm->migrateFrom)))
+ goto no_memory;
+ }
+
(*argv)[++n] = NULL;
return 0;
Index: src/qemu_conf.h
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_conf.h,v
retrieving revision 1.6
diff -u -r1.6 qemu_conf.h
--- src/qemu_conf.h 30 Jul 2007 09:59:06 -0000 1.6
+++ src/qemu_conf.h 9 Aug 2007 21:15:10 -0000
@@ -213,6 +213,7 @@
char configFile[PATH_MAX];
char autostartLink[PATH_MAX];
+ char migrateFrom[PATH_MAX];
struct qemud_vm_def *def; /* The current definition */
struct qemud_vm_def *newDef; /* New definition to activate at shutdown */
Index: src/qemu_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/qemu_driver.c,v
retrieving revision 1.14
diff -u -r1.14 qemu_driver.c
--- src/qemu_driver.c 30 Jul 2007 09:59:06 -0000 1.14
+++ src/qemu_driver.c 9 Aug 2007 21:15:10 -0000
@@ -656,7 +656,7 @@
if (virExecNonBlock(conn, argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) {
vm->id = driver->nextvmid++;
- vm->state = VIR_DOMAIN_RUNNING;
+ vm->state = vm->migrateFrom[0] ? VIR_DOMAIN_PAUSED : VIR_DOMAIN_RUNNING;
driver->ninactivevms--;
driver->nactivevms++;
@@ -1852,29 +1852,151 @@
return 0;
}
+#define QEMUD_SAVE_MAGIC "LibvirtQemudUUID"
-static int qemudDomainSave(virDomainPtr dom,
- const char *path ATTRIBUTE_UNUSED) {
+static int qemudDomainSave(virDomainPtr dom,
+ const char *path) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
struct qemud_vm *vm = qemudFindVMByID(driver, dom->id);
+ char *command, *info;
+ int fd;
+
if (!vm) {
- qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", dom->id);
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
+ "no domain with matching id %d", dom->id);
return -1;
}
+
if (!qemudIsActiveVM(vm)) {
- qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, "domain is not running");
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+ "domain is not running");
return -1;
}
- qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED, "save is not supported");
- return -1;
+
+ if (strchr(path, '\'') || strchr(path, '\\') ) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+ "invalid filename");
+ return -1;
+ }
+
+ /* Pause */
+ if (qemudDomainSuspend(dom) != 0) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+ "failed to pause domain");
+ return -1;
+ }
+
+ /* Migrate to file. */
+ if (asprintf (&command, "migrate \"exec:dd of='%s' 2>/dev/null\"\n",
+ path) == -1) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+ "out of memory");
+ return -1;
+ }
+
+ if (qemudMonitorCommand(driver, vm, command, &info) < 0) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+ "migrate operation failed");
+ free(command);
+ return -1;
+ }
+
+ free(info);
+ free(command);
+
+ /* Append the UUID, which we'll need in order to restore the domain. */
+ if ((fd = open(path, O_APPEND|O_WRONLY)) < 0) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+ "failed to open '%s'", path);
+ return -1;
+ }
+
+ if (write(fd, QEMUD_SAVE_MAGIC, sizeof(QEMUD_SAVE_MAGIC)) !=
+ sizeof(QEMUD_SAVE_MAGIC)) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+ "failed to write magic");
+ close(fd);
+ return -1;
+ }
+
+ if (write(fd, dom->uuid, VIR_UUID_BUFLEN) != VIR_UUID_BUFLEN) {
+ qemudReportError(dom->conn, dom, NULL, VIR_ERR_OPERATION_FAILED,
+ "failed to write uuid");
+ close(fd);
+ return -1;
+ }
+ close(fd);
+
+ /* Shut it down */
+ qemudShutdownVMDaemon(dom->conn, driver, vm);
+ if (!vm->configFile[0])
+ qemudRemoveInactiveVM(driver, vm);
+
+ return 0;
}
static int qemudDomainRestore(virConnectPtr conn,
- const char *path ATTRIBUTE_UNUSED) {
- /*struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;*/
- qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, "restore is not supported");
- return -1;
+ const char *path) {
+ struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
+ unsigned char uuid[VIR_UUID_BUFLEN];
+ unsigned char magic[sizeof(QEMUD_SAVE_MAGIC)];
+ virDomainPtr dom;
+ struct qemud_vm *vm;
+ int fd;
+
+ /* Find the UUID */
+ if ((fd = open(path, O_RDONLY)) < 0) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+ "cannot read domain image");
+ return -1;
+ }
+ if (lseek(fd, 0 - (sizeof(magic) + sizeof(uuid)), SEEK_END) == -1) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+ "failed to seek to end of domain image");
+ close(fd);
+ return -1;
+ }
+ if (read(fd, magic, sizeof(magic)) != sizeof(magic)) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+ "failed to read domain image");
+ close(fd);
+ return -1;
+ }
+ if (memcmp(magic, QEMUD_SAVE_MAGIC, sizeof(magic))) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+ "image magic is not correct");
+ close(fd);
+ return -1;
+ }
+ if (read(fd, uuid, sizeof(uuid)) != sizeof(uuid)) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
+ "failed to read domain UUID from image");
+ close(fd);
+ return -1;
+ }
+ close(fd);
+
+ /* Find the domain & vm */
+ dom = qemudDomainLookupByUUID(conn, uuid);
+ if (!dom) {
+ qemudReportError(conn, NULL, NULL, VIR_ERR_INVALID_DOMAIN,
+ "no domain with matching uuid");
+ return -1;
+ }
+
+ vm = qemudFindVMByUUID(driver, dom->uuid);
+ if (!vm) {
+ qemudReportError(conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
+ "no vm with matching uuid");
+ return -1;
+ }
+
+ /* Set the migration source and start it up. */
+ snprintf(vm->migrateFrom, sizeof(vm->migrateFrom), "file://%s", path);
+ vm->migrateFrom[sizeof(vm->migrateFrom)-1] = '\0';
+
+ return qemudStartVMDaemon(dom->conn, driver, vm);
}
@@ -1931,6 +2053,7 @@
return -1;
}
+ vm->migrateFrom[0] = '\0';
return qemudStartVMDaemon(dom->conn, driver, vm);
}
17 years, 4 months
[Libvir] [PATCH] Block device and network stats
by Richard W.M. Jones
This is the implementation (currently Xen, local only).
It includes a couple of virsh commands if you want to play with looking
at the stats.
Rich.
--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in
England and Wales under Company Registration No. 03798903
17 years, 4 months
[Libvir] PATCH: Fix paravirt FB with xm driver
by Daniel P. Berrange
The code for dealing with the paravirt framebuffer was missing code to deal
with an explicit vncdisplay=N setting - only working for vncunused=1. It
was also not flexible enough in processing the 2 different styles of FB
config.
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
17 years, 4 months