-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support direct use blob cache to run image #1436
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,7 @@ impl BackendConfigV2 { | |
} | ||
None => return false, | ||
}, | ||
"noop" => return true, | ||
_ => return false, | ||
} | ||
|
||
|
@@ -755,6 +756,9 @@ pub struct FileCacheConfig { | |
/// Key for data encryption, a heximal representation of [u8; 32]. | ||
#[serde(default)] | ||
pub encryption_key: String, | ||
/// disbale chunk map, it is assumed that all data is ready | ||
#[serde(default)] | ||
pub disable_chunk_map: bool, | ||
} | ||
|
||
impl FileCacheConfig { | ||
|
@@ -842,6 +846,9 @@ pub struct RafsConfigV2 { | |
/// Filesystem prefetching configuration. | ||
#[serde(default)] | ||
pub prefetch: PrefetchConfigV2, | ||
// Only use cache, don't access the backend | ||
#[serde(default)] | ||
pub use_cache_only: bool, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The option should be put into the |
||
} | ||
|
||
impl RafsConfigV2 { | ||
|
@@ -1260,6 +1267,9 @@ impl TryFrom<&BackendConfig> for BackendConfigV2 { | |
"registry" => { | ||
config.registry = Some(serde_json::from_value(value.backend_config.clone())?); | ||
} | ||
"noop" => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need |
||
// do nothing, noop don't have config | ||
} | ||
v => { | ||
return Err(Error::new( | ||
ErrorKind::InvalidInput, | ||
|
@@ -1366,6 +1376,9 @@ struct RafsConfig { | |
// ZERO value means, amplifying user io is not enabled. | ||
#[serde(default = "default_batch_size")] | ||
pub amplify_io: usize, | ||
// Only use cache, don't access the backend | ||
#[serde(default)] | ||
pub use_cache_only: bool, | ||
} | ||
|
||
impl TryFrom<RafsConfig> for ConfigV2 { | ||
|
@@ -1383,6 +1396,7 @@ impl TryFrom<RafsConfig> for ConfigV2 { | |
access_pattern: v.access_pattern, | ||
latest_read_files: v.latest_read_files, | ||
prefetch: v.fs_prefetch.into(), | ||
use_cache_only: v.use_cache_only, | ||
}; | ||
if !cache.prefetch.enable && rafs.prefetch.enable { | ||
cache.prefetch = rafs.prefetch.clone(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (C) 2021-2023 Alibaba Cloud. All rights reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! Storage backend driver to reject all blob operations. | ||
|
||
use std::io::Result; | ||
use std::sync::Arc; | ||
|
||
use fuse_backend_rs::file_buf::FileVolatileSlice; | ||
use nydus_utils::metrics::BackendMetrics; | ||
|
||
use crate::backend::{BackendError, BackendResult, BlobBackend, BlobReader}; | ||
|
||
#[derive(Debug)] | ||
pub enum NoopError { | ||
Noop, | ||
} | ||
|
||
/// a Noop backend, do nothing | ||
#[derive(Default)] | ||
pub struct Noop { | ||
metrics: Arc<BackendMetrics>, | ||
} | ||
|
||
impl Noop { | ||
pub fn new(id: Option<&str>) -> Result<Self> { | ||
let id = id.ok_or_else(|| einval!("noop requires blob_id"))?; | ||
Ok(Noop { | ||
metrics: BackendMetrics::new(id, "noop"), | ||
}) | ||
} | ||
} | ||
|
||
struct NoopEntry { | ||
blob_id: String, | ||
metrics: Arc<BackendMetrics>, | ||
} | ||
|
||
impl BlobReader for NoopEntry { | ||
fn blob_size(&self) -> BackendResult<u64> { | ||
Err(BackendError::Unsupported(format!( | ||
"unsupport blob_size operation for {}", | ||
self.blob_id, | ||
))) | ||
} | ||
|
||
fn try_read(&self, _buf: &mut [u8], _offset: u64) -> BackendResult<usize> { | ||
Err(BackendError::Unsupported(format!( | ||
"unsupport try_read operation for {}", | ||
self.blob_id, | ||
))) | ||
} | ||
|
||
fn readv( | ||
&self, | ||
_bufs: &[FileVolatileSlice], | ||
_offset: u64, | ||
_max_size: usize, | ||
) -> BackendResult<usize> { | ||
Err(BackendError::Unsupported(format!( | ||
"unsupport readv operation for {}", | ||
self.blob_id, | ||
))) | ||
} | ||
|
||
fn metrics(&self) -> &BackendMetrics { | ||
&self.metrics | ||
} | ||
} | ||
|
||
impl BlobBackend for Noop { | ||
fn shutdown(&self) {} | ||
|
||
fn metrics(&self) -> &BackendMetrics { | ||
&self.metrics | ||
} | ||
|
||
fn get_reader(&self, blob_id: &str) -> BackendResult<Arc<dyn BlobReader>> { | ||
Ok(Arc::new(NoopEntry { | ||
blob_id: blob_id.to_owned(), | ||
metrics: self.metrics.clone(), | ||
})) | ||
} | ||
} | ||
|
||
impl Drop for Noop { | ||
fn drop(&mut self) { | ||
self.metrics.release().unwrap_or_else(|e| error!("{:?}", e)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this option similar to
disable_indexed_map
? And should we export the option to the user?