stratovirt/machine_manager-move-argument-serial-from-drive-to-d.patch
Jie Yang 2d9d03c21a Update version to 2.0.0-6
Signed-off-by: Jie Yang <yangjieyj.yang@huawei.com>
(cherry picked from commit 6158eab66897bf7fb11ce7ae8c3b568f8de0e2dd)
2021-08-30 21:19:11 +08:00

136 lines
5.7 KiB
Diff

From a2dcc9cb71d8a341d5f437edcbe1a9c19a69e1a7 Mon Sep 17 00:00:00 2001
From: Ming Yang <yangming73@huawei.com>
Date: Fri, 27 Aug 2021 16:51:29 +0800
Subject: [PATCH 07/10] machine_manager: move argument "serial" from -drive to
-device virtio-blk-pci/device.
1. When interconnect with libvirt, the "serial" argument is given followed by -device
virtio-blk-pci. Thus it is moved in this commit.
Signed-off-by: Ming Yang <yangming73@huawei.com>
---
docs/config_guidebook.md | 8 ++++----
machine_manager/src/config/drive.rs | 25 +++++++++++++------------
2 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/docs/config_guidebook.md b/docs/config_guidebook.md
index e1279e1..b1f7b08 100644
--- a/docs/config_guidebook.md
+++ b/docs/config_guidebook.md
@@ -171,11 +171,11 @@ If you want to boot VM with a virtio block device as rootfs, you should add `roo
```shell
# virtio mmio block device.
--drive id=drive_id,file=path_on_host[,serial=serial_num,readonly=off,direct=off,throttling.iops-total=200]
--device virtio-blk-device,drive=drive_id[,iothread=iothread1]
+-drive id=drive_id,file=path_on_host[,readonly=off][,direct=off][,throttling.iops-total=200]
+-device virtio-blk-device,drive=drive_id[,iothread=iothread1][,serial=serial_num]
# virtio pci block device.
--drive id=drive_id,file=path_on_host[,serial=serial_num,readonly=off,direct=off,throttling.iops-total=200]
--device virtio-blk-pci,drive=drive_id,bus=pcie.0,addr=0x3.0x0[,iothread=iothread1]
+-drive id=drive_id,file=path_on_host[,readonly=off][,direct=off][,throttling.iops-total=200]
+-device virtio-blk-pci,drive=drive_id,bus=pcie.0,addr=0x3.0x0[,iothread=iothread1,][serial=serial_num]
```
diff --git a/machine_manager/src/config/drive.rs b/machine_manager/src/config/drive.rs
index 4d05eb8..3aaef75 100644
--- a/machine_manager/src/config/drive.rs
+++ b/machine_manager/src/config/drive.rs
@@ -62,7 +62,6 @@ pub struct DriveConfig {
pub path_on_host: String,
pub read_only: bool,
pub direct: bool,
- pub serial_num: Option<String>,
pub iops: Option<u64>,
}
@@ -73,7 +72,6 @@ impl Default for DriveConfig {
path_on_host: "".to_string(),
read_only: false,
direct: true,
- serial_num: None,
iops: None,
}
}
@@ -155,9 +153,6 @@ pub fn parse_drive(cmd_parser: CmdParser) -> Result<DriveConfig> {
if let Some(direct) = cmd_parser.get_value::<ExBool>("direct")? {
drive.direct = direct.into();
}
- if let Some(serial) = cmd_parser.get_value::<String>("serial")? {
- drive.serial_num = Some(serial);
- }
drive.iops = cmd_parser.get_value::<u64>("throttling.iops-total")?;
Ok(drive)
}
@@ -171,6 +166,7 @@ pub fn parse_blk(vm_config: &mut VmConfig, drive_config: &str) -> Result<BlkDevC
.push("addr")
.push("drive")
.push("bootindex")
+ .push("serial")
.push("iothread");
cmd_parser.parse(drive_config)?;
@@ -192,12 +188,15 @@ pub fn parse_blk(vm_config: &mut VmConfig, drive_config: &str) -> Result<BlkDevC
blkdevcfg.iothread = Some(iothread);
}
+ if let Some(serial) = cmd_parser.get_value::<String>("serial")? {
+ blkdevcfg.serial_num = Some(serial);
+ }
+
if let Some(drive_arg) = &vm_config.drives.remove(&blkdrive) {
blkdevcfg.id = drive_arg.id.clone();
blkdevcfg.path_on_host = drive_arg.path_on_host.clone();
blkdevcfg.read_only = drive_arg.read_only;
blkdevcfg.direct = drive_arg.direct;
- blkdevcfg.serial_num = drive_arg.serial_num.clone();
blkdevcfg.iops = drive_arg.iops;
} else {
bail!("No drive configured matched for blk device");
@@ -361,11 +360,13 @@ mod tests {
fn test_drive_config_cmdline_parser() {
let mut vm_config = VmConfig::default();
assert!(vm_config
- .add_drive("id=rootfs,file=/path/to/rootfs,serial=111111,readonly=off,direct=on,throttling.iops-total=200")
+ .add_drive(
+ "id=rootfs,file=/path/to/rootfs,readonly=off,direct=on,throttling.iops-total=200"
+ )
.is_ok());
let blk_cfg_res = parse_blk(
&mut vm_config,
- "virtio-blk-device,drive=rootfs,iothread=iothread1",
+ "virtio-blk-device,drive=rootfs,iothread=iothread1,serial=111111",
);
assert!(blk_cfg_res.is_ok());
let blk_device_config = blk_cfg_res.unwrap();
@@ -377,11 +378,11 @@ mod tests {
let mut vm_config = VmConfig::default();
assert!(vm_config
- .add_drive("id=rootfs,file=/path/to/rootfs,serial=111111,readonly=off,direct=on")
+ .add_drive("id=rootfs,file=/path/to/rootfs,readonly=off,direct=on")
.is_ok());
let blk_cfg_res = parse_blk(
&mut vm_config,
- "virtio-blk-device,drive=rootfs1,iothread=iothread1,iops=200",
+ "virtio-blk-device,drive=rootfs1,iothread=iothread1,iops=200,serial=111111",
);
assert!(blk_cfg_res.is_err()); // Can not find drive named "rootfs1".
}
@@ -390,9 +391,9 @@ mod tests {
fn test_pci_block_config_cmdline_parser() {
let mut vm_config = VmConfig::default();
assert!(vm_config
- .add_drive("id=rootfs,file=/path/to/rootfs,serial=111111,readonly=off,direct=on")
+ .add_drive("id=rootfs,file=/path/to/rootfs,readonly=off,direct=on")
.is_ok());
- let blk_cfg = "virtio-blk-pci,id=blk1,bus=pcie.0,addr=0x1.0x2,drive=rootfs";
+ let blk_cfg = "virtio-blk-pci,id=blk1,bus=pcie.0,addr=0x1.0x2,drive=rootfs,serial=111111";
let blk_cfg_res = parse_blk(&mut vm_config, blk_cfg);
assert!(blk_cfg_res.is_ok());
let drive_configs = blk_cfg_res.unwrap();
--
2.25.1