[flashrom] [Patch] Add coarse-grained IPC locking mechanism to Flashrom

David Hendricks dhendrix at google.com
Tue Feb 1 22:37:42 CET 2011


Hi,
I have attached a patch which adds a locking mechanism to Flashrom to
prevent multiple instances from running simultaneously. It may need some
modification to fit different Flashrom use cases better, but I think it's a
good start.

The size of the patch is somewhat misleading -- The only real changes to
Flashrom's current code are some of the exit points in cli_classic() and
some added stuff in the Makefile. Everything else is contained in new files.
The new files are:
csem.{c,h}: Low-level code that interfaces with semctl(), semget(), etc.
ipc_lock.{c,h}: Wrapper for csem stuff.
locks.h: A listing of locks that Flashrom cares about.
big_lock.{c,h}: An even higher-level wrapper around ipc_lock stuff, useful
for simple, coarse-grained locking.
util/use_big_lock.sh: Used by the Makefile to test for POSIX.1-2001
compliance.

The advantages of this approach are:
- The semaphore can be shared easily with other processes.
- The semaphore is cleaned automagically in case of abnormal program
termination.
- Semaphore info can be viewed and managed easily using standard utilities
like ipcs.
- On Linux at least, a second instance of Flashrom will automatically begin
immediately after the first instance is done. No busy waiting, no excessive
delays.
- We avoid errata with other locking mechanisms (there are known issues with
flock(), for example).

Disadvantages:
- The current patch is very coarse-grained, which could be problematic for
people who wish to flash multiple chips simultaneously.
- Requires >= POSIX.1-2001 compliance.

Please note that some files in this patch are BSD-licensed. Much of it is
based off code which was open-sourced by Sun Microsystems, after acquiring
it from Cobalt Networks.

Signed-off-by: David Hendricks <dhendrix at google.com>

-- 
David Hendricks (dhendrix)
Systems Software Engineer, Google Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.flashrom.org/pipermail/flashrom/attachments/20110201/e082ba95/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ipc_lock.patch
Type: text/x-patch
Size: 25305 bytes
Desc: not available
URL: <http://www.flashrom.org/pipermail/flashrom/attachments/20110201/e082ba95/attachment.patch>


More information about the flashrom mailing list