From a8cdf2f070ce7d596dba2f6f43508d6624eecdad Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Thu, 4 Jun 2020 12:19:24 -0700 Subject: [PATCH] tests,vm-virtio,vmm: Use 'socket' for all CLI/API parameters This patch unifies the inconsistent uses of 'socket' and 'sock' from our CLI/API parameters. Fixes: #1091 Signed-off-by: Bo Chen --- docs/fs.md | 8 +-- src/main.rs | 82 +++++++++++----------- tests/integration.rs | 34 ++++----- vm-virtio/src/vhost_user/blk.rs | 2 +- vm-virtio/src/vhost_user/net.rs | 2 +- vm-virtio/src/vhost_user/vu_common_ctrl.rs | 2 +- vmm/src/api/openapi/cloud-hypervisor.yaml | 8 +-- vmm/src/config.rs | 70 +++++++++--------- vmm/src/device_manager.rs | 34 ++++----- 9 files changed, 122 insertions(+), 120 deletions(-) diff --git a/docs/fs.md b/docs/fs.md index 86b3c63c8..68d21df94 100644 --- a/docs/fs.md +++ b/docs/fs.md @@ -59,21 +59,21 @@ Assuming you have `clear-kvm.img` and `custom-vmlinux.bin` on your system, here --memory "size=512,file=/dev/shm" \ --disk path=clear-kvm.img \ --kernel custom-vmlinux.bin \ - --cmdline "console=ttyS0 reboot=k panic=1 nomodules root=/dev/vda3" \ - --fs tag=myfs,sock=/tmp/virtiofs,num_queues=1,queue_size=512 + --cmdline "console=ttyS0 reboot=k panic=1 nomodules root=/dev/vda3" \ + --fs tag=myfs,socket=/tmp/virtiofs,num_queues=1,queue_size=512 ``` By default, DAX is enabled with a cache window of 8GiB. You can specify a custom size (let's say 4GiB for this example) for the cache by explicitly setting DAX and the cache size: ```bash ---fs tag=virtiofs,sock=/tmp/virtiofs,num_queues=1,queue_size=512,dax=on,cache_size=4G +--fs tag=virtiofs,socket=/tmp/virtiofs,num_queues=1,queue_size=512,dax=on,cache_size=4G ``` In case you don't want to use a shared window of cache to pass the shared files content, this means you will have to explicitly disable DAX with `dax=off`. Note that in this case, the `cache_size` parameter will be ignored. ```bash ---fs tag=virtiofs,sock=/tmp/virtiofs,num_queues=1,queue_size=512,dax=off +--fs tag=virtiofs,socket=/tmp/virtiofs,num_queues=1,queue_size=512,dax=off ``` diff --git a/src/main.rs b/src/main.rs index f7c3a7420..7250158f7 100755 --- a/src/main.rs +++ b/src/main.rs @@ -745,14 +745,14 @@ mod unit_tests { "--memory", "shared=true", "--disk", - "vhost_user=true,socket=/tmp/socket1", + "vhost_user=true,socket=/tmp/sock1", "path=/path/to/disk/2", ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "disks": [ - {"vhost_user":true, "vhost_socket":"/tmp/socket1"}, + {"vhost_user":true, "vhost_socket":"/tmp/sock1"}, {"path": "/path/to/disk/2"} ] }"#, @@ -766,14 +766,14 @@ mod unit_tests { "--memory", "shared=true", "--disk", - "vhost_user=true,socket=/tmp/socket1", + "vhost_user=true,socket=/tmp/sock1", "path=/path/to/disk/2", ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "disks": [ - {"vhost_user":true, "vhost_socket":"/tmp/socket1"}, + {"vhost_user":true, "vhost_socket":"/tmp/sock1"}, {"path": "/path/to/disk/2"} ] }"#, @@ -952,12 +952,12 @@ mod unit_tests { true, ), ( - vec!["cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--net", "mac=12:34:56:78:90:ab,host_mac=34:56:78:90:ab:cd,vhost_user=true,socket=/tmp/socket"], + vec!["cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--net", "mac=12:34:56:78:90:ab,host_mac=34:56:78:90:ab:cd,vhost_user=true,socket=/tmp/sock"], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "net": [ - {"mac": "12:34:56:78:90:ab", "host_mac": "34:56:78:90:ab:cd", "vhost_user": true, "vhost_socket": "/tmp/socket"} + {"mac": "12:34:56:78:90:ab", "host_mac": "34:56:78:90:ab:cd", "vhost_user": true, "vhost_socket": "/tmp/sock"} ] }"#, true, @@ -999,15 +999,15 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1", - "tag=virtiofs2,sock=/path/to/sock2", + "tag=virtiofs1,socket=/path/to/sock1", + "tag=virtiofs2,socket=/path/to/sock2", ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1"}, - {"tag": "virtiofs2", "sock": "/path/to/sock2"} + {"tag": "virtiofs1", "socket": "/path/to/sock1"}, + {"tag": "virtiofs2", "socket": "/path/to/sock2"} ] }"#, true, @@ -1017,14 +1017,14 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1", - "tag=virtiofs2,sock=/path/to/sock2", + "tag=virtiofs1,socket=/path/to/sock1", + "tag=virtiofs2,socket=/path/to/sock2", ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1"} + {"tag": "virtiofs1", "socket": "/path/to/sock1"} ] }"#, false, @@ -1034,13 +1034,13 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1,num_queues=4", + "tag=virtiofs1,socket=/path/to/sock1,num_queues=4", ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1", "num_queues": 4} + {"tag": "virtiofs1", "socket": "/path/to/sock1", "num_queues": 4} ] }"#, true, @@ -1050,13 +1050,13 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1,num_queues=4,queue_size=128" + "tag=virtiofs1,socket=/path/to/sock1,num_queues=4,queue_size=128" ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1", "num_queues": 4, "queue_size": 128} + {"tag": "virtiofs1", "socket": "/path/to/sock1", "num_queues": 4, "queue_size": 128} ] }"#, true, @@ -1066,13 +1066,13 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1,num_queues=4,queue_size=128,dax=on" + "tag=virtiofs1,socket=/path/to/sock1,num_queues=4,queue_size=128,dax=on" ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1", "num_queues": 4, "queue_size": 128} + {"tag": "virtiofs1", "socket": "/path/to/sock1", "num_queues": 4, "queue_size": 128} ] }"#, true, @@ -1082,13 +1082,13 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1,num_queues=4,queue_size=128,dax=on" + "tag=virtiofs1,socket=/path/to/sock1,num_queues=4,queue_size=128,dax=on" ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1", "num_queues": 4, "queue_size": 128, "dax": true} + {"tag": "virtiofs1", "socket": "/path/to/sock1", "num_queues": 4, "queue_size": 128, "dax": true} ] }"#, true, @@ -1098,13 +1098,13 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1,num_queues=4,queue_size=128" + "tag=virtiofs1,socket=/path/to/sock1,num_queues=4,queue_size=128" ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1", "num_queues": 4, "queue_size": 128, "dax": true} + {"tag": "virtiofs1", "socket": "/path/to/sock1", "num_queues": 4, "queue_size": 128, "dax": true} ] }"#, true, @@ -1114,13 +1114,13 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1,num_queues=4,queue_size=128,cache_size=8589934592" + "tag=virtiofs1,socket=/path/to/sock1,num_queues=4,queue_size=128,cache_size=8589934592" ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1", "num_queues": 4, "queue_size": 128} + {"tag": "virtiofs1", "socket": "/path/to/sock1", "num_queues": 4, "queue_size": 128} ] }"#, true, @@ -1130,13 +1130,13 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1,num_queues=4,queue_size=128" + "tag=virtiofs1,socket=/path/to/sock1,num_queues=4,queue_size=128" ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1", "num_queues": 4, "queue_size": 128, "cache_size": 8589934592} + {"tag": "virtiofs1", "socket": "/path/to/sock1", "num_queues": 4, "queue_size": 128, "cache_size": 8589934592} ] }"#, true, @@ -1146,13 +1146,13 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1,num_queues=4,queue_size=128,cache_size=4294967296" + "tag=virtiofs1,socket=/path/to/sock1,num_queues=4,queue_size=128,cache_size=4294967296" ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1", "num_queues": 4, "queue_size": 128, "cache_size": 4294967296} + {"tag": "virtiofs1", "socket": "/path/to/sock1", "num_queues": 4, "queue_size": 128, "cache_size": 4294967296} ] }"#, true, @@ -1162,13 +1162,13 @@ mod unit_tests { "cloud-hypervisor", "--kernel", "/path/to/kernel", "--memory", "shared=true", "--fs", - "tag=virtiofs1,sock=/path/to/sock1,num_queues=4,queue_size=128,cache_size=4294967296" + "tag=virtiofs1,socket=/path/to/sock1,num_queues=4,queue_size=128,cache_size=4294967296" ], r#"{ "kernel": {"path": "/path/to/kernel"}, "memory" : { "shared": true, "size": 536870912 }, "fs": [ - {"tag": "virtiofs1", "sock": "/path/to/sock1", "num_queues": 4, "queue_size": 128} + {"tag": "virtiofs1", "socket": "/path/to/sock1", "num_queues": 4, "queue_size": 128} ] }"#, false, @@ -1427,11 +1427,11 @@ mod unit_tests { "--kernel", "/path/to/kernel", "--vsock", - "cid=123,sock=/path/to/sock/1", + "cid=123,socket=/path/to/sock/1", ], r#"{ "kernel": {"path": "/path/to/kernel"}, - "vsock": {"cid": 123, "sock": "/path/to/sock/1"} + "vsock": {"cid": 123, "socket": "/path/to/sock/1"} }"#, true, ), @@ -1441,11 +1441,11 @@ mod unit_tests { "--kernel", "/path/to/kernel", "--vsock", - "cid=124,sock=/path/to/sock/1", + "cid=124,socket=/path/to/sock/1", ], r#"{ "kernel": {"path": "/path/to/kernel"}, - "vsock": {"cid": 123, "sock": "/path/to/sock/1"} + "vsock": {"cid": 123, "socket": "/path/to/sock/1"} }"#, false, ), @@ -1455,11 +1455,11 @@ mod unit_tests { "--kernel", "/path/to/kernel", "--vsock", - "cid=123,sock=/path/to/sock/1,iommu=on", + "cid=123,socket=/path/to/sock/1,iommu=on", ], r#"{ "kernel": {"path": "/path/to/kernel"}, - "vsock": {"cid": 123, "sock": "/path/to/sock/1", "iommu": true}, + "vsock": {"cid": 123, "socket": "/path/to/sock/1", "iommu": true}, "iommu": true }"#, true, @@ -1470,11 +1470,11 @@ mod unit_tests { "--kernel", "/path/to/kernel", "--vsock", - "cid=123,sock=/path/to/sock/1,iommu=on", + "cid=123,socket=/path/to/sock/1,iommu=on", ], r#"{ "kernel": {"path": "/path/to/kernel"}, - "vsock": {"cid": 123, "sock": "/path/to/sock/1", "iommu": true} + "vsock": {"cid": 123, "socket": "/path/to/sock/1", "iommu": true} }"#, false, ), @@ -1484,11 +1484,11 @@ mod unit_tests { "--kernel", "/path/to/kernel", "--vsock", - "cid=123,sock=/path/to/sock/1,iommu=off", + "cid=123,socket=/path/to/sock/1,iommu=off", ], r#"{ "kernel": {"path": "/path/to/kernel"}, - "vsock": {"cid": 123, "sock": "/path/to/sock/1", "iommu": false} + "vsock": {"cid": 123, "socket": "/path/to/sock/1", "iommu": false} }"#, true, ), diff --git a/tests/integration.rs b/tests/integration.rs index 8768471ef..ddf910009 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -370,7 +370,7 @@ mod tests { // Start the daemon let child = Command::new(clh_command("vhost_user_fs")) .args(&["--shared-dir", shared_dir]) - .args(&["--sock", virtiofsd_socket_path.as_str()]) + .args(&["--socket", virtiofsd_socket_path.as_str()]) .spawn() .unwrap(); @@ -813,7 +813,7 @@ mod tests { Ok(cache == (end_addr - start_addr + 1)) } - fn check_vsock(&self, sock: &str) { + fn check_vsock(&self, socket: &str) { // Listen from guest on vsock CID=3 PORT=16 // SOCKET-LISTEN::: let guest_ip = self.network.guest_ip.clone(); @@ -830,7 +830,7 @@ mod tests { .arg( format!( "echo -e \"CONNECT 16\\nHelloWorld!\" | socat - UNIX-CONNECT:{}", - sock + socket ) .as_str(), ) @@ -1926,7 +1926,7 @@ mod tests { .args(&["--api-socket", &api_socket]); let fs_params = format!( - "id=myfs0,tag=myfs,sock={},num_queues=1,queue_size=1024,dax={}{}", + "id=myfs0,tag=myfs,socket={},num_queues=1,queue_size=1024,dax={}{}", virtiofsd_socket_path, dax_vmm_param, cache_size_vmm_param ); @@ -2048,7 +2048,7 @@ mod tests { ); thread::sleep(std::time::Duration::new(10, 0)); let fs_params = format!( - "id=myfs0,tag=myfs,sock={},num_queues=1,queue_size=1024,dax={}{}", + "id=myfs0,tag=myfs,socket={},num_queues=1,queue_size=1024,dax={}{}", virtiofsd_socket_path, dax_vmm_param, cache_size_vmm_param ); @@ -2706,7 +2706,7 @@ mod tests { .args(&[ "--fs", format!( - "tag=myfs,sock={},num_queues=1,queue_size=1024,dax=on", + "tag=myfs,socket={},num_queues=1,queue_size=1024,dax=on", virtiofsd_socket_path, ) .as_str(), @@ -3023,7 +3023,7 @@ mod tests { let mut workload_path = dirs::home_dir().unwrap(); workload_path.push("workloads"); - let sock = temp_vsock_path(&guest.tmp_dir); + let socket = temp_vsock_path(&guest.tmp_dir); let api_socket = temp_api_path(&guest.tmp_dir); let mut cmd = GuestCommand::new(&guest); @@ -3035,7 +3035,7 @@ mod tests { cmd.default_net(); if !hotplug { - cmd.args(&["--vsock", format!("cid=3,sock={}", sock).as_str()]); + cmd.args(&["--vsock", format!("cid=3,socket={}", socket).as_str()]); } let mut child = cmd.spawn().unwrap(); @@ -3048,19 +3048,19 @@ mod tests { remote_command( &api_socket, "add-vsock", - Some(format!("cid=3,sock={},id=test0", sock).as_str()) + Some(format!("cid=3,socket={},id=test0", socket).as_str()) ) ); thread::sleep(std::time::Duration::new(10, 0)); // Check adding a second one fails aver!( tb, - !remote_command(&api_socket, "add-vsock", Some("cid=1234,sock=/tmp/fail")) + !remote_command(&api_socket, "add-vsock", Some("cid=1234,socket=/tmp/fail")) ); } // Validate vsock works as expected. - guest.check_vsock(sock.as_str()); + guest.check_vsock(socket.as_str()); let reboot_count = guest .ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"") @@ -3082,7 +3082,7 @@ mod tests { aver_eq!(tb, reboot_count, 1); // Validate vsock still works after a reboot. - guest.check_vsock(sock.as_str()); + guest.check_vsock(socket.as_str()); if hotplug { aver!( @@ -4304,7 +4304,7 @@ mod tests { ) }; - let sock = temp_vsock_path(&guest.tmp_dir); + let socket = temp_vsock_path(&guest.tmp_dir); let mut child = GuestCommand::new(&guest) .args(&["--api-socket", &api_socket]) @@ -4321,7 +4321,7 @@ mod tests { cloudinit_params.as_str(), ]) .args(&["--net", net_params.as_str()]) - .args(&["--vsock", format!("cid=3,sock={}", sock).as_str()]) + .args(&["--vsock", format!("cid=3,socket={}", socket).as_str()]) .args(&["--cmdline", CLEAR_KERNEL_CMDLINE]) .capture_output() .spawn() @@ -4354,7 +4354,7 @@ mod tests { .is_ok() ); // Check vsock - guest.check_vsock(sock.as_str()); + guest.check_vsock(socket.as_str()); // Check if the console is usable let console_text = String::from("On a branch floating down river a cricket, singing."); let console_cmd = format!("echo {} | sudo tee /dev/hvc0", console_text); @@ -4416,7 +4416,7 @@ mod tests { // Remove the vsock socket file. Command::new("rm") .arg("-f") - .arg(sock.as_str()) + .arg(socket.as_str()) .output() .unwrap(); @@ -4455,7 +4455,7 @@ mod tests { .ssh_command("head -c 1000 /dev/hwrng > /dev/null") .is_ok() ); - guest.check_vsock(sock.as_str()); + guest.check_vsock(socket.as_str()); aver!(tb, guest.ssh_command(&console_cmd).is_ok()); // Shutdown the target VM and check console output diff --git a/vm-virtio/src/vhost_user/blk.rs b/vm-virtio/src/vhost_user/blk.rs index 8d20b4a5c..a36e821a7 100644 --- a/vm-virtio/src/vhost_user/blk.rs +++ b/vm-virtio/src/vhost_user/blk.rs @@ -50,7 +50,7 @@ pub struct Blk { impl Blk { /// Create a new vhost-user-blk device pub fn new(id: String, vu_cfg: VhostUserConfig) -> Result { - let mut vhost_user_blk = Master::connect(&vu_cfg.sock, vu_cfg.num_queues as u64) + let mut vhost_user_blk = Master::connect(&vu_cfg.socket, vu_cfg.num_queues as u64) .map_err(Error::VhostUserCreateMaster)?; // Filling device and vring features VMM supports. diff --git a/vm-virtio/src/vhost_user/net.rs b/vm-virtio/src/vhost_user/net.rs index 1e5eecd0b..50cb4af4d 100644 --- a/vm-virtio/src/vhost_user/net.rs +++ b/vm-virtio/src/vhost_user/net.rs @@ -56,7 +56,7 @@ impl Net { /// Create a new vhost-user-net device /// Create a new vhost-user-net device pub fn new(id: String, mac_addr: MacAddr, vu_cfg: VhostUserConfig) -> Result { - let mut vhost_user_net = Master::connect(&vu_cfg.sock, vu_cfg.num_queues as u64) + let mut vhost_user_net = Master::connect(&vu_cfg.socket, vu_cfg.num_queues as u64) .map_err(Error::VhostUserCreateMaster)?; // Filling device and vring features VMM supports. diff --git a/vm-virtio/src/vhost_user/vu_common_ctrl.rs b/vm-virtio/src/vhost_user/vu_common_ctrl.rs index 527ac53cb..920211115 100644 --- a/vm-virtio/src/vhost_user/vu_common_ctrl.rs +++ b/vm-virtio/src/vhost_user/vu_common_ctrl.rs @@ -18,7 +18,7 @@ use vmm_sys_util::eventfd::EventFd; #[derive(Debug, Clone)] pub struct VhostUserConfig { - pub sock: String, + pub socket: String, pub num_queues: usize, pub queue_size: u16, } diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index 4aea18d24..5c5edb283 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -506,12 +506,12 @@ components: FsConfig: required: - tag - - sock + - socket type: object properties: tag: type: string - sock: + socket: type: string num_queues: type: integer @@ -581,7 +581,7 @@ components: VsockConfig: required: - cid - - sock + - socket type: object properties: cid: @@ -589,7 +589,7 @@ components: format: int64 minimum: 3 description: Guest Vsock CID - sock: + socket: type: string description: Path to UNIX domain socket, used to proxy vsock connections. iommu: diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 780d3188a..8cc5321e7 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -123,7 +123,7 @@ impl fmt::Display for Error { ParseDevice(o) => write!(f, "Error parsing --device: {}", o), ParseDevicePathMissing => write!(f, "Error parsing --device: path missing"), ParseFileSystem(o) => write!(f, "Error parsing --fs: {}", o), - ParseFsSockMissing => write!(f, "Error parsing --fs: sock missing"), + ParseFsSockMissing => write!(f, "Error parsing --fs: socket missing"), ParseFsTagMissing => write!(f, "Error parsing --fs: tag missing"), InvalidCacheSizeWithDaxOff => { write!(f, "Error parsing --fs: cache_size used with dax=on") @@ -132,7 +132,7 @@ impl fmt::Display for Error { ParsePmemFileMissing => write!(f, "Error parsing --pmem: file missing"), ParseVsock(o) => write!(f, "Error parsing --vsock: {}", o), ParseVsockCidMissing => write!(f, "Error parsing --vsock: cid missing"), - ParseVsockSockMissing => write!(f, "Error parsing --vsock: sock missing"), + ParseVsockSockMissing => write!(f, "Error parsing --vsock: socket missing"), ParseMemory(o) => write!(f, "Error parsing --memory: {}", o), ParseNetwork(o) => write!(f, "Error parsing --net: {}", o), ParseDisk(o) => write!(f, "Error parsing --disk: {}", o), @@ -857,7 +857,7 @@ impl Default for RngConfig { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct FsConfig { pub tag: String, - pub sock: PathBuf, + pub socket: PathBuf, #[serde(default = "default_fsconfig_num_queues")] pub num_queues: usize, #[serde(default = "default_fsconfig_queue_size")] @@ -890,7 +890,7 @@ impl Default for FsConfig { fn default() -> Self { Self { tag: "".to_owned(), - sock: PathBuf::new(), + socket: PathBuf::new(), num_queues: default_fsconfig_num_queues(), queue_size: default_fsconfig_queue_size(), dax: default_fsconfig_dax(), @@ -902,7 +902,7 @@ impl Default for FsConfig { impl FsConfig { pub const SYNTAX: &'static str = "virtio-fs parameters \ - \"tag=,sock=,num_queues=,\ + \"tag=,socket=,num_queues=,\ queue_size=,dax=on|off,cache_size=,id=\""; @@ -914,12 +914,12 @@ impl FsConfig { .add("cache_size") .add("queue_size") .add("num_queues") - .add("sock") + .add("socket") .add("id"); parser.parse(fs).map_err(Error::ParseFileSystem)?; let tag = parser.get("tag").ok_or(Error::ParseFsTagMissing)?; - let sock = PathBuf::from(parser.get("sock").ok_or(Error::ParseFsSockMissing)?); + let socket = PathBuf::from(parser.get("socket").ok_or(Error::ParseFsSockMissing)?); let queue_size = parser .convert("queue_size") @@ -950,7 +950,7 @@ impl FsConfig { Ok(FsConfig { tag, - sock, + socket, num_queues, queue_size, dax, @@ -1141,7 +1141,7 @@ impl DeviceConfig { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Default)] pub struct VsockConfig { pub cid: u64, - pub sock: PathBuf, + pub socket: PathBuf, #[serde(default)] pub iommu: bool, #[serde(default)] @@ -1150,14 +1150,14 @@ pub struct VsockConfig { impl VsockConfig { pub const SYNTAX: &'static str = "Virtio VSOCK parameters \ - \"cid=,sock=,iommu=on|off,id=\""; + \"cid=,socket=,iommu=on|off,id=\""; pub fn parse(vsock: &str) -> Result { let mut parser = OptionParser::new(); - parser.add("sock").add("cid").add("iommu").add("id"); + parser.add("socket").add("cid").add("iommu").add("id"); parser.parse(vsock).map_err(Error::ParseVsock)?; - let sock = parser - .get("sock") + let socket = parser + .get("socket") .map(PathBuf::from) .ok_or(Error::ParseVsockSockMissing)?; let iommu = parser @@ -1173,7 +1173,7 @@ impl VsockConfig { Ok(VsockConfig { cid, - sock, + socket, iommu, id, }) @@ -1663,12 +1663,14 @@ mod tests { ); assert_eq!( - NetConfig::parse("mac=de:ad:be:ef:12:34,host_mac=12:34:de:ad:be:ef,vhost_user=true,socket=/tmp/socket")?, + NetConfig::parse( + "mac=de:ad:be:ef:12:34,host_mac=12:34:de:ad:be:ef,vhost_user=true,socket=/tmp/sock" + )?, NetConfig { mac: MacAddr::parse_str("de:ad:be:ef:12:34").unwrap(), host_mac: MacAddr::parse_str("12:34:de:ad:be:ef").unwrap(), vhost_user: true, - vhost_socket: Some("/tmp/socket".to_owned()), + vhost_socket: Some("/tmp/sock".to_owned()), ..Default::default() } ); @@ -1720,27 +1722,27 @@ mod tests { // "tag" and "socket" must be supplied assert!(FsConfig::parse("").is_err()); assert!(FsConfig::parse("tag=mytag").is_err()); - assert!(FsConfig::parse("sock=/tmp/sock").is_err()); + assert!(FsConfig::parse("socket=/tmp/sock").is_err()); assert_eq!( - FsConfig::parse("tag=mytag,sock=/tmp/sock")?, + FsConfig::parse("tag=mytag,socket=/tmp/sock")?, FsConfig { - sock: PathBuf::from("/tmp/sock"), + socket: PathBuf::from("/tmp/sock"), tag: "mytag".to_owned(), ..Default::default() } ); assert_eq!( - FsConfig::parse("tag=mytag,sock=/tmp/sock")?, + FsConfig::parse("tag=mytag,socket=/tmp/sock")?, FsConfig { - sock: PathBuf::from("/tmp/sock"), + socket: PathBuf::from("/tmp/sock"), tag: "mytag".to_owned(), ..Default::default() } ); assert_eq!( - FsConfig::parse("tag=mytag,sock=/tmp/sock,num_queues=4,queue_size=1024")?, + FsConfig::parse("tag=mytag,socket=/tmp/sock,num_queues=4,queue_size=1024")?, FsConfig { - sock: PathBuf::from("/tmp/sock"), + socket: PathBuf::from("/tmp/sock"), tag: "mytag".to_owned(), num_queues: 4, queue_size: 1024, @@ -1749,9 +1751,9 @@ mod tests { ); // DAX on -> default cache size assert_eq!( - FsConfig::parse("tag=mytag,sock=/tmp/sock,dax=on")?, + FsConfig::parse("tag=mytag,socket=/tmp/sock,dax=on")?, FsConfig { - sock: PathBuf::from("/tmp/sock"), + socket: PathBuf::from("/tmp/sock"), tag: "mytag".to_owned(), dax: true, cache_size: default_fsconfig_cache_size(), @@ -1759,9 +1761,9 @@ mod tests { } ); assert_eq!( - FsConfig::parse("tag=mytag,sock=/tmp/sock,dax=on,cache_size=4G")?, + FsConfig::parse("tag=mytag,socket=/tmp/sock,dax=on,cache_size=4G")?, FsConfig { - sock: PathBuf::from("/tmp/sock"), + socket: PathBuf::from("/tmp/sock"), tag: "mytag".to_owned(), dax: true, cache_size: 4 << 30, @@ -1769,7 +1771,7 @@ mod tests { } ); // Cache size without DAX is an error - assert!(FsConfig::parse("tag=mytag,sock=/tmp/sock,dax=off,cache_size=4G").is_err()); + assert!(FsConfig::parse("tag=mytag,socket=/tmp/sock,dax=off,cache_size=4G").is_err()); Ok(()) } @@ -1901,22 +1903,22 @@ mod tests { #[test] fn test_vsock_parsing() -> Result<()> { - // sock and cid is required + // socket and cid is required assert!(VsockConfig::parse("").is_err()); assert_eq!( - VsockConfig::parse("sock=/tmp/sock,cid=1")?, + VsockConfig::parse("socket=/tmp/sock,cid=1")?, VsockConfig { cid: 1, - sock: PathBuf::from("/tmp/sock"), + socket: PathBuf::from("/tmp/sock"), iommu: false, id: None, } ); assert_eq!( - VsockConfig::parse("sock=/tmp/sock,cid=1,iommu=on")?, + VsockConfig::parse("socket=/tmp/sock,cid=1,iommu=on")?, VsockConfig { cid: 1, - sock: PathBuf::from("/tmp/sock"), + socket: PathBuf::from("/tmp/sock"), iommu: true, id: None, } @@ -1993,7 +1995,7 @@ mod tests { let mut invalid_config = valid_config.clone(); invalid_config.disks = Some(vec![DiskConfig { - vhost_socket: Some("/path/to/socket".to_owned()), + vhost_socket: Some("/path/to/sock".to_owned()), path: Some(PathBuf::from("/path/to/image")), ..Default::default() }]); diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 9c73b7585..c0ba9e1ca 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -135,7 +135,7 @@ pub enum DeviceManagerError { /// Cannot create virtio-fs device CreateVirtioFs(vm_virtio::vhost_user::Error), - /// Virtio-fs device was created without a sock. + /// Virtio-fs device was created without a socket. NoVirtioFsSock, /// Cannot create vhost-user-blk device @@ -1331,7 +1331,7 @@ impl DeviceManager { /// Launch block backend fn start_block_backend(&mut self, disk_cfg: &DiskConfig) -> DeviceManagerResult { let _socket_file = NamedTempFile::new().map_err(DeviceManagerError::CreateSocketFile)?; - let sock = _socket_file.path().to_str().unwrap().to_owned(); + let socket = _socket_file.path().to_str().unwrap().to_owned(); let child = std::process::Command::new(&self.vmm_path) .args(&[ @@ -1344,7 +1344,7 @@ impl DeviceManager { .ok_or(DeviceManagerError::NoDiskPath)? .to_str() .unwrap(), - &sock, + &socket, disk_cfg.num_queues, disk_cfg.queue_size ), @@ -1358,7 +1358,7 @@ impl DeviceManager { _socket_file, }); - Ok(sock) + Ok(socket) } fn make_virtio_block_device( @@ -1374,13 +1374,13 @@ impl DeviceManager { }; if disk_cfg.vhost_user { - let sock = if let Some(sock) = disk_cfg.vhost_socket.clone() { - sock + let socket = if let Some(socket) = disk_cfg.vhost_socket.clone() { + socket } else { self.start_block_backend(disk_cfg)? }; let vu_cfg = VhostUserConfig { - sock, + socket, num_queues: disk_cfg.num_queues, queue_size: disk_cfg.queue_size, }; @@ -1506,7 +1506,7 @@ impl DeviceManager { /// Launch network backend fn start_net_backend(&mut self, net_cfg: &NetConfig) -> DeviceManagerResult { let _socket_file = NamedTempFile::new().map_err(DeviceManagerError::CreateSocketFile)?; - let sock = _socket_file.path().to_str().unwrap().to_owned(); + let socket = _socket_file.path().to_str().unwrap().to_owned(); let child = std::process::Command::new(&self.vmm_path) .args(&[ @@ -1515,7 +1515,7 @@ impl DeviceManager { "ip={},mask={},socket={},num_queues={},queue_size={},host_mac={}", net_cfg.ip, net_cfg.mask, - &sock, + &socket, net_cfg.num_queues, net_cfg.queue_size, net_cfg.host_mac @@ -1530,7 +1530,7 @@ impl DeviceManager { _socket_file, }); - Ok(sock) + Ok(socket) } fn make_virtio_net_device( @@ -1546,13 +1546,13 @@ impl DeviceManager { }; if net_cfg.vhost_user { - let sock = if let Some(sock) = net_cfg.vhost_socket.clone() { - sock + let socket = if let Some(socket) = net_cfg.vhost_socket.clone() { + socket } else { self.start_net_backend(net_cfg)? }; let vu_cfg = VhostUserConfig { - sock, + socket, num_queues: net_cfg.num_queues, queue_size: net_cfg.queue_size, }; @@ -1715,7 +1715,7 @@ impl DeviceManager { None }; - if let Some(fs_sock) = fs_cfg.sock.to_str() { + if let Some(fs_socket) = fs_cfg.socket.to_str() { let cache = if fs_cfg.dax { let (cache_base, cache_size) = if let Some((base, size)) = cache_range { // The memory needs to be 2MiB aligned in order to support @@ -1792,7 +1792,7 @@ impl DeviceManager { let virtio_fs_device = Arc::new(Mutex::new( vm_virtio::vhost_user::Fs::new( id.clone(), - fs_sock, + fs_socket, &fs_cfg.tag, fs_cfg.num_queues, fs_cfg.queue_size, @@ -2028,7 +2028,7 @@ impl DeviceManager { }; let socket_path = vsock_cfg - .sock + .socket .to_str() .ok_or(DeviceManagerError::CreateVsockConvertPath)?; let backend = @@ -2039,7 +2039,7 @@ impl DeviceManager { vm_virtio::Vsock::new( id.clone(), vsock_cfg.cid, - vsock_cfg.sock.clone(), + vsock_cfg.socket.clone(), backend, vsock_cfg.iommu, )