Skip to content

Add support for mount export for fuse-nfs #140

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ type Handler interface {

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

// List of all exported file systems.
Export(context.Context) []Export

// Fill in information about a file system's free space.
FSStat(context.Context, billy.Filesystem, *FSStat) error

Expand Down
5 changes: 5 additions & 0 deletions helpers/nullauthhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ func (h *NullAuthHandler) Change(fs billy.Filesystem) billy.Change {
return nil
}

// List of all exported file systems.
func (h *NullAuthHandler) Export(context.Context) []nfs.Export {
return []nfs.Export{{Dir: []byte("/mount")}}
}

// FSStat provides information about a filesystem.
func (h *NullAuthHandler) FSStat(ctx context.Context, f billy.Filesystem, s *nfs.FSStat) error {
return nil
Expand Down
16 changes: 16 additions & 0 deletions mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func init() {
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcNull), onMountNull)
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcMount), onMount)
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcUmnt), onUMount)
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcExport), onMountExport)
}

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

return w.writeHeader(ResponseCodeSuccess)
}

func onMountExport(ctx context.Context, w *response, userHandle Handler) error {
exports := userHandle.Export(ctx)

if err := w.writeHeader(ResponseCodeSuccess); err != nil {
return err
}

writer := bytes.NewBuffer([]byte{})

if err := xdr.Write(writer, exports); err != nil {
return err
}
return w.Write(writer.Bytes())
}
13 changes: 13 additions & 0 deletions mountinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,16 @@ type MountResponse struct {
FileHandle
AuthFlavors []int
}

// Group contains a group node, with information about the allowed access group.
type Group struct {
Name []byte
Next []Group
}

// Export contains an export node, with information about an exported filesystem.
type Export struct {
Dir []byte
Groups []Group
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is *Group rather than []Group - in that it is either nil or the next group in a linked list, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, but the Go wrapper "helpfully" dereferences all pointers - so we declare it as an array instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are documented as equivalent in XDR: https://datatracker.ietf.org/doc/html/rfc1014#section-3.18

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern in the rest of this library has been to write the individual fields with the extra 0 to signify the end of the list

e.g. https://github.com/willscott/go-nfs/blob/master/nfs_onreaddir.go#L116

while this is more fiddly, it makes the type 'logically correct', so that the caller doesn't have to understand the nuance.

Next []Export
}