1 /* util.h --- utility functions for FSFS repo access
3 * ====================================================================
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
20 * ====================================================================
23 #ifndef SVN_LIBSVN_FS__UTIL_H
24 #define SVN_LIBSVN_FS__UTIL_H
29 /* Functions for dealing with recoverable errors on mutable files
31 * Revprops, current, and txn-current files are mutable; that is, they
32 * change as part of normal fsfs operation, in constrat to revs files, or
33 * the format file, which are written once at create (or upgrade) time.
34 * When more than one host writes to the same repository, we will
35 * sometimes see these recoverable errors when accesssing these files.
37 * These errors all relate to NFS, and thus we only use this retry code if
42 * In NFS v3 and under, the server doesn't track opened files. If you
43 * unlink(2) or rename(2) a file held open by another process *on the
44 * same host*, that host's kernel typically renames the file to
45 * .nfsXXXX and automatically deletes that when it's no longer open,
46 * but this behavior is not required.
48 * For obvious reasons, this does not work *across hosts*. No one
49 * knows about the opened file; not the server, and not the deleting
50 * client. So the file vanishes, and the reader gets stale NFS file
55 * Some client implementations (at least the 2.6.18.5 kernel that ships
56 * with Ubuntu Dapper) sometimes give spurious ENOENT (only on open) or
57 * even EIO errors when trying to read these files that have been renamed
58 * over on some other host.
62 * Try open and read of such files in try_stringbuf_from_file(). Call
63 * this function within a loop of SVN_FS_FS__RECOVERABLE_RETRY_COUNT
64 * iterations (though, realistically, the second try will succeed).
67 #define SVN_FS_FS__RECOVERABLE_RETRY_COUNT 10
69 /* Return TRUE is REV is packed in FS, FALSE otherwise. */
71 svn_fs_fs__is_packed_rev(svn_fs_t *fs,
74 /* Return TRUE is REV's props have been packed in FS, FALSE otherwise. */
76 svn_fs_fs__is_packed_revprop(svn_fs_t *fs,
79 /* Return the first revision in the pack / rev file containing REVISION in
80 * filesystem FS. For non-packed revs, this will simply be REVISION. */
82 svn_fs_fs__packed_base_rev(svn_fs_t *fs,
83 svn_revnum_t revision);
85 /* Return the full path of the rev shard directory that will contain
86 * revision REV in FS. Allocate the result in POOL.
89 svn_fs_fs__path_rev_shard(svn_fs_t *fs,
93 /* Return the full path of the non-packed rev file containing revision REV
94 * in FS. Allocate the result in POOL.
97 svn_fs_fs__path_rev(svn_fs_t *fs,
101 /* Return the path of the pack-related file that for revision REV in FS.
102 * KIND specifies the file name base, e.g. "manifest" or "pack".
103 * The result will be allocated in POOL.
106 svn_fs_fs__path_rev_packed(svn_fs_t *fs,
111 /* Return the full path of the "txn-current" file in FS.
112 * The result will be allocated in POOL.
115 svn_fs_fs__path_txn_current(svn_fs_t *fs,
118 /* Return the full path of the "txn-current-lock" file in FS.
119 * The result will be allocated in POOL.
122 svn_fs_fs__path_txn_current_lock(svn_fs_t *fs,
125 /* Return the full path of the global write lock file in FS.
126 * The result will be allocated in POOL.
129 svn_fs_fs__path_lock(svn_fs_t *fs,
132 /* Return the full path of the pack operation lock file in FS.
133 * The result will be allocated in POOL.
136 svn_fs_fs__path_pack_lock(svn_fs_t *fs,
139 /* Return the full path of the revprop generation file in FS.
140 * Allocate the result in POOL.
143 svn_fs_fs__path_revprop_generation(svn_fs_t *fs,
146 /* Return the full path of the revision properties pack shard directory
147 * that will contain the packed properties of revision REV in FS.
148 * Allocate the result in POOL.
151 svn_fs_fs__path_revprops_pack_shard(svn_fs_t *fs,
155 /* Set *PATH to the path of REV in FS, whether in a pack file or not.
156 Allocate *PATH in POOL.
158 Note: If the caller does not have the write lock on FS, then the path is
159 not guaranteed to be correct or to remain correct after the function
160 returns, because the revision might become packed before or after this
161 call. If a file exists at that path, then it is correct; if not, then
162 the caller should call update_min_unpacked_rev() and re-try once. */
164 svn_fs_fs__path_rev_absolute(svn_fs_t *fs,
168 /* Return the full path of the revision properties shard directory that
169 * will contain the properties of revision REV in FS.
170 * Allocate the result in POOL.
173 svn_fs_fs__path_revprops_shard(svn_fs_t *fs,
177 /* Return the full path of the non-packed revision properties file that
178 * contains the props for revision REV in FS. Allocate the result in POOL.
181 svn_fs_fs__path_revprops(svn_fs_t *fs,
185 /* Return the path of the file storing the oldest non-packed revision in FS.
186 * The result will be allocated in POOL.
189 svn_fs_fs__path_min_unpacked_rev(svn_fs_t *fs,
192 /* Return the path of the 'transactions' directory in FS.
193 * The result will be allocated in POOL.
196 svn_fs_fs__path_txns_dir(svn_fs_t *fs,
199 /* Return the path of the directory containing the transaction TXN_ID in FS.
200 * The result will be allocated in POOL.
203 svn_fs_fs__path_txn_dir(svn_fs_t *fs,
204 const svn_fs_fs__id_part_t *txn_id,
207 /* Return the path of the 'txn-protorevs' directory in FS, even if that
208 * folder may not exist in FS. The result will be allocated in POOL.
211 svn_fs_fs__path_txn_proto_revs(svn_fs_t *fs,
214 /* Return the path of the proto-revision file for transaction TXN_ID in FS.
215 * The result will be allocated in POOL.
218 svn_fs_fs__path_txn_proto_rev(svn_fs_t *fs,
219 const svn_fs_fs__id_part_t *txn_id,
222 /* Return the path of the proto-revision lock file for transaction TXN_ID
223 * in FS. The result will be allocated in POOL.
226 svn_fs_fs__path_txn_proto_rev_lock(svn_fs_t *fs,
227 const svn_fs_fs__id_part_t *txn_id,
230 /* Return the path of the file containing the in-transaction node revision
231 * identified by ID in FS. The result will be allocated in POOL.
234 svn_fs_fs__path_txn_node_rev(svn_fs_t *fs,
235 const svn_fs_id_t *id,
238 /* Return the path of the file containing the in-transaction properties of
239 * the node identified by ID in FS. The result will be allocated in POOL.
242 svn_fs_fs__path_txn_node_props(svn_fs_t *fs,
243 const svn_fs_id_t *id,
246 /* Return the path of the file containing the directory entries of the
247 * in-transaction directory node identified by ID in FS.
248 * The result will be allocated in POOL.
251 svn_fs_fs__path_txn_node_children(svn_fs_t *fs,
252 const svn_fs_id_t *id,
255 /* Return the path of the file containing the log-to-phys index for
256 * the transaction identified by TXN_ID in FS.
257 * The result will be allocated in POOL.
260 svn_fs_fs__path_l2p_proto_index(svn_fs_t *fs,
261 const svn_fs_fs__id_part_t *txn_id,
264 /* Return the path of the file containing the phys-to-log index for
265 * the transaction identified by TXN_ID in FS.
266 * The result will be allocated in POOL.
269 svn_fs_fs__path_p2l_proto_index(svn_fs_t *fs,
270 const svn_fs_fs__id_part_t *txn_id,
273 /* Return the path of the file containing item_index counter for
274 * the transaction identified by TXN_ID in FS.
275 * The result will be allocated in POOL.
278 svn_fs_fs__path_txn_item_index(svn_fs_t *fs,
279 const svn_fs_fs__id_part_t *txn_id,
282 /* Return the path of the file containing the node origins cachs for
283 * the given NODE_ID in FS. The result will be allocated in POOL.
286 svn_fs_fs__path_node_origin(svn_fs_t *fs,
287 const svn_fs_fs__id_part_t *node_id,
290 /* Set *MIN_UNPACKED_REV to the integer value read from the file returned
291 * by #svn_fs_fs__path_min_unpacked_rev() for FS.
292 * Use POOL for temporary allocations.
295 svn_fs_fs__read_min_unpacked_rev(svn_revnum_t *min_unpacked_rev,
299 /* Check that BUF, a nul-terminated buffer of text from file PATH,
300 contains only digits at OFFSET and beyond, raising an error if not.
301 TITLE contains a user-visible description of the file, usually the
304 Uses POOL for temporary allocation. */
306 svn_fs_fs__check_file_buffer_numeric(const char *buf,
312 /* Re-read the MIN_UNPACKED_REV member of FS from disk.
313 * Use POOL for temporary allocations.
316 svn_fs_fs__update_min_unpacked_rev(svn_fs_t *fs,
319 /* Atomically update the 'min-unpacked-rev' file in FS to hold the specifed
320 * REVNUM. Perform temporary allocations in SCRATCH_POOL.
323 svn_fs_fs__write_min_unpacked_rev(svn_fs_t *fs,
325 apr_pool_t *scratch_pool);
327 /* Set *REV, *NEXT_NODE_ID and *NEXT_COPY_ID to the values read from the
328 * 'current' file. For new FS formats, which only store the youngest
329 * revision, set the *NEXT_NODE_ID and *NEXT_COPY_ID to 0. Perform
330 * temporary allocations in POOL.
333 svn_fs_fs__read_current(svn_revnum_t *rev,
334 apr_uint64_t *next_node_id,
335 apr_uint64_t *next_copy_id,
339 /* Atomically update the 'current' file to hold the specifed REV,
340 NEXT_NODE_ID, and NEXT_COPY_ID. (The two next-ID parameters are
341 ignored and may be 0 if the FS format does not use them.)
342 Perform temporary allocations in POOL. */
344 svn_fs_fs__write_current(svn_fs_t *fs,
346 apr_uint64_t next_node_id,
347 apr_uint64_t next_copy_id,
350 /* Read the file at PATH and return its content in *CONTENT. *CONTENT will
351 * not be modified unless the whole file was read successfully.
353 * ESTALE, EIO and ENOENT will not cause this function to return an error
354 * unless LAST_ATTEMPT has been set. If MISSING is not NULL, indicate
355 * missing files (ENOENT) there.
357 * Use POOL for allocations.
360 svn_fs_fs__try_stringbuf_from_file(svn_stringbuf_t **content,
361 svn_boolean_t *missing,
363 svn_boolean_t last_attempt,
366 /* Read the file FNAME and store the contents in *BUF.
367 Allocations are performed in POOL. */
369 svn_fs_fs__read_content(svn_stringbuf_t **content,
373 /* Reads a line from STREAM and converts it to a 64 bit integer to be
374 * returned in *RESULT. If we encounter eof, set *HIT_EOF and leave
375 * *RESULT unchanged. If HIT_EOF is NULL, EOF causes an "corrupt FS"
377 * SCRATCH_POOL is used for temporary allocations.
380 svn_fs_fs__read_number_from_stream(apr_int64_t *result,
381 svn_boolean_t *hit_eof,
382 svn_stream_t *stream,
383 apr_pool_t *scratch_pool);
385 /* Move a file into place from OLD_FILENAME in the transactions
386 directory to its final location NEW_FILENAME in the repository. On
387 Unix, match the permissions of the new file to the permissions of
388 PERMS_REFERENCE. Temporary allocations are from POOL.
390 This function almost duplicates svn_io_file_move(), but it tries to
391 guarantee a flush if FLUSH_TO_DISK is non-zero. */
393 svn_fs_fs__move_into_place(const char *old_filename,
394 const char *new_filename,
395 const char *perms_reference,
396 svn_boolean_t flush_to_disk,
399 /* Return TRUE, iff FS uses logical addressing. */
401 svn_fs_fs__use_log_addressing(svn_fs_t *fs);