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>
... | ... |
@@ -284,9 +284,9 @@ func FindLoopDeviceFor(file *os.File) *os.File { |
284 | 284 |
return nil |
285 | 285 |
} |
286 | 286 |
|
287 |
-func UdevWait(cookie uint) error { |
|
288 |
- if res := DmUdevWait(cookie); res != 1 { |
|
289 |
- logrus.Debugf("Failed to wait on udev cookie %d", cookie) |
|
287 |
+func UdevWait(cookie *uint) error { |
|
288 |
+ if res := DmUdevWait(*cookie); res != 1 { |
|
289 |
+ logrus.Debugf("Failed to wait on udev cookie %d", *cookie) |
|
290 | 290 |
return ErrUdevWait |
291 | 291 |
} |
292 | 292 |
return nil |
... | ... |
@@ -358,7 +358,7 @@ func RemoveDevice(name string) error { |
358 | 358 |
if err := task.SetCookie(&cookie, 0); err != nil { |
359 | 359 |
return fmt.Errorf("Can not set cookie: %s", err) |
360 | 360 |
} |
361 |
- defer UdevWait(cookie) |
|
361 |
+ defer UdevWait(&cookie) |
|
362 | 362 |
|
363 | 363 |
dmSawBusy = false // reset before the task is run |
364 | 364 |
if err = task.Run(); err != nil { |
... | ... |
@@ -425,7 +425,7 @@ func CreatePool(poolName string, dataFile, metadataFile *os.File, poolBlockSize |
425 | 425 |
if err := task.SetCookie(&cookie, flags); err != nil { |
426 | 426 |
return fmt.Errorf("Can't set cookie %s", err) |
427 | 427 |
} |
428 |
- defer UdevWait(cookie) |
|
428 |
+ defer UdevWait(&cookie) |
|
429 | 429 |
|
430 | 430 |
if err := task.Run(); err != nil { |
431 | 431 |
return fmt.Errorf("Error running DeviceCreate (CreatePool) %s", err) |
... | ... |
@@ -556,7 +556,7 @@ func ResumeDevice(name string) error { |
556 | 556 |
if err := task.SetCookie(&cookie, 0); err != nil { |
557 | 557 |
return fmt.Errorf("Can't set cookie %s", err) |
558 | 558 |
} |
559 |
- defer UdevWait(cookie) |
|
559 |
+ defer UdevWait(&cookie) |
|
560 | 560 |
|
561 | 561 |
if err := task.Run(); err != nil { |
562 | 562 |
return fmt.Errorf("Error running DeviceResume %s", err) |
... | ... |
@@ -632,7 +632,7 @@ func ActivateDevice(poolName string, name string, deviceId int, size uint64) err |
632 | 632 |
return fmt.Errorf("Can't set cookie %s", err) |
633 | 633 |
} |
634 | 634 |
|
635 |
- defer UdevWait(cookie) |
|
635 |
+ defer UdevWait(&cookie) |
|
636 | 636 |
|
637 | 637 |
if err := task.Run(); err != nil { |
638 | 638 |
return fmt.Errorf("Error running DeviceCreate (ActivateDevice) %s", err) |