Commit Graph

5670 Commits

Author SHA1 Message Date
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
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
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
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
Jiri Denemark
3398eeda75 Do not try to cancel non-existent migration on source
If migration failed on source daemon, the migration is automatically
canceled by the daemon itself. Thus we don't need to call
virDomainMigrateConfirm3(cancelled=1). Calling it doesn't cause any harm
but the resulting error message printed in logs may confuse people.
2011-08-26 11:18:27 +02:00
Eric Blake
6766ff10dd snapshot: track current snapshot across restarts
Audit all changes to the qemu vm->current_snapshot, and make them
update the saved xml file for both the previous and the new
snapshot, so that there is always at most one snapshot with
<active>1</active> in the xml, and that snapshot is used as the
current snapshot even across libvirtd restarts.

This patch does not fix the case of virDomainSnapshotDelete(,CHILDREN)
where one of the children is the current snapshot; that will be later.

* src/conf/domain_conf.h (_virDomainSnapshotDef): Alter member
type and name.
* src/conf/domain_conf.c (virDomainSnapshotDefParseString)
(virDomainSnapshotDefFormat): Update clients.
* docs/schemas/domainsnapshot.rng: Tighten rng.
* src/qemu/qemu_driver.c (qemuDomainSnapshotLoad): Reload current
snapshot.
(qemuDomainSnapshotCreateXML, qemuDomainRevertToSnapshot)
(qemuDomainSnapshotDiscard): Track current snapshot.
2011-08-25 15:11:03 -06:00
Eric Blake
5e47785b85 snapshot: only pass snapshot to qemu command line when reverting
Changing the current vm, and writing that change to the file
system, all before a new qemu starts, is risky; it's hard to
roll back if starting the new qemu fails for some reason.
Instead of abusing vm->current_snapshot and making the command
line generator decide whether the current snapshot warrants
using -loadvm, it is better to just directly pass a snapshot all
the way through the call chain if it is to be loaded.

This frees up the last use of snapshot->def->active for qemu's
use, so the next patch can repurpose that field for tracking
which snapshot is current.

* src/qemu/qemu_command.c (qemuBuildCommandLine): Don't use active
field of snapshot.
* src/qemu/qemu_process.c (qemuProcessStart): Add a parameter.
* src/qemu/qemu_process.h (qemuProcessStart): Update prototype.
* src/qemu/qemu_migration.c (qemuMigrationPrepareAny): Update
callers.
* src/qemu/qemu_driver.c (qemudDomainCreate)
(qemuDomainSaveImageStartVM, qemuDomainObjStart)
(qemuDomainRevertToSnapshot): Likewise.
(qemuDomainSnapshotSetCurrentActive)
(qemuDomainSnapshotSetCurrentInactive): Delete unused functions.
2011-08-25 15:07:57 -06:00
Eric Blake
861dc84bb5 snapshot: don't leak resources on qemu snapshot failure
https://bugzilla.redhat.com/show_bug.cgi?id=727709
mentions that if qemu fails to create the snapshot (such as what
happens on Fedora 15 qemu, which has qmp but where savevm is only
in hmp, and where libvirt is old enough to not try the hmp fallback),
then 'virsh snapshot-list dom' will show a garbage snapshot entry,
and the libvirt internal directory for storing snapshot metadata
will have a bogus file.

This fixes the fallout bug of polluting the snapshot-list with
garbage on failure (the root cause of the F15 bug of not having
fallback to hmp has already been fixed in newer libvirt releases).

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Allocate
memory before making snapshot, and cleanup on failure.  Don't
dereference NULL if transient domain exited during snapshot creation.
2011-08-25 14:01:36 -06:00
Alex Jia
5495e45e70 libvirt: avoid dead store in virDomainMigrateVersion3
* src/qemu/qemu_migration.c: avoid dead 'ret' assignment and silence
  clang warning.

Detected by ccc-analyzer:

libvirt.c:4277:5: warning: Value stored to 'ret' is never read
    ret = domain->conn->driver->domainMigrateConfirm3
    ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2011-08-25 13:28:10 -06:00
Alex Jia
d69d321086 qemu: avoid dead store in doPeer2PeerMigrate3
* src/qemu/qemu_migration.c: avoid dead 'ret' assignment and silence
  clang warning.

Detected by ccc-analyzer:

  CC     libvirt_driver_qemu_la-qemu_migration.lo
qemu/qemu_migration.c:2046:5: warning: Value stored to 'ret' is never read
    ret = qemuMigrationConfirm(driver, sconn, vm,
    ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2011-08-25 13:28:08 -06:00
Michal Privoznik
eaddec976e daemon: Move TLS initialization to virInitialize
My previous patch 74c7567133
introduced a regression by removing TLS initialization from client.
2011-08-25 10:22:03 +02:00
Laine Stump
b1643dc15c util: only fchown newly created files in virFileOpenAs
virFileOpenAs takes desired uid:gid as arguments, and not only uses
them for a fork/setuid/setgid when retrying failed open operations,
but additionally always forces the opened file to be owned by the
given uid:gid.

One example of the problems this causes is that, when restoring a
domain from a file that is owned by the qemu user, opening the file
chowns it to root. if dynamic_ownership=1 this is coincidentally
expected, but if dynamic_ownership=0, no existing file should ever
have its ownership changed.

This patch adds an extra check before calling fchown() - it only does
it if O_CREAT was passed to virFileOpenAs() in the openflags.
2011-08-24 15:32:00 -04:00
Shradha Shah
7ae740fcb1 qemu: fix off-by-one in pci slot reservation
Signed-off-by: Steve Hodgson <shodgson@solarflare.com>
2011-08-24 10:49:02 -06:00
Shradha Shah
c0f025b8ba pci: fix pciDeviceListSteal on multiple devices
pciDeviceListSteal(pcidevs, dev) removes dev from pcidevs reducing
the length of pcidevs, so moving onto what was the next dev is wrong.

Instead callers should pop entry 0 repeatedly until pcidevs is empty.

Signed-off-by: Steve Hodgson <shodgson@solarflare.com>
Signed-off-by: Shradha Shah <sshah@solarflare.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2011-08-24 10:31:29 -06:00
Eric Blake
ba0c219902 libvirt: log all flags parameters
I was testing a virsh patch, and wanted to see if I had passed the
flags I thought.  But with LIBVIRT_DEBUG in the environment, I just
saw:

14:24:52.359: 15022: debug : virDomainSnapshotNum:15586 : dom=0xc9c180, (VM: name=rhel_6-64, uuid=48f8e8e7-e14f-0e14-02f0-ce71997bdcab),

including a trailing space.  This fixes the issues.

* src/libvirt.c: Log flag parameters, even if currently unused.
(VIR_DOMAIN_DEBUG_0): Drop trailing comma in log.
(VIR_DOMAIN_DEBUG_1): Split guts into...
(VIR_DOMAIN_DEBUG_2): ...new macro.
2011-08-24 08:34:49 -06:00
Matthias Bolte
6aa57af3e4 esx: Use $(PYTHON) instead of the shebang to run the generator 2011-08-24 10:45:03 +02:00
Osier Yang
10b100240f qemu: Report error if qemu monitor command not found for BlockJob
* src/qemu/qemu_monitor_json.c: Handle error "CommandNotFound" and
  report the error.

* src/qemu/qemu_monitor_text.c: If a sub info command is not found,
  it prints the output of "help info", for other commands,
  "unknown command" is printed.

Without this patch, libvirt always report:

  An error occurred, but the cause is unknown

This patch was adapted from a patch by Osier Yang <jyang@redhat.com> to
break out detection of unrecognized text monitor commands into a separate
function.

Signed-off-by: Adam Litke <agl@us.ibm.com>
2011-08-24 14:39:42 +08:00
Matthias Bolte
678cd0f04b esx: Refactor a repeated string in the generator 2011-08-23 23:15:21 +02:00
Eric Blake
3a52b864dd maint: fix comment typos
* src/qemu/qemu_driver.c (qemuDomainSaveInternal): Fix typo.
* src/conf/domain_event.c (virDomainEventDispatchMatchCallback):
Likewise.
* daemon/libvirtd.c (daemonRunStateInit): Likewise.
* src/lxc/lxc_container.c (lxcContainerChildMountSort): Likewise.
* src/util/virterror.c (virCopyError, virRaiseErrorFull): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprSound): Likewise.
2011-08-23 11:31:28 -06:00
Osier Yang
0756e5ad92 xen: Cleanup improper VIR_ERR_NO_SUPPORT use 2011-08-23 16:53:15 +08:00
Osier Yang
172214bd30 test: Cleanup improper VIR_ERR_NO_SUPPORT use 2011-08-23 16:32:06 +08:00
Osier Yang
0376f4a69b storage: Cleanup improper VIR_ERR_NO_SUPPORT use 2011-08-23 16:31:03 +08:00
Osier Yang
d4b53ef6cf remote: Cleanup improper VIR_ERR_NO_SUPPORT use 2011-08-23 16:26:26 +08:00
Osier Yang
4340b3ba40 qemu: Cleanup improper VIR_ERR_NO_SUPPORT use
* src/qemu/qemu_command.c: s/VIR_ERR_NO_SUPPORT/VIR_ERR_CONFIG_UNSUPPORTED/

* src/qemu/qemu_driver.c: s/VIR_ERR_NO_SUPPORT/VIR_ERR_OPERATION_INVALID/

* src/qemu/qemu_process.c: s/VIR_ERR_NO_SUPPORT/VIR_ERR_OPERATION_INVALID/
2011-08-23 16:23:10 +08:00
Osier Yang
5e495c8bd8 nodeinfo: Cleanup improper VIR_ERR_NO_SUPPORT use 2011-08-23 16:20:35 +08:00
Osier Yang
6ac47762bb lxc: Cleanup improper VIR_ERR_NO_SUPPORT use
s/VIR_ERR_NO_SUPPORT/VIR_ERR_OPERATION_INVALID/

Special case is changes on lxcDomainInterfaceStats, if it's not
implemented on the platform, prints error like:

    lxcError(VIR_ERR_OPERATION_INVALID, "%s",
             _("interface stats not implemented on this platform"));

As the function is supported by driver actually, error like
VIR_ERR_NO_SUPPORT is confused.
2011-08-23 16:17:10 +08:00
Osier Yang
49218c59b2 conf: Cleanup improper use of VIR_ERR_NO_SUPPORT in node_device_conf 2011-08-23 15:04:00 +08:00
Osier Yang
825d91cd31 qemu: Substitute VIR_ERR_NO_SUPPORT with VIR_ERR_OPERATION_INVALID
* src/qemu/qemu_monitor_text.c: Error like "this function is not
supported by the connection driver" is confused obviously.
2011-08-23 14:59:16 +08:00
KAMEZAWA Hiroyuki
9f5afc732c send-key: fix scan keycode map
Now, bad key-code in send-key can cause segmentation fault in libvirt.
(example)
 % virsh send-key --codeset win32 12
   error: End of file while reading data: Input/output error

This is caused by overrun at scanning keycode array.

Fix it.

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
2011-08-22 07:24:15 -06:00
Eric Blake
d89dd42d51 maint: simplify lots of libxml2 clients
Repetitive patterns should be factored.  The sign of a good
factorization is a change that kills 5x more lines than it adds :)

* src/conf/domain_conf.c (virDomainDeviceDefParse)
(virDomainSnapshotDefParseString): Use new convenience macros.
* src/conf/storage_conf.c (virStoragePoolDefParseSourceString):
Likewise.
* src/cpu/cpu.c (cpuCompareXML, cpuBaselineXML): Likewise.
* src/esx/esx_vi.c (esxVI_Context_Execute): Likewise.
* src/qemu/qemu_migration.c (qemuMigrationCookieXMLParseStr):
Likewise.
* src/security/virt-aa-helper.c (caps_mockup): Likewise.
* src/test/test_driver.c (testOpenFromFile): Likewise.
* tests/cputest.c (cpuTestLoadXML, cpuTestLoadMultiXML):
Likewise.
* tools/virsh.c (cmdFreecell, makeCloneXML, cmdVNCDisplay)
(cmdTTYConsole, cmdDetachInterface, cmdDetachDisk)
(cmdSnapshotCreate, cmdSnapshotCreateAs, cmdSnapshotCurrent)
(cmdSnapshotList, cmdSnapshotParent): Likewise.
2011-08-19 09:13:55 -06:00
Eric Blake
751304e367 xml: add another convenience function
Often, we want to use XPath functions on the just-parsed document;
fold this into the parser function for convenience.

* src/util/xml.h (virXMLParseHelper): Add argument.
(virXMLParseStrHelper, virXMLParseFileHelper): Delete.
(virXMLParseCtxt, virXMLParseStringCtxt, virXMLParseFileCtxt): New
macros.
* src/libvirt_private.syms (xml.h): Remove deleted functions.
* src/util/xml.c (virXMLParseHelper): Add argument.
(virXMLParseStrHelper, virXMLParseFileHelper): Delete.
2011-08-19 09:13:54 -06:00
Eric Blake
e472fe25c7 maint: treat more libxml2 functions as free-like
* cfg.mk (useless_free_options): Add xmlFreeDoc, xmlBufferFree.
* src/esx/esx_vi.c (ESX_VI__TEMPLATE__FREE): Fix offenders.
* tools/virsh.c (cmdFreecell, cmdVNCDisplay, cmdTTYConsole)
(cmdDetachInterface, cmdDetachDisk, cmdSnapshotCreate)
(cmdSnapshotCreateAs, cmdSnapshotList, cmdSnapshotParent):
Likewise.
2011-08-19 09:13:54 -06:00
Eric Blake
04682e694c build: fix typo in recent test patch
* src/test/test_driver.c (testDomainUndefineFlags): Use right
variable name.
2011-08-19 08:20:33 -06:00
Eric Blake
ecc2735480 Revert "xen: Allow to undefine a running domain (xm_internal)"
ACK was given too soon.  According to the code, the xm driver is
only used for inactive domains, and has no notion of an active
domain, thus, it cannot support undefine of a running domain.
The real fix for xen needs to be in the unified driver and/or
the xend level.

This reverts commit 49186deda6.
2011-08-19 08:19:34 -06:00
Osier Yang
49186deda6 xen: Allow to undefine a running domain (xm_internal) 2011-08-19 21:53:39 +08:00
Osier Yang
b9736d5b21 vmware: Allow to undefine a running domain 2011-08-19 21:52:12 +08:00
Osier Yang
b3b4aba5d4 uml: Allow to undefine a running domain 2011-08-19 21:51:42 +08:00
Osier Yang
7d3390f802 test: Allow to undefine a running domain 2011-08-19 21:50:49 +08:00
Osier Yang
aaa93ab6fa qemu: Allow to undefine a running domain 2011-08-19 21:49:37 +08:00
Osier Yang
ea92a34d1d openvz: Allow to undefine a running domain 2011-08-19 21:48:47 +08:00
Osier Yang
b375fc01e2 lxc: Allow to undefine a running domain 2011-08-19 21:47:33 +08:00
Osier Yang
0f407570b4 libxl: Allow to undefine a running domain.
Undefining a running domain will convert it to trasient, but keep
the domain still running.
2011-08-19 21:46:22 +08:00
Osier Yang
4ffa7530a4 qemu: Get memory balloon info correctly for text monitor
* src/qemu/qemu_monitor_text.c: BALLOON_PREFIX was defined as
"balloon: actual=", which cause "actual=" is stripped early before
the real parsing. This patch changes BALLOON_PREFIX into "balloon: ",
and modifies related functions, also renames
"qemuMonitorParseExtraBalloonInfo" to "qemuMonitorParseBalloonInfo",
as after the changing, it parses all the info returned by "info balloon".
2011-08-19 21:34:59 +08:00
Michal Privoznik
b32f8b1989 storage: Flush host cache after write
Although we are flushing cache after some critical writes (e.g.
volume creation), after some others we do not (e.g. volume cloning).
This patch fix this issue. That is for volume cloning, writing
header of logical volume, and storage wipe.
2011-08-19 11:10:31 +02:00
Michal Privoznik
74c7567133 daemon: initialize GnuTLS
When spice_tls is set but listen_tls is not, we don't initialize
GnuTLS library. So any later gnutls call (e.g. during migration,
where we initialize a certificate) will access uninitialized GnuTLS
internal structs and throws an error.

Although, we might now initialize GnuTLS twice, it is safe according
to the documentation:

    This function can be called many times,
    but will only do something the first time.

This patch creates 2 functions: virNetTLSInit and virNetTLSDeinit
with respect to written above.
2011-08-19 10:58:51 +02:00
Eric Blake
310b09ec27 build: fix virnetsocket on mingw
Regression introduced in commit 5d30db0.

* src/rpc/virnetsocket.c (virNetSocketNewListenUNIX) [WIN32]: Use
correct signature.
2011-08-17 11:52:38 -06:00
Eric Blake
c811de8fb7 build: fix virpidfile on mingw
Regression introduced in commit b7e5ca4.

Mingw lacks kill(), but we were only using it for a sanity check;
so we can go with one less check.

Also, on OOM error, this function should outright fail rather than
claim that the pid file was successfully read.

* src/util/virpidfile.c (virPidFileReadPathIfAlive): Skip kill
call where unsupported, and report error on OOM.
2011-08-17 11:51:24 -06:00
Daniel P. Berrange
984840a2c2 Ensure async packets never get marked for sync replies
If a client had initiated a stream abort, it will have a call
waiting for a reply in the queue. If more data continues to
arrive on the stream, the abort command could mistakenly get
signalled as complete. Remove the code from async data processing
that looked for waiting calls. Add a sanity check to ensure no
async call can ever be marked as needing a reply

* src/rpc/virnetclient.c: Ensure async data packets can't
  trigger a reply
2011-08-17 09:44:12 -07:00
Tom Vijlbrief
108ca33357 qemu: disk migration verbose progress
A virsh command like:

migrate --live --copy-storage-all Guest qemu+ssh://user@host/system
--persistent --verbose

shows

Migration: [  0 %]

during the storage copy and does not start counting
until the ram transfer starts

Fix this by scraping optional disk transfer status, and adding it
into the progress meter.
2011-08-17 08:01:12 -06:00
Osier Yang
2ce90ea296 qemu: Init reattaching related members of pciDevice before reattach
Otherwise the device will still be bound to pci-stub driver even
it's set as "managed=yes" when do detaching. Of course, it won't
triger any driver reprobing too.
2011-08-17 20:58:33 +08:00
Daniel P. Berrange
d48a0597e3 Tweak debugging message in RPC client code
Make it clearer that a log message is for an outgoing message
2011-08-16 14:38:11 -07:00
Daniel P. Berrange
b4633113fc Fix race condition in abort of stream
If a stream gets a server initiated abort, the client may still
send an abort request before it receives the server side abort.
This causes the server to send back another abort for the
stream. Since the protocol defines that abort is the last thing
to be sent, the client gets confused by this second abort from
the server. If the stream is already shutdown, just drop any
client requested abort, rather than sending back another message.
This fixes the regression from previous versions.

Tested as follows

In one virsh session

  virsh # start foo
  virsh # console foo

In other virsh session

  virsh # destroy foo

The first virsh session should be able to continue issuing
commands without error. Prior to this patch it saw

  virsh # list
  error: Failed to list active domains
  error: An error occurred, but the cause is unknown

  virsh # list
  error: Failed to list active domains
  error: no call waiting for reply with prog 536903814 vers 1 serial 9

* src/rpc/virnetserverprogram.c: Drop abort requests
  for streams which no longer exist
2011-08-16 14:38:11 -07:00
Daniel P. Berrange
f682c25308 Ensure client streams are closed when marking a client for close
Every active stream results in a reference being held on the
virNetServerClientPtr object. This meant that if a client quit
with any streams active, although all I/O was stopped the
virNetServerClientPtr object would leak. This causes libvirtd
to leak any file handles associated with open streams when a
client quit

To fix this, when we call virNetServerClientClose there is a
callback invoked which lets the daemon release the streams
and thus the extra references

* daemon/remote.c: Add a hook to close all streams
* daemon/stream.c, daemon/stream.h: Add API for releasing
  all streams
* src/rpc/virnetserverclient.c, src/rpc/virnetserverclient.h:
  Allow registration of a hook to trigger when closing client
2011-08-16 14:38:11 -07:00
Stefan Berger
57c7b40b76 maint: fix some compilation issues on non-linux platforms (part 2)
Get rid of the #if __linux__ check in virPidFileReadPathIfAlive that
was preventing a check of a symbolic link in /proc/<pid>/exe on
non-linux platforms against an expected executable. Replace
this with a run-time check testing whether the /proc/<pid>/exe is a
symbolic link and if so call the function doing the comparison
against the expected file the link is supposed to point to.
2011-08-16 15:36:22 -04:00
Stefan Berger
f4765b691d maint: fix some compilation issues on non-linux platforms
This patch fixes *some* compilation issues on non-Linux platforms (cygwin).
2011-08-16 13:54:15 -04:00
Stefan Berger
34a01fc431 maint: add missing symbols
Add missing symbols to libvirt_private.syms.
2011-08-16 12:38:02 -04:00
Roopa Prabhu
5abbf7b958 macvtap: Fix getPhysfn to get the PF of a direct attach network interface
This patch renames getPhysfn to getPhysfnDev and adds code to get the
Physical function and Virtual Function index of the direct attach linkdev (if
the direct attach interface is a SRIOV VF). The idea is to send the port
profile message to a PF if the direct attach interface is a SRIOV VF.

Signed-off-by: Roopa Prabhu <roprabhu@cisco.com>
Signed-off-by: Christian Benvenuti <benve@cisco.com>
Signed-off-by: David Wang <dwang2@cisco.com>
2011-08-16 11:59:00 -04:00
Roopa Prabhu
cd5544d412 interface: Add functions to get sriov PF/VF relationship of a net interface
This patch adds the following functions to get PF/VF relationship of an SRIOV
network interface:
ifaceIsVirtualFunction: Function to check if a network interface is a SRIOV VF
ifaceGetVirtualFunctionIndex: Function to get VF index if a network interface is a SRIOV VF
ifaceGetPhysicalFunction: Function to get the PF net interface name of a SRIOV VF net interface

Signed-off-by: Roopa Prabhu <roprabhu@cisco.com>
Signed-off-by: Christian Benvenuti <benve@cisco.com>
Signed-off-by: David Wang <dwang2@cisco.com>
2011-08-16 11:59:00 -04:00
Roopa Prabhu
17d64cab16 pci: Add helper functions for sriov devices
This patch adds the following helper functions:
pciDeviceIsVirtualFunction: Function to check if a pci device is a sriov VF
pciGetVirtualFunctionIndex: Function to get the VF index of a sriov VF
pciDeviceNetName: Function to get the network device name of a pci device
pciConfigAddressCompare: Function to compare pci config addresses

Signed-off-by: Roopa Prabhu <roprabhu@cisco.com>
Signed-off-by: Christian Benvenuti <benve@cisco.com>
Signed-off-by: David Wang <dwang2@cisco.com>
Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2011-08-16 11:59:00 -04:00
Roopa Prabhu
03172265d3 pci: Move some pci sriov helper code out of node device driver to util/pci
This patch moves some of the sriov related pci code from node_device driver
to src/util/pci.[ch]. Some functions had to go thru name and argument list
change to accommodate the move.

Signed-off-by: Roopa Prabhu <roprabhu@cisco.com>
Signed-off-by: Christian Benvenuti <benve@cisco.com>
Signed-off-by: David Wang <dwang2@cisco.com>
2011-08-16 11:59:00 -04:00
Laine Stump
73c0a148af qemu: support event_idx parameter for virtio disk and net devices
In some versions of qemu, both virtio-blk-pci and virtio-net-pci
devices can have an event_idx setting that determines some details of
event processing. When it is enabled, it "reduces the number of
interrupts and exits for the guest". qemu will automatically enable
this feature when it is available, but there may be cases where this
new feature could actually make performance worse (NB: no such case
has been found so far).

As a safety switch in case such a situation is encountered in the
field, this patch adds a new attribute "event_idx" to the <driver>
element of both disk and interface devices. event_idx can be set to
"on" (to force event_idx on in case qemu has it disabled by default)
or "off" (for force event_idx off). In the case that event_idx support
isn't present in qemu, the attribute is ignored (this on the advice of
the qemu developer).

docs/formatdomain.html.in: document the new flag (marking it as
   "don't mess with this!"
docs/schemas/domain.rng: add event_idx in appropriate places
src/conf/domain_conf.[ch]: add event_idx to parser and formatter
src/libvirt_private.syms: export
   virDomainVirtioEventIdx(From|To)String
src/qemu/qemu_capabilities.[ch]: detect and report event_idx in
   disk/net
src/qemu/qemu_command.c: add event_idx parameter to qemu commandline
    when appropriate.
tests/qemuxml2argvdata/qemuxml2argv-event_idx.args,
tests/qemuxml2argvdata/qemuxml2argv-event_idx.xml,
tests/qemuxml2argvtest.c,
tests/qemuxml2xmltest.c: test cases for event_idx.
2011-08-15 09:35:42 -04:00
Peter Krempa
d17101e011 qemu: error message should show uri instead of (null)
Fix pointer for error message uri if domain migration fails.

BZ# 730244
2011-08-15 15:30:03 +02:00
Jiri Denemark
3261761794 qemu: Use fd: protocol for migration
By opening a connection to remote qemu process ourselves and passing the
socket to qemu we get much better errors than just "migration failed"
when the connection is opened by qemu.
2011-08-15 15:21:31 +02:00
Jiri Denemark
e8989ae4e2 qemu: Use virNetSocket for tunneled migration 2011-08-15 15:21:31 +02:00
Jiri Denemark
52e2918ae1 qemu: Refactor do{Tunnel,Native}Migrate functions
The core of these two functions is very similar and most of it is even
exactly the same. Factor out the core functionality into a separate
function to remove code duplication and make further changes easier.
2011-08-15 15:21:31 +02:00
Jiri Denemark
5d30db09a6 Support changing UNIX socket owner in virNetSocketNewListenUNIX
This patch allows owner's UID to be changed as well.
2011-08-15 15:21:31 +02:00
Jiri Denemark
70e4295bc4 Add backlog parameter to virNetSocketListen
So that callers can change the default value.
2011-08-15 15:21:31 +02:00
Daniel P. Berrange
f4287c7676 Add API for duplicating a socket/client file descriptor
* src/rpc/virnetsocket.c, src/rpc/virnetsocket.h: Add
  virNetSocketDupFD()
* src/rpc/virnetclient.c, src/rpc/virnetclient.h: Add
  virNetClientDupFD() and virNetClientGetFD()
2011-08-15 15:21:26 +02:00
Philipp Hahn
24d3738f2d Swap virDomain / virFomainSnapshot declaration
In preparation for storing the domain description with the snapshot,
swap the order of declaration.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2011-08-12 16:17:28 -06:00
Eric Blake
be427e8b0b build: fix recent build failures
With gcc 4.5.1:

util/virpidfile.c: In function 'virPidFileAcquirePath':
util/virpidfile.c:308:66: error: nested extern declaration of '_gl_verify_function2' [-Wnested-externs]

Then in tests/commandtest.c, the new virPidFile APIs need to be used.

* src/util/virpidfile.c (virPidFileAcquirePath): Move verify to
top level.
* tests/commandtest.c: Use new pid APIs.
2011-08-12 16:16:29 -06:00
Daniel P. Berrange
e1da464d88 Add some APIs which use locking for crashsafe pidfile handling
In daemons using pidfiles to protect against concurrent
execution there is a possibility that a crash may leave a stale
pidfile on disk, which then prevents later restart of the daemon.

To avoid this problem, introduce a pair of APIs which make
use of virFileLock to ensure crash-safe & race condition-safe
pidfile acquisition & releae

* src/libvirt_private.syms, src/util/virpidfile.c,
  src/util/virpidfile.h: Add virPidFileAcquire and virPidFileRelease
2011-08-12 20:37:00 +01:00
Daniel P. Berrange
b7e5ca48f8 Introduce functions for checking whether a pidfile is valid
In some cases the caller of virPidFileRead might like extra checks
to determine whether the pid just read is really the one they are
expecting. This adds virPidFileReadIfAlive which will check whether
the pid is still alive with kill(0, -1), and (on linux only) will
look at /proc/$PID/path

* libvirt_private.syms, util/virpidfile.c, util/virpidfile.h: Add
  virPidFileReadIfValid and virPidFileReadPathIfValid
* network/bridge_driver.c: Use new APIs to check PID validity
2011-08-12 20:37:00 +01:00
Daniel P. Berrange
f80a4ed77a Move pidfile functions into util/virpidfile.{c,h}
The functions for manipulating pidfiles are in util/util.{c,h}.
We will shortly be adding some further pidfile related functions.
To avoid further growing util.c, this moves the pidfile related
functions into a dedicated virpidfile.{c,h}. The functions are
also all renamed to have 'virPidFile' as their name prefix

* util/util.h, util/util.c: Remove all pidfile code
* util/virpidfile.c, util/virpidfile.h: Add new APIs for pidfile
  handling.
* lxc/lxc_controller.c, lxc/lxc_driver.c, network/bridge_driver.c,
  qemu/qemu_process.c: Add virpidfile.h include and adapt for API
  renames
2011-08-12 20:37:00 +01:00
Daniel P. Berrange
e48427051d Add virFileLock and virFileUnlock APIs
Add some simple wrappers around the fcntl() discretionary file
locking capability.

* src/util/util.c, src/util/util.h, src/libvirt_private.syms: Add
  virFileLock and virFileUnlock APIs
2011-08-12 20:37:00 +01:00
Eric Blake
cfe35a88f0 vbox, xenapi: add virDomainUndefineFlags
We forgot to add virDomainUndefineFlags for a couple of hypervisors.
This wires up trivial versions (since neither hypervisor supports
managed save yet, they do not need to support any flags).

* src/vbox/vbox_tmpl.c (vboxDomainCreateXML): Update caller.
(vboxDomainUndefine): Move guts...
(vboxDomainUndefineFlags): ...to new function.
* src/xenapi/xenapi_driver.c (xenapiDomainUndefine)
(xenapiDomainUndefineFlags): Likewise.
2011-08-12 07:44:54 -06:00
Peter Krempa
6c55124f37 storage: Directory shouldn't be listed as type 'file'
Fix internals of libvirt for new storage volume type.
Libvirt reported an invalid type of the volume.

BZ #727088
2011-08-11 13:34:26 -06:00
Eric Blake
398ce48d5c qemu: silence clang false positive
Our logic throws off analyzer tools:

ptr var = NULL;
if (flags == 0) flags = live ? _LIVE : _CONFIG;
if (flags & _LIVE) do stuff
if (flags & _CONFIG) var = non-null;
if (flags & _LIVE) do more stuff
else if (flags & _CONFIG) use var

the tools keep thinking that var can still be NULL in the last
if clause, adding the hint shuts them up.

* src/qemu/qemu_driver.c (qemuDomainSetBlkioParameters): Add a
static analysis hint.
2011-08-11 13:04:25 -06:00