Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VM: Avoid QEMU device ID trimming #13596

Closed
wants to merge 8 commits into from

Conversation

hamistao
Copy link
Contributor

@hamistao hamistao commented Jun 12, 2024

This fixes the duplicate ID problem on qemu when adding a div drive device.
The problem occurs because QEMU trimms down long device IDs to 64 characters internally and that may result in other references to that device mismatching the device ID or even duplicate IDs if a dir drive device ID is big enough that the suffix that differentiates the tags of the 9p entry and the virtiofs entry are removed in the trimming process.
As an example, dev-lxd_{long_device_name}-virtio-fs and dev-lxd_{long_device_name}-9p would be used in separate qem.conf entries for the same device named {long_device_name}. This can generate duplicate IDs when both those ids get trimmed down to dev-lxd_{trimmed_long_device_name}, losing the protocol suffixes.
This PR proposes hashing the device name when the device name is big enough that the QEMU ID has to be trimmed (but not in any other case). This results is device IDs like dev-lxd_{device_name_hash}-virtio-fs

@hamistao
Copy link
Contributor Author

@tomponline warning that this hashes the device names even if the protocol suffixes would just be partially trimmed, like in dev-lxd_{long_device_name}-v and dev-lxd_long_device_name}-9, so this could change the behavior of devices with very specific name lengths.

@hamistao hamistao marked this pull request as draft June 12, 2024 21:49
@hamistao hamistao force-pushed the fix-duplicate-device-id branch 3 times, most recently from c25ce0c to 0f43e45 Compare June 13, 2024 03:40
@hamistao hamistao marked this pull request as ready for review June 13, 2024 03:48
@tomponline tomponline changed the title Fix duplicate device ID VM: Fix duplicate device ID Jun 13, 2024
@hamistao hamistao changed the title VM: Fix duplicate device ID VM: Avoid QEMU device ID trimming Jun 13, 2024
@hamistao
Copy link
Contributor Author

@tomponline this is ready again

…DMaxLength`

Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
This includes the protocol on `nameSuffix` and defines the `lxd_` via `namePrefix`

Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
…o `hashIfLonger`

Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
This function shortens only the device name part of the qemu device ID, leaving the prefixes and suffixes. For example: `dev-lxd_{device_name_hash}-virtio-fs`

Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
Signed-off-by: hamistao <pedro.ribeiro@canonical.com>
@hamistao
Copy link
Contributor Author

@tomponline I couldn't test this with hotplugging because of the issue you are working on, it may be necessary to use generateQemuDirDriveName when hotplugging a device but I would like to test it before making that decision.

@tomponline
Copy link
Member

@tomponline I couldn't test this with hotplugging because of the issue you are working on, it may be necessary to use generateQemuDirDriveName when hotplugging a device but I would like to test it before making that decision.

Yep, we'll land the other hotplug fix first. Good idea.

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.

2 participants