Skip to content

Commit

Permalink
Merge branch 'wedsonaf/tardev' into danmihai1/tardev
Browse files Browse the repository at this point in the history
  • Loading branch information
danmihai1 committed Jun 16, 2023
2 parents 2409aca + 6303b9e commit 96528c5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
11 changes: 8 additions & 3 deletions src/agent/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ async fn overlayfs_storage_handler(
cid: Option<&str>,
_sandbox: Arc<Mutex<Sandbox>>,
) -> Result<String> {
let mut storage = storage.clone();
if storage
.options
.iter()
Expand All @@ -262,18 +263,22 @@ async fn overlayfs_storage_handler(
fs::create_dir_all(&work)?;
fs::create_dir_all(&upper)?;

let mut storage = storage.clone();
storage.fstype = "overlay".into();
storage
.options
.push(format!("upperdir={}", upper.to_string_lossy()));
storage
.options
.push(format!("workdir={}", work.to_string_lossy()));
return common_storage_handler(logger, &storage);
}

common_storage_handler(logger, storage)
// Switch to the pod layers path. This allows snapshotters to skip the path of directories in
// lowerdir.
let saved = std::env::current_dir()?;
std::env::set_current_dir(Path::new("/run/kata-containers/sandbox/layers"))?;
let ret = common_storage_handler(logger, &storage);
std::env::set_current_dir(saved)?;
ret
}

#[instrument]
Expand Down
15 changes: 13 additions & 2 deletions src/runtime/pkg/containerd-shim-v2/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ var defaultStartManagementServerFunc startManagementServerFunc = func(s *service
}

func copyLayersToMounts(rootFs *vc.RootFs, spec *specs.Spec) error {
prefix := ""
for _, o := range rootFs.Options {
if strings.HasPrefix(o, annotations.FileSystemLayerSourcePrefix) {
prefix = o[len(annotations.FileSystemLayerSourcePrefix):]
continue
}

if !strings.HasPrefix(o, annotations.FileSystemLayer) {
continue
}
Expand All @@ -62,10 +68,15 @@ func copyLayersToMounts(rootFs *vc.RootFs, spec *specs.Spec) error {
return fmt.Errorf("Missing fields in rootfs layer: %q", o)
}

source := fields[0]
if len(source) > 0 && source[0] != '/' {
source = filepath.Join(prefix, source)
}

spec.Mounts = append(spec.Mounts, specs.Mount{
Destination: "/run/kata-containers/sandbox/layers/" + filepath.Base(fields[0]),
Destination: "/run/kata-containers/sandbox/layers/" + filepath.Base(source),
Type: fields[1],
Source: fields[0],
Source: source,
Options: fields[2:],
})
}
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/virtcontainers/pkg/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ const (
// FileSystemLayer describes a layer of an overlay filesystem.
FileSystemLayer = kataAnnotFsOptPrefix + "layer="

// FileSystemLayerSourcePrefix determines the prefix path of the source files of the subquent layers.
FileSystemLayerSourcePrefix = kataAnnotFsOptPrefix + "layer-src-prefix="

// IsFileSystemLayer indicates that the annotated filesystem is a layer of an overlay fs.
IsFileSystemLayer = kataAnnotFsOptPrefix + "is-layer"

Expand Down
10 changes: 6 additions & 4 deletions src/tardev-snapshotter/src/snapshotter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ impl Store {
// Get chain of layers.
let mut next_parent = Some(parent.to_string());
let mut layers = Vec::new();
let mut opts = Vec::new();
let mut opts = vec![format!(
"{PREFIX}.layer-src-prefix={}",
self.root.join("layers").to_string_lossy()
)];
while let Some(p) = next_parent {
let info = self.read_snapshot(&p)?;
if info.kind != Kind::Committed {
Expand All @@ -125,11 +128,10 @@ impl Store {
};

let name = name_to_hash(&p);
layers.push(format!("/run/kata-containers/sandbox/layers/{name}"));
opts.push(format!(
"{PREFIX}.layer={},tar,ro,{PREFIX}.block_device=file,{PREFIX}.is-layer,{PREFIX}.root-hash={root_hash}",
self.layer_path(&p).to_string_lossy()
"{PREFIX}.layer={name},tar,ro,{PREFIX}.block_device=file,{PREFIX}.is-layer,{PREFIX}.root-hash={root_hash}",
));
layers.push(name);

next_parent = (!info.parent.is_empty()).then_some(info.parent);
}
Expand Down

0 comments on commit 96528c5

Please sign in to comment.