From 95fa549c14994dc386ee1f98c9be4b02ca189c45 Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Fri, 1 May 2015 12:36:20 -0700 Subject: [PATCH 1/2] travis: add mds to micro cluster Signed-off-by: Noah Watkins --- .travis.yml | 1 + ci/micro-osd.sh | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.travis.yml b/.travis.yml index c05ac54..c4fdfb7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/ci/micro-osd.sh b/ci/micro-osd.sh index 7e10ffc..62a158a 100644 --- a/ci/micro-osd.sh +++ b/ci/micro-osd.sh @@ -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 < Date: Fri, 1 May 2015 12:35:40 -0700 Subject: [PATCH 2/2] cephfs: begin cephfs wrappers Signed-off-by: Noah Watkins --- cephfs/cephfs.go | 77 +++++++++++++++++++++++++++++++++++++++++++ cephfs/cephfs_test.go | 68 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 cephfs/cephfs.go create mode 100644 cephfs/cephfs_test.go diff --git a/cephfs/cephfs.go b/cephfs/cephfs.go new file mode 100644 index 0000000..7fe17c7 --- /dev/null +++ b/cephfs/cephfs.go @@ -0,0 +1,77 @@ +package cephfs + +/* +#cgo LDFLAGS: -lcephfs +#cgo CPPFLAGS: -D_FILE_OFFSET_BITS=64 +#include +#include +*/ +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) + } +} diff --git a/cephfs/cephfs_test.go b/cephfs/cephfs_test.go new file mode 100644 index 0000000..7e9bcc6 --- /dev/null +++ b/cephfs/cephfs_test.go @@ -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) +}