mirror of https://github.com/ceph/go-ceph
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 <jmulligan@redhat.com>
This commit is contained in:
parent
bf0e4723e2
commit
c34501fc6a
|
@ -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.
|
||||
//
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue