devmapper: Call UdevWait() even in failure path

Currently we set up a cookie and upon failure not call UdevWait(). This
does not cleanup the cookie and associated semaphore and system will
soon max out on total number of semaphores.

To avoid this, call UdevWait() even in failure path which in turn will
cleanup associated semaphore.

Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Vincent Batts <vbatts@redhat.com>
This commit is contained in:
Vivek Goyal 2014-11-14 18:15:56 -05:00 committed by Vincent Batts
parent d246e5f28e
commit 17e6f792c7

View file

@ -373,13 +373,12 @@ func CreatePool(poolName string, dataFile, metadataFile *os.File, poolBlockSize
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)
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)
} }
UdevWait(cookie)
return nil return nil
} }
@ -516,13 +515,12 @@ 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)
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)
} }
UdevWait(cookie)
return nil return nil
} }
@ -596,12 +594,12 @@ 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)
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)
} }
UdevWait(cookie)
return nil return nil
} }