Skip to content

Commit 2b6db74

Browse files
authored
Merge pull request #564 from rancher-sandbox/sshfs-cache-option
Make sshfs caching configurable
2 parents 5f6559c + 8afdaa9 commit 2b6db74

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

pkg/hostagent/mount.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ func (a *HostAgent) setupMount(ctx context.Context, m limayaml.Mount) (*mount, e
4242
return nil, err
4343
}
4444
// NOTE: allow_other requires "user_allow_other" in /etc/fuse.conf
45-
sshfsOptions := "allow_other,cache=no"
45+
sshfsOptions := "allow_other"
46+
if !*m.SSHFS.Cache {
47+
sshfsOptions = sshfsOptions + ",cache=no"
48+
}
4649
if *m.SSHFS.FollowSymlinks {
4750
sshfsOptions = sshfsOptions + ",follow_symlinks"
4851
}

pkg/limayaml/default.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,15 @@ mounts:
4747
# Setting `writable` to true is possible, but untested and dangerous.
4848
# Default: false
4949
writable: null
50-
# SSHFS has an optional flag called 'follow_symlinks'. This allows mounts
51-
# to be properly resolved in the guest os and allow for access to the
52-
# contents of the symlink. As a result, symlinked files & folders on the Host
53-
# system will look and feel like regular files directories in the Guest OS.
5450
sshfs:
51+
# Enabling the SSHFS cache will increase performance of the mounted filesystem, at
52+
# the cost of potentially not reflecting changes made on the host in a timely manner.
53+
# Default: false
54+
cache: null
55+
# SSHFS has an optional flag called 'follow_symlinks'. This allows mounts
56+
# to be properly resolved in the guest os and allow for access to the
57+
# contents of the symlink. As a result, symlinked files & folders on the Host
58+
# system will look and feel like regular files directories in the Guest OS.
5559
# Default: false
5660
followSymlinks: null
5761
- location: "/tmp/lima"

pkg/limayaml/defaults.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
320320
location := make(map[string]int)
321321
for _, mount := range append(append(d.Mounts, y.Mounts...), o.Mounts...) {
322322
if i, ok := location[mount.Location]; ok {
323+
if mount.SSHFS.Cache != nil {
324+
mounts[i].SSHFS.Cache = mount.SSHFS.Cache
325+
}
323326
if mount.SSHFS.FollowSymlinks != nil {
324327
mounts[i].SSHFS.FollowSymlinks = mount.SSHFS.FollowSymlinks
325328
}
@@ -335,6 +338,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
335338

336339
for i := range y.Mounts {
337340
mount := &y.Mounts[i]
341+
if mount.SSHFS.Cache == nil {
342+
mount.SSHFS.Cache = pointer.Bool(false)
343+
}
338344
if mount.SSHFS.FollowSymlinks == nil {
339345
mount.SSHFS.FollowSymlinks = pointer.Bool(false)
340346
}

pkg/limayaml/defaults_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ func TestFillDefault(t *testing.T) {
120120
expect := builtin
121121
expect.Mounts = y.Mounts
122122
expect.Mounts[0].Writable = pointer.Bool(false)
123+
expect.Mounts[0].SSHFS.Cache = pointer.Bool(false)
123124
expect.Mounts[0].SSHFS.FollowSymlinks = pointer.Bool(false)
124125
// Only missing Mounts field is Writable, and the default value is also the null value: false
125126

@@ -243,6 +244,7 @@ func TestFillDefault(t *testing.T) {
243244
expect = d
244245
// Also verify that archive arch is filled in
245246
expect.Containerd.Archives[0].Arch = *d.Arch
247+
expect.Mounts[0].SSHFS.Cache = pointer.Bool(false)
246248
expect.Mounts[0].SSHFS.FollowSymlinks = pointer.Bool(false)
247249

248250
y = LimaYAML{}
@@ -314,7 +316,10 @@ func TestFillDefault(t *testing.T) {
314316
{
315317
Location: "/var/log",
316318
Writable: pointer.Bool(true),
317-
SSHFS: SSHFS{FollowSymlinks: pointer.Bool(true)},
319+
SSHFS: SSHFS{
320+
Cache: pointer.Bool(true),
321+
FollowSymlinks: pointer.Bool(true),
322+
},
318323
},
319324
},
320325
Provision: []Provision{
@@ -371,6 +376,7 @@ func TestFillDefault(t *testing.T) {
371376
// o.Mounts just makes d.Mounts[0] writable because the Location matches
372377
expect.Mounts = append(d.Mounts, y.Mounts...)
373378
expect.Mounts[0].Writable = pointer.Bool(true)
379+
expect.Mounts[0].SSHFS.Cache = pointer.Bool(true)
374380
expect.Mounts[0].SSHFS.FollowSymlinks = pointer.Bool(true)
375381

376382
// o.Networks[1] is overriding the d.Networks[0].Lima entry for the "def0" interface

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Mount struct {
5050
}
5151

5252
type SSHFS struct {
53+
Cache *bool `yaml:"cache,omitempty" json:"cache,omitempty"`
5354
FollowSymlinks *bool `yaml:"followSymlinks,omitempty" json:"followSymlinks,omitempty"`
5455
}
5556

0 commit comments

Comments
 (0)