Struct crosvm::crosvm::plugin::process::Process

source ·
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>§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>

Implementations§

source§

impl Process

source

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 vcpus
  • cmd: path to plugin executable
  • args: arguments to plugin executable
  • jail: jail to launch plugin in. If None plugin will just be spawned as a child
  • stderr: File to redirect stderr of plugin process to
source

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.

source

pub fn is_started(&self) -> bool

Returns if the plugin process indicated the VM was ready to start.

source

pub fn pid(&self) -> pid_t

Returns the process ID of the plugin process.

source

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.

source

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.

source

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.

source

pub fn try_wait(&mut self) -> SysResult<ProcessStatus>

Waits without blocking for the plugin process to exit and returns the status.

source

fn handle_io_event( entry: VacantEntry<'_, u32, PluginObject>, vm: &mut Vm, io_event: &IoEvent, ) -> SysResult<RawDescriptor>

source

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<()>

source

fn handle_reserve_range( &mut self, reserve_range: &ReserveRange, ) -> SysResult<()>

source

fn handle_set_irq_routing( vm: &mut Vm, irq_routing: &SetIrqRouting, ) -> SysResult<()>

source

fn handle_set_call_hint(&mut self, hints: &SetCallHint) -> SysResult<()>

source

fn handle_pause_vcpus( &self, vcpu_handles: &[JoinHandle<()>], cpu_mask: u64, user_data: u64, )

source

fn handle_get_net_config(tap: &Tap, config: &mut GetNetConfig) -> SysResult<()>

source

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§

source§

impl Drop for Process

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V