cephfs: add functions for Init and SetMountPerms

The Init functions initializes the connection without mounting the fs.
This function must be called before setting the perms but before
creating the mount.

SetMountPerms accepts a UserPerm object to set the fs ownership info
on the mount. The corresponding tests verifies that the UserPerm
can be applied and it effects the gid of newly created dirs for that
mount.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-03-24 19:56:53 -04:00 committed by Niels de Vos
parent e1bbd45b5c
commit 29c88f4b2d
3 changed files with 75 additions and 0 deletions

View File

@ -96,6 +96,14 @@ func (mount *MountInfo) GetConfigOption(option string) (string, error) {
return value, nil
}
// Init the file system client without actually mounting the file system.
//
// Implements:
// int ceph_init(struct ceph_mount_info *cmount);
func (mount *MountInfo) Init() error {
return getError(C.ceph_init(mount.mount))
}
// Mount the file system, establishing a connection capable of I/O.
//
// Implements:

View File

@ -0,0 +1,22 @@
// +build !luminous
//
// ceph_mount_perms_set available in mimic & later
package cephfs
/*
#cgo LDFLAGS: -lcephfs
#cgo CPPFLAGS: -D_FILE_OFFSET_BITS=64
#include <cephfs/libcephfs.h>
*/
import "C"
// SetMountPerms applies the given UserPerm to the mount object, which it will
// then use to define the connection's ownership credentials.
// This function must be called after Init but before Mount.
//
// Implements:
// int ceph_mount_perms_set(struct ceph_mount_info *cmount, UserPerm *perm);
func (mount *MountInfo) SetMountPerms(perm *UserPerm) error {
return getError(C.ceph_mount_perms_set(mount.mount, perm.userPerm))
}

View File

@ -0,0 +1,45 @@
// +build !luminous
package cephfs
import (
"os"
"path"
"syscall"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestSetMountPerms(t *testing.T) {
mount, err := CreateMount()
require.NoError(t, err)
require.NotNil(t, mount)
defer func() { assert.NoError(t, mount.Release()) }()
err = mount.ReadDefaultConfigFile()
require.NoError(t, err)
err = mount.Init()
assert.NoError(t, err)
uperm := NewUserPerm(0, 500, []int{0, 500, 501})
err = mount.SetMountPerms(uperm)
assert.NoError(t, err)
err = mount.Mount()
assert.NoError(t, err)
defer func() { assert.NoError(t, mount.Unmount()) }()
t.Run("checkStat", func(t *testing.T) {
useMount(t)
dirname := "/check-mount-perms"
err := mount.MakeDir(dirname, 0755)
assert.NoError(t, err)
defer mount.RemoveDir(dirname)
s, err := os.Stat(path.Join(CephMountDir, dirname))
require.NoError(t, err)
assert.EqualValues(t, s.Sys().(*syscall.Stat_t).Gid, 500)
})
}