nfsserver

package
v0.41.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package nfsserver serves knot's file storage over NFSv4.0 and NFSv3, so buckets can be mounted by the operating system (the macOS Finder or mount_nfs) and by Docker and Podman as volumes with the local driver's nfs type, without FUSE. It is a client of a knot server's files API, acting as the user whose token it is given, so any number can run against one knot server.

NFS itself carries no authentication, so the server only accepts connections from the addresses it is told to trust: loopback by default.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Buckets(ctx context.Context) ([]Bucket, error)
	Bucket(ctx context.Context, name string) (*Bucket, error)
	CreateBucket(ctx context.Context, name string) error
	DeleteBucket(ctx context.Context, name string) error

	Head(ctx context.Context, bucket, key string) (*Object, error)
	// Stat says what a path is in one request: a file, or a folder, with
	// its marker (the object keeping an empty folder) when it has one. A
	// path that is neither is os.ErrNotExist.
	Stat(ctx context.Context, bucket, key string) (*Stat, error)
	// List lists a folder; with a delimiter, Listing.Markers holds the
	// markers of the folders rolled up into Prefixes.
	List(ctx context.Context, bucket, prefix, delimiter, after string, max int) (*Listing, error)
	// ReadAt reads part of a file, returning io.EOF with what there is at
	// its end.
	ReadAt(ctx context.Context, bucket, key string, p []byte, off int64) (int, error)
	// Get reads a whole file.
	Get(ctx context.Context, bucket, key string) (io.ReadCloser, *Object, error)
	Put(ctx context.Context, bucket, key string, r io.Reader, size int64, contentType string, meta map[string]string) (*Object, error)
	// Patch changes part of a file, sending only the ranges: they are
	// written over it, in order and not overlapping, and it is cut or
	// zero-filled to size. With ifMatch, only if it still has that ETag.
	Patch(ctx context.Context, bucket, key string, ranges []Range, size int64, ifMatch, contentType string, meta map[string]string) (*Object, error)
	Delete(ctx context.Context, bucket, key string) error
	// SetMeta replaces a file's metadata, if it still has the ETag ifMatch.
	SetMeta(ctx context.Context, bucket, key string, meta map[string]string, ifMatch string) error
	// Move renames a file, or a folder and everything under it, replacing
	// what is at the destination.
	Move(ctx context.Context, bucket, from, to string) error
	// Forget drops anything kept of a file changed elsewhere; an empty key
	// means every file in the bucket, and an empty bucket every bucket.
	Forget(bucket, key string)
}

Backend is the file storage the filesystem serves. Errors are matched with errors.Is against os.ErrNotExist, os.ErrExist, os.ErrPermission, syscall.ENOTEMPTY, syscall.EDQUOT, syscall.EINVAL and errPrecondition.

Buckets are named as the user sees them: the short name for their own, the full name for those shared with them.

func NewAPIBackend

func NewAPIBackend(client *apiclient.ApiClient) Backend

NewAPIBackend serves file storage through client.

type Bucket

type Bucket struct {
	Name      string
	Id        string
	Writable  bool
	CreatedAt time.Time
}

type Config

type Config struct {
	Listen      string        // address to listen on, e.g. 127.0.0.1:2049
	Allow       []string      // client addresses or CIDRs allowed to connect; loopback when empty
	FlushDelay  time.Duration // save a written file once writes stop for this long
	MaxDirtyAge time.Duration // and at the latest this long after it changed
	StagingDir  string        // where written files wait to be saved; a temp dir when empty
	Uid, Gid    uint32        // owner of files with none stored

	// ForceUid and ForceGid make Uid and Gid the owner of every file,
	// whatever owner is stored, so files look the mounting user's own
	// (a container's root, say). An owner set is still stored.
	ForceUid, ForceGid bool

	// CacheDir keeps files read and written on local disk, up to CacheSize
	// bytes, so they need not be fetched again; none when empty.
	CacheDir  string
	CacheSize int64

	// Writer is the name this server's backend gives the changes it makes
	// (apiclient.ApiClient.SetWriter), so it can pass over its own.
	Writer string
}

type FileChanged

type FileChanged struct {
	BucketId, Key, Writer string
}

FileChanged is a file named in a change event, and the writer that changed it, when it said.

type Listing

type Listing struct {
	Objects   []*Object
	Prefixes  []string
	Markers   map[string]*Object // by prefix
	Truncated bool
	Next      string
}

type Object

type Object struct {
	Key         string
	Size        int64
	ETag        string
	SHA256      string
	ContentType string
	ModifiedAt  time.Time
	Meta        map[string]string
}

type Range

type Range struct {
	Offset, Length int64
	Data           io.Reader
}

Range is part of a file to write.

type Server

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

func Start

func Start(backend Backend, cfg Config) (*Server, error)

Start serves file storage from backend over NFS until Close.

func (*Server) Addr

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

Addr is the address the server listens on.

func (*Server) Changed

func (s *Server) Changed(bucketIds []string, files []FileChanged)

Changed tells of changes to the buckets with these ids, made through this server or anywhere else, naming the files where it can; no buckets means any bucket.

func (*Server) Close

func (s *Server) Close() error

Close stops accepting connections and saves every file still being written. Connections already open are not interrupted.

func (*Server) Live

func (s *Server) Live(live bool)

Live says whether the knot server is telling of file changes through Changed; while it is, what is known of files is kept for longer.

type Stat

type Stat struct {
	File   *Object
	Folder bool
	Marker *Object
}

Stat is what a path is.

Jump to

Keyboard shortcuts

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