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:
John Mulligan 2020-03-23 17:00:29 -04:00 committed by John Mulligan
parent 4277d40137
commit 2ad8361692
2 changed files with 11 additions and 3 deletions

View File

@ -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.

View File

@ -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) {