sparse

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2020 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	FiemapSize = 32 // sizeof(struct fiemap)
	ExtentSize = 56 // sizeof(struct Extent)

	// FS_IOC_FIEMAP is defined in <linux/fs.h>:
	FS_IOC_FIEMAP = 3223348747

	// FIEMAP_MAX_OFFSET Defined in <linux/fiemap.h>:
	FIEMAP_MAX_OFFSET            = ^uint64(0)
	FIEMAP_FLAG_SYNC             = 0x0001 // sync file data before map
	FIEMAP_FLAG_XATTR            = 0x0002 // map extended attribute tree
	FIEMAP_FLAG_CACHE            = 0x0004 // request caching of the extents
	FIEMAP_FLAGS_COMPAT          = (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR)
	FIEMAP_EXTENT_LAST           = 0x0001 // Last extent in file.
	FIEMAP_EXTENT_UNKNOWN        = 0x0002 // Data location unknown.
	FIEMAP_EXTENT_DELALLOC       = 0x0004 // Location still pending. Sets EXTENT_UNKNOWN.
	FIEMAP_EXTENT_ENCODED        = 0x0008 // Data can not be read while fs is unmounted
	FIEMAP_EXTENT_DATA_ENCRYPTED = 0x0080 // Data is encrypted by fs. Sets EXTENT_NO_BYPASS.
	FIEMAP_EXTENT_NOT_ALIGNED    = 0x0100 // Extent offsets may not be block aligned.
	FIEMAP_EXTENT_DATA_INLINE    = 0x0200 // Data mixed with metadata. Sets EXTENT_NOT_ALIGNED.
	FIEMAP_EXTENT_DATA_TAIL      = 0x0400 // Multiple files in block. Sets EXTENT_NOT_ALIGNED.
	FIEMAP_EXTENT_UNWRITTEN      = 0x0800 // Space allocated, but no data (i.e. zero).
	FIEMAP_EXTENT_MERGED         = 0x1000 // File does not natively support extents. Result merged for efficiency.
	FIEMAP_EXTENT_SHARED         = 0x2000 // Space shared with other files.

	// FALLOC_FL_KEEP_SIZE Defined in <linux/falloc.h>:
	FALLOC_FL_KEEP_SIZE    = 0x01 // default is extend size
	FALLOC_FL_PUNCH_HOLE   = 0x02 // de-allocates range
	FALLOC_FL_NO_HIDE_STAE = 0x04 // reserved codepoint
)
View Source
const (

	// BlockSize sic
	BlockSize = alignment
)
View Source
const (
	// Blocks : block size in bytes
	Blocks int64 = 4 << 10 // 4k
)

Variables

View Source
var (
	HTTPClientTimeout time.Duration = 30
)

Functions

func AllocateAligned

func AllocateAligned(size int) []byte

AllocateAligned returns []byte of size aligned to alignment

func FailPointFileHashMatch

func FailPointFileHashMatch() bool

FailPointFileHashMatch returns true if this failpoint is set, clears the failpoint

func FoldFile

func FoldFile(childFileName, parentFileName string, ops FoldFileOperations) error

FoldFile folds child snapshot data into its parent

func HashData

func HashData(data []byte) ([]byte, error)

func HashFileInterval

func HashFileInterval(file FileIoProcessor, dataInterval Interval) ([]byte, error)

func ReadDataInterval

func ReadDataInterval(file FileIoProcessor, dataInterval Interval) ([]byte, error)

func SetFailPointFileHashMatch

func SetFailPointFileHashMatch(fail bool)

SetFailPointFileHashMatch simulates file hash match failure

func SyncFile

func SyncFile(localPath string, remote string, timeout int) error

SyncFile synchronizes local file to remote host

func WriteDataInterval

func WriteDataInterval(file FileIoProcessor, dataInterval Interval, data []byte) error

Types

type BufferedFileIoProcessor

type BufferedFileIoProcessor struct {
	*os.File
}

func NewBufferedFileIoProcessor

func NewBufferedFileIoProcessor(name string, flag int, perm os.FileMode, isCreate ...bool) (*BufferedFileIoProcessor, error)

func NewBufferedFileIoProcessorByFP

func NewBufferedFileIoProcessorByFP(fp *os.File) *BufferedFileIoProcessor

func (*BufferedFileIoProcessor) Close

func (file *BufferedFileIoProcessor) Close() error

func (*BufferedFileIoProcessor) GetFile

func (file *BufferedFileIoProcessor) GetFile() *os.File

func (*BufferedFileIoProcessor) Size

func (file *BufferedFileIoProcessor) Size() (int64, error)

type DirectFileIoProcessor

type DirectFileIoProcessor struct {
	*os.File
}

func NewDirectFileIoProcessor

func NewDirectFileIoProcessor(name string, flag int, perm os.FileMode, isCreate ...bool) (*DirectFileIoProcessor, error)

func NewDirectFileIoProcessorByFP

func NewDirectFileIoProcessorByFP(fp *os.File) *DirectFileIoProcessor

func (*DirectFileIoProcessor) GetFile

func (file *DirectFileIoProcessor) GetFile() *os.File

func (*DirectFileIoProcessor) ReadAt

func (file *DirectFileIoProcessor) ReadAt(data []byte, offset int64) (int, error)

ReadAt read into unaligned data buffer via direct I/O Use AllocateAligned to avoid extra data fuffer copy

func (*DirectFileIoProcessor) Size

func (file *DirectFileIoProcessor) Size() (int64, error)

func (*DirectFileIoProcessor) WriteAt

func (file *DirectFileIoProcessor) WriteAt(data []byte, offset int64) (int, error)

WriteAt write from unaligned data buffer via direct I/O Use AllocateAligned to avoid extra data fuffer copy

type Extent

type Extent struct {
	Logical    uint64 // logical offset in bytes for the start of the extent from the beginning of the file
	Physical   uint64 // physical offset in bytes for the start	of the extent from the beginning of the disk
	Length     uint64 // length in bytes for this extent
	Reserved64 [2]uint64
	Flags      uint32 // FIEMAP_EXTENT_* flags for this extent
	Reserved   [3]uint32
}

Extent : based on struct fiemap_extent from <linux/fiemap.h>

func GetFiemapExtents

func GetFiemapExtents(file FileIoProcessor) ([]Extent, error)

func GetFiemapRegionExts

func GetFiemapRegionExts(file FileIoProcessor, interval Interval) ([]Extent, error)

type FiemapFile

type FiemapFile struct {
	*os.File
}

FiemapFile creates a new type by wrapping up os.File

func NewFiemapFile

func NewFiemapFile(f *os.File) FiemapFile

NewFiemapFile : return a new FibmapFile

func (FiemapFile) Fallocate

func (f FiemapFile) Fallocate(offset int64, length int64) error

Fallocate : allocate using fallocate

func (FiemapFile) Fiemap

func (f FiemapFile) Fiemap(size uint32) (uint32, []Extent, syscall.Errno)

Fiemap : call FIEMAP ioctl

func (FiemapFile) FiemapRegion

func (f FiemapFile) FiemapRegion(numExts uint32, start uint64, length uint64) (uint32, []Extent, syscall.Errno)

func (FiemapFile) PunchHole

func (f FiemapFile) PunchHole(offset int64, length int64) error

PunchHole : punch hole using fallocate

type FileInterval

type FileInterval struct {
	Kind FileIntervalKind
	Interval
}

FileInterval describes either sparse data Interval or a hole

func (FileInterval) String

func (i FileInterval) String() string

type FileIntervalKind

type FileIntervalKind int

FileIntervalKind distinguishes between data and hole

const (
	SparseData FileIntervalKind = 1 + iota
	SparseHole
	SparseIgnore // ignore file interval (equal src vs dst part)
)

Sparse file Interval types

type FileIoProcessor

type FileIoProcessor interface {
	// File I/O methods for direct or bufferend I/O
	ReadAt(data []byte, offset int64) (int, error)
	WriteAt(data []byte, offset int64) (int, error)
	GetFile() *os.File
	Close() error
	Sync() error
	Truncate(size int64) error
	Seek(offset int64, whence int) (ret int64, err error)
	Name() string
	Stat() (os.FileInfo, error)
}

type FoldFileOperations

type FoldFileOperations interface {
	UpdateFoldFileProgress(progress int, done bool, err error)
}

type Interval

type Interval struct {
	Begin, End int64
}

Interval [Begin, End) is non-inclusive at the End

func (Interval) Len

func (interval Interval) Len() int64

Len returns length of Interval

func (Interval) String

func (interval Interval) String() string

String conversion

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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