diff --git a/cephfs/conn_nautilus.go b/cephfs/conn_nautilus.go new file mode 100644 index 0000000..13d1a65 --- /dev/null +++ b/cephfs/conn_nautilus.go @@ -0,0 +1,30 @@ +// +build !luminous,!mimic + +package cephfs + +/* +#cgo LDFLAGS: -lcephfs +#cgo CPPFLAGS: -D_FILE_OFFSET_BITS=64 +#include +*/ +import "C" + +// Some general connectivity and mounting functions are new in +// Ceph Nautilus. + +// GetFsCid returns the cluster ID for a mounted ceph file system. +// If the object does not refer to a mounted file system, an error +// will be returned. +// +// Note: +// Only supported in Ceph Nautilus and newer. +// +// Implements: +// int64_t ceph_get_fs_cid(struct ceph_mount_info *cmount); +func (mount *MountInfo) GetFsCid() (int64, error) { + ret := C.ceph_get_fs_cid(mount.mount) + if ret < 0 { + return 0, getError(C.int(ret)) + } + return int64(ret), nil +} diff --git a/cephfs/conn_nautilus_test.go b/cephfs/conn_nautilus_test.go new file mode 100644 index 0000000..7277d45 --- /dev/null +++ b/cephfs/conn_nautilus_test.go @@ -0,0 +1,32 @@ +// +build !luminous,!mimic + +package cephfs + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestGetFsCid(t *testing.T) { + t.Run("unmounted", func(t *testing.T) { + mount, err := CreateMount() + require.NoError(t, err) + require.NotNil(t, mount) + + err = mount.ReadDefaultConfigFile() + require.NoError(t, err) + + cid, err := mount.GetFsCid() + assert.Error(t, err) + assert.Equal(t, cid, int64(0)) + }) + t.Run("mounted", func(t *testing.T) { + mount := fsConnect(t) + + cid, err := mount.GetFsCid() + assert.NoError(t, err) + assert.GreaterOrEqual(t, cid, int64(0)) + }) +}