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

vsock: avoid circular references #499

Merged
merged 3 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vhost-device-vsock/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ pub(crate) fn start_backend_server(
)
.map_err(BackendError::CouldNotCreateDaemon)?;

let mut vring_workers = daemon.get_epoll_handlers();
let mut epoll_handlers = daemon.get_epoll_handlers();

for thread in backend.threads.iter() {
thread
.lock()
.unwrap()
.set_vring_worker(Some(vring_workers.remove(0)));
.register_listeners(epoll_handlers.remove(0));
}

daemon.start(listener).unwrap();
Expand Down
18 changes: 5 additions & 13 deletions vhost-device-vsock/src/vhu_vsock_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ pub(crate) struct VhostUserVsockThread {
host_sock_path: String,
/// Listener listening for new connections on the host.
host_listener: UnixListener,
/// Instance of VringWorker.
vring_worker: Option<Arc<VringEpollHandler<ArcVhostBknd, VringRwLock, ()>>>,
/// epoll fd to which new host connections are added.
epoll_file: File,
/// VsockThreadBackend instance.
Expand Down Expand Up @@ -151,7 +149,6 @@ impl VhostUserVsockThread {
host_sock: host_sock.as_raw_fd(),
host_sock_path: uds_path,
host_listener: host_sock,
vring_worker: None,
epoll_file,
thread_backend,
guest_cid,
Expand Down Expand Up @@ -242,20 +239,15 @@ impl VhostUserVsockThread {
self.epoll_file.as_raw_fd()
}

/// Set self's VringWorker.
pub fn set_vring_worker(
/// Register our listeners in the VringEpollHandler
pub fn register_listeners(
&mut self,
vring_worker: Option<Arc<VringEpollHandler<ArcVhostBknd, VringRwLock, ()>>>,
epoll_handler: Arc<VringEpollHandler<ArcVhostBknd, VringRwLock, ()>>,
) {
self.vring_worker = vring_worker;
self.vring_worker
.as_ref()
.unwrap()
epoll_handler
.register_listener(self.get_epoll_fd(), EventSet::IN, u64::from(BACKEND_EVENT))
.unwrap();
self.vring_worker
.as_ref()
.unwrap()
epoll_handler
.register_listener(
self.sibling_event_fd.as_raw_fd(),
EventSet::IN,
Expand Down