ploop

package module
v0.0.0-...-44c2656 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2015 License: Apache-2.0 Imports: 6 Imported by: 1

README

goploop GoDoc

This is a Go wrapper for libploop, a C library to manage ploop.

What is ploop?

Ploop is a loopback block device (a.k.a. "filesystem in a file"), not unlike loop but with better performance and more features, including:

  • thin provisioning (image grows on demand)
  • dynamic resize (both grow and shrink)
  • instant online snapshots
  • online snapshot merge
  • optimized image migration with write tracker (ploop copy)

Ploop is implemented in the kernel and is currently available in OpenVZ RHEL6 and RHEL7 based kernels. For more information about ploop, see openvz.org/Ploop.

Prerequisites

You need to have

  • ext4 formatted partition (note RHEL/CentOS 7 installer uses xfs by default, that won't work!)
  • ploop-enabled kernel installed
  • ploop kernel modules loaded
  • ploop-lib and ploop-devel packages installed

Currently, all the above comes with OpenVZ, please see openvz.org/Quick_installation. After installing OpenVZ, you might need to run:

yum install ploop-devel

Building

If you are going to build a binary that uses this package statically, you need to add static_build build tag to your go build command, such as:

go build -tags static_build

Usage

This package is used by Docker ploop graphdriver, see https://github.com/kolyshkin/docker/tree/ploop/daemon/graphdriver/ploop

For primitive examples of how to use the package, see ploop_test.go.

Documentation

Index

Constants

View Source
const (
	NoConsole  = C.PLOOP_LOG_NOCONSOLE
	NoStdout   = C.PLOOP_LOG_NOSTDOUT
	Timestamps = C.PLOOP_LOG_TIMESTAMPS
)

Possible SetVerboseLevel arguments

View Source
const (
	E_CREAT
	E_DEVICE
	E_DEVIOC
	E_OPEN
	E_MALLOC
	E_READ
	E_WRITE
	E_RESERVED_8
	E_SYSFS
	E_RESERVED_10
	E_PLOOPFMT
	E_SYS
	E_PROTOCOL
	E_LOOP
	E_FSTAT
	E_FSYNC
	E_EBUSY
	E_FLOCK
	E_FTRUNCATE
	E_FALLOCATE
	E_MOUNT
	E_UMOUNT
	E_LOCK
	E_MKFS
	E_RESERVED_25
	E_RESIZE_FS
	E_MKDIR
	E_RENAME
	E_ABORT
	E_RELOC
	E_RESERVED_31
	E_RESERVED_32
	E_CHANGE_GPT
	E_RESERVED_34
	E_UNLINK
	E_MKNOD
	E_PLOOPINUSE
	E_PARAM
	E_DISKDESCR
	E_DEV_NOT_MOUNTED
	E_FSCK
	E_RESERVED_42
	E_NOSNAP
)

SYSEXIT_* errors

Variables

View Source
var ErrCodes = []string{
	E_CREAT:           "E_CREAT",
	E_DEVICE:          "E_DEVICE",
	E_DEVIOC:          "E_DEVIOC",
	E_OPEN:            "E_OPEN",
	E_MALLOC:          "E_MALLOC",
	E_READ:            "E_READ",
	E_WRITE:           "E_WRITE",
	E_RESERVED_8:      "E_RESERVED",
	E_SYSFS:           "E_SYSFS",
	E_RESERVED_10:     "E_RESERVED",
	E_PLOOPFMT:        "E_PLOOPFMT",
	E_SYS:             "E_SYS",
	E_PROTOCOL:        "E_PROTOCOL",
	E_LOOP:            "E_LOOP",
	E_FSTAT:           "E_FSTAT",
	E_FSYNC:           "E_FSYNC",
	E_EBUSY:           "E_EBUSY",
	E_FLOCK:           "E_FLOCK",
	E_FTRUNCATE:       "E_FTRUNCATE",
	E_FALLOCATE:       "E_FALLOCATE",
	E_MOUNT:           "E_MOUNT",
	E_UMOUNT:          "E_UMOUNT",
	E_LOCK:            "E_LOCK",
	E_MKFS:            "E_MKFS",
	E_RESERVED_25:     "E_RESERVED",
	E_RESIZE_FS:       "E_RESIZE_FS",
	E_MKDIR:           "E_MKDIR",
	E_RENAME:          "E_RENAME",
	E_ABORT:           "E_ABORT",
	E_RELOC:           "E_RELOC",
	E_RESERVED_31:     "E_RESERVED",
	E_RESERVED_32:     "E_RESERVED",
	E_CHANGE_GPT:      "E_CHANGE_GPT",
	E_RESERVED_34:     "E_RESERVED",
	E_UNLINK:          "E_UNLINK",
	E_MKNOD:           "E_MKNOD",
	E_PLOOPINUSE:      "E_PLOOPINUSE",
	E_PARAM:           "E_PARAM",
	E_DISKDESCR:       "E_DISKDESCR",
	E_DEV_NOT_MOUNTED: "E_DEV_NOT_MOUNTED",
	E_FSCK:            "E_FSCK",
	E_RESERVED_42:     "E_RESERVED",
	E_NOSNAP:          "E_NOSNAP",
}

ErrCodes is a map of ploop numerical error codes to their short names

Functions

func Create

func Create(p *CreateParam) error

Create creates a ploop image and its DiskDescriptor.xml

func IsError

func IsError(err error, code int) bool

IsError checks if an error is a specific ploop error

func IsNotMounted

func IsNotMounted(err error) bool

IsNotMounted returns true if an error is ploop "device is not mounted"

func SetLogFile

func SetLogFile(file string) error

SetLogFile enables logging to a file and sets log file name

func SetLogLevel

func SetLogLevel(v int)

SetLogLevel sets a level of verbosity when logging to a file

func SetVerboseLevel

func SetVerboseLevel(v int)

SetVerboseLevel sets a level of verbosity when logging to stdout/stderr

func UUID

func UUID() (string, error)

UUID generates a ploop UUID

func UmountByDevice

func UmountByDevice(dev string) error

UmountByDevice unmounts the ploop filesystem and dismantles the device. Unlike Umount(), this is a lower-level function meaning it can be less safe and should generally not be used.

Types

type CreateFlags

type CreateFlags uint

CreateFlags is a type for CreateParam.Flags

const (
	NoLazy CreateFlags = C.PLOOP_CREATE_NOLAZY
)

Possible values for CreateFlags

type CreateParam

type CreateParam struct {
	Size  uint64      // image size, in kilobytes (FS size is about 10% smaller)
	Mode  ImageMode   // image mode
	File  string      // path to and a file name for base delta image
	CLog  uint        // cluster block size log (6 to 15, default 11)
	Flags CreateFlags // flags
}

CreateParam is a set of parameters for a newly created ploop

type Err

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

Err contains a ploop error

func (*Err) Error

func (e *Err) Error() string

Error returns a string representation of a ploop error

type FSInfoData

type FSInfoData struct {
	BlockSize  uint64
	Blocks     uint64
	BlocksFree uint64
	Inodes     uint64
	InodesFree uint64
}

FSInfoData holds information about ploop inner file system

func FSInfo

func FSInfo(file string) (FSInfoData, error)

FSInfo gets info of ploop's inner file system

type ImageInfoData

type ImageInfoData struct {
	Blocks    uint64
	BlockSize uint32
	Version   int
}

ImageInfoData holds information about ploop image

type ImageMode

type ImageMode int

ImageMode is a type for CreateParam.Mode field

Possible values for ImageMode

func ParseImageMode

func ParseImageMode(s string) (ImageMode, error)

ParseImageMode converts a string to ImageMode value

func (ImageMode) String

func (m ImageMode) String() string

String converts an ImageMode value to string

type MountParam

type MountParam struct {
	UUID     string // snapshot uuid (empty for top delta)
	Target   string // mount point (empty if no mount is needed)
	Flags    int    // bit mount flags such as MS_NOATIME
	Data     string // auxiliary mount options
	Readonly bool   // mount read-only
	Fsck     bool   // do fsck before mounting inner FS
	Quota    bool   // enable quota for inner FS
}

MountParam is a set of parameters to pass to Mount()

type Ploop

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

Ploop is a type containing DiskDescriptor.xml opened by the library

func Open

func Open(file string) (Ploop, error)

Open opens a ploop DiskDescriptor.xml, most ploop operations require it

func (Ploop) Close

func (d Ploop) Close()

Close closes a ploop disk descriptor when it is no longer needed

func (Ploop) DeleteSnapshot

func (d Ploop) DeleteSnapshot(uuid string) error

DeleteSnapshot deletes a snapshot (merging it down if necessary)

func (Ploop) ImageInfo

func (d Ploop) ImageInfo() (ImageInfoData, error)

ImageInfo gets information about a ploop image

func (Ploop) IsMounted

func (d Ploop) IsMounted() (bool, error)

IsMounted returns true if ploop is mounted

func (Ploop) Mount

func (d Ploop) Mount(p *MountParam) (string, error)

Mount creates a ploop device and (optionally) mounts it

func (Ploop) Replace

func (d Ploop) Replace(p *ReplaceParam) error

Replace replaces a ploop image to a different (but identical) one

func (Ploop) Resize

func (d Ploop) Resize(size uint64, offline bool) error

Resize changes the ploop size. Online resize is recommended.

func (Ploop) Snapshot

func (d Ploop) Snapshot() (string, error)

Snapshot creates a ploop snapshot, returning its uuid

func (Ploop) SwitchSnapshot

func (d Ploop) SwitchSnapshot(uuid string) error

SwitchSnapshot switches to a specified snapshot, creates a new empty delta on top of it, and makes it a top one (i.e. the one new data will be written to). Old top delta (i.e. data modified since the last snapshot) is lost.

func (Ploop) SwitchSnapshotExtended

func (d Ploop) SwitchSnapshotExtended(uuid string, flags SwitchFlag) (string, error)

SwitchSnapshotExtended is same as SwitchSnapshot but with additional flags modifying its behavior. Please see individual flags description. Returns uuid of what was the old top delta if SkipDestroy flag is set.

func (Ploop) TopDeltaFile

func (d Ploop) TopDeltaFile() (string, error)

TopDeltaFile returns file name of top delta

func (Ploop) Umount

func (d Ploop) Umount() error

Umount unmounts the ploop filesystem and dismantles the device

type ReplaceFlag

type ReplaceFlag int

ReplaceFlag is a type for ReplaceParam.Flags field

const (
	// KeepName renames the new file to old file name after replace;
	// note that if this option is used the old file is removed.
	KeepName ReplaceFlag = C.PLOOP_REPLACE_KEEP_NAME
)

Possible values for ReplaceParam.Flags field

type ReplaceParam

type ReplaceParam struct {
	File string // new image file name
	// Image to be replaced is specified by either
	// uuid, current file name, or level,
	// in the above order of preference.
	UUID    string
	CurFile string
	Level   int
	Flags   ReplaceFlag
}

ReplaceParam is a set of parameters to Replace()

type SwitchFlag

type SwitchFlag uint

SwitchFlag is a type for SwitchSnapshotExtended.Flags

const (
	// SkipDestroy flag, if set, modifies the behavior of
	// SwitchSnapshotExtended to not delete the old top delta, but
	// make it a snapshot and return its uuid. Without this flag,
	// old top delta (i.e. data modified since the last snapshot)
	// is lost.
	SkipDestroy SwitchFlag = C.PLOOP_SNAP_SKIP_TOPDELTA_DESTROY
	// SkipCreate flag, if set, modifies the behavior of
	// SwitchSnapshotExtended to not create a new top delta,
	// but rather transform the specified snapshot itself to be
	// the new top delta), so all new changes will be written
	// right to it. Snapshot UUID is lost in this case.
	SkipCreate SwitchFlag = C.PLOOP_SNAP_SKIP_TOPDELTA_CREATE
)

Jump to

Keyboard shortcuts

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