Commit Graph

3992 Commits

Author SHA1 Message Date
Guido Günther
50a7c59bb3 OpenVZ: take veid from vmdef->name when defining new domains
We currently use the next free veid although there's one given in the
domain xml. This currently breaks defining new domains since vmdef->name
and veid don't match leading to the following error later on:

    error: Failed to define domain from 110.xml
    error: internal error Could not set UUID

Since silently ignoring vmdef->name is not nice respect it instead. We
avoid veid collisions in the upper levels already.
2010-11-30 17:20:02 +01:00
Matthias Bolte
abff683f78 Log client errors in libvirtd at debug priority
This reverts commit

 Log all errors at level INFO to stop polluting syslog
 04bd0360f3.

and makes virRaiseErrorFull() log errors at debug priority
when called from inside libvirtd. This stops libvirtd from
polluting it's own log with client errors at error priority
that'll be reported and logged on the client side anyway.
2010-11-30 15:52:30 +01:00
Wen Congyang
4f7162d106 correct the arguments of migrate_speed
When we set migrate_speed by json, we receive the following
error message:
libvirtError: internal error unable to execute QEMU command
'migrate_set_speed': Invalid parameter type, expected: number

The reason is that: the arguments of migrate_set_speed
by json is json number, not json string.

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
2010-11-29 15:11:03 -07:00
Daniel P. Berrange
6aff3f2091 Fix memory leaks in audit & VirtualBox code
* src/util/virtaudit.c: Free audit string
* src/vbox/vbox_XPCOMCGlue.c: Free library name
2010-11-29 15:17:16 +00:00
Jiri Denemark
ac9dd4a676 Fix host CPU counting on unusual NUMA topologies
The nodeinfo structure includes

    nodes   : the number of NUMA cell, 1 for uniform mem access
    sockets : number of CPU socket per node
    cores   : number of core per socket
    threads : number of threads per core

which does not work well for NUMA topologies where each node does not
consist of integral number of CPU sockets.

We also have VIR_NODEINFO_MAXCPUS macro in public libvirt.h which
computes maximum number of CPUs as (nodes * sockets * cores * threads).

As a result, we can't just change sockets to report total number of
sockets instead of sockets per node. This would probably be the easiest
since I doubt anyone is using the field directly. But because of the
macro, some apps might be using sockets indirectly.

This patch leaves sockets to be the number of CPU sockets per node (and
fixes qemu driver to comply with this) on machines where sockets can be
divided by nodes. If we can't divide sockets by nodes, we behave as if
there was just one NUMA node containing all sockets. Apps interested in
NUMA should consult capabilities XML, which is what they probably do
anyway.

This way, the only case in which apps that care about NUMA may break is
on machines with funky NUMA topology. And there is a chance libvirt
wasn't able to start any guests on those machines anyway (although it
depends on the topology, total number of CPUs and kernel version).
Nothing changes at all for apps that don't care about NUMA.
2010-11-25 10:49:47 +01:00
Eric Blake
d95488dce5 security, storage: plug memory leaks for security_context_t
security_context_t happens to be a typedef for char*, and happens to
begin with a string usable as a raw context string.  But in reality,
it is an opaque type that may or may not have additional information
after the first NUL byte, where that additional information can
include pointers that can only be freed via freecon().

Proof is from this valgrind run of daemon/libvirtd:

==6028== 839,169 (40 direct, 839,129 indirect) bytes in 1 blocks are definitely lost in loss record 274 of 274
==6028==    at 0x4A0515D: malloc (vg_replace_malloc.c:195)
==6028==    by 0x3022E0D48C: selabel_open (label.c:165)
==6028==    by 0x3022E11646: matchpathcon_init_prefix (matchpathcon.c:296)
==6028==    by 0x3022E1190D: matchpathcon (matchpathcon.c:317)
==6028==    by 0x4F9D842: SELinuxRestoreSecurityFileLabel (security_selinux.c:382)

800k is a lot of memory to be leaking.

* src/storage/storage_backend.c
(virStorageBackendUpdateVolTargetInfoFD): Avoid leak on error.
* src/security/security_selinux.c
(SELinuxReserveSecurityLabel, SELinuxGetSecurityProcessLabel)
(SELinuxRestoreSecurityFileLabel): Use correct function to free
security_context_t.
2010-11-24 15:23:43 -07:00
Eric Blake
d90babe961 network: plug memory leak
* src/conf/network_conf.c (virNetworkDHCPRangeDefParseXML): Free
xml strings when no longer referenced.
2010-11-24 15:23:43 -07:00
Eric Blake
416c09bcc0 maint: prohibit most uses of xmlGetProp
Making this change makes it easier to spot the memory leaks
that will be fixed in the next patch.

* cfg.mk (sc_prohibit_xmlGetProp): New rule.
* .x-sc_prohibit_xmlGetProp: New exception.
* Makefile.am (EXTRA_DIST): Ship exception file.
* tools/virsh.c (cmdDetachInterface, cmdDetachDisk): Adjust
offenders.
* src/conf/storage_conf.c (virStoragePoolDefParseSource):
Likewise.
* src/conf/network_conf.c (virNetworkDHCPRangeDefParseXML)
(virNetworkIPParseXML): Likewise.
2010-11-24 15:23:43 -07:00
Eric Blake
117246e0f7 qemu: plug memory leak
https://bugzilla.redhat.com/show_bug.cgi?id=656795

* src/qemu/qemu_monitor.c (qemuMonitorFree): Also free the buffer.
2010-11-24 15:23:43 -07:00
Eric Blake
f1fe9671e3 build: enforce files.h usage
* cfg.mk (sc_prohibit_close): New syntax-check rule.
* src/util/pci.c (pciWaitForDeviceCleanup): Fix violation.
* .x-sc_prohibit_close: New exceptions.
* Makefile.am (EXTRA_DIST): Distribute new file.
2010-11-24 15:23:43 -07:00
Matthias Bolte
d8b367496e Always close drivers when a virConnectPtr is released
virConnectClose calls virUnrefConnect which in turn closes
all open drivers when the refcount of that connection dropped
to zero. This works fine when you free all other objects that
hold a ref to the connection before you close it, because in
this case virUnrefConnect is the one that removes the last
ref to the connection.

But it doesn't work when you close the connection first before
freeing the other objects. This is because the other virUnref*
functions call virReleaseConnect when they detect that the
connection's refcount dropped to zero. In this case another
virUnref* function (different from virUnrefConnect) removes the
last ref to the connection. This results in not closing the
open drivers and leaking things that should have been cleaned
up in the driver close functions.

To fix this move the driver close calls to virReleaseConnect.
2010-11-24 22:48:36 +01:00
Osier Yang
f3605b33a1 Implementations of virDomainIsUpdated for drivers except qemu
Except LXC and UML driver, implementations of all other drivers
simply return 0, because these drivers doesn't have config both
in memory and on disk, no need to track if the domain of these
drivers updated or not.

Rename "xenUnifiedDomainisPersistent" to "xenUnifiedDomainIsPersistent"

* esx/esx_driver.c
* lxc/lxc_driver.c
* opennebula/one_driver.c
* openvz/openvz_driver.c
* phyp/phyp_driver.c
* test/test_driver.c
* uml/uml_driver.c
* vbox/vbox_tmpl.c
* xen/xen_driver.c
* xenapi/xenapi_driver.c
2010-11-24 11:22:30 -07:00
Osier Yang
c1fb916618 implement callback function for qemu driver
* src/qemu/qemu_driver.c (add function qemuDomainIsUpdated)
2010-11-23 15:04:42 -07:00
Osier Yang
313215e15f implement the remote protocol
* daemon/remote.c
* daemon/remote_dispatch_args.h
* daemon/remote_dispatch_prototypes.h
* daemon/remote_dispatch_ret.h
* daemon/remote_dispatch_table.h
* src/remote/remote_driver.c
* src/remote/remote_protocol.c
* src/remote/remote_protocol.h
* src/remote/remote_protocol.x
* src/remote_protocol-structs
2010-11-23 15:04:42 -07:00
Osier Yang
20a017df68 implement public API virDomainIsUpdated
* src/libvirt.c
2010-11-23 15:04:41 -07:00
Osier Yang
37a02efd71 define internal driver API
* src/driver.h (new typedef, new callback member for "_virDriver")
* src/esx/esx_driver.c
* src/lxc/lxc_driver.c
* src/opennebula/one_driver.c
* src/openvz/openvz_driver.c
* src/phyp/phyp_driver.c
* src/qemu/qemu_driver.c
* src/remote/remote_driver.c
* src/test/test_driver.c
* src/uml/uml_driver.c
* src/vbox/vbox_tmpl.c
* src/xen/xen_driver.c
* src/xenapi/xenapi_driver.c
2010-11-23 15:04:41 -07:00
Osier Yang
347d73f211 virDomainIsUpdated: define the new public API
introduce new public API "virDomainIsUpdated"

* src/conf/domain_conf.h (new member "updated" for "virDomainObj")
* src/libvirt_public.syms
* include/libvirt/libvirt.h.in
2010-11-23 14:22:31 -07:00
Eric Blake
2ed149a6d0 maint: sort exports
* src/libvirt_private.syms (buf.h): Sort.
2010-11-23 14:05:20 -07:00
Matthias Bolte
9abe1e4358 remote: Fix TLS transport on Windows
gnulib wraps Windows' SOCKET handle based send() and recv() functions
into file descriptor based ones that are used in libvirt.

Even though GnuTLS is using gnulib too, it explicitly doesn't use
gnulib's replacement functions on Windows. By default GnuTLS uses the
SOCKET handle based send() and recv(). This makes gnutls_handshake()
fail internally with a WSAENOTSOCK error because libvirt passes a
file descriptor; GnuTLS needs the SOCKET handle.

To avoid this mismatch make sure that GnuTLS uses gnulib's replacment
functions, by setting custom pull() and push() functions for GnuTLS.
2010-11-23 18:31:42 +01:00
Daniel P. Berrange
c73bd6f34a Rename 'remove' param to 'toremove' to avoid clash with stdio.h
The stdio.h header has a function called 'remove' declared. This
clashes with the 'remove' parameter in virShrinkN

* src/util/memory.c: Rename 'remove' to 'toremove'
2010-11-23 15:19:35 +00:00
Daniel P. Berrange
f86c7801e9 Fix 32-bit int truncation in QED header check
* src/util/memory.c: Avoid 32-bit truncation extracting a 64bit int
2010-11-23 15:18:03 +00:00
Daniel P. Berrange
174d737d95 Improve SCSI volume name generation
The SCSI volumes currently get a name like '17:0:0:1' based
on $host:$bus:$target:$lun. The names are intended to be unique
per pool and stable across pool restarts. The inclusion of the
$host component breaks this, because the $host number for iSCSI
pools is dynamically allocated by the kernel at time of login.
This changes the name to be 'unit:0:0:1', ie removes the leading
host component. The 'unit:' prefix is just to ensure the volume
name doesn't start with a number and make it clearer when seen
out of context.

* src/storage/storage_backend_scsi.c: Improve volume name
  field value stability and uniqueness
2010-11-23 15:00:35 +00:00
Daniel P. Berrange
e4c97a10db Fix error codes returned when a storage pool is inactive
Many operations are not valid on inactive storage pools. The
storage driver is currently returning VIR_ERR_INTERNAL_ERROR
in these cases, rather than the more suitable error code
VIR_ERR_OPERATION_INVALID

* src/storage/storage_driver.c: Fix error code when pool
  is not active
2010-11-23 15:00:35 +00:00
Daniel P. Berrange
1b7e0b1a9c Check whether pools are already active upon libvirtd startup
When libvirt starts up all storage pools default to the inactive
state, even if the underlying storage is already active on the
host. This introduces a new API into the internal storage backend
drivers that checks whether a storage pool is already active. If
the pool is active at libvirtd startup, the volume list will be
immediately populated.

* src/storage/storage_backend.h: New internal API for checking
  storage pool state
* src/storage/storage_driver.c: Check whether a pool is active
  upon driver startup
* src/storage/storage_backend_fs.c, src/storage/storage_backend_iscsi.c,
  src/storage/storage_backend_logical.c, src/storage/storage_backend_mpath.c,
  src/storage/storage_backend_scsi.c: Add checks for pool state
2010-11-23 15:00:35 +00:00
Daniel P. Berrange
1da8c5672f Add support for iSCSI target auto-discovery
Since the previous patch added support for parsing the output of
the 'sendtargets' command, it is now trivial to support the
storage pool discovery API.

Given a hostname and optional portnumber and initiator IQN,
the code can return a full list of storage pool source docs,
each one representing a iSCSI target.

* src/storage/storage_backend_iscsi.c: Wire up target
  auto-discovery
2010-11-23 15:00:29 +00:00
Daniel P. Berrange
3c12b6542c Stop iSCSI targets automatically logging back in after logout
The Linux iSCSI initiator toolchain has the dubious feature that
if you ever run the 'sendtargets' command to merely query what
targets are available from a server, the results will be recorded
in /var/lib/iscsi. Any time the '/etc/init.d/iscsi' script runs
in the future, it will then automatically login to all those
targets. /etc/init.d/iscsi is automatically run whenever a NIC
comes online.

So from the moment you ask a server what targets are available,
your client will forever more automatically try to login to all
targets without ever asking if you actually want it todo this.

To stop this stupid behaviour, we need to run

  iscsiadm --portal $PORTAL --target $TARGET
   --op update --name node.startup --value manual

For every target on the server.

* src/storage/storage_backend_iscsi.c: Disable automatic login
  for targets found as a result of a 'sendtargets' command
2010-11-23 14:55:45 +00:00
Daniel P. Berrange
59446096ff Refactor iSCSI driver code to facilitate future changes
The following series of patches are adding significant
extra functionality to the iSCSI driver. THe current
internal helper methods are not sufficiently flexible
to cope with these changes. This patch refactors the
code to avoid needing to have a virStoragePoolObjPtr
instance as a parameter, instead passing individual
target, portal and initiatoriqn parameters.

It also removes hardcoding of port 3260 in the portal
address, instead using the XML value if any.

* src/storage/storage_backend_iscsi.c: Refactor internal
  helper methods
2010-11-23 14:55:38 +00:00
Daniel P. Berrange
b6e5a0a26e Fix parsing of port attribute in storage XML configuration
The XML docs describe a 'port' attribute for the
storage source <host> element, but the parser never
handled it.

* docs/schemas/storagepool.rng: Define port attribute
* src/conf/storage_conf.c: Add missing parsing/formatting
  of host port number
* src/conf/storage_conf.h: Remove bogus/unused 'protocol' field
2010-11-23 14:55:33 +00:00
Daniel P. Berrange
7f9cebc0c0 Ensure logfile isn't truncated by shutdown message.
When running non-root, the QEMU log file is usually opened with
truncation, since there is no logrotate for non-root usage.
This means that when libvirt logs the shutdown timestamp, the
log is accidentally truncated

* src/qemu/qemu_driver.c: Never truncate log file with shutdown
  message
2010-11-23 14:10:05 +00:00
Daniel P. Berrange
dbf405bf04 Remove trailing ':' from timestamp
The QEMU logger appends a ':' to the timestamp when it deems
it neccessary, so the virTimestamp API should not duplicate
this

* src/util/util.c: Remove trailing ':' from timestamp
2010-11-23 14:09:58 +00:00
Daniel P. Berrange
04bd0360f3 Log all errors at level INFO to stop polluting syslog
Everytime a public API returns an error, libvirtd pollutes
syslog with that error message. Reduce the error logging
level to INFO so these don't appear by default.

* src/util/virterror.c: Log all errors at INFO
2010-11-23 14:09:52 +00:00
Daniel P. Berrange
882f78c3cb Ensure virExec preserves logging environment
The virFork call resets all logging handlers that may have been
set. Re-enable them after fork in virExec, so that env variables
fir LIBVIRT_LOG_OUTPUTS and LIBVIRT_LOG_FILTERS take effect
until the execve()

* src/util/util.c: Preserve logging in child in virExec
2010-11-23 14:09:46 +00:00
Daniel P. Berrange
9288c31bf7 Include a thread identifier in log messages
To allow messages from different threads to be untangled,
include an integer thread identifier in log messages.

* src/util/logging.c: Include thread ID
* src/util/threads.h, src/util/threads.h, src/util/threads-pthread.c:
  Add new virThreadSelfID() function
* configure.ac: Check for sys/syscall.h
2010-11-23 14:09:35 +00:00
Cole Robinson
388fa6257e qemu: setvcpus: Save config changes to disk
Currently changes to the persistent config aren't flushed to disk, meaning
they are lost if the domain is redefined or libvirtd is restarted.
2010-11-23 08:42:46 -05:00
Cole Robinson
39b6265476 qemu: setvcpus: Simplify altering the persistent config
Do this by adding a helper function to get the persistent domain config. This
should be useful for other functions that may eventually want to alter
the persistent domain config (attach/detach device). Also make similar changes
to the test drivers setvcpus command.

A caveat is that the function will return the running config for a transient
domain, rather than error. This simplifies callers, as long as they use
other methods to ensure the guest is persistent.
2010-11-23 08:42:46 -05:00
Cole Robinson
d75202915e qemu: setvcpus: Fix maxvcpus check
Doing 'virsh setvcpus $vm --config 10' doesn't check the value against the
domains maxvcpus value. A larger value for example will prevent the guest
from starting.

Also make a similar change to the test driver.
2010-11-23 08:42:46 -05:00
Cole Robinson
81e6f68d0e conf: domain: Improve vcpus validation reporting 2010-11-23 08:42:45 -05:00
Cole Robinson
45ec297d6f Make state driver device hotplug/update actually transient
The current semantics of non-persistent hotplug/update are confusing: the
changes will persist as long as the in memory domain definition isn't
overwritten. This means hotplug changes stay around until the domain is
redefined or libvirtd is restarted.

Call virDomainObjSetDefTransient at VM startup, so that we properly discard
hotplug changes when the VM is shutdown.
2010-11-23 08:42:45 -05:00
Cole Robinson
08a72a7d89 domain_conf: Add virDomainObjSetDefTransient
This function sets the running domain definition as transient, by reparsing
the persistent config and assigning it to newDef. This ensures that any
changes made to the running definition and not the persistent config are
discarded when the VM is shutdown.
2010-11-23 08:42:44 -05:00
Cole Robinson
3afe5d402b xend: Escape reserved sexpr characters
If we don't escape ' or \ xend can't parse the generated sexpr. This
might over apply the EscapeSexpr routine, but it shouldn't hurt.
2010-11-22 16:43:29 -05:00
Cole Robinson
0af02cb2e8 buf: Simplify virBufferEscapeString
We are about to copy this function, so clean it up before we do.
2010-11-22 16:37:21 -05:00
Cole Robinson
c8b2a23c02 xend: urlencode: Properly escape '&'
Since we send the sexpr to xend via HTTP, we need to properly escape
'&'
2010-11-22 16:37:21 -05:00
Cole Robinson
21108d37a3 conf: Fix parsing python style triple quotes
An incorrect check broke matching the closing set of quotes. Update
tests to cover this case for XM config files.
2010-11-22 16:37:21 -05:00
Cole Robinson
f57c0b23a8 conf: Convert ParseString to use STRPREFIX 2010-11-22 16:37:21 -05:00
Adam Litke
a76234f31c qed: Minor updates to QED support patches
This patch makes two corrections to the newly-added QED support patch series:

 - Correct the QED header field offsets
 - Remove XML parsing for VIR_STORAGE_FILE_AUTO_SAFE

Signed-off-by: Adam Litke <agl@us.ibm.com>
2010-11-22 13:21:35 -07:00
Stefan Berger
52834904d2 nwfilter: re-order lock grabbed by IP addr. learn thread
The IP address learning thread was causing a deadlock when it instantiated a filter while a filter update/change was ongoing. The reason for this was the ordering of locks due to the following calls

virNWFilterUnlockFilterUpdates()
virNWFilterPoolObjFindByName()

The below patch now puts the order of the locks in the above shown order when instantiating the filter from the IP address learning thread.
2010-11-19 20:41:25 -05:00
Adam Litke
c9f48f4e50 Support for probing qed image metadata
Implement getBackingStore() for QED images.  The header format is defined in
the QED spec: http://wiki.qemu.org/Features/QED .

Signed-off-by: Adam Litke <agl@us.ibm.com>
Cc: Stefan Hajnoczi <stefan.hajnoczi@uk.ibm.com>
Cc: Anthony Liguori <aliguori@linux.vnet.ibm.com>
2010-11-19 16:27:34 -07:00
Adam Litke
fd93d46642 storage_file: Add a new flag to mark backing files that are safe to probe
Signed-off-by: Adam Litke <agl@us.ibm.com>
2010-11-19 16:07:06 -07:00
Adam Litke
5dca07e272 QED: Basic support for QED images
Add an entry in fileTypeInfo for QED image files.

Signed-off-by: Adam Litke <agl@us.ibm.com>
Cc: Stefan Hajnoczi <stefan.hajnoczi@uk.ibm.com>
Cc: Anthony Liguori <aliguori@linux.vnet.ibm.com>
2010-11-19 16:05:44 -07:00
Adam Litke
5a2a474ee8 Allow probing of image formats without version information
Disk image formats that wish to opt-out of version validation are supposed to
set versionOffset to -1 in their fileTypeInfo entry.

By unconditionally returning False for these formats,
virStorageFileMatchesVersion() incorrectly reports a version mismatch when the
test was actually skipped.  The correct behavior is to return True so these
formats can be successfully probed using the magic bytes alone.

Signed-off-by: Adam Litke <agl@us.ibm.com>
2010-11-19 15:55:02 -07:00
Daniel P. Berrange
dec720aa93 virExec: fix bug in setting up child stderr/out with /dev/null 2010-11-18 12:21:58 -07:00
Eric Blake
aca20efbf8 capabilities, cpu: use new array API
* src/conf/capabilities.h (_virCaps, _virCapsHost, _virCapsGuest)
(_virCapsGuestArch): Add additional fields.
* src/conf/cpu_conf.h (_virCPUDef): Likewise.
* src/conf/capabilities.c (virCapabilitiesFormatXML): Reflect
updated type.
(virCapabilitiesAddGuest, virCapabilitiesAddHostFeature)
(virCapabilitiesAddHostMigrateTransport)
(virCapabilitiesAddHostNUMACell, virCapabilitiesAddGuestFeature)
(virCapabilitiesAddGuestDomain): Use new array APIs.
* src/conf/cpu_conf.c (virCPUDefAddFeature, virCPUDefCopy)
(virCPUDefParseXML): Likewise.
* tests/testutilsqemu.c (testQemuCapsInit): Adjust test.
2010-11-18 12:21:58 -07:00
Eric Blake
269d3b72f6 memory: make it easier to avoid quadratic scaling of arrays
* src/util/memory.h (VIR_RESIZE_N): New macro.
* src/util/memory.c (virResizeN): New function.
* src/libvirt_private.syms: Export new helper.
* docs/hacking.html.in: Document it.
* HACKING: Regenerate.
2010-11-18 12:17:49 -07:00
Eric Blake
5a0beacc12 memory: make it safer to expand arrays
* src/util/memory.h (VIR_REALLOC_N): Update docs.
(VIR_EXPAND_N, VIR_SHRINK_N): New macros.
(virAlloc, virAllocN, virReallocN, virAllocVar, virFree): Add some
gcc attributes.
* src/util/memory.c (virExpandN, virShrinkN): New functions.
(virReallocN): Update docs.
* src/libvirt_private.syms: Export new helpers.
* docs/hacking.html.in: Prefer newer interfaces over
VIR_REALLOC_N, since uninitialized memory can bite us.
* HACKING: Regenerate.
2010-11-18 12:11:43 -07:00
Daniel Veillard
83fa118458 Fix a failure to restore SELinux label for character devices
The code in SELinuxRestoreSecurityChardevLabel() was trying to
use SELinuxSetFilecon directly for devices or file types while
it should really use SELinuxRestoreSecurityFileLabel encapsulating
routine, which avoid various problems like resolving symlinks,
making sure he file exists and work around NFS problems
2010-11-18 17:55:14 +01:00
Matthias Bolte
c505eafeda virt-aa-helper: Fix several compile errors
Include locale.h for setlocale().

Revert the usage string back to it's original form.

Use puts() instead of fputs(), as fputs() expects a FILE*.

Add closing parenthesis to some vah_error() calls.

Use argv[0] instead of an undefined argv0.
2010-11-17 21:36:27 +01:00
Eric Blake
e8aba782e7 maint: avoid remaining sprintf uses
* cfg.mk (sc_prohibit_sprintf): New rule.
(sc_prohibit_asprintf): Avoid false positives.
* docs/hacking.html.in (Printf-style functions): Document the
policy.
* HACKING: Regenerate.
* .x-sc_prohibit_sprintf: New exemptions.
* Makefile.am (syntax_check_exceptions): Ship new file.
* src/vbox/vbox_tmpl.c (vboxStartMachine, vboxAttachUSB): Use
virAsprintf instead.
* src/uml/uml_driver.c (umlOpenMonitor): Use snprintf instead.
* tools/virsh.c (cmdDetachInterface): Likewise.
* src/security/security_selinux.c (SELinuxGenSecurityLabel):
Likewise.
* src/openvz/openvz_driver.c (openvzDomainDefineCmd): Likewise,
and ensure large enough buffer.
2010-11-17 10:13:12 -07:00
Eric Blake
c811d46fab virt-aa-helper: translate error messages
These messages are visible to the user, so they should be
consistently translated.

* cfg.mk (msg_gen_function): Add vah_error, vah_warning.
* src/security/virt-aa-helper.c: Translate messages.
(catchXMLError): Fix capitalization.
2010-11-17 10:13:12 -07:00
Eric Blake
981d2cdab4 maint: improve i18n on non-Linux
Per the gettext developer:
http://lists.gnu.org/archive/html/bug-gnu-utils/2010-10/msg00019.html
http://lists.gnu.org/archive/html/bug-gnu-utils/2010-10/msg00021.html

gettext() doesn't work correctly on all platforms unless you have
called setlocale().  Furthermore, gnulib's gettext.h has provisions
for setting up a default locale, which is the preferred method for
libraries to use gettext without having to call textdomain() and
override the main program's default domain (virInitialize already
calls bindtextdomain(), but this is insufficient without the
setlocale() added in this patch; and a redundant bindtextdomain()
in this patch doesn't hurt, but serves as a good example for other
packages that need to bind a second translation domain).

This patch is needed to silence a new gnulib 'make syntax-check'
rule in the next patch.

* daemon/libvirtd.c (main): Setup locale and gettext.
* src/lxc/lxc_controller.c (main): Likewise.
* src/security/virt-aa-helper.c (main): Likewise.
* src/storage/parthelper.c (main): Likewise.
* tools/virsh.c (main): Fix exit status.
* src/internal.h (DEFAULT_TEXT_DOMAIN): Define, for gettext.h.
(_): Simplify definition accordingly.
* po/POTFILES.in: Add src/storage/parthelper.c.
2010-11-17 10:12:57 -07:00
Eric Blake
0d5f54bb21 maint: use gnulib configmake rather than open-coding things
* bootstrap.conf (gnulib_modules): Add configmake.
* daemon/Makefile.am (libvirtd_CFLAGS): Drop defines provided by
gnulib.
* src/Makefile.am (INCLUDES): Likewise.
* tests/Makefile.am (INCLUDES): Likewise.
* tools/Makefile.am (virsh_CFLAGS): Likewise.
* daemon/libvirtd.c (qemudInitPaths, usage, main): Update
clients.
* src/cpu/cpu_map.c (CPUMAPFILE): Likewise.
* src/driver.c (DEFAULT_DRIVER_DIR): Likewise.
* src/internal.h (_): Likewise.
* src/libvirt.c (virInitialize): Likewise.
* src/lxc/lxc_conf.h (LXC_CONFIG_DIR, LXC_STATE_DIR, LXC_LOG_DIR):
Likewise.
* src/lxc/lxc_conf.c (lxcCapsInit, lxcLoadDriverConfig):
Likewise.
* src/network/bridge_driver.c (NETWORK_PID_DIR)
(NETWORK_STATE_DIR, DNSMASQ_STATE_DIR, networkStartup): Likewise.
* src/nwfilter/nwfilter_driver.c (nwfilterDriverStartup):
Likewise.
* src/qemu/qemu_conf.c (qemudLoadDriverConfig): Likewise.
* src/qemu/qemu_driver.c (qemudStartup): Likewise.
* src/remote/remote_driver.h (LIBVIRTD_PRIV_UNIX_SOCKET)
(LIBVIRTD_PRIV_UNIX_SOCKET_RO, LIBVIRTD_CONFIGURATION_FILE)
(LIBVIRT_PKI_DIR): Likewise.
* src/secret/secret_driver.c (secretDriverStartup): Likewise.
* src/security/security_apparmor.c (VIRT_AA_HELPER): Likewise.
* src/security/virt-aa-helper.c (main): Likewise.
* src/storage/storage_backend_disk.c (PARTHELPER): Likewise.
* src/storage/storage_driver.c (storageDriverStartup): Likewise.
* src/uml/uml_driver.c (TEMPDIR, umlStartup): Likewise.
* src/util/hooks.c (LIBVIRT_HOOK_DIR): Likewise.
* tools/virsh.c (main): Likewise.
* docs/hooks.html.in: Likewise.
2010-11-17 08:58:58 -07:00
Stefan Berger
8e3051af84 replace last instances of close()
I am replacing the last instances of close() I found with VIR_CLOSE() / VIR_FORCE_CLOSE respectively.

The first part patches virsh, which I missed out on previously.

The 2nd patch I had left out intentionally to look at it more carefully:
The 'closed' variable could be easily removed since it wasn't used anywhere else. The possible race condition that could result from the filedescriptor being closed and not set to -1 (and possibly let us write into 'something' totally different if the fd was allocated by another thread) seems to be prevented by the qemuMonitorLock() already placed around the code that reads from or writes to the fd. So the change of this code as shown in the patch should not have any side-effects.
2010-11-17 10:19:13 -05:00
Stefan Berger
d4897acff8 nwfilter: also purge ip(6)tables rules before detecting IP address
Rather than only cleaning any remaining ebtables rules, also clean those applied to iptables and ip6tables when detecting the IP address of an interface. Previous applied iptables rules may hinder DHCP packets.
2010-11-16 21:18:21 -05:00
Stefan Berger
7b7cb1ecc9 deprecate fclose() and introduce VIR_{FORCE_}FCLOSE()
Similarly to deprecating close(), I am now deprecating fclose() and
introduce VIR_FORCE_FCLOSE() and VIR_FCLOSE(). Also, fdopen() is replaced with
VIR_FDOPEN().

Most of the files are opened in read-only mode, so usage of
VIR_FORCE_CLOSE() seemed appropriate. Others that are opened in write
mode already had the fclose()<  0 check and I converted those to
VIR_FCLOSE()<  0.

I did not find occurrences of possible double-closed files on the way.
2010-11-16 21:13:29 -05:00
Osier Yang
5483745534 qemu: fix typos in qemu_monitor_text.c
* src/qemu/qemu_monitor_text.c (qemuMonitorTextChangeMedia)
2010-11-16 09:26:54 -07:00
Osier Yang
93bc093ac2 qemu: record timestamp in qemu domain log
Currently only support domain start and shutdown, for domain start,
record timestamp before the qemu command line, and for domain shutdown,
just say it's shutting down with timestamp.

* src/qemu/qemu_driver.c (qemudStartVMDaemon, qemudShutdownVMDaemon
  introduced two macros - START_POSTFIX, SHUTDOWN_POSTFIX)
2010-11-16 09:18:32 -07:00
Eric Blake
61af79c141 nwfilter: use /bin/sh rather than requiring bash
* src/nwfilter/nwfilter_ebiptables_driver.c (CMD_EXEC): Fix syntax
error in previous patch.
Reported by Stefan Berger.
2010-11-16 07:53:32 -07:00
Eric Blake
61cdff653c nwfilter: use /bin/sh rather than requiring bash
* src/nwfilter/nwfilter_ebiptables_driver.c
(ebiptablesWriteToTempFile): Use /bin/sh.
(bash_cmd_path): Delete.
(ebiptablesDriverInit, ebiptablesDriverShutdown): No need to
search for bash.
(CMD_EXEC): Prefer $() over ``, since we can assume POSIX.
(iptablesSetupVirtInPost): Use portable 'test' syntax.
(iptablesLinkIPTablesBaseChain): Use POSIX $(()) syntax.
2010-11-15 16:14:33 -07:00
Stefan Berger
1fa88772e9 macvtap: convert send / recv function to use libnl
In a second step I am converting the netlink send/receive functions to
use libnl.

I tested this with 802.1Qbg profiles and my test server and did not see
a regression.

Caveat: The online documentation of libnl talks about nl_socket_alloc()
but the header file provides nl_handle_alloc() -- this could be a hint
to a possible problem between libnl versions...

http://www.infradead.org/~tgr/libnl/doc/group__socket.html

versus

http://libnl.sourcearchive.com/documentation/1.1/group__socket_gf903c9ea089735b1ba8e40dae801c47d.html
2010-11-15 13:58:55 -05:00
Matthias Bolte
e4384459c9 Use python discovered through env instead of hardcoding a path
This is more flexible regarding the location of the python binary
but doesn't allow to pass the -u flag. The -i flag can be passed
from inside the script using the PYTHONINSPECT env variable.

This fixes a problem with the esx_vi_generator.py on FreeBSD.
2010-11-14 22:45:59 +01:00
Matthias Bolte
f76c6dde2e esx: Avoid warnings about breaking strict-aliasing rules on FreeBSD 2010-11-14 22:44:04 +01:00
Matthias Bolte
5c2aa3b7d8 Make sure struct sockaddr_in is defined on FreeBSD 2010-11-14 22:32:55 +01:00
John Morrissey
90afacb3b0 qemu: Remove unnecessary quoting from the process name argument 2010-11-12 14:19:20 +01:00
Matthias Bolte
d941eb13e4 phyp: Don't do a flags check in the storage driver
This makes the storage driver fail when the connection is
opened with the VIR_CONNECT_RO flag, resulting in a read-only
connection with no storage driver.
2010-11-12 14:02:04 +01:00
Matthias Bolte
f6d9a3e208 qemu: Add qemu-system-s390x to the emulators list 2010-11-12 13:52:24 +01:00
Stefan Berger
77e7c13b2e macvtap: convert nl msg construction to use libnl
In a first step I am converting the netlink message construction in
macvtap code to use libnl. It's pretty much a 1:1 conversion except that
now the message needs to be allocated and deallocated.
2010-11-12 07:14:01 -05:00
Jamie Strandboge
29318e177a virt-aa-helper should require <uuid> in XML
When <uuid> is not in the XML, a virUUIDGenerate() ends up being called which
is unnecessary and can lead to crashes if /dev/urandom isn't available
because virRandomInitialize() is not called within virt-aa-helper. This patch
adds verify_xpath_context() and updates caps_mockup() to use it.

Bug-Ubuntu: https://launchpad.net/bugs/672943
2010-11-11 14:59:50 -07:00
Matthias Bolte
5288881344 esx: Support SMBIOS host mode 2010-11-11 19:18:19 +01:00
Laine Stump
45dc5a142f remote_driver.c: fix non-literal format strings w/o args 2010-11-11 12:05:21 -05:00
Laine Stump
5b04f42c6f ignore SELinuxSetFilecon error in SELinuxSetSecurityFileLabel if on nfs
If virDomainAttachDevice() was called with an image that was located
on a root-squashed NFS server, and in a directory that was unreadable
by root on the machine running libvirtd, the attach would fail due to
an attempt to change the selinux label of the image with EACCES (which
isn't covered as an ignore case in SELinuxSetFilecon())

NFS doesn't support SELinux labelling anyway, so we mimic the failure
handling of commit 93a18bbafa, which
just ignores the errors if the target is on an NFS filesystem (in
SELinuxSetSecurityAllLabel() only, though.)

This can be seen as a follow-on to commit
347d266c51, which ignores file open
failures of files on NFS that occur directly in
virDomainDiskDefForeachPath() (also necessary), but does not ignore
failures in functions that are called from there (eg
SELinuxSetSecurityFileLabel()).
2010-11-11 11:43:06 -05:00
Daniel P. Berrange
5fb9db272d Wire up virDomainOpenConsole for LXC, Xen and UML
Introduce implementations of the virDomainOpenConsole() API
for LXC, Xen and UML drivers.

* src/lxc/lxc_driver.c, src/lxc/lxc_driver.c,
  src/xen/xen_driver.c: Wire up virDomainOpenConsole
2010-11-11 16:03:31 +00:00
Daniel P. Berrange
64d6750709 Introduce portability APIs for creating threads
The util/threads.c/h code already has APIs for mutexes,
condition variables and thread locals. This commit adds
in code for actually creating threads.

* src/libvirt_private.syms: Export new symbols
* src/util/threads.h: Define APIs virThreadCreate, virThreadSelf,
  virThreadIsSelf and virThreadJoin
* src/util/threads-win32.c, src/util/threads-win32.h: Win32
  impl of threads
* src/util/threads-pthread.c, src/util/threads-pthread.h: POSIX
  impl of threads
2010-11-11 16:03:09 +00:00
Daniel P. Berrange
bdb28f4426 Support virDomainOpenConsole with QEMU
This provides an implementation of the virDomainOpenConsole
API with the QEMU driver. For the streams code, this reuses
most of the code previously added for the tunnelled migration
streams since it is generic.

* src/qemu/qemu_driver.c: Support virDomainOpenConsole
2010-11-11 16:03:03 +00:00
Daniel P. Berrange
7c08fcc439 Add a generic internal API for handling any FD based stream
To avoid the need for duplicating implementations of virStream
drivers, provide a generic implementation that can handle any
FD based stream. This code is copied from the existing impl
in the QEMU driver, with the locking moved into the stream
impl, and addition of a read callback

The FD stream code will refuse to operate on regular files or
block devices, since those can't report EAGAIN properly when
they would block on I/O

* include/libvirt/virterror.h, include/libvirt/virterror.h: Add
  VIR_FROM_STREAM error domain
* src/qemu/qemu_driver.c: Remove code obsoleted by the new
  generic streams driver.
* src/fdstream.h, src/fdstream.c, src/fdstream.c,
  src/libvirt_private.syms: Generic reusable FD based streams
2010-11-11 16:02:57 +00:00
Daniel P. Berrange
4ef40df13d Lower logging level in remote driver streams
Now that bi-directional, non-blocking streams are supported
in the remote driver, some of the VIR_WARN statements need
to be reduced to VIR_DEBUG.

* src/remote/remote_driver.c: Lower logging level
2010-11-11 16:02:52 +00:00
Daniel P. Berrange
73d8b03cda Remote driver client and server for virDomainOpenConsole
This provides an implementation of the virDomainOpenConsole
API for the remote driver client and server.

* daemon/remote.c: Server side impl
* src/remote/remote_driver.c: Client impl
* src/remote/remote_protocol.x: Wire definition
2010-11-11 16:02:46 +00:00
Daniel P. Berrange
88a9b382c6 Introduce a virDomainOpenConsole API
To enable virsh console (or equivalent) to be used remotely
it is necessary to provide remote access to the /dev/pts/XXX
pseudo-TTY associated with the console/serial/parallel device
in the guest. The virStream API provide a bi-directional I/O
stream capability that can be used for this purpose. This
patch thus introduces a virDomainOpenConsole API that uses
the stream APIs.

* src/libvirt.c, src/libvirt_public.syms,
  include/libvirt/libvirt.h.in, src/driver.h: Define the
  new virDomainOpenConsole API
* src/esx/esx_driver.c, src/lxc/lxc_driver.c,
  src/opennebula/one_driver.c, src/openvz/openvz_driver.c,
  src/phyp/phyp_driver.c, src/qemu/qemu_driver.c,
  src/remote/remote_driver.c, src/test/test_driver.c,
  src/uml/uml_driver.c, src/vbox/vbox_tmpl.c,
  src/xen/xen_driver.c, src/xenapi/xenapi_driver.c: Stub
  API entry point
2010-11-11 16:02:41 +00:00
Daniel P. Berrange
5126926548 Support callbacks on virStream APIs in remote driver client
The current remote driver code for streams only supports
blocking I/O mode. This is fine for the usage with migration
but is a problem for more general use cases, in particular
bi-directional streams.

This adds supported for the stream callbacks and non-blocking
I/O. with the minor caveat is that it doesn't actually do
non-blocking I/O for sending stream data, only receiving it.
A future patch will try to do non-blocking sends, but this is
quite tricky to get right.

* src/remote/remote_driver.c: Allow non-blocking I/O for
  streams and support callbacks
2010-11-11 16:02:35 +00:00
Daniel P. Berrange
2fbec00203 Fix LXC container console device setup
The /dev/console device inside the container must NOT map
to the real /dev/console device node, since this allows the
container control over the current host console. A fun side
effect of this is that starting a container containing a
real Fedora OS will kill off your X server.

Remove the /dev/console node, and replace it with a symlink
to the primary console TTY

* src/lxc/lxc_container.c: Replace /dev/console with a
  symlink to /dev/pty/0
* src/lxc/lxc_controller.c: Remove /dev/console from cgroups
  ACL
2010-11-11 12:06:30 +00:00
Cole Robinson
96d52fcf43 qemu: Add flag to force a CDROM eject
QEMU allows forcing a CDROM eject even if the guest has locked the device.
Expose this via a new UpdateDevice flag, VIR_DOMAIN_DEVICE_MODIFY_FORCE.

This has been requested for RHEV:

https://bugzilla.redhat.com/show_bug.cgi?id=626305

v2: Change flag name, bool cleanups
2010-11-10 12:31:20 -05:00
Adam Litke
9c7c4a4fc5 Allow non-file disk backingStores
I am trying to use a qcow image with libvirt where the backing 'file' is a
qemu-nbd server.  Unfortunately virDomainDiskDefForeachPath() assumes that
backingStore is always a real file so something like 'nbd:0:3333' is rejected
because a file with that name cannot be accessed.  Note that I am not worried
about directly using nbd images.  That would require a new disk type with XML
markup, etc.  I only want it to be permitted as a backingStore

The following patch implements danpb's suggestion:
> I think I'm inclined to push the logic for skipping NBD one stage higher.
> I'd rather expect virStorageFileGetMetadata() to return all backing
> stores, even if not files. The virDomainDiskDefForeachPath() method
> should definitely ignore non-file backing stores though.
>
> So what I'm thinking is to extend the virStorageFileMetadata struct and
> just add a 'bool isFile' field to it. Default this field to true, unless
> you see the prefix of nbd: in which case set it to false. The
> virDomainDiskDefForeachPath() method can then skip over any backing
> store with isFile == false

Signed-off-by: Adam Litke <agl@us.ibm.com>
Cc: Daniel P. Berrange <berrange@redhat.com>
2010-11-09 16:40:27 -07:00
Matthias Bolte
c2e9e90742 xencapstest: Don't fail when Xen is installed
xencapstest calls xenHypervisorMakeCapabilitiesInternal with conn == NULL
which calls xenDaemonNodeGetTopology with conn == NULL when a recent
enough Xen was detected (sys_interface_version >= SYS_IFACE_MIN_VERS_NUMA).
But xenDaemonNodeGetTopology insists in having conn != NULL and fails,
because it expects to be able to talk to an actual xend.

We cannot do that in a 'make check' test. Therefore, only call the xend
subdriver function when conn isn't NULL.

Reported by Andy Howell and Jim Fehlig.
2010-11-10 00:06:49 +01:00
Stefan Berger
60ae1c34ad bye to close(), welcome to VIR_(FORCE_)CLOSE()
Using automated replacement with sed and editing I have now replaced all
occurrences of close() with VIR_(FORCE_)CLOSE() except for one, of
course. Some replacements were straight forward, others I needed to pay
attention. I hope I payed attention in all the right places... Please
have a look. This should have at least solved one more double-close
error.
2010-11-09 15:48:48 -05:00
Matthias Bolte
809926db8f esx: Add support for memtune/min_guarantee
Also add a test case for the VMX handling of it.
2010-11-09 19:28:33 +01:00
Daniel P. Berrange
b0ef5c5367 Support SPICE channel security options
This extends the SPICE XML to allow channel security options

    <graphics type='spice' port='-1' tlsPort='-1' autoport='yes'>
      <channel name='main' mode='secure'/>
      <channel name='record' mode='insecure'/>
    </graphics>

Any non-specified channel uses the default, which allows both
secure & insecure usage

* src/conf/domain_conf.c, src/conf/domain_conf.h,
  src/libvirt_private.syms: Add XML syntax for specifying per
  channel security options for spice.
* src/qemu/qemu_conf.c: Configure channel security with spice
2010-11-09 11:47:26 +00:00
Daniel P. Berrange
6794a44b85 Support multiple QXL video cards
QEMU crashes & burns if you try multiple Cirrus video cards, but
QXL copes fine. Adapt QEMU config code to allow multiple QXL
video cards

* src/qemu/qemu_conf.c: Support multiple QXL video cards
2010-11-09 11:47:21 +00:00
Daniel P. Berrange
7a696678e5 Define XML syntax for password expiry
This extends the XML syntax for <graphics> to allow a password
expiry time to be set

eg

  <graphics type='vnc' port='5900' autoport='yes' keymap='en-us' passwd='12345' passwdValidTo='2010-04-09T15:51:00'/>

The timestamp is in UTC.

* src/conf/domain_conf.h: Pull passwd out into separate struct
  virDomainGraphicsAuthDef to allow sharing between VNC & SPICE
* src/conf/domain_conf.c: Add parsing/formatting of new passwdValidTo
  argument
* src/opennebula/one_conf.c, src/qemu/qemu_conf.c, src/qemu/qemu_driver.c,
  src/xen/xend_internal.c, src/xen/xm_internal.c: Update for changed
  struct containing VNC password
2010-11-09 11:47:13 +00:00
Daniel P. Berrange
b5c9920955 Add SPICE support for QEMU driver configuration file
In common with VNC, the QEMU driver configuration file is used
specify the host level TLS certificate location and a default
password / listen address

* src/qemu/qemu.conf: Add spice_listen, spice_tls,
  spice_tls_x509_cert_dir & spice_password config params
* src/qemu/qemu_conf.c, src/qemu/qemu_conf.h: Parsing of
  spice config parameters and updating -spice arg generation
  to use them
* tests/qemuxml2argvdata/qemuxml2argv-graphics-spice-rhel6.args,
  tests/qemuxml2argvtest.c: Expand test case to cover driver
  level configuration
2010-11-09 11:47:05 +00:00
Daniel P. Berrange
ed0d9f6c0c Support automatic port number allocation for SPICE
* src/qemu/qemu_driver.c: Allocate the TCP ports for SPICE
  before starting guest
2010-11-09 11:46:56 +00:00
Daniel P. Berrange
9b57fa65bd Implement QEMU/KVM support for SPICE graphics
This supports the -spice argument posted for review against
the latest upstream QEMU/KVM. This supports the bare minimum
config with port, TLS port & listen address. The x509 bits are
added in a later patch.

* src/qemu_conf.c, src/qemu_conf.h: Add SPICE flag. Check for
  -spice availability. Format -spice arg for command line
* qemuhelptest.c: Add SPICE flag
* qemuxml2argvdata/qemuxml2argv-graphics-spice.args: Add <graphics>
  for spice
* qemuxml2argvdata/qemuxml2argv-graphics-spice.xml: Add -spice arg
* qemuxml2argvtest.c: Add SPICE flag
2010-11-09 11:46:50 +00:00
Daniel P. Berrange
635f9ca1f3 Implement QEMU/KVM QXL video card support in QEMU driver
This supports the '-vga qxl' parameter in upstream QEMU/KVM
which has SPICE support added. This isn't particularly useful
until you get the next patch for -spice support. Also note that
while the libvirt XML supports multiple video devices, this
patch only supports a single one. A later patch can add support
for 2nd, 3rd, etc PCI devices for QXL

* src/qemu/qemu_conf.h: Flag for QXL support
* src/qemu/qemu_conf.c: Probe for '-vga qxl' support and implement it
* tests/qemuxml2argvtest.c, tests/qemuxml2xmltest.c,
  tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.args,
  tests/qemuxml2argvdata/qemuxml2argv-graphics-spice.xml: Test
  case for generating spice args with RHEL6 kvm
2010-11-09 11:46:45 +00:00