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]] |[[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 ‘<tt>#cvs.rfl.</tt>’ is a read lock. Any file in 29the repository with a name starting with 30‘<tt>#cvs.wfl</tt>’ is a write lock. Old versions of <small>CVS</small> 31(before <small>CVS</small> 1.5) also created files with names starting 32with ‘<tt>#cvs.tfl</tt>’, but they are not discussed here. 33The directory ‘<tt>#cvs.lock</tt>’ 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 ‘<tt>#cvs.lock</tt>’ 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 ‘<tt>#cvs.lock</tt>’ lock, create a file 43whose name is ‘<tt>#cvs.rfl.</tt>’ followed by information 44of your choice (for example, hostname and process 45identification number). Then remove the 46‘<tt>#cvs.lock</tt>’ directory to release the master lock. 47Then proceed with reading the repository. When you are 48done, remove the ‘<tt>#cvs.rfl</tt>’ file to release the 49read lock. 50 51To obtain a writelock, first create the 52‘<tt>#cvs.lock</tt>’ directory, as with a readlock. Then 53check that there are no files whose names start with 54‘<tt>#cvs.rfl.</tt>’. If there are, remove 55‘<tt>#cvs.lock</tt>’, wait for a while, and try again. If 56there are no readers, then create a file whose name is 57‘<tt>#cvs.wfl</tt>’ followed by information of your choice 58(for example, hostname and process identification 59number). Hang on to the ‘<tt>#cvs.lock</tt>’ lock. Proceed 60with writing the repository. When you are done, first 61remove the ‘<tt>#cvs.wfl</tt>’ file and then the 62‘<tt>#cvs.lock</tt>’ directory. Note that unlike the 63‘<tt>#cvs.rfl</tt>’ file, the ‘<tt>#cvs.wfl</tt>’ file is just 64informational; it has no effect on the locking operation 65beyond what is provided by holding on to the 66‘<tt>#cvs.lock</tt>’ lock itself. 67 68Note that each lock (writelock or readlock) only locks 69a single directory in the repository, including 70‘<tt>Attic</tt>’ and ‘<tt>CVS</tt>’ 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 ‘<tt>foo,v</tt>’ files. <small>RCS</small> has 79a scheme where the ‘<tt>,foo,</tt>’ 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]] |[[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