mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: rename terminate_fd to kill_evt for consistency
On-behalf-of: SAP julian.schindel@sap.com Signed-off-by: Julian Schindel <julian.schindel@cyberus-technology.de>
This commit is contained in:
committed by
Rob Bradford
parent
2ec52debc8
commit
11eace2660
@@ -281,8 +281,8 @@ fn wait_for_readable(fd: &impl AsFd, abort_event: &impl AsRawFd) -> Result<bool,
|
|||||||
pub(crate) struct ReceiveAdditionalConnections {
|
pub(crate) struct ReceiveAdditionalConnections {
|
||||||
accept_thread: Option<thread::JoinHandle<Result<(), MigratableError>>>,
|
accept_thread: Option<thread::JoinHandle<Result<(), MigratableError>>>,
|
||||||
|
|
||||||
/// Shared termination event for the accept thread and memory workers.
|
/// Shared kill eventfd for the accept thread and memory workers.
|
||||||
terminate_fd: EventFd,
|
kill_evt: EventFd,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReceiveAdditionalConnections {
|
impl ReceiveAdditionalConnections {
|
||||||
@@ -297,12 +297,12 @@ impl ReceiveAdditionalConnections {
|
|||||||
seccomp_action: &SeccompAction,
|
seccomp_action: &SeccompAction,
|
||||||
) -> Result<Self, MigratableError> {
|
) -> Result<Self, MigratableError> {
|
||||||
let event_fd = EventFd::new(0)
|
let event_fd = EventFd::new(0)
|
||||||
.context("Error creating terminate fd")
|
.context("Error creating kill_evt fd")
|
||||||
.map_err(MigratableError::MigrateReceive)?;
|
.map_err(MigratableError::MigrateReceive)?;
|
||||||
|
|
||||||
let terminate_fd = event_fd
|
let kill_evt = event_fd
|
||||||
.try_clone()
|
.try_clone()
|
||||||
.context("Error cloning terminate fd")
|
.context("Error cloning kill_evt fd")
|
||||||
.map_err(MigratableError::MigrateReceive)?;
|
.map_err(MigratableError::MigrateReceive)?;
|
||||||
|
|
||||||
let seccomp_filter = get_seccomp_filter(seccomp_action, Thread::MigrationTcpWorker, None)
|
let seccomp_filter = get_seccomp_filter(seccomp_action, Thread::MigrationTcpWorker, None)
|
||||||
@@ -320,7 +320,7 @@ impl ReceiveAdditionalConnections {
|
|||||||
|
|
||||||
Self::accept_connections(
|
Self::accept_connections(
|
||||||
listener,
|
listener,
|
||||||
&terminate_fd,
|
&kill_evt,
|
||||||
&guest_memory,
|
&guest_memory,
|
||||||
&fault_tx,
|
&fault_tx,
|
||||||
&seccomp_filter,
|
&seccomp_filter,
|
||||||
@@ -331,7 +331,7 @@ impl ReceiveAdditionalConnections {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
accept_thread: Some(accept_thread),
|
accept_thread: Some(accept_thread),
|
||||||
terminate_fd: event_fd,
|
kill_evt: event_fd,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,7 +348,7 @@ impl ReceiveAdditionalConnections {
|
|||||||
/// until EOF, error, or termination.
|
/// until EOF, error, or termination.
|
||||||
fn accept_connections(
|
fn accept_connections(
|
||||||
mut listener: ReceiveListener,
|
mut listener: ReceiveListener,
|
||||||
terminate_fd: &EventFd,
|
kill_evt: &EventFd,
|
||||||
guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>,
|
guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>,
|
||||||
fault_tx: &Sender<SocketStream>,
|
fault_tx: &Sender<SocketStream>,
|
||||||
seccomp_filter: &BpfProgram,
|
seccomp_filter: &BpfProgram,
|
||||||
@@ -356,7 +356,7 @@ impl ReceiveAdditionalConnections {
|
|||||||
let mut threads = Vec::new();
|
let mut threads = Vec::new();
|
||||||
let first_err = Self::accept_connections_loop(
|
let first_err = Self::accept_connections_loop(
|
||||||
&mut listener,
|
&mut listener,
|
||||||
terminate_fd,
|
kill_evt,
|
||||||
guest_memory,
|
guest_memory,
|
||||||
fault_tx,
|
fault_tx,
|
||||||
&mut threads,
|
&mut threads,
|
||||||
@@ -365,7 +365,7 @@ impl ReceiveAdditionalConnections {
|
|||||||
|
|
||||||
if first_err.is_err() {
|
if first_err.is_err() {
|
||||||
warn!("Signaling termination due to an error while accepting connections.");
|
warn!("Signaling termination due to an error while accepting connections.");
|
||||||
let _ = terminate_fd.write(1);
|
let _ = kill_evt.write(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Stopped accepting additional connections. Cleaning up threads.");
|
debug!("Stopped accepting additional connections. Cleaning up threads.");
|
||||||
@@ -381,14 +381,14 @@ impl ReceiveAdditionalConnections {
|
|||||||
/// migration thread and do not spawn workers.
|
/// migration thread and do not spawn workers.
|
||||||
fn accept_connections_loop(
|
fn accept_connections_loop(
|
||||||
listener: &mut ReceiveListener,
|
listener: &mut ReceiveListener,
|
||||||
terminate_fd: &EventFd,
|
kill_evt: &EventFd,
|
||||||
guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>,
|
guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>,
|
||||||
fault_tx: &Sender<SocketStream>,
|
fault_tx: &Sender<SocketStream>,
|
||||||
threads: &mut Vec<thread::JoinHandle<Result<(), MigratableError>>>,
|
threads: &mut Vec<thread::JoinHandle<Result<(), MigratableError>>>,
|
||||||
seccomp_filter: &BpfProgram,
|
seccomp_filter: &BpfProgram,
|
||||||
) -> Result<(), MigratableError> {
|
) -> Result<(), MigratableError> {
|
||||||
loop {
|
loop {
|
||||||
let socket = listener.abortable_accept(terminate_fd)?;
|
let socket = listener.abortable_accept(kill_evt)?;
|
||||||
let Some(socket) = socket else {
|
let Some(socket) = socket else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
@@ -406,7 +406,7 @@ impl ReceiveAdditionalConnections {
|
|||||||
let thread = Self::spawn_memory_worker(
|
let thread = Self::spawn_memory_worker(
|
||||||
socket,
|
socket,
|
||||||
threads.len(),
|
threads.len(),
|
||||||
terminate_fd,
|
kill_evt,
|
||||||
guest_memory.clone(),
|
guest_memory.clone(),
|
||||||
seccomp_filter,
|
seccomp_filter,
|
||||||
)?;
|
)?;
|
||||||
@@ -461,13 +461,13 @@ impl ReceiveAdditionalConnections {
|
|||||||
fn spawn_memory_worker(
|
fn spawn_memory_worker(
|
||||||
mut socket: SocketStream,
|
mut socket: SocketStream,
|
||||||
index: usize,
|
index: usize,
|
||||||
terminate_fd: &EventFd,
|
kill_evt: &EventFd,
|
||||||
guest_memory: GuestMemoryAtomic<GuestMemoryMmap>,
|
guest_memory: GuestMemoryAtomic<GuestMemoryMmap>,
|
||||||
seccomp_filter: &BpfProgram,
|
seccomp_filter: &BpfProgram,
|
||||||
) -> Result<thread::JoinHandle<Result<(), MigratableError>>, MigratableError> {
|
) -> Result<thread::JoinHandle<Result<(), MigratableError>>, MigratableError> {
|
||||||
let terminate_fd = terminate_fd
|
let kill_evt = kill_evt
|
||||||
.try_clone()
|
.try_clone()
|
||||||
.context("Error cloning terminate fd")
|
.context("Error cloning kill_evt fd")
|
||||||
.map_err(MigratableError::MigrateReceive)?;
|
.map_err(MigratableError::MigrateReceive)?;
|
||||||
|
|
||||||
let seccomp_filter_t = seccomp_filter.clone();
|
let seccomp_filter_t = seccomp_filter.clone();
|
||||||
@@ -479,7 +479,7 @@ impl ReceiveAdditionalConnections {
|
|||||||
.context("Error applying migration TCP worker seccomp filter")
|
.context("Error applying migration TCP worker seccomp filter")
|
||||||
.map_err(MigratableError::MigrateReceive)?;
|
.map_err(MigratableError::MigrateReceive)?;
|
||||||
}
|
}
|
||||||
Self::worker_receive_memory(&mut socket, &terminate_fd, &guest_memory)
|
Self::worker_receive_memory(&mut socket, &kill_evt, &guest_memory)
|
||||||
})
|
})
|
||||||
.map_err(|e| {
|
.map_err(|e| {
|
||||||
error!("Error spawning receive-memory thread: {e}");
|
error!("Error spawning receive-memory thread: {e}");
|
||||||
@@ -518,13 +518,13 @@ impl ReceiveAdditionalConnections {
|
|||||||
/// memory.
|
/// memory.
|
||||||
fn worker_receive_memory(
|
fn worker_receive_memory(
|
||||||
mut socket: &mut SocketStream,
|
mut socket: &mut SocketStream,
|
||||||
terminate_fd: &EventFd,
|
kill_evt: &EventFd,
|
||||||
guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>,
|
guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>,
|
||||||
) -> Result<(), MigratableError> {
|
) -> Result<(), MigratableError> {
|
||||||
loop {
|
loop {
|
||||||
// We only check whether we should abort when waiting for a new request. If the
|
// We only check whether we should abort when waiting for a new request. If the
|
||||||
// sender stops sending data mid-request, we will hang forever.
|
// sender stops sending data mid-request, we will hang forever.
|
||||||
if !wait_for_readable(socket, terminate_fd)
|
if !wait_for_readable(socket, kill_evt)
|
||||||
.context("Failed to poll fds")
|
.context("Failed to poll fds")
|
||||||
.map_err(MigratableError::MigrateReceive)?
|
.map_err(MigratableError::MigrateReceive)?
|
||||||
{
|
{
|
||||||
@@ -567,9 +567,9 @@ impl ReceiveAdditionalConnections {
|
|||||||
/// Signals to the worker threads that the migration is finished and joins them.
|
/// Signals to the worker threads that the migration is finished and joins them.
|
||||||
/// If any thread encountered an error, this error is returned by this function.
|
/// If any thread encountered an error, this error is returned by this function.
|
||||||
pub(crate) fn cleanup(&mut self) -> Result<(), MigratableError> {
|
pub(crate) fn cleanup(&mut self) -> Result<(), MigratableError> {
|
||||||
self.terminate_fd
|
self.kill_evt
|
||||||
.write(1)
|
.write(1)
|
||||||
.context("Failed to signal termination to worker threads.")
|
.context("Failed to write to kill eventfd")
|
||||||
.map_err(MigratableError::MigrateReceive)?;
|
.map_err(MigratableError::MigrateReceive)?;
|
||||||
let accept_thread = self
|
let accept_thread = self
|
||||||
.accept_thread
|
.accept_thread
|
||||||
|
|||||||
Reference in New Issue
Block a user