1<div id="Locks"></div>
2<div class="header">
3<p>
4Next: [[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>
5</div>
6
7----
8
9<div id="CVS-locks-in-the-repository"></div>
10==== CVS locks in the repository ====
11
12<div id="index-_0023cvs_002erfl_002c-technical-details"></div>
13<div id="index-_0023cvs_002ewfl_002c-technical-details"></div>
14<div id="index-_0023cvs_002elock_002c-technical-details"></div>
15<div id="index-Locks_002c-cvs_002c-technical-details"></div>
16For an introduction to <small>CVS</small> locks focusing on
17user-visible behavior, see [[cvs: Several developers simultaneously attempting to run CVS#Several developers simultaneously attempting to run CVS|Concurrency]].  The
18following section is aimed at people who are writing
19tools which want to access a <small>CVS</small> repository without
20interfering with other tools accessing the same
21repository.  If you find yourself confused by concepts
22described here, like <em>read lock</em>, <em>write lock</em>,
23and <em>deadlock</em>, you might consult the literature on
24operating systems or databases.
25
26<div id="index-_0023cvs_002etfl"></div>
27Any file in the repository with a name starting
28with &lsquo;<tt>#cvs.rfl.</tt>&rsquo; is a read lock.  Any file in
29the repository with a name starting with
30&lsquo;<tt>#cvs.wfl</tt>&rsquo; is a write lock.  Old versions of <small>CVS</small>
31(before <small>CVS</small> 1.5) also created files with names starting
32with &lsquo;<tt>#cvs.tfl</tt>&rsquo;, but they are not discussed here.
33The directory &lsquo;<tt>#cvs.lock</tt>&rsquo; serves as a master
34lock.  That is, one must obtain this lock first before
35creating any of the other locks.
36
37To obtain a readlock, first create the &lsquo;<tt>#cvs.lock</tt>&rsquo;
38directory.  This operation must be atomic (which should
39be true for creating a directory under most operating
40systems).  If it fails because the directory already
41existed, wait for a while and try again.  After
42obtaining the &lsquo;<tt>#cvs.lock</tt>&rsquo; lock, create a file
43whose name is &lsquo;<tt>#cvs.rfl.</tt>&rsquo; followed by information
44of your choice (for example, hostname and process
45identification number).  Then remove the
46&lsquo;<tt>#cvs.lock</tt>&rsquo; directory to release the master lock.
47Then proceed with reading the repository.  When you are
48done, remove the &lsquo;<tt>#cvs.rfl</tt>&rsquo; file to release the
49read lock.
50
51To obtain a writelock, first create the
52&lsquo;<tt>#cvs.lock</tt>&rsquo; directory, as with a readlock.  Then
53check that there are no files whose names start with
54&lsquo;<tt>#cvs.rfl.</tt>&rsquo;.  If there are, remove
55&lsquo;<tt>#cvs.lock</tt>&rsquo;, wait for a while, and try again.  If
56there are no readers, then create a file whose name is
57&lsquo;<tt>#cvs.wfl</tt>&rsquo; followed by information of your choice
58(for example, hostname and process identification
59number).  Hang on to the &lsquo;<tt>#cvs.lock</tt>&rsquo; lock.  Proceed
60with writing the repository.  When you are done, first
61remove the &lsquo;<tt>#cvs.wfl</tt>&rsquo; file and then the
62&lsquo;<tt>#cvs.lock</tt>&rsquo; directory. Note that unlike the
63&lsquo;<tt>#cvs.rfl</tt>&rsquo; file, the &lsquo;<tt>#cvs.wfl</tt>&rsquo; file is just
64informational; it has no effect on the locking operation
65beyond what is provided by holding on to the
66&lsquo;<tt>#cvs.lock</tt>&rsquo; lock itself.
67
68Note that each lock (writelock or readlock) only locks
69a single directory in the repository, including
70&lsquo;<tt>Attic</tt>&rsquo; and &lsquo;<tt>CVS</tt>&rsquo; but not including
71subdirectories which represent other directories under
72version control.  To lock an entire tree, you need to
73lock each directory (note that if you fail to obtain
74any lock you need, you must release the whole tree
75before waiting and trying again, to avoid deadlocks).
76
77Note also that <small>CVS</small> expects writelocks to control
78access to individual &lsquo;<tt>foo,v</tt>&rsquo; files.  <small>RCS</small> has
79a scheme where the &lsquo;<tt>,foo,</tt>&rsquo; file serves as a lock,
80but <small>CVS</small> does not implement it and so taking out a
81<small>CVS</small> writelock is recommended.  See the comments at
82rcs_internal_lockfile in the <small>CVS</small> source code for
83further discussion/rationale.
84
85
86----
87
88<div class="header">
89<p>
90Next: [[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>
91</div>
92This document was generated on <i>a sunny day</i> using [http://www.nongnu.org/texi2html/ <i>texi2html</i>].
93