Browse Source

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 <vgoyal@redhat.com>
Vivek Goyal 10 years ago
parent
commit
665656afbb
1 changed files with 7 additions and 7 deletions
  1. 7 7
      pkg/devicemapper/devmapper.go

+ 7 - 7
pkg/devicemapper/devmapper.go

@@ -284,9 +284,9 @@ func FindLoopDeviceFor(file *os.File) *os.File {
 	return nil
 	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 ErrUdevWait
 	}
 	}
 	return nil
 	return nil
@@ -358,7 +358,7 @@ func RemoveDevice(name string) error {
 	if err := task.SetCookie(&cookie, 0); err != nil {
 	if err := task.SetCookie(&cookie, 0); err != nil {
 		return fmt.Errorf("Can not set cookie: %s", err)
 		return fmt.Errorf("Can not set cookie: %s", err)
 	}
 	}
-	defer UdevWait(cookie)
+	defer UdevWait(&cookie)
 
 
 	dmSawBusy = false // reset before the task is run
 	dmSawBusy = false // reset before the task is run
 	if err = task.Run(); err != nil {
 	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 {
 	if err := task.SetCookie(&cookie, flags); err != nil {
 		return fmt.Errorf("Can't set cookie %s", err)
 		return fmt.Errorf("Can't set cookie %s", err)
 	}
 	}
-	defer UdevWait(cookie)
+	defer UdevWait(&cookie)
 
 
 	if err := task.Run(); err != nil {
 	if err := task.Run(); err != nil {
 		return fmt.Errorf("Error running DeviceCreate (CreatePool) %s", err)
 		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 {
 	if err := task.SetCookie(&cookie, 0); err != nil {
 		return fmt.Errorf("Can't set cookie %s", err)
 		return fmt.Errorf("Can't set cookie %s", err)
 	}
 	}
-	defer UdevWait(cookie)
+	defer UdevWait(&cookie)
 
 
 	if err := task.Run(); err != nil {
 	if err := task.Run(); err != nil {
 		return fmt.Errorf("Error running DeviceResume %s", err)
 		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)
 		return fmt.Errorf("Can't set cookie %s", err)
 	}
 	}
 
 
-	defer UdevWait(cookie)
+	defer UdevWait(&cookie)
 
 
 	if err := task.Run(); err != nil {
 	if err := task.Run(); err != nil {
 		return fmt.Errorf("Error running DeviceCreate (ActivateDevice) %s", err)
 		return fmt.Errorf("Error running DeviceCreate (ActivateDevice) %s", err)