Skip to content

Commit 8cb5490

Browse files
committed
Add support for mount export for fuse-nfs
It wants to list the exported file systems, for mount. But currently the nullauth ignores the dirpath anyway. Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
1 parent 7070f5a commit 8cb5490

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

handler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ type Handler interface {
2020

2121
// Optional methods - generic helpers or trivial implementations can be sufficient depending on use case.
2222

23+
// List of all exported file systems.
24+
Export(context.Context) []Export
25+
2326
// Fill in information about a file system's free space.
2427
FSStat(context.Context, billy.Filesystem, *FSStat) error
2528

helpers/nullauthhandler.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type NullAuthHandler struct {
2020

2121
// Mount backs Mount RPC Requests, allowing for access control policies.
2222
func (h *NullAuthHandler) Mount(ctx context.Context, conn net.Conn, req nfs.MountRequest) (status nfs.MountStatus, hndl billy.Filesystem, auths []nfs.AuthFlavor) {
23+
_ = req.Dirpath
2324
status = nfs.MountStatusOk
2425
hndl = h.fs
2526
auths = []nfs.AuthFlavor{nfs.AuthFlavorNull}
@@ -34,6 +35,12 @@ func (h *NullAuthHandler) Change(fs billy.Filesystem) billy.Change {
3435
return nil
3536
}
3637

38+
// List of all exported file systems.
39+
func (h *NullAuthHandler) Export(context.Context) []nfs.Export {
40+
groups := []nfs.Group{{Name: []byte("anonymous")}}
41+
return []nfs.Export{{Dir: []byte("/mount"), Groups: groups}}
42+
}
43+
3744
// FSStat provides information about a filesystem.
3845
func (h *NullAuthHandler) FSStat(ctx context.Context, f billy.Filesystem, s *nfs.FSStat) error {
3946
return nil

mount.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func init() {
1515
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcNull), onMountNull)
1616
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcMount), onMount)
1717
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcUmnt), onUMount)
18+
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcExport), onMountExport)
1819
}
1920

2021
func onMountNull(ctx context.Context, w *response, userHandle Handler) error {
@@ -56,3 +57,18 @@ func onUMount(ctx context.Context, w *response, userHandle Handler) error {
5657

5758
return w.writeHeader(ResponseCodeSuccess)
5859
}
60+
61+
func onMountExport(ctx context.Context, w *response, userHandle Handler) error {
62+
exports := userHandle.Export(ctx)
63+
64+
if err := w.writeHeader(ResponseCodeSuccess); err != nil {
65+
return err
66+
}
67+
68+
writer := bytes.NewBuffer([]byte{})
69+
70+
if err := xdr.Write(writer, exports); err != nil {
71+
return err
72+
}
73+
return w.Write(writer.Bytes())
74+
}

mountinterface.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,16 @@ type MountResponse struct {
8888
FileHandle
8989
AuthFlavors []int
9090
}
91+
92+
// Group contains a group node, with information about the allowed access group.
93+
type Group struct {
94+
Name []byte
95+
Next []Group
96+
}
97+
98+
// Export contains an export node, with information about an exported filesystem.
99+
type Export struct {
100+
Dir []byte
101+
Groups []Group
102+
Next []Export
103+
}

0 commit comments

Comments
 (0)