Commit Graph

77 Commits

Author SHA1 Message Date
Daniel P. Berrange
e4e69e899e Apply security label when entering LXC namespaces
Add a new virDomainLxcEnterSecurityLabel() function as a
counterpart to virDomainLxcEnterNamespaces(), which can
change the current calling process to have a new security
context. This call runs client side, not in libvirtd
so we can't use the security driver infrastructure.

When entering a namespace, the process spawned from virsh
will default to running with the security label of virsh.
The actual desired behaviour is to run with the security
label of the container most of the time. So this changes
virsh lxc-enter-namespace command to invoke the
virDomainLxcEnterSecurityLabel method.

The current behaviour is:

LABEL                             PID TTY          TIME CMD
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 1 pts/0 00:00:00 systemd
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 3 pts/1 00:00:00 sh
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 24 ? 00:00:00 systemd-journal
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 29 ? 00:00:00 dhclient
staff_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 47 ? 00:00:00 ps

Note the ps command is running as unconfined_t,  After this patch,

The new behaviour is this:

virsh -c lxc:/// lxc-enter-namespace dan -- /bin/ps -eZ
LABEL                             PID TTY          TIME CMD
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 1 pts/0 00:00:00 systemd
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 3 pts/1 00:00:00 sh
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 24 ? 00:00:00 systemd-journal
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 32 ? 00:00:00 dhclient
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 38 ? 00:00:00 ps

The '--noseclabel' flag can be used to skip security labelling.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-03-13 15:16:37 +00:00
Peter Krempa
38cc07b7bc virsh-domain: Remove unused vshCompleteXMLFromDomain
The function is marked as unused and breaks compilation on RHEL4. Remove
it from the tree until a new use case can be found.
2013-03-10 10:18:23 +01:00
Peter Krempa
406dc47757 Revert "Ensure xmlSaveToBuffer is always defined"
The commit originally fixed code that isn't being used. Revert
it and remove the unused code as a real fix.

This reverts commit a66b32d929.
2013-03-10 10:18:23 +01:00
Daniel P. Berrange
a66b32d929 Ensure xmlSaveToBuffer is always defined
RHEL4 vintage libxml2 header files are missing xmlSaveToBuffer
despite the symbol existing in the binary

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-03-07 18:10:35 +00:00
Jiri Denemark
e94aeb1428 virsh: Add migrate-compcache command
This is a command wrapping virDomainMigrateGetCompressionCache and
virDomainMigrateSetCompressionCache.
2013-02-22 17:35:59 +01:00
Jiri Denemark
38ab12251e virsh: Use virDomainGetJobStats in domjobinfo if available 2013-02-22 17:35:58 +01:00
Jiri Denemark
ecfff1dab3 Introduce VIR_MIGRATE_COMPRESSED flag
This flag may be used with migration APIs to request compression of
migration data.
2013-02-22 17:35:58 +01:00
Michal Privoznik
38d52f6318 virsh-domain.c: Switch to c99 initialization of vshCmdInfo 2013-02-12 17:50:21 +01:00
Michal Privoznik
df5fd11f86 virsh: Switch to c99 initialization of vshCmdDef 2013-02-12 17:50:21 +01:00
Peter Krempa
fa956d9055 virsh-domain: Update domain commands to use vshCommandOptStringReq 2013-02-04 14:17:44 +01:00
John Ferlan
46b1d8cf7a Enforce return check on virAsprintf() calls
Way back when I started making changes for Coverity messages my first set
were to a bunch of CHECKED_RETURN errors.  In particular virAsprintf() had
a few callers that Coverity noted didn't check their return (although some
did check if the buffer being printed to was NULL or not).

It was suggested at the time as a further patch an ATTRIBUTE_RETURN_CHECK
should be added to virAsprintf(), see:

https://www.redhat.com/archives/libvir-list/2013-January/msg00120.html

This patch does that and fixes a few more instances not found by Coverity
that failed the check.
2013-01-30 14:42:22 -07:00
Peter Krempa
f8d5119e4f virsh: Add --print-xml flag for attach-disk command
The flag causes the XML of the disk that would be attached to be printed
instead.
2013-01-25 20:53:37 +01:00
Peter Krempa
a54f25a946 virsh-domain: Refactor error paths for cmdCPUStats
This patch fixes the following issues in the cpu-stats virsh command:

1) Renames label failed_params to no_memory to match coding style
2) Uses proper typed parameter cleanup in error paths to avoid leaks
3) Adds a ret variable and simplifies error labels
4) Changes error message to a slightly more descriptive one and gets rid
   of the newline at the end:

Before:
$ virsh cpu-stats tr
error: Failed to virDomainGetCPUStats()

error: Requested operation is not valid: domain is not running

After:
$ tools/virsh cpu-stats tr
error: Failed to retrieve CPU statistics for domain 'tr'
error: Requested operation is not valid: domain is not running
2013-01-22 17:36:45 +01:00
Jiri Denemark
de78bf604c Introduce virTypedParamsClear public API
The function is just a renamed public version of former
virTypedParameterArrayClear.
2013-01-18 15:04:00 +01:00
Jiri Denemark
f52e9f1f4d virsh: Use virTypedParams* APIs in cpu-stats 2013-01-18 15:04:00 +01:00
Jiri Denemark
ec3e50644e virsh: Use virTypedParams* APIs in numatune 2013-01-18 15:04:00 +01:00
Jiri Denemark
7786233009 virsh: Use virTypedParams* APIs in memtune 2013-01-18 15:03:59 +01:00
Jiri Denemark
e982dacb45 virsh: Use virTypedParams* APIs in schedinfo 2013-01-18 15:03:59 +01:00
Jiri Denemark
9b2d2446af virsh: Use virTypedParams* APIs in domiftune 2013-01-18 15:03:59 +01:00
Jiri Denemark
39e5173a3d virsh: Use virTypedParams* APIs in blkiotune 2013-01-18 15:03:59 +01:00
Jiri Denemark
a8fca0da06 virsh: Use virTypedParams* APIs in blkdeviotune 2013-01-18 15:03:59 +01:00
Michal Privoznik
99419bd11e virsh-domain.c: Switch to C99 initialization of vshCmdOptDef 2013-01-17 13:58:52 +01:00
Daniel P. Berrange
e397f658b0 Add 'lxc-enter-namespace' command to virsh
Add a 'lxc-enter-namespace' command which accepts a domain name
and then a command + args to run, attached to the container

eg

  virsh -c lxc:/// lxc-enter-namespace demo -- /bin/ps -auxf

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-01-15 19:09:47 +00:00
Daniel P. Berrange
24bcd8d45a Move qemu-XXX commands from virsh-host.c to virsh-domain.c
The QEMU specific APIs all operate on domains, not the host,
so should be in the virsh-domain.c file / group

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-01-08 08:56:49 +00:00
Daniel P. Berrange
f24404a324 Rename virterror.c virterror_internal.h to virerror.{c,h} 2012-12-21 11:19:50 +00:00
Daniel P. Berrange
556cf5f617 Rename xml.{c,h} to virxml.{c,h} 2012-12-21 11:19:50 +00:00
Daniel P. Berrange
44f6ae27fe Rename util.{c,h} to virutil.{c,h} 2012-12-21 11:19:49 +00:00
Daniel P. Berrange
ab9b7ec2f6 Rename memory.{c,h} to viralloc.{c,h} 2012-12-21 11:17:14 +00:00
Daniel P. Berrange
2005f7b552 Rename buf.{c,h} to virbuffer.{c,h}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-12-21 11:17:12 +00:00
Daniel P. Berrange
a27e4fbb72 Rename bitmap.{c,h} to virbitmap.{c,h}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-12-21 11:17:12 +00:00
liguang
8b9bf7879b Add support for offline migration
Offline migration transfers inactive definition of a domain (which may
or may not be active). After successful completion, the domain remains
in its current state on source host and is defined but inactive on
destination host. It's a bit more clever than virDomainGetXMLDesc() on
source host followed by virDomainDefineXML() on destination host, as
offline migration will run pre-migration hook to update the domain XML
on destination host. Currently, copying non-shared storage is not
supported during offline migration.

Offline migration can be requested with a new migration flag called
VIR_MIGRATE_OFFLINE (which has to be combined with
VIR_MIGRATE_PERSIST_DEST flag).
2012-12-10 21:52:15 +01:00
Peter Krempa
989a427de8 virsh: Fix usage of header termios.h
The termios struct exported by the termios.h header is used as an
argument for vshMakeStdinRaw(). The header isn't used anywhere in
tools/virsh-domain.c.

This patch adds the header to the header declaring vshMakeStdinRaw() and
removes other places in virsh.
2012-12-07 14:21:25 +01:00
Peter Krempa
bf72095954 virsh: Report errors if arguments of the schedinfo command are incorrect
Libvirt's helper API's when called directly don't raise the error so
that virsh remembers it. Subsequent calls to libvirt API's might reset
the error.

In case of schedinfo virDomainFree() in the cleanup section resets the
error when virTypedParameterAssignFromStr() fails.

This patch adds function vshSaveLibvirtError() that can be called after
calling libvirt helper APIs to ensure the error is remembered.
2012-12-03 16:37:10 +01:00
Peter Krempa
8312435707 maint: Misc whitespace cleanups 2012-12-03 15:13:32 +01:00
Eric Blake
7243752694 virsh: don't crash if shutdown --mode not provided
virStringSplit requires a non-NULL input, but commit cef78ed forgot
to follow the rule.

* tools/virsh-domain.c (cmdReboot, cmdShutdown): Avoid NULL deref.
2012-11-30 14:56:30 -07:00
Daniel P. Berrange
cef78ed84a Allow comma separated list of shutdown/reboot modes with virsh
The shutdown and reboot commands in virsh allow a comma
separated list of mode values

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-11-30 20:05:43 +00:00
Daniel P. Berrange
76d9f65644 Introduce two new methods for triggering controlled shutdown/reboot
The virDomainShutdownFlags and virDomainReboot APIs allow the caller
to request the operation is implemented via either acpi button press
or a guest agent. For containers, a couple of other methods make
sense, a message to /dev/initctl, and direct kill(SIGTERM|HUP) of
the container init process.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-11-30 19:19:38 +00:00
Ján Tomko
dc04b2a737 virsh: use correct sizeof when allocating cpumap
Found by coverity:
Error: SIZEOF_MISMATCH (CWE-569):
    libvirt-0.10.2/tools/virsh-domain.c:4754: suspicious_sizeof: Passing
    argument "8UL /* sizeof (cpumap) */" to function
    "_vshCalloc(vshControl *, size_t, size_t, char const *, int)" and
    then casting the return value to "unsigned char *" is suspicious.

Error: SIZEOF_MISMATCH (CWE-569):
    libvirt-0.10.2/tools/virsh-domain.c:4942: suspicious_sizeof: Passing
    argument "8UL /* sizeof (cpumap) */" to function
    "_vshCalloc(vshControl *, size_t, size_t, char const *, int)" and
    then casting the return value to "unsigned char *" is suspicious.
2012-11-29 10:10:08 -07:00
Daniel P. Berrange
d9a52520c7 Add a 'send-process-signal' command to virsh
* tools/virsh.c: Add send-process-signal
* tools/virsh.pod: Document new command

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-11-29 15:50:12 +00:00
Michal Privoznik
4ded3fb1c2 maint: Fix use of invalid reboot flags
Throughout the code, we've always used VIR_DOMAIN_SHUTDOWN* flags
even for virDomainReboot() API and its implementation. Fortunately,
the appropriate macros has the same value. But if we want to keep
things consistent, we should be using the correct macros. This
patch doesn't break anything, luckily.
2012-11-28 17:45:30 +01:00
Martin Kletzander
1d4f41fdbe virsh: Rewrite cmdDomDisplay
Just a little rewrite of the cmdDomDisplay function to make it
consistent and hopefully more readable.  This also fixes a problem
with password not being displayed for vnc even with the
"--include-password" option.
2012-11-28 16:22:10 +01:00
Michal Privoznik
47c724e54f virsh: Expose new virDomainFSTrim API
It's exposed under domfstrim command. Although the API
doesn't support specifying mount point yet, expose it
anyway.
2012-11-28 16:15:01 +01:00
Eric Blake
79caaf70ae Revert "virsh: add aliases 'boot', 'stop', and 'restart'"
This reverts commits 5f63a5cb42
and ff86b0c97b.  After much list
discussion, consensus was that libvirt aliases should be reserved
to correct typos, otherwise it risks confusion.  Rather, we
should implement a way for users to provide their own aliases
as part of their virsh configuration preferences.
2012-11-16 08:23:57 -07:00
Ján Tomko
58110b4887 virsh: save: report an error if XML file can't be read
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=876868
2012-11-15 22:21:35 -07:00
Viktor Mihajlovski
2bbe624e1d virsh: Use virNodeGetCPUMap if possible
Modified the places where virNodeGetInfo was used for the purpose
of obtaining the maximum node CPU number. Transparently falling
back to virNodeGetInfo in case of failure.
Wrote utility function vshNodeGetCPUCount to compute node CPU
number.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
2012-11-15 09:06:54 -07:00
Eric Blake
ff86b0c97b virsh: add aliases 'boot', 'stop', and 'restart'
https://bugzilla.redhat.com/show_bug.cgi?id=873344 suggested that
the grouping 'boot', 'shutdown', 'reboot'; as well as the grouping
'start', 'stop', 'restart'; might be easier to remember than the
current mix of 'start', 'shutdown', 'reboot'.

Also, touch up the wording of 'reboot' to be more accurate.

* tools/virsh-domain.c (domManagementCmds): Add other command names.
* tools/virsh.pod (start, shutdown, reboot): Document the aliases.
2012-11-06 08:03:48 -07:00
Daniel P. Berrange
1c04f99970 Remove spurious whitespace between function name & open brackets
The libvirt coding standard is to use 'function(...args...)'
instead of 'function (...args...)'. A non-trivial number of
places did not follow this rule and are fixed in this patch.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-11-02 13:36:49 +00:00
Laine Stump
def31e4c58 qemu: fix attach/detach of netdevs with matching mac addrs
This resolves:

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

which describes inconsistencies in dealing with duplicate mac
addresses on network devices in a domain.

(at any rate, it resolves *almost* everything, and prints out an
informative error message for the one problem that isn't solved, but
has a workaround.)

A synopsis of the problems:

1) you can't do a persistent attach-interface of a device with a mac
address that matches an existing device.

2) you *can* do a live attach-interface of such a device.

3) you *can* directly edit a domain and put in two devices with
matching mac addresses.

4) When running virsh detach-device (live or config), only MAC address
is checked when matching the device to remove, so the first device
with the desired mac address will be removed. This isn't always the
one that's wanted.

5) when running virsh detach-interface (live or config), the only two
items that can be specified to match against are mac address and model
type (virtio, etc) - if multiple netdevs match both of those
attributes, it again just finds the first one added and assumes that
is the only match.

Since it is completely valid to have multiple network devices with the
same MAC address (although it can cause problems in many cases, there
*are* valid use cases), what is needed is:

1) remove the restriction that prohibits doing a persistent add of a
netdev with a duplicate mac address.

2) enhance the backend of virDomainDetachDeviceFlags to check for
something that *is* guaranteed unique (but still work with just mac
address, as long as it yields only a single results.

This patch does three things:

1) removes the check for duplicate mac address during a persistent
netdev attach.

2) unifies the searching for both live and config detach of netdevices
in the subordinate functions of qemuDomainModifyDeviceFlags() to use the
new function virDomainNetFindIdx (which matches mac address and PCI
address if available, checking for duplicates if only mac address was
specified). This function returns -2 if multiple matches are found,
allowing the callers to print out an appropriate message.

Steps 1 & 2 are enough to fully fix the problem when using virsh
attach-device and detach-device (which require an XML description of
the device rather than a bunch of commandline args)

3) modifies the virsh detach-interface command to check for multiple
matches of mac address and show an error message suggesting use of the
detach-device command in cases where there are multiple matching mac
addresses.

Later we should decide how we want to input a PCI address on the virsh
commandline, and enhance detach-interface to take a --address option,
eliminating the need to use detach-device

* src/conf/domain_conf.c
* src/conf/domain_conf.h
* src/libvirt_private.syms
  * added new virDomainNetFindIdx function
  * removed now unused virDomainNetIndexByMac and
    virDomainNetRemoveByMac

* src/qemu/qemu_driver.c
  * remove check for duplicate max from qemuDomainAttachDeviceConfig
  * use virDomainNetFindIdx/virDomainNetRemove instead
    of virDomainNetRemoveByMac in qemuDomainDetachDeviceConfig
  * use virDomainNetFindIdx instead of virDomainIndexByMac
    in qemuDomainUpdateDeviceConfig

* src/qemu/qemu_hotplug.c
  * use virDomainNetFindIdx instead of a homespun loop in
    qemuDomainDetachNetDevice.

* tools/virsh-domain.c: modified detach-interface command as described
    above
2012-10-26 20:47:54 -04:00
Ján Tomko
c0fab87106 virsh: remove reference to migration in blockcopy 2012-10-11 21:12:45 -06:00
Ján Tomko
13fefaf37f virsh: block SIGINT while getting BlockJobInfo
SIGINT hasn't been blocked, which could lead to losing it somewhere in
virDomainGetBlockJobInfo and not aborting the job.
2012-10-11 21:01:54 -06:00