Commit Graph

8028 Commits

Author SHA1 Message Date
Eric Blake
691ec08bac virsh: support 'virsh start --force-boot' on older servers
Managed save was added in 0.8.0, virDomainCreateWithFlags in 0.8.2,
and FORCE_BOOT in 0.9.5.  The virsh flag is more useful if we
emulate it for all older servers (note that if a hypervisor fails
the query for a managed save image, then it does not have one to
be removed, so the flag can be safely ignored).

* tools/virsh.c (cmdStart): Add emulation for new flag.
2011-09-01 12:42:48 -06:00
Alex Jia
59d4b170fc virsh: avoid memory leak on cmdVolCreateAs
* tools/virsh.c: fix memory leak on cmdVolCreateAs function.

* Detected in valgrind run:

==4746==
==4746== 48 (40 direct, 8 indirect) bytes in 1 blocks are definitely lost in loss record 26 of 52
==4746==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==4746==    by 0x4C76E51: virAlloc (memory.c:101)
==4746==    by 0x4CD9418: virGetStoragePool (datatypes.c:592)
==4746==    by 0x4D21367: remoteStoragePoolLookupByName (remote_driver.c:4126)
==4746==    by 0x4CE42B0: virStoragePoolLookupByName (libvirt.c:10232)
==4746==    by 0x40C276: vshCommandOptPoolBy (virsh.c:13660)
==4746==    by 0x40CA37: cmdVolCreateAs (virsh.c:8094)
==4746==    by 0x412AF2: vshCommandRun (virsh.c:13770)
==4746==    by 0x422F11: main (virsh.c:15127)
==4746==
==4746== 1,011 bytes in 1 blocks are definitely lost in loss record 45 of 52
==4746==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==4746==    by 0x4A06167: realloc (vg_replace_malloc.c:525)
==4746==    by 0x4C76ECB: virReallocN (memory.c:161)
==4746==    by 0x4C60319: virBufferGrow (buf.c:72)
==4746==    by 0x4C606AA: virBufferAdd (buf.c:106)
==4746==    by 0x40CB37: cmdVolCreateAs (virsh.c:8118)
==4746==    by 0x412AF2: vshCommandRun (virsh.c:13770)
==4746==    by 0x422F11: main (virsh.c:15127)
==4746==
==4746== LEAK SUMMARY:
==4746==    definitely lost: 1,051 bytes in 2 blocks
==4746==    indirectly lost: 8 bytes in 1 blocks
==4746==      possibly lost: 0 bytes in 0 blocks
==4746==    still reachable: 390,767 bytes in 1,373 blocks
==4746==         suppressed: 0 bytes in 0 blocks

* How to reproduce?

% valgrind -v --leak-check=full virsh vol-create-as default foo.img 10M \
  --allocation 0 --format qcow2 --backing-vol bar.img

Notes: bar.img doesn't exist.

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-09-01 12:41:00 -06:00
Eric Blake
7bc1c5cefe build: fix 'make check' with pdwtags
Problem introduced by commit b12354b.

* src/remote_protocol-structs: Remove spurious blank line.
2011-09-01 12:33:46 -06:00
Jim Fehlig
1282bd80f7 virsh: Expose virDomainMigrateGetMaxSpeed API 2011-09-01 11:26:21 -06:00
Jim Fehlig
b12354befe Add public API for getting migration speed
Includes impl of python binding since the generator was not
able to cope.

Note: Requires gendispatch.pl patch from Matthias Bolte

https://www.redhat.com/archives/libvir-list/2011-August/msg01367.html
2011-09-01 11:26:21 -06:00
Eric Blake
d1535e668a virsh: prefer unsigned flags
virsh had some leftover 'int flags', and even an 'int flag'
declaration, compared to our preferred style of 'unsigned int flags'.

* tools/virsh.c (cmdUndefine, cmdSave, cmdSaveImageDumpxml)
(cmdSaveImageEdit, cmdManagedSave, cmdRestore, cmdDump)
(cmdVcpuPin, cmdSetvcpus, cmdSetmem, cmdSetmaxmem, cmdDumpXML)
(cmdDomXMLFromNative, cmdDomXMLToNative, doMigrate)
(cmdInterfaceEdit, cmdInterfaceDumpXML, cmdEdit): Match coding
style for flags.
(struct vshComdOptDef): Rename field member.
(vshCmddefOptParse, vshCmddefHelp): Adjust clients.
2011-09-01 08:16:57 -06:00
Daniel P. Berrange
b3fb288e52 Fix tracking of RPC messages wrt streams
Commit 2c85644b0b attempted to
fix a problem with tracking RPC messages from streams by doing

-            if (msg->header.type == VIR_NET_REPLY) {
+            if (msg->header.type == VIR_NET_REPLY ||
+                (msg->header.type == VIR_NET_STREAM &&
+                 msg->header.status != VIR_NET_CONTINUE)) {
                 client->nrequests--;

In other words any stream packet, with status NET_OK or NET_ERROR
would cause nrequests to be decremented. This is great if the
packet from from a synchronous virStreamFinish or virStreamAbort
API call, but wildly wrong if from a server initiated abort.
The latter resulted in 'nrequests' being decremented below zero.
This then causes all I/O for that client to be stopped.

Instead of trying to infer whether we need to decrement the
nrequests field, from the message type/status, introduce an
explicit 'bool tracked' field to mark whether the virNetMessagePtr
object is subject to tracking.

Also add a virNetMessageClear function to allow a message
contents to be cleared out, without adversely impacting the
'tracked' field as a naive memset() would do

* src/rpc/virnetmessage.c, src/rpc/virnetmessage.h: Add
  a 'bool tracked' field and virNetMessageClear() API
* daemon/remote.c, daemon/stream.c, src/rpc/virnetclientprogram.c,
  src/rpc/virnetclientstream.c, src/rpc/virnetserverclient.c,
  src/rpc/virnetserverprogram.c: Switch over to use
  virNetMessageClear() and pass in the 'bool tracked' value
  when creating messages.
2011-09-01 10:52:35 +01:00
Daniel P. Berrange
1b72ad2eaa Avoid use-after-free on streams, due to message callbacks
When sending outbound stream RPC messages, a callback is
used to re-enable stream data transmission. If the stream
aborts while one of these messages is outstanding, the
stream may have been free'd by the time it is invoked. This
results in a use-after-free error

* daemon/stream.c: Ref-count streams to avoid use-after-free
2011-09-01 10:52:35 +01:00
Daniel P. Berrange
b6263c1801 Fix parted sector size assumption
Parted does not report disk size in 512 byte units, but
rather the disks' logical sector size, which with modern
drives might be 4k.

* src/storage/parthelper.c: Remove hardcoded 512 byte sector
  size
2011-09-01 10:46:31 +01:00
Osier Yang
6f2581edd7 qemu: Fix a regression of domain save
* src/qemu/qemu_driver.c - qemuDomainSaveInternal: Return directly
will keep the domain object locked, introduced by 173015bec6.
2011-09-01 17:38:20 +08:00
Osier Yang
9f3e724339 Revert "test: Cleanup improper VIR_ERR_NO_SUPPORT use"
This reverts commit 172214bd30.
2011-09-01 17:37:11 +08:00
Osier Yang
ffafede112 storage: Fix incorrect error codes
Commit 0376f4a69b intended to fix incorrect use of VIR_ERR_NO_SUPPORT,
but replacing it with VIR_ERR_OPERATION_INVALID is not proper either.
2011-09-01 17:36:38 +08:00
Osier Yang
fd038a337b remote: Fix incorrect error codes
Introduced by d4b53ef6c. For "no internalFlags support", the
error code is changed into INTERNAL_ERROR.
2011-09-01 17:35:56 +08:00
Osier Yang
03388b6424 nodeinfo: Fix incorrect error codes
Introduced by 5e495c8b, except the ones for checking if numa
is supported by host, all the NO_SUPPORT are changed back. For
the ones about numa checking, change them into INTERNAL_ERROR.
2011-09-01 17:35:23 +08:00
Osier Yang
6af0c3e82b lxc: Fix incorrect changes on error codes.
Fix incorrect changes introduced by commit 6ac47762bb.
2011-09-01 17:34:31 +08:00
Osier Yang
c2c713dd00 conf: Substitute OPERATION_INVALID with INTERNAL_ERROR 2011-09-01 17:31:24 +08:00
Daniel P. Berrange
6ff9fc26d3 Stop libxl driver polluting logs on non-Xen hosts
If the libxl driver is compiled in, then everytime libvirtd
starts up on a non-Xen Dom0 host, it logs a error message.
Since this is an expected condition, we should not log at
'error' level, only 'info'.

* src/libxl/libxl_driver.c: Lower log level for certain
  expected errors during driver init
2011-08-31 17:53:01 +01:00
Daniel P. Berrange
d07aa6a96f Fix memory leak parsing 'relabel' attribute in domain security XML
* src/conf/domain_conf.c: Free the 'relabel' attribute
2011-08-31 17:51:09 +01:00
Daniel P. Berrange
a91d3115b5 Fix memory leak dispatching domain events
When dispatching domain events we will create an XDR struct
containing the event info. Some of this data may be allocated
on the heap and so must be freed. The graphics event dispatcher
had a broken attempt to free one field, but missed others. All
the events have a dom->name string that needs freeing. The code
should have used the xdr_free() procedure for doing all this

* daemon/remote.c: Use xdr_free after dispatching events
2011-08-31 17:51:09 +01:00
Daniel P. Berrange
c32536e7da Don't leak memory if a cgroup is mounted multiple times
It is possible (expected/likely in Fedora 15) for a cgroup controller
to be mounted in multiple locations at the same time, due to bind
mounts. Currently we leak memory if this happens, because we overwrite
the previous 'mountPoint' string. Instead just accept the first match
we find.

* src/util/cgroup.c: Only accept first match for a cgroup
  controller mount
2011-08-31 17:51:09 +01:00
Eric Blake
cab55fa0a8 security: fix build
Regression introduced in commit 183383889.

* src/libvirt_private.syms (security_manager.h): Drop deleted
symbol. Detected by build-bot.
2011-08-31 08:33:17 -06:00
Guannan Ren
0e5c4ab79c stream: remove redundant reference to client while sending stream data
*daemon/stream.c: remove virNetServerClientRef()
2011-08-31 08:29:46 -06:00
Daniel P. Berrange
183383889a Remove bogus virSecurityManagerSetProcessFDLabel method
The virSecurityManagerSetProcessFDLabel method was introduced
after a mis-understanding from a conversation about SELinux
socket labelling. The virSecurityManagerSetSocketLabel method
should have been used for all such scenarios.

* src/security/security_apparmor.c, src/security/security_apparmor.c,
  src/security/security_driver.h, src/security/security_manager.c,
  src/security/security_manager.h, src/security/security_selinux.c,
  src/security/security_stack.c: Remove SetProcessFDLabel driver
2011-08-31 11:07:31 +01:00
Daniel P. Berrange
64bdec3841 Fix sanlock socket security labelling
It is not possible to change the label of a TCP socket once it
has been opened. When creating a TCP socket care must be taken
to ensure the socket creation label is set & then cleared.
Remove the bogus call to virSecurityManagerSetProcessFDLabel
from the lock driver guest setup code and instead make use of
virSecurityManagerSetSocketLabel
2011-08-31 11:07:31 +01:00
Daniel P. Berrange
2223b1f71f Fix incorrect path length check in sanlock lockspace setup
The code for creating a sanlock lockspace accidentally used
SANLK_NAME_LEN instead of SANLK_PATH_LEN for a size check.
This meant disk paths were limited to 48 bytes !

* src/locking/lock_driver_sanlock.c: Fix disk path length
  check
2011-08-31 11:07:31 +01:00
Eric Blake
173015bec6 snapshot: forbid snapshot on autodestroy domain
There is no reason to forbid pausing an autodestroy domain
(not to mention that 'virsh start --paused --autodestroy'
succeeds in creating a paused autodestroy domain).

Meanwhile, qemu was failing to enforce the API documentation that
autodestroy domains cannot be saved.  And while the original
documentation only mentioned save/restore, snapshots are another
form of saving that are close enough in semantics as to make no
sense on one-shot domains.

* src/qemu/qemu_driver.c (qemudDomainSuspend): Drop bogus check.
(qemuDomainSaveInternal, qemuDomainSnapshotCreateXML): Forbid
saves of autodestroy domains.
* src/libvirt.c (virDomainCreateWithFlags, virDomainCreateXML):
Document snapshot interaction.
2011-08-30 11:03:54 -06:00
Philipp Hahn
4521ffabeb Fix error detection in device change
According to qemu-kvm/qerror.c all messages start with a capital
"Device ", but the current code only scans for the lower case "device ".
This results in "virDomainUpdateDeviceFlags()" to not detect locked
CD-ROMs and reporting success even in the case of a failure:
	# virsh qemu-monitor-command "$VM" change\ drive-ide0-0-0\ \"/var/lib/libvirt/images/ucs_2.4-0-sec4-20110714145916-dvd-amd64.iso\"
	Device 'drive-ide0-0-0' is locked
	# virsh update-device "$VM" /dev/stdin <<<"<disk type='file' device='cdrom'><driver name='qemu' type='raw'/><source file='/var/lib/libvirt/images/ucs_2.4-0-sec4-20110714145916-dvd-amd64.iso'/><target dev='hda' bus='ide'/><readonly/><alias name='ide0-0-0'/><address type='drive' controller='0' bus='0' unit='0'/></disk>"
	Device updated successfully

Signed-off-by: Philipp Hahn <hahn@univention.de>
2011-08-30 10:32:13 -06:00
Eric Blake
27c8526053 start: allow discarding managed save
There have been several instances of people having problems with
a broken managed save file, and not aware that they could use
'virsh managedsave-remove dom' to fix things.  Making it possible
to do this as part of starting a domain makes the same functionality
easier to find, and one less API call.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_START_FORCE_BOOT): New
flag.
* src/libvirt.c (virDomainCreateWithFlags): Document it.
* src/qemu/qemu_driver.c (qemuDomainObjStart): Alter signature.
(qemuAutostartDomain, qemuDomainStartWithFlags): Update callers.
* tools/virsh.c (cmdStart): Expose it in virsh.
* tools/virsh.pod (start): Document it.
2011-08-30 09:26:47 -06:00
Eric Blake
71a0beaf3a build: simplify use of verify
Back in 2008 when this line of util.h was written, gnulib's verify
module didn't allow the use of multiple verify() in one file
in combination with our choice of gcc -W options.  But that has
since been fixed in gnulib, and newer gnulib even maps verify()
to the C1x feature of _Static_assert, which gives even nicer
diagnostics with a new enough compiler, so we might as well go
with the simpler verify().

* src/util/util.h (VIR_ENUM_IMPL): Use simpler verify, now that
gnulib module is smarter.
2011-08-30 09:23:20 -06:00
Eric Blake
e6b8bc812a qemu: properly label outgoing pipe for tunneled migration
Commit 3261761 made it possible to use pipes instead of sockets
for outgoing tunneled migration; however, it caused a regression
because the pipe was never given a SELinux label.

* src/qemu/qemu_migration.c (doTunnelMigrate): Label outgoing pipe.
2011-08-30 09:15:26 -06:00
Guannan Ren
bae460fc56 rpc: fix a typo in debugging log in virNetServerProgramSendStreamData
The bufferOffset has been initialized to zero in virNetMessageEncodePayloadRaw(),
so, we use bufferLength to represent the length of message which is going to be
sent to client side.
2011-08-29 11:35:49 -06:00
Eric Blake
a71f8fc70f maint: fix spelling errors on lose
* docs/drvqemu.html.in: Fix typo.
* src/libvirt.c (virDomainCreateXML, virDomainCreateWithFlags):
Likewise.
2011-08-26 16:48:24 -06:00
Jim Fehlig
7e5f6a516c Fix generator to cope with call-by-ref long types
From: Matthias Bolte <matthias.bolte@googlemail.com>
Tested-by: Jim Fehlig <jfehlig@novell.com>

Matthias provided this patch to fix an issue I encountered in the
generator with APIs containing call-by-ref long type, e.g.

int virDomainMigrateGetMaxSpeed(virDomainPtr domain,
                                unsigned long *bandwidth,
                                unsigned int flags);
2011-08-26 11:46:41 -06:00
Matthias Bolte
2137cb1911 hyperv: Add basic documentation 2011-08-26 17:52:55 +02:00
Matthias Bolte
5e3b0f8b57 hyperv: Add basic driver for Microsoft Hyper-V
Domain listing, basic information retrieval and domain life cycle
management is implemented. But currently the domain XML output
lacks the complete devices section.

The driver uses OpenWSMAN to directly communicate with a Hyper-V
server over its WS-Management interface exposed via Microsoft WinRM.

The driver is based on the work of Michael Sievers. This started in
the same master program project group at the University of Paderborn
as the ESX driver.

See Michael's blog for details: http://hyperv4libvirt.wordpress.com/
2011-08-26 17:52:55 +02:00
Matthias Bolte
e224b6f8fb hyperv: Add OpenWSMAN based client for the Hyper-V WMI API
Add a generator script to generate the structs and serialization
information for OpenWSMAN.

openwsman.h collects workarounds for problems in OpenWSMAN <= 2.2.6.
There are also disabled sections that would use ws_serializer_free_mem
but can't because it's broken in OpenWSMAN <= 2.2.6. Patches to fix
this have been posted upstream.
2011-08-26 17:52:55 +02:00
Matthias Bolte
4d6e6f4aa9 hyperv: Add driver skeleton 2011-08-26 17:52:55 +02:00
Matthias Bolte
f2e7064373 hyperv: Add configure check for OpenWSMAN 2011-08-26 17:52:54 +02:00
Taku Izumi
5f57c48528 schedinfo: update man page about virsh schedinfo command
This patch updates the man page about virsh schedinfo command.

 - fix typo: 1844674407370955 -> 18446744073709551
 - describe the value 0 of vcpu_period and vcpu_quota parameters

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-08-26 09:50:43 -06:00
KAMEZAWA Hiroyuki
709b4c500d Fix persistent migration config save
When a user migrates a domain by command as

libvirt saves vm's domain XML config in destination host after migration.
But it saves vm->def. Then, the saved XML contains some garbage.

  <domain type='kvm' id='50'>
                     ^^^^^^^^
  ...
   <console type='pty' tty='/dev/pts/5'>
                       ^^^^^^^^^^^^^^^^^

Avoid saving unnecessary things by saving persistent vm definition.
2011-08-26 09:45:57 -06:00
Jiri Denemark
22d744d0c7 rpc: Don't close connection if program is unknown
In case we add a new program in the future (we did that in the past and
we are going to do it again soon) current daemon will behave badly with
new client that wants to use the new program. Before the RPC rewrite we
used to just send an error reply to any request with unknown program.
With the RPC rewrite in 0.9.3 the daemon just closes the connection
through which such request was sent. This patch fixes this regression.
2011-08-26 17:29:44 +02:00
Michal Privoznik
c4f91b144c remote: Refuse connecting to remote socket
If users wants to connect to remote unix socket, e.g.
'qemu+unix://<remote>/system' currently the <remote> part is ignored,
ending up connecting to localhost. Connecting to remote socket is not
supported and user should have used TLS/TCP/SSH instead.
2011-08-26 16:40:58 +02:00
Michal Privoznik
6c7299d47d virterror: Fix error message for VIR_ERR_INVALID_ARG
When a detail message is presented, nobody expects prefix 'invalid
argument in' but something more general, like 'invalid argument:'.
2011-08-26 16:40:42 +02:00
Daniel P. Berrange
6b434da6bf Detect errors from the 'sendkey' command
On success, the 'sendkey' command does not return any data, so
any data in the reply should be considered to be an error
message

* src/qemu/qemu_monitor_text.c: Treat non-"" reply data as an
  error message for 'sendkey' command
2011-08-26 14:18:57 +01:00
Daniel P. Berrange
ce93f64b1e Fix keymap used to talk with QEMU
The QEMU 'sendkey' command expects keys to be encoded in the same
way as the RFB extended keycode set. Specifically it wants extended
keys to have the high bit of the first byte set, while the Linux
XT KBD driver codeset uses the low bit of the second byte. To deal
with this we introduce a new keymap 'RFB' and use that in the QEMU
driver

* include/libvirt/libvirt.h.in: Add VIR_KEYCODE_SET_RFB
* src/qemu/qemu_driver.c: Use RFB keycode set instead of XT KBD
* src/util/virkeycode-mapgen.py: Auto-generate the RFB keycode
  set from the XT KBD set
* src/util/virkeycode.c: Add RFB keycode entry to table. Add a
  verify check on cardinality of the codeOffset table
2011-08-26 14:18:57 +01:00
Jiri Denemark
7ac78e3237 virsh: Clarify documentation of -d option
The default is 4, not 0.
2011-08-26 11:52:54 +02:00
Jiri Denemark
855f768996 qemu: Correctly label migration TCP socket 2011-08-26 11:52:54 +02:00
Jiri Denemark
520d91f8bd security: Introduce SetSocketLabel
This API labels all sockets created until ClearSocketLabel is called in
a way that a vm can access them (i.e., they are labeled with svirt_t
based label in SELinux).
2011-08-26 11:52:48 +02:00
Jiri Denemark
4c85d96f27 security: Rename SetSocketLabel APIs to SetDaemonSocketLabel
The APIs are designed to label a socket in a way that the libvirt daemon
itself is able to access it (i.e., in SELinux the label is virtd_t based
as opposed to svirt_* we use for labeling resources that need to be
accessed by a vm). The new name reflects this.
2011-08-26 11:51:09 +02:00
Jiri Denemark
b136266d57 Ignore unused streams in virStreamAbort
When virStreamAbort is called on a stream that has not been used yet,
quite confusing error is returned: "this function is not supported by
the connection driver". Let's just ignore such streams as there's
nothing to abort anyway.
2011-08-26 11:25:01 +02:00