Skip to content

qui-devices: Improve partition handling#310

Open
noskb wants to merge 1 commit into
QubesOS:mainfrom
noskb:qui-fixes-1
Open

qui-devices: Improve partition handling#310
noskb wants to merge 1 commit into
QubesOS:mainfrom
noskb:qui-fixes-1

Conversation

@noskb
Copy link
Copy Markdown

@noskb noskb commented Apr 23, 2026

At device_attached() function:
When a partition is attached, the parent device’s entry is immediately removed from the QubesDB, the sub-device’s infomation is changed, and an device-attach event is triggered. However, due to concurrency issues, the API may not return information about the attached device. In that case, let’s query the backend domain to get the proper device information.

At device_removed() function:
If the parent device has sub-devices, updates their internal information.

Fixes: QubesOS/qubes-issues#10828
Fixes: QubesOS/qubes-issues#10732

@marmarek
Copy link
Copy Markdown
Member

When a partition is attached, the parent device’s entry is immediately removed from the QubesDB

This is the problem. @piotrbartman you had some idea how to fix it, but I can't find it now

Copy link
Copy Markdown
Member

@marmarta marmarta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is a good idea, in terms of where the bug is - the amount of clearing cache and re-iterating over the devices suggests to me the problem is in some bug in core-admin-client?

Plus, some pylint complaining.

Comment thread qui/devices/device_widget.py Outdated
parent_dev = dev
for dev_id, device in self.devices.items():
if device.parent == parent_dev.port:
vm.devices[parent_dev.device_class].clear_cache()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this and the following lines means that you clear cache and re-query the backend vm multiple times, once per each parent device. That's not very effective, I think this should only be done once when needed.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I did it.

Comment thread qui/devices/device_widget.py Outdated
if device.attachments
]
if dev_id != backend.Device.id_from_device(dev):
to_delete.append(device._full_id)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pylint complains about this (rightly, I think)

return

if not isinstance(device, qubesadmin.device_protocol.DeviceInfo):
device.backend_domain.devices[device.devclass].clear_cache()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am somewhat worried by the amount of clear_cache here. One, this will potentially be quire slow, I think, but two, doesn't this point to an underlying issue in core-admin-client that should be fixed instead of working around it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am somewhat worried by the amount of clear_cache here. One, this will potentially be quire slow, I think,

if the backend vm is holding onto a lot of block devices ?

but two, doesn't this point to an underlying issue in core-admin-client that should be fixed instead of working around it?

I agree. As @marmarek pointed out in the first comment as well, it needs to be fixed at the root.
However, since some time has passed since this message (QubesOS/qubes-issues#10180 (comment)) of yours and there has been no progress, I wrote a workaround to be used as a temporary stopgap until that is completed. (In other words, my brain finds it hard to tinker with APIs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am somewhat worried by the amount of clear_cache here. One, this will potentially be quire slow, I think,

if the backend vm is holding onto a lot of block devices ?

yeah, for example in the default case of sys-usb, just having a bunch of USB sticks with multiple partitions each will cause the amount of calls to skyrocket.

In general, I am very worried about putting a slow workaround to an API bug in the frontend... It is ultimately @marmarek's call here.

Copy link
Copy Markdown
Author

@noskb noskb Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your concern is entirely justified. I appreciate you taking the time to wrote a review despite your busy workload.

At device_attached() function:
When a partition is attached, the parent device’s entry is immediately
removed from the QubesDB, the sub-device’s infomation is changed, and
an device-attach event is triggered. However, due to concurrency
issues, the API may not return information about the attached device.
In that case, let’s query the backend domain to get the proper device
information.

At device_removed() function:
If the parent device has sub-devices, updates their internal
information.

Fixes: QubesOS/qubes-issues#10828
Fixes: QubesOS/qubes-issues#10732
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-attaching USB partition (block device) shows error in dom0's journal qui-devices widget does not reflect devices attached using command line

3 participants