Skip to content

Commit 4320643

Browse files
committed
9p: removed division into OS-specific files for StartVsockShares,
return created 9p servers for StartShares
1 parent 5ab5be6 commit 4320643

File tree

4 files changed

+47
-58
lines changed

4 files changed

+47
-58
lines changed

cmd/crc/cmd/daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func run(configuration *types.Configuration) error {
254254
if err != nil {
255255
return err
256256
}
257-
if err := fs9p.StartShares([]fs9p.Mount9p{{Listener: listener9p, Path: constants.GetHomeDir()}}); err != nil {
257+
if _, err := fs9p.StartShares([]fs9p.Mount9p{{Listener: listener9p, Path: constants.GetHomeDir()}}); err != nil {
258258
return err
259259
}
260260

pkg/fileserver/fs9p/shares.go

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,35 @@ import (
44
"fmt"
55
"net"
66

7+
"github.com/linuxkit/virtsock/pkg/hvsock"
78
"github.com/sirupsen/logrus"
89
)
910

10-
type Mount struct {
11-
Listener net.Listener
11+
// Mount9p represents an exposed directory path with the listener
12+
// the 9p server is bound to
13+
type Mount9p struct {
1214
Path string
15+
Listener net.Listener
16+
}
17+
18+
// VsockMount9p represents an exposed directory path with the Vsock GUID
19+
// the 9p server is bound to
20+
type VsockMount9p struct {
21+
Path string
22+
VsockGuid string
1323
}
1424

15-
func StartShares(plan9Mounts []Mount) (defErr error) {
16-
for _, m := range plan9Mounts {
25+
// StartShares starts a new 9p server for each of the supplied mounts.
26+
func StartShares(mounts []Mount9p) (servers []*Server, defErr error) {
27+
servers9p := []*Server{}
28+
for _, m := range mounts {
1729
server, err := New9pServer(m.Listener, m.Path)
1830
if err != nil {
19-
return fmt.Errorf("serving directory %s on %s: %w", m.Path, m.Listener.Addr().String(), err)
31+
return nil, fmt.Errorf("serving directory %s on %s: %w", m.Path, m.Listener.Addr().String(), err)
2032
}
33+
34+
servers9p = append(servers9p, server)
35+
2136
defer func() {
2237
if defErr != nil {
2338
if err := server.Stop(); err != nil {
@@ -38,5 +53,30 @@ func StartShares(plan9Mounts []Mount) (defErr error) {
3853
}()
3954
}
4055

41-
return nil
56+
return servers9p, nil
57+
}
58+
59+
// StartVsockShares starts serving the given shares on vsocks instead of TCP sockets.
60+
// The vsocks used must already be defined before StartVsockShares is called.
61+
func StartVsockShares(mounts []VsockMount9p) ([]*Server, error) {
62+
mounts9p := []Mount9p{}
63+
for _, mount := range mounts {
64+
service, err := hvsock.GUIDFromString(mount.VsockGuid)
65+
if err != nil {
66+
return nil, fmt.Errorf("parsing vsock guid %s: %w", mount.VsockGuid, err)
67+
}
68+
69+
listener, err := hvsock.Listen(hvsock.Addr{
70+
VMID: hvsock.GUIDWildcard,
71+
ServiceID: service,
72+
})
73+
if err != nil {
74+
return nil, fmt.Errorf("retrieving listener for vsock %s: %w", mount.VsockGuid, err)
75+
}
76+
77+
logrus.Debugf("Going to serve directory %s on vsock %s", mount.Path, mount.VsockGuid)
78+
mounts9p = append(mounts9p, Mount9p{Path: mount.Path, Listener: listener})
79+
}
80+
81+
return StartShares(mounts9p)
4282
}

pkg/fileserver/fs9p/shares_unsupported.go

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

pkg/fileserver/fs9p/shares_windows.go

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

0 commit comments

Comments
 (0)