diff --git a/Cargo.lock b/Cargo.lock index 4b622d5faf2..5e5a86e6a8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1121,13 +1121,13 @@ dependencies = [ name = "nydus-api" version = "0.2.2" dependencies = [ + "backtrace", "dbs-uhttp", "http", "lazy_static", "libc", "log", "mio", - "nydus-error", "serde", "serde_json", "toml", @@ -1147,18 +1147,6 @@ dependencies = [ "nydus-storage", ] -[[package]] -name = "nydus-error" -version = "0.2.3" -dependencies = [ - "backtrace", - "httpdate", - "libc", - "log", - "serde", - "serde_json", -] - [[package]] name = "nydus-rafs" version = "0.2.2" @@ -1179,7 +1167,6 @@ dependencies = [ "lz4-sys", "nix", "nydus-api", - "nydus-error", "nydus-storage", "nydus-utils", "serde", @@ -1210,7 +1197,6 @@ dependencies = [ "mio", "nix", "nydus-api", - "nydus-error", "nydus-rafs", "nydus-service", "nydus-storage", @@ -1243,7 +1229,6 @@ dependencies = [ "mio", "nix", "nydus-api", - "nydus-error", "nydus-rafs", "nydus-storage", "nydus-utils", @@ -1283,7 +1268,6 @@ dependencies = [ "log", "nix", "nydus-api", - "nydus-error", "nydus-utils", "regex", "reqwest", @@ -1305,6 +1289,7 @@ version = "0.4.1" dependencies = [ "blake3", "flate2", + "httpdate", "lazy_static", "libc", "libz-sys", @@ -1312,7 +1297,7 @@ dependencies = [ "lz4", "lz4-sys", "nix", - "nydus-error", + "nydus-api", "openssl", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 0d50076fa41..2a3e773a9e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,6 @@ openssl = { version = "0.10.48", features = ["vendored"] } #openssl-src = { version = "111.22" } nydus-api = { version = "0.2.2", path = "api", features = ["handler"] } -nydus-error = { version = "0.2.3", path = "error" } nydus-rafs = { version = "0.2.2", path = "rafs", features = ["builder"] } nydus-service = { version = "0.2.0", path = "service", features = ["block-device"] } nydus-storage = { version = "0.6.2", path = "storage" } @@ -106,4 +105,4 @@ backend-registry = ["nydus-storage/backend-registry"] backend-s3 = ["nydus-storage/backend-s3"] [workspace] -members = ["api", "clib", "error", "rafs", "storage", "service", "utils"] +members = ["api", "clib", "rafs", "storage", "service", "utils"] diff --git a/api/Cargo.toml b/api/Cargo.toml index 791a0665d81..ec46e2a678a 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -9,6 +9,7 @@ repository = "https://github.com/dragonflyoss/image-service" edition = "2018" [dependencies] +backtrace = "0.3" dbs-uhttp = { version = "0.3.0", optional = true } http = { version = "0.2.1", optional = true } lazy_static = { version = "1.4.0", optional = true } @@ -20,8 +21,6 @@ serde_json = "1.0.53" toml = "0.5" url = { version = "2.1.1", optional = true } -nydus-error = { version = "0.2", path = "../error" } - [dev-dependencies] vmm-sys-util = { version = "0.10" } diff --git a/api/src/config.rs b/api/src/config.rs index ada5503f97c..c6fb5ace227 100644 --- a/api/src/config.rs +++ b/api/src/config.rs @@ -83,7 +83,10 @@ impl ConfigV2 { pub fn from_file>(path: P) -> Result { let md = fs::metadata(path.as_ref())?; if md.len() > 0x100000 { - return Err(eother!("configuration file size is too big")); + return Err(Error::new( + ErrorKind::Other, + "configuration file size is too big", + )); } let content = fs::read_to_string(path)?; Self::from_str(&content) @@ -115,16 +118,22 @@ impl ConfigV2 { /// Get configuration information for storage backend. pub fn get_backend_config(&self) -> Result<&BackendConfigV2> { - self.backend - .as_ref() - .ok_or_else(|| einval!("no configuration information for backend")) + self.backend.as_ref().ok_or_else(|| { + Error::new( + ErrorKind::InvalidInput, + "no configuration information for backend", + ) + }) } /// Get configuration information for cache subsystem. pub fn get_cache_config(&self) -> Result<&CacheConfigV2> { - self.cache - .as_ref() - .ok_or_else(|| einval!("no configuration information for cache")) + self.cache.as_ref().ok_or_else(|| { + Error::new( + ErrorKind::InvalidData, + "no configuration information for cache", + ) + }) } /// Get cache working directory. @@ -208,14 +217,14 @@ impl FromStr for ConfigV2 { return if v.validate() { Ok(v) } else { - Err(einval!("invalid configuration")) + Err(Error::new(ErrorKind::InvalidInput, "invalid configuration")) }; } if let Ok(v) = toml::from_str::(s) { return if v.validate() { Ok(v) } else { - Err(einval!("invalid configuration")) + Err(Error::new(ErrorKind::InvalidInput, "invalid configuration")) }; } if let Ok(v) = serde_json::from_str::(s) { @@ -225,7 +234,10 @@ impl FromStr for ConfigV2 { } } } - Err(einval!("failed to parse configuration information")) + Err(Error::new( + ErrorKind::InvalidInput, + "failed to parse configuration information", + )) } } @@ -325,66 +337,102 @@ impl BackendConfigV2 { /// Get configuration information for localdisk pub fn get_localdisk_config(&self) -> Result<&LocalDiskConfig> { if &self.backend_type != "localdisk" { - Err(einval!("backend type is not 'localdisk'")) + Err(Error::new( + ErrorKind::InvalidInput, + "backend type is not 'localdisk'", + )) } else { - self.localdisk - .as_ref() - .ok_or_else(|| einval!("no configuration information for localdisk")) + self.localdisk.as_ref().ok_or_else(|| { + Error::new( + ErrorKind::InvalidData, + "no configuration information for localdisk", + ) + }) } } /// Get configuration information for localfs pub fn get_localfs_config(&self) -> Result<&LocalFsConfig> { if &self.backend_type != "localfs" { - Err(einval!("backend type is not 'localfs'")) + Err(Error::new( + ErrorKind::InvalidInput, + "backend type is not 'localfs'", + )) } else { - self.localfs - .as_ref() - .ok_or_else(|| einval!("no configuration information for localfs")) + self.localfs.as_ref().ok_or_else(|| { + Error::new( + ErrorKind::InvalidData, + "no configuration information for localfs", + ) + }) } } /// Get configuration information for OSS pub fn get_oss_config(&self) -> Result<&OssConfig> { if &self.backend_type != "oss" { - Err(einval!("backend type is not 'oss'")) + Err(Error::new( + ErrorKind::InvalidInput, + "backend type is not 'oss'", + )) } else { - self.oss - .as_ref() - .ok_or_else(|| einval!("no configuration information for OSS")) + self.oss.as_ref().ok_or_else(|| { + Error::new( + ErrorKind::InvalidData, + "no configuration information for OSS", + ) + }) } } /// Get configuration information for S3 pub fn get_s3_config(&self) -> Result<&S3Config> { if &self.backend_type != "s3" { - Err(einval!("backend type is not 's3'")) + Err(Error::new( + ErrorKind::InvalidInput, + "backend type is not 's3'", + )) } else { - self.s3 - .as_ref() - .ok_or_else(|| einval!("no configuration information for s3")) + self.s3.as_ref().ok_or_else(|| { + Error::new( + ErrorKind::InvalidData, + "no configuration information for s3", + ) + }) } } /// Get configuration information for Registry pub fn get_registry_config(&self) -> Result<&RegistryConfig> { if &self.backend_type != "registry" { - Err(einval!("backend type is not 'registry'")) + Err(Error::new( + ErrorKind::InvalidInput, + "backend type is not 'registry'", + )) } else { - self.registry - .as_ref() - .ok_or_else(|| einval!("no configuration information for registry")) + self.registry.as_ref().ok_or_else(|| { + Error::new( + ErrorKind::InvalidData, + "no configuration information for registry", + ) + }) } } /// Get configuration information for http proxy pub fn get_http_proxy_config(&self) -> Result<&HttpProxyConfig> { if &self.backend_type != "http-proxy" { - Err(einval!("backend type is not 'http-proxy'")) + Err(Error::new( + ErrorKind::InvalidInput, + "backend type is not 'http-proxy'", + )) } else { - self.http_proxy - .as_ref() - .ok_or_else(|| einval!("no configuration information for http-proxy")) + self.http_proxy.as_ref().ok_or_else(|| { + Error::new( + ErrorKind::InvalidData, + "no configuration information for http-proxy", + ) + }) } } } @@ -643,22 +691,34 @@ impl CacheConfigV2 { /// Get configuration information for file cache. pub fn get_filecache_config(&self) -> Result<&FileCacheConfig> { if self.is_filecache() { - self.file_cache - .as_ref() - .ok_or_else(|| einval!("no configuration information for filecache")) + self.file_cache.as_ref().ok_or_else(|| { + Error::new( + ErrorKind::InvalidInput, + "no configuration information for filecache", + ) + }) } else { - Err(einval!("cache type is not 'filecache'")) + Err(Error::new( + ErrorKind::InvalidData, + "cache type is not 'filecache'", + )) } } /// Get configuration information for fscache. pub fn get_fscache_config(&self) -> Result<&FsCacheConfig> { if self.is_fscache() { - self.fs_cache - .as_ref() - .ok_or_else(|| einval!("no configuration information for fscache")) + self.fs_cache.as_ref().ok_or_else(|| { + Error::new( + ErrorKind::InvalidData, + "no configuration information for fscache", + ) + }) } else { - Err(einval!("cache type is not 'fscache'")) + Err(Error::new( + ErrorKind::InvalidInput, + "cache type is not 'fscache'", + )) } } } @@ -692,19 +752,17 @@ impl FileCacheConfig { fs::metadata(&self.work_dir) }) .map_err(|e| { - last_error!(format!( - "fail to stat filecache work_dir {}: {}", - self.work_dir, e - )) + log::error!("fail to stat filecache work_dir {}: {}", self.work_dir, e); + e })?; if path.is_dir() { Ok(&self.work_dir) } else { - Err(enoent!(format!( - "filecache work_dir {} is not a directory", - self.work_dir - ))) + Err(Error::new( + ErrorKind::NotFound, + format!("filecache work_dir {} is not a directory", self.work_dir), + )) } } } @@ -726,19 +784,17 @@ impl FsCacheConfig { fs::metadata(&self.work_dir) }) .map_err(|e| { - last_error!(format!( - "fail to stat fscache work_dir {}: {}", - self.work_dir, e - )) + log::error!("fail to stat fscache work_dir {}: {}", self.work_dir, e); + e })?; if path.is_dir() { Ok(&self.work_dir) } else { - Err(enoent!(format!( - "fscache work_dir {} is not a directory", - self.work_dir - ))) + Err(Error::new( + ErrorKind::NotFound, + format!("fscache work_dir {} is not a directory", self.work_dir), + )) } } } @@ -909,7 +965,10 @@ impl BlobCacheEntryConfigV2 { pub fn from_file>(path: P) -> Result { let md = fs::metadata(path.as_ref())?; if md.len() > 0x100000 { - return Err(eother!("configuration file size is too big")); + return Err(Error::new( + ErrorKind::InvalidInput, + "configuration file size is too big", + )); } let content = fs::read_to_string(path)?; Self::from_str(&content) @@ -933,17 +992,20 @@ impl FromStr for BlobCacheEntryConfigV2 { return if v.validate() { Ok(v) } else { - Err(einval!("invalid configuration")) + Err(Error::new(ErrorKind::InvalidInput, "invalid configuration")) }; } if let Ok(v) = toml::from_str::(s) { return if v.validate() { Ok(v) } else { - Err(einval!("invalid configuration")) + Err(Error::new(ErrorKind::InvalidInput, "invalid configuration")) }; } - Err(einval!("failed to parse configuration information")) + Err(Error::new( + ErrorKind::InvalidInput, + "failed to parse configuration information", + )) } } @@ -1043,7 +1105,10 @@ impl BlobCacheEntry { pub fn from_file>(path: P) -> Result { let md = fs::metadata(path.as_ref())?; if md.len() > 0x100000 { - return Err(eother!("configuration file size is too big")); + return Err(Error::new( + ErrorKind::InvalidInput, + "configuration file size is too big", + )); } let content = fs::read_to_string(path)?; Self::from_str(&content) @@ -1074,17 +1139,20 @@ impl FromStr for BlobCacheEntry { return if v.validate() { Ok(v) } else { - Err(einval!("invalid configuration")) + Err(Error::new(ErrorKind::InvalidInput, "invalid configuration")) }; } if let Ok(v) = toml::from_str::(s) { return if v.validate() { Ok(v) } else { - Err(einval!("invalid configuration")) + Err(Error::new(ErrorKind::InvalidInput, "invalid configuration")) }; } - Err(einval!("failed to parse configuration information")) + Err(Error::new( + ErrorKind::InvalidInput, + "failed to parse configuration information", + )) } } @@ -1185,7 +1253,12 @@ impl TryFrom<&BackendConfig> for BackendConfigV2 { "registry" => { config.registry = Some(serde_json::from_value(value.backend_config.clone())?); } - v => return Err(einval!(format!("unsupported backend type '{}'", v))), + v => { + return Err(Error::new( + ErrorKind::InvalidInput, + format!("unsupported backend type '{}'", v), + )) + } } Ok(config) @@ -1233,7 +1306,12 @@ impl TryFrom<&CacheConfig> for CacheConfigV2 { config.fs_cache = Some(serde_json::from_value(v.cache_config.clone())?); } "" => {} - t => return Err(einval!(format!("unsupported cache type '{}'", t))), + t => { + return Err(Error::new( + ErrorKind::InvalidInput, + format!("unsupported cache type '{}'", t), + )) + } } Ok(config) diff --git a/error/src/error.rs b/api/src/error.rs similarity index 93% rename from error/src/error.rs rename to api/src/error.rs index 865f392de5a..c0caefa9c06 100644 --- a/error/src/error.rs +++ b/api/src/error.rs @@ -5,8 +5,9 @@ use std::env; use std::fmt::Debug; +#[cfg(debug_assertions)] use backtrace::Backtrace; -use serde_json::Error as SerdeError; +use log::error; /// Display error messages with line number, file path and optional backtrace. pub fn make_error(err: std::io::Error, raw: impl Debug, file: &str, line: u32) -> std::io::Error { @@ -82,15 +83,6 @@ macro_rules! bail_eio { define_error_macro!(last_error, std::io::Error::last_os_error()); define_error_macro!(eother, std::io::Error::new(std::io::ErrorKind::Other, "")); -/// Errors related to Metrics. -#[derive(Debug)] -pub enum MetricsError { - /// Non-exist counter. - NoCounter, - /// Failed to serialize message. - Serialize(SerdeError), -} - #[cfg(test)] mod tests { fn check_size(size: usize) -> std::io::Result<()> { diff --git a/api/src/http.rs b/api/src/http.rs index 92c342ce6e3..e18aad34ee8 100644 --- a/api/src/http.rs +++ b/api/src/http.rs @@ -7,12 +7,20 @@ use std::io; use std::sync::mpsc::{RecvError, SendError}; -use nydus_error::error::MetricsError; use serde::Deserialize; use serde_json::Error as SerdeError; use crate::BlobCacheEntry; +/// Errors related to Metrics. +#[derive(Debug)] +pub enum MetricsError { + /// Non-exist counter. + NoCounter, + /// Failed to serialize message. + Serialize(SerdeError), +} + /// Mount a filesystem. #[derive(Clone, Deserialize, Debug)] pub struct ApiMountCmd { diff --git a/api/src/http_handler.rs b/api/src/http_handler.rs index f4ab8a1ef9c..36a181a6be4 100644 --- a/api/src/http_handler.rs +++ b/api/src/http_handler.rs @@ -12,12 +12,12 @@ use dbs_uhttp::{Body, HttpServer, MediaType, Request, Response, ServerError, Sta use http::uri::Uri; use mio::unix::SourceFd; use mio::{Events, Interest, Poll, Token, Waker}; -use nydus_error::error::MetricsError; use serde::Deserialize; use url::Url; use crate::http::{ - ApiError, ApiRequest, ApiResponse, DaemonErrorKind, ErrorMessage, HttpError, MetricsErrorKind, + ApiError, ApiRequest, ApiResponse, DaemonErrorKind, ErrorMessage, HttpError, MetricsError, + MetricsErrorKind, }; use crate::http_endpoint_common::{ EventsHandler, ExitHandler, MetricsBackendHandler, MetricsBlobcacheHandler, MountHandler, diff --git a/api/src/lib.rs b/api/src/lib.rs index 68643a42f82..531d62ded93 100644 --- a/api/src/lib.rs +++ b/api/src/lib.rs @@ -14,11 +14,11 @@ extern crate serde; #[cfg(feature = "handler")] #[macro_use] extern crate lazy_static; -#[macro_use] -extern crate nydus_error; pub mod config; pub use config::*; +#[macro_use] +pub mod error; pub mod http; pub use self::http::*; diff --git a/error/CHANGELOG.md b/error/CHANGELOG.md deleted file mode 100644 index bc9c278ffaa..00000000000 --- a/error/CHANGELOG.md +++ /dev/null @@ -1,14 +0,0 @@ -# Changelog -## [Unreleased] - -### Added - -### Fixed - -### Deprecated - -## [v0.1.0] - -### Added - -- Initial release diff --git a/error/CODEOWNERS b/error/CODEOWNERS deleted file mode 100644 index 2372b6c7dcd..00000000000 --- a/error/CODEOWNERS +++ /dev/null @@ -1 +0,0 @@ -* @bergwolf @imeoer @jiangliu diff --git a/error/Cargo.toml b/error/Cargo.toml deleted file mode 100644 index eddebbf92ef..00000000000 --- a/error/Cargo.toml +++ /dev/null @@ -1,21 +0,0 @@ -[package] -name = "nydus-error" -version = "0.2.3" -description = "Error handling utilities for Nydus Image Service" -authors = ["The Nydus Developers"] -license = "Apache-2.0 OR BSD-3-Clause" -homepage = "https://nydus.dev/" -repository = "https://github.com/dragonflyoss/image-service" -edition = "2018" - -[dependencies] -backtrace = "0.3" -httpdate = "1.0" -libc = "0.2" -log = "0.4" -serde = { version = "1.0.110", features = ["serde_derive", "rc"] } -serde_json = "1.0.53" - -[package.metadata.docs.rs] -all-features = true -targets = ["x86_64-unknown-linux-gnu", "aarch64-unknown-linux-gnu", "aarch64-apple-darwin"] diff --git a/error/LICENSE-APACHE b/error/LICENSE-APACHE deleted file mode 100644 index d6456956733..00000000000 --- a/error/LICENSE-APACHE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/error/LICENSE-BSD-3-Clause b/error/LICENSE-BSD-3-Clause deleted file mode 120000 index f2b07913555..00000000000 --- a/error/LICENSE-BSD-3-Clause +++ /dev/null @@ -1 +0,0 @@ -../LICENSE-BSD-3-Clause \ No newline at end of file diff --git a/error/README.md b/error/README.md deleted file mode 100644 index ae50b1e7838..00000000000 --- a/error/README.md +++ /dev/null @@ -1,57 +0,0 @@ -# nydus-error - -The `nydus-error` crate is a collection of helper utilities to handle error codes for [`Nydus Image Service`](https://github.com/dragonflyoss/image-service) project, which provides: -- `macro define_error_macro!()` to optionally augment Posix errno with backtrace information. -- `macro einval!(), enoent!()` etc for commonly used error codes. -- `struct ErrorHolder` to provide a circular buffer to hold the latest error messages. - -## Support - -**Platforms**: -- x86_64 -- aarch64 - -**Operating Systems**: -- Linux - -## Usage - -Add `nydus-error` as a dependency in `Cargo.toml` - -```toml -[dependencies] -nydus-error = "*" -``` - -Then add `extern crate nydus-error;` to your crate root if needed. - -## Examples - -- Return an error with backtracing information: - -```rust -fn check_size(size: usize) -> std::io::Result<()> { - if size > 0x1000 { - return Err(einval!()); - } - - Ok(()) -} -``` - -- Put an error message into an `ErrorHolder` object. - -```rust -fn record_error(size: usize) { - let mut holder = ErrorHolder::new(10, 80); - let error_msg = "123456789"; - let r = holder.push(error_msg); - - assert_eq!(r.is_ok(), true); - let _msg = holder.export().unwrap(); -} -``` - -## License - -This code is licensed under [Apache-2.0](LICENSE-APACHE) or [BSD-3-Clause](LICENSE-BSD-3-Clause). diff --git a/error/src/lib.rs b/error/src/lib.rs deleted file mode 100644 index e78ceedcf8e..00000000000 --- a/error/src/lib.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2020 Ant Group. All rights reserved. -// -// SPDX-License-Identifier: Apache-2.0 - -//! Error handling utilities and helpers for Nydus. -//! -//! The `nydus-error` crate provides commonly used error handling utilities and helpers for Nydus, -//! including: -//! - [`fn make_error()`](error.fn.make_error.html): display error messages with line number, -//! file path and optional backtrace. -//! - Macros for commonly used error code, such as `einval!()`, `enosys!()` etc. -//! - [`struct ErrorHolder`](logger.struct.ErrorHolder.html): a circular ring buffer to hold latest -//! error messages. - -#[macro_use] -extern crate log; - -#[macro_use] -pub mod error; - -pub mod logger; diff --git a/rafs/Cargo.toml b/rafs/Cargo.toml index 2d62e143b67..4a05727266d 100644 --- a/rafs/Cargo.toml +++ b/rafs/Cargo.toml @@ -34,7 +34,6 @@ vmm-sys-util = { version = "0.10.0", optional = true } xattr = { version = "0.2.3", optional = true } nydus-api = { version = "0.2", path = "../api" } -nydus-error = { version = "0.2", path = "../error" } nydus-storage = { version = "0.6", path = "../storage", features = ["backend-localfs"] } nydus-utils = { version = "0.4", path = "../utils" } diff --git a/rafs/src/lib.rs b/rafs/src/lib.rs index cedea54ae97..b0b045ec118 100644 --- a/rafs/src/lib.rs +++ b/rafs/src/lib.rs @@ -33,7 +33,7 @@ extern crate log; #[macro_use] extern crate bitflags; #[macro_use] -extern crate nydus_error; +extern crate nydus_api; #[macro_use] extern crate nydus_storage as storage; diff --git a/service/Cargo.toml b/service/Cargo.toml index 1855db32186..b7ddcdea4ec 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -25,7 +25,6 @@ time = { version = "0.3.14", features = ["serde-human-readable"] } tokio = { version = "1.24", features = ["macros"] } nydus-api = { version = "0.2.2", path = "../api"} -nydus-error = { version = "0.2.3", path = "../error" } nydus-rafs = { version = "0.2.2", path = "../rafs" } nydus-storage = { version = "0.6.2", path = "../storage" } nydus-utils = { version = "0.4.1", path = "../utils" } diff --git a/service/src/lib.rs b/service/src/lib.rs index f07dcbbe49a..e9431224e9b 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -15,7 +15,7 @@ #[macro_use] extern crate log; #[macro_use] -extern crate nydus_error; +extern crate nydus_api; use std::fmt::{self, Display}; use std::io; diff --git a/src/bin/nydusd/main.rs b/src/bin/nydusd/main.rs index f0e01f0c222..16ec048f0f7 100644 --- a/src/bin/nydusd/main.rs +++ b/src/bin/nydusd/main.rs @@ -10,7 +10,7 @@ extern crate log; #[macro_use] extern crate lazy_static; #[macro_use] -extern crate nydus_error; +extern crate nydus_api; use std::convert::TryInto; use std::io::{Error, ErrorKind, Result}; diff --git a/src/lib.rs b/src/lib.rs index 946b54eceaa..2a3df9f389e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ #[macro_use] extern crate log; #[macro_use] -extern crate nydus_error; +extern crate nydus_api; use clap::parser::ValuesRef; use clap::ArgMatches; diff --git a/storage/Cargo.toml b/storage/Cargo.toml index 1a483b36a54..dbd7b83182c 100644 --- a/storage/Cargo.toml +++ b/storage/Cargo.toml @@ -37,7 +37,6 @@ gpt = { version = "3.0.0", optional = true } nydus-api = { version = "0.2", path = "../api" } nydus-utils = { version = "0.4", path = "../utils", features = ["encryption", "zran"] } -nydus-error = { version = "0.2", path = "../error" } sha1 = { version = "0.10.5", optional = true } [dev-dependencies] diff --git a/storage/src/lib.rs b/storage/src/lib.rs index ab6aeb253c4..8cb99d558f1 100644 --- a/storage/src/lib.rs +++ b/storage/src/lib.rs @@ -42,7 +42,7 @@ extern crate log; #[macro_use] extern crate bitflags; #[macro_use] -extern crate nydus_error; +extern crate nydus_api; use std::fmt::{Display, Formatter}; diff --git a/utils/Cargo.toml b/utils/Cargo.toml index 65aa0920a6d..a9bb5a7c2f1 100644 --- a/utils/Cargo.toml +++ b/utils/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" [dependencies] blake3 = "1.3" +httpdate = "1.0" lazy_static = "1.4" libc = "0.2" log = "0.4" @@ -23,7 +24,7 @@ tokio = { version = "1.19.0", features = ["rt", "sync"] } zstd = "0.11" nix = "0.24" -nydus-error = { version = "0.2", path = "../error" } +nydus-api = { version = "0.2.2", path = "../api" } # libz-ng-sys doesn't compile on ppc64. Have to fallback to stock zlib-sys [target.'cfg(target_arch = "powerpc64")'.dependencies] diff --git a/utils/src/lib.rs b/utils/src/lib.rs index a8c124fec44..cae9fc8071e 100644 --- a/utils/src/lib.rs +++ b/utils/src/lib.rs @@ -5,11 +5,11 @@ #[macro_use] extern crate log; #[macro_use] -extern crate nydus_error; -#[macro_use] extern crate serde; #[macro_use] extern crate lazy_static; +#[macro_use] +extern crate nydus_api; use std::convert::{Into, TryFrom, TryInto}; use std::time::Duration; @@ -28,6 +28,7 @@ pub mod digest; pub mod exec; pub mod filemap; pub mod inode_bitmap; +pub mod logger; pub mod metrics; pub mod mpmc; pub mod reader; diff --git a/error/src/logger.rs b/utils/src/logger.rs similarity index 100% rename from error/src/logger.rs rename to utils/src/logger.rs diff --git a/utils/src/metrics.rs b/utils/src/metrics.rs index 420cc4d3b26..7c216f0c75c 100644 --- a/utils/src/metrics.rs +++ b/utils/src/metrics.rs @@ -16,9 +16,9 @@ use std::sync::atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicUsize, Ordering} use std::sync::{Arc, Mutex, RwLock}; use std::time::{Duration, SystemTime}; -use nydus_error::error::MetricsError; -use nydus_error::logger::ErrorHolder; +use nydus_api::http::MetricsError; +use crate::logger::ErrorHolder; use crate::InodeBitmap; /// Type of `inode`.