Skip to content

Commit 35908b7

Browse files
committed
9p: use fscache by default for RO mounts
Fix issue 786 Signed-off-by: Akihiro Suda <[email protected]>
1 parent e486db9 commit 35908b7

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

examples/default.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ mounts:
7272
# 🟢 Builtin default: "128KiB"
7373
msize: null
7474
# Specifies a caching policy. Valid options are: "none", "loose", "fscache" and "mmap".
75-
# 🟢 Builtin default: "mmap"
75+
# Try choosing "mmap" or "none" if you see a stability issue with the default "fscache".
76+
# See https://www.kernel.org/doc/Documentation/filesystems/9p.txt
77+
# 🟢 Builtin default: "fscache" for non-writable mounts, "mmap" for writable mounts
7678
cache: null
7779
- location: "/tmp/lima"
7880
# 🟢 Builtin default: false

examples/experimental/9p.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ images:
1818

1919
mounts:
2020
- location: "~"
21+
9p:
22+
# Try choosing "mmap" or "none" if you see a stability issue with the default "fscache".
23+
cache: "fscache"
2124
- location: "/tmp/lima"
2225
writable: true
26+
9p:
27+
cache: "mmap"
28+
2329
mountType: "9p"

pkg/limayaml/defaults.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const (
2525
Default9pSecurityModel string = "mapped-xattr"
2626
Default9pProtocolVersion string = "9p2000.L"
2727
Default9pMsize string = "128KiB"
28-
Default9pCache string = "mmap"
28+
Default9pCacheForRO string = "fscache"
29+
Default9pCacheForRW string = "mmap"
2930
)
3031

3132
func defaultContainerdArchives() []File {
@@ -413,12 +414,16 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
413414
if mount.NineP.Msize == nil {
414415
mounts[i].NineP.Msize = pointer.String(Default9pMsize)
415416
}
416-
if mount.NineP.Cache == nil {
417-
mounts[i].NineP.Cache = pointer.String(Default9pCache)
418-
}
419417
if mount.Writable == nil {
420418
mount.Writable = pointer.Bool(false)
421419
}
420+
if mount.NineP.Cache == nil {
421+
if *mount.Writable {
422+
mounts[i].NineP.Cache = pointer.String(Default9pCacheForRW)
423+
} else {
424+
mounts[i].NineP.Cache = pointer.String(Default9pCacheForRO)
425+
}
426+
}
422427
}
423428

424429
if y.MountType == nil {

pkg/limayaml/defaults_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func TestFillDefault(t *testing.T) {
140140
expect.Mounts[0].NineP.SecurityModel = pointer.String(Default9pSecurityModel)
141141
expect.Mounts[0].NineP.ProtocolVersion = pointer.String(Default9pProtocolVersion)
142142
expect.Mounts[0].NineP.Msize = pointer.String(Default9pMsize)
143-
expect.Mounts[0].NineP.Cache = pointer.String(Default9pCache)
143+
expect.Mounts[0].NineP.Cache = pointer.String(Default9pCacheForRO)
144144
// Only missing Mounts field is Writable, and the default value is also the null value: false
145145

146146
expect.MountType = pointer.String(NINEP)
@@ -277,7 +277,7 @@ func TestFillDefault(t *testing.T) {
277277
expect.Mounts[0].NineP.SecurityModel = pointer.String(Default9pSecurityModel)
278278
expect.Mounts[0].NineP.ProtocolVersion = pointer.String(Default9pProtocolVersion)
279279
expect.Mounts[0].NineP.Msize = pointer.String(Default9pMsize)
280-
expect.Mounts[0].NineP.Cache = pointer.String(Default9pCache)
280+
expect.Mounts[0].NineP.Cache = pointer.String(Default9pCacheForRO)
281281
expect.HostResolver.Hosts = map[string]string{
282282
"default.": d.HostResolver.Hosts["default"],
283283
}

0 commit comments

Comments
 (0)