Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #18 from noahdesu/cephfs
Browse files Browse the repository at this point in the history
cephfs: add initial cephfs go wrappers
  • Loading branch information
dotnwat committed May 1, 2015
2 parents c7a0450 + 1efdf98 commit de82ee5
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 77 additions & 0 deletions cephfs/cephfs.go
Original file line number Diff line number Diff line change
@@ -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 changes: 68 additions & 0 deletions cephfs/cephfs_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
19 changes: 19 additions & 0 deletions ci/micro-osd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de82ee5

Please sign in to comment.