fs

package
v0.0.0-...-22430d5 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2016 License: MIT Imports: 16 Imported by: 7

Documentation

Index

Constants

View Source
const (
	BlockBit  = 18
	BlockSize = 1 << BlockBit
)
View Source
const (
	InodePadding  = 36
	InodeSize     = 1024
	InodeBlockCnt = 150
	InodeCap      = InodeBlockCnt * BlockSize
)
View Source
const (
	InodeMapCap  = 1 << 20
	InodeMapSize = 6 * InodeMapCap
)
View Source
const (
	VolumeHeaderSize          = 16
	VolumeHeaderMinCheckpoint = VolumeHeaderSize + InodeMapSize
)
View Source
const FileNameSize = 28
View Source
const MagicSize = 4
View Source
const (
	NameMapItemSize = 32
)

Variables

View Source
var (
	MagicEOF    = Magic{0x8a, 0x9b, 0x0, 0x1}
	MagicVolume = Magic{0x8a, 0x9b, 0x0, 0x2}
	MagicInode  = Magic{0x8a, 0x9b, 0x0, 0x3}
)
View Source
var ErrFileNotExist = logex.Define("file is not exists")
View Source
var ErrSpaceNotEnough = fmt.Errorf("buffer space is not enough")

Functions

func CalNeedInodeCnt

func CalNeedInodeCnt(ino *Inode, n int) int

n: append data size

func FloorBlk

func FloorBlk(n int) int

func GetBlockCnt

func GetBlockCnt(n int) int

func GetBlockIdx

func GetBlockIdx(offset int64) int32

func GetInodeIdx

func GetInodeIdx(offset int64) int32

func IsFileCreate

func IsFileCreate(flags int) bool

func MakeRoom

func MakeRoom(b []byte, n int) []byte

func ReadDisk

func ReadDisk(r io.ReaderAt, d Diskable, addr Address) error

func ResetStat

func ResetStat()

func WriteDisk

func WriteDisk(w io.Writer, d Diskable) error

func WriteDiskAt

func WriteDiskAt(w io.WriterAt, d Diskable, addr Address) error

Types

type Address

type Address int64

func (Address) DiskSize

func (Address) DiskSize() int

func (Address) IsEmpty

func (a Address) IsEmpty() bool

func (Address) IsInMem

func (a Address) IsInMem() bool

func (*Address) ReadDisk

func (a *Address) ReadDisk(b []byte) error

func (*Address) Set

func (a *Address) Set(to Address)

func (*Address) SetMem

func (a *Address) SetMem(p unsafe.Pointer)

func (*Address) String

func (a *Address) String() string

func (Address) WriteDisk

func (a Address) WriteDisk(w []byte)

type Cobuffer

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

func NewCobuffer

func NewCobuffer(n int, maxSize int) *Cobuffer

func (*Cobuffer) Close

func (c *Cobuffer) Close()

func (*Cobuffer) Flush

func (c *Cobuffer) Flush()

func (*Cobuffer) GetData

func (c *Cobuffer) GetData(buffer []byte) int

func (*Cobuffer) IsFlush

func (c *Cobuffer) IsFlush() <-chan struct{}

func (*Cobuffer) IsWritten

func (c *Cobuffer) IsWritten() <-chan struct{}

func (*Cobuffer) WriteData

func (c *Cobuffer) WriteData(b []byte)

type DataSlice

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

func NewDataSlice

func NewDataSlice(d []byte) *DataSlice

func (*DataSlice) Append

func (f *DataSlice) Append(b []byte)

func (*DataSlice) Len

func (f *DataSlice) Len() int

func (*DataSlice) WriteData

func (f *DataSlice) WriteData(dw *DiskWriter, n int)

type DiskBuffer

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

func NewDiskBuffer

func NewDiskBuffer(rw io.ReadWriter) *DiskBuffer

func (*DiskBuffer) ReadItem

func (d *DiskBuffer) ReadItem(da Diskable) error

func (*DiskBuffer) WriteItem

func (d *DiskBuffer) WriteItem(da Diskable) error

type DiskItem

type DiskItem interface {
	DiskSize() int
	ReadDisk([]byte) error
	WriteDisk([]byte)
}

type DiskReadItem

type DiskReadItem interface {
	DiskSize() int
	ReadDisk([]byte) error
}

type DiskReader

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

func NewDiskReader

func NewDiskReader(b []byte) *DiskReader

func (*DiskReader) Peek

func (r *DiskReader) Peek(n int) []byte

func (*DiskReader) ReadBytes

func (r *DiskReader) ReadBytes(n int) []byte

func (*DiskReader) ReadItem

func (r *DiskReader) ReadItem(d DiskReadItem) error

func (*DiskReader) ReadItems

func (r *DiskReader) ReadItems(ds []DiskReadItem) error

func (*DiskReader) ReadMagic

func (r *DiskReader) ReadMagic(d Diskable) error

func (*DiskReader) Skip

func (r *DiskReader) Skip(n int)

type DiskWriteItem

type DiskWriteItem interface {
	DiskSize() int
	WriteDisk([]byte)
}

type DiskWriter

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

func NewDiskWriter

func NewDiskWriter(b []byte) *DiskWriter

func (*DiskWriter) Mark

func (w *DiskWriter) Mark()

func (*DiskWriter) Reset

func (w *DiskWriter) Reset()

func (*DiskWriter) Skip

func (w *DiskWriter) Skip(n int)

func (*DiskWriter) WriteBytes

func (w *DiskWriter) WriteBytes(b []byte)

func (*DiskWriter) WriteItem

func (w *DiskWriter) WriteItem(d DiskWriteItem)

func (*DiskWriter) WriteMagic

func (w *DiskWriter) WriteMagic(d Diskable)

func (*DiskWriter) Written

func (w *DiskWriter) Written() int64

type Diskable

type Diskable interface {
	Magic() Magic
	DiskItem
}

type File

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

func NewFile

func NewFile(f *flow.Flow, cfg *FileConfig) (*File, error)

func (*File) AddRef

func (f *File) AddRef() bool

func (*File) Close

func (f *File) Close() error

func (*File) Ino

func (f *File) Ino() int32

func (*File) Name

func (f *File) Name() string

func (*File) ReadAt

func (f *File) ReadAt(b []byte, off int64) (readBytes int, err error)

func (*File) Size

func (f *File) Size() int64

func (*File) Stat

func (f *File) Stat() (*Inode, error)

func (*File) Sync

func (f *File) Sync()

func (*File) Write

func (f *File) Write(b []byte) (int, error)

type FileConfig

type FileConfig struct {
	Ino           int32
	Name          string
	Flags         int
	Delegate      FileDelegater
	FlushInterval time.Duration
	Flusher       FileFlusher
	FlushSize     int
}

type FileDelegater

type FileDelegater interface {
	InodePoolDelegate
	ReadData(offset ShortAddr, n int) ([]byte, error)
}

type FileFlusher

type FileFlusher interface {
	WriteByInode(*InodePool, []byte, chan *FlusherWriteReply)
	Flush(wait bool)
}

type FileName

type FileName [FileNameSize]byte

func (*FileName) String

func (f *FileName) String() string

type FlushDelegate

type FlushDelegate interface {
	ReadData(off int64, n int) ([]byte, error)
	io.WriterAt

	UpdateCheckpoint(cp int64)
}

type Flusher

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

func NewFlusher

func NewFlusher(f *flow.Flow, cfg *FlusherConfig) *Flusher

func (*Flusher) Close

func (f *Flusher) Close()

func (*Flusher) Flush

func (f *Flusher) Flush(wait bool)

func (*Flusher) WriteByInode

func (f *Flusher) WriteByInode(inoPool *InodePool, data []byte, done chan *FlusherWriteReply)

type FlusherConfig

type FlusherConfig struct {
	Interval time.Duration
	Delegate FlushDelegate
	Offset   int64
}

type FlusherWriteReply

type FlusherWriteReply struct {
	N   int
	Err error
}

type GStat

type GStat struct {
	Volume struct {
		CloseTime ptrace.RatioTime
	}
	Flusher struct {
		BlockCopy ptrace.Size
		ReadTime  ptrace.RatioTime
		HandleOp  struct {
			Total        ptrace.RatioTime
			DataArea     ptrace.RatioTime
			DataAreaCopy ptrace.RatioTime
			Partial      ptrace.RatioTime
			Inode        ptrace.RatioTime
		}
		FlushBuffer      ptrace.RatioTime
		FlushBufferGetOp ptrace.RatioTime
		Buffering        struct {
			Size ptrace.RatioSize
		}
		Flush struct {
			Total    ptrace.RatioTime
			Count    ptrace.Int
			Size     ptrace.RatioSize
			RawWrite ptrace.RatioTime
		}
		CloseTime        ptrace.RatioTime
		FlushBufferAddOp ptrace.RatioTime
		DataSlice        struct {
		}
	}
	Inode struct {
		Cache struct {
			NextHit   ptrace.Ratio
			InoIdxHit ptrace.Ratio
		}

		ReadDisk    ptrace.Int
		PrevSeekCnt ptrace.Ratio
	}
	File struct {
		FlushSize   ptrace.RatioSize
		RegenBuffer ptrace.Ratio
		CloseTime   ptrace.RatioTime
		Loop        struct {
			BufferDuration ptrace.RatioTime
		}
		Flush struct {
			WaitSize  ptrace.Ratio
			WaitReply ptrace.RatioTime
		}
		DiskRead ptrace.RatioTime
	}
	Cobuffer struct {
		Trytime            ptrace.Ratio
		NotifyFlushByWrite ptrace.Ratio
		GetData            struct {
			Lock ptrace.RatioTime
			Copy ptrace.RatioTime
			Size ptrace.RatioSize
		}
		Grow       ptrace.RatioTime
		FlushDelay ptrace.RatioTime
		FullTime   ptrace.RatioTime
		WriteTime  ptrace.RatioTime
	}
}
var Stat GStat

func (*GStat) String

func (c *GStat) String() string

type Handle

type Handle struct {
	*File
	// contains filtered or unexported fields
}

func NewHandle

func NewHandle(f *File, off int64) *Handle

func (*Handle) Read

func (f *Handle) Read(b []byte) (int, error)

type Inode

type Inode struct {
	// Magic 4
	Ino   Int32
	Start Int32
	Size  Int32 // 8

	// 1, 2, 4, 8, 16, 32
	PrevInode [6]*Address
	PrevGroup Address // 7*8

	GroupSize Int32
	GroupIdx  Int32 // 8

	Mtime Time // 4

	Offsets [InodeBlockCnt]ShortAddr
	// contains filtered or unexported fields
}

size: 1kB one inode can store 37.5MB

func NewInode

func NewInode(ino int32) *Inode

func (*Inode) DiskSize

func (i *Inode) DiskSize() int

func (*Inode) GetBlockIdx

func (i *Inode) GetBlockIdx(off int64) int

func (*Inode) GetBlockSize

func (i *Inode) GetBlockSize(idx int) int

func (*Inode) GetRemainInBlock

func (i *Inode) GetRemainInBlock(off int64) int

off: global offset off must in this Inode

func (*Inode) GetSizeIdx

func (i *Inode) GetSizeIdx() int

func (*Inode) IsFull

func (i *Inode) IsFull() bool

func (*Inode) Magic

func (i *Inode) Magic() Magic

func (*Inode) ReadDisk

func (i *Inode) ReadDisk(b []byte) error

func (*Inode) SeekIdx

func (i *Inode) SeekIdx(offset int64) (int, bool)

func (*Inode) SetOffset

func (i *Inode) SetOffset(idx int, addr ShortAddr, size int)

func (*Inode) WriteDisk

func (i *Inode) WriteDisk(b []byte)

type InodeMap

type InodeMap struct {
	InoMap []byte
	// contains filtered or unexported fields
}

func NewInodeMap

func NewInodeMap(offset int64, delegate InodeMapDelegate, create bool) (*InodeMap, error)

func (*InodeMap) DiskSize

func (m *InodeMap) DiskSize() int

func (*InodeMap) Flush

func (m *InodeMap) Flush() error

TODO(chzyer): add replica

func (*InodeMap) GetInode

func (m *InodeMap) GetInode(ino int32) (*Inode, error)

func (*InodeMap) GetInodeByAddr

func (m *InodeMap) GetInodeByAddr(addr Address) (*Inode, error)

func (*InodeMap) SaveInode

func (m *InodeMap) SaveInode(inode *Inode)

type InodeMapDelegate

type InodeMapDelegate interface {
	bio.ReadWriterAt
}

type InodePool

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

Pool for one file

func NewInodePool

func NewInodePool(ino int32, delegate InodePoolDelegate) *InodePool

func (*InodePool) CleanCache

func (p *InodePool) CleanCache()

func (*InodePool) GetByAddr

func (i *InodePool) GetByAddr(addr Address) (*Inode, error)

func (*InodePool) GetLastest

func (i *InodePool) GetLastest() (*Inode, error)

get newest inode from memory or disk

func (*InodePool) InitInode

func (p *InodePool) InitInode() *Inode

func (*InodePool) OnFlush

func (p *InodePool) OnFlush(ino *Inode, addr Address)

func (*InodePool) RefPayloadBlock

func (p *InodePool) RefPayloadBlock() (*Inode, int, error)

func (*InodePool) ResetCache

func (p *InodePool) ResetCache()

func (*InodePool) SeekNext

func (p *InodePool) SeekNext(inode *Inode) (*Inode, error)

func (*InodePool) SeekPrev

func (p *InodePool) SeekPrev(offset int64) (*Inode, error)

type InodePoolDelegate

type InodePoolDelegate interface {
	GetInode(ino int32) (*Inode, error)
	GetInodeByAddr(addr Address) (*Inode, error)
	SaveInode(inode *Inode)
}

type InodeScatter

type InodeScatter [32]*Inode

func (*InodeScatter) Clean

func (is *InodeScatter) Clean()

func (*InodeScatter) Push

func (is *InodeScatter) Push(i *Inode)

func (*InodeScatter) Top

func (is *InodeScatter) Top() *Inode

type Int32

type Int32 int32

func (Int32) DiskSize

func (Int32) DiskSize() int

func (*Int32) ReadDisk

func (v *Int32) ReadDisk(w []byte) error

func (Int32) WriteDisk

func (v Int32) WriteDisk(w []byte)

type Magic

type Magic []byte

func (Magic) String

func (m Magic) String() string

type NameMap

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

NameMap is a File which ino is 0 fd close by NameMap

func NewNameMap

func NewNameMap(fh *Handle, start int32) (*NameMap, error)

func (*NameMap) AddIno

func (n *NameMap) AddIno(name string, ino int32) error

func (*NameMap) Close

func (n *NameMap) Close()

func (*NameMap) GetFreeIno

func (n *NameMap) GetFreeIno() (int32, error)

func (*NameMap) GetIno

func (n *NameMap) GetIno(name string) (ino int32, err error)

ino: -1 means file not found

func (*NameMap) List

func (n *NameMap) List() []string

type NameMapItem

type NameMapItem struct {
	Name FileName
	Ino  Int32
}

func (*NameMapItem) DiskSize

func (n *NameMapItem) DiskSize() int

func (*NameMapItem) ReadDisk

func (n *NameMapItem) ReadDisk(b []byte) error

func (*NameMapItem) WriteDisk

func (n *NameMapItem) WriteDisk(b []byte)

type ShortAddr

type ShortAddr int64

func (ShortAddr) DiskSize

func (ShortAddr) DiskSize() int

func (ShortAddr) IsEmpty

func (a ShortAddr) IsEmpty() bool

func (*ShortAddr) ReadDisk

func (a *ShortAddr) ReadDisk(b []byte) error

func (ShortAddr) WriteDisk

func (a ShortAddr) WriteDisk(b []byte)

type Time

type Time int64

func (Time) DiskSize

func (Time) DiskSize() int

func (Time) Get

func (v Time) Get() time.Time

func (*Time) ReadDisk

func (v *Time) ReadDisk(w []byte) error

func (*Time) Set

func (v *Time) Set(t time.Time)

func (Time) WriteDisk

func (v Time) WriteDisk(w []byte)

type Volume

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

func NewVolume

func NewVolume(f *flow.Flow, cfg *VolumeConfig) (*Volume, error)

func (*Volume) CleanCache

func (v *Volume) CleanCache()

func (*Volume) Close

func (v *Volume) Close()

func (*Volume) FlushInodeMap

func (v *Volume) FlushInodeMap() error

func (*Volume) List

func (v *Volume) List() []string

func (*Volume) Open

func (v *Volume) Open(name string, flags int) (*Handle, error)

type VolumeConfig

type VolumeConfig struct {
	Delegate      VolumeDelegate
	FlushInterval time.Duration
	FlushSize     int
}

type VolumeDelegate

type VolumeDelegate interface {
	bio.ReadWriterAt
	ReadData(off int64, n int) ([]byte, error)
}

type VolumeHeader

type VolumeHeader struct {
	Version    Int32
	Checkpoint Address
	InodeMap   *InodeMap
}

func GenNewVolumeHeader

func GenNewVolumeHeader(rw bio.ReadWriterAt) (*VolumeHeader, error)

func ReadVolumeHeader

func ReadVolumeHeader(rw bio.ReadWriterAt) (*VolumeHeader, error)

func (*VolumeHeader) DiskSize

func (v *VolumeHeader) DiskSize() int

func (*VolumeHeader) Flush

func (v *VolumeHeader) Flush(w io.WriterAt) error

func (*VolumeHeader) Magic

func (v *VolumeHeader) Magic() Magic

func (*VolumeHeader) ReadDisk

func (v *VolumeHeader) ReadDisk(b []byte) error

func (*VolumeHeader) WriteDisk

func (v *VolumeHeader) WriteDisk(b []byte)

type VolumeSource

type VolumeSource struct {
	*bio.Hybrid
	// contains filtered or unexported fields
}

func NewVolumeSource

func NewVolumeSource(dir string) (*VolumeSource, error)

func (*VolumeSource) Close

func (v *VolumeSource) Close()

Jump to

Keyboard shortcuts

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