Skip to content
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

Make sshfs caching configurable #564

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/hostagent/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ func (a *HostAgent) setupMount(ctx context.Context, m limayaml.Mount) (*mount, e
return nil, err
}
// NOTE: allow_other requires "user_allow_other" in /etc/fuse.conf
sshfsOptions := "allow_other,cache=no"
sshfsOptions := "allow_other"
if !*m.SSHFS.Cache {
sshfsOptions = sshfsOptions + ",cache=no"
}
if *m.SSHFS.FollowSymlinks {
sshfsOptions = sshfsOptions + ",follow_symlinks"
}
Expand Down
12 changes: 8 additions & 4 deletions pkg/limayaml/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ mounts:
# Setting `writable` to true is possible, but untested and dangerous.
# Default: false
writable: null
# SSHFS has an optional flag called 'follow_symlinks'. This allows mounts
# to be properly resolved in the guest os and allow for access to the
# contents of the symlink. As a result, symlinked files & folders on the Host
# system will look and feel like regular files directories in the Guest OS.
sshfs:
# Enabling the SSHFS cache will increase performance of the mounted filesystem, at
# the cost of potentially not reflecting changes made on the host in a timely manner.
# Default: false
cache: null
# SSHFS has an optional flag called 'follow_symlinks'. This allows mounts
# to be properly resolved in the guest os and allow for access to the
# contents of the symlink. As a result, symlinked files & folders on the Host
# system will look and feel like regular files directories in the Guest OS.
# Default: false
followSymlinks: null
- location: "/tmp/lima"
Expand Down
6 changes: 6 additions & 0 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
location := make(map[string]int)
for _, mount := range append(append(d.Mounts, y.Mounts...), o.Mounts...) {
if i, ok := location[mount.Location]; ok {
if mount.SSHFS.Cache != nil {
mounts[i].SSHFS.Cache = mount.SSHFS.Cache
}
if mount.SSHFS.FollowSymlinks != nil {
mounts[i].SSHFS.FollowSymlinks = mount.SSHFS.FollowSymlinks
}
Expand All @@ -335,6 +338,9 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {

for i := range y.Mounts {
mount := &y.Mounts[i]
if mount.SSHFS.Cache == nil {
mount.SSHFS.Cache = pointer.Bool(false)
}
if mount.SSHFS.FollowSymlinks == nil {
mount.SSHFS.FollowSymlinks = pointer.Bool(false)
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func TestFillDefault(t *testing.T) {
expect := builtin
expect.Mounts = y.Mounts
expect.Mounts[0].Writable = pointer.Bool(false)
expect.Mounts[0].SSHFS.Cache = pointer.Bool(false)
expect.Mounts[0].SSHFS.FollowSymlinks = pointer.Bool(false)
// Only missing Mounts field is Writable, and the default value is also the null value: false

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

y = LimaYAML{}
Expand Down Expand Up @@ -314,7 +316,10 @@ func TestFillDefault(t *testing.T) {
{
Location: "/var/log",
Writable: pointer.Bool(true),
SSHFS: SSHFS{FollowSymlinks: pointer.Bool(true)},
SSHFS: SSHFS{
Cache: pointer.Bool(true),
FollowSymlinks: pointer.Bool(true),
},
},
},
Provision: []Provision{
Expand Down Expand Up @@ -371,6 +376,7 @@ func TestFillDefault(t *testing.T) {
// o.Mounts just makes d.Mounts[0] writable because the Location matches
expect.Mounts = append(d.Mounts, y.Mounts...)
expect.Mounts[0].Writable = pointer.Bool(true)
expect.Mounts[0].SSHFS.Cache = pointer.Bool(true)
expect.Mounts[0].SSHFS.FollowSymlinks = pointer.Bool(true)

// o.Networks[1] is overriding the d.Networks[0].Lima entry for the "def0" interface
Expand Down
1 change: 1 addition & 0 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Mount struct {
}

type SSHFS struct {
Cache *bool `yaml:"cache,omitempty" json:"cache,omitempty"`
FollowSymlinks *bool `yaml:"followSymlinks,omitempty" json:"followSymlinks,omitempty"`
}

Expand Down