<div id="Locks"></div>
<div class="header">
<p>
Next: [[cvs: How files are stored in the CVSROOT directory#How files are stored in the CVSROOT directory|CVSROOT storage]], Previous: [[cvs: The CVS directory in the repository#The CVS directory in the repository|CVS in repository]], Up: [[cvs: How data is stored in the repository#How data is stored in the repository|Repository storage]] &nbsp; |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p>
</div>

----

<div id="CVS-locks-in-the-repository"></div>
==== CVS locks in the repository ====

<div id="index-_0023cvs_002erfl_002c-technical-details"></div>
<div id="index-_0023cvs_002ewfl_002c-technical-details"></div>
<div id="index-_0023cvs_002elock_002c-technical-details"></div>
<div id="index-Locks_002c-cvs_002c-technical-details"></div>
For an introduction to <small>CVS</small> locks focusing on
user-visible behavior, see [[cvs: Several developers simultaneously attempting to run CVS#Several developers simultaneously attempting to run CVS|Concurrency]].  The
following section is aimed at people who are writing
tools which want to access a <small>CVS</small> repository without
interfering with other tools accessing the same
repository.  If you find yourself confused by concepts
described here, like <em>read lock</em>, <em>write lock</em>,
and <em>deadlock</em>, you might consult the literature on
operating systems or databases.

<div id="index-_0023cvs_002etfl"></div>
Any file in the repository with a name starting
with &lsquo;<tt>#cvs.rfl.</tt>&rsquo; is a read lock.  Any file in
the repository with a name starting with
&lsquo;<tt>#cvs.wfl</tt>&rsquo; is a write lock.  Old versions of <small>CVS</small>
(before <small>CVS</small> 1.5) also created files with names starting
with &lsquo;<tt>#cvs.tfl</tt>&rsquo;, but they are not discussed here.
The directory &lsquo;<tt>#cvs.lock</tt>&rsquo; serves as a master
lock.  That is, one must obtain this lock first before
creating any of the other locks.

To obtain a readlock, first create the &lsquo;<tt>#cvs.lock</tt>&rsquo;
directory.  This operation must be atomic (which should
be true for creating a directory under most operating
systems).  If it fails because the directory already
existed, wait for a while and try again.  After
obtaining the &lsquo;<tt>#cvs.lock</tt>&rsquo; lock, create a file
whose name is &lsquo;<tt>#cvs.rfl.</tt>&rsquo; followed by information
of your choice (for example, hostname and process
identification number).  Then remove the
&lsquo;<tt>#cvs.lock</tt>&rsquo; directory to release the master lock.
Then proceed with reading the repository.  When you are
done, remove the &lsquo;<tt>#cvs.rfl</tt>&rsquo; file to release the
read lock.

To obtain a writelock, first create the
&lsquo;<tt>#cvs.lock</tt>&rsquo; directory, as with a readlock.  Then
check that there are no files whose names start with
&lsquo;<tt>#cvs.rfl.</tt>&rsquo;.  If there are, remove
&lsquo;<tt>#cvs.lock</tt>&rsquo;, wait for a while, and try again.  If
there are no readers, then create a file whose name is
&lsquo;<tt>#cvs.wfl</tt>&rsquo; followed by information of your choice
(for example, hostname and process identification
number).  Hang on to the &lsquo;<tt>#cvs.lock</tt>&rsquo; lock.  Proceed
with writing the repository.  When you are done, first
remove the &lsquo;<tt>#cvs.wfl</tt>&rsquo; file and then the
&lsquo;<tt>#cvs.lock</tt>&rsquo; directory. Note that unlike the
&lsquo;<tt>#cvs.rfl</tt>&rsquo; file, the &lsquo;<tt>#cvs.wfl</tt>&rsquo; file is just
informational; it has no effect on the locking operation
beyond what is provided by holding on to the
&lsquo;<tt>#cvs.lock</tt>&rsquo; lock itself.

Note that each lock (writelock or readlock) only locks
a single directory in the repository, including
&lsquo;<tt>Attic</tt>&rsquo; and &lsquo;<tt>CVS</tt>&rsquo; but not including
subdirectories which represent other directories under
version control.  To lock an entire tree, you need to
lock each directory (note that if you fail to obtain
any lock you need, you must release the whole tree
before waiting and trying again, to avoid deadlocks).

Note also that <small>CVS</small> expects writelocks to control
access to individual &lsquo;<tt>foo,v</tt>&rsquo; files.  <small>RCS</small> has
a scheme where the &lsquo;<tt>,foo,</tt>&rsquo; file serves as a lock,
but <small>CVS</small> does not implement it and so taking out a
<small>CVS</small> writelock is recommended.  See the comments at
rcs_internal_lockfile in the <small>CVS</small> source code for
further discussion/rationale.


----

<div class="header">
<p>
Next: [[cvs: How files are stored in the CVSROOT directory#How files are stored in the CVSROOT directory|CVSROOT storage]], Previous: [[cvs: The CVS directory in the repository#The CVS directory in the repository|CVS in repository]], Up: [[cvs: How data is stored in the repository#How data is stored in the repository|Repository storage]] &nbsp; |[[cvs: Index#SEC_Contents|Contents]]||[[cvs: Index#Index|Index]]|</p>
</div>
This document was generated on <i>a sunny day</i> using [http://www.nongnu.org/texi2html/ <i>texi2html</i>].
