ext/block: make use of QubesDB watch

Actually use just introduced API.

Also document new `device-list-change:class` event.

QubesOS/qubes-issues#2940
This commit is contained in:
Marek Marczykowski-Górecki 2017-07-25 01:24:30 +02:00
parent b7f0cf7d82
commit 67c382c8b0
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 18 additions and 0 deletions

View File

@ -44,11 +44,17 @@ Such extension should provide:
domain of given identifier
- handle `device-list-attached:class` event - list currently attached
devices to this domain
- fire `device-list-change:class` event when device list change is detected
(new/removed device)
Note that device-listing event handlers can not be asynchronous. This for
example means you can not call qrexec service there. This is intentional to
keep device listing operation cheap. You need to design the extension to take
this into account (for example by using QubesDB).
Extension may use QubesDB watch API (QubesVM.watch_qdb_path(path), then handle
`domain-qdb-change:path`) to detect changes and fire
`device-list-change:class` event.
'''
import asyncio

View File

@ -106,6 +106,18 @@ class BlockDevice(qubes.devices.DeviceInfo):
class BlockDeviceExtension(qubes.ext.Extension):
@qubes.ext.handler('domain-init', 'domain-load')
def on_domain_init_load(self, vm, event):
'''Initialize watching for changes'''
# pylint: disable=unused-argument,no-self-use
vm.watch_qdb_path('/qubes-block-devices')
@qubes.ext.handler('domain-qdb-change:/qubes-block-devices')
def on_qdb_change(self, vm, event, path):
'''A change in QubesDB means a change in device list'''
# pylint: disable=unused-argument,no-self-use
vm.fire_event('device-list-change:block')
def device_get(self, vm, ident):
# pylint: disable=no-self-use
'''Read information about device from QubesDB