Skip to content
This repository was archived by the owner on Oct 24, 2022. It is now read-only.

Refactor vring abstraction #30

Merged
merged 4 commits into from
Sep 7, 2021
Merged

Refactor vring abstraction #30

merged 4 commits into from
Sep 7, 2021

Conversation

jiangliu
Copy link
Member

@jiangliu jiangliu commented Sep 1, 2021

Add trait VringT and provide three implementation of it: VringState, VringMutex, VringRwLock,
so clients could choose different implementation.

Copy link
Member

@stefano-garzarella stefano-garzarella left a comment

Choose a reason for hiding this comment

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

The refactor looks great, just a couple of simple copy&paste typos :-)

@slp
Copy link
Collaborator

slp commented Sep 1, 2021

Thanks for working on this. I must be missing something, but I can't find a way to access the underlying Queue in VringState to iterate over it. What's the pattern to lock the Vring and iterate on the Queue to get the descriptor chains?

@jiangliu
Copy link
Member Author

jiangliu commented Sep 2, 2021

Thanks for working on this. I must be missing something, but I can't find a way to access the underlying Queue in VringState to iterate over it. What's the pattern to lock the Vring and iterate on the Queue to get the descriptor chains?

I realized this issue and have updated the patch yesterday. Now we have "VringState::get_queue()" and "VringState::get_queue_mut()" for that purpose.
https://github.com/rust-vmm/vhost-user-backend/pull/30/files#diff-04f224919b2745af8bfb2d2aea4be7d9100e861a8a16f2cd0263cb1021b44c4dR151

@slp
Copy link
Collaborator

slp commented Sep 2, 2021

Thanks for working on this. I must be missing something, but I can't find a way to access the underlying Queue in VringState to iterate over it. What's the pattern to lock the Vring and iterate on the Queue to get the descriptor chains?

I realized this issue and have updated the patch yesterday. Now we have "VringState::get_queue()" and "VringState::get_queue_mut()" for that purpose.
https://github.com/rust-vmm/vhost-user-backend/pull/30/files#diff-04f224919b2745af8bfb2d2aea4be7d9100e861a8a16f2cd0263cb1021b44c4dR151

Great, thanks!

I've tested this crate with virtiofsd, and was able to implement both a multi-threaded method and a single-threaded method for processing the queue, so I think this model should work for most consumers of this crate.

One change that I think could be interesting, is publishing VringStateGuard and VringStateMutGuard in the root of the crate (since vring is private). That allows consumers to acquire a reference to VringState (and thus, the underlying lock, if using VringMutex or VringRwLock) once and pass it around to other methods. What do you think about this?

@jiangliu
Copy link
Member Author

jiangliu commented Sep 2, 2021

Thanks for working on this. I must be missing something, but I can't find a way to access the underlying Queue in VringState to iterate over it. What's the pattern to lock the Vring and iterate on the Queue to get the descriptor chains?

I realized this issue and have updated the patch yesterday. Now we have "VringState::get_queue()" and "VringState::get_queue_mut()" for that purpose.
https://github.com/rust-vmm/vhost-user-backend/pull/30/files#diff-04f224919b2745af8bfb2d2aea4be7d9100e861a8a16f2cd0263cb1021b44c4dR151

Great, thanks!

I've tested this crate with virtiofsd, and was able to implement both a multi-threaded method and a single-threaded method for processing the queue, so I think this model should work for most consumers of this crate.

One change that I think could be interesting, is publishing VringStateGuard and VringStateMutGuard in the root of the crate (since vring is private). That allows consumers to acquire a reference to VringState (and thus, the underlying lock, if using VringMutex or VringRwLock) once and pass it around to other methods. What do you think about this?

Done:)

@slp
Copy link
Collaborator

slp commented Sep 3, 2021

Thanks again! :-)

slp
slp previously approved these changes Sep 3, 2021
@slp
Copy link
Collaborator

slp commented Sep 6, 2021

@jiangliu Could you please rebase this on top of f0af5f7 ?

That should fix CI.

Introduce trait VringT, and provide three implementations of it:
VringState, VringMutex, VringRwLock.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Enhance VhostUserBackend, VhostUserBackendMut, VringEpollHandler,
VhostUserHandler and VhostUserDaemon to support generic type
`V: VringT', so clients could choose different VringT implementations.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Add VringT::get_mut() to get exclusive reference to underlying
VringState object, so the clients could avoid repeatedly lock/unlock
when using VringMutex and VringRwLock.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Refine the way to manage epoll event id and simplify interfaces:
- Change VhostUserBackend::exit_event() to return Option<EventFd>
  instead of Option<(EventFd, u16)>.
- Delete VringEpollHandler::exit_event_id.
- Add VringEpollHandler::register_event/unregister_event for internal
  use.
- Make VringEpollHandler::register_listener/unregister_listener() for
  external users only, and 'data` range [0..backend.num_queues()] is
  reserved for queues and exit event.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
Copy link
Collaborator

@slp slp left a comment

Choose a reason for hiding this comment

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

LGTM (again), thanks!

@jiangliu jiangliu merged commit e8beb23 into rust-vmm:main Sep 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants