nfs

package
v0.0.0-...-1dc401f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package nfs implements a server to serve a VFS remote over NFSv3 protocol

There is no authentication available on this server and it is served on loopback interface by default.

This is primarily used for mounting a VFS remote in macOS, where FUSE-mounting mechanisms are usually not available.

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "nfs remote:path",
	Short: `Serve the remote as an NFS mount`,
	Long: `Create an NFS server that serves the given remote over the network.
	
The primary purpose for this command is to enable [mount command](/commands/rclone_mount/) on recent macOS versions where
installing FUSE is very cumbersome. 

Since this is running on NFSv3, no authentication method is available. Any client
will be able to access the data. To limit access, you can use serve NFS on loopback address
and rely on secure tunnels (such as SSH). For this reason, by default, a random TCP port is chosen and loopback interface is used for the listening address;
meaning that it is only available to the local machine. If you want other machines to access the
NFS mount over local network, you need to specify the listening address and port using ` + "`--addr`" + ` flag.

Modifying files through NFS protocol requires VFS caching. Usually you will need to specify ` + "`--vfs-cache-mode`" + `
in order to be able to write to the mountpoint (full is recommended). If you don't specify VFS cache mode,
the mount will be read-only. Note also that ` + "`--nfs-cache-handle-limit`" + ` controls the maximum number of cached file handles stored by the caching handler.
This should not be set too low or you may experience errors when trying to access files. The default is ` + "`1000000`" + `, but consider lowering this limit if
the server's system resource usage causes problems.

To serve NFS over the network use following command:

    rclone serve nfs remote: --addr 0.0.0.0:$PORT --vfs-cache-mode=full

We specify a specific port that we can use in the mount command:

To mount the server under Linux/macOS, use the following command:
    
    mount -oport=$PORT,mountport=$PORT $HOSTNAME: path/to/mountpoint

Where ` + "`$PORT`" + ` is the same port number we used in the serve nfs command.

This feature is only available on Unix platforms.

` + vfs.Help(),
	Annotations: map[string]string{
		"versionIntroduced": "v1.65",
		"groups":            "Filter",
		"status":            "Experimental",
	},
	Run: Run,
}

Command is the definition of the command

View Source
var OnUnmountFunc func()

OnUnmountFunc registers a function to call when externally unmounted

Functions

func AddFlags

func AddFlags(flagSet *pflag.FlagSet, Opt *Options)

AddFlags adds flags for serve nfs (and nfsmount)

func NewBackendAuthHandler

func NewBackendAuthHandler(vfs *vfs.VFS, opt *Options) nfs.Handler

NewBackendAuthHandler creates a handler for the provided filesystem

func Run

func Run(command *cobra.Command, args []string)

Run the command

Types

type BackendAuthHandler

type BackendAuthHandler struct {
	// contains filtered or unexported fields
}

BackendAuthHandler returns a NFS backing that exposes a given file system in response to all mount requests.

func (*BackendAuthHandler) Change

func (h *BackendAuthHandler) Change(fs billy.Filesystem) billy.Change

Change provides an interface for updating file attributes.

func (*BackendAuthHandler) FSStat

func (h *BackendAuthHandler) FSStat(ctx context.Context, f billy.Filesystem, s *nfs.FSStat) error

FSStat provides information about a filesystem.

func (*BackendAuthHandler) FromHandle

func (h *BackendAuthHandler) FromHandle(b []byte) (billy.Filesystem, []string, error)

FromHandle handled by CachingHandler

func (*BackendAuthHandler) HandleLimit

func (h *BackendAuthHandler) HandleLimit() int

HandleLimit handled by cachingHandler

func (*BackendAuthHandler) InvalidateHandle

func (h *BackendAuthHandler) InvalidateHandle(billy.Filesystem, []byte) error

InvalidateHandle is called on removes or renames

func (*BackendAuthHandler) Mount

func (h *BackendAuthHandler) Mount(ctx context.Context, conn net.Conn, req nfs.MountRequest) (status nfs.MountStatus, hndl billy.Filesystem, auths []nfs.AuthFlavor)

Mount backs Mount RPC Requests, allowing for access control policies.

func (*BackendAuthHandler) ToHandle

func (h *BackendAuthHandler) ToHandle(f billy.Filesystem, s []string) []byte

ToHandle handled by CachingHandler

type FS

type FS struct {
	// contains filtered or unexported fields
}

FS is our wrapper around the VFS to properly support billy.Filesystem interface

func (*FS) Capabilities

func (f *FS) Capabilities() billy.Capability

Capabilities exports the filesystem capabilities

func (*FS) Chmod

func (f *FS) Chmod(name string, mode os.FileMode) error

Chmod changes the file modes

func (*FS) Chown

func (f *FS) Chown(name string, uid, gid int) error

Chown changes owner of the file

func (*FS) Chroot

func (f *FS) Chroot(path string) (billy.Filesystem, error)

Chroot is not supported in VFS

func (*FS) Chtimes

func (f *FS) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes changes the acces time and modified time

func (*FS) Create

func (f *FS) Create(filename string) (billy.File, error)

Create implements creating new files

func (*FS) Join

func (f *FS) Join(elem ...string) string

Join joins path elements

func (*FS) Lchown

func (f *FS) Lchown(name string, uid, gid int) error

Lchown changes the owner of symlink

func (*FS) Lstat

func (f *FS) Lstat(filename string) (os.FileInfo, error)

Lstat gets the stats for symlink

func (*FS) MkdirAll

func (f *FS) MkdirAll(filename string, perm os.FileMode) error

MkdirAll creates a directory and all the ones above it it does not redirect to VFS.MkDirAll because that one doesn't honor the permissions

func (*FS) Open

func (f *FS) Open(filename string) (billy.File, error)

Open opens a file

func (*FS) OpenFile

func (f *FS) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error)

OpenFile opens a file

func (*FS) ReadDir

func (f *FS) ReadDir(path string) (dir []os.FileInfo, err error)

ReadDir implements read dir

func (f *FS) Readlink(link string) (string, error)

Readlink is not supported

func (*FS) Remove

func (f *FS) Remove(filename string) error

Remove deletes a file

func (*FS) Rename

func (f *FS) Rename(oldpath, newpath string) error

Rename renames a file

func (*FS) Root

func (f *FS) Root() string

Root returns the root of a VFS

func (*FS) Stat

func (f *FS) Stat(filename string) (os.FileInfo, error)

Stat gets the file stat

func (f *FS) Symlink(target, link string) error

Symlink is not supported over NFS

func (*FS) TempFile

func (f *FS) TempFile(dir, prefix string) (billy.File, error)

TempFile is not implemented

type LogIntercepter

type LogIntercepter struct {
	Level nfs.LogLevel
}

LogIntercepter intercepts noisy go-nfs logs and reroutes them to DEBUG

func (*LogIntercepter) Debug

func (l *LogIntercepter) Debug(args ...interface{})

Debug reroutes go-nfs Debug messages to Intercept

func (*LogIntercepter) Debugf

func (l *LogIntercepter) Debugf(format string, args ...interface{})

Debugf reroutes go-nfs Debugf messages to Interceptf

func (*LogIntercepter) Error

func (l *LogIntercepter) Error(args ...interface{})

Error reroutes go-nfs Error messages to Intercept

func (*LogIntercepter) Errorf

func (l *LogIntercepter) Errorf(format string, args ...interface{})

Errorf reroutes go-nfs Errorf messages to Interceptf

func (*LogIntercepter) Fatal

func (l *LogIntercepter) Fatal(args ...interface{})

Fatal reroutes go-nfs Fatal messages to Intercept

func (*LogIntercepter) Fatalf

func (l *LogIntercepter) Fatalf(format string, args ...interface{})

Fatalf reroutes go-nfs Fatalf messages to Interceptf

func (*LogIntercepter) GetLevel

func (l *LogIntercepter) GetLevel() nfs.LogLevel

GetLevel returns the nfs.LogLevel

func (*LogIntercepter) Info

func (l *LogIntercepter) Info(args ...interface{})

Info reroutes go-nfs Info messages to Intercept

func (*LogIntercepter) Infof

func (l *LogIntercepter) Infof(format string, args ...interface{})

Infof reroutes go-nfs Infof messages to Interceptf

func (*LogIntercepter) Intercept

func (l *LogIntercepter) Intercept(args ...interface{})

Intercept intercepts go-nfs logs and calls fs.Debugf instead

func (*LogIntercepter) Interceptf

func (l *LogIntercepter) Interceptf(format string, args ...interface{})

Interceptf intercepts go-nfs logs and calls fs.Debugf instead

func (*LogIntercepter) Panic

func (l *LogIntercepter) Panic(args ...interface{})

Panic reroutes go-nfs Panic messages to Intercept

func (*LogIntercepter) Panicf

func (l *LogIntercepter) Panicf(format string, args ...interface{})

Panicf reroutes go-nfs Panicf messages to Interceptf

func (*LogIntercepter) ParseLevel

func (l *LogIntercepter) ParseLevel(level string) (nfs.LogLevel, error)

ParseLevel parses the nfs.LogLevel

func (*LogIntercepter) Print

func (l *LogIntercepter) Print(args ...interface{})

Print reroutes go-nfs Print messages to Intercept

func (*LogIntercepter) Printf

func (l *LogIntercepter) Printf(format string, args ...interface{})

Printf reroutes go-nfs Printf messages to Intercept

func (*LogIntercepter) SetLevel

func (l *LogIntercepter) SetLevel(level nfs.LogLevel)

SetLevel sets the nfs.LogLevel

func (*LogIntercepter) Trace

func (l *LogIntercepter) Trace(args ...interface{})

Trace reroutes go-nfs Trace messages to Intercept

func (*LogIntercepter) Tracef

func (l *LogIntercepter) Tracef(format string, args ...interface{})

Tracef reroutes go-nfs Tracef messages to Interceptf

func (*LogIntercepter) Warn

func (l *LogIntercepter) Warn(args ...interface{})

Warn reroutes go-nfs Warn messages to Intercept

func (*LogIntercepter) Warnf

func (l *LogIntercepter) Warnf(format string, args ...interface{})

Warnf reroutes go-nfs Warnf messages to Interceptf

type Options

type Options struct {
	ListenAddr  string // Port to listen on
	HandleLimit int    // max file handles cached by go-nfs CachingHandler
}

Options contains options for the NFS Server

func (*Options) Limit

func (o *Options) Limit() int

Limit overrides the --nfs-cache-handle-limit value if out-of-range

type Server

type Server struct {
	UnmountedExternally bool
	// contains filtered or unexported fields
}

Server contains everything to run the Server

func NewServer

func NewServer(ctx context.Context, vfs *vfs.VFS, opt *Options) (s *Server, err error)

NewServer creates a new server

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns the listening address of the server

func (*Server) Serve

func (s *Server) Serve() (err error)

Serve starts the server

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown stops the server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL