Skip to content

Commit 1d59e03

Browse files
committed
nfs: implement Guest mountpoint
1 parent 8ff54d3 commit 1d59e03

File tree

2 files changed

+54
-5
lines changed

2 files changed

+54
-5
lines changed

internal/filesystem/nfs/client.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ type (
6262
ClientOption func(*clientSettings) error
6363
)
6464

65-
const (
66-
errStale = generic.ConstError("handle became stale")
67-
GuestID filesystem.ID = "NFS"
68-
)
65+
const errStale = generic.ConstError("handle became stale")
6966

7067
func NewNFSGuest(maddr multiaddr.Multiaddr, options ...ClientOption) (*goFS, error) {
7168
var (

internal/filesystem/nfs/mountpoint.go

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,23 @@ type (
2424
Host struct {
2525
Maddr multiaddr.Multiaddr `json:"maddr,omitempty"`
2626
}
27+
// Guest holds metadata required to establish
28+
// a client connection to an NFS server.
29+
Guest struct {
30+
Maddr multiaddr.Multiaddr `json:"maddr,omitempty"`
31+
Hostname string `json:"hostname,omitempty"`
32+
Dirpath string `json:"dirpath,omitempty"`
33+
LinkSeparator string `json:"linkSeparator,omitempty"`
34+
LinkLimit uint `json:"linkLimit,omitempty"`
35+
UID uint32 `json:"uid,omitempty"`
36+
GID uint32 `json:"gid,omitempty"`
37+
}
2738
)
2839

29-
const HostID filesystem.Host = "NFS"
40+
const (
41+
HostID filesystem.Host = "NFS"
42+
GuestID filesystem.ID = "NFS"
43+
)
3044

3145
func (*Host) HostID() filesystem.Host { return HostID }
3246

@@ -76,3 +90,41 @@ func (nh *Host) Mount(fsys fs.FS) (io.Closer, error) {
7690
go func() { errsCh <- nfs.Serve(goListener, cachedHandler) }()
7791
return closerFn, nil
7892
}
93+
94+
func (*Guest) GuestID() filesystem.ID { return GuestID }
95+
func (gn *Guest) UnmarshalJSON(b []byte) error {
96+
// multiformats/go-multiaddr issue #100
97+
var maddrWorkaround struct {
98+
Maddr maddrc.Multiaddr `json:"maddr,omitempty"`
99+
}
100+
if err := json.Unmarshal(b, &maddrWorkaround); err != nil {
101+
return err
102+
}
103+
gn.Maddr = maddrWorkaround.Maddr.Multiaddr
104+
return json.Unmarshal(b, &struct {
105+
Hostname *string `json:"hostname,omitempty"`
106+
Dirpath *string `json:"dirpath,omitempty"`
107+
LinkSeparator *string `json:"linkSeparator,omitempty"`
108+
LinkLimit *uint `json:"linkLimit,omitempty"`
109+
UID *uint32 `json:"uid,omitempty"`
110+
GID *uint32 `json:"gid,omitempty"`
111+
}{
112+
Hostname: &gn.Hostname,
113+
Dirpath: &gn.Dirpath,
114+
LinkSeparator: &gn.LinkSeparator,
115+
LinkLimit: &gn.LinkLimit,
116+
UID: &gn.UID,
117+
GID: &gn.GID,
118+
})
119+
}
120+
121+
func (gn *Guest) MakeFS() (fs.FS, error) {
122+
return NewNFSGuest(gn.Maddr,
123+
WithHostname(gn.Hostname),
124+
WithDirpath(gn.Dirpath),
125+
WithLinkSeparator(gn.LinkSeparator),
126+
WithLinkLimit(gn.LinkLimit),
127+
WithUID(gn.UID),
128+
WithGID(gn.GID),
129+
)
130+
}

0 commit comments

Comments
 (0)