From 38fd0f8001cceea88b879e52213f3f1a1033098f Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Mon, 21 Jun 2021 14:21:49 -0700 Subject: Upgrade rust/crates/vsock to 0.2.4 Test: make Change-Id: I2b8243e2b6b10866c9778ff4d1d3050faee2f62a --- .cargo_vcs_info.json | 2 +- Android.bp | 3 ++- Cargo.toml | 2 +- Cargo.toml.orig | 2 +- METADATA | 8 ++++---- src/lib.rs | 3 ++- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index c3a6da8..4fc9144 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "c24bde75d75afb29563cc465f4c3e2cedfea69b9" + "sha1": "56852d4006efce337875594e6a21ec49f0fc9c89" } } diff --git a/Android.bp b/Android.bp index 36b9fb8..5e4e836 100644 --- a/Android.bp +++ b/Android.bp @@ -1,4 +1,5 @@ // This file is generated by cargo2android.py --run --device --dependencies. +// Do not modify this file as changes will be overridden on upgrade. package { default_applicable_licenses: ["external_rust_crates_vsock_license"], @@ -32,5 +33,5 @@ rust_library { // dependent_library ["feature_list"] // bitflags-1.2.1 "default" // cfg-if-1.0.0 -// libc-0.2.86 "default,extra_traits,std" +// libc-0.2.97 "default,extra_traits,std" // nix-0.19.1 diff --git a/Cargo.toml b/Cargo.toml index c4b49fa..be4c916 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ [package] edition = "2018" name = "vsock" -version = "0.2.3" +version = "0.2.4" authors = ["fsyncd", "rust-vsock"] exclude = ["test_fixture"] description = "Virtio socket support for Rust" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index afe8103..aa90128 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "vsock" -version = "0.2.3" +version = "0.2.4" authors = ["fsyncd", "rust-vsock"] description = "Virtio socket support for Rust" repository = "https://github.com/rust-vsock/vsock-rs" diff --git a/METADATA b/METADATA index 1f3b1c3..1bb714c 100644 --- a/METADATA +++ b/METADATA @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/vsock/vsock-0.2.3.crate" + value: "https://static.crates.io/crates/vsock/vsock-0.2.4.crate" } - version: "0.2.3" + version: "0.2.4" license_type: NOTICE last_upgrade_date { year: 2021 - month: 2 - day: 9 + month: 6 + day: 21 } } diff --git a/src/lib.rs b/src/lib.rs index 82d5092..065ca57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -134,10 +134,11 @@ impl VsockListener { }; let mut vsock_addr_len = size_of::() as socklen_t; let socket = unsafe { - accept( + accept4( self.socket, &mut vsock_addr as *mut _ as *mut sockaddr, &mut vsock_addr_len, + SOCK_CLOEXEC, ) }; if socket < 0 { -- cgit v1.2.3 From d8fb876292662691f2c8b990c7b3e079177de98b Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Fri, 9 Jul 2021 18:26:50 +0900 Subject: Make libvsock available to the virt APEX The library is used by virtualizationservice Bug: 192904048 Test: m com.android.virt Change-Id: Ifadc3319d1c8ce736b406faca3ba7d5491684b4d --- Android.bp | 8 ++++++-- cargo2android.json | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 cargo2android.json diff --git a/Android.bp b/Android.bp index 5e4e836..3022ab7 100644 --- a/Android.bp +++ b/Android.bp @@ -1,4 +1,4 @@ -// This file is generated by cargo2android.py --run --device --dependencies. +// This file is generated by cargo2android.py --config cargo2android.json. // Do not modify this file as changes will be overridden on upgrade. package { @@ -28,10 +28,14 @@ rust_library { "liblibc", "libnix", ], + apex_available: [ + "//apex_available:platform", + "com.android.virt", + ], } // dependent_library ["feature_list"] // bitflags-1.2.1 "default" // cfg-if-1.0.0 -// libc-0.2.97 "default,extra_traits,std" +// libc-0.2.98 "default,extra_traits,std" // nix-0.19.1 diff --git a/cargo2android.json b/cargo2android.json new file mode 100644 index 0000000..5c18d15 --- /dev/null +++ b/cargo2android.json @@ -0,0 +1,9 @@ +{ + "apex-available": [ + "//apex_available:platform", + "com.android.virt" + ], + "dependencies": true, + "device": true, + "run": true +} -- cgit v1.2.3 From 86e6d34be1164cac543f3aa7dbe73aefa1d589b9 Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Mon, 30 Aug 2021 10:58:10 -0700 Subject: Update TEST_MAPPING Test: None Change-Id: Ie0c964d8c3590c2739dffa009944493c74f1b668 --- TEST_MAPPING | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 TEST_MAPPING diff --git a/TEST_MAPPING b/TEST_MAPPING new file mode 100644 index 0000000..ab8f416 --- /dev/null +++ b/TEST_MAPPING @@ -0,0 +1,11 @@ +// Generated by update_crate_tests.py for tests that depend on this crate. +{ + "presubmit": [ + { + "name": "microdroid_manager_test" + }, + { + "name": "virtualizationservice_device_test" + } + ] +} -- cgit v1.2.3 From 0904891fa35be20a14de565818561ec76efd3390 Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Thu, 28 Oct 2021 13:53:53 -0700 Subject: Remove deprecated file. This file only talks about a patch that no longer exists. Test: None Change-Id: I384d71fb4ff25cc194c5fb16deccda5df98db9af --- README.android | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 README.android diff --git a/README.android b/README.android deleted file mode 100644 index 2ca244b..0000000 --- a/README.android +++ /dev/null @@ -1,3 +0,0 @@ -local_modifications: - "Cherry-picked https://github.com/qwandor/vsock-rs/commit/4f73c26fc9a95e36e3ac4d304a02b6a424d7bcfd to fix Android build. This should be included in the next upstream release." - See patches/src.lib.diff -- cgit v1.2.3 From 91d7d38ec70f124aff6f14f70df26d43ca91a9fe Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Mon, 29 Nov 2021 14:05:54 -0800 Subject: Refresh Android.bp, cargo2android.json, TEST_MAPPING. Test: None Change-Id: I402a45aecb45789cb899a28b612af97c1ab3103f --- Android.bp | 8 ++------ TEST_MAPPING | 8 ++++++++ cargo2android.json | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Android.bp b/Android.bp index 3022ab7..b2544e0 100644 --- a/Android.bp +++ b/Android.bp @@ -22,6 +22,8 @@ rust_library { name: "libvsock", host_supported: true, crate_name: "vsock", + cargo_env_compat: true, + cargo_pkg_version: "0.2.4", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ @@ -33,9 +35,3 @@ rust_library { "com.android.virt", ], } - -// dependent_library ["feature_list"] -// bitflags-1.2.1 "default" -// cfg-if-1.0.0 -// libc-0.2.98 "default,extra_traits,std" -// nix-0.19.1 diff --git a/TEST_MAPPING b/TEST_MAPPING index ab8f416..b7c1df9 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -7,5 +7,13 @@ { "name": "virtualizationservice_device_test" } + ], + "presubmit-rust": [ + { + "name": "microdroid_manager_test" + }, + { + "name": "virtualizationservice_device_test" + } ] } diff --git a/cargo2android.json b/cargo2android.json index 5c18d15..42b7833 100644 --- a/cargo2android.json +++ b/cargo2android.json @@ -6,4 +6,4 @@ "dependencies": true, "device": true, "run": true -} +} \ No newline at end of file -- cgit v1.2.3 From bc5a1c46a74c871b18a2ffb9bebe04338fc628e2 Mon Sep 17 00:00:00 2001 From: David LeGare Date: Wed, 2 Mar 2022 16:21:06 +0000 Subject: Update vsock to 0.2.6 Test: cd external/rust/crates && atest --host -c Change-Id: I7c177a85cfef2cac0a82b939719b69adbc3c053c --- .cargo_vcs_info.json | 2 +- Android.bp | 2 +- Cargo.toml | 13 ++++++------- Cargo.toml.orig | 4 ++-- METADATA | 10 +++++----- src/lib.rs | 29 +++++++++++++++++++++++++---- tests/vsock.rs | 7 ++++++- 7 files changed, 46 insertions(+), 21 deletions(-) diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 4fc9144..3d9568d 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "56852d4006efce337875594e6a21ec49f0fc9c89" + "sha1": "9b5e180bf04fd1d02db0c1e79c5ddd838dd42328" } } diff --git a/Android.bp b/Android.bp index b2544e0..17b9a91 100644 --- a/Android.bp +++ b/Android.bp @@ -23,7 +23,7 @@ rust_library { host_supported: true, crate_name: "vsock", cargo_env_compat: true, - cargo_pkg_version: "0.2.4", + cargo_pkg_version: "0.2.6", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ diff --git a/Cargo.toml b/Cargo.toml index be4c916..0002416 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,17 +3,16 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "vsock" -version = "0.2.4" +version = "0.2.6" authors = ["fsyncd", "rust-vsock"] exclude = ["test_fixture"] description = "Virtio socket support for Rust" @@ -25,7 +24,7 @@ repository = "https://github.com/rust-vsock/vsock-rs" version = "0.2.79" [dependencies.nix] -version = "0.19.1" +version = "0.23.0" [dev-dependencies.rand] version = "0.8.3" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index aa90128..7a6d39a 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "vsock" -version = "0.2.4" +version = "0.2.6" authors = ["fsyncd", "rust-vsock"] description = "Virtio socket support for Rust" repository = "https://github.com/rust-vsock/vsock-rs" @@ -12,7 +12,7 @@ exclude = ["test_fixture"] [dependencies] libc = "0.2.79" -nix = "0.19.1" +nix = "0.23.0" [dev-dependencies] rand = "0.8.3" diff --git a/METADATA b/METADATA index 1bb714c..768fa97 100644 --- a/METADATA +++ b/METADATA @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/vsock/vsock-0.2.4.crate" + value: "https://static.crates.io/crates/vsock/vsock-0.2.6.crate" } - version: "0.2.4" + version: "0.2.6" license_type: NOTICE last_upgrade_date { - year: 2021 - month: 6 - day: 21 + year: 2022 + month: 3 + day: 1 } } diff --git a/src/lib.rs b/src/lib.rs index 065ca57..aaeb393 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,15 +17,17 @@ //! Virtio socket support for Rust. -use std::io::{Error, ErrorKind, Read, Result, Write}; -use std::mem::{self, size_of}; -use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; - use libc::*; +use nix::ioctl_read_bad; use std::ffi::c_void; +use std::fs::File; +use std::io::{Error, ErrorKind, Read, Result, Write}; +use std::mem::{self, size_of}; use std::net::Shutdown; +use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd}; use std::time::Duration; +pub use libc::{VMADDR_CID_ANY, VMADDR_CID_HOST, VMADDR_CID_HYPERVISOR, VMADDR_CID_LOCAL}; pub use nix::sys::socket::{SockAddr, VsockAddr}; fn new_socket() -> libc::c_int { @@ -505,3 +507,22 @@ impl Drop for VsockStream { unsafe { close(self.socket) }; } } + +const IOCTL_VM_SOCKETS_GET_LOCAL_CID: usize = 0x7b9; +ioctl_read_bad!( + vm_sockets_get_local_cid, + IOCTL_VM_SOCKETS_GET_LOCAL_CID, + u32 +); + +/// Gets the CID of the local machine. +/// +/// Note that when calling [`VsockListener::bind`], you should generally use [`VMADDR_CID_ANY`] +/// instead, and for making a loopback connection you should use [`VMADDR_CID_LOCAL`]. +pub fn get_local_cid() -> Result { + let f = File::open("/dev/vsock")?; + let mut cid = 0; + // SAFETY: the kernel only modifies the given u32 integer. + unsafe { vm_sockets_get_local_cid(f.as_raw_fd(), &mut cid) }?; + Ok(cid) +} diff --git a/tests/vsock.rs b/tests/vsock.rs index d51bad0..52d908b 100644 --- a/tests/vsock.rs +++ b/tests/vsock.rs @@ -17,7 +17,7 @@ use rand::RngCore; use sha2::{Digest, Sha256}; use std::io::{Read, Write}; -use vsock::{SockAddr, VsockAddr, VsockStream}; +use vsock::{get_local_cid, SockAddr, VsockAddr, VsockStream, VMADDR_CID_HOST}; const TEST_BLOB_SIZE: usize = 1_000_000; const TEST_BLOCK_SIZE: usize = 5_000; @@ -67,3 +67,8 @@ fn test_vsock() { assert_eq!(expected, actual); } + +#[test] +fn test_get_local_cid() { + assert_eq!(get_local_cid().unwrap(), VMADDR_CID_HOST); +} -- cgit v1.2.3