vm-virtio: blk: 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 11:21:15 +02:00
committed by Rob Bradford
parent ff9c8b847f
commit be946caf4b
2 changed files with 16 additions and 11 deletions

View File

@@ -1181,9 +1181,13 @@ impl DeviceManager {
&mut self,
disk_cfg: &mut DiskConfig,
) -> DeviceManagerResult<(VirtioDeviceArc, bool, Option<String>)> {
if disk_cfg.id.is_none() {
disk_cfg.id = Some(self.next_device_name(DISK_DEVICE_NAME_PREFIX)?);
}
let id = if let Some(id) = &disk_cfg.id {
id.clone()
} else {
let id = self.next_device_name(DISK_DEVICE_NAME_PREFIX)?;
disk_cfg.id = Some(id.clone());
id
};
if disk_cfg.vhost_user {
let sock = if let Some(sock) = disk_cfg.vhost_socket.clone() {
@@ -1235,6 +1239,7 @@ impl DeviceManager {
match image_type {
ImageType::Raw => {
let dev = vm_virtio::Block::new(
id,
raw_img,
disk_cfg
.path
@@ -1262,6 +1267,7 @@ impl DeviceManager {
let qcow_img =
QcowFile::from(raw_img).map_err(DeviceManagerError::QcowDeviceCreate)?;
let dev = vm_virtio::Block::new(
id,
qcow_img,
disk_cfg
.path