Skip to content

Include USB devices when connecting the custom-device interface - #1151

Draft
jonathan-conder wants to merge 1 commit into
mainfrom
fix/custom-device
Draft

jonathan-conder wants to merge 1 commit into
mainfrom
fix/custom-device

Conversation

@jonathan-conder

Copy link
Copy Markdown
Contributor

Description

Fixes #1046, at least the bit about USB devices being completely skipped. It still won't support hotplugging or ownership inheritance until those are fixed in LXD (canonical/lxd#19450, canonical/lxd#19451).

LXD deliberately filters out subsystem: usb when starting a unix-hotplug device, because it has a dedicated usb device type. Workshop now uses both unix-hotplug and usb devices to back a custom-device plug when subsystem is unset. When subsystem=usb it only uses a usb device, no unix-hotplug.

Self-review quick check

  • Make decisions that cost a lot to reverse explicit in the PR description.
  • Avoid nested conditions.
  • Delete dead code and redundant comments.
  • Normalise symmetries by sticking to doing identical things identically.
// one way to handle errors
if err := f(); err != nil {
   ...
}

// one way to handle multiple returns
val, err := f()
if err != nil {
   ...
}
...
  • Check that coupled code elements, files, and directories are adjacent. For example, test data is stored as close as possible to a test.
  • Put variable declaration and initialisation together.
  • Divide large expressions into digestable and self-explanatory ones. Use multiple variables if required.
  • Put a blank line between two logically different chunks of code.
  • Follow the style guide for new error messages.

Docs

Procedure:

  • I have checked and added or updated relevant documentation.
  • I have checked and added or updated relevant release notes.
  • I have included the technical author in the review.

Content:

  • Headings and titles accurately describe the content.
  • New and updated pages include correct metadata.
  • Documentation tests are added or updated where applicable (for tutorial/ and how-to/ sections).
  • Documentation follows the style guide.
  • If needed, docs/.coverage.yaml updated, coverage tags added (.. artefact).

Or:

  • I confirm the PR has no implications for documentation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Real USB hardware and supported LXD servers are needed to validate node visibility, workshop-user permissions, and connect/disconnect/restart behavior, which the added profile-construction and decoding tests do not cover.

No open issues 🎉

What changed in this PR

Updates the LXD backend so custom-device connections include USB device nodes, addressing the device-visibility portion of #1046. USB hotplugging and ownership inheritance remain dependent on upstream LXD fixes.

Changes:

  • Uses a USB device for subsystem=usb, and both USB and unix-hotplug devices when the subsystem is unset.
  • Preserves custom-device metadata when reading profiles and omits USB ownership inheritance when LXD lacks support.
  • Adds unit tests for device generation and profile reconstruction.
File Description
internal/​workshop/​lxd/​lxd_backend_profile.go Restores custom-device metadata from placeholders and ignores auxiliary USB entries.
internal/​workshop/​lxd/​lxd_backend_profile_test.go Tests USB-only and unspecified-subsystem profile reconstruction.
internal/​interfaces/​lxd_device/​spec.go Generates USB devices according to subsystem selection.
internal/​interfaces/​lxd_device/​spec_test.go Tests USB, non-USB, and unspecified-subsystem device generation.
internal/​interfaces/​lxd_device/​backend.go Removes unsupported USB ownership-inheritance settings before applying profiles.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

Custom device plug with subsystem: usb passes no device node into the container

2 participants