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

util: Added function to find specific UUID in UUID list. #756

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

lgdacunh
Copy link
Contributor

No description provided.

@lgdacunh lgdacunh force-pushed the find_uuid branch 2 times, most recently from 8d264dd to 5734426 Compare December 16, 2023 00:44
if (memcmp(uuid_end, &uuid_list->entry[i].uuid, NVME_UUID_LEN) == 0)
return 0;
if (memcmp(uuid, &uuid_list->entry[i].uuid, NVME_UUID_LEN) == 0)
return i + 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not just use a int as return type and then return -1 in with errno set as we do in all other commands? This allows to return the correct index here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@igaw , the initial idea here was to produce output already on the type used by command structures like nvme_get_log_args.uuidx, nvme_get_features_args.uuidx, nvme_set_features_args.uuidx, and nvme_lockdown_args.uuidx.
I guess it is ok to let the compiler automatically cast when assigning the value to the uuidx property, and use the extra bits to signal certain conditions.
But I don't see were we would get an errno here. Maybe we could get a segfault if we receive bad uuid_list/uuid pointers.
I is worth mention that my interpretation of the NVMe spec is UUID index 0, indicates the absence of UUID.
I still see a point on keeping consistency. If you still would prefer to keep consistency on the library API, please make me know what would be the ideal function signature in this case and what error code I could return.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have to check the return value anyway to decide to use it or not. Thus it doesn't really matter if it is 0 or -1. My point is about consistency as we use this pattern (hopefully) consistently everywhere. In hindsight, it would have been better not to follow the POSIX style here but well that's too late now. In this case if the function return -1, errno could be set to ENOENT.

About the idea with additional bits encoded in the return value: I'd like to avoid overloading values. This is something we should only do if speed and size really matters in an API. I'd rather choose simplicity instead (and use the compiler to catch problems). There are some ideas how to handle errors for 2.x but for 1.x the ship has sailed :(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@igaw, Done!

Finds a given UUID in the UUID list returned by identify UUID.

Signed-off-by: Leonardo da Cunha <[email protected]>
@igaw igaw merged commit d1f4c66 into linux-nvme:master Jan 18, 2024
14 checks passed
@igaw
Copy link
Collaborator

igaw commented Jan 18, 2024

Thanks!

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