canonical / lxd

Powerful system container and virtual machine manager
https://canonical.com/lxd
GNU Affero General Public License v3.0
4.34k stars 930 forks source link

Potential duplicate QEMU device ID when using long device names #13597

Closed hamistao closed 1 month ago

hamistao commented 3 months ago

Required information

Issue description

This is related to #13596. If a QEMU device name is too long, QEMU will trim it down to 64 characters. For LXD, this means that two devices named "{long_name}1" and "{longname}2" may end up with the same QEMU device ID `dev-lxd{trimmed_long_name}`, which will result in the VM failing to start.

Steps to reproduce

  1. LONG_DEVICE_NAME="device-with-very-long-name-for-long-qemu-property-handling-test"
  2. mkdir -p $HOME/device-test && mkdir -p $HOME/device-test && lxc init ubuntu:n vm --vm
  3. lxc config device add v2 "${LONG_DEVICE_NAME}1" pci address=01:00.0 # Requires having an available PCI device.
  4. lxc config device add v2 "${LONG_DEVICE_NAME}2" pci address=02:00.0
  5. lxc start vm
hamistao commented 3 months ago

@tomponline I did not fix this in #13596 because:

  1. To get the fix for the tests in faster
  2. This may impact the behavior of devices that are currently working so I decided it would be better to take some time to decide on an approach
tomponline commented 3 months ago

@hamistao is this confirmed as a bug? If so please can you add the Bug label to the issue.

hamistao commented 3 months ago

@tomponline still to be confirmed after some recent changes that have altered the scope of this problem by improving device ID generation, but is still probably a bug

hamistao commented 1 month ago

Indeed the duplication happens with PCI and GPU passthrough devices only. After some tests with Testflinger, I concluded that the device ID does not affect the device information as seen from inside the insatance and is just a reference for LXD and QEMU. This PR fixes this.