From 5c96a920bda5b9012c5e051fd515b96ff1d2e377 Mon Sep 17 00:00:00 2001 From: Erich Cordoba Date: Thu, 31 Oct 2019 12:21:27 -0600 Subject: [PATCH] agent: Remove `get_key_value` to enable building in stable rust. The get_key_value method is currently only avaiable in nightly rust. As only this feature is required it worth to refactor and enable building in the stable channel. The method was removed by first getting the value from the CGROUPS hashmap, then key is get by iterating over all the keys. The checks for an empty key and key == "devices" were moved out of the hashmap block. The README.md was updated as well to detail the instructions for stable rust. Signed-off-by: Erich Cordoba --- .travis.yml | 2 +- src/agent/README.md | 4 +--- src/agent/src/mount.rs | 30 ++++++++++++++---------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index b7a10d0ad8..6b8992f95e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ os: language: rust rust: - - nightly + - stable env: - target_branch=$TRAVIS_BRANCH RUST_AGENT=yes diff --git a/src/agent/README.md b/src/agent/README.md index bb4b49790b..0e4c716e43 100644 --- a/src/agent/README.md +++ b/src/agent/README.md @@ -45,9 +45,7 @@ The `rust-agent` depends on [`grpc-rs`](https://github.com/pingcap/grpc-rs) by P ### Build from Source The rust-agent need to be built with rust nightly, and static linked with musl. ```bash -rustup toolchain install nightly -rustup default nightly -rustup target add x86_64-unknown-linux-musl --toolchain=nightly +rustup target add x86_64-unknown-linux-musl git submodule update --init --recursive sudo ln -s /usr/bin/g++ /bin/musl-g++ cargo build --target x86_64-unknown-linux-musl --release diff --git a/src/agent/src/mount.rs b/src/agent/src/mount.rs index b3e594045c..af91e6ec71 100644 --- a/src/agent/src/mount.rs +++ b/src/agent/src/mount.rs @@ -588,24 +588,22 @@ pub fn get_cgroup_mounts(logger: &Logger, cg_path: &str) -> Result { - if *key == "" { - continue; - } + if fields[0] == "" { + continue; + } - if *key == "devices" { - has_device_cgroup = true; - } + if fields[0] == "devices" { + has_device_cgroup = true; + } - cg_mounts.push(INIT_MOUNT { - fstype: "cgroup", - src: "cgroup", - dest: *value, - options: vec!["nosuid", "nodev", "noexec", "relatime", *key], - }); - } - None => continue, + if let Some(value) = CGROUPS.get(&fields[0]) { + let key = CGROUPS.keys().find(|&&f| f == fields[0]).unwrap(); + cg_mounts.push(INIT_MOUNT { + fstype: "cgroup", + src: "cgroup", + dest: *value, + options: vec!["nosuid", "nodev", "noexec", "relatime", key] + }); } }