From 4401f264f94593e339fbbaa8b2384bffcc12482c Mon Sep 17 00:00:00 2001 From: Vivek Goyal Date: Thu, 2 Apr 2015 16:47:14 -0400 Subject: [PATCH] devmapper: Use a pointer as argument to deferred function UdevWait() UdevWait() is deferred and takes uint cookie as an argument. As arguments to deferred functions are calculated at the time of call, it is possible that any update to cookie later by libdm are not taken into account when UdevWait() is called. Hence use a pointer to uint as argument to UdevWait() function. Signed-off-by: Vivek Goyal --- devicemapper/devmapper.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/devicemapper/devmapper.go b/devicemapper/devmapper.go index f750319..bb89f7f 100644 --- a/devicemapper/devmapper.go +++ b/devicemapper/devmapper.go @@ -284,9 +284,9 @@ func FindLoopDeviceFor(file *os.File) *os.File { return nil } -func UdevWait(cookie uint) error { - if res := DmUdevWait(cookie); res != 1 { - logrus.Debugf("Failed to wait on udev cookie %d", cookie) +func UdevWait(cookie *uint) error { + if res := DmUdevWait(*cookie); res != 1 { + logrus.Debugf("Failed to wait on udev cookie %d", *cookie) return ErrUdevWait } return nil @@ -358,7 +358,7 @@ func RemoveDevice(name string) error { if err := task.SetCookie(&cookie, 0); err != nil { return fmt.Errorf("Can not set cookie: %s", err) } - defer UdevWait(cookie) + defer UdevWait(&cookie) dmSawBusy = false // reset before the task is run if err = task.Run(); err != nil { @@ -425,7 +425,7 @@ func CreatePool(poolName string, dataFile, metadataFile *os.File, poolBlockSize if err := task.SetCookie(&cookie, flags); err != nil { return fmt.Errorf("Can't set cookie %s", err) } - defer UdevWait(cookie) + defer UdevWait(&cookie) if err := task.Run(); err != nil { return fmt.Errorf("Error running DeviceCreate (CreatePool) %s", err) @@ -556,7 +556,7 @@ func ResumeDevice(name string) error { if err := task.SetCookie(&cookie, 0); err != nil { return fmt.Errorf("Can't set cookie %s", err) } - defer UdevWait(cookie) + defer UdevWait(&cookie) if err := task.Run(); err != nil { return fmt.Errorf("Error running DeviceResume %s", err) @@ -632,7 +632,7 @@ func ActivateDevice(poolName string, name string, deviceId int, size uint64) err return fmt.Errorf("Can't set cookie %s", err) } - defer UdevWait(cookie) + defer UdevWait(&cookie) if err := task.Run(); err != nil { return fmt.Errorf("Error running DeviceCreate (ActivateDevice) %s", err)