From c34501fc6a507e7c2447c3ebd0b241e17c3ae061 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 11 Jun 2020 14:37:51 -0400 Subject: [PATCH] cephfs: add a ParseConfigArgv function The ParseConfigArgv behaves similarly to the same named function in rados. The command line argv value is parsed by ceph libs and used to configure the mount object. Signed-off-by: John Mulligan --- cephfs/cephfs.go | 22 ++++++++++++++++++++++ cephfs/cephfs_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/cephfs/cephfs.go b/cephfs/cephfs.go index 288ab47..cf773f9 100644 --- a/cephfs/cephfs.go +++ b/cephfs/cephfs.go @@ -70,6 +70,28 @@ func (mount *MountInfo) ReadDefaultConfigFile() error { return getError(ret) } +// ParseConfigArgv configures the mount using a unix style command line +// argument vector. +// +// Implements: +// int ceph_conf_parse_argv(struct ceph_mount_info *cmount, int argc, const char **argv); +func (mount *MountInfo) ParseConfigArgv(argv []string) error { + if err := mount.validate(); err != nil { + return err + } + if len(argv) == 0 { + return ErrEmptyArgument + } + cargv := make([]*C.char, len(argv)) + for i := range argv { + cargv[i] = C.CString(argv[i]) + defer C.free(unsafe.Pointer(cargv[i])) + } + + ret := C.ceph_conf_parse_argv(mount.mount, C.int(len(cargv)), &cargv[0]) + return getError(ret) +} + // SetConfigOption sets the value of the configuration option identified by // the given name. // diff --git a/cephfs/cephfs_test.go b/cephfs/cephfs_test.go index ddbd112..da36030 100644 --- a/cephfs/cephfs_test.go +++ b/cephfs/cephfs_test.go @@ -270,6 +270,35 @@ func TestGetSetConfigOption(t *testing.T) { assert.Equal(t, origVal, currVal) } +func TestParseConfigArgv(t *testing.T) { + mount, err := CreateMount() + require.NoError(t, err) + require.NotNil(t, mount) + defer func() { assert.NoError(t, mount.Release()) }() + + origVal, err := mount.GetConfigOption("log_file") + assert.NoError(t, err) + + err = mount.ParseConfigArgv( + []string{"cephfs.test", "--log_file", "/dev/null"}) + assert.NoError(t, err) + + currVal, err := mount.GetConfigOption("log_file") + assert.NoError(t, err) + assert.Equal(t, "/dev/null", currVal) + assert.NotEqual(t, "/dev/null", origVal) + + // ensure that an empty slice triggers an error (not a crash) + err = mount.ParseConfigArgv([]string{}) + assert.Error(t, err) + + // ensure we get an error for an invalid mount value + badMount := &MountInfo{} + err = badMount.ParseConfigArgv( + []string{"cephfs.test", "--log_file", "/dev/null"}) + assert.Error(t, err) +} + func TestValidate(t *testing.T) { mount, err := CreateMount() assert.NoError(t, err)