hotplug/Linux: use flock based locking
authorZhigang Wang <zhigang.x.wang@oracle.com>
Wed, 4 Jul 2012 14:46:14 +0000 (15:46 +0100)
committerZhigang Wang <zhigang.x.wang@oracle.com>
Wed, 4 Jul 2012 14:46:14 +0000 (15:46 +0100)
commit827fbaa64b1c3540edd202fe393896a6c4775a80
treee71bcbe3075fd95993098f70dfd320614a1bd4fa
parente7e8937625f5a62f8f15a0dcf98546113446675e
hotplug/Linux: use flock based locking

In the normal case of a single domain booting with one disk, the disk hotplug
script will fire once. In this case taking out the lock will never cause a
sleep because there's no other concurrent invocations. If a domain has 4 disks
configured, then the hotplug script will fire 4 times, all 4 invocations at
pretty much the same time. If there is even a little load on the system, the
locking function in the shell script will sleep for a few seconds - as many as
5 seconds, or potentially even time out & fail completely.

If say 4 or even more domains each with 4 disks start up at once, that's 16
invocations of the hotplug script running at once. There will be a lot of
sleep's done & because of the very coarse 1 second granularity the delay can
add up significantly.

The change to using flock() removes the arbitrary 1 second sleep, so the very
instant once hotplug script finishes, another can start & there is no repeated
attempts & failures to lock which would add more delay.

In addition the current locking implementation would allow two processes get
the lock simultaneously if one decided the other had timed out.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Zhigang Wang <zhigang.x.wang@oracle.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
tools/hotplug/Linux/locking.sh