From 7dea1f728ff3abd32ba6f5fdb45ee0c82805edff Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 11 Jun 2020 14:46:25 -0400 Subject: [PATCH] cephfs: add function ParseDefaultConfigEnv to set ceph config from env Similar to the rados function of the same name, ParseDefaultConfigEnv uses the environment to configure the cephfs mount. Signed-off-by: John Mulligan --- cephfs/cephfs.go | 13 +++++++++++++ cephfs/cephfs_test.go | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/cephfs/cephfs.go b/cephfs/cephfs.go index cf773f9..b90f894 100644 --- a/cephfs/cephfs.go +++ b/cephfs/cephfs.go @@ -92,6 +92,19 @@ func (mount *MountInfo) ParseConfigArgv(argv []string) error { return getError(ret) } +// ParseDefaultConfigEnv configures the mount from the default Ceph +// environment variable CEPH_ARGS. +// +// Implements: +// int ceph_conf_parse_env(struct ceph_mount_info *cmount, const char *var); +func (mount *MountInfo) ParseDefaultConfigEnv() error { + if err := mount.validate(); err != nil { + return err + } + ret := C.ceph_conf_parse_env(mount.mount, nil) + 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 da36030..5162827 100644 --- a/cephfs/cephfs_test.go +++ b/cephfs/cephfs_test.go @@ -299,6 +299,26 @@ func TestParseConfigArgv(t *testing.T) { assert.Error(t, err) } +func TestParseDefaultConfigEnv(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 = os.Setenv("CEPH_ARGS", "--log_file /dev/null") + assert.NoError(t, err) + err = mount.ParseDefaultConfigEnv() + 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) +} + func TestValidate(t *testing.T) { mount, err := CreateMount() assert.NoError(t, err)