pub struct Process {
started: bool,
plugin_pid: pid_t,
request_sockets: Vec<ScmSocket<UnixDatagram>>,
objects: HashMap<u32, PluginObject>,
shared_vcpu_state: Arc<RwLock<SharedVcpuState>>,
per_vcpu_states: Vec<Arc<Mutex<PerVcpuState>>>,
kill_evt: Event,
vcpu_pipes: Vec<VcpuPipe>,
request_buffer: Vec<u8>,
response_buffer: Vec<u8>,
}
Expand description
Creates, owns, and handles messages from a plugin process.
A plugin process has control over a single VM and a fixed number of VCPUs via a set of pipes &
unix domain socket connections and a protocol defined in protos::plugin
. The plugin process is
run in an unprivileged manner as a child process spawned via a path to a arbitrary executable.
Fields§
§started: bool
§plugin_pid: pid_t
§request_sockets: Vec<ScmSocket<UnixDatagram>>
§objects: HashMap<u32, PluginObject>
§per_vcpu_states: Vec<Arc<Mutex<PerVcpuState>>>
§kill_evt: Event
§vcpu_pipes: Vec<VcpuPipe>
§request_buffer: Vec<u8>
§response_buffer: Vec<u8>
Implementations§
source§impl Process
impl Process
sourcepub fn new(
cpu_count: u32,
cmd: &Path,
args: &[&str],
jail: Option<Minijail>,
stderr: File,
) -> Result<Process>
pub fn new( cpu_count: u32, cmd: &Path, args: &[&str], jail: Option<Minijail>, stderr: File, ) -> Result<Process>
Creates a new plugin process for the given number of vcpus and VM.
This will immediately spawn the plugin process and wait for the child to signal that it is ready to start. This call may block indefinitely.
Set the jail
argument to spawn the plugin process within the preconfigured jail.
Due to an API limitation in libminijail necessitating that this function set an environment
variable, this function is not thread-safe.
Arguments:
cpu_count
: number of vcpuscmd
: path to plugin executableargs
: arguments to plugin executablejail
: jail to launch plugin in. If None plugin will just be spawned as a childstderr
: File to redirect stderr of plugin process to
sourcepub fn create_vcpu(&self, cpu_id: u32) -> Result<PluginVcpu>
pub fn create_vcpu(&self, cpu_id: u32) -> Result<PluginVcpu>
Creates a VCPU plugin connection object, used by a VCPU run loop to communicate with the plugin process.
While each invocation of create_vcpu
with the given cpu_id
will return a unique
PluginVcpu
object, the underlying resources are shared by each PluginVcpu
resulting from
the same cpu_id
.
sourcepub fn is_started(&self) -> bool
pub fn is_started(&self) -> bool
Returns if the plugin process indicated the VM was ready to start.
sourcepub fn sockets(&self) -> &[ScmSocket<UnixDatagram>]
pub fn sockets(&self) -> &[ScmSocket<UnixDatagram>]
Returns a slice of each socket that should be polled.
If any socket in this slice becomes readable, handle_socket
should be called with the
index of that socket. If any socket becomes closed, its index should be passed to
drop_sockets
.
sourcepub fn drop_sockets(&mut self, socket_idxs: &mut [usize])
pub fn drop_sockets(&mut self, socket_idxs: &mut [usize])
Drops the each socket identified by its index in the slice returned by sockets
.
The given socket_idxs
slice will be modified in an arbitrary way for efficient removal of
the sockets from internal data structures.
sourcepub fn signal_kill(&mut self) -> SysResult<()>
pub fn signal_kill(&mut self) -> SysResult<()>
Gently requests that the plugin process exit cleanly, and ends handling of all VCPU connections.
The plugin process can ignore the given signal, and so some timeout should be used before forcefully terminating the process.
Any blocked VCPU connections will get interrupted so that the VCPU threads can exit cleanly. Any subsequent attempt to use the VCPU connections will fail.
sourcepub fn try_wait(&mut self) -> SysResult<ProcessStatus>
pub fn try_wait(&mut self) -> SysResult<ProcessStatus>
Waits without blocking for the plugin process to exit and returns the status.
fn handle_io_event( entry: VacantEntry<'_, u32, PluginObject>, vm: &mut Vm, io_event: &IoEvent, ) -> SysResult<RawDescriptor>
fn handle_memory( entry: VacantEntry<'_, u32, PluginObject>, vm: &mut Vm, memfd: File, offset: u64, start: u64, length: u64, read_only: bool, dirty_log: bool, ) -> SysResult<()>
fn handle_reserve_range( &mut self, reserve_range: &ReserveRange, ) -> SysResult<()>
fn handle_set_irq_routing( vm: &mut Vm, irq_routing: &SetIrqRouting, ) -> SysResult<()>
fn handle_set_call_hint(&mut self, hints: &SetCallHint) -> SysResult<()>
fn handle_pause_vcpus( &self, vcpu_handles: &[JoinHandle<()>], cpu_mask: u64, user_data: u64, )
fn handle_get_net_config(tap: &Tap, config: &mut GetNetConfig) -> SysResult<()>
sourcepub fn handle_socket(
&mut self,
index: usize,
kvm: &Kvm,
vm: &mut Vm,
vcpu_handles: &[JoinHandle<()>],
taps: &[Tap],
) -> Result<(), CommError>
pub fn handle_socket( &mut self, index: usize, kvm: &Kvm, vm: &mut Vm, vcpu_handles: &[JoinHandle<()>], taps: &[Tap], ) -> Result<(), CommError>
Handles a request on a readable socket identified by its index in the slice returned by
sockets
.
The vm
is used to service request that affect the VM. The vcpu_handles
slice is used to
interrupt a VCPU thread currently running in the VM if the socket request it.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Process
impl RefUnwindSafe for Process
impl Send for Process
impl Sync for Process
impl Unpin for Process
impl UnwindSafe for Process
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.