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

udiskslinuxmanager: add resolving devices by partuuid/partlabel #861

Closed

Conversation

agners
Copy link

@agners agners commented Mar 19, 2021

Allow to find block devices by partition name and partition UUID. Use strings similar to how Linux allows to find such block devices (partuuid and partlabel).

@StorageGhoul
Copy link

Can one of the admins verify this patch?

@vojtechtrefny
Copy link
Member

Jenkins, ok to test.

Copy link
Member

@vojtechtrefny vojtechtrefny left a comment

Choose a reason for hiding this comment

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

Lookup using both partuuid and partlabel is already possible with paths: both /dev/disk/by-partlabel/xxx and /dev/disk/by-partuuid/xxx should work. But I'm not against adding these two to make the API a little bit more user friendly.
Also using the paths internally would make the code way simpler (e.g. constructing the /dev/disk/by- path and using same helper function we use for devpath).

@@ -1224,6 +1230,27 @@ handle_resolve_device (UDisksManager *object,
if (devlabel != NULL)
found = g_strcmp0 (udisks_block_get_id_label (blocks_p->data), devlabel) == 0;

if (partlabel != NULL || partuuid != NULL)
Copy link
Member

@vojtechtrefny vojtechtrefny Mar 22, 2021

Choose a reason for hiding this comment

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

These two checks should be separate -- you need to match both partlabel and partuuid when user specifies both (documentation for ResolveDevice allows specifying multiple keys and all must match).

Copy link
Member

Choose a reason for hiding this comment

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

True, that OR between the tests doesn't conform to the "devices matching all values" condition.

Also, you should be pulling strings from the org.freedesktop.UDisks2.Partition interface of the block object as suggested in the D-Bus API docs addition. The udev ID_PART_ENTRY_ properties are encoded strings (e.g. ID_PART_ENTRY_NAME=EFI\x20System\x20Partition) and are different from what is presented on the .Partition interface.

Copy link
Author

Choose a reason for hiding this comment

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

FWIW, this code is borrowed from https://github.com/storaged-project/udisks/blob/udisks-2.9.2/src/udiskslinuxblock.c#L424. But from what I can tell udisks_linux_block_matches_id has a different use case as we don't have "matching all values" situation there.

Ok, I'll try to use .Partition interface. Maybe should be fixed in udisks_linux_block_matches_id as well?

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, thanks for bringing this up. I've tried to addess this in #888.

Copy link
Member

@tbzatek tbzatek left a comment

Choose a reason for hiding this comment

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

Also, could you please add some test cases for these new options?


blocks = get_block_objects (object, &num_blocks);

for (blocks_p = blocks; blocks_p != NULL; blocks_p = blocks_p->next)
{
found = FALSE;
Copy link
Member

Choose a reason for hiding this comment

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

Good catch! Actually the logic around found is completely wrong here, overwriting the value as the checks go, making only the last requested check relevant. So much for the "only devices matching all values" statement.

Could you please correct all the checks while you're at it? (Alternatively we can deal with that later, this would need to be covered by test cases anyway).

Copy link
Author

Choose a reason for hiding this comment

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

Oh I see. Yeah I added found = FALSE; since that would replicate what happened before, but yeah "only devices matching all values" is defunct currently. Will fix this.

@@ -1224,6 +1230,27 @@ handle_resolve_device (UDisksManager *object,
if (devlabel != NULL)
found = g_strcmp0 (udisks_block_get_id_label (blocks_p->data), devlabel) == 0;

if (partlabel != NULL || partuuid != NULL)
Copy link
Member

Choose a reason for hiding this comment

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

True, that OR between the tests doesn't conform to the "devices matching all values" condition.

Also, you should be pulling strings from the org.freedesktop.UDisks2.Partition interface of the block object as suggested in the D-Bus API docs addition. The udev ID_PART_ENTRY_ properties are encoded strings (e.g. ID_PART_ENTRY_NAME=EFI\x20System\x20Partition) and are different from what is presented on the .Partition interface.

@tbzatek
Copy link
Member

tbzatek commented Nov 3, 2021

I've incorporated the notes above and slightly refactored the code, resulting in #933. Closing this one.

@tbzatek tbzatek closed this Nov 3, 2021
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.

4 participants