summary refs log tree commit diff
path: root/devices/src/virtio/vhost/control_socket.rs
blob: a1ccfaf90667c95a6c4e91dcfa6a4fba04ae10bd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use msg_socket::{MsgOnSocket, MsgSocket};
use sys_util::Error as SysError;

#[derive(MsgOnSocket, Debug)]
pub enum VhostDevRequest {
    /// Mask or unmask all the MSI entries for a Virtio Vhost device.
    MsixChanged,
    /// Mask or unmask a MSI entry for a Virtio Vhost device.
    MsixEntryChanged(usize),
}

#[derive(MsgOnSocket, Debug)]
pub enum VhostDevResponse {
    Ok,
    Err(SysError),
}

pub type VhostDevRequestSocket = MsgSocket<VhostDevRequest, VhostDevResponse>;
pub type VhostDevResponseSocket = MsgSocket<VhostDevResponse, VhostDevRequest>;

/// Create control socket pair. This pair is used to communicate with the
/// virtio device process.
/// Mainly between the virtio and activate thread.
pub fn create_control_sockets() -> (
    Option<VhostDevRequestSocket>,
    Option<VhostDevResponseSocket>,
) {
    match msg_socket::pair::<VhostDevRequest, VhostDevResponse>() {
        Ok((request, response)) => (Some(request), Some(response)),
        _ => (None, None),
    }
}