mfscli

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: MIT Imports: 17 Imported by: 1

README

moosefs-client

Build Status

go client for moosefs version 3.0.103

Most code logic is from source of moosefs, and also take examples from wfxiang08 and xiexiao.

Install

go get github.com/Hacky-DH/moosefs-client

Documentation

Index

Constants

View Source
const (
	MFSBLOCKSINCHUNK  = 0x400
	MFSCHUNKSIZE      = 0x04000000
	MFSCHUNKMASK      = 0x03FFFFFF
	MFSCHUNKBITS      = 26
	MFSCHUNKBLOCKMASK = 0x03FF0000
	MFSBLOCKSIZE      = 0x10000
	MFSBLOCKMASK      = 0x0FFFF
	MFSBLOCKNEGMASK   = 0x7FFF0000
	MFSBLOCKBITS      = 16
	MFSCRCEMPTY       = 0xD7978EEB
	MFSHDRSIZE        = 0x2000
)
View Source
const (
	TYPE_FILE = iota + 1
	TYPE_DIRECTORY
	TYPE_SYMLINK
	TYPE_FIFO
	TYPE_BLOCKDEV
	TYPE_CHARDEV
	TYPE_SOCKET
	TYPE_TRASH
	TYPE_SUSTAINED
)
View Source
const (
	SET_WINATTR_FLAG = 1 << iota
	SET_MODE_FLAG
	SET_UID_FLAG
	SET_GID_FLAG
	SET_MTIME_NOW_FLAG
	SET_MTIME_FLAG
	SET_ATIME_FLAG
	SET_ATIME_NOW_FLAG
)

for setmask

View Source
const (
	CHUNKOPFLAG_CANMODTIME = 1 << iota
	CHUNKOPFLAG_CONTINUEOP
	CHUNKOPFLAG_CANUSERESERVESPACE
)

chunkopflags

View Source
const ANTOAN_GET_VERSION = 10
View Source
const ANTOAN_NOP = 0
View Source
const ANTOCS_GET_CHUNK_CHECKSUM = 300
View Source
const ANTOCS_GET_CHUNK_CHECKSUM_TAB = 302
View Source
const CLTOCS_READ = 200
View Source
const CLTOCS_WRITE = 210
View Source
const CLTOCS_WRITE_DATA = 212
View Source
const CLTOCS_WRITE_FINISH = 213
View Source
const CLTOMA_FUSE_ACCESS = 404
View Source
const CLTOMA_FUSE_APPEND_SLICE = 438
View Source
const CLTOMA_FUSE_ARCHCTL = 496
View Source
const CLTOMA_FUSE_CHECK = 440
View Source
const CLTOMA_FUSE_CREATE = 482
View Source
const CLTOMA_FUSE_FLOCK = 492
View Source
const CLTOMA_FUSE_FSYNC = 498
View Source
const CLTOMA_FUSE_GETATTR = 408
View Source
const CLTOMA_FUSE_GETDETACHEDATTR = 452
View Source
const CLTOMA_FUSE_GETDIRSTATS = 462
View Source
const CLTOMA_FUSE_GETEATTR = 472
View Source
const CLTOMA_FUSE_GETFACL = 488
View Source
const CLTOMA_FUSE_GETSCLASS = 446
View Source
const CLTOMA_FUSE_GETSUSTAINED = 470
View Source
const CLTOMA_FUSE_GETTRASH = 450
View Source
const CLTOMA_FUSE_GETTRASHPATH = 454
View Source
const CLTOMA_FUSE_GETTRASHTIME = 442
View Source
const CLTOMA_FUSE_GETXATTR = 478
View Source
const CLTOMA_FUSE_LINK = 426
View Source
const CLTOMA_FUSE_LOOKUP = 406
View Source
const CLTOMA_FUSE_MKDIR = 418
View Source
const CLTOMA_FUSE_MKNOD = 416
View Source
const CLTOMA_FUSE_OPEN = 430
View Source
const CLTOMA_FUSE_PARENTS = 484
View Source
const CLTOMA_FUSE_PATHS = 486
View Source
const CLTOMA_FUSE_POSIX_LOCK = 494
View Source
const CLTOMA_FUSE_PURGE = 460
View Source
const CLTOMA_FUSE_QUOTACONTROL = 476
View Source
const CLTOMA_FUSE_READDIR = 428
View Source
const CLTOMA_FUSE_READLINK = 412
View Source
const CLTOMA_FUSE_READ_CHUNK = 432
View Source
const CLTOMA_FUSE_REGISTER = 400
View Source
const CLTOMA_FUSE_RENAME = 424
View Source
const CLTOMA_FUSE_REPAIR = 466
View Source
const CLTOMA_FUSE_RMDIR = 422
View Source
const CLTOMA_FUSE_SETATTR = 410
View Source
const CLTOMA_FUSE_SETEATTR = 474
View Source
const CLTOMA_FUSE_SETFACL = 490
View Source
const CLTOMA_FUSE_SETSCLASS = 448
View Source
const CLTOMA_FUSE_SETTRASHPATH = 456
View Source
const CLTOMA_FUSE_SETTRASHTIME = 444
View Source
const CLTOMA_FUSE_SETXATTR = 480
View Source
const CLTOMA_FUSE_SNAPSHOT = 468
View Source
const CLTOMA_FUSE_STATFS = 402
View Source
const CLTOMA_FUSE_SYMLINK = 414
View Source
const CLTOMA_FUSE_TRUNCATE = 464
View Source
const CLTOMA_FUSE_UNDEL = 458
View Source
const CLTOMA_FUSE_UNLINK = 420
View Source
const CLTOMA_FUSE_WRITE_CHUNK = 434
View Source
const CLTOMA_FUSE_WRITE_CHUNK_END = 436
View Source
const CLTOMA_INFO = 510
View Source
const CLTOMA_QUOTA_INFO = 518
View Source
const CLTOMA_SESSION_COMMAND = 526
View Source
const CLTOMA_SESSION_LIST = 508
View Source
const CSTOAN_CHUNK_CHECKSUM = 301
View Source
const CSTOAN_CHUNK_CHECKSUM_TAB = 303
View Source
const CSTOCL_READ_DATA = 202
View Source
const CSTOCL_READ_STATUS = 201
View Source
const CSTOCL_WRITE_STATUS = 211
View Source
const FUSE_REGISTER_BLOB_ACL = "DjI1GAQDULI5d2YjA26ypc3ovkhjvhciTQVx3CS4nYgtBoUcsljiVpsErJENHaw0"
View Source
const MASTER_HEARTBEAT_INTERVAL = 5 * time.Second
View Source
const MFS_NAME_MAX = 255
View Source
const MFS_PATH_MAX = 1024
View Source
const MFS_ROOT_ID = 1
View Source
const MFS_SYMLINK_MAX = 4096
View Source
const MFS_VERSION string = "3.0.103"
View Source
const MIN_SPECIAL_INODE = 0x7FFFFFF0
View Source
const REGISTER_CLOSESESSION uint8 = 6
View Source
const REGISTER_GETRANDOM uint8 = 1
View Source
const REGISTER_NEWMETASESSION uint8 = 5
View Source
const REGISTER_NEWSESSION uint8 = 2
View Source
const REGISTER_RECONNECT uint8 = 3
View Source
const REGISTER_TOOLS uint8 = 4
View Source
const TCP_CONNECT_TIMEOUT = 30 * time.Second
View Source
const TCP_RETRY_TIMES = 3
View Source
const TCP_RW_TIMEOUT = time.Minute

Variables

View Source
var ERROR_TABLE = []string{
	"OK",
	"Operation not permitted",
	"Not a directory",
	"No such file or directory",
	"Permission denied",
	"File exists",
	"Invalid argument",
	"Directory not empty",
	"Chunk lost",
	"Out of memory",
	"Index too big",
	"Chunk locked",
	"No chunk servers",
	"No such chunk",
	"Chunk is busy",
	"Incorrect register BLOB",
	"Operation not completed",
	"File not opened",
	"Write not started",
	"Wrong chunk version",
	"Chunk already exists",
	"No space left",
	"IO error",
	"Incorrect block number",
	"Incorrect size",
	"Incorrect offset",
	"Can't connect",
	"Incorrect chunk id",
	"Disconnected",
	"CRC error",
	"Operation delayed",
	"Can't create path",
	"Data mismatch",
	"Read-only file system",
	"Quota exceeded",
	"Bad session id",
	"Password is needed",
	"Incorrect password",
	"Attribute not found",
	"Operation not supported",
	"Result too large",
	"Entity not found",
	"Entity is active",
	"Chunkserver not present",
	"Waiting on lock",
	"Resource temporarily unavailable",
	"Interrupted system call",
	"Operation canceled",
	"No such file or directory (not cacheable)",
	"Operation not permitted (mfs admin only)",
	"Class name already in use",
	"Maximum number of classes reached",
	"No such class",
	"Class in use",
	"Unknown MFS error",
}

Functions

func FormatBytes

func FormatBytes(b float64, mode Mode) string

func MFSStrerror

func MFSStrerror(code uint8) string

func Pack

func Pack(data ...interface{}) []byte

func PackCmd

func PackCmd(cmd uint32, data ...interface{}) []byte

func ParseBytes

func ParseBytes(str string) (uint64, error)

2.45M -> 2450000 2.45Mi -> 2569011

func UnPack

func UnPack(in []byte, out ...interface{})

Types

type CSClient

type CSClient struct {
	Version
	// contains filtered or unexported fields
}

chunk server client

func NewCSClient

func NewCSClient(t *CSItem) (c *CSClient, err error)

func (*CSClient) Close

func (c *CSClient) Close()

func (*CSClient) Recv

func (c *CSClient) Recv(buf []byte) (n int, err error)

func (*CSClient) Send

func (c *CSClient) Send(msg []byte) error

type CSData

type CSData struct {
	ProtocolId uint8
	Length     uint64
	ChunkId    uint64
	Version    uint32
	CSItems    CSItemMap
}

reponse data from master

func (*CSData) Read

func (d *CSData) Read(buf []byte, off uint64) (n uint32, err error)

func (*CSData) ReadBlock

func (d *CSData) ReadBlock(c *CSClient, buf []byte, off uint64) (n uint32, err error)

func (*CSData) Write

func (d *CSData) Write(buf []byte, off uint64) (n uint32, err error)

func (*CSData) WriteBlock

func (d *CSData) WriteBlock(c *CSClient, wid uint32, blockNum, off uint16,
	buf []byte) (err error)

type CSItem

type CSItem struct {
	Ip        uint32
	Port      uint16
	Version   uint32
	LabelMask uint32
}

type CSItemMap

type CSItemMap map[uint32]*CSItem

type CSPool

type CSPool struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewCSPool

func NewCSPool() *CSPool

func (*CSPool) Close

func (p *CSPool) Close()

func (*CSPool) Get

func (p *CSPool) Get(t *CSItem) (c *CSClient, err error)

func (*CSPool) Put

func (p *CSPool) Put(c *CSClient)

type Client

type Client struct {
	Cwd string
	// contains filtered or unexported fields
}

func NewCLient

func NewCLient() (c *Client, err error)

func NewClientFull

func NewClientFull(addr, password, subDir string) (c *Client, err error)

func (*Client) Chdir

func (c *Client) Chdir(path string) (err error)

func (*Client) Chmod

func (c *Client) Chmod(path string, mode uint16) (fi *FileInfo, err error)

func (*Client) Chown

func (c *Client) Chown(path string, uid, gid uint32) (fi *FileInfo, err error)

func (*Client) Close

func (c *Client) Close()

close client, not file

func (*Client) Create

func (c *Client) Create(path string) (f *File, err error)

func (*Client) GetDirStats

func (c *Client) GetDirStats(path string) (ds *DirStats, err error)

func (*Client) Mkdir

func (c *Client) Mkdir(path string) (err error)

func (*Client) Open

func (c *Client) Open(path string) (f *File, err error)

func (*Client) OpenOrCreate

func (c *Client) OpenOrCreate(path string) (f *File, err error)

func (*Client) ReadFile

func (c *Client) ReadFile(path, localPath string) (err error)

read mfs file to local file

func (*Client) Readdir

func (c *Client) Readdir(path string) (infoMap ReaddirInfoMap, err error)

func (*Client) Rmdir

func (c *Client) Rmdir(path string) (err error)
func (c *Client) Unlink(path string) (err error)

func (*Client) WriteFile

func (c *Client) WriteFile(localPath, path string) (err error)

write local file to mfs

type DirStats

type DirStats struct {
	Inode  uint32
	Inodes uint32
	Dirs   uint32
	Files  uint32
	Chunks uint32
	Length uint64
	Size   uint64
	RSize  uint64
}

type File

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

func (*File) Length

func (f *File) Length() string

func (*File) Read

func (f *File) Read(buf []byte, offset uint64) (n uint32, err error)

func (*File) Write

func (f *File) Write(buf []byte, offset uint64) (n uint32, err error)

type FileInfo

type FileInfo struct {
	Flags uint8
	Type  uint8
	Inode uint32
	Uid   uint32
	Gid   uint32
	Mode  os.FileMode
	NLink uint32
	ATime time.Time
	MTime time.Time
	CTime time.Time
	Size  uint64
}

flags: 01 noacache 02 noecache 04 allowdatacache

08 noxattr 10 directmode

'floating-point' size examples:

1200 =  12.00 B

1023443 = 234.43 kB 2052312 = 523.12 MB 3001298 = 12.98 GB 4001401 = 14.01 TB

func (*FileInfo) GetSize

func (fi *FileInfo) GetSize() string

func (*FileInfo) IsDir

func (fi *FileInfo) IsDir() bool

func (*FileInfo) IsFile

func (fi *FileInfo) IsFile() bool

func (*FileInfo) String

func (fi *FileInfo) String() string

type MAClient

type MAClient struct {
	Password string
	Subdir   string //remote subdir
	RootPath string //local root path

	sync.Mutex
	Version
	// contains filtered or unexported fields
}

mfs master client

func NewMAClient

func NewMAClient(addr string) *MAClient

func NewMAClientPwd

func NewMAClientPwd(addr, pwd string, heartbeat bool) (c *MAClient)

func NewTools

func NewTools(addr string) *MAClient

func (*MAClient) Access

func (c *MAClient) Access(inode uint32, mode uint16) (err error)

func (*MAClient) AllQuotaInfo

func (c *MAClient) AllQuotaInfo() (quota QuotaInfoMap, err error)

func (*MAClient) Chmod

func (c *MAClient) Chmod(inode uint32, mode uint16) (fi *FileInfo, err error)

func (*MAClient) Chown

func (c *MAClient) Chown(inode uint32, uid, gid uint32) (fi *FileInfo, err error)

func (*MAClient) Close

func (c *MAClient) Close()

func (*MAClient) CloseSession

func (c *MAClient) CloseSession() (err error)

func (*MAClient) Connect

func (c *MAClient) Connect() (err error)

func (*MAClient) Create

func (c *MAClient) Create(parent uint32, name string,
	mode uint16) (fi *FileInfo, err error)

mknod and open

func (*MAClient) CreateSession

func (c *MAClient) CreateSession() (err error)

func (*MAClient) GetAttr

func (c *MAClient) GetAttr(inode uint32) (fi *FileInfo, err error)

func (*MAClient) GetDirStats

func (c *MAClient) GetDirStats(inode uint32) (ds *DirStats, err error)
func (c *MAClient) Link(inode, inodeDst uint32, nameDst string,
) (fi *FileInfo, err error)

func (*MAClient) ListSession

func (c *MAClient) ListSession() (ids []uint32, err error)

func (*MAClient) Lookup

func (c *MAClient) Lookup(parent uint32, name string) (fi *FileInfo, err error)

func (*MAClient) MasterVersion

func (c *MAClient) MasterVersion() error

func (*MAClient) Mkdir

func (c *MAClient) Mkdir(parent uint32, name string,
	mode uint16) (fi *FileInfo, err error)

func (*MAClient) Mknod

func (c *MAClient) Mknod(parent uint32, name string,
	mode uint16) (fi *FileInfo, err error)

func (*MAClient) Open

func (c *MAClient) Open(inode uint32, flags uint8) (fi *FileInfo, err error)

flags 01 read 02 write 04

func (*MAClient) Purge

func (c *MAClient) Purge(inode uint32) (err error)

func (*MAClient) QuotaControl

func (c *MAClient) QuotaControl(info *QuotaInfo, mode QuotaMode) (err error)

func (*MAClient) ReadChunk

func (c *MAClient) ReadChunk(inode, index uint32,
	flags uint8) (cs *CSData, err error)
func (c *MAClient) ReadLink(inode uint32) (path string, err error)

func (*MAClient) Readdir

func (c *MAClient) Readdir(parent uint32) (infoMap ReaddirInfoMap, err error)

func (*MAClient) ReaddirAttr

func (c *MAClient) ReaddirAttr(parent uint32) (infoMap ReaddirInfoAttrMap, err error)

func (*MAClient) Recv

func (c *MAClient) Recv(buf []byte) (n int, err error)

func (*MAClient) RemoveSession

func (c *MAClient) RemoveSession(sessionId uint32) (err error)

func (*MAClient) Rename

func (c *MAClient) Rename(inodeSrc uint32, nameSrc string, inodeDst uint32,
	nameDst string) (fi *FileInfo, err error)

func (*MAClient) Rmdir

func (c *MAClient) Rmdir(parent uint32, name string) (err error)

func (*MAClient) Send

func (c *MAClient) Send(msg []byte) error

func (*MAClient) SetAttr

func (c *MAClient) SetAttr(inode uint32, setmask uint8, mode uint16,
	uid, gid, atime, mtime uint32) (fi *FileInfo, err error)

func (*MAClient) Statfs

func (c *MAClient) Statfs() (st *StatInfo, err error)
func (c *MAClient) Symlink(parent uint32, name string, path string,
) (fi *FileInfo, err error)

func (*MAClient) Truncate

func (c *MAClient) Truncate(inode uint32, flags uint8) (fi *FileInfo, err error)

msgid:32 inode:32 flags:8 uid:32 gcnt:32 gcnt * [ gid:32 ] length:64 (version >= 2.0.89/3.0.25)

func (*MAClient) UnPackQuota

func (c *MAClient) UnPackQuota(buf []byte) *QuotaInfo

func (*MAClient) Undel

func (c *MAClient) Undel(inode uint32) (err error)
func (c *MAClient) Unlink(parent uint32, name string) (err error)

func (*MAClient) WriteChunk

func (c *MAClient) WriteChunk(inode, index uint32,
	flags uint8) (cs *CSData, err error)

func (*MAClient) WriteChunkEnd

func (c *MAClient) WriteChunkEnd(chunkId uint64, inode, index uint32,
	length uint64, flags uint8) (err error)

type Mode

type Mode int
const (
	Binary Mode = iota
	Decimal
)

type QuotaInfo

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

func (*QuotaInfo) Usage

func (info *QuotaInfo) Usage() (current, quota string, retio float64)

get the max retio, only care soft quota

type QuotaInfoMap

type QuotaInfoMap map[string]*QuotaInfo

func GetUsage

func GetUsage(masterAddr string) (QuotaInfoMap, error)

get all usage of mfs by sending command to mfs master

type QuotaMode

type QuotaMode int
const (
	QuotaGet QuotaMode = iota
	QuotaSet
	QuotaDel
)

type ReaddirInfo

type ReaddirInfo struct {
	Type  uint8
	Inode uint32
	Name  string
}

type ReaddirInfoAttr

type ReaddirInfoAttr struct {
	Inode uint32
	Name  string
	Info  *FileInfo
}

type ReaddirInfoAttrMap

type ReaddirInfoAttrMap map[uint32]*ReaddirInfoAttr

type ReaddirInfoMap

type ReaddirInfoMap map[uint32]*ReaddirInfo

type StatInfo

type StatInfo struct {
	TotalSpace    uint64
	AvailSpace    uint64
	TrashSpace    uint64
	ReservedSpace uint64
	Inodes        uint32
}

type Version

type Version uint32

func GetVersion

func GetVersion(ver uint32) Version

func ParseVersionInt

func ParseVersionInt(maj uint16, mid, min uint8) Version

func ParseVersionString

func ParseVersionString(str string) Version

func (Version) LessThan

func (v Version) LessThan(maj uint16, mid, min uint8) bool

func (Version) MoreThan

func (v Version) MoreThan(maj uint16, mid, min uint8) bool

func (Version) String

func (v Version) String() string

func (Version) ToInt

func (v Version) ToInt() (maj uint16, mid, min uint8)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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