From 6d3c5e3bd47dd18f3f6ca212138c8dec7757578b Mon Sep 17 00:00:00 2001 From: Faruk Kasumovic Date: Fri, 9 Nov 2018 16:08:20 +0100 Subject: [PATCH] Prevent race condition on zfs-linux internal implementation of access to mnttab --- zfs.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/zfs.go b/zfs.go index 4956c05..17f2456 100644 --- a/zfs.go +++ b/zfs.go @@ -182,8 +182,10 @@ func DatasetCreate(path string, dtype DatasetType, // and cleanup dataset object/s from memory) func (d *Dataset) Close() { // path, _ := d.Path() + Global.Mtx.Lock() C.dataset_list_close(d.list) d.list = nil + Global.Mtx.Unlock() for _, cd := range d.Children { cd.Close() } @@ -320,6 +322,8 @@ func (d *Dataset) GetProperty(p Prop) (prop Property, err error) { err = errors.New(msgDatasetIsNil) return } + Global.Mtx.Lock() + defer Global.Mtx.Unlock() plist := C.read_dataset_property(d.list, C.int(p)) if plist == nil { err = LastError() @@ -492,6 +496,8 @@ func (d *Dataset) IsMounted() (mounted bool, where string) { if d.list == nil { return } + Global.Mtx.Lock() + defer Global.Mtx.Unlock() mp := C.dataset_is_mounted(d.list) // defer C.free(mp) if mounted = (mp != nil); mounted { @@ -503,6 +509,8 @@ func (d *Dataset) IsMounted() (mounted bool, where string) { // Mount the given filesystem. func (d *Dataset) Mount(options string, flags int) (err error) { + Global.Mtx.Lock() + defer Global.Mtx.Unlock() if d.list == nil { err = errors.New(msgDatasetIsNil) return