Commit Graph

291 Commits

Author SHA1 Message Date
Bahtiar `kalkin-` Gadimov
15d5e6edbb Add Pool & XenPool 2015-11-17 19:37:18 +01:00
Bahtiar `kalkin-` Gadimov
7550fccf94 Removed WNI 2015-11-17 19:37:18 +01:00
Rusty Bird
3e3ac36f58
cp --reflink=auto to speed up clone/backup/restore on btrfs 2015-11-10 17:10:03 +00:00
Marek Marczykowski-Górecki
f714a8224b
backup: follow symbolic links
For a long time Qubes backup did not include symlinked files, which
apparently is quite common practice for users with multiple disks (for
example HDD + SSD). It is covered in documentation
(https://www.qubes-os.org/doc/secondary-storage/), but better solution
would be to simply include symlinked files.

Restore of such files would (of course) not preserve the symlinks -
normal files will be restored instead. But that's fine. If the user want
to move the data to another location, he/she can do that and restore the
symlink.

The only possible breakage from this change is having a copy (instead of
symlink) to a VM icon. But storing that symlink in a backup was broken
for some time (because of --xform usage) and it is handled during
restore, so not a real problem.

This doesn't cover all the problems with symlinked VM images - the other
one is qvm-block behaviour, which would treat such images as non-system
disks, so easily detachable (which would break VM operation). But that's
another story.

Fixes QubesOS/qubes-issues#1384
2015-11-07 05:03:54 +01:00
Marek Marczykowski-Górecki
8275e828af
backup: move existing directories out of the way during restore
In most cases it would be some leftover after failed restore, or even
the reason why the user is restoring a VM in the first place. Move it to
nearby directory, but do not remove - backup tool should _never_ remove
any data.

When the pre-existing directory would not be moved, restore utility
(`shutil.move`) would place the data inside of that directory, with
additional directory level (for example `/var/lib/qubes/appvms/work/work`),
which would be wrong and would later fail on `vm.verify_files`. And more
importantly - such VM would not work.

Fixes QubesOS/qubes-issues#1386
2015-11-07 05:03:54 +01:00
Marek Marczykowski-Górecki
0695e7ba78
utils/QubesWatch: register libvirt event loop only when really launched
Registering event implementation in libvirt and then not calling it is
harmful, because libvirt expects it working. Known drawbacks:
- keep-alives are advertised as supported but not really sent (cause
  dropping connections)
- connections are not closed (sockets remains open, effectively leaking
  file descriptors)

So call libvirt.virEventRegisterDefaultImpl only when it will be really
used (libvirt.virEventRunDefaultImpl called), which means calling it in
QubesWatch. Registering events implementation have effect only on new
libvirt connections, so start a new one for QubesWatch.

Fixes QubesOS/qubes-issues#1380
2015-11-07 03:51:51 +01:00
Marek Marczykowski-Górecki
93b7b3cb72
utils/QubesWatch: improve error handling (minor) 2015-11-07 03:51:50 +01:00
Marek Marczykowski-Górecki
d38883833a
core: ensure that QubesDB connections are closed when disposing a VM collection
There are some circular dependencies (TemplateVM.appvms,
NetVM.connected_vms, and probably more), which prevents garbage
collector from cleaning them.

Fixes QubesOS/qubes-issues#1380
2015-11-07 03:51:50 +01:00
Marek Marczykowski-Górecki
de295136ce
Fix "utils/QubesWatch: use timers to retry QubesDB watch registration" 2015-10-27 21:47:01 +01:00
Wojtek Porczyk
ea44c0acf3 qubes: pylint fixes
Fix bunch of errors and warnings.
2015-10-05 23:49:39 +02:00
Wojtek Porczyk
c538d536c8 core3: move qmemman
This is part of fixing qvm-start.

qmemman was moved with minimal touching, mainly module names.

Moved function parsing human-readable sizes from core2. This function is
wrong, because it treats k/M/G as 1024-based, but leave it for now.
2015-10-05 12:46:14 +02:00
Wojtek Porczyk
fcdb579bab core3: qubesmanager notifying extension
core/notify.py was excavated and tray notifying remnants were moved to
qubes.log. They are unused as yet.

Also extension events are fixed.
2015-10-05 12:46:14 +02:00
Marek Marczykowski-Górecki
64590423fd
Merge branch 'bug1110'
Fixes QubesOS/qubes-issues#1110
2015-10-02 01:58:46 +02:00
Marek Marczykowski-Górecki
ef6095662e
utils/QubesWatch: register domain watches on VIR_DOMAIN_EVENT_RESUMED
QubesVM.start() first creates domain as paused, completes its setup
(including starting qubesdb-daemon and creating appropriate entries),
then resumes the domain. So wait for that resume to be sure that
`qubesdb-daemon` is already running and populated.

QubesOS/qubes-issues#1110
2015-09-25 22:02:53 +02:00
Marek Marczykowski-Górecki
5f0d564051
utils/QubesWatch: use timers to retry QubesDB watch registration
QubesWatch._register_watches is called from libvirt event callback,
asynchronously to qvm-start. This means that `qubesdb-daemon` may
not be running or populated yet.

If first QubesDB connection (or watch registration) fails, schedule next
try using timers in libvirt event API (as it is base of QubesWatch
mainloop), instead of some sleep loop. This way other events will be
processed in the meantime.

QubesOS/qubes-issues#1110
2015-09-25 20:37:44 +02:00
Marek Marczykowski-Górecki
9205fbb336 backup: fix R2B3 and older backup restore (#1124)
Similar issue to qubesos/qubes-issues#1124
2015-09-06 00:06:09 +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
26cf723841
core/hvm: fix external disks handling 2015-08-09 21:21:27 +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
8f862cdf69
core/hvm: check if VM serving cdrom content is running 2015-07-25 04:17:59 +02:00
Marek Marczykowski-Górecki
6df309351d
block: fix detection if the block device is attached anywhere 2015-07-13 00:58:11 +02:00
Marek Marczykowski-Górecki
4bf73a5d7f Increase default swiotlb size to 16MB (#1038)
Fixes qubesos/qubes-issues#1038
2015-07-01 04:46:46 +02:00
Marek Marczykowski-Górecki
310ba9f1df block: do not treat disks of not running VMs as used
There are legitimate use cases when one want to attach disk of one VM to
some other. Do not try to detach the disk from powered down VM in such
case.
2015-07-01 04:42:44 +02:00
Marek Marczykowski-Górecki
d9c2990747 core: fix creation of private.img at VM startup
This code is used when VM is migrated from older system, where HVM
didn't have private.img.
2015-07-01 04:41:09 +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
Wojtek Porczyk
8afba4c5e9 core3 move: storage/* 2015-06-29 17:39:26 +02:00
Wojtek Porczyk
b623a71d87 core3 move: QubesVmCollection
This got split to qubes.Qubes and qubes.VMCollection.
From now on, VMCollection is a stupid bag. Some parts went elsewhere.
2015-06-29 17:39:23 +02:00
Wojtek Porczyk
f3673dd34c core3 move: class QubesVmLabel 2015-06-29 17:39:23 +02:00
Wojtek Porczyk
778571fe8d core3 move: class QubesHost 2015-06-29 17:39:23 +02:00
Wojtek Porczyk
cec3db993d core3 move: class QubesVMMConnection 2015-06-29 17:39:22 +02:00
Wojtek Porczyk
e1a6fb2859 core3 move: class QubesException 2015-06-29 17:39:22 +02:00
Marek Marczykowski-Górecki
b1f4e6d15c backup: fix missing 'unused' variables
Actually the 'vm' variable is used - in eval'ed statement.
2015-05-11 02:31:56 +02:00
Marek Marczykowski-Górecki
13f0f64d0a backup: code style, no functional change (part 2)
Remove unused variables, rename potentially coliding one.
2015-05-03 14:57:28 +02:00
Marek Marczykowski-Górecki
9ec0580840 backup: code style fixes, no functional change (part 1)
Indentation, break long lines, use is/is not None instead of ==/!=.
2015-05-03 14:57:28 +02:00
Marek Marczykowski-Górecki
868ee83093 block: trigger QubesDB watches after attaching/detaching device
Since libvirt do not support such events (at least for libxl driver), we
need some way to notify qubes-manager when device is attached/detached.
Use the same protocol as for connect/disconnect but on the target
domain.
2015-04-14 23:08:52 +02:00
Marek Marczykowski-Górecki
e1da1fb3c1 block: fixes for dom0-backed devices and dead domains 2015-04-14 23:07:54 +02:00
Marek Marczykowski-Górecki
dbb43f6035 core/storage: fix disk handling for HVM template
Currently HVM template do not have root-cow.img (also do not use 2-layer
device-mapper as PV VMs), so vm.is_template() check isn't enough.
2015-04-06 00:21:38 +02:00
Marek Marczykowski-Górecki
a6448e073c block: fix handling non-dom0 backend
The libvirt XML config syntax was changed - the element is named
<backenddomain/>.
2015-04-04 16:18:10 +02:00
Marek Marczykowski-Górecki
6dac228648 backup: backup any template marked to do so, even if installed by rpm 2015-03-31 05:54:41 +02:00
Marek Marczykowski-Górecki
01e208d5ec utils/QubesWatch: provide domain UUID to domain_callback 2015-03-30 00:08:00 +02:00
Marek Marczykowski-Górecki
30fadfa994 core/block: handle any QubesDB exception 2015-03-29 23:47:39 +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
f8ad78d174 core: use absolute imports in qubesutils 2015-03-29 17:33:02 +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
c878beb25d utils/block: catch an exception when talking to disconnected qubesdb
This can happen for example when domain disappeared in the meantime.
2015-03-26 22:10:49 +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
ae6ca5c0a3 core: prevent taking database lock twice 2015-02-22 01:25:51 +01:00
Marek Marczykowski-Górecki
b858488719 Merge remote-tracking branch 'woju/master' 2015-02-21 03:09:29 +01:00
Marek Marczykowski-Górecki
e65842322a core: hold the lock after QubesVmCollection.save()
The statement that unlock_db() is always called directly after save() is
no longer true - tests holds the lock all the time, doing multiple saves
in the middle.
2015-02-21 00:25:50 +01:00
Wojtek Porczyk
2b14bc88d0 core/modules: debug important VM changes 2015-02-19 21:32:43 +01:00
Wojtek Porczyk
241cf2e089 core/qubes.py: ensure that all default_*vm are present in collection
References to invalid qids are None'd. Failure to do so may cause KeyErrors even
on fixing ntpd service during instantiation of QubesVmCollection.
2015-02-19 21:32:43 +01:00
Marek Marczykowski-Górecki
bdae560770 backup: fix deadlock on error while receiving backup from a VM
When qfile-dom0-unpacker detects an error, it sends error report to
stdout and terminate (so stdout is closed). That close should be
transferred to the VM process (as EOF on its stdin), which will signal
it to stop sending the data and handle error report.
Also qrexec-client holds the connection until both stdin and
stdout are closed.
So when that EOF is missing, tar2qfile will not detect error report and
still tries to send the data and qrexec-client will hold the
connection while receiving process is long dead.

To prevent that deadlock from happening, close FD in python code, so
qfile-dom0-unpacker will be the last owner of write end of the pipe.
When it closes its stdout, qrexec-client will receive EOF at its stdin.
2015-02-18 21:41:22 +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
869675c15c core: convert memory/cpu stats to libvirt API 2015-02-09 03:28:01 +01:00
Marek Marczykowski-Górecki
48fd2669cb raise correct exception 2015-02-07 01:14:22 +01:00
Marek Marczykowski-Górecki
1da8ab5823 core: Add missing import 2015-01-08 03:55:02 +01:00
Marek Marczykowski-Górecki
adff88101a Rework QubesWatch implementation for libvirt events 2014-12-26 02:56:38 +01:00
Marek Marczykowski-Górecki
d4ab70ae9d core: update qvm-block code for HAL API
Use QubesDB to get list of devices, call libvirt methods to
attach/detach devices.
2014-12-12 03:59:01 +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
Wojciech Zygmunt Porczyk
6b0a5f9738 storage/xen.py: always initialise args['otherdevs'] 2014-11-19 12:50:32 +01:00
Marek Marczykowski-Górecki
9205c5c054 core: fix imports 2014-11-19 12:50:32 +01:00
Rafał Wojdyła
7e8978d278 wni: changed qrexec agent path environment variable name 2014-11-19 12:50:32 +01:00
Rafał Wojdyła
f91d6e93f6 wni: set random password on user creation 2014-11-19 12:50:31 +01:00
Rafał Wojdyła
ccd04c7c8f wni: properly get user profiles directory 2014-11-19 12:50:31 +01:00
Rafał Wojdyła
81fb2b696b wni: vm users can't change their password 2014-11-19 12:50:31 +01:00
Rafał Wojdyła
b4d827d5e8 wni: remove user profiles on domain removal 2014-11-19 12:50:31 +01:00
Rafał Wojdyła
b6a379e94a Fixed PyQt4 import in guihelpers 2014-11-19 12:50:31 +01:00
Marek Marczykowski-Górecki
fef2672935 settings-wni: get installation directory from windows registry 2014-11-19 12:50:31 +01:00
Marek Marczykowski-Górecki
803e128b8e wni: Add qrexec-client path to WNI settings 2014-11-19 12:50:30 +01:00
Marek Marczykowski-Górecki
071a01d29e guihelpers: Import PyQt only when needed 2014-11-19 12:50:30 +01:00
Marek Marczykowski-Górecki
06189b4a5b wni: set path to qrexec-daemon 2014-11-19 12:50:30 +01:00
Marek Marczykowski-Górecki
63eccac025 wni: use win32net module for creating new user
This require UAC disabled (or already started as administrator), but
works much more reliable ("net user" sometimes fails _silently_).
2014-11-19 12:50:30 +01:00
Marek Marczykowski-Górecki
e5c2448af4 copy & paste error (VM rename fix) 2014-11-19 12:50:30 +01:00
Marek Marczykowski-Górecki
4300d778a5 qvm-toos: import dbus only when needed
Void import errors when 'dbus' module not really needed.
2014-11-19 12:50:29 +01:00
Marek Marczykowski-Górecki
d88da1e66b wni: add missing parameter 2014-11-19 12:50:29 +01:00
Marek Marczykowski-Górecki
f6729b4968 wni: use generated password 2014-11-19 12:50:29 +01:00
Marek Marczykowski-Górecki
5dbad01796 Fill some more WNI settings
Especially use new "wni" libvirt driver.
2014-11-19 12:50:29 +01:00
Marek Marczykowski-Górecki
ea68c6a766 xen: fix template vm storage code 2014-11-19 12:50:28 +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
a5a2c0b97c Revert "release qubes.xml lock on object destroy"
This reverts commit 39e056b74acca3854c5707d8f2cbcd199b8cac75.
This change rely on reverted python-locking use.
2014-11-19 12:50:28 +01:00
Marek Marczykowski-Górecki
5fb1991ad5 QubesWniVmStorage: prefix system user with "qubes-vm-". 2014-11-19 12:50:28 +01:00
Marek Marczykowski-Górecki
f927f12e39 QubesWniVmStorage: pass all positional parameters to base class 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
ada5ebd784 Use "None" in *_img attr for "not applicable"
Some VM types do not have particular disk image. Instead of enumerating
cases in storage class, signal unused image from VM class by setting
appropriate attr to None.
2014-11-19 12:50:27 +01:00
Marek Marczykowski-Górecki
e2bea656b4 Add vm-configs for WNI 2014-11-19 12:50:27 +01:00
Marek Marczykowski-Górecki
ec37a4e681 Rename vm-configs directory to be more generic 2014-11-19 12:50:27 +01:00
Marek Marczykowski-Górecki
35ecfc82ef wni: QubesWniVmStorage and update settings file 2014-11-19 12:50:27 +01:00
Marek Marczykowski-Górecki
e8715cd561 release qubes.xml lock on object destroy
This will ensure that lock will be released even in case of error.
2014-11-19 12:50:27 +01:00
Marek Marczykowski-Górecki
50188c8832 Use relative path in system_path dict instead of path templates
This will allow use of correct slashes/backslashes (os.path.join instead
of hardcoded '/').
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
b323a4d1e3 core: Fix handling the case when no settings file present. 2014-11-19 12:50:26 +01:00
Marek Marczykowski-Górecki
50e44ce22d makefile: Improve readability of settings.py install command 2014-11-19 12:50:26 +01:00
Marek Marczykowski-Górecki
ec17f7d329 core/xen: setup xen-specific defaults in separate settings file 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
a8bee8d978 Ignore error when 'xen.lowlevel.xs' doesn't exists
There are still few uses of direct xenstore access, most of them are
xen-specific (so doesn't need to be portable). For now simply don't
connect to xenstore when no 'xen.lowlevel.xs' module present. It will
break such xen-specific accesses - it must be somehow reworked - either
by adding appropriate conditionals, or moving such code somewhere else
(custom methods of libvirt driver?).
2014-11-19 12:50:25 +01:00
Marek Marczykowski-Górecki
bc58ca5edb Remove import xen.lowlevel.xc
There is still use of it: QubesHost.get_free_xen_memory and
QubesHost.measure_cpu_usage. Will migrate them to libvirt later (for now
some things will be broken - namely qubes-manager).
2014-11-19 12:50:25 +01:00
Marek Marczykowski-Górecki
6193b4fea3 Add support for VMM-specific settings. 2014-11-19 12:50:25 +01:00
Marek Marczykowski-Górecki
80c89cc91c Delay resolving system_path['qubes_base_dir']
So changes made by os/vmm-specific settings would be taken into account.
2014-11-19 12:50:25 +01:00
Marek Marczykowski-Górecki
f6835346d4 Move initialization code at the end of file
So all of it will be in one place.
2014-11-19 12:50:25 +01:00