A method, system, apparatus, and computer-readable medium are provided for
synchronizing I/O operations in a computer system. According to aspects
of the invention, multiple reader and writer locks are provided that may
be acquired by calling processes at two different granularities. Locks
may be acquired for an area of storage equivalent to the logical unit of
allocation or for a sub-provision area equivalent to a unit of snapshot
read-modify-write. Each lock is represented by a lock data structure that
represents the same amount of logical address space as the logical unit
of allocation. A request that arrives to the lock data structure is made
to wait in a lock wait queue until the request can be honored. Requests
that have been honored but that have not yet released the lock are
maintained in a dispatch queue. When a writer lock is assigned to a lock
request, no other readers or writers may be allocated to it. When a
reader lock is assigned to a lock request, the lock may also be given to
other readers, but not to a writer. A round robin technique is utilized
to respond to requests for locks so that one lock does not starve the
other locks.