Skip to content

Commit 4d1d994

Browse files
committed
refactor: remove files from utils that are vmm specific
In previous commit we moved `vmm` specific parts of `utils` into `vmm` crate, so now we can remove them from `utils`. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent 3c3c15b commit 4d1d994

File tree

14 files changed

+16
-598
lines changed

14 files changed

+16
-598
lines changed

src/firecracker/examples/uffd/uffd_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ mod tests {
299299
use std::mem::MaybeUninit;
300300
use std::os::unix::net::UnixListener;
301301

302-
use utils::tempdir::TempDir;
303-
use utils::tempfile::TempFile;
302+
use vmm::utils::tempdir::TempDir;
303+
use vmm::utils::tempfile::TempFile;
304304

305305
use super::*;
306306

src/firecracker/src/api_server/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use parsed_request::{ParsedRequest, RequestAction};
1717
use seccompiler::BpfProgramRef;
1818
use serde_json::json;
1919
use utils::eventfd::EventFd;
20+
use utils::time::{get_time_us, ClockType};
2021
use vmm::logger::{
2122
debug, error, info, update_metric_with_elapsed_time, warn, ProcessTimeReporter, METRICS,
2223
};
@@ -101,17 +102,15 @@ impl ApiServer {
101102
}
102103
};
103104
for server_request in request_vec {
104-
let request_processing_start_us =
105-
utils::time::get_time_us(utils::time::ClockType::Monotonic);
105+
let request_processing_start_us = get_time_us(ClockType::Monotonic);
106106
// Use `self.handle_request()` as the processing callback.
107107
let response = server_request
108108
.process(|request| self.handle_request(request, request_processing_start_us));
109109
if let Err(err) = server.respond(response) {
110110
error!("API Server encountered an error on response: {}", err);
111111
};
112112

113-
let delta_us = utils::time::get_time_us(utils::time::ClockType::Monotonic)
114-
- request_processing_start_us;
113+
let delta_us = get_time_us(ClockType::Monotonic) - request_processing_start_us;
115114
debug!("Total previous API call duration: {} us.", delta_us);
116115
}
117116
}
@@ -259,7 +258,7 @@ mod tests {
259258
// latencies_us.pause_vm metric can be set to 0, failing the assertion below. By
260259
// subtracting 1 we assure that the metric will always be set to at least 1 (if it gets set
261260
// at all, which is what this test is trying to prove).
262-
let start_time_us = utils::time::get_time_us(ClockType::Monotonic) - 1;
261+
let start_time_us = get_time_us(ClockType::Monotonic) - 1;
263262
assert_eq!(METRICS.latencies_us.pause_vm.fetch(), 0);
264263
to_api.send(Box::new(Ok(VmmData::Empty))).unwrap();
265264
let response =

src/jailer/src/env.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::{fmt, io};
1313

1414
use utils::arg_parser::UtilsArgParserError::MissingValue;
1515
use utils::syscall::SyscallReturnCode;
16+
use utils::time::{get_time_us, ClockType};
1617
use utils::{arg_parser, validators};
1718

1819
use crate::cgroup::{CgroupConfiguration, CgroupConfigurationBuilder};
@@ -663,7 +664,7 @@ impl Env {
663664
// Daemonize before exec, if so required (when the dev_null variable != None).
664665
if let Some(dev_null) = dev_null {
665666
// Meter CPU usage before fork()
666-
self.jailer_cpu_time_us = utils::time::get_time_us(utils::time::ClockType::ProcessCpu);
667+
self.jailer_cpu_time_us = get_time_us(ClockType::ProcessCpu);
667668

668669
// We follow the double fork method to daemonize the jailer referring to
669670
// https://0xjet.github.io/3OHA/2022/04/11/post.html
@@ -688,7 +689,7 @@ impl Env {
688689
.map_err(JailerError::SetSid)?;
689690

690691
// Meter CPU usage before fork()
691-
self.jailer_cpu_time_us += utils::time::get_time_us(utils::time::ClockType::ProcessCpu);
692+
self.jailer_cpu_time_us += get_time_us(ClockType::ProcessCpu);
692693

693694
// Daemons should not have controlling terminals.
694695
// If a daemon has a controlling terminal, it can receive signals
@@ -714,8 +715,7 @@ impl Env {
714715
}
715716

716717
// Compute jailer's total CPU time up to the current time.
717-
self.jailer_cpu_time_us +=
718-
utils::time::get_time_us(utils::time::ClockType::ProcessCpu) - self.start_time_cpu_us;
718+
self.jailer_cpu_time_us += get_time_us(ClockType::ProcessCpu) - self.start_time_cpu_us;
719719
// Reset process start time.
720720
self.start_time_cpu_us = 0;
721721

src/jailer/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::{env as p_env, fs, io};
99
use env::PROC_MOUNTS;
1010
use utils::arg_parser::{ArgParser, Argument, UtilsArgParserError as ParsingError};
1111
use utils::syscall::SyscallReturnCode;
12+
use utils::time::{get_time_us, ClockType};
1213
use utils::validators;
1314

1415
use crate::env::Env;
@@ -334,8 +335,8 @@ fn main_exec() -> Result<(), JailerError> {
334335

335336
Env::new(
336337
arguments,
337-
utils::time::get_time_us(utils::time::ClockType::Monotonic),
338-
utils::time::get_time_us(utils::time::ClockType::ProcessCpu),
338+
get_time_us(ClockType::Monotonic),
339+
get_time_us(ClockType::ProcessCpu),
339340
PROC_MOUNTS,
340341
)
341342
.and_then(|env| {

src/rebase-snap/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::os::unix::io::AsRawFd;
88

99
use utils::arg_parser::{ArgParser, Argument, Arguments, UtilsArgParserError as ArgError};
1010
use utils::seek_hole::SeekHole;
11-
use utils::u64_to_usize;
1211

1312
const REBASE_SNAP_VERSION: &str = env!("CARGO_PKG_VERSION");
1413
const BASE_FILE: &str = "base-file";
@@ -104,7 +103,7 @@ fn rebase(base_file: &mut File, diff_file: &mut File) -> Result<(), FileError> {
104103
base_file.as_raw_fd(),
105104
diff_file.as_raw_fd(),
106105
(&mut cursor as *mut u64).cast::<i64>(),
107-
u64_to_usize(block_end.saturating_sub(cursor)),
106+
usize::try_from(block_end.saturating_sub(cursor)).unwrap(),
108107
)
109108
};
110109
if num_transferred_bytes < 0 {

src/snapshot-editor/src/edit_memory.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::path::PathBuf;
88

99
use clap::Subcommand;
1010
use fc_utils::seek_hole::SeekHole;
11-
use fc_utils::u64_to_usize;
11+
use vmm::utils::u64_to_usize;
1212

1313
#[derive(Debug, thiserror::Error, displaydoc::Display)]
1414
pub enum EditMemoryError {

src/snapshot-editor/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
use std::fs::{File, OpenOptions};
55
use std::path::PathBuf;
66

7-
use fc_utils::u64_to_usize;
87
use semver::Version;
98
use vmm::persist::MicrovmState;
109
use vmm::snapshot::Snapshot;
10+
use vmm::utils::u64_to_usize;
1111

1212
// Some errors are only used in aarch64 code
1313
#[allow(unused)]

src/utils/src/byte_order.rs

Lines changed: 0 additions & 117 deletions
This file was deleted.

src/utils/src/lib.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,5 @@ pub use vmm_sys_util::{
1212
};
1313

1414
pub mod arg_parser;
15-
pub mod byte_order;
16-
pub mod net;
17-
pub mod signal;
18-
pub mod sm;
1915
pub mod time;
2016
pub mod validators;
21-
22-
use std::num::Wrapping;
23-
use std::result::Result;
24-
25-
/// Return the default page size of the platform, in bytes.
26-
pub fn get_page_size() -> Result<usize, errno::Error> {
27-
// SAFETY: Safe because the parameters are valid.
28-
match unsafe { libc::sysconf(libc::_SC_PAGESIZE) } {
29-
-1 => Err(errno::Error::last()),
30-
ps => Ok(usize::try_from(ps).unwrap()),
31-
}
32-
}
33-
34-
/// Safely converts a u64 value to a usize value.
35-
/// This bypasses the Clippy lint check because we only support 64-bit platforms.
36-
#[cfg(target_pointer_width = "64")]
37-
#[inline]
38-
#[allow(clippy::cast_possible_truncation)]
39-
pub const fn u64_to_usize(num: u64) -> usize {
40-
num as usize
41-
}
42-
43-
/// Safely converts a usize value to a u64 value.
44-
/// This bypasses the Clippy lint check because we only support 64-bit platforms.
45-
#[cfg(target_pointer_width = "64")]
46-
#[inline]
47-
#[allow(clippy::cast_possible_truncation)]
48-
pub const fn usize_to_u64(num: usize) -> u64 {
49-
num as u64
50-
}
51-
52-
/// Converts a usize into a wrapping u32.
53-
#[inline]
54-
pub const fn wrap_usize_to_u32(num: usize) -> Wrapping<u32> {
55-
Wrapping(((num as u64) & 0xFFFFFFFF) as u32)
56-
}

src/utils/src/net/ipv4addr.rs

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)