nfsmgr

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package nfsmgr provides NFS (Network File System) management capabilities.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSupported = errors.New("NFS management is not supported on this platform")
	ErrNoEntry      = errors.New("NFS entry not found")
)

Functions

func AddFstabEntry

func AddFstabEntry(entry *MountEntry) error

AddFstabEntry adds an NFS mount entry to /etc/fstab. No-op if mount point already exists in fstab.

func FormatExportClient

func FormatExportClient(c *ExportClient) string

FormatExportClient formats a client spec for display.

func RemoveFstabEntry

func RemoveFstabEntry(mountPoint string) error

RemoveFstabEntry removes an NFS entry from /etc/fstab by mount point. Uses atomic write (temp file + rename).

Types

type Client

type Client interface {
	// Export management
	ListExports(ctx context.Context) ([]*ExportEntry, error)
	WriteExports(ctx context.Context, entries []*ExportEntry) error
	ReloadExports(ctx context.Context) error

	// Mount management
	ListMounts(ctx context.Context) ([]*MountEntry, error)
	Mount(ctx context.Context, entry *MountEntry) error
	Unmount(ctx context.Context, mountPoint string) error

	// Server status
	ServerStatus(ctx context.Context) (*NFSStatus, error)

	// Quota management
	ListQuota(ctx context.Context) ([]*QuotaReport, error)
	SetQuota(ctx context.Context, limit *QuotaLimit) error
}

Client defines the interface for NFS management operations.

func NewClient

func NewClient() (Client, error)

NewClient creates an NFS management client for the current platform. On non-Linux platforms it returns ErrNotSupported.

type ExportClient

type ExportClient struct {
	Host    string   `json:"host"`    // Client IP/network/hostname, e.g. "192.168.1.0/24" or "*"
	Options []string `json:"options"` // Per-client options, e.g. ["rw", "no_root_squash"]
}

ExportClient represents a client/host allowed to access an NFS export.

type ExportEntry

type ExportEntry struct {
	Path    string         `json:"path"`    // Export path, e.g. "/data"
	Clients []ExportClient `json:"clients"` // Clients allowed to access
	Comment string         `json:"comment,omitempty"`
}

ExportEntry represents a single export entry in /etc/exports.

type MountEntry

type MountEntry struct {
	Server     string   `json:"server"`     // NFS server address
	Remote     string   `json:"remote"`     // Remote export path
	MountPoint string   `json:"mountPoint"` // Local mount point
	Type       string   `json:"type"`       // "nfs" or "nfs4"
	Options    []string `json:"options"`    // Mount options
	ReadOnly   bool     `json:"readOnly"`   // Whether mount is read-only
}

MountEntry represents a mounted NFS share.

type NFSStatus

type NFSStatus struct {
	Running  bool   `json:"running"`
	Enabled  bool   `json:"enabled"`
	Active   string `json:"active"`   // systemd active state
	SubState string `json:"subState"` // systemd sub state
}

NFSStatus represents the NFS server service status.

type QuotaEntry

type QuotaEntry struct {
	User       string `json:"user"`
	BlockUsed  uint64 `json:"blockUsed"`
	BlockSoft  uint64 `json:"blockSoft"`
	BlockHard  uint64 `json:"blockHard"`
	BlockGrace string `json:"blockGrace,omitempty"`
	InodeUsed  uint64 `json:"inodeUsed"`
	InodeSoft  uint64 `json:"inodeSoft"`
	InodeHard  uint64 `json:"inodeHard"`
	InodeGrace string `json:"inodeGrace,omitempty"`
	Status     string `json:"status"`
}

QuotaEntry represents a single user quota entry from repquota.

func (*QuotaEntry) BlockAvail

func (e *QuotaEntry) BlockAvail() uint64

BlockAvail returns available blocks before hitting hard limit.

func (*QuotaEntry) BlockPercent

func (e *QuotaEntry) BlockPercent() int

BlockPercent returns usage percentage of hard block limit (0-100).

func (*QuotaEntry) InodeAvail

func (e *QuotaEntry) InodeAvail() uint64

InodeAvail returns available inodes before hitting hard limit.

func (*QuotaEntry) InodePercent

func (e *QuotaEntry) InodePercent() int

InodePercent returns usage percentage of hard inode limit (0-100).

type QuotaLimit

type QuotaLimit struct {
	User       string `json:"user"`       // Username
	MountPoint string `json:"mountPoint"` // Mount point or device path
	BlockSoft  uint64 `json:"blockSoft"`  // Soft limit for blocks (1KB units, 0=unlimited)
	BlockHard  uint64 `json:"blockHard"`  // Hard limit for blocks
	InodeSoft  uint64 `json:"inodeSoft"`  // Soft limit for inodes
	InodeHard  uint64 `json:"inodeHard"`  // Hard limit for inodes
}

QuotaLimit defines quota limits to apply via setquota.

type QuotaReport

type QuotaReport struct {
	Device  string        `json:"device"`
	Entries []*QuotaEntry `json:"entries"`
}

QuotaReport contains quota info for one device.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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