Commit Graph

47 Commits

Author SHA1 Message Date
Marek Marczykowski-Górecki
4fe08d31e4
Adjust permissions of /dev/xen/hypercall
Starting with Linux 4.18, there is new device node for issuing
hypercalls from user space - /dev/xen/hypercall (partially duplicating
functionality of /dev/xen/privcmd). New Xen tools (4.12) make use of it,
so make it available for them. Otherwise such tools will fail the
operation (there is no fallback to privcmd on EACCESS).
2019-02-16 14:56:14 +01:00
Marek Marczykowski-Górecki
f7b8a79ce6
udev: create /dev/mapper/dmroot -> xvda3 symlink when its mounted directly
When root device is available read-write (TemplateVM/StandaloneVM), its
mounted directly, instead of using device-mapper layer. But
/dev/mapper/dmroot still needs to exists (it is pointed from
/etc/fstab), otherwise various tools, including grub-mkconfig get
confused.
Create a symlink using udev rule. It is already done in initramfs, and
in case of Fedora that udev rule/symlink survive switching to
non-initramfs udev, but not on Debian. So, add appropriate udev rules
file.

Fixes QubesOS/qubes-issues#3178
2018-06-13 15:48:00 +02:00
Marek Marczykowski-Górecki
9eafc65cb4
udev: don't call udev-block-add-change for devices excluded by other rules
The script call is quite expensive (it does multiple things, including
checking device-mapper, qubesdb etc). Don't call it for devices we (or
else) already excluded earlier.
This is the most relevant for dom0, where udev "change" event is
triggered quite often, for multiple LVM volumes - all excluded, because
being VM's disks.
2018-04-20 16:47:46 +02:00
Marek Marczykowski-Górecki
e37f9da355
udev: update detecting usbip-connected devices
Controller sysfs path have changed in recent kernels ('vhci_hcd' ->
'vhci_hcd.0'), look for vhci_hcd prefix, not exact this name.

QubesOS/qubes-issues#3455
2018-01-17 16:12:24 +01:00
Rusty Bird
6b3830ba31
udev-block-add-change: ignore unconnected Network Block Device
"modprobe nbd" shouldn't instantly send 16 zero byte nbd devices to
dom0.
2017-12-30 21:27:28 +00:00
Marek Marczykowski-Górecki
68d7be77db
Make udev-block-add-change executable again 2017-11-21 05:34:21 +01:00
qubesuser
4d08ff40a9 Speed up udev-block-add-change by not using xenstore
xenstore-ls is incredibly slow, while reading sysfs is much faster
2017-11-08 03:37:53 +01:00
Marek Marczykowski-Górecki
c7420318e2
udev: fix loop devices exclusion based on directory flagfile
Getting loop device backing file path was broken:
${NAME%p*} for not-partitioned devices will cut the actual device name.
Use full name instead. This probably breaks handling partitioned
devices, but such devices should not appear in a directory flagged to be
ignored (VM images)

QubesOS/qubes-issues#3084
2017-09-15 05:25:42 +02:00
Marek Marczykowski-Górecki
764b0f3f07
udev: major cleanup in block devices handling
1. Do not detach device forcefully when it's removed. This breaks
libvirt (which thinks the device is still there). After this change, it
is possible to detach device using libvirt, even if it was already
removed physically from backend domain (unless it is dom0 - in which
case it is still broken). So, this is partial fix for
QubesOS/qubes-issues#1082.

2. Do not trigger "change" udev event when only QubesDB state needs to
be updated - this leads to massive udev events queue, and heavy I/O
usage - for example scanning all LVM many times. In some cases it even
caused infinite event queue.

3. Do not use QUBES_EXPOSED udev property - it was needed a while back
before QubesDB, because concurrent xenstore accesses are expensive
(because of transactions). It isn't the problem on QubesDB.

4. Cache information about device-mapper, so it is possible to
reconstruct it at device remove - when the actual device cannot be
queried anymore. This is specifically about list of lower layer devices
used.

5. Allow excluding loop devices pointing at a file in directory marked
with ".qubes-exclude-block-devices" file. This is more generic than
hardcoding /var/lib/qubes.

QubesOS/qubes-issues#3084
Fixes QubesOS/qubes-issues#3073
QubesOS/qubes-issues#1082
2017-09-12 04:25:34 +02:00
Marek Marczykowski-Górecki
823d73a524
udev: filter-out QEMU devices
Fixes QubesOS/qubes-issues#2969
2017-08-07 23:00:53 +02:00
Marek Marczykowski-Górecki
0d4c561064
udev: don't list in qvm-block any device marked to be ignored by udev
Not only device-mapper one.
This especially include loop devices for VM disk images.

QubesOS/qubes-issues#2319
2017-07-06 19:40:51 +02:00
Marek Marczykowski-Górecki
db2b027153
udev: use DM ignore device flag only for DM devices
For example do not exclude (from exposing to qvm-block) loop devices
with this flag set, otherwise `qvm-block -l` would not list just
attached disk image files.

Fixes QubesOS/qubes-issues#2453
2016-11-23 03:40:37 +01:00
Marek Marczykowski-Górecki
e0acdee23c
udev-block-add-change: fix checking if partition is mounted
is_used() function should operate on its argument, not global $DEVNAME.
2016-07-17 05:08:25 +02:00
Marek Marczykowski-Górecki
3422cffe0d
Merge remote-tracking branch 'qubesos/pr/6'
* qubesos/pr/6:
  udev-block-add-change: simplify a check
  udev-block-add-change: don't exclude already attached devs
  udev-block-add-change: better mount status check
2016-07-16 21:34:17 +02:00
Rusty Bird
a032129b80
udev-block-add-change: simplify a check 2016-07-15 16:15:42 +00:00
Rusty Bird
6b32378158
udev-block-add-change: don't exclude already attached devs
For example, attaching a device-mapper device to another VM increases
its "dmsetup info" open count in is_used(), which triggered its removal
from qvm-block.
2016-07-15 16:15:41 +00:00
Rusty Bird
e7d7111f13
udev-block-add-change: better mount status check
The canonical device name is not necessarily used in /proc/mounts or
/proc/self/mountinfo, see /dev/dm-0 vs. /dev/mapper/dmroot. (And only
checking by major:minor is not possible in the case of btrfs.)

Also fixes another bug where e.g. dm-10 would match when really only
dm-1 was mounted, or when the mountpoint path included the device name,
etc.

Also catches enabled swap.
2016-07-15 16:15:41 +00:00
Marek Marczykowski-Górecki
f7eea5548a
udev: make USB device version detection more generic
Apparently some devices do not comply with standards (there is no such
thing as USB version 2.01), but other than that works fine. So take into
account only the major number of bcdUSB field.

Fixes QubesOS/qubes-issues#2158
2016-07-08 10:40:12 +02:00
Marek Marczykowski-Górecki
93f676d998
udev: fix removing USB entries
QubesOS/qubes-issues#531
2016-06-01 14:04:10 +02:00
Marek Marczykowski-Górecki
cf5f382d7a
udev: ignore usbip-connected USB devices
Those devices are most likely attached using "PV USB" from another
domain, so it doesn't make sense to list them as available for further
passthrough.

QubesOS/qubes-issues#531
2016-06-01 14:03:01 +02:00
Marek Marczykowski-Górecki
c926f4565d
udev: expose USB 3.0 devices for PV USB
Even if particular PV USB implementation doesn't support it, still have
it included in QubesDB. It should be up to attaching code to decide.

Also, don't fail if xen-usbback module doesn't exist. This isn't the
only option (the other one is usbip over qrexec).

QubesOS/qubes-issues#531
2016-05-25 03:41:54 +02:00
Marek Marczykowski-Górecki
cdbcb2eb55
udev: fix deadlock on xenstore access during dom0 boot
During early dom0 boot, before xenstored is started any access to it
through /proc/xen/xenbus (or /dev/xen/xenbus) will wait until xenstored
is started. If that happens in script ordered to start before xenstored,
we have a deadlock. Prevent this by using `xenstore-ls -s` in dom0,
which will fail immediately when xenstored isn't running yet. This fail
isn't a problem, because when xenstored isn't running yet, surely device
isn't attached anywhere.

QubesOS/qubes-issues#1081
2016-05-17 22:41:51 +02:00
Marek Marczykowski-Górecki
098bfb634d
udev/qvm-block: exclude device if its partition is already attached
This prevents simultaneous attachment of the same device (in practice)
to multiple VMs.
This change to be effective requires udev action being called when such
device is attached/detached to some domain. Script
/etc/xen/scripts/block will take care of it.

Fixes QubesOS/qubes-issues#1081
2016-05-16 11:53:30 +02:00
Marek Marczykowski-Górecki
efd9854376
udev/qvm-block: exclude devices used elsewhere
Exclude exclude device if mounted/part of other device, or any of its
partition is used (same definition). Update this state whenever device
or it's partition receives udev event.

Fixes QubesOS/qubes-issues#1600
2016-05-16 11:52:57 +02:00
Marek Marczykowski-Górecki
22d6892ec9
udev: fix hiding devices from qvm-block
When device becomes non-attachable (for example because it gets mounted,
or used as part of LVM/RAID/whatever), it should be removed from
advertised available devices. The code for removing QubesDB entry was
buggy - the device is actually a directory in QubesDB, not a single
entry.

QubesOS/qubes-issues#1600
2016-01-14 05:01:27 +01:00
Marek Marczykowski-Górecki
6ac3fc3247
udev: ignore devices set to be ignore elsewhere
There are already some other rules to ignore not interesting devices.
This includes device-mapper assembled in initramfs manually. 'dmroot'
isn't properly detected as mounted because /dev/mapper/dmroot isn't a
symlink to /dev/dm-0 and /proc/mounts contains the former name, while
udev event the later.

Fixes QubesOS/qubes-issues#1586
2016-01-07 03:00:32 +01:00
Marek Marczykowski-Górecki
50145d448a
udev: do not assume static device-mapper major number
It is not static.

QubesOS/qubes-issues#1586
2016-01-06 04:22:50 +01:00
Marek Marczykowski-Górecki
e23cbbc261
Fix building Fedora package after Archlinux build fixes
LIBDIR on Fedora is /usr/lib64, not something that we want for scripts,
Also make sure to export SYSLIBDIR.
2016-01-06 04:21:42 +01:00
pqg
86e7f7c2c8 Fix build (installation) on Archlinux
/lib is a symlink to /usr/lib on Arch, so /lib/blah... paths are
rejected when installation is attempted.
2015-12-15 14:19:24 +00:00
Marek Marczykowski-Górecki
7148f8d135
Move udev scripts to /usr/lib/qubes, move rules to /lib/udev/
Resolve udev-rule-in-etc, non-standard-dir-in-usr, file-in-unusual-dir
lintian warnings.

QubesOS/qubes-issues#1416
2015-11-26 22:18:03 +01:00
Marek Marczykowski-Górecki
643ff5876d udev: do not use a separate lock for udev block scripts
Since migration to QubesDB, it isn't needed anymore (QubesDB have no
problem with concurrent writes, as transactions are not supported).
This should speedup system startup.
2015-06-28 21:59:39 +02:00
Marek Marczykowski-Górecki
68bbd408d7 udev: fix block devices ignoring rule
First of all there was missing ']'. Bu additionally change that rule to
detect partitioned loop devices instead of device-mapper.
2015-04-03 11:14:15 +02:00
Marek Marczykowski-Górecki
c731fa5b28 udev: ignore temporary devices created during VM startup 2015-03-30 04:54:37 +02:00
Marek Marczykowski-Górecki
501cbca4c1 udev: allow normal user to access /dev/xen/xenbus for vchan connections
Recently we've switched all xenstore access to the new interface
(instead of deprecated /proc/xen/xenbus). Mostly because of deadlock in
/proc/xen/xenbus implementation.
2015-03-25 00:04:45 +01:00
Marek Marczykowski-Górecki
b4f48c1770 udev: update hotplug block scripts for QubesDB
Some initial work was done, but apparently not complete and buggy.
2014-12-11 06:06:57 +01:00
Marek Marczykowski-Górecki
a930f7b2ea udev: setup permissions on xen device nodes 2014-11-19 15:10:58 +01:00
Marek Marczykowski
dc41fbad79 Use Qubes DB instead of Xenstore 2014-11-19 15:10:58 +01:00
Marek Marczykowski-Górecki
35300b54ac udev: update dmsetup path
Debian has it in /sbin/dmsetup. Fedora has /sbin->/usr/sbin symlink, so
it should work on both.
2014-07-26 15:47:15 +02:00
Marek Marczykowski-Górecki
644372149f udev: convert device description to ascii only 2014-07-05 16:13:08 +02:00
Marek Marczykowski-Górecki
36a2c99b49 udev: filter out template's root device 2014-07-05 16:12:37 +02:00
Marek Marczykowski-Górecki
58df64ad20 udev: skip empty device-mapper nodes
It can happen during device reconfiguration - do not decide to expose
the device until its known what device it will be.
This fixes bug where root.img was visible in qvm-block as normal device
and could be detached.
2014-07-04 03:29:38 +02:00
Marek Marczykowski-Górecki
44e5c20806 udev: fix perms of udev-block-add-change
Accidentally "x" was removed.
2014-06-29 21:57:20 +02:00
Marek Marczykowski-Górecki
570446f448 udev: better support device-mapper/LVM
Do not ignore them completely.
2014-06-07 04:53:32 +02:00
Marek Marczykowski-Górecki
be74125d40 udev: hide internal drives from file-selection dialogs 2014-02-07 05:26:52 +01:00
Marek Marczykowski-Górecki
b51435c903 udev: add locking on block device processing
xenstored does handle concurrent writes very harshly - it aborts the
whole transaction if any other write happened the same time. For udev
(which process all the events almost at once) it means hundreds of
retries and in some times even exceed udev timeout (60s or so).
To prevent this problem, add locking to allow only one such event being
processed at once. It looks like it should slow down the system startup,
but actually it does otherwise.
2014-01-13 05:01:56 +01:00
Marek Marczykowski-Górecki
23ea1ebe19 qvm-block: detect read-only devices 2013-10-01 04:19:14 +02:00
Marek Marczykowski
42e133b753 Qrexec common code, qubes.Filecopy common code, udev scripts 2013-03-20 06:27:32 +01:00