mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vhost_user_backend: Wait on the worker thread
Check the return value from the worker thread by saving the thread handle and waiting for it to return. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
committed by
Sebastien Boeuf
parent
97ab767a2f
commit
613f254908
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1072,6 +1072,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"epoll 4.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"epoll 4.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"log 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"vhost_rs 0.1.0",
|
"vhost_rs 0.1.0",
|
||||||
"vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)",
|
"vm-memory 0.1.0 (git+https://github.com/rust-vmm/vm-memory)",
|
||||||
"vm-virtio 0.1.0",
|
"vm-virtio 0.1.0",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ mmio_support = ["vm-virtio/mmio_support"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
epoll = ">=4.0.1"
|
epoll = ">=4.0.1"
|
||||||
libc = "0.2.66"
|
libc = "0.2.66"
|
||||||
|
log = "0.4.8"
|
||||||
vm-memory = { git = "https://github.com/rust-vmm/vm-memory" }
|
vm-memory = { git = "https://github.com/rust-vmm/vm-memory" }
|
||||||
vm-virtio = { path = "../vm-virtio" }
|
vm-virtio = { path = "../vm-virtio" }
|
||||||
vmm-sys-util = ">=0.3.1"
|
vmm-sys-util = ">=0.3.1"
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
// Copyright 2019 Alibaba Cloud Computing. All rights reserved.
|
// Copyright 2019 Alibaba Cloud Computing. All rights reserved.
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate log;
|
||||||
|
|
||||||
use std::error;
|
use std::error;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
@@ -398,6 +401,7 @@ struct VhostUserHandler<S: VhostUserBackend> {
|
|||||||
max_queue_size: usize,
|
max_queue_size: usize,
|
||||||
memory: Option<Memory>,
|
memory: Option<Memory>,
|
||||||
vrings: Vec<Arc<RwLock<Vring>>>,
|
vrings: Vec<Arc<RwLock<Vring>>>,
|
||||||
|
worker_thread: Option<thread::JoinHandle<VringWorkerResult<()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: VhostUserBackend> VhostUserHandler<S> {
|
impl<S: VhostUserBackend> VhostUserHandler<S> {
|
||||||
@@ -421,10 +425,12 @@ impl<S: VhostUserBackend> VhostUserHandler<S> {
|
|||||||
let vring_worker = Arc::new(VringWorker { epoll_fd });
|
let vring_worker = Arc::new(VringWorker { epoll_fd });
|
||||||
let worker = vring_worker.clone();
|
let worker = vring_worker.clone();
|
||||||
|
|
||||||
thread::Builder::new()
|
let worker_thread = Some(
|
||||||
.name("vring_worker".to_string())
|
thread::Builder::new()
|
||||||
.spawn(move || vring_worker.run(vring_handler))
|
.name("vring_worker".to_string())
|
||||||
.map_err(VhostUserHandlerError::SpawnVringWorker)?;
|
.spawn(move || vring_worker.run(vring_handler))
|
||||||
|
.map_err(VhostUserHandlerError::SpawnVringWorker)?,
|
||||||
|
);
|
||||||
|
|
||||||
Ok(VhostUserHandler {
|
Ok(VhostUserHandler {
|
||||||
backend,
|
backend,
|
||||||
@@ -437,6 +443,7 @@ impl<S: VhostUserBackend> VhostUserHandler<S> {
|
|||||||
max_queue_size,
|
max_queue_size,
|
||||||
memory: None,
|
memory: None,
|
||||||
vrings,
|
vrings,
|
||||||
|
worker_thread,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,3 +745,13 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandler for VhostUserHandler<S> {
|
|||||||
.map_err(VhostUserError::ReqHandlerError)
|
.map_err(VhostUserError::ReqHandlerError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<S: VhostUserBackend> Drop for VhostUserHandler<S> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
if let Some(thread) = self.worker_thread.take() {
|
||||||
|
if let Err(e) = thread.join() {
|
||||||
|
error!("Error in vring worker: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user