Commit Graph

342 Commits

Author SHA1 Message Date
Marek Marczykowski-Górecki
a0723a9e32
storage/kernels: refuse changes to 'rw' and 'revisions_to_keep'
This pool driver support only rw=False and revisions_to_keep=0 volumes.
Since there is API for changing those properties dynamically, block it
at pool driver level, instead of silently ignoring them.
2018-03-20 16:52:46 +01:00
Rusty Bird
1743c76ca9
storage/reflink: reorder start() to be more readable
This also makes slightly more sense in the exotic (and currently unused)
case of restarting a crashed snap_on_start *and* save_on_stop volume.
2018-03-12 16:38:56 +00:00
Rusty Bird
31810db977
storage/reflink: simplify 2018-03-11 17:39:51 +00:00
Rusty Bird
c382eb3752
storage/reflink: let _remove_empty_dir() ignore ENOTEMPTY 2018-03-11 17:39:51 +00:00
Rusty Bird
023cb49293
storage/reflink: show size in refused volume shrink message
Like e6bb282 did for lvm.
2018-03-11 15:34:56 +00:00
Rusty Bird
c31d317c63
storage/reflink: fsync() after resizing existing file
Ensure that the updated metadata is written to disk.
2018-03-11 15:34:55 +00:00
Marek Marczykowski-Górecki
1774be1c69
storage/kernel: skip modules.img block device if kernel dir doesn't have it
Some kernels (like pvgrub2) may not provide modules.img and it isn't an
error. Don't break VM startup in that case, skip that device instead.

Fixes QubesOS/qubes-issues#3563
2018-02-27 04:35:05 +01:00
Marek Marczykowski-Górecki
7731a56daa
Merge remote-tracking branch 'qubesos/pr/192'
* qubesos/pr/192:
  storage/lvm: add more details to refused volume shrink message
  tests: storage/lvm resize
  storage/lvm: fix resizing not persistent volumes
2018-02-22 19:46:11 +01:00
Rusty Bird
37e1aedfa3
reflink: style fix 2018-02-16 21:47:39 +00:00
Rusty Bird
c871424fb0
storage: typo fix 2018-02-16 21:47:37 +00:00
Rusty Bird
f6542effc5
lvm_thin: _remove_revisions() on revisions_to_keep==0
If revisions_to_keep is 0, it may nevertheless have been > 0 before, so
it makes sense to call _remove_revisions() and hold back none (not all)
of the revisions in this case.
2018-02-16 21:47:36 +00:00
Rusty Bird
ade49d44b7
lvm_thin: don't purge one revision too few
We just added one that must be taken into account.
2018-02-16 21:47:35 +00:00
Rusty Bird
86998b0815
lvm_thin: really remove revision 2018-02-16 21:47:33 +00:00
Rusty Bird
9f468f93f5
lvm_thin: fill in volume's revisions_to_keep from pool
Otherwise, the base class defaults revisions_to_keep to 0.
2018-02-16 21:47:32 +00:00
Rusty Bird
1695a732b8
file-reflink, a storage driver optimized for CoW filesystems
This adds the file-reflink storage driver. It is never selected
automatically for pool creation, especially not the creation of
'varlibqubes' (though it can be used if set up manually).

The code is quite small:

               reflink.py  lvm.py      file.py + block-snapshot
    sloccount  334 lines   447 (134%)  570 (171%)

Background: btrfs and XFS (but not yet ZFS) support instant copies of
individual files through the 'FICLONE' ioctl behind 'cp --reflink'.
Which file-reflink uses to snapshot VM image files without an extra
device-mapper layer. All the snapshots are essentially freestanding;
there's no functional origin vs. snapshot distinction.

In contrast to 'file'-on-btrfs, file-reflink inherently avoids
CoW-on-CoW. Which is a bigger issue now on R4.0, where even AppVMs'
private volumes are CoW. (And turning off the lower, filesystem-level
CoW for 'file'-on-btrfs images would turn off data checksums too, i.e.
protection against bit rot.)

Also in contrast to 'file', all storage features are supported,
including

    - any number of revisions_to_keep
    - volume.revert()
    - volume.is_outdated
    - online fstrim/discard

Example tree of a file-reflink pool - *-dirty.img are connected to Xen:

    - /var/lib/testpool/appvms/foo/volatile-dirty.img
    - /var/lib/testpool/appvms/foo/root-dirty.img
    - /var/lib/testpool/appvms/foo/root.img
    - /var/lib/testpool/appvms/foo/private-dirty.img
    - /var/lib/testpool/appvms/foo/private.img
    - /var/lib/testpool/appvms/foo/private.img@2018-01-02T03:04:05Z
    - /var/lib/testpool/appvms/foo/private.img@2018-01-02T04:05:06Z
    - /var/lib/testpool/appvms/foo/private.img@2018-01-02T05:06:07Z
    - /var/lib/testpool/appvms/bar/...
    - /var/lib/testpool/appvms/...
    - /var/lib/testpool/template-vms/fedora-26/...
    - /var/lib/testpool/template-vms/...

It looks similar to a 'file' pool tree, and in fact file-reflink is
drop-in compatible:

    $ qvm-shutdown --all --wait
    $ systemctl stop qubesd
    $ sed 's/ driver="file"/ driver="file-reflink"/g' -i.bak /var/lib/qubes/qubes.xml
    $ systemctl start qubesd
    $ sudo rm -f /path/to/pool/*/*/*-cow.img*

If the user tries to create a fresh file-reflink pool on a filesystem
that doesn't support reflinks, qvm-pool will abort and mention the
'setup_check=no' option. Which can be passed to force a fallback on
regular sparse copies, with of course lots of time/space overhead. The
same fallback code is also used when initially cloning a VM from a
foreign pool, or from another file-reflink pool on a different
mountpoint.

'journalctl -fu qubesd' will show all file-reflink copy/rename/remove
operations on VM creation/startup/shutdown/etc.
2018-02-12 21:20:05 +00:00
Marek Marczykowski-Górecki
e6bb2828f1
storage/lvm: add more details to refused volume shrink message
Include old and new size.
2018-02-07 02:07:25 +01:00
Marek Marczykowski-Górecki
7903dc53f9
storage/lvm: fix resizing not persistent volumes
Even when volume is not persistent (like TemplateBasedVM:root), it
should be resizeable. Just the new size, similarly to the volume
content, will be reverted after qube shutdown.

Additionally, when VM is running, volume resize should affect _only_ its
temporary snapshot. This way resize can be properly reverted together
with actual volume changes (which include resize2fs call).

Fixes QubesOS/qubes-issues#3519
2018-02-07 02:07:25 +01:00
Marek Marczykowski-Górecki
bcf42c13fa
storage/lvm: check for LVM LV existence and type when creating ThinPool
Check if requested thin pool exists and really is thin pool.

QubesOS/qubes-issues#3438
2018-01-12 05:12:08 +01:00
Marek Marczykowski-Górecki
377f331d52
storage/lvm: fix size reporting just after creating LV
Force cache refresh after registering new pool - it might be just
created.

QubesOS/qubes-issues#3438
2018-01-11 03:56:30 +01:00
Marek Marczykowski-Górecki
32c6083e1c
Make pylint happy
Fix thing detected by updated pylint in Travis-CI
2017-12-21 18:19:10 +01:00
Marek Marczykowski-Górecki
96bd734852
storage/lvm: clean -snap LV on volume removal 2017-12-14 23:26:52 +01:00
Marek Marczykowski-Górecki
81f455e15d
storage/file: move revisions_to_keep restrictions to property setter
Do not check for accepted value only in constructor, do that in property
setter. This will allow enforcing the limit regardless of how the value
was set.

This is preparation for dynamic revisions_to_keep change.

QubesOS/qubes-issues#3256
2017-11-07 02:57:59 +01:00
Marek Marczykowski-Górecki
439d9b87ff
storage/lvm: fix importing different-sized volume from another pool
Fixes QubesOS/qubes-issues#3257
2017-11-07 02:57:59 +01:00
Marek Marczykowski-Górecki
f3455b5d99
storage/file: fix preserving spareness on volume clone
Force creating sparse file, even if source volume is not such file (for
example block device).

Reported by @na--
QubesOS/qubes-issues#3255
2017-11-07 02:57:58 +01:00
Marek Marczykowski-Górecki
e76372b934
storage: add size and usage properties to pool object
Add Pool.size and Pool.usage to the API. Implement them for LVM and File
pools. Add appropriate tests.

QubesOS/qubes-issues#3240
2017-11-07 02:57:58 +01:00
Marek Marczykowski-Górecki
49e35e66aa
storage: improve error reporting
- make it clear that failed qubes.ResizeDisk service call means the need
to resize filesystem manually (but not necessarily the volume itself)
- propagate exceptions raised by async storage pool implementations

Related QubesOS/qubes-issues#3173
2017-10-21 03:35:01 +02:00
Marek Marczykowski-Górecki
836d9f902a
Merge branch 'bug3164'
* bug3164:
  tests: add regression test for #3164
  storage/lvm: make sure volume cache is refreshed after changes
  storage/lvm: fix Volume.verify()
  storage/lvm: remove old volume only after successfully cloning new one
2017-10-16 04:28:26 +02:00
Marek Marczykowski-Górecki
08583af1ff
storage/lvm: make sure volume cache is refreshed after changes
Even if start/stop fails, still refresh the cache. The failed operation
might still modified something.
2017-10-16 00:44:52 +02:00
Marek Marczykowski-Górecki
145ccfb34e
storage/lvm: fix Volume.verify()
This function is supposed to raise an exception if something is wrong,
not just return False. Document this.
2017-10-16 00:43:10 +02:00
Marek Marczykowski-Górecki
021047f950
storage/lvm: remove old volume only after successfully cloning new one
In some cases, it may happen that new volume (`self._vid_snap`) does not
exists. This is normally an error, but even in such a case, do not
remove the only remaining instance of volume (`self.vid`). Instead,
rename it temporarily and remove only after new volume is successfully
cloned.

Fixes QubesOS/qubes-issues#3164
2017-10-13 01:11:55 +02:00
Marek Marczykowski-Górecki
2164a8d7b8
Change license to LGPL v2.1+
See this thread for reasoning and acceptance from contributors:
https://groups.google.com/d/topic/qubes-devel/G7KzrfU0lWY/discussion
"Changing qubes-core-admin license to LGPL v2.1+"
2017-10-12 00:11:50 +02:00
Marek Marczykowski-Górecki
b8d45c214d
storage/lvm: don't crash when resizing to the same size
This applies to qvm-template-postprocess, which at the beginning try to
resize root volume to appropriate size. It makes more sense to silently
succeed here, instead of forcing every client-side utility to check if
the volume have already desired size.
2017-10-08 18:37:25 +02:00
Marek Marczykowski-Górecki
6091bbbe88
storage/lvm: fix size units on resize
lvextend uses MiB, not MB.
2017-10-03 18:46:39 +02:00
Marek Marczykowski-Górecki
34125d915b
storage: fix method name in LinuxModules volume
It's `import_volume`, not `clone`.
2017-09-29 11:53:01 +02:00
Nicolai Søborg
9d797cc864
lvm->init_cache: fix incorrect max splits 2017-09-13 18:50:02 +02:00
Nicolai Søborg
c30131633b Fix service qubesd not working with some locales
On certain locales (e.g. danish) `usage_percent` will output a comma-separated number, which will make `attr` point the last two decimal points, s.t. `return vol_info['attr'][4] == 'a'` (in the `verify` func) will fail and `qubesd` wont run.
2017-09-12 01:57:49 +02:00
Marek Marczykowski-Górecki
6e5fe58128
storage/lvm: fix Volume() instance init when physical volume is unavailable
First, cache objects created with init_volume - this is the only place
where we have full volume configuration (including snap_on_start and
save_on_stop properties).
But also implement get_volume method, to get a volume instance for given
volume id. Such volume instance may be incomplete (other attributes are
available only in owning domain configuration), but it will be enough
for basic operations - like cheching and changing its size, cloning
etc.
Listing volumes still use list of physically present volumes.

This makes it possible to start qubesd service, without physical
presence of some storage devices. Starting VMs using such storage would
still fail, of course.

Fixes QubesOS/qubes-issues#2960
2017-08-12 22:44:03 +02:00
Marek Marczykowski-Górecki
9ad85a3dff
storage: fix getting list of pool driver parameters
function.func_code existed in python2. Use inspect module (instead of
__code__ attribute).
2017-08-12 22:42:30 +02:00
Marek Marczykowski-Górecki
3338854b1c
storage: fix storage.import_data_end when given Volume instance
Leftover from '0f12870 storage: use direct object references, not only
identifiers'
2017-08-12 22:39:41 +02:00
Marek Marczykowski-Górecki
a833692c63
storage/lvm: extend volume snapshot of running VM too
Extend both backing volume as well as current snapshot, so the increased
size is visible immediately to the user.

Fixes QubesOS/qubes-issues#2982
2017-08-06 20:54:10 +02:00
Marek Marczykowski-Górecki
b9c217704c
storage/file: fix disk usage reporting
Do not report root image usage in template-based VMs. This space is used
only once - by template.
2017-07-30 18:36:23 +02:00
Marek Marczykowski-Górecki
76640df091
Merge branch 'tests-storage'
* tests-storage:
  tests: register libvirt events
  tests: even more agressive cleanup in tearDown
  app: do not wrap libvirt_conn.close() in auto-reconnect wrapper
  api: keep track of established connections
  tests: drop VM cleanup from tearDownClass, fix asyncio usage in tearDown
  storage: fix Storage.clone and Storage.clone_volume
  tests: more tests fixes
  firewall: raise ValueError on invalid hostname in dsthost=
  qmemman: don't load qubes.xml
  tests: fix AdminVM test
  tests: create temporary files in /tmp
  tests: remove renaming test - it isn't supported anymore
  tests: various fixes for storage tests
  tests: fix removing LVM volumes
  tests: fix asyncio usage in some tests
  tests: minor fixes to api/admin tests
  storage/file: create -cow.img only when needed
  storage: move volume_config['source'] filling to one place
  app: do not create 'default' storage pool
  app: add missing setters for default_pool* global properties
2017-07-29 05:01:42 +02:00
Marek Marczykowski-Górecki
639fa26079
Merge branch 'qdb-watch'
* qdb-watch:
  tests: add qdb_watch test
  ext/block: make use of QubesDB watch
  vm: add API for watching changes in QubesDB
  vm: optimize imports
  api/admin: don't send internal events in admin.Events
  Add explanation why admin.vm.volume.Import is a custom script
  Follow change of qubesdb path return type
  Rename vm.qdb to vm.untrusted_qdb
2017-07-29 05:01:13 +02:00
Marek Marczykowski-Górecki
46bfa14d08
storage/lvm: make sure that volumes have /dev entries when export() is called
In some cases (even manual manipulation) those files may not be present
- especially because thin snapshots do not have nodes in /dev by default.
2017-07-29 04:47:44 +02:00
Marek Marczykowski-Górecki
910f793c61
storage: fix Storage.clone and Storage.clone_volume
1. Volume.import_volume expect volume to be created first.
2. asyncio.wait do not accept generator, it must be concrete iterable.
2017-07-26 03:26:59 +02:00
Marek Marczykowski-Górecki
4208897146
storage/file: create -cow.img only when needed
Do not create it at volume creation time. It it needed only when VM is
running, so create it just before startup only.

QubesOS/qubes-issues#2256
2017-07-26 03:26:11 +02:00
Marek Marczykowski-Górecki
c5667791e8
storage: move volume_config['source'] filling to one place
Don't set 'source' volume in various places (each VM class constructor
etc), do it as part of volume initialization. And when it needs to be
re-calculated, call storage.init_volume again.

This code was duplicated, and as usual in such a case, those copies
were different - one have set 'size', the other one not.

QubesOS/qubes-issues#2256
2017-07-26 03:26:11 +02:00
Marek Marczykowski-Górecki
3a21e1f1b3
app: do not create 'default' storage pool
Since we have app.default_pool* properties, create appropriately named
pool and let those properties choose the right pool. This also means we
don't need to specify pool name in default volume config anymore

QubesOS/qubes-issues#2256
2017-07-25 06:20:42 +02:00
Marek Marczykowski-Górecki
1759bca00f
Rename vm.qdb to vm.untrusted_qdb
QubesDB can be freely modified by a VM, so one should take care when
reading any data retrieved from it.

Fixes QubesOS/qubes-issues#2934
2017-07-24 13:01:55 +02:00
Marek Marczykowski-Górecki
088c838ac3
storage: typo fix in comment 2017-07-20 12:19:02 +02:00
Marek Marczykowski-Górecki
c6e09b5a99
storage: fix resize and revert handling
- fix coroutine calling from Admin API
 - fix off-by-one error in resize
 - adjust tests
2017-07-18 01:42:37 +02:00
Marek Marczykowski-Górecki
ab7ed776f9
Merge branch 'dispvm-fix'
* dispvm-fix:
  storage: add comment about source volume lookup
  vm/dispvm: convert DispVM related function to coroutines
  vm/dispvm: fix DispVM storage definition
2017-07-14 01:13:20 +02:00
Marek Marczykowski-Górecki
1e45d297b3
storage: add comment about source volume lookup 2017-07-12 21:37:12 +02:00
Marek Marczykowski-Górecki
f2f89c7b0c
storage: do not use deepcopy on volume configs
There may be Pool or Volume object references, which is intentional to
keep them as is - not copy whole Pool/Volume objects.
2017-07-12 21:33:14 +02:00
Marek Marczykowski-Górecki
148d1cda78
vm/dispvm: fix DispVM storage definition
Specify empty 'source' field, so it gets filled with appropriate
template's images. Then also fix recursive 'source' handling - DispVM
root volume should point at TemplateVM's root volume as a source, not a
AppVM's one - which is also only a snapshot.

Fixes QubesOS/qubes-issues#2896
2017-07-08 02:58:21 +02:00
Marek Marczykowski-Górecki
12adf8bede
storage/lvm: major cleanup, update
- remove obsolete volume types, use snap_on_start/save_on_stop directly
- handle multiple revisions
- implement is_outdated()

QubesOS/qubes-issues#2256
2017-07-04 14:25:09 +02:00
Marek Marczykowski-Górecki
c7ca4a445e
storage/kernels: support only save_on_stop=False volumes
LinuxKernel pool support only read-only volumes, so save_on_stop=True
doesn't make sense. Make it more explicit - raise NotImplementedError
otherwise.
Also, migrate old configs where snap_on_start=True, but no source was
given.

QubesOS/qubes-issues#2256
2017-07-04 14:25:08 +02:00
Marek Marczykowski-Górecki
0e554296e3
storage: drop 'internal' and 'removable' volume properties
Since dynamic volumes (qvm-block) are moved to devices API, those two
are not needed anymore.

QubesOS/qubes-issues#2256
2017-07-04 14:25:08 +02:00
Marek Marczykowski-Górecki
317d140f46
storage/file: major FilePool/FileVolume cleanup and documentation
This driver isn't used in default Qubes 4.0 installation, but if we do
have it, let it follow defined API and its own documentation. And also
explicitly reject not supported operations:
 - support only revisions_to_keep<=1, but do not support revert() anyway
 (implemented version were wrong on so many levels...)
 - use 'save_on_stop'/'snap_on_start' properties directly instead of
 obsolete volume types
 - don't call sudo - qubesd is running as root
 - consistently use path, path_cow, path_source, path_source_cow

Also, add tests for BlockDevice instance returned by
FileVolume.block_device().

QubesOS/qubes-issues#2256
2017-07-04 14:25:07 +02:00
Marek Marczykowski-Górecki
1a1dd3dba2
storage: make default pool configurable
Do not always use pool named 'default'. Instead, have global
`default_pool` property to specify default storage pools.
Additionally add `default_pool_*` properties for each VM property, so
those can be set separately.

QubesOS/qubes-issues#2256
2017-07-04 14:25:06 +02:00
Marek Marczykowski-Górecki
82c3f85042
storage: add API documentation
QubesOS/qubes-issues#2256
2017-07-04 04:11:14 +02:00
Marek Marczykowski-Górecki
5971873680
storage: drop functions not being part of the API
commit/recover/reset should really be handled in start/stop. Nothing
stops specific pool implementation to define such functions privately.

QubesOS/qubes-issues#2256
2017-07-04 04:11:14 +02:00
Marek Marczykowski-Górecki
820539e909
storage: make volume snap_on_start/save_on_stop explicit
Always define those properties, always include them in volume config.
Also simplify overriding pool based on volume type defined by those:
override pool unless snap_on_start=True.

QubesOS/qubes-issues#2256
2017-07-04 04:11:14 +02:00
Marek Marczykowski-Górecki
697eb05c20
storage: drop rename support
Since VM name is immutable, rename method can be dropped from storage
API.

QubesOS/qubes-issues#2868
2017-07-04 04:11:14 +02:00
Marek Marczykowski-Górecki
fabd8119b4
storage: volume.import_volume now expect create()d volume
This is much more logical for *import*_volume function.

QubesOS/qubes-issues#2256
2017-06-26 13:09:26 +02:00
Marek Marczykowski-Górecki
28f78ed3b8
storage/lvm: minor fixes
QubesOS/qubes-issues#2256
2017-06-26 13:09:26 +02:00
Marek Marczykowski-Górecki
a748b393f4
storage: move remove() to Volume
This is continuation of 0f12870 "storage: use direct object references,
not only identifiers".

QubesOS/qubes-issues#2256
2017-06-26 13:09:26 +02:00
Marek Marczykowski-Górecki
ae600e24bf
storage: simplify pool.volumes usage
Add convenient collection wrapper for easier getting selected volume.
Storage pool implementation may still provide only volume listing
function (pool.list_volumes), or, additionally, optimized
pool.get_volume.

This means it is both possible to iterate over volumes:
```python
for volume in pool.volumes:
    ...

```

And get a single volume:
```python
volume = pool.volumes[vid]
```

QubesOS/qubes-issues#2256
2017-06-26 13:09:26 +02:00
Marek Marczykowski-Górecki
f976f7ec6c
storage: simplify coroutine handling
Suggested by @woju
2017-06-23 02:35:49 +02:00
Marek Marczykowski-Górecki
f48b1be669
storage: extract single volume clone into clone_volume
This will be useful for admin.vm.volume.Clone implementation.

QubesOS/qubes-issues#2256
2017-06-20 00:54:15 +02:00
Marek Marczykowski-Górecki
0f12870803
storage: use direct object references, not only identifiers
Reference objects, not their IDs - this way when object is modified, it
is visible everywhere where it is used. Main changes:
- volume.pool - Pool object
- volume.source - Volume object

Since volume have Pool object reference now, move volume related
functions into Volume class (from Pool class). This avoids horrible
`storage.get_pool(volume).something(volume)` construct.

One issue here is since volume.source reference a Volume object from a
different VM - VM's template, now VM load order is important. Since we
don't have control over it, initialize vm.storage when needed - possibly
while initializing storage of different VM. Since we don't have cycles
in AppVM-TemplateVM dependencies, it is safe.

Also, since this commit, volume.source (if defined) always points at
volume of the same name from VM's template. Using volumes with something
else as a source is no longer supported.

QubesOS/qubes-issues#2256
2017-06-09 04:55:06 +02:00
Marek Marczykowski-Górecki
fd5386cd47
storage/lvm: prefix VM LVM volumes with 'vm-'
This will allow filtering them out in udev rules - to not parse any of
it.

QubesOS/qubes-issues#2319
2017-06-09 04:54:59 +02:00
Marek Marczykowski-Górecki
fd3f19d4a6
storage: fix VM rename
When VM is renamed only volume.vid get updated, but not other attributes
calculated from it. Convert them to dynamic properties to not worry
about it.

QubesOS/qubes-issues#2256
2017-06-09 04:54:50 +02:00
Marek Marczykowski-Górecki
4c4f903fe3
vm: change kernel=None to kernel=''
vm.kernel property have type 'str'. Putting None there makes a lot of
troubles: it gets encoded as 'None' in qubes.xml and then loaded back as
'None' string, not None value. Also it isn't possible to assign None
value to str property throgh Admin API.

kernel='' is equally good to specify "no kernel from dom0".

QubesOS/qubes-issues#2622
2017-06-05 23:38:30 +02:00
Marek Marczykowski-Górecki
b5a4573290
storage: remove DomainPool
Replaced by BlockDevice extension
2017-06-05 23:33:58 +02:00
Marek Marczykowski-Górecki
7f3dd8b3d7
storage: don't fail on import if lvm is not installed 2017-05-26 15:08:20 +02:00
Marek Marczykowski-Górecki
d7af67d875
storage: minor error handling fix 2017-05-26 15:08:15 +02:00
Marek Marczykowski-Górecki
3cacf290bb
admin: implement admin.vm.volume.Import
Implement this in two parts:
1. Permissions checks, getting a path from appropriate storage pool
2. Actual data import

The first part is done by qubesd in a standard way, but then, instead of
accepting all the data (which may be several GB), return a path to which
a shell script (in practice: `dd` command) will write the data.
Then the script call back to qubesd again to report success/failure and
qubesd response from that call is actually returned to the user.

This way we do not pass all the data through qubesd, but still can
control the process from there in a meaningful way. Note that the last
part (second call to qubesd) may perform all kind of verification (like
a signature check on the data, or so) and can also prevent VM from
starting (hooking also domain-pre-start event) from not verified image.

QubesOS/qubes-issues#2622
2017-05-26 15:08:14 +02:00
Marek Marczykowski-Górecki
46b60dbf42
storage: add Pool.import_data to the API
Allow importing not only from another volume, but also raw data. In
practice, for all currently implemented storage pools, this is the same
as Pool.export, because path returned there is read-write. But lets not
abuse this fact, some future implementation may need different methods.

QubesOS/qubes-issues#2622
QubesOS/qubes-issues#2256
2017-05-23 15:35:55 +02:00
Marek Marczykowski-Górecki
0b64e3fbe0
storage: make LinuxKernel pool track vm kernel version
Do not initialize it only at qubes.xml load time, but re-read vm.kernel
property each time the path is constructed. While at it, add support for
vm.kernel set to 'None' - simply don't include modules.img (xvdd) then.
2017-05-17 11:17:21 +02:00
Marek Marczykowski-Górecki
595d983659
storage: make verify() asyncio aware 2017-05-17 11:17:21 +02:00
Marek Marczykowski-Górecki
bb4dc91ee8
storage/lvm: add workaround for ancient lvm2 in Travis-CI environment 2017-05-12 18:16:30 +02:00
Marek Marczykowski-Górecki
b91b89a341
Make pylint ♥ 2017-05-12 17:41:38 +02:00
Marek Marczykowski-Górecki
68d5ca93e1
storage: have QubesVM() handle vm.dir_path, also on clone and rename
Keep it uniform - QubesVM() object is responsible for handling
vm.dir_path, Storage() is responsible for handling disk volumes (which
may live in that directory

QubesOS/qubes-issues#2256
2017-05-12 17:04:18 +02:00
Marek Marczykowski-Górecki
52c3753d61
storage: support asynchronous storage pool implementations
Allow specific pool implementation to provide asynchronous
implementation. vm.storage.* methods will detect if given implementation
is synchronous or asynchronous and will act accordingly.
Then it's up to pool implementation how asynchronous should be achieved.
Do not force it using threads (`run_in_executor()`). But pool
implementation is free to use threads, if consider it safe in a
particular case.

This commit does not touch any pool implementation - all of them are
still synchronous.

QubesOS/qubes-issues#2256
2017-05-12 17:04:18 +02:00
Marek Marczykowski-Górecki
f324d30d4e
quebs: make Label() and storage.Pool() objects hashable 2017-05-12 14:27:47 +02:00
Bahtiar `kalkin-` Gadimov
5bc7a8f9e3
Fix pylint warning no-else-return 2017-04-15 23:49:41 +02:00
Bahtiar `kalkin-` Gadimov
e446e7a2f4
Rename qubes.devices.BlockDevice to qubes.storage.BlockDevice
Signed-off-by: Bahtiar `kalkin-` Gadimov <bahtiar@gadimov.de>
2017-04-15 23:49:36 +02:00
Marek Marczykowski-Górecki
fb7bd6823a
mgmt: implement storage-related methods
QubesOS/qubes-issues#2622
2017-03-16 20:04:01 +01:00
Marek Marczykowski-Górecki
f7d73893d7
qubes/storage: py3k related fixes 2017-03-01 21:50:06 +01:00
Marek Marczykowski-Górecki
570cbe5225
qubes: py3k related fixes 2017-02-27 02:37:45 +01:00
Marek Marczykowski-Górecki
01aedb7f18
storage: fix handling snap_on_start=True file volumes
Use the right cow image and apply the second layer to provide read-write
access. The correct setup is:
 - base image + base cow -> read-only snapshot (base changes "cached"
   until committed)
 - read-only snapshot + VM cow -> read-write snapshot (changes discarded
   after VM shutdown)

This way, even VM without Qubes-specific startup scripts will can
benefit from Template VMs, while VMs with Qubes-specific startup scripts
may still see original root.img content (for possible signature
verification, when storage domain got implemented).

QubesOS/qubes-issues#2256
2017-02-14 23:59:07 +01:00
Wojtek Porczyk
1be75d9c83 misc python3 fixes 2017-02-07 17:07:52 +01:00
Wojtek Porczyk
d74567d65f qubes: port core to python3
fixes QubesOS/qubes-issues#2074
2017-01-20 16:42:51 +01:00
Wojtek Porczyk
2b0ad51b18 Merge remote-tracking branch 'origin/pull/68/head' into core3-devel 2016-11-15 17:41:47 +01:00
Bahtiar `kalkin-` Gadimov
5db67fca8d
Fix init property swap in DomainVolumes 2016-11-07 23:26:53 +01:00
Marek Marczykowski-Górecki
b59463e8e8
qvm-block: fix listing non-internal volumes
In case of LVM (at least), "internal" flag is initialized only when
listing volume attached to given VM, but not when listing them from the
pool. This looks like a limitation (bug?) of pool driver, it looks like
much nicer fix is to handle the flag in qvm-block tool (which list VMs
volumes anyway), than in LVM storage pool driver (which would need to
keep second copy of volumes list - just like file driver).

QubesOS/qubes-issues#2256
2016-11-04 14:18:56 +01:00
Marek Marczykowski-Górecki
1a7f2892d1
storage/lvm: fix logic regarding snapshots, start, stop etc
There are mutiple cases when snapshots are inconsistently created, for
example:
 - "-back" snapshot created from the "new" data, instead of old one
 - "-snap" created even when volume.snap_on_start=False
 - probably more

Fix this by following volume.snap_on_start and volume.save_on_stop
directly, instead of using abstraction of old volume types.

QubesOS/qubes-issues#2256
2016-11-04 14:18:56 +01:00
Marek Marczykowski-Górecki
ab9d7fbb76
storage: improve/fix handling extra volumes
Just calling pool.init_volume isn't enough - a lot of code depends on
additional data loaded into vm.storage object. Provide a convenient
wrapper for this.

At the same time, fix loading extra volumes from qubes.xml - don't fail
on volume not mentioned in initial vm.volume_config.

QubesOS/qubes-issues#2256
2016-11-04 14:18:56 +01:00
Marek Marczykowski-Górecki
4323651afb
storage/lvm: remove duplicated _reset function
There were two: _reset and _reset_volume. Neither of them was working,
but the later was closer. Remove the other one.

QubesOS/qubes-issues#2256
2016-11-04 14:18:55 +01:00
Marek Marczykowski-Górecki
37dbf29bc1
storage/lvm: don't fail on removing already removed volumes
This may happen when removing not fully created VM.

QubesOS/qubes-issues#2256
2016-11-04 14:18:55 +01:00
Marek Marczykowski-Górecki
400e92b25a
storage/lvm: misc fixes
- add missing lvm remove call when commiting changes
- delay creating volatile image until domain startup (it will be created
  then anyway)
- reset cache only when really changed anything
- attach VM to the volume (snapshot) created for its runtime - to not
  expose changes (for example in root volume) to child VMs until
  shutdown

QubesOS/qubes-issues#2412
QubesOS/qubes-issues#2256
2016-11-04 14:18:55 +01:00
Marek Marczykowski-Górecki
0471453773
storage/lvm: call lvm directly, don't use qubes-lvm wrapper
The wrapper doesn't do anything else than translating command
parameters, but it's load time is significant (because of python imports
mostly). Since we can't use python lvm API from non-root user anyway,
lets drop the wrapper and call `lvm` directly (or through sudo when
necessary).

This makes VM startup much faster - storage preparation is down from
over 10s to about 3s.

QubesOS/qubes-issues#2256
2016-11-04 14:18:55 +01:00
Marek Marczykowski-Górecki
9197bde76e
storage/lvm: use dd for importing volumes
...instead of manual copy in python. DD is much faster and when used
with `conv=sparse` it will correctly preserve sparse image.

QubesOS/qubes-issues#2256
2016-11-04 14:18:54 +01:00
Marek Marczykowski-Górecki
ae42308f5f
storage: improve handling volume export
1. Add a helper function on vm.storage. This is equivalent of:

    vm.storage.get_pool(vm.volumes[name]).export(vm.volumes[name])

2. Make sure the path returned by `export` on LVM volume is accessible.
2016-09-29 01:59:54 +02:00
Marek Marczykowski-Górecki
1af1784c69
Merge remote-tracking branch 'qubesos/pr/54' into core3-devel
* qubesos/pr/54:
  Fix file storage resize
  Fix lvm reset_cache size cache
2016-09-19 20:36:20 +02:00
Bahtiar `kalkin-` Gadimov
d63d93b0ab
Fix file storage resize 2016-09-05 16:56:57 +02:00
Bahtiar `kalkin-` Gadimov
d72448615d
Fix lvm reset_cache size cache 2016-09-04 23:25:39 +02:00
Marek Marczykowski-Górecki
2285789b49
Merge remote-tracking branch 'qubesos/pr/54' into core3-devel
* qubesos/pr/54:
  Volume add size property wrapper
2016-09-04 22:38:06 +02:00
Bahtiar `kalkin-` Gadimov
b863152f73
Volume add size property wrapper 2016-09-04 21:55:56 +02:00
Marek Marczykowski-Górecki
16db68b053
Merge branch 'core3-devices' into core3-devel
* core3-devices:
  Fix core2migration and tests for new devices API
  tests: more qubes.devices tests
  qubes/ext/pci: implement pci-no-strict-reset/BDF feature
  qubes/tools: allow calling qvm-device as qvm-devclass (like qvm-pci)
  qubes: make pylint happy
  qubes/tools: add qvm-device tool (and tests)
  tests: load qubes.tests.tools.qvm_ls
  tests: PCI devices tests
  tests: add context manager to catch stdout
  qubes/ext/pci: move PCI devices handling to an extension
  qubes/devices: use more detailed exceptions than just KeyError
  qubes/devices: allow non-persistent attach
  qubes/storage: misc fixes for VM-exposed block devices handling
  qubes: new devices API

Fixes QubesOS/qubes-issues#2257
2016-09-04 21:32:01 +02:00
Marek Marczykowski-Górecki
ae72e294cd
Merge remote-tracking branch 'qubesos/pr/52' into core3-devel
* qubesos/pr/52:
  qvm-block extend Fix help message
  Fix a few typo bugs in qubes.storage.lvm
  qvm-block extends volumes to NEW_SIZE
  Make pylint happy ♥ qubes.storage.lvm
  Fix ThinVolume _size access
  qvm-block extend use qubes.utils.parse_size
  Make pylint happy ♥ qubes_lvm
  Fix lvm size/usage
  Add ThinPool.resize()
  Document qubes-block extend command in the manpage
  Fix file storage resize
  qvm-block add extend sub command
  qvm-block refactor attach/detach sub_parser init
2016-09-04 21:21:43 +02:00
Marek Marczykowski-Górecki
6cb624daf3
Merge remote-tracking branch 'qubesos/pr/51' into core3-devel
* qubesos/pr/51:
  Make pylint happy ♥ qubes.storage.lvm
  Fix lvm AppVM startup from lvm
  qubes.storage.lvm.qubes_lvm use debug not info
  Fix qvm-create lvm based AppVM
  qvm-block & qvm-pool add better Exception handling
  Remove unexpected property
  qvm-start --debug don't catch exceptions
2016-09-04 21:02:19 +02:00
Marek Marczykowski-Górecki
0af5fdd267
qubes/storage/file: clone file images as normal user
No need to be root here.

QubesOS/qubes-issues#2256
2016-09-04 20:56:02 +02:00
Marek Marczykowski-Górecki
70d3f58024
qubes/storage: misc fixes for VM-exposed block devices handling
Add 'backenddomain' element when source (not target) domain is not dom0.
Fix XML elemenet name. Actually set volume.domain when listing
VM-exposed devices.

QubesOS/qubes-issues#2256
2016-09-03 20:41:02 +02:00
Bahtiar `kalkin-` Gadimov
e4433f9a65
Make pylint happy ♥ qubes.storage.lvm 2016-09-02 20:16:03 +02:00
Bahtiar `kalkin-` Gadimov
46eb4a72dd
Fix a few typo bugs in qubes.storage.lvm 2016-09-02 19:57:35 +02:00
Bahtiar `kalkin-` Gadimov
be48d48e56
Make pylint happy ♥ qubes.storage.lvm 2016-09-02 19:46:11 +02:00
Bahtiar `kalkin-` Gadimov
8974b2cbc0
Fix ThinVolume _size access 2016-09-02 19:45:31 +02:00
Bahtiar `kalkin-` Gadimov
1ca3c00797
Fix lvm size/usage
- Uses a size_cache, because it's faster than doing a call for each volume
2016-08-29 00:15:47 +02:00
Bahtiar `kalkin-` Gadimov
0561dfce60
Add ThinPool.resize() 2016-08-29 00:13:50 +02:00
Bahtiar `kalkin-` Gadimov
e7caa14a85
Fix file storage resize 2016-08-29 00:09:55 +02:00
Bahtiar `kalkin-` Gadimov
355ea0c2a8
Fix lvm AppVM startup from lvm 2016-08-29 00:05:19 +02:00
Bahtiar `kalkin-` Gadimov
24bbc971b0
qubes.storage.lvm.qubes_lvm use debug not info 2016-08-29 00:05:19 +02:00
Bahtiar `kalkin-` Gadimov
e0bf4bdb8e
Fix qvm-create lvm based AppVM 2016-08-29 00:05:18 +02:00
Marek Marczykowski-Górecki
06f46243ec
qubes/storage: add resize to Pool API
It was already implemented by FilePool and used by Storage object, but
wasn't included in base class.
2016-08-18 11:42:00 +02:00
Marek Marczykowski-Górecki
42d6fddcd3
qubes/storage: support on-line resize
Call `qubes.ResizeDisk` qrexec service after resizing volume, to adjust
filesystem size there.
2016-08-18 11:40:38 +02:00
Marek Marczykowski-Górecki
6e383c703d
qubes/storage: allow passing just volume name to storage.resize
It makes much more sense to call:

    vm.storage.resize('private', 10000000000)

instead of:

    vm.storage.resize(vm.volumes['private'], 10000000000)
2016-08-17 22:42:15 +02:00
Marek Marczykowski-Górecki
ab6f961931
qubes/dispvm: misc fixes, make it actually working
- DispVM is no longer a special case for storage
- Add missing 'rw=True' for volatile volume
- Handle storage initialization (copy&paste from AppVM)
- Clone properties from DispVM template

QubesOS/qubes-issues#2253
2016-08-17 00:42:17 +02:00
Marek Marczykowski-Górecki
6490767278
qubes/storage: update vm.storage.commit
Better name it 'commit', as it isn't only for template. And also fix to
call `pool.commit`
2016-08-09 05:14:11 +02:00
Bahtiar `kalkin-` Gadimov
02c8fc999c
ThinPool.import() skips not saveable volumes 2016-08-03 02:57:46 +02:00
Bahtiar `kalkin-` Gadimov
064629b63a
Fix qubes.lvm _reset 2016-08-03 02:57:44 +02:00
Bahtiar `kalkin-` Gadimov
9d30bb132a
Fix umask 2016-08-03 02:57:44 +02:00
Bahtiar `kalkin-` Gadimov
824c359319
Fix ThinPool revision handling 2016-08-03 02:57:43 +02:00
Bahtiar `kalkin-` Gadimov
3ae6530cd8
Add lvm thin pool storage implementation 2016-08-03 02:57:42 +02:00
Bahtiar `kalkin-` Gadimov
1467f1ede5
Storage add clone support 2016-07-13 22:35:57 +02:00
Bahtiar `kalkin-` Gadimov
95fed1eb71
qubes.linux.kernel use new storage api 2016-07-13 22:34:34 +02:00
Bahtiar `kalkin-` Gadimov
f60ccb235d
qubes.storage.domain use new storage API 2016-07-13 22:34:34 +02:00
Bahtiar `kalkin-` Gadimov
d1c606b952
qubes.storage.file use new storage API 2016-07-13 22:34:33 +02:00
Bahtiar `kalkin-` Gadimov
7e1563c88d
Add handling for old volume config 2016-07-13 22:34:31 +02:00
Bahtiar `kalkin-` Gadimov
1bccb146d8
Add qubes.storage.isodate() helper function 2016-07-13 22:34:31 +02:00
Bahtiar `kalkin-` Gadimov
7841e3f6c0
qubes.storage rework api 2016-07-13 22:34:30 +02:00
Wojtek Porczyk
1ff1ca37a1 Merge remote-tracking branch 'woju/pull/21/head' into core3-devel
Conflicts:
	qubes/storage/__init__.py
2016-07-02 11:54:56 +02:00
Wojtek Porczyk
c9accc258c Merge remote-tracking branch 'woju/pull/15/head' into core3-devel
Conflicts:
	qubes/storage/__init__.py
	qubes/storage/file.py
	qubes/vm/qubesvm.py
2016-06-28 15:15:00 +02:00
Bahtiar `kalkin-` Gadimov
e26932a81a
Fix bug in FilesPool.target_dir() 2016-06-23 14:23:34 +02:00
Bahtiar `kalkin-` Gadimov
7081bd433a
Make pylint happy 2016-06-23 14:23:34 +02:00
Bahtiar `kalkin-` Gadimov
b584d1a4bb
Remove QubesVM.is_netvm() and is_disposablevm() 2016-06-23 14:23:33 +02:00
Bahtiar `kalkin-` Gadimov
e08ca1ff57
Remove QubesVM.is_template() 2016-06-23 14:23:31 +02:00
Bahtiar `kalkin-` Gadimov
4db84c42a6
Fix qubes.storage.file _remove_if_exists 2016-06-23 13:17:00 +02:00
Bahtiar `kalkin-` Gadimov
8fc3772017
Add Volume.__str__() 2016-06-23 13:16:59 +02:00