vm-virtio: vhost-user-fs: Expect an identifier upon device creation

This identifier is chosen from the DeviceManager so that it will manage
all identifiers across the VM, which will ensure uniqueness.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-04-27 13:53:45 +02:00 committed by Rob Bradford
parent ec5ff395cf
commit bb7fa71fcb
2 changed files with 16 additions and 4 deletions

View File

@ -267,6 +267,7 @@ impl Default for VirtioFsConfig {
unsafe impl ByteValued for VirtioFsConfig {}
pub struct Fs {
id: String,
vu: Master,
queue_sizes: Vec<u16>,
avail_features: u64,
@ -287,6 +288,7 @@ pub struct Fs {
impl Fs {
/// Create a new virtio-fs device.
pub fn new(
id: String,
path: &str,
tag: &str,
req_num_queues: usize,
@ -352,6 +354,7 @@ impl Fs {
config.num_request_queues = req_num_queues as u32;
Ok(Fs {
id,
vu: master,
queue_sizes: vec![queue_size; num_queues],
avail_features,
@ -605,6 +608,10 @@ impl VirtioDevice for Fs {
}
virtio_pausable!(Fs);
impl Snapshottable for Fs {}
impl Snapshottable for Fs {
fn id(&self) -> String {
self.id.clone()
}
}
impl Transportable for Fs {}
impl Migratable for Fs {}

View File

@ -1458,9 +1458,13 @@ impl DeviceManager {
&mut self,
fs_cfg: &mut FsConfig,
) -> DeviceManagerResult<(VirtioDeviceArc, bool, Option<String>)> {
if fs_cfg.id.is_none() {
fs_cfg.id = Some(self.next_device_name(FS_DEVICE_NAME_PREFIX)?);
}
let id = if let Some(id) = &fs_cfg.id {
id.clone()
} else {
let id = self.next_device_name(FS_DEVICE_NAME_PREFIX)?;
fs_cfg.id = Some(id.clone());
id
};
if let Some(fs_sock) = fs_cfg.sock.to_str() {
let cache = if fs_cfg.dax {
@ -1519,6 +1523,7 @@ impl DeviceManager {
let virtio_fs_device = Arc::new(Mutex::new(
vm_virtio::vhost_user::Fs::new(
id,
fs_sock,
&fs_cfg.tag,
fs_cfg.num_queues,