Skip to content

Commit e504a69

Browse files
committed
Support native writable layer on nerdctl run
Signed-off-by: Yifan Yuan <tuji.yyf@alibaba-inc.com>
1 parent dbbe895 commit e504a69

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

pkg/snapshot/overlay.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -831,25 +831,23 @@ func (o *snapshotter) prepareDirectory(ctx context.Context, snapshotDir string,
831831
if err := os.Mkdir(filepath.Join(td, "fs"), 0755); err != nil {
832832
return td, err
833833
}
834+
if err := os.Mkdir(filepath.Join(td, "block"), 0711); err != nil {
835+
return td, err
836+
}
837+
if err := os.Mkdir(filepath.Join(td, "block", "mountpoint"), 0711); err != nil {
838+
return td, err
839+
}
840+
841+
f, err := os.Create(filepath.Join(td, "block", "init-debug.log"))
842+
f.Close()
843+
if err != nil {
844+
return td, err
845+
}
834846

835847
if kind == snapshots.KindActive {
836848
if err := os.Mkdir(filepath.Join(td, "work"), 0711); err != nil {
837849
return td, err
838850
}
839-
840-
if err := os.Mkdir(filepath.Join(td, "block"), 0711); err != nil {
841-
return td, err
842-
}
843-
844-
if err := os.Mkdir(filepath.Join(td, "block", "mountpoint"), 0711); err != nil {
845-
return td, err
846-
}
847-
848-
f, err := os.Create(filepath.Join(td, "block", "init-debug.log"))
849-
f.Close()
850-
if err != nil {
851-
return td, err
852-
}
853851
}
854852
return td, nil
855853
}
@@ -862,13 +860,18 @@ func (o *snapshotter) basedOnBlockDeviceMount(ctx context.Context, s storage.Sna
862860
log.G(ctx).Errorf("basedOnBlockDeviceMount return error: %v", err)
863861
}
864862
}()
863+
rwflag := "rw"
864+
if s.Kind == snapshots.KindView && (writeType == rwflag || writeType == rwDev) {
865+
log.G(ctx).Infof("snapshot.Kind == View, reset overlaybd as READ-ONLY.")
866+
rwflag = "ro"
867+
}
865868
if writeType == rwDir {
866869
return []mount.Mount{
867870
{
868871
Source: o.overlaybdMountpoint(s.ID),
869872
Type: "bind",
870873
Options: []string{
871-
"rw",
874+
rwflag,
872875
"rbind",
873876
},
874877
},
@@ -885,7 +888,7 @@ func (o *snapshotter) basedOnBlockDeviceMount(ctx context.Context, s storage.Sna
885888
Source: string(devName),
886889
Type: "ext4",
887890
Options: []string{
888-
"rw",
891+
rwflag,
889892
"discard",
890893
},
891894
},

0 commit comments

Comments
 (0)