Skip to content

Commit

Permalink
storage: introduce new backend localdisk in nydusd
Browse files Browse the repository at this point in the history
The localdisk backend adds support for storing images in disks. In this
scenario, each layer of the blob is stored in partitions, and multiple
partitions are addressed in the local raw disk via the GUID partition
table (GPT), which means that this disk stores the entire image.

Signed-off-by: Qinqi Qu <[email protected]>
  • Loading branch information
adamqqqplay committed Feb 1, 2023
1 parent 33d2499 commit b0684c1
Show file tree
Hide file tree
Showing 13 changed files with 409 additions and 3 deletions.
48 changes: 48 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ nydus-rafs = { version = "0.2.0", path = "rafs", features = [
"backend-registry",
"backend-oss",
"backend-s3",
"backend-localdisk",
] }
nydus-storage = { version = "0.6.0", path = "storage" }
nydus-utils = { version = "0.4.0", path = "utils" }
Expand Down
46 changes: 44 additions & 2 deletions api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ pub struct BackendConfigV2 {
/// Type of storage backend.
#[serde(rename = "type")]
pub backend_type: String,
/// Configuration for local disk backend.
pub localdisk: Option<LocalDiskConfig>,
/// Configuration for local filesystem backend.
pub localfs: Option<LocalFsConfig>,
/// Configuration for OSS backend.
Expand All @@ -244,6 +246,14 @@ impl BackendConfigV2 {
/// Validate storage backend configuration.
pub fn validate(&self) -> bool {
match self.backend_type.as_str() {
"localdisk" => match self.localdisk.as_ref() {
Some(v) => {
if v.device_path.is_empty() {
return false;
}
}
None => return false,
},
"localfs" => match self.localfs.as_ref() {
Some(v) => {
if v.blob_file.is_empty() && v.dir.is_empty() {
Expand Down Expand Up @@ -282,6 +292,17 @@ impl BackendConfigV2 {
true
}

/// 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'"))
} else {
self.localdisk
.as_ref()
.ok_or_else(|| einval!("no configuration information for localdisk"))
}
}

/// Get configuration information for localfs
pub fn get_localfs_config(&self) -> Result<&LocalFsConfig> {
if &self.backend_type != "localfs" {
Expand Down Expand Up @@ -327,6 +348,14 @@ impl BackendConfigV2 {
}
}

/// Configuration information for localdisk storage backend.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct LocalDiskConfig {
/// Mounted block device path or original localdisk image file path.
#[serde(default)]
pub device_path: String,
}

/// Configuration information for localfs storage backend.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct LocalFsConfig {
Expand Down Expand Up @@ -889,7 +918,7 @@ struct BackendConfig {
#[serde(rename = "type")]
pub backend_type: String,
/// Configuration for storage backend.
/// Possible value: `LocalFsConfig`, `RegistryConfig`, `OssConfig`.
/// Possible value: `LocalFsConfig`, `RegistryConfig`, `OssConfig`, `LocalDiskConfig`.
#[serde(rename = "config")]
pub backend_config: Value,
}
Expand All @@ -900,13 +929,17 @@ impl TryFrom<&BackendConfig> for BackendConfigV2 {
fn try_from(value: &BackendConfig) -> std::result::Result<Self, Self::Error> {
let mut config = BackendConfigV2 {
backend_type: value.backend_type.clone(),
localdisk: None,
localfs: None,
oss: None,
s3: None,
registry: None,
};

match value.backend_type.as_str() {
"localdisk" => {
config.localdisk = Some(serde_json::from_value(value.backend_config.clone())?);
}
"localfs" => {
config.localfs = Some(serde_json::from_value(value.backend_config.clone())?);
}
Expand Down Expand Up @@ -1126,7 +1159,7 @@ pub(crate) struct BlobCacheEntryConfig {
backend_type: String,
/// Configuration for storage backend, corresponding to `FactoryConfig::BackendConfig::backend_config`.
///
/// Possible value: `LocalFsConfig`, `RegistryConfig`, `OssConfig`.
/// Possible value: `LocalFsConfig`, `RegistryConfig`, `OssConfig`, `LocalDiskConfig`.
backend_config: Value,
/// Type of blob cache, corresponding to `FactoryConfig::CacheConfig::cache_type`.
///
Expand Down Expand Up @@ -1382,6 +1415,15 @@ mod tests {
assert_eq!(config.alt_dirs, vec!["dir1", "dir2"]);
}

#[test]
fn test_localdisk_config() {
let content = r#"{
"device_path": "device_path"
}"#;
let config: LocalDiskConfig = serde_json::from_str(content).unwrap();
assert_eq!(config.device_path, "device_path");
}

#[test]
fn test_backend_config() {
let config = BackendConfig {
Expand Down
1 change: 1 addition & 0 deletions blobfs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ virtiofs = ["fuse-backend-rs/virtiofs", "nydus-rafs/virtio-fs"]
baekend-s3 = ["nydus-rafs/backend-s3"]
backend-oss = ["nydus-rafs/backend-oss"]
backend-registry = ["nydus-rafs/backend-registry"]
backend-localdisk = ["nydus-rafs/backend-localdisk"]

[package.metadata.docs.rs]
all-features = true
Expand Down
1 change: 1 addition & 0 deletions clib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ nydus-rafs = { version = "0.2.0", path = "../rafs" }
baekend-s3 = ["nydus-rafs/backend-s3"]
backend-oss = ["nydus-rafs/backend-oss"]
backend-registry = ["nydus-rafs/backend-registry"]
backend-localdisk = ["nydus-rafs/backend-localdisk"]
19 changes: 19 additions & 0 deletions docs/nydusd.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,25 @@ We are working on enabling cloud-hypervisor support for nydus.
}
```

##### Localdisk Backend

```
{
"device": {
"backend": {
"type": "localdisk",
"config": {
// Mounted block device path or original localdisk image file path.
"device_path": "/dev/loop1"
//"device_path": "/home/user/ubuntu.img"
}
},
...
},
...
}
```

##### OSS backend with blobcache

```
Expand Down
1 change: 1 addition & 0 deletions rafs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ vhost-user-fs = ["fuse-backend-rs/vhost-user-fs"]
backend-oss = ["nydus-storage/backend-oss"]
backend-s3 = ["nydus-storage/backend-s3"]
backend-registry = ["nydus-storage/backend-registry"]
backend-localdisk = ["nydus-storage/backend-localdisk"]

[package.metadata.docs.rs]
all-features = true
Expand Down
2 changes: 2 additions & 0 deletions storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tokio = { version = "1.19.0", features = ["rt", "rt-multi-thread", "sync", "time
url = { version = "2.1.1", optional = true }
vm-memory = "0.9"
fuse-backend-rs = "0.10"
gpt = { version = "3.0.0", optional = true }

nydus-api = { version = "0.2", path = "../api" }
nydus-utils = { version = "0.4", path = "../utils", features = ["zran"] }
Expand All @@ -43,6 +44,7 @@ tar = "0.4.38"
regex = "1.7.0"

[features]
backend-localdisk = ["gpt"]
backend-localfs = []
backend-oss = ["base64", "httpdate", "hmac", "sha1", "reqwest", "url"]
backend-registry = ["base64", "reqwest", "url"]
Expand Down
2 changes: 1 addition & 1 deletion storage/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# nydus-storage

The core storage subsystem for [Nydus Image Service](https://nydus.dev/) to:
- Fetch blob objects from storage backend such as Registry, OSS, S3 and file systems etc.
- Fetch blob objects from storage backend such as Registry, OSS, S3, local disk and file systems etc.
- Load data from storage backend on demand.
- Cache blob objects on local storage.

Expand Down
Loading

0 comments on commit b0684c1

Please sign in to comment.