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

nvme: Add APIs for managing nvme_ctrl instances #19

Merged
merged 1 commit into from
Aug 27, 2024
Merged

Conversation

minwooim
Copy link
Collaborator

One might want for libvfn to manage nvme_ctrl instances which are initialized by the application inside of the library. This patch introduces nvme_get_ctrl, nvme_add_ctrl and nvme_del_ctrl APIs for application to request controller intance management. Rather than adding list_node to struct nvme_ctrl, it uses struct nvme_ctrl_handle inside of the core.c and open APIs based on the struct nvme_ctrl.

@minwooim minwooim requested a review from birkelund August 27, 2024 00:57
@minwooim minwooim force-pushed the add-ctrl-handles branch 4 times, most recently from 4df38d0 to be8bd90 Compare August 27, 2024 01:18
src/nvme/core.c Outdated

if (vfio_pci_open(&ctrl->pci, bdf))
return -1;

ctrl->pci.bdf = strdup(bdf);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a bug fix on its own?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, my bad. It should have not been added. Will remove it. Nice catch!

src/nvme/core.c Outdated
return -1;
}

handle = calloc(1, sizeof(struct nvme_ctrl_handle));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer zmalloc(), or in this case maybe znew_t(struct nvme_ctrl_handle, 1).

struct nvme_ctrl_handle *handle = nvme_get_ctrl_handle(bdf);

if (!handle)
return NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we set errno to ENODEV here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so. It might be used to check whether the library has the controller or not which means NULL itself does not mean failure.

src/nvme/core.c Outdated
struct nvme_ctrl_handle *handle;

if (nvme_get_ctrl(ctrl->pci.bdf)) {
errno = EALREADY;
Copy link
Collaborator

Choose a reason for hiding this comment

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

EALREADY is usually used for network, no? Not that EEXIST is that much better (referring to files), but we already use that in other places.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think EINVAL would be fine since the given bdf is invalid which has already been added.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

EEXIST is also fine to me.

@birkelund birkelund added the approved Approved for device testing label Aug 27, 2024
One might want for libvfn to manage nvme_ctrl instances which are
initialized by the application inside of the library.  This patch
introduces nvme_get_ctrl, nvme_add_ctrl and nvme_del_ctrl APIs for
application to request controller intance management.  Rather than
adding list_node to struct nvme_ctrl, it uses struct nvme_ctrl_handle
inside of the core.c and open APIs based on the struct nvme_ctrl.

Signed-off-by: Minwoo Im <[email protected]>
@minwooim
Copy link
Collaborator Author

@birkelund , Updated commit.

@birkelund birkelund merged commit a11cf59 into main Aug 27, 2024
25 checks passed
@birkelund birkelund deleted the add-ctrl-handles branch August 27, 2024 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved for device testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants