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)