902 lines
27 KiB
Diff
902 lines
27 KiB
Diff
From abdafc1728b233b93c42b76034e19286e3fcbda7 Mon Sep 17 00:00:00 2001
|
|
From: renoseven <dev@renoseven.net>
|
|
Date: Tue, 21 May 2024 15:01:48 +0800
|
|
Subject: [PATCH] all: remove redundant code
|
|
|
|
Signed-off-by: renoseven <dev@renoseven.net>
|
|
---
|
|
syscare-build/src/build_root/mod.rs | 20 +-
|
|
syscare-build/src/build_root/package_root.rs | 6 -
|
|
syscare-build/src/build_root/patch_root.rs | 6 -
|
|
syscare-build/src/package/dependency.rs | 10 -
|
|
syscare-build/src/package/mod.rs | 1 -
|
|
syscare-build/src/package/rpm/mod.rs | 4 -
|
|
syscare-common/src/os/disk.rs | 64 ----
|
|
syscare-common/src/os/grub.rs | 312 ------------------
|
|
syscare-common/src/os/kernel.rs | 43 +--
|
|
syscare-common/src/os/mod.rs | 2 -
|
|
syscare-common/src/util/digest.rs | 7 -
|
|
syscared/src/fast_reboot/manager.rs | 123 -------
|
|
syscared/src/fast_reboot/mod.rs | 17 -
|
|
syscared/src/main.rs | 7 +-
|
|
syscared/src/rpc/skeleton/fast_reboot.rs | 21 --
|
|
syscared/src/rpc/skeleton/mod.rs | 2 -
|
|
syscared/src/rpc/skeleton_impl/fast_reboot.rs | 42 ---
|
|
syscared/src/rpc/skeleton_impl/mod.rs | 2 -
|
|
18 files changed, 3 insertions(+), 686 deletions(-)
|
|
delete mode 100644 syscare-build/src/package/dependency.rs
|
|
delete mode 100644 syscare-common/src/os/disk.rs
|
|
delete mode 100644 syscare-common/src/os/grub.rs
|
|
delete mode 100644 syscared/src/fast_reboot/manager.rs
|
|
delete mode 100644 syscared/src/fast_reboot/mod.rs
|
|
delete mode 100644 syscared/src/rpc/skeleton/fast_reboot.rs
|
|
delete mode 100644 syscared/src/rpc/skeleton_impl/fast_reboot.rs
|
|
|
|
diff --git a/syscare-build/src/build_root/mod.rs b/syscare-build/src/build_root/mod.rs
|
|
index 81de6b2..6a12788 100644
|
|
--- a/syscare-build/src/build_root/mod.rs
|
|
+++ b/syscare-build/src/build_root/mod.rs
|
|
@@ -12,11 +12,7 @@
|
|
* See the Mulan PSL v2 for more details.
|
|
*/
|
|
|
|
-use std::{
|
|
- ffi::OsStr,
|
|
- ops::Deref,
|
|
- path::{Path, PathBuf},
|
|
-};
|
|
+use std::path::{Path, PathBuf};
|
|
|
|
use anyhow::Result;
|
|
use syscare_common::fs;
|
|
@@ -61,17 +57,3 @@ impl BuildRoot {
|
|
Ok(())
|
|
}
|
|
}
|
|
-
|
|
-impl Deref for BuildRoot {
|
|
- type Target = Path;
|
|
-
|
|
- fn deref(&self) -> &Self::Target {
|
|
- &self.path
|
|
- }
|
|
-}
|
|
-
|
|
-impl AsRef<OsStr> for BuildRoot {
|
|
- fn as_ref(&self) -> &OsStr {
|
|
- self.as_os_str()
|
|
- }
|
|
-}
|
|
diff --git a/syscare-build/src/build_root/package_root.rs b/syscare-build/src/build_root/package_root.rs
|
|
index abb7a86..724a42b 100644
|
|
--- a/syscare-build/src/build_root/package_root.rs
|
|
+++ b/syscare-build/src/build_root/package_root.rs
|
|
@@ -50,9 +50,3 @@ impl PackageRoot {
|
|
})
|
|
}
|
|
}
|
|
-
|
|
-impl AsRef<Path> for PackageRoot {
|
|
- fn as_ref(&self) -> &Path {
|
|
- &self.path
|
|
- }
|
|
-}
|
|
diff --git a/syscare-build/src/build_root/patch_root.rs b/syscare-build/src/build_root/patch_root.rs
|
|
index b780e32..af8ec6b 100644
|
|
--- a/syscare-build/src/build_root/patch_root.rs
|
|
+++ b/syscare-build/src/build_root/patch_root.rs
|
|
@@ -44,9 +44,3 @@ impl PatchRoot {
|
|
})
|
|
}
|
|
}
|
|
-
|
|
-impl AsRef<Path> for PatchRoot {
|
|
- fn as_ref(&self) -> &Path {
|
|
- &self.path
|
|
- }
|
|
-}
|
|
diff --git a/syscare-build/src/package/dependency.rs b/syscare-build/src/package/dependency.rs
|
|
deleted file mode 100644
|
|
index 37bdf92..0000000
|
|
--- a/syscare-build/src/package/dependency.rs
|
|
+++ /dev/null
|
|
@@ -1,10 +0,0 @@
|
|
-pub struct PackageDependency {
|
|
- requires: HashSet<String>,
|
|
- conflicts: HashSet<String>,
|
|
- suggests: HashSet<String>,
|
|
- recommends: HashSet<String>,
|
|
-}
|
|
-
|
|
-impl PackageDependency {
|
|
-
|
|
-}
|
|
\ No newline at end of file
|
|
diff --git a/syscare-build/src/package/mod.rs b/syscare-build/src/package/mod.rs
|
|
index 9ba29a1..72b555a 100644
|
|
--- a/syscare-build/src/package/mod.rs
|
|
+++ b/syscare-build/src/package/mod.rs
|
|
@@ -33,7 +33,6 @@ pub use spec_writer::*;
|
|
pub use tar::*;
|
|
|
|
trait Package {
|
|
- fn extension(&self) -> &'static str;
|
|
fn parse_package_info(&self, pkg_path: &Path) -> Result<PackageInfo>;
|
|
fn query_package_files(&self, pkg_path: &Path) -> Result<Vec<PathBuf>>;
|
|
fn extract_package(&self, pkg_path: &Path, output_dir: &Path) -> Result<()>;
|
|
diff --git a/syscare-build/src/package/rpm/mod.rs b/syscare-build/src/package/rpm/mod.rs
|
|
index 5b4bf07..0e9f77c 100644
|
|
--- a/syscare-build/src/package/rpm/mod.rs
|
|
+++ b/syscare-build/src/package/rpm/mod.rs
|
|
@@ -60,10 +60,6 @@ impl RpmPackage {
|
|
}
|
|
|
|
impl Package for RpmPackage {
|
|
- fn extension(&self) -> &'static str {
|
|
- PKG_FILE_EXT
|
|
- }
|
|
-
|
|
fn parse_package_info(&self, pkg_path: &Path) -> Result<PackageInfo> {
|
|
let query_result = Self::query_package_info(
|
|
pkg_path,
|
|
diff --git a/syscare-common/src/os/disk.rs b/syscare-common/src/os/disk.rs
|
|
deleted file mode 100644
|
|
index 7ace804..0000000
|
|
--- a/syscare-common/src/os/disk.rs
|
|
+++ /dev/null
|
|
@@ -1,64 +0,0 @@
|
|
-// SPDX-License-Identifier: Mulan PSL v2
|
|
-/*
|
|
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
- * syscare-common is licensed under Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- *
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- */
|
|
-
|
|
-use std::ffi::OsStr;
|
|
-use std::path::{Path, PathBuf};
|
|
-
|
|
-use crate::fs;
|
|
-
|
|
-#[inline(always)]
|
|
-fn find_disk<P: AsRef<Path>, S: AsRef<OsStr>>(directory: P, name: S) -> std::io::Result<PathBuf> {
|
|
- #[inline(always)]
|
|
- fn __find_disk(directory: &Path, name: &OsStr) -> std::io::Result<PathBuf> {
|
|
- let dev = fs::find_symlink(
|
|
- directory,
|
|
- name,
|
|
- fs::FindOptions {
|
|
- fuzz: false,
|
|
- recursive: false,
|
|
- },
|
|
- )?;
|
|
- fs::canonicalize(dev)
|
|
- }
|
|
-
|
|
- __find_disk(directory.as_ref(), name.as_ref()).map_err(|_| {
|
|
- std::io::Error::new(
|
|
- std::io::ErrorKind::NotFound,
|
|
- format!(
|
|
- "Cannot find block device by label \"{}\"",
|
|
- name.as_ref().to_string_lossy()
|
|
- ),
|
|
- )
|
|
- })
|
|
-}
|
|
-
|
|
-pub fn find_by_id<S: AsRef<OsStr>>(name: S) -> std::io::Result<PathBuf> {
|
|
- find_disk("/dev/disk/by-id", name)
|
|
-}
|
|
-
|
|
-pub fn find_by_label<S: AsRef<OsStr>>(name: S) -> std::io::Result<PathBuf> {
|
|
- find_disk("/dev/disk/by-label", name)
|
|
-}
|
|
-
|
|
-pub fn find_by_uuid<S: AsRef<OsStr>>(name: S) -> std::io::Result<PathBuf> {
|
|
- find_disk("/dev/disk/by-uuid", name)
|
|
-}
|
|
-
|
|
-pub fn find_by_partuuid<S: AsRef<OsStr>>(name: S) -> std::io::Result<PathBuf> {
|
|
- find_disk("/dev/disk/by-partuuid", name)
|
|
-}
|
|
-
|
|
-pub fn find_by_path<S: AsRef<OsStr>>(name: S) -> std::io::Result<PathBuf> {
|
|
- find_disk("/dev/disk/by-path", name)
|
|
-}
|
|
diff --git a/syscare-common/src/os/grub.rs b/syscare-common/src/os/grub.rs
|
|
deleted file mode 100644
|
|
index 54299d8..0000000
|
|
--- a/syscare-common/src/os/grub.rs
|
|
+++ /dev/null
|
|
@@ -1,312 +0,0 @@
|
|
-// SPDX-License-Identifier: Mulan PSL v2
|
|
-/*
|
|
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
- * syscare-common is licensed under Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- *
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- */
|
|
-
|
|
-use std::collections::HashMap;
|
|
-use std::ffi::{OsStr, OsString};
|
|
-use std::io::{BufRead, BufReader};
|
|
-use std::os::unix::prelude::OsStrExt as StdOsStrExt;
|
|
-use std::path::{Path, PathBuf};
|
|
-
|
|
-use lazy_static::lazy_static;
|
|
-use log::debug;
|
|
-use regex::bytes::Regex;
|
|
-
|
|
-use super::{disk, proc_mounts};
|
|
-use crate::{
|
|
- ffi::OsStrExt,
|
|
- fs,
|
|
- io::{BufReadOsLines, OsLines},
|
|
-};
|
|
-
|
|
-#[derive(Debug, Clone, Copy)]
|
|
-enum BootType {
|
|
- Csm,
|
|
- Uefi,
|
|
-}
|
|
-
|
|
-#[derive(Debug)]
|
|
-pub struct GrubMenuEntry {
|
|
- name: OsString,
|
|
- root: PathBuf,
|
|
- kernel: PathBuf,
|
|
- initrd: PathBuf,
|
|
-}
|
|
-
|
|
-impl GrubMenuEntry {
|
|
- pub fn get_name(&self) -> &OsStr {
|
|
- &self.name
|
|
- }
|
|
-
|
|
- pub fn get_root(&self) -> &Path {
|
|
- &self.root
|
|
- }
|
|
-
|
|
- pub fn get_kernel(&self) -> PathBuf {
|
|
- // Path is stripped by regular expression, thus, it would always start with '/'
|
|
- self.root.join(self.kernel.strip_prefix("/").unwrap())
|
|
- }
|
|
-
|
|
- pub fn get_initrd(&self) -> PathBuf {
|
|
- // Path is stripped by regular expression, thus, it would always start with '/'
|
|
- self.root.join(self.initrd.strip_prefix("/").unwrap())
|
|
- }
|
|
-}
|
|
-
|
|
-struct GrubConfigParser<R> {
|
|
- lines: OsLines<R>,
|
|
- is_matching: bool,
|
|
- entry_name: Option<OsString>,
|
|
- entry_root: Option<PathBuf>,
|
|
- entry_kernel: Option<PathBuf>,
|
|
- entry_initrd: Option<PathBuf>,
|
|
-}
|
|
-
|
|
-impl<R: BufRead> GrubConfigParser<R> {
|
|
- pub fn new(buf: R) -> Self {
|
|
- Self {
|
|
- lines: buf.os_lines(),
|
|
- is_matching: false,
|
|
- entry_name: None,
|
|
- entry_root: None,
|
|
- entry_kernel: None,
|
|
- entry_initrd: None,
|
|
- }
|
|
- }
|
|
-
|
|
- #[inline(always)]
|
|
- fn parse_name(str: &OsStr) -> Option<OsString> {
|
|
- lazy_static! {
|
|
- static ref RE: Regex = Regex::new(r"'([^']*)'").unwrap();
|
|
- }
|
|
- RE.captures(str.as_bytes())
|
|
- .and_then(|captures| captures.get(1))
|
|
- .map(|matched| OsStr::from_bytes(matched.as_bytes()).to_os_string())
|
|
- }
|
|
-
|
|
- #[inline(always)]
|
|
- fn parse_uuid(str: &OsStr) -> Option<OsString> {
|
|
- str.split_whitespace()
|
|
- .filter_map(|str| {
|
|
- let arg = str.trim();
|
|
- if arg != OsStr::new("search") && !arg.starts_with("--") {
|
|
- return Some(arg.to_os_string());
|
|
- }
|
|
- None
|
|
- })
|
|
- .next()
|
|
- }
|
|
-
|
|
- #[inline(always)]
|
|
- fn parse_path(str: &OsStr) -> Option<PathBuf> {
|
|
- lazy_static! {
|
|
- static ref RE: Regex = Regex::new(r"/\.?\w+([\w\-\.])*").unwrap();
|
|
- }
|
|
- RE.find(str.as_bytes())
|
|
- .map(|matched| PathBuf::from(OsStr::from_bytes(matched.as_bytes())))
|
|
- }
|
|
-
|
|
- #[inline(always)]
|
|
- fn parse_mount_point(str: &OsStr) -> Option<PathBuf> {
|
|
- let find_dev = Self::parse_uuid(str).and_then(|uuid| disk::find_by_uuid(uuid).ok());
|
|
- if let (Some(dev_name), Ok(mounts)) = (find_dev, proc_mounts::Mounts::new()) {
|
|
- for mount in mounts {
|
|
- if mount.mount_source == dev_name {
|
|
- return Some(mount.mount_point);
|
|
- }
|
|
- }
|
|
- }
|
|
- None
|
|
- }
|
|
-}
|
|
-
|
|
-impl<R: BufRead> Iterator for GrubConfigParser<R> {
|
|
- type Item = GrubMenuEntry;
|
|
-
|
|
- fn next(&mut self) -> Option<Self::Item> {
|
|
- for line in (&mut self.lines).flatten() {
|
|
- if line.starts_with("#") {
|
|
- continue;
|
|
- }
|
|
-
|
|
- let str = line.trim();
|
|
- if str.is_empty() {
|
|
- continue;
|
|
- }
|
|
-
|
|
- if !self.is_matching {
|
|
- if str.starts_with("menuentry '") {
|
|
- self.entry_name = Self::parse_name(str);
|
|
- self.is_matching = true;
|
|
- }
|
|
- continue;
|
|
- }
|
|
- if str.starts_with("search") {
|
|
- self.entry_root = Self::parse_mount_point(str);
|
|
- } else if str.starts_with("linux") {
|
|
- self.entry_kernel = Self::parse_path(str);
|
|
- } else if str.starts_with("initrd") {
|
|
- self.entry_initrd = Self::parse_path(str);
|
|
- } else if str.starts_with("}") {
|
|
- let entry = match (
|
|
- &self.entry_name,
|
|
- &self.entry_root,
|
|
- &self.entry_kernel,
|
|
- &self.entry_initrd,
|
|
- ) {
|
|
- (Some(name), Some(root), Some(kernel), Some(initrd)) => Some(GrubMenuEntry {
|
|
- name: name.to_os_string(),
|
|
- root: root.to_path_buf(),
|
|
- kernel: kernel.to_path_buf(),
|
|
- initrd: initrd.to_path_buf(),
|
|
- }),
|
|
- _ => None,
|
|
- };
|
|
- self.is_matching = false;
|
|
- self.entry_name = None;
|
|
- self.entry_root = None;
|
|
- self.entry_kernel = None;
|
|
- self.entry_initrd = None;
|
|
-
|
|
- return entry;
|
|
- }
|
|
- }
|
|
- None
|
|
- }
|
|
-}
|
|
-
|
|
-struct GrubEnvParser<R> {
|
|
- lines: OsLines<R>,
|
|
-}
|
|
-
|
|
-impl<R: BufRead> GrubEnvParser<R> {
|
|
- pub fn new(buf: R) -> Self {
|
|
- Self {
|
|
- lines: buf.os_lines(),
|
|
- }
|
|
- }
|
|
-}
|
|
-
|
|
-impl<R: BufRead> Iterator for GrubEnvParser<R> {
|
|
- type Item = (OsString, OsString);
|
|
-
|
|
- fn next(&mut self) -> Option<Self::Item> {
|
|
- for line in (&mut self.lines).flatten() {
|
|
- if line.starts_with("#") {
|
|
- continue;
|
|
- }
|
|
-
|
|
- let str = line.trim();
|
|
- if str.is_empty() {
|
|
- continue;
|
|
- }
|
|
-
|
|
- let mut kv = line.split('=');
|
|
- if let (Some(key), Some(value)) = (kv.next(), kv.next()) {
|
|
- return Some((key.trim().to_os_string(), value.trim().to_os_string()));
|
|
- }
|
|
- }
|
|
-
|
|
- None
|
|
- }
|
|
-}
|
|
-
|
|
-fn get_boot_type() -> BootType {
|
|
- const UEFI_SYS_INTERFACE: &str = "/sys/firmware/efi";
|
|
-
|
|
- match fs::metadata(UEFI_SYS_INTERFACE) {
|
|
- Ok(_) => BootType::Uefi,
|
|
- Err(_) => BootType::Csm,
|
|
- }
|
|
-}
|
|
-
|
|
-fn get_grub_path(boot_type: BootType) -> PathBuf {
|
|
- const CSM_GRUB_PATH: &str = "/boot/grub2";
|
|
- const UEFI_GRUB_PATH: &str = "/boot/efi/EFI";
|
|
-
|
|
- match boot_type {
|
|
- BootType::Csm => PathBuf::from(CSM_GRUB_PATH),
|
|
- BootType::Uefi => PathBuf::from(UEFI_GRUB_PATH),
|
|
- }
|
|
-}
|
|
-
|
|
-fn find_grub_config<P: AsRef<Path>>(grub_root: P) -> std::io::Result<PathBuf> {
|
|
- const GRUB_CFG_NAME: &str = "grub.cfg";
|
|
-
|
|
- fs::find_file(
|
|
- grub_root,
|
|
- GRUB_CFG_NAME,
|
|
- fs::FindOptions {
|
|
- fuzz: false,
|
|
- recursive: true,
|
|
- },
|
|
- )
|
|
-}
|
|
-
|
|
-fn find_grub_env<P: AsRef<Path>>(grub_root: P) -> std::io::Result<PathBuf> {
|
|
- const GRUB_ENV_NAME: &str = "grubenv";
|
|
-
|
|
- fs::find_file(
|
|
- grub_root,
|
|
- GRUB_ENV_NAME,
|
|
- fs::FindOptions {
|
|
- fuzz: false,
|
|
- recursive: true,
|
|
- },
|
|
- )
|
|
-}
|
|
-
|
|
-pub fn read_menu_entries<P: AsRef<Path>>(grub_root: P) -> std::io::Result<Vec<GrubMenuEntry>> {
|
|
- let grub_config = find_grub_config(grub_root)?;
|
|
-
|
|
- let result = GrubConfigParser::new(BufReader::new(fs::open_file(grub_config)?)).collect();
|
|
-
|
|
- Ok(result)
|
|
-}
|
|
-
|
|
-pub fn read_grub_env<P: AsRef<Path>>(grub_root: P) -> std::io::Result<HashMap<OsString, OsString>> {
|
|
- let grub_env = find_grub_env(grub_root).unwrap();
|
|
-
|
|
- let result = GrubEnvParser::new(BufReader::new(fs::open_file(grub_env)?)).collect();
|
|
-
|
|
- Ok(result)
|
|
-}
|
|
-
|
|
-pub fn get_boot_entry() -> std::io::Result<GrubMenuEntry> {
|
|
- let boot_type = get_boot_type();
|
|
- let grub_root = get_grub_path(boot_type);
|
|
- debug!("Boot type: {:?}", boot_type);
|
|
-
|
|
- let menu_entries = read_menu_entries(&grub_root)?;
|
|
- debug!("Boot entries: {:#?}", menu_entries);
|
|
-
|
|
- let grub_env = read_grub_env(&grub_root)?;
|
|
- let default_entry_name = grub_env.get(OsStr::new("saved_entry")).ok_or_else(|| {
|
|
- std::io::Error::new(
|
|
- std::io::ErrorKind::Other,
|
|
- "Cannot read grub default entry name",
|
|
- )
|
|
- })?;
|
|
- debug!("Default entry: {:?}", default_entry_name);
|
|
-
|
|
- for entry in menu_entries {
|
|
- if entry.get_name() == default_entry_name {
|
|
- return Ok(entry);
|
|
- }
|
|
- }
|
|
-
|
|
- Err(std::io::Error::new(
|
|
- std::io::ErrorKind::Other,
|
|
- format!("Cannot find grub default entry {:?}", default_entry_name),
|
|
- ))
|
|
-}
|
|
diff --git a/syscare-common/src/os/kernel.rs b/syscare-common/src/os/kernel.rs
|
|
index b89850b..a29e663 100644
|
|
--- a/syscare-common/src/os/kernel.rs
|
|
+++ b/syscare-common/src/os/kernel.rs
|
|
@@ -12,51 +12,10 @@
|
|
* See the Mulan PSL v2 for more details.
|
|
*/
|
|
|
|
-use std::{ffi::OsStr, path::Path};
|
|
-
|
|
-use anyhow::Result;
|
|
-
|
|
-const KEXEC_PATH: &str = "kexec";
|
|
-const SYSTEMCTL_PATH: &str = "systemctl";
|
|
+use std::ffi::OsStr;
|
|
|
|
use super::platform;
|
|
-use crate::{concat_os, process::Command};
|
|
|
|
pub fn version() -> &'static OsStr {
|
|
platform::release()
|
|
}
|
|
-
|
|
-pub fn load<P, Q>(kernel: P, initramfs: Q) -> Result<()>
|
|
-where
|
|
- P: AsRef<Path>,
|
|
- Q: AsRef<Path>,
|
|
-{
|
|
- Command::new(KEXEC_PATH)
|
|
- .arg("--load")
|
|
- .arg(kernel.as_ref())
|
|
- .arg(concat_os!("--initrd=", initramfs.as_ref()))
|
|
- .arg("--reuse-cmdline")
|
|
- .run_with_output()?
|
|
- .exit_ok()
|
|
-}
|
|
-
|
|
-pub fn unload() -> Result<()> {
|
|
- Command::new(KEXEC_PATH)
|
|
- .arg("--unload")
|
|
- .run_with_output()?
|
|
- .exit_ok()
|
|
-}
|
|
-
|
|
-pub fn systemd_exec() -> Result<()> {
|
|
- Command::new(SYSTEMCTL_PATH)
|
|
- .arg("kexec")
|
|
- .run_with_output()?
|
|
- .exit_ok()
|
|
-}
|
|
-
|
|
-pub fn force_exec() -> Result<()> {
|
|
- Command::new(KEXEC_PATH)
|
|
- .arg("--exec")
|
|
- .run_with_output()?
|
|
- .exit_ok()
|
|
-}
|
|
diff --git a/syscare-common/src/os/mod.rs b/syscare-common/src/os/mod.rs
|
|
index 8e6d5c1..6a93a20 100644
|
|
--- a/syscare-common/src/os/mod.rs
|
|
+++ b/syscare-common/src/os/mod.rs
|
|
@@ -13,8 +13,6 @@
|
|
*/
|
|
|
|
pub mod cpu;
|
|
-pub mod disk;
|
|
-pub mod grub;
|
|
pub mod kernel;
|
|
pub mod platform;
|
|
pub mod proc_maps;
|
|
diff --git a/syscare-common/src/util/digest.rs b/syscare-common/src/util/digest.rs
|
|
index bb879cb..086b636 100644
|
|
--- a/syscare-common/src/util/digest.rs
|
|
+++ b/syscare-common/src/util/digest.rs
|
|
@@ -45,10 +45,3 @@ where
|
|
|
|
Ok(format!("{:#x}", hasher.finalize()))
|
|
}
|
|
-
|
|
-pub fn dir<P: AsRef<Path>>(directory: P) -> std::io::Result<String> {
|
|
- file_list(fs::list_files(
|
|
- directory,
|
|
- fs::TraverseOptions { recursive: true },
|
|
- )?)
|
|
-}
|
|
diff --git a/syscared/src/fast_reboot/manager.rs b/syscared/src/fast_reboot/manager.rs
|
|
deleted file mode 100644
|
|
index 8a4a928..0000000
|
|
--- a/syscared/src/fast_reboot/manager.rs
|
|
+++ /dev/null
|
|
@@ -1,123 +0,0 @@
|
|
-// SPDX-License-Identifier: Mulan PSL v2
|
|
-/*
|
|
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
- * syscared is licensed under Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- *
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- */
|
|
-
|
|
-use std::path::PathBuf;
|
|
-
|
|
-use anyhow::{Context, Result};
|
|
-use lazy_static::lazy_static;
|
|
-use log::{error, info};
|
|
-
|
|
-use syscare_common::{
|
|
- fs,
|
|
- os::{grub, kernel},
|
|
-};
|
|
-
|
|
-lazy_static! {
|
|
- static ref BOOT_DIRECTORY: PathBuf = PathBuf::from("/boot");
|
|
-}
|
|
-
|
|
-pub enum RebootOption {
|
|
- Normal,
|
|
- Forced,
|
|
-}
|
|
-
|
|
-struct LoadKernelOption {
|
|
- name: String,
|
|
- kernel: PathBuf,
|
|
- initramfs: PathBuf,
|
|
-}
|
|
-
|
|
-pub struct KExecManager;
|
|
-
|
|
-impl KExecManager {
|
|
- fn find_kernel(kernel_version: &str) -> Result<LoadKernelOption> {
|
|
- info!("Finding kernel {}...", kernel_version);
|
|
- let kernel_file_name = format!("vmlinuz-{}", kernel_version);
|
|
- let kernel_file = fs::find_file(
|
|
- BOOT_DIRECTORY.as_path(),
|
|
- kernel_file_name,
|
|
- fs::FindOptions {
|
|
- fuzz: false,
|
|
- recursive: false,
|
|
- },
|
|
- )
|
|
- .with_context(|| format!("Cannot find kernel {}", kernel_version))?;
|
|
-
|
|
- info!("Finding initramfs...");
|
|
- let initramfs_file_name = format!("initramfs-{}.img", kernel_version);
|
|
- let initramfs_file = fs::find_file(
|
|
- BOOT_DIRECTORY.as_path(),
|
|
- initramfs_file_name,
|
|
- fs::FindOptions {
|
|
- fuzz: false,
|
|
- recursive: false,
|
|
- },
|
|
- )
|
|
- .with_context(|| format!("Cannot find kernel {} initramfs", kernel_version))?;
|
|
-
|
|
- Ok(LoadKernelOption {
|
|
- name: kernel_version.to_owned(),
|
|
- kernel: kernel_file,
|
|
- initramfs: initramfs_file,
|
|
- })
|
|
- }
|
|
-
|
|
- fn find_kernel_by_grub() -> Result<LoadKernelOption> {
|
|
- info!("Parsing grub configuration...");
|
|
- let entry = grub::get_boot_entry().context("Failed to read grub boot entry")?;
|
|
- let entry_name = entry
|
|
- .get_name()
|
|
- .to_str()
|
|
- .context("Failed to parse grub entry name")?;
|
|
-
|
|
- Ok(LoadKernelOption {
|
|
- name: entry_name.to_owned(),
|
|
- kernel: entry.get_kernel(),
|
|
- initramfs: entry.get_initrd(),
|
|
- })
|
|
- }
|
|
-
|
|
- pub fn load_kernel(kernel_version: Option<String>) -> Result<()> {
|
|
- let load_option = match kernel_version {
|
|
- Some(version) => Self::find_kernel(&version),
|
|
- None => Self::find_kernel_by_grub().or_else(|e| {
|
|
- error!("{:?}", e);
|
|
- let version: &str = kernel::version()
|
|
- .to_str()
|
|
- .context("Failed to parse current kernel version")?;
|
|
-
|
|
- Self::find_kernel(version)
|
|
- }),
|
|
- }?;
|
|
-
|
|
- kernel::unload().context("Failed to unload kernel")?;
|
|
-
|
|
- let name = load_option.name;
|
|
- let kernel = load_option.kernel;
|
|
- let initramfs = load_option.initramfs;
|
|
- info!("Loading {:?}", name);
|
|
- info!("Using kernel: {:?}", kernel);
|
|
- info!("Using initrd: {:?}", initramfs);
|
|
-
|
|
- kernel::load(&kernel, &initramfs).context("Failed to load kernel")
|
|
- }
|
|
-
|
|
- pub fn execute(option: RebootOption) -> Result<()> {
|
|
- match option {
|
|
- RebootOption::Normal => kernel::systemd_exec(),
|
|
- RebootOption::Forced => kernel::force_exec(),
|
|
- }
|
|
- .context("Failed to execute kernel")
|
|
- }
|
|
-}
|
|
diff --git a/syscared/src/fast_reboot/mod.rs b/syscared/src/fast_reboot/mod.rs
|
|
deleted file mode 100644
|
|
index 8c40eb9..0000000
|
|
--- a/syscared/src/fast_reboot/mod.rs
|
|
+++ /dev/null
|
|
@@ -1,17 +0,0 @@
|
|
-// SPDX-License-Identifier: Mulan PSL v2
|
|
-/*
|
|
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
- * syscared is licensed under Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- *
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- */
|
|
-
|
|
-mod manager;
|
|
-
|
|
-pub use manager::*;
|
|
diff --git a/syscared/src/main.rs b/syscared/src/main.rs
|
|
index 5c60ecf..f13a9f8 100644
|
|
--- a/syscared/src/main.rs
|
|
+++ b/syscared/src/main.rs
|
|
@@ -32,17 +32,13 @@ use syscare_common::{concat_os, fs, os};
|
|
|
|
mod args;
|
|
mod config;
|
|
-mod fast_reboot;
|
|
mod patch;
|
|
mod rpc;
|
|
|
|
use args::Arguments;
|
|
use config::Config;
|
|
use patch::monitor::PatchMonitor;
|
|
-use rpc::{
|
|
- skeleton::{FastRebootSkeleton, PatchSkeleton},
|
|
- skeleton_impl::{FastRebootSkeletonImpl, PatchSkeletonImpl},
|
|
-};
|
|
+use rpc::{skeleton::PatchSkeleton, skeleton_impl::PatchSkeletonImpl};
|
|
|
|
const DAEMON_NAME: &str = env!("CARGO_PKG_NAME");
|
|
const DAEMON_VERSION: &str = env!("CARGO_PKG_VERSION");
|
|
@@ -195,7 +191,6 @@ impl Daemon {
|
|
let mut io_handler = IoHandler::new();
|
|
|
|
io_handler.extend_with(PatchSkeletonImpl::new(patch_manager).to_delegate());
|
|
- io_handler.extend_with(FastRebootSkeletonImpl.to_delegate());
|
|
|
|
Ok(io_handler)
|
|
}
|
|
diff --git a/syscared/src/rpc/skeleton/fast_reboot.rs b/syscared/src/rpc/skeleton/fast_reboot.rs
|
|
deleted file mode 100644
|
|
index 1a7b496..0000000
|
|
--- a/syscared/src/rpc/skeleton/fast_reboot.rs
|
|
+++ /dev/null
|
|
@@ -1,21 +0,0 @@
|
|
-// SPDX-License-Identifier: Mulan PSL v2
|
|
-/*
|
|
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
- * syscared is licensed under Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- *
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- */
|
|
-
|
|
-use super::function::{rpc, RpcResult};
|
|
-
|
|
-#[rpc(server)]
|
|
-pub trait FastRebootSkeleton {
|
|
- #[rpc(name = "fast_reboot")]
|
|
- fn fast_reboot(&self, kernel_version: Option<String>, force: bool) -> RpcResult<()>;
|
|
-}
|
|
diff --git a/syscared/src/rpc/skeleton/mod.rs b/syscared/src/rpc/skeleton/mod.rs
|
|
index 74456ca..6fa6b60 100644
|
|
--- a/syscared/src/rpc/skeleton/mod.rs
|
|
+++ b/syscared/src/rpc/skeleton/mod.rs
|
|
@@ -14,8 +14,6 @@
|
|
|
|
use super::function;
|
|
|
|
-mod fast_reboot;
|
|
mod patch;
|
|
|
|
-pub use fast_reboot::*;
|
|
pub use patch::*;
|
|
diff --git a/syscared/src/rpc/skeleton_impl/fast_reboot.rs b/syscared/src/rpc/skeleton_impl/fast_reboot.rs
|
|
deleted file mode 100644
|
|
index aeab458..0000000
|
|
--- a/syscared/src/rpc/skeleton_impl/fast_reboot.rs
|
|
+++ /dev/null
|
|
@@ -1,42 +0,0 @@
|
|
-// SPDX-License-Identifier: Mulan PSL v2
|
|
-/*
|
|
- * Copyright (c) 2024 Huawei Technologies Co., Ltd.
|
|
- * syscared is licensed under Mulan PSL v2.
|
|
- * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
- * You may obtain a copy of Mulan PSL v2 at:
|
|
- * http://license.coscl.org.cn/MulanPSL2
|
|
- *
|
|
- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
|
- * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
|
- * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
|
- * See the Mulan PSL v2 for more details.
|
|
- */
|
|
-
|
|
-use anyhow::{Context, Result};
|
|
-
|
|
-use crate::fast_reboot::{KExecManager, RebootOption};
|
|
-use log::info;
|
|
-
|
|
-use super::{
|
|
- function::{RpcFunction, RpcResult},
|
|
- skeleton::FastRebootSkeleton,
|
|
-};
|
|
-
|
|
-pub struct FastRebootSkeletonImpl;
|
|
-
|
|
-impl FastRebootSkeleton for FastRebootSkeletonImpl {
|
|
- fn fast_reboot(&self, kernel_version: Option<String>, force: bool) -> RpcResult<()> {
|
|
- RpcFunction::call(move || -> Result<()> {
|
|
- info!("Rebooting system...");
|
|
-
|
|
- KExecManager::load_kernel(kernel_version)
|
|
- .and_then(|_| {
|
|
- KExecManager::execute(match force {
|
|
- true => RebootOption::Forced,
|
|
- false => RebootOption::Normal,
|
|
- })
|
|
- })
|
|
- .context("Failed to reboot system")
|
|
- })
|
|
- }
|
|
-}
|
|
diff --git a/syscared/src/rpc/skeleton_impl/mod.rs b/syscared/src/rpc/skeleton_impl/mod.rs
|
|
index a238df4..7037946 100644
|
|
--- a/syscared/src/rpc/skeleton_impl/mod.rs
|
|
+++ b/syscared/src/rpc/skeleton_impl/mod.rs
|
|
@@ -15,8 +15,6 @@
|
|
use super::function;
|
|
use super::skeleton;
|
|
|
|
-mod fast_reboot;
|
|
mod patch;
|
|
|
|
-pub use fast_reboot::*;
|
|
pub use patch::*;
|
|
--
|
|
2.34.1
|
|
|