Merge pull request #18 from noahdesu/cephfs

cephfs: add initial cephfs go wrappers
This commit is contained in:
Noah Watkins 2015-05-01 12:42:57 -07:00
commit de82ee54cf
4 changed files with 165 additions and 0 deletions

View File

@ -12,6 +12,7 @@ before_install:
- ceph-deploy install --release giant `hostname`
- ceph-deploy pkg --install librados-dev `hostname`
- ceph-deploy pkg --install librbd-dev `hostname`
- ceph-deploy pkg --install libcephfs-dev `hostname`
- bash ci/micro-osd.sh /tmp/micro-ceph
- export CEPH_CONF=/tmp/micro-ceph/ceph.conf
- ceph status

77
cephfs/cephfs.go Normal file
View File

@ -0,0 +1,77 @@
package cephfs
/*
#cgo LDFLAGS: -lcephfs
#cgo CPPFLAGS: -D_FILE_OFFSET_BITS=64
#include <stdlib.h>
#include <cephfs/libcephfs.h>
*/
import "C"
import "fmt"
import "unsafe"
//
type CephError int
func (e CephError) Error() string {
return fmt.Sprintf("cephfs: ret=%d", e)
}
//
type MountInfo struct {
mount *C.struct_ceph_mount_info
}
func CreateMount() (*MountInfo, error) {
mount := &MountInfo{}
ret := C.ceph_create(&mount.mount, nil)
if ret == 0 {
return mount, nil
} else {
return nil, CephError(ret)
}
}
func (mount *MountInfo) ReadDefaultConfigFile() error {
ret := C.ceph_conf_read_file(mount.mount, nil)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
}
func (mount *MountInfo) Mount() error {
ret := C.ceph_mount(mount.mount, nil)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
}
func (mount *MountInfo) SyncFs() error {
ret := C.ceph_sync_fs(mount.mount)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
}
func (mount *MountInfo) CurrentDir() string {
c_dir := C.ceph_getcwd(mount.mount)
return C.GoString(c_dir)
}
func (mount *MountInfo) ChangeDir(path string) error {
c_path := C.CString(path)
defer C.free(unsafe.Pointer(c_path))
ret := C.ceph_chdir(mount.mount, c_path)
if ret == 0 {
return nil
} else {
return CephError(ret)
}
}

68
cephfs/cephfs_test.go Normal file
View File

@ -0,0 +1,68 @@
package cephfs_test
import "testing"
import "github.com/noahdesu/go-ceph/cephfs"
import "github.com/stretchr/testify/assert"
func TestCreateMount(t *testing.T) {
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
}
func TestMountRoot(t *testing.T) {
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
err = mount.ReadDefaultConfigFile()
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
}
func TestSyncFs(t *testing.T) {
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
err = mount.ReadDefaultConfigFile()
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
err = mount.SyncFs()
assert.NoError(t, err)
}
func TestChangeDir(t *testing.T) {
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
err = mount.ReadDefaultConfigFile()
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
err = mount.ChangeDir("/")
assert.NoError(t, err)
}
func TestCurrentDir(t *testing.T) {
mount, err := cephfs.CreateMount()
assert.NoError(t, err)
assert.NotNil(t, mount)
err = mount.ReadDefaultConfigFile()
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
dir := mount.CurrentDir()
assert.NotNil(t, dir)
}

View File

@ -81,6 +81,25 @@ ceph osd crush add osd.${OSD_ID} 1 root=default host=localhost
ceph-osd --id ${OSD_ID} --mkjournal --mkfs
ceph-osd --id ${OSD_ID}
# single mds
MDS_DATA=${DIR}/mds.a
mkdir ${MDS_DATA}
cat >> $DIR/ceph.conf <<EOF
[mds.a]
mds data = ${MDS_DATA}
mds log max segments = 2
mds cache size = 10000
host = localhost
EOF
ceph-authtool --create-keyring --gen-key --name=mds.a ${MDS_DATA}/keyring
ceph -i ${MDS_DATA}/keyring auth add mds.a mon 'allow profile mds' osd 'allow *' mds 'allow'
ceph osd pool create cephfs_data 8
ceph osd pool create cephfs_metadata 8
ceph fs new cephfs cephfs_metadata cephfs_data
ceph-mds -i a
# check that it works
rados --pool rbd put group /etc/group
rados --pool rbd get group ${DIR}/group