mirror of https://github.com/ceph/go-ceph
cephfs: make the Release function more idempotent to callers
Previously, calling Release more than once for the same MountInfo would abort due to a double free in the ceph libs. As this is somewhat user hostile we add some simple state tracking in our wrapper type such that one can make redundant calls to Release without crashing the application. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
4277d40137
commit
2ad8361692
|
@ -155,8 +155,15 @@ func (mount *MountInfo) Unmount() error {
|
|||
// Implements:
|
||||
// int ceph_release(struct ceph_mount_info *cmount);
|
||||
func (mount *MountInfo) Release() error {
|
||||
if mount.mount == nil {
|
||||
return nil
|
||||
}
|
||||
ret := C.ceph_release(mount.mount)
|
||||
return getError(ret)
|
||||
if err := getError(ret); err != nil {
|
||||
return err
|
||||
}
|
||||
mount.mount = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// SyncFs synchronizes all filesystem data to persistent media.
|
||||
|
|
|
@ -187,8 +187,9 @@ func TestReleaseMount(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
require.NotNil(t, mount)
|
||||
|
||||
err = mount.Release()
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, mount.Release())
|
||||
// call release again to ensure idempotency of the func
|
||||
assert.NoError(t, mount.Release())
|
||||
}
|
||||
|
||||
func TestChmodDir(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue