sparse

package
v0.0.0-...-7951cd7 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: Apache-2.0 Imports: 19 Imported by: 7

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

This section is empty.

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 FileHandlingOperations) error

FoldFile folds child snapshot data into its parent

func GetFileLayout

func GetFileLayout(ctx context.Context, file FileIoProcessor) (<-chan FileInterval, <-chan error, error)

func HashData

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

func HashFileInterval

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

func PruneFile

func PruneFile(parentFileName, childFileName string, ops FileHandlingOperations) error

PruneFile removes the overlapping chunks from the parent snapshot based on its child volume head

func ReadDataInterval

func ReadDataInterval(rw ReaderWriterAt, dataInterval Interval) ([]byte, error)

func SetFailPointFileHashMatch

func SetFailPointFileHashMatch(fail bool)

SetFailPointFileHashMatch simulates file hash match failure

func SyncContent

func SyncContent(sourceName string, rw ReaderWriterAt, fileSize int64, remote string, httpClientTimeout int, directIO, fastSync bool) (err error)

func SyncFile

func SyncFile(localPath string, remote string, httpClientTimeout int, directIO, fastSync bool) error

SyncFile synchronizes local file to remote host

func SyncLocalFile

func SyncLocalFile(sourceFilePath, targetFilePath string) error

SyncLocalFile syncs a local file from sourceFilePath to targetFilePath. It ensures the file size is a multiple of the Block constant before syncing.

func WriteDataInterval

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

Types

type BufferedFileIoProcessor

type BufferedFileIoProcessor struct {
	*FiemapFile
}

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) GetDataLayout

func (file *BufferedFileIoProcessor) GetDataLayout(ctx context.Context) (<-chan FileInterval, <-chan error, error)

func (*BufferedFileIoProcessor) GetFieMap

func (file *BufferedFileIoProcessor) GetFieMap() *FiemapFile

func (*BufferedFileIoProcessor) GetFile

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

func (*BufferedFileIoProcessor) Size

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

func (*BufferedFileIoProcessor) UnmapAt

func (file *BufferedFileIoProcessor) UnmapAt(length uint32, offset int64) (int, error)

type DataSyncClient

type DataSyncClient interface {
	// contains filtered or unexported methods
}

type DirectFileIoProcessor

type DirectFileIoProcessor struct {
	*FiemapFile
}

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) GetDataLayout

func (file *DirectFileIoProcessor) GetDataLayout(ctx context.Context) (<-chan FileInterval, <-chan error, error)

func (*DirectFileIoProcessor) GetFieMap

func (file *DirectFileIoProcessor) GetFieMap() *FiemapFile

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 buffer copy

func (*DirectFileIoProcessor) Size

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

func (*DirectFileIoProcessor) UnmapAt

func (file *DirectFileIoProcessor) UnmapAt(length uint32, offset int64) (int, error)

UnmapAt punches a hole

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 buffer 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, extCount int) ([]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 FiemapFile

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 FileHandlingOperations

type FileHandlingOperations interface {
	UpdateFileHandlingProgress(progress int, done bool, err error)
}

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)
	UnmapAt(length uint32, offset int64) (int, error)
	GetFile() *os.File
	GetFieMap() *FiemapFile
	GetDataLayout(ctx context.Context) (<-chan FileInterval, <-chan error, error)
	Close() error
	Sync() error
	Truncate(size int64) error
	Seek(offset int64, whence int) (ret int64, err error)
	Name() string
	Stat() (os.FileInfo, 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

type ReaderWriterAt

type ReaderWriterAt interface {
	io.ReaderAt
	io.WriterAt

	GetDataLayout(ctx context.Context) (<-chan FileInterval, <-chan error, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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