agent: clean up clippy warnings about '`static'

warning: Constants have by default a `'static` lifetime
  --> src/grpc.rs:59:24
   |
59 | const CONTAINER_BASE: &'static str = "/run/kata-containers";
   |                       -^^^^^^^---- help: consider removing `'static`: `&str`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
This commit is contained in:
Liu Jiang
2019-11-30 18:54:23 +08:00
parent eb6258b751
commit 8868eaeb4c
10 changed files with 59 additions and 65 deletions

View File

@@ -6,17 +6,17 @@ use rustjail::errors::*;
use std::fs;
use std::time;
const DEBUG_CONSOLE_FLAG: &'static str = "agent.debug_console";
const DEV_MODE_FLAG: &'static str = "agent.devmode";
const LOG_LEVEL_OPTION: &'static str = "agent.log";
const HOTPLUG_TIMOUT_OPTION: &'static str = "agent.hotplug_timeout";
const DEBUG_CONSOLE_FLAG: &str = "agent.debug_console";
const DEV_MODE_FLAG: &str = "agent.devmode";
const LOG_LEVEL_OPTION: &str = "agent.log";
const HOTPLUG_TIMOUT_OPTION: &str = "agent.hotplug_timeout";
const DEFAULT_LOG_LEVEL: slog::Level = slog::Level::Info;
const DEFAULT_HOTPLUG_TIMEOUT: time::Duration = time::Duration::from_secs(3);
// FIXME: unused
const TRACE_MODE_FLAG: &'static str = "agent.trace";
const USE_VSOCK_FLAG: &'static str = "agent.use_vsock";
const TRACE_MODE_FLAG: &str = "agent.trace";
const USE_VSOCK_FLAG: &str = "agent.use_vsock";
#[derive(Debug)]
pub struct agentConfig {
@@ -100,17 +100,11 @@ fn get_log_level(param: &str) -> Result<slog::Level> {
return Err(ErrorKind::ErrorCode(String::from("invalid log level parameter")).into());
}
let key = fields[0];
if key != LOG_LEVEL_OPTION {
return Err(ErrorKind::ErrorCode(String::from("invalid log level key name").into()).into());
if fields[0] != LOG_LEVEL_OPTION {
Err(ErrorKind::ErrorCode(String::from("invalid log level key name")).into())
} else {
Ok(logrus_to_slog_level(fields[1])?)
}
let value = fields[1];
let level = logrus_to_slog_level(value)?;
Ok(level)
}
fn get_hotplug_timeout(param: &str) -> Result<time::Duration> {

View File

@@ -32,27 +32,27 @@ macro_rules! sl {
target_arch = "powerpc64le",
target_arch = "s390x"
))]
pub const ROOT_BUS_PATH: &'static str = "/devices/pci0000:00";
pub const ROOT_BUS_PATH: &str = "/devices/pci0000:00";
#[cfg(target_arch = "arm")]
pub const ROOT_BUS_PATH: &'static str = "/devices/platform/4010000000.pcie/pci0000:00";
pub const ROOT_BUS_PATH: &str = "/devices/platform/4010000000.pcie/pci0000:00";
pub const SYSFS_DIR: &'static str = "/sys";
pub const SYSFS_DIR: &str = "/sys";
const SYS_BUS_PREFIX: &'static str = "/sys/bus/pci/devices";
const PCI_BUS_RESCAN_FILE: &'static str = "/sys/bus/pci/rescan";
const SYSTEM_DEV_PATH: &'static str = "/dev";
const SYS_BUS_PREFIX: &str = "/sys/bus/pci/devices";
const PCI_BUS_RESCAN_FILE: &str = "/sys/bus/pci/rescan";
const SYSTEM_DEV_PATH: &str = "/dev";
// SCSI const
// Here in "0:0", the first number is the SCSI host number because
// only one SCSI controller has been plugged, while the second number
// is always 0.
pub const SCSI_HOST_CHANNEL: &'static str = "0:0:";
const SYS_CLASS_PREFIX: &'static str = "/sys/class";
const SCSI_DISK_PREFIX: &'static str = "/sys/class/scsi_disk/0:0:";
pub const SCSI_BLOCK_SUFFIX: &'static str = "block";
const SCSI_DISK_SUFFIX: &'static str = "/device/block";
const SCSI_HOST_PATH: &'static str = "/sys/class/scsi_host";
pub const SCSI_HOST_CHANNEL: &str = "0:0:";
const SYS_CLASS_PREFIX: &str = "/sys/class";
const SCSI_DISK_PREFIX: &str = "/sys/class/scsi_disk/0:0:";
pub const SCSI_BLOCK_SUFFIX: &str = "block";
const SCSI_DISK_SUFFIX: &str = "/device/block";
const SCSI_HOST_PATH: &str = "/sys/class/scsi_host";
// DeviceHandler is the type of callback to be defined to handle every
// type of device driver.

View File

@@ -53,10 +53,10 @@ use std::io::{BufRead, BufReader};
use std::os::unix::fs::FileExt;
use std::path::PathBuf;
const SYSFS_MEMORY_BLOCK_SIZE_PATH: &'static str = "/sys/devices/system/memory/block_size_bytes";
const SYSFS_MEMORY_HOTPLUG_PROBE_PATH: &'static str = "/sys/devices/system/memory/probe";
pub const SYSFS_MEMORY_ONLINE_PATH: &'static str = "/sys/devices/system/memory";
const CONTAINER_BASE: &'static str = "/run/kata-containers";
const SYSFS_MEMORY_BLOCK_SIZE_PATH: &str = "/sys/devices/system/memory/block_size_bytes";
const SYSFS_MEMORY_HOTPLUG_PROBE_PATH: &str = "/sys/devices/system/memory/probe";
pub const SYSFS_MEMORY_ONLINE_PATH: &str = "/sys/devices/system/memory";
const CONTAINER_BASE: &str = "/run/kata-containers";
// Convenience macro to obtain the scope logger
macro_rules! sl {

View File

@@ -63,11 +63,11 @@ use uevent::watch_uevents;
mod grpc;
const NAME: &'static str = "kata-agent";
const VSOCK_ADDR: &'static str = "vsock://-1";
const NAME: &str = "kata-agent";
const VSOCK_ADDR: &str = "vsock://-1";
const VSOCK_PORT: u16 = 1024;
const KERNEL_CMDLINE_FILE: &'static str = "/proc/cmdline";
const CONSOLE_PATH: &'static str = "/dev/console";
const KERNEL_CMDLINE_FILE: &str = "/proc/cmdline";
const CONSOLE_PATH: &str = "/dev/console";
lazy_static! {
static ref GLOBAL_DEVICE_WATCHER: Arc<Mutex<HashMap<String, Sender<String>>>> =

View File

@@ -27,23 +27,23 @@ use crate::protocols::agent::Storage;
use crate::Sandbox;
use slog::Logger;
const DRIVER9PTYPE: &'static str = "9p";
const DRIVERVIRTIOFSTYPE: &'static str = "virtio-fs";
pub const DRIVERBLKTYPE: &'static str = "blk";
pub const DRIVERMMIOBLKTYPE: &'static str = "mmioblk";
pub const DRIVERSCSITYPE: &'static str = "scsi";
pub const DRIVERNVDIMMTYPE: &'static str = "nvdimm";
const DRIVEREPHEMERALTYPE: &'static str = "ephemeral";
const DRIVERLOCALTYPE: &'static str = "local";
const DRIVER9PTYPE: &str = "9p";
const DRIVERVIRTIOFSTYPE: &str = "virtio-fs";
pub const DRIVERBLKTYPE: &str = "blk";
pub const DRIVERMMIOBLKTYPE: &str = "mmioblk";
pub const DRIVERSCSITYPE: &str = "scsi";
pub const DRIVERNVDIMMTYPE: &str = "nvdimm";
const DRIVEREPHEMERALTYPE: &str = "ephemeral";
const DRIVERLOCALTYPE: &str = "local";
pub const TYPEROOTFS: &'static str = "rootfs";
pub const TYPEROOTFS: &str = "rootfs";
pub const PROCMOUNTSTATS: &'static str = "/proc/self/mountstats";
pub const PROCMOUNTSTATS: &str = "/proc/self/mountstats";
const ROOTBUSPATH: &'static str = "/devices/pci0000:00";
const ROOTBUSPATH: &str = "/devices/pci0000:00";
const CGROUPPATH: &'static str = "/sys/fs/cgroup";
const PROCCGROUPS: &'static str = "/proc/cgroups";
const CGROUPPATH: &str = "/sys/fs/cgroup";
const PROCCGROUPS: &str = "/proc/cgroups";
#[cfg_attr(rustfmt, rustfmt_skip)]
lazy_static! {

View File

@@ -17,10 +17,10 @@ use crate::mount::{BareMount, FLAGS};
use slog::Logger;
//use container::Process;
const PERSISTENT_NS_DIR: &'static str = "/var/run/sandbox-ns";
pub const NSTYPEIPC: &'static str = "ipc";
pub const NSTYPEUTS: &'static str = "uts";
pub const NSTYPEPID: &'static str = "pid";
const PERSISTENT_NS_DIR: &str = "/var/run/sandbox-ns";
pub const NSTYPEIPC: &str = "ipc";
pub const NSTYPEUTS: &str = "uts";
pub const NSTYPEPID: &str = "pid";
pub fn get_current_thread_ns_path(ns_type: &str) -> String {
format!(

View File

@@ -10,7 +10,7 @@ use nix::sys::stat::Mode;
use rustjail::errors::*;
use std::fs;
pub const RNGDEV: &'static str = "/dev/random";
pub const RNGDEV: &str = "/dev/random";
pub const RNDADDTOENTCNT: libc::c_int = 0x40045201;
pub const RNDRESEEDRNG: libc::c_int = 0x5207;

View File

@@ -221,9 +221,9 @@ impl Sandbox {
}
}
pub const CPU_ONLINE_PATH: &'static str = "/sys/devices/system/cpu";
pub const MEMORY_ONLINE_PATH: &'static str = "/sys/devices/system/memory";
pub const ONLINE_FILE: &'static str = "online";
pub const CPU_ONLINE_PATH: &str = "/sys/devices/system/cpu";
pub const MEMORY_ONLINE_PATH: &str = "/sys/devices/system/memory";
pub const ONLINE_FILE: &str = "online";
fn online_resources(logger: &Logger, path: &str, pattern: &str, num: i32) -> Result<i32> {
let mut count = 0;

View File

@@ -11,12 +11,12 @@ use crate::GLOBAL_DEVICE_WATCHER;
use std::sync::{Arc, Mutex};
use std::thread;
pub const U_EVENT_ACTION: &'static str = "ACTION";
pub const U_EVENT_DEV_PATH: &'static str = "DEVPATH";
pub const U_EVENT_SUB_SYSTEM: &'static str = "SUBSYSTEM";
pub const U_EVENT_SEQ_NUM: &'static str = "SEQNUM";
pub const U_EVENT_DEV_NAME: &'static str = "DEVNAME";
pub const U_EVENT_INTERFACE: &'static str = "INTERFACE";
pub const U_EVENT_ACTION: &str = "ACTION";
pub const U_EVENT_DEV_PATH: &str = "DEVPATH";
pub const U_EVENT_SUB_SYSTEM: &str = "SUBSYSTEM";
pub const U_EVENT_SEQ_NUM: &str = "SEQNUM";
pub const U_EVENT_DEV_NAME: &str = "DEVNAME";
pub const U_EVENT_INTERFACE: &str = "INTERFACE";
#[derive(Debug, Default)]
pub struct Uevent {

View File

@@ -3,5 +3,5 @@
// SPDX-License-Identifier: Apache-2.0
//
pub const AGENT_VERSION: &'static str = "1.4.5";
pub const API_VERSION: &'static str = "0.0.1";
pub const AGENT_VERSION: &str = "1.4.5";
pub const API_VERSION: &str = "0.0.1";