xfsquota

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: MIT Imports: 12 Imported by: 0

README

go-xfsquota

A golang wrapper library for xfs_quota commandline tool.

Overview

Please note that this library will NOT work with Go binaries alone.

This library executes xfs_quota binary via the os/exec package. Therefore, the xfs_quota binary must be deployed in the environment where this library is used.

Note also that a child process is created when exec binary.

Installation

Installation can be done with a normal go get:

go get github.com/ry023/go-xfsquota

And, import package on your Go code.

import xfsquota "github.com/ry023/go-xfsquota"

Usage

Please see also examples/

Documentation

Index

Constants

View Source
const (
	ProjectDirTreeSetupOps = ProjectOpsType("Setup")
	ProjectDirTreeClearOps = ProjectOpsType("Clear")
	ProjectDirTreeCheckOps = ProjectOpsType("Check")
)
View Source
const (
	QuotaTypeGroup   = QuotaType("Group")
	QuotaTypeProject = QuotaType("Project")
	QuotaTypeUser    = QuotaType("User")
)
View Source
const (
	QuotaTargetTypeBlocks   = QuotaTargetType("Blocks")
	QuotaTargetTypeInodes   = QuotaTargetType("Inodes")
	QuotaTargetTypeRealtime = QuotaTargetType("Realtime")
)
View Source
const DefaultVersionConstraint = ">= 5.13.0"

Variables

View Source
var DefaultVersionCommandRegexp = regexp.MustCompile(`xfs_quota version\s(.*)\r?\n?$`)
View Source
var ProjectCheckRegexp = regexp.MustCompile(`^(.*) - project inheritance flag is not set`)
View Source
var ProjectIdNotSetRegexp = regexp.MustCompile(`^(.*) - project identifier is not set`)
View Source
var ProjectInheritanceFlagNotSetRegexp = regexp.MustCompile(`^(.*) - project inheritance flag is not set`)

Functions

This section is empty.

Types

type Binary added in v0.1.0

type Binary struct {
	// The path to xfs_quota binary
	Path string
}

func (*Binary) Execute added in v0.1.0

func (b *Binary) Execute(ctx context.Context, stdout io.Writer, stderr io.Writer, args ...string) error

func (*Binary) Validate added in v0.1.0

func (b *Binary) Validate() error

type BinaryExecuter

type BinaryExecuter interface {
	Execute(ctx context.Context, stdout io.Writer, stderr io.Writer, args ...string) error
	Validate() error
}

type Client added in v0.1.0

type Client struct {
	// xfs_quota binary
	Binary BinaryExecuter
	// xfs_quota will only run if it satisfies the constraints of this version.
	VersionConstraint string
	// Ignore version checking if true. (Default is false)
	IgnoreVersionConstraint bool
	// Regexp used for parsing stdout of version command. (DefaultVersionCommandRegexp is used normally)
	VersionCommandRegexp *regexp.Regexp
}

xfs_quota wrapper client.

func New added in v0.1.0

func New(binaryPath string) (*Client, error)

func (*Client) Command added in v0.1.0

func (c *Client) Command(filesystemPath string, opt *GlobalOption) Commander

func (*Client) GetBinaryVersion added in v0.1.0

func (c *Client) GetBinaryVersion() (string, error)

type Command

type Command struct {
	GlobalOpt GlobalOption
	Stdout    io.Writer
	Stderr    io.Writer
	Binary    BinaryExecuter

	// The path argument can be used to specify mount points or device files which identify XFS filesystems. The output of the individual xfs_quota commands will then be restricted to the set of filesystems specified.
	// NOTE: This argument is optional on original xfs_quota but required on current go-xfsquota-wrapper version.
	FileSystemPath string
	// contains filtered or unexported fields
}

func NewCommand

func NewCommand(binary BinaryExecuter, filesystemPath string, globalOpt *GlobalOption) *Command

func (*Command) CheckDirectoryTree added in v0.1.0

func (c *Command) CheckDirectoryTree(ctx context.Context, projid uint32, opt ProjectCommandOption) error

func (*Command) ClearDirectoryTree added in v0.1.0

func (c *Command) ClearDirectoryTree(ctx context.Context, projid uint32, opt ProjectCommandOption) error

func (*Command) Execute

func (c *Command) Execute(ctx context.Context) error

func (*Command) LimitWithId

func (c *Command) LimitWithId(ctx context.Context, id uint32, quotaType QuotaType, opt LimitCommandOption) error

func (*Command) LimitWithName

func (c *Command) LimitWithName(ctx context.Context, name string, quotaType QuotaType, opt LimitCommandOption) error

func (*Command) OperateDirectoryTree added in v0.1.0

func (c *Command) OperateDirectoryTree(ctx context.Context, op ProjectOpsType, id uint32, opt ProjectCommandOption) error

func (*Command) Report

func (c *Command) Report(ctx context.Context, quotaType QuotaType, quotaTargetType QuotaTargetType, opt ReportCommandOption) (*ReportResult, error)

func (*Command) SetupDirectoryTree added in v0.1.0

func (c *Command) SetupDirectoryTree(ctx context.Context, projid uint32, opt ProjectCommandOption) error

type Commander

type Commander interface {
	Execute(ctx context.Context) error
	OperateDirectoryTree(ctx context.Context, op ProjectOpsType, id uint32, opt ProjectCommandOption) error

	LimitCommander
	ReportCommander
	ProjectCommander
}

type GlobalOption

type GlobalOption struct {
	// Equeal to "-p" flag on commandline.
	// Set the program name for prompts and some error messages, the default value is xfs_quota.
	ProgramName string
	// Equeal to "-x" flag on commandline.
	// Enable expert mode. All of the administrative commands which allow modifications to the quota system are available only in expert mode.
	EnableExpertMode bool
	// Equeal to "-d" flag on commandline.
	// Project names or numeric identifiers may be specified with this option, which restricts the output of the individual xfs_quota commands to the set of projects specified.
	Projects []string
}

type LimitCommandOption

type LimitCommandOption struct {
	// Equal to `bsoft=N` (N > 0) argument on commandline.
	// Set quota block soft limits.
	Bsoft uint32
	// Equal to `bhard=N` (N > 0) argument on commandline.
	// Set quota block hard limits.
	Bhard uint32
	// Equal to `isoft=N` argument on commandline.
	// Set quota inode count soft limits.
	Isoft uint32
	// Equal to `ihard=N` (N > 0) argument on commandline.
	// Set quota inode count hard limits.
	Ihard uint32
	// Equal to `rtbsoft=N` (N > 0) argument on commandline.
	// Set quota realtime block soft limits.
	Rtbsoft uint32
	// Equal to `rtbhard=N` (N > 0) argument on commandline.
	// Set quota realtime block hard limits.
	Rtbhard uint32
	// Equal to `bsoft=0` (N > 0)  argument on commandline.
	// Reset quota block soft limits.
	ResetBsoft bool
	// Equal to `bhard=0` argument on commandline.
	// Reset quota block hard limits.
	ResetBhard bool
	// Equal to `isoft=0` argument on commandline.
	// Reset quota inode count soft limits.
	ResetIsoft bool
	// Equal to `ihard=0` argument on commandline.
	// Reset quota inode count hard limits.
	ResetIhard bool
	// Equal to `rtbsoft=0` argument on commandline.
	// Reset quota realtime block soft limits.
	ResetRtbsoft bool
	// Equal to `rtbhard=0` argument on commandline.
	// Reset quota realtime block hard limits.
	ResetRtbhard bool
}

type LimitCommander

type LimitCommander interface {
	LimitWithId(ctx context.Context, id uint32, quotaType QuotaType, opt LimitCommandOption) error
	LimitWithName(ctx context.Context, name string, quotaType QuotaType, opt LimitCommandOption) error
}

type ProjectCheckError

type ProjectCheckError struct {
	Errors []error
}

func (*ProjectCheckError) Error

func (e *ProjectCheckError) Error() string

type ProjectCommandOption

type ProjectCommandOption struct {
	// Equeal to "-d" flag on commandline.
	// This option allows to limit recursion level when processing project directories
	Depth uint32
	// Equeal to "-p" flag on commandline.
	// This option allows to specify project paths at command line ( instead of /etc/projects ).
	Path string
}

type ProjectCommander

type ProjectCommander interface {
	// SetupDirectoryTree setup directory tree to project identified by projid.
	// Equeal to "project" subcommand with "-s" flag
	SetupDirectoryTree(ctx context.Context, projid uint32, opt ProjectCommandOption) error
	// ClearDirectoryTree clear directory tree to project identified by projid.
	// Equeal to "project" subcommand with "-C" flag
	ClearDirectoryTree(ctx context.Context, projid uint32, opt ProjectCommandOption) error
	// CheckDirectoryTree check directory tree to project identified by projid.
	// Equeal to "project" subcommand with "-c" flag
	CheckDirectoryTree(ctx context.Context, projid uint32, opt ProjectCommandOption) error
}

type ProjectIdNotSetError

type ProjectIdNotSetError struct {
	Directory string
}

func (*ProjectIdNotSetError) Error

func (e *ProjectIdNotSetError) Error() string

type ProjectInheritanceFlagNotSetError

type ProjectInheritanceFlagNotSetError struct {
	Directory string
}

func (*ProjectInheritanceFlagNotSetError) Error

type ProjectOpsType

type ProjectOpsType string

Equeal to "-sCc" flag on commandline.

type QuotaTargetType

type QuotaTargetType string

func (QuotaTargetType) Flag

func (t QuotaTargetType) Flag() string

type QuotaType

type QuotaType string

func (QuotaType) Flag

func (t QuotaType) Flag() string

type ReportCommandOption

type ReportCommandOption struct {
	// Equal to `-L` flag on commandline.
	// lower ID bounds to report on
	LowerId uint32
	// Equal to `-U` flag on commandline.
	// upper ID bounds to report on
	UpperId uint32
}

type ReportCommander

type ReportCommander interface {
	Report(ctx context.Context, quotaType QuotaType, quotaTargetType QuotaTargetType, opt ReportCommandOption) (*ReportResult, error)
}

type ReportResult

type ReportResult struct {
	ReportSets []ReportSet
}

type ReportSet

type ReportSet struct {
	QuotaType       QuotaType
	QuotaTargetType QuotaTargetType
	MountPath       string
	DevicePath      string
	ReportValues    []ReportValue
}

type ReportValue

type ReportValue struct {
	Id    uint32
	Used  uint32
	Soft  uint32
	Hard  uint32
	Grace uint32
}

Directories

Path Synopsis
testutil
cmd

Jump to

Keyboard shortcuts

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