Skip to content

Commit 9d1d21b

Browse files
committed
Only do virtfs mounts at boot time with fstab
External filesystems can be mounted in /etc/fstab. It is only the reverse-sshfs that needs to use ssh. Signed-off-by: Anders F Björklund <[email protected]>
1 parent f63e8bf commit 9d1d21b

File tree

3 files changed

+17
-157
lines changed

3 files changed

+17
-157
lines changed

pkg/hostagent/hostagent.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,19 +378,21 @@ func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
378378
if err := a.waitForRequirements(ctx, "essential", a.essentialRequirements()); err != nil {
379379
mErr = multierror.Append(mErr, err)
380380
}
381-
mounts, err := a.setupMounts(ctx)
382-
if err != nil {
383-
mErr = multierror.Append(mErr, err)
384-
}
385-
a.onClose = append(a.onClose, func() error {
386-
var unmountMErr error
387-
for _, m := range mounts {
388-
if unmountErr := m.close(); unmountErr != nil {
389-
unmountMErr = multierror.Append(unmountMErr, unmountErr)
390-
}
381+
if *a.y.MountType == limayaml.REVSSHFS {
382+
mounts, err := a.setupMounts(ctx)
383+
if err != nil {
384+
mErr = multierror.Append(mErr, err)
391385
}
392-
return unmountMErr
393-
})
386+
a.onClose = append(a.onClose, func() error {
387+
var unmountMErr error
388+
for _, m := range mounts {
389+
if unmountErr := m.close(); unmountErr != nil {
390+
unmountMErr = multierror.Append(unmountMErr, unmountErr)
391+
}
392+
}
393+
return unmountMErr
394+
})
395+
}
394396
go a.watchGuestAgentEvents(ctx)
395397
if err := a.waitForRequirements(ctx, "optional", a.optionalRequirements()); err != nil {
396398
mErr = multierror.Append(mErr, err)

pkg/hostagent/mount.go

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import (
55
"fmt"
66
"os"
77

8-
"github.com/docker/go-units"
98
"github.com/hashicorp/go-multierror"
109

1110
"github.com/lima-vm/lima/pkg/limayaml"
1211
"github.com/lima-vm/lima/pkg/localpathutil"
13-
"github.com/lima-vm/lima/pkg/remotemount"
1412
"github.com/lima-vm/sshocker/pkg/reversesshfs"
1513
"github.com/sirupsen/logrus"
1614
)
@@ -24,8 +22,8 @@ func (a *HostAgent) setupMounts(ctx context.Context) ([]*mount, error) {
2422
res []*mount
2523
mErr error
2624
)
27-
for i, f := range a.y.Mounts {
28-
m, err := a.setupMount(ctx, i, f)
25+
for _, f := range a.y.Mounts {
26+
m, err := a.setupMount(ctx, f)
2927
if err != nil {
3028
mErr = multierror.Append(mErr, err)
3129
continue
@@ -35,17 +33,7 @@ func (a *HostAgent) setupMounts(ctx context.Context) ([]*mount, error) {
3533
return res, mErr
3634
}
3735

38-
func (a *HostAgent) setupMount(ctx context.Context, i int, m limayaml.Mount) (*mount, error) {
39-
switch *a.y.MountType {
40-
case limayaml.REVSSHFS:
41-
return a.setupMountReverseSSHFS(ctx, m)
42-
case limayaml.NINEP:
43-
return a.setupMount9P(ctx, i, m)
44-
}
45-
return nil, fmt.Errorf("unknown mount type: %v", *a.y.MountType)
46-
}
47-
48-
func (a *HostAgent) setupMountReverseSSHFS(ctx context.Context, m limayaml.Mount) (*mount, error) {
36+
func (a *HostAgent) setupMount(ctx context.Context, m limayaml.Mount) (*mount, error) {
4937
expanded, err := localpathutil.Expand(m.Location)
5038
if err != nil {
5139
return nil, err
@@ -94,51 +82,3 @@ func (a *HostAgent) setupMountReverseSSHFS(ctx context.Context, m limayaml.Mount
9482
}
9583
return res, nil
9684
}
97-
98-
func (a *HostAgent) setupMount9P(ctx context.Context, i int, m limayaml.Mount) (*mount, error) {
99-
expanded, err := localpathutil.Expand(m.Location)
100-
if err != nil {
101-
return nil, err
102-
}
103-
if err := os.MkdirAll(expanded, 0755); err != nil {
104-
return nil, err
105-
}
106-
mountOptions := "trans=virtio"
107-
mountOptions += fmt.Sprintf(",version=%s", *m.NineP.ProtocolVersion)
108-
msize, err := units.RAMInBytes(*m.NineP.Msize)
109-
if err != nil {
110-
return nil, fmt.Errorf("failed to parse msize for %q: %w", expanded, err)
111-
}
112-
mountOptions += fmt.Sprintf(",msize=%d", msize)
113-
mountOptions += fmt.Sprintf(",cache=%s", *m.NineP.Cache)
114-
115-
logrus.Infof("Mounting %q", expanded)
116-
rsf := &remotemount.RemoteMount{
117-
SSHConfig: a.sshConfig,
118-
LocalPath: expanded,
119-
Host: "127.0.0.1",
120-
Port: a.sshLocalPort,
121-
RemotePath: expanded,
122-
Readonly: !(*m.Writable),
123-
MountType: "9p",
124-
MountTag: fmt.Sprintf("mount%d", i),
125-
MountAdditionalArgs: []string{"-o", mountOptions},
126-
}
127-
if err := rsf.Prepare(); err != nil {
128-
return nil, fmt.Errorf("failed to prepare 9p for %q: %w", expanded, err)
129-
}
130-
if err := rsf.Start(); err != nil {
131-
return nil, fmt.Errorf("failed to mount 9p for %q: %w", expanded, err)
132-
}
133-
134-
res := &mount{
135-
close: func() error {
136-
logrus.Infof("Unmounting %q", expanded)
137-
if closeErr := rsf.Close(); closeErr != nil {
138-
return fmt.Errorf("failed to unmount 9p for %q: %w", expanded, err)
139-
}
140-
return nil
141-
},
142-
}
143-
return res, nil
144-
}

pkg/remotemount/remotemount.go

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)