cephfs

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

CephFS backend for Afero

About

Provides an afero filesystem implementation of an CephFS backend.
The backend is connected to with the go-ceph/cephfs package.

How to use

This wrapper indirectly relies on Ceph's C code, so we will authenticate the same way.
That means we need our ceph.conf and keyring files in /etc/ceph/. We set our client name via the CEPH_ARGS environment variable.
See the hack/ directory for a dockerfile and some scripts to run against rook-ceph.


import (
    "os"

    cephfs "github.com/crimsonfez/afero-cephfs"
)

func main() {
    mount, err := cephfs.NewCephFS()
    if err != nil {
        fmt.Println(err.Error())
        os.Exit(1)
    }
    defer mount.Unmount()

    for _, s := range mount.Readdirnames(-1) {
        fmt.Println(s)
    }
}

Testing

The tests rely on a running ceph cluster. See the hack/ dir and the makefile for scripts to connect to a cluster running via rook-ceph.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDirDoesntSupport = errors.New("type of Dir does not support this operation")
	ErrFileNil          = errors.New("cephfs file is nil, is this a directory?")
	ErrDirNil           = errors.New("cephfs dir is nil, is this a file?")
)

Functions

This section is empty.

Types

type File

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

func (*File) Close

func (f *File) Close() error

func (*File) Name

func (f *File) Name() string

func (*File) Read

func (f *File) Read(buf []byte) (int, error)

func (*File) ReadAt

func (f *File) ReadAt(buf []byte, offset int64) (int, error)

func (*File) Readdir

func (f *File) Readdir(count int) ([]os.FileInfo, error)

os.File.Readdir spec: Readdir reads the contents of the directory associated with file and returns a slice of up to n FileInfo values, as would be returned by Lstat, in directory order. Subsequent calls on the same file will yield further FileInfos.

If n > 0, Readdir returns at most n FileInfo structures. In this case, if Readdir returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.

If n <= 0, Readdir returns all the FileInfo from the directory in a single slice. In this case, if Readdir succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdir returns the FileInfo read until that point and a non-nil error.

note: cephfs does not have any restriction on reproducible ordering of directories. if we run into issues with this in the future we'll have to redo this function. That would likely involve having our own read itterator and instead of reading one file at a time, we read them all (-1) and sort them before culling the list to the requested ammount and returning

func (*File) Readdirnames

func (f *File) Readdirnames(count int) ([]string, error)

list items in directory only by name

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

func (*File) Sync

func (f *File) Sync() error

func (*File) Truncate

func (f *File) Truncate(size int64) error

func (*File) Write

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

func (*File) WriteAt

func (f *File) WriteAt(buf []byte, off int64) (int, error)

func (*File) WriteString

func (f *File) WriteString(s string) (int, error)

type FileInfo

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

implements os.FileInfo interface for CephFS.

func (*FileInfo) IsDir

func (info *FileInfo) IsDir() bool

func (*FileInfo) ModTime

func (info *FileInfo) ModTime() time.Time

func (*FileInfo) Mode

func (info *FileInfo) Mode() os.FileMode

func (*FileInfo) Name

func (info *FileInfo) Name() string

func (*FileInfo) Size

func (info *FileInfo) Size() int64

func (*FileInfo) Sys

func (info *FileInfo) Sys() interface{}

type Fs

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

func NewCephFS

func NewCephFS() (*Fs, error)

func ToAferoFS

func ToAferoFS(cephfsys *gocephfs.MountInfo) *Fs

func (*Fs) Chmod

func (fs *Fs) Chmod(path string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func (*Fs) Chown

func (fs *Fs) Chown(path string, uid int, gid int) error

Chown changes the uid and gid of the named file.

func (*Fs) Chtimes

func (fs *Fs) Chtimes(path string, atime time.Time, mtime time.Time) error

Chtimes changes the access and modification times of the named file

func (*Fs) Create

func (fs *Fs) Create(path string) (afero.File, error)

Create creates a file in the filesystem, returning the file and an error, if any happens.

func (*Fs) Mkdir

func (fs *Fs) Mkdir(path string, perm os.FileMode) error

Mkdir creates a directory in the filesystem, return an error if any happens.

func (*Fs) MkdirAll

func (fs *Fs) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory path and all parents that does not exist yet.

func (*Fs) Name

func (fs *Fs) Name() string

The name of this FileSystem

func (*Fs) Open

func (fs *Fs) Open(path string) (afero.File, error)

Open opens a file, returning it or an error, if any happens.

func (*Fs) OpenFile

func (fs *Fs) OpenFile(path string, flag int, perm os.FileMode) (afero.File, error)

OpenFile opens a file using the given flags and the given mode.

func (*Fs) Remove

func (fs *Fs) Remove(path string) error

Remove removes a file identified by name, returning an error, if any happens.

func (*Fs) RemoveAll

func (fs *Fs) RemoveAll(path string) error

RemoveAll removes a directory path and any children it contains. It does not fail if the path does not exist (return nil).

func (*Fs) Rename

func (fs *Fs) Rename(oldPath, newPath string) error

Rename renames a file.

func (*Fs) Stat

func (fs *Fs) Stat(path string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file, or an error, if any happens.

func (*Fs) Unmount

func (fs *Fs) Unmount() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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