This repository has been archived by the owner on Jan 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from noahdesu/cephfs
cephfs: add initial cephfs go wrappers
- Loading branch information
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters