Commit Graph

77 Commits

Author SHA1 Message Date
Wojtek Porczyk
6a10daf7be Merge branch 'master' into core3-devel
Remains to be fixed:
  88cb62fc
  d2640b51
  958c2926
2016-06-13 19:03:46 +02:00
Marek Marczykowski-Górecki
767d1f0074
qvm-usb: implement usb_detach_all
QubesOS/qubes-issues#531
2016-06-02 02:49:22 +02:00
Marek Marczykowski-Górecki
d5e06bfb83
qvm-usb: issue detach call to backend domain
Make sure that even compromised frontend will be cut of (possibly
sensitive - like a webcam) device. On the other hand, if backend domain
is already compromised, it may already compromise frontend domain too,
so none of them would be better to call detach to.

QubesOS/qubes-issues#531
2016-06-02 02:45:26 +02:00
Marek Marczykowski-Górecki
52fb410deb
qvm-usb: always pass VM as object reference not a name
Make the API consistent.

QubesOS/qubes-issues#531
2016-06-02 02:44:38 +02:00
Marek Marczykowski-Górecki
d67636308f
qvm-usb: modify for USBIP-over-qrexec implementation
QubesOS/qubes-issues#531
2016-05-26 01:38:08 +02:00
Wojtek Porczyk
9eafa57539 Merge remote-tracking branch 'marmarek/master' into core3-devel
The following list is bollocks. There were many, many more.

Conflicts:
    core-modules/003QubesTemplateVm.py
    core-modules/005QubesNetVm.py
    core/qubes.py
    core/storage/__init__.py
    core/storage/xen.py
    doc/qvm-tools/qvm-pci.rst
    doc/qvm-tools/qvm-prefs.rst
    qubes/tools/qmemmand.py
    qvm-tools/qvm-create
    qvm-tools/qvm-prefs
    qvm-tools/qvm-start
    tests/__init__.py
    vm-config/xen-vm-template-hvm.xml

This commit took 2 days (26-27.01.2016) and put our friendship to test.
    --Wojtek and Marek
2016-03-03 01:13:51 +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
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
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
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
6df309351d
block: fix detection if the block device is attached anywhere 2015-07-13 00:58:11 +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
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
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
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
48fd2669cb raise correct exception 2015-02-07 01:14:22 +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
9205c5c054 core: fix imports 2014-11-19 12:50:32 +01:00
Marek Marczykowski
b8c62c0279 Wrap all VMM connection related object into QubesVMMConnection class
This makes easier to import right objects in submodules (only one
object). This also implement lazy connection - at first access, not at
module import, which speeds up tools, which doesn't need runtime
information (like qvm-prefs or qvm-service). In the future this will
ease migration from xenstore to QubesDB.

Also implement "offline mode" - operate on qubes.xml without connecting
to VMM - raise exception at such try.
This is needed to run tools during installation, where only minimal
set of services are started, especially no libvirt.
2014-11-19 12:48:26 +01:00
Marek Marczykowski
a880483092 Migration to libvirt - core part
Still not all code migrated, added appropriate TODO/FIXME comments.
2014-11-19 12:47:00 +01:00
Victor Lopez
99315fd02c support partitions on loop devices
loop device parsing should have "dXpY_style = True" in order to
correctly parse partitions on loop devices.

Reasoning:
==========
Using losetup to create a virtual SD card disk into a loop device and
creating partitions for it results in new devices within an AppVM that
look like: /dev/loop0p1 /dev/loop0p2 and so on.

However as soon as they are created, Qubes Manager rises an exception
and becomes blocked with the following message (redacted):
"QubesException: Invalid device name: loop0p1
at line 639 of file /usr/lib64/python2.7/site-
packages/qubesmanager/main.py

Details:
line: raise QubesException....
func: block_name_to_majorminor
line no.: 181
file: ....../qubes/qubesutils.py
2014-09-19 11:00:56 +02:00
Marek Marczykowski-Górecki
fcc77167a9 block: fix support for device-mapper devices 2014-06-07 04:54:15 +02:00
Marek Marczykowski-Górecki
1ed9c74d83 Rearrange code to not import PyQt on every qvm-* call
Move notification functions to separate file (out of guihelpers).
2014-06-05 01:59:42 +02:00
Marek Marczykowski-Górecki
44f38fe076 Declare file encoding for all python files, fill missing copyright headers
Without that, python do not accept UTF-8 even in comments.
2014-05-18 21:03:27 +02:00
Wojciech Zygmunt Porczyk
624ab67e86 qubesutils.py: don't fail on broken symlinks 2014-05-02 17:03:50 +02:00
Wojciech Zygmunt Porczyk
1840420331 qubesutils.py: fix get_disk_usage hidden exception 2014-04-30 15:43:35 +02:00
Wojciech Zygmunt Porczyk
4b15838009 qubesutils.py: remove imported but unused classes
This is needed to remove circular dependency with modules.

This commit is part of #822 fix.
2014-04-28 12:19:52 +02:00
Wojciech Zygmunt Porczyk
ee059df63e qubesutils.py: get_disk_usage
get_disk_usage is moved from code-modules and backup.py and rewritten not to
call external du

This commit is part of #822 fix.
2014-04-24 21:50:12 +02:00
Marek Marczykowski-Górecki
5cbfb64a57 qubesutils: enable/disable updates check on all the VMs and dom0 (#800) 2014-04-11 07:06:12 +02:00
Marek Marczykowski-Górecki
bc70581bd3 qubesutils: Add meminfo watching to QubesWatch class (#788) 2014-03-31 03:45:21 +02:00
Marek Marczykowski-Górecki
9e7b8a63bc qubesutils: reduce code duplication in QubesWatch class 2014-03-30 22:53:34 +02:00
Marek Marczykowski-Górecki
11961cbbff qvm-block: fix handling unusual devices attached to dom0
Simply get device major-minor from /dev/ device file.
This is only partial solution, because this will work only for dom0
devices, but the same problem can apply to VM.
2014-03-05 00:49:28 +01:00
Danny Fullerton
268dcfd71d Fix qvm-block crash with /dev/mdXpY devices 2014-01-08 11:51:05 +01:00
Marek Marczykowski-Górecki
27f6f0e64e Merge branch 'new-backups'
Conflicts:
	core-modules/000QubesVm.py
2013-11-29 04:00:58 +01:00
Marek Marczykowski-Górecki
c781a522d8 backups: move backup code to separate file
Also some major cleanups: Reduce some more code duplication
(verify_hmac, simplify backup_restore_prepare). Rename
backup_dir/backup_tmpdir variables to better match its purpose. Rename
backup_do_copy back to backup_do.  Require QubesVm object (instead of VM
name) as appvm param.
2013-11-25 05:41:13 +01:00
Marek Marczykowski-Górecki
657beaf655 backups: move extracted dom0 home from /var/tmp instead of copy 2013-11-25 01:11:29 +01:00
Marek Marczykowski-Górecki
e31c3ae8e7 backup: reduce volume size to 100M and limit queue length
This way backup process won't need more than 1GB for temporary files and
also will give more precise progress information. For now it looks like
the slowest element is qrexec, so without such limit, all the data would
be prepared (basically making second copy of it in dom0) while only
first few files would be transfered to the VM.
Also backup progress is calculated based on preparation thread, so when
it finishes there is some other time needed to flush all the data to the
VM. Limiting this amount makes progress somehow more accurate (but still
off by 1GB...).
2013-11-25 00:55:59 +01:00
Marek Marczykowski-Górecki
10a01010bb backups: fix handling multi-volume archive during restore
We can't wait for tar next volume prompt using stderr.readline(),
because tar don't output EOL marker after this prompt. The other way
would be switching file descriptor to non-blocking mode and using lower
level os.read(), but this looks like more error-prone way (races...).
So change idea of handling such archives: after switching to next
archive volume, simply send '\n' to tar (which will receive when
needed). When getting "*.000" file, assume that previous archive was
over and wait for previous tar process. Then start the new one.

Also don't give explicit tape length, only turn multi-volume mode on. So
will correctly handle all multi-volume archives, regardless of its size.
2013-11-25 00:48:54 +01:00
Marek Marczykowski-Górecki
7229b78bbf backups: minor reduce code duplication 2013-11-25 00:48:00 +01:00