Commit Graph

269 Commits

Author SHA1 Message Date
Marek Marczykowski-Górecki
fa3325a2b2
Merge branch 'bug1198'
Fixes QubesOS/qubes-issues#1198
2015-10-02 01:59:05 +02:00
Marek Marczykowski-Górecki
3cdae85254
core: preserve 'autostart' setting during VM rename
Systemd unit name needs to be renamed.

Fixes QubesOS/qubes-issues#1256
2015-10-02 01:57:00 +02:00
Wojtek Porczyk
12092c3aa5 core3: port TemplateVM 2015-09-28 18:15:24 +02:00
Marek Marczykowski-Górecki
b9e6b0a076
core/hvm: fix error message when creating HVM while not supported by the hardware
libvirt reports such errors at domain definition, not startup (as was in
libxl).

QubesOS/qubes-issues#1198
2015-09-25 22:21:10 +02:00
Marek Marczykowski-Górecki
dd1bea98e1
core/start: ensure that the previous QubesDB daemon isn't running
When restarting VM (starting it just after it was shut down), it may
happen that previous `qubesdb-daemon` instance is still running - if VM
doesn't properly terminate the connection, dom0 part will not terminate
immediately, but at next alive check (every 10s). Such `qubesdb-daemon`,
when terminating, will remove pid file and socket file. In case of new
daemon already running it would be those of the new daemon, making the
whole QubesDB of this VM inaccessible for dom0 (`qubesdb-daemon` is
running, but its socket is removed).

To prevent this race, ensure that previous instance is terminated before
starting the new one.
There is no need to manually removing socket file, because if some stale
socket exists, it will be replaced by the new one when new
`qubesdb-daemon` starts up.

QubesOS/qubes-issues#1241
2015-09-25 22:06:14 +02:00
Marek Marczykowski-Górecki
76bddaa280 core: use vm.absolute_path to parse paths in qubes.xml
This makes easier to handle some corner cases. One of them is having
entry without `dir_path` defined. This may happen when migrating from R2
(using backup+restore or in-place) while some DisposableVM was running
(even if not included in the backup itself).

Fixes qubesos/qubes-issues#1124
Reported by @doncohen, thanks @wyory for providing more details.
2015-09-04 01:58:53 +02:00
Marek Marczykowski-Górecki
226a144285 core: fix vm-persistence info for DispVM
(reported by @adrelanos)
qubesos/qubes-issues#1101
2015-09-03 21:11:43 +02:00
Marek Marczykowski-Górecki
3beb307901 core: add VM persistence info to qubesdb (#1101)
Fixes qubesos/qubes-issues#1101
2015-09-02 00:15:14 +02:00
Marek Marczykowski-Górecki
1ed4a2cbb2
core: fix getting libvirt error code 2015-08-08 21:29:56 +02:00
Marek Marczykowski-Górecki
da0e5dd4ba
core: inherit kernelopts from the template by default
Fixes qubesos/qubes-issues#1091
2015-08-05 01:43:43 +02:00
Marek Marczykowski-Górecki
2ed9008a83
core: handle firewall.xml path during VM rename 2015-08-05 01:04:44 +02:00
Marek Marczykowski-Górecki
46b94b6682
Make qubes-set-updates set also default state for new VMs
This makes possible to also check if the "updates check enabled" state
is consistent across VMs.

Fixes qubesos/qubes-issues#892
2015-08-05 01:04:43 +02:00
Marek Marczykowski-Górecki
90393c33f2
core: add offline mode to qvm-create, qvm-prefs
This is required to create VMs in process of building Live system, where
libvirt isn't running.

Additionally there is no udev in the build environment, so needs to
manually create /dev/loop*p* based on sysfs info.
2015-08-01 21:58:38 +02:00
Marek Marczykowski-Górecki
8f862cdf69
core/hvm: check if VM serving cdrom content is running 2015-07-25 04:17:59 +02:00
Marek Marczykowski-Górecki
51826decec
core/hvm: start guid before qrexec, even when gui agent is installed
This way even when qrexec agent would timeout on connection, guid will
be already running.
Also use new -K guid option to terminate stubdom guid when the real guid
is connected (unless in debug mode - then both guid will be running).
2015-07-25 03:55:50 +02:00
Marek Marczykowski-Górecki
1199806b5a core: fix handling firewall configuration for VM clones and DispVMs (#1032)
There were two bugs:
1. Firewall configuration wasn't copied during qvm-clone (it is in
   separate file, so now it is included in vm.clone_disk_files).
2. Non-default firewall configuration wasn't stored in qubes.xml. This
   means that initially DispVM got proper configuration (inherited from
   calling VM), but if anything caused firewall reload (for example
   starting another VM), the firewall rules was cleared to default state
   (allow all).

Fixes qubesos/qubes-issues#1032
2015-07-08 04:46:14 +02:00
Marek Marczykowski-Górecki
e52f0a0566 core: by default call qrexec services without GUI
Most of them do not need GUI (especially those started from dom0), so
speed the things up a little (no need to wait for guid). But if some
service will need GUI access, there is "gui" parameter.
2015-07-08 01:36:28 +02:00
Marek Marczykowski-Górecki
284419b355 core: add "localcmd" support in QubesVm.run_service function 2015-07-08 01:35:59 +02:00
Marek Marczykowski-Górecki
402d1b9a3d indentation fix 2015-07-01 04:40:48 +02:00
Marek Marczykowski-Górecki
522bfc427a core: fix template-based HVM disk handling
We use only one device-mapper layer for HVMs, and this isn't the same as
for PV - it is that one, which PV does in initramfs.
Device-mapper layers summary for template-based VMs:
PV: root.img+root-cow.img (dom0) -> xvda, xvda+volatile.img (VM)
HVM: root.img+volatile.img (dom0)
2015-07-01 04:35:09 +02:00
Marek Marczykowski-Górecki
a96d49a40a core: properly redirect qrexec output to /dev/null when necessary
/dev/null was opened in read-only mode ("rw" is invalid value), so
qrexec couldn't write there.
2015-07-01 04:33:04 +02:00
Wojtek Porczyk
8805db5e5f core3 move: AdminVM class 2015-06-29 17:39:26 +02:00
Jason Mehring
be3e888bbe Fixed typos 2015-06-29 17:39:26 +02:00
Marek Marczykowski-Górecki
ad89c8f8a2 core: show clear message when a VM has non-existing PCI device assigned 2015-06-27 04:52:25 +02:00
Marek Marczykowski-Górecki
ee48954445 core: fix starting stubdom guid for HVM in debug mode
Remove artificial attribute '_start_guid_first' and use
guiagent_installed directly. This way starting guid for stubdom in debug
mode, even if guiagent_installed is set is much clearer.
2015-06-27 04:10:32 +02:00
Marek Marczykowski-Górecki
9cbf9a8a59 Add support for 'pci_strictreset' option
This allows to assign PCI device to the VM, even if it doesn't support
proper reset. The default behaviour (when the value is True) is to not
allow such attachment (VM will not start if such device is assigned).

Require libvirt patch for this option.
2015-05-28 00:11:17 +02:00
Marek Marczykowski-Górecki
602155374a dispvm: restore DispVM naming independent of Qubes VM ID (#983)
Using QID for DispVM ID was a bad idea in terms of anonymity:
1. It gives some clue about VMs count in the system. In case of large
numbers, this can be quite unique.
2. If new DispVM is started just after closing previous one, it will get
the same ID, and in consequence the same IP. In case of using TorVM,
this leads to use the same circuit as just closed DispVM.

Fixes qubesos/qubes-issues#983
2015-05-04 00:41:33 +02:00
Marek Marczykowski-Górecki
b985bf3b65 core: fix removing VMs not registered in libvirt
It can happen that VM will not be registered in libvirt (for example
when it was never started). It shouldn't be a problem when we want to
remove it.
2015-05-03 20:26:07 +02:00
Marek Marczykowski-Górecki
6ecc263534 core: use libvirtError instance instead of virConnGetLastError 2015-05-03 20:23:26 +02:00
Marek Marczykowski-Górecki
1a284f18fb core: store dom0 info in qubes.xml
At least to have there info about its backup.

This was already done in commit
dc6fd3c8f3, but later was erroneously
reverted during migration to libvirt.

Fixes qubesos/qubes-issues#958
2015-04-28 15:00:50 +02:00
Marek Marczykowski-Górecki
7652137854 core: make sure that dom0.libvirt_domain isn't used
libvirt do not have domain object for dom0, so do not try to access it.
2015-04-28 15:00:50 +02:00
Marek Marczykowski-Górecki
bbf2ee3a67 core: cleanup_vifs should not fail when no network intf is present
This can happen when initially there was no default netvm, some domain
was started, then default netvm was set and started - then
netvm.connected_vms will contain domains which aren't really connected
there.
Especially this was happening in firstboot.
2015-04-15 12:04:21 +02:00
Marek Marczykowski-Górecki
913cc27023 core: fix QubesVm.clone_attrs - really copy dicts
Otherwise it would point at the same object and for example changing
vm.services[] in one VM will change that also for another. That link
will be severed after reloading the VMs from qubes.xml, but at least in
case of DispVM startup its too late - vm.service['qubes-dvm'] is set for
the DispVM template even during normal startup, not savefile preparation.
2015-04-10 18:32:14 +02:00
Marek Marczykowski-Górecki
1ab4663293 core: reject non-NetVM for vm.netvm and vm.dispvm_netvm 2015-04-06 02:55:26 +02:00
Marek Marczykowski-Górecki
678ccdfaa0 core: fix saving 'dispvm_netvm' attribute 2015-04-06 00:21:08 +02:00
Marek Marczykowski-Górecki
d8533bd061 core: do not reset firewal when setting netvm=none
It is no longer needed as qubesos/qubes-issues#862 is implemented.
2015-04-04 21:48:03 +02:00
Marek Marczykowski-Górecki
7516737fae core: Add "dispvm_netvm" property - NetVM for DispVMs started from a VM
This allows to specify tight network isolation for a VM, and finally
close one remaining way for leaking traffic around TorVM. Now when VM is
connected to for example TorVM, its DispVMs will be also connected
there.
The new property can be set to:
 - default (uses_default_dispvm_netvm=True) - use the same NetVM/ProxyVM as the
 calling VM itself - including none it that's the case
 - None - DispVMs will be network-isolated
 - some NetVM/ProxyVM - will be used, even if calling VM is network-isolated

Closes qubesos/qubes-issues#862
2015-04-04 21:47:31 +02:00
Wojtek Porczyk
19dfe3d390 core: allow '.' in domain name 2015-03-31 20:42:53 +02:00
Marek Marczykowski-Górecki
0b0dbfd1e7 core: default 'include_in_backups' to negative of 'installed_by_rpm'
As we allow to backup template, even if installed by rpm, it makes sense
to not include such templates in backup by default.
2015-03-31 05:49:13 +02:00
Marek Marczykowski-Górecki
5c59067676 core: treat absence of libvirt domain as 'Halted' state
If the domain isn't defined in libvirt, it surely isn't running. This is
needed for DispVM, which compares with exactly this state.
2015-03-30 05:33:13 +02:00
Marek Marczykowski-Górecki
9bfcb72722 core: fix setting the VM autostart (#925)
This is actually workaround for systemd bug reported here:
https://bugzilla.redhat.com/show_bug.cgi?id=1181922

Closes qubesos/qubes-issues#925
2015-03-29 23:48:10 +02:00
Marek Marczykowski-Górecki
2e8624e322 core: add missing import 2015-03-29 23:47:24 +02:00
Marek Marczykowski-Górecki
075f35b873 core: do not assume that libvirt domain is always defined
Define it only when really needed:
 - during VM creation - to generate UUID
 - just before VM startup

As a consequence we must handle possible exception when accessing
vm.libvirt_domain. It would be a good idea to make this field private in
the future. It isn't possible for now because block_* are external for
QubesVm class.

This hopefully fixes race condition when Qubes Manager tries to access
libvirt_domain (using some QubesVm.*) at the same time as other tool is
removing the domain. Additionally if Qubes Manage would loose that race, it could
define the domain again leaving some unused libvirt domain (blocking
that domain name for future use).
2015-03-29 23:38:36 +02:00
Marek Marczykowski-Górecki
bb958fd1c8 core: improve handling dead domains when talking to QubesDB daemon
Provide vm.refresh(), which will force to reconnect do QubesDB daemon,
and also get new libvirt object (including new ID, if any). Use this
method whenever QubesDB call returns DisconnectedError exception. Also
raise that exception when someone is trying to talk to not running
QubesDB - instead of returning None.
2015-03-29 17:22:15 +02:00
Marek Marczykowski-Górecki
124a26ec97 core: do not undefine libvirt domain when not necessary
Libvirt will replace domain XML when trying to define the new one with
the same name and UUID - this is exactly what we need. This fixes race
condition with other processes (especially Qubes Manager), which can try
to access that libvirt domain object at the same time.
2015-03-29 16:31:56 +02:00
Marek Marczykowski-Górecki
1b428f6865 core: fix bogus return value from __init__ 2015-03-29 16:19:50 +02:00
Marek Marczykowski-Górecki
999698bd68 core: rename create_xenstore_entries, get rid of xid parameter
It have nothing to do with xenstore, so change the name to not mislead.
Also get rid of unused "xid" parameter - we should use XID as little as
possible, because it is not a simple task to keep it current.
2015-03-28 22:36:28 +01:00
Marek Marczykowski-Górecki
4dfb629dd8 Update libvirt config syntax for new version of driver domain patches
Finally accepted patches uses different syntax: <backenddomain name=.../> tag
instead of <source domain=.../>.
2015-03-21 21:12:48 +01:00
Marek Marczykowski-Górecki
7463a55f0f dispvm: do not require shmoverride loaded to start gui daemon
This isn't needed anymore because we'll show no window in invisible
mode. This allows to prepare DispVM from firstboot.
2015-03-19 10:30:18 +01:00
Marek Marczykowski-Górecki
69f8d8aecf dispvm: create /qubes-restore-complete qubesdb key
It is used by just started DispVM to notice when restore process
completed. Alternatively it could watch its own domid, but lets do it in
Xen-independent way.
2015-03-04 02:20:24 +01:00
Marek Marczykowski-Górecki
90b76b489d dispvm: start gui-daemon in "invisible mode" when preparing DispVM 2015-03-04 02:19:29 +01:00
Marek Marczykowski-Górecki
2eeea65ce6 core: do not call GUI-related RPC services, when qrexec is not running 2015-03-04 02:18:46 +01:00
Marek Marczykowski-Górecki
7265cb9d0f Merge branch 'dispvm-speedup' into dispvm-speedup3
Conflicts:
	dispvm/qubes-prepare-saved-domain.sh
2015-03-02 03:35:15 +01:00
Marek Marczykowski-Górecki
54a06f3f46 core: add dummy QubesTemplateHVm.commit_changes
It does nothing as root-cow.img isn't used by HVMs (yet), but this
function is required by qvm-template-commit.
2015-02-22 03:53:51 +01:00
Wojtek Porczyk
2b14bc88d0 core/modules: debug important VM changes 2015-02-19 21:32:43 +01:00
Marek Marczykowski-Górecki
246de96dcd core: make vm.rootcow_img a property 2015-02-11 13:59:57 +01:00
Marek Marczykowski-Górecki
cf41d94754 core: implement VM suspend
Required for proper host sleep when netvm is running.
2015-02-10 06:45:47 +01:00
Marek Marczykowski-Górecki
e67e9a4be1 Revert part of "core: remove kernel properties from DispVM and Dom0 (#948)"
This reverts DispVM part of commit 72cf3a8201.
2015-02-09 22:29:23 +01:00
Marek Marczykowski-Górecki
adfc4e0ac9 core: disks handling cleanup, fix them for TemplateHVM
Move rootcow_img to storage class, remove clean_volatile_img. And most
importantly - set source_template in QubesHVm.create_on_disk.
2015-02-09 06:02:20 +01:00
Marek Marczykowski-Górecki
2def43517a core/hvm: handle verbose option for guid 2015-02-09 05:39:44 +01:00
Marek Marczykowski-Górecki
393bb00471 core: update reporting for missing VT-x 2015-02-09 03:46:53 +01:00
Marek Marczykowski-Górecki
869675c15c core: convert memory/cpu stats to libvirt API 2015-02-09 03:28:01 +01:00
Marek Marczykowski-Górecki
4e26588bb3 core/hvm: remove xenstore code
QubesDB does not require setting up directory (and permissions), so just
remove the function.
2015-02-07 01:12:29 +01:00
Marek Marczykowski-Górecki
89f8f219bf core: changes in libvirt config for libvirt-1.2.12 2015-02-05 06:31:00 +01:00
Marek Marczykowski-Górecki
72cf3a8201 core: remove kernel properties from DispVM and Dom0 (#948)
Qubes does not keep track of those kernel versions.

Conflicts:
	core-modules/01QubesDisposableVm.py
2015-01-30 01:40:40 +01:00
Marek Marczykowski-Górecki
49d510dc65 core: prevent permissions error when VM was started by root
When VM is started by root, config file is created with root owner and
user has no write access to it. As the directory is user-writable,
delete the file first.

Conflicts:
	core-modules/000QubesVm.py
2015-01-30 01:39:57 +01:00
Marek Marczykowski-Górecki
52334bc414 core: fix firewall update code
Do not load qubes.xml again, it can cause race conditions between two
instances of the same VM objects.
Especially when VM is starting ProxyVM to which it is connected,
firewall rules could not be loaded.
2015-01-30 01:38:56 +01:00
Marek Marczykowski-Górecki
73301a67c8 core: fix vm.run(..., passio=False) handling
Long time ago passio=True was used to replace current process with
qrexec-client directly (qvm-run --pass-io was the called), but this
behaviour is not used anymore (qvm-run was the only user). And this
option was left untouched, with misleading name - one would assume that
using passio=False should disallow any I/O, but this isn't the case.

Especially qvm-sync-clock is calling clockvm.run('...', wait=True),
default value for passio=False. This causes to output data from
untrusted VM, without sanitising terminal sequences, which can be fatal.

This patch changes passio semantic to actually do what it means - when
set to True - VM process will be able to interact with
stdin/stdout/stderr. But when set to False, all those FDs will be
connected to /dev/null.

Conflicts:
	core-modules/000QubesVm.py
2015-01-30 01:38:52 +01:00
Marek Marczykowski-Górecki
7a3bce6c61 core: fix is_paused method 2014-11-29 02:58:47 +01:00
Marek Marczykowski-Górecki
592a4901c9 core: import monitorlayoutnotify instead of calling it as external script
Otherwise deadlock could happen - the script will try to get read lock
on qubes.xml, while the calling tool can already hold the lock. If that
was write lock (which is in case of qfile-daemon-dvm), the deadlock
occurs.
2014-11-21 21:45:03 +01:00
Marek Marczykowski-Górecki
1df73d31c6 core: xid is no longer local variable here 2014-11-19 12:50:32 +01:00
Marek Marczykowski-Górecki
9205c5c054 core: fix imports 2014-11-19 12:50:32 +01:00
Marek Marczykowski-Górecki
479ac1e42d core: check libvirt error on specific connection
Not global last one.
2014-11-19 12:50:32 +01:00
Rafał Wojdyła
97c793ed16 QubesVm.run(): wait for client to exit on Windows 2014-11-19 12:50:31 +01:00
Marek Marczykowski-Górecki
3ba424e6ac Use VM name as argument to qrexec-client
This is the only place where ID was used - all other places uses name.
Linux qrexec-client accepts both ID and name, but sticking to one option
will simplify things (especially Windows qrexec-client/daemon).
2014-11-19 12:50:31 +01:00
Marek Marczykowski-Górecki
def58ab911 core: typo fix 2014-11-19 12:50:30 +01:00
Marek Marczykowski-Górecki
687e004b1d windows: workaround for windows "behavior" regarding parsing exec() arguments 2014-11-19 12:50:30 +01:00
Marek Marczykowski-Górecki
27b031c59f Check for None before calling method (VM rename fix) 2014-11-19 12:50:29 +01:00
Marek Marczykowski-Górecki
c3d9b1971a Handle the case when libvirt object doesn't exists for given VM
This can be some "virtual" VM (like dom0).
2014-11-19 12:50:29 +01:00
Marek Marczykowski-Górecki
5763beb898 HVM: do not fail on non-Xen systems (without xenstore)
Currently getting Stubdom XID is (the last one?) read directly from
Xenstore as there is no libvirt function for it.
This means that even if HVM is running it can have not connection to
Xenstore. For now give -1 in such situation.
2014-11-19 12:50:29 +01:00
Marek Marczykowski-Górecki
7e355c5dad core: ignore error when PCI device already "detached"
This can be the case at startup, when all network devices are connected
to pciback module by initramfs.
2014-11-19 12:50:29 +01:00
Marek Marczykowski-Górecki
11047bf427 Use platform specific locking method
None of found existing portable locking module does support RW locks.
Use lowlevel system locking support - both Windows and Linux support
such feature.

Drop locking code in write_firewall_conf() b/c is is called with
QubesVmCollection lock held anyway.
2014-11-19 12:50:28 +01:00
Marek Marczykowski-Górecki
392b70a4d8 Create missing private.img when needed
Not only for HVM, but any VM type which support private.img.
2014-11-19 12:50:28 +01:00
Marek Marczykowski-Górecki
21c908b9b2 Move storage-related VM rename code to storage class 2014-11-19 12:50:28 +01:00
Marek Marczykowski-Górecki
396011e227 Fix initialization of storage class
Move it earlier - before first access to *_img attrs.
2014-11-19 12:50:27 +01:00
Marek Marczykowski-Górecki
7b5dd67b58 Completely move *_img attrs to QubesVmStorage class 2014-11-19 12:50:27 +01:00
Marek Marczykowski-Górecki
2457a705d0 Load Qubes DB python module only when needed.
This is temporary band aid for the python module problems.
This should also slightly speed up some tools (not all uses Qubes DB).
2014-11-19 12:50:27 +01:00
Marek Marczykowski-Górecki
a17f6ef779 Update QubesHVM to use QubesVmStorage classes
Also add external drive support to QubesXenVmStorage (move from
QubesHVM).
2014-11-19 12:50:27 +01:00
Marek Marczykowski-Górecki
66b39ac2a2 Typo fix in error message. 2014-11-19 12:50:26 +01:00
Marek Marczykowski-Górecki
4ae720956d Use file copy instead of symlink on Windows 2014-11-19 12:50:26 +01:00
Marek Marczykowski-Górecki
d91162e74d minor comment fix 2014-11-19 12:50:26 +01:00
Marek Marczykowski-Górecki
0a1f3d0a44 core: split VM images handling to separate class
This will ease handling different types of VMM (which can require
different image types, location etc).
2014-11-19 12:50:25 +01:00
Marek Marczykowski-Górecki
69d1ae645f Do not use qmemman when not present (installed) on particular VMM 2014-11-19 12:50:25 +01:00
Marek Marczykowski-Górecki
0009805041 rpm+makefile: move build/install code to Makefile files
This makes build "scripts" not tied to Fedora-specific files. Especially
ease porting to other platforms.
2014-11-19 12:50:24 +01:00
Marek Marczykowski
fb353ea615 core: fix regression in iptables rule generator
This commit:
eb11a2f Use QubesDB instead of Xenstore.
introduced regression in iptables rules generator (sed misuse...).
2014-11-19 12:50:24 +01:00
Marek Marczykowski
ff2c925e18 dispvm: use qubesdb instead of xenstore 2014-11-19 12:50:24 +01:00
Marek Marczykowski
457737b6cc QubesVm: ignore errors during debug VM config file creation
Currently <vm-dir>/<vm-name>.conf file is used only for debugging
purposes - the real one is passed directly to libvirt, without storing
on disk for it.
In some cases (e.g. qvm-clone) QubesVM.create_config_file() can be
called before VM directory exists and in this case it would fail.
Because it isn't critical fail in any means (the config file will be
recreated on next occasion) just ignore this error.

Final version most likely will have this part of code removed
completely.
2014-11-19 12:48:28 +01:00
Marek Marczykowski
f159f3e168 Use QubesDB instead of Xenstore.
Mostly done. Things still using xenstore/not working at all:
 - DispVM
 - qubesutils.py (especially qvm-block and qvm-usb code)
 - external IP change notification for ProxyVM (should be done via RPC
   service)
2014-11-19 12:48:28 +01:00
Marek Marczykowski
3f6947b87e dispvm: fix domain ID handling
Do not use obsoleted get_xid() function.
2014-11-19 12:48:27 +01:00
Marek Marczykowski
9393b5f931 Fix domain rename
libvirt_domain object needs to be recreated, so force it. Also fix
config path setting (missing extension) - create_config_file
uses it as custom config indicator (if such detected, VM settings -
especially name, would not be updated).
2014-11-19 12:48:27 +01:00