]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - subversion/libsvn_fs_x/batch_fsync.h
Import Subversion-1.10.0
[FreeBSD/FreeBSD.git] / subversion / libsvn_fs_x / batch_fsync.h
1 /* batch_fsync.h --- efficiently fsync multiple targets
2  *
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  *    under the License.
20  * ====================================================================
21  */
22
23 #ifndef SVN_LIBSVN_FS_X__BATCH_FSYNC_H
24 #define SVN_LIBSVN_FS_X__BATCH_FSYNC_H
25
26 #include "svn_error.h"
27
28 /* Infrastructure for efficiently calling fsync on files and directories.
29  *
30  * The idea is to have a container of open file handles (including
31  * directory handles on POSIX), at most one per file.  During the course
32  * of an FS operation that needs to be fsync'ed, all touched files and
33  * folders accumulate in the container.
34  *
35  * At the end of the FS operation, all file changes will be written the
36  * physical disk, once per file and folder.  Afterwards, all handles will
37  * be closed and the container is ready for reuse.
38  *
39  * To minimize the delay caused by the batch flush, run all fsync calls
40  * concurrently - if the OS supports multi-threading.
41  */
42
43 /* Opaque container type.
44  */
45 typedef struct svn_fs_x__batch_fsync_t svn_fs_x__batch_fsync_t;
46
47 /* Initialize the concurrent fsync infrastructure.  Clean it up when
48  * OWNING_POOL gets cleared.
49  *
50  * This function must be called before using any of the other functions in
51  * in this module.  It should only be called once.
52  */
53 svn_error_t *
54 svn_fs_x__batch_fsync_init(apr_pool_t *owning_pool);
55
56 /* Set *RESULT_P to a new batch fsync structure, allocated in RESULT_POOL.
57  * If FLUSH_TO_DISK is not set, the resulting struct will not actually use
58  * fsync. */
59 svn_error_t *
60 svn_fs_x__batch_fsync_create(svn_fs_x__batch_fsync_t **result_p,
61                              svn_boolean_t flush_to_disk,
62                              apr_pool_t *result_pool);
63
64 /* Open the file at FILENAME for read and write access.  Return it in *FILE
65  * and schedule it for fsync in BATCH.  If BATCH already contains an open
66  * file for FILENAME, return that instead creating a new instance.
67  *
68  * Use SCRATCH_POOL for temporaries. */
69 svn_error_t *
70 svn_fs_x__batch_fsync_open_file(apr_file_t **file,
71                                 svn_fs_x__batch_fsync_t *batch,
72                                 const char *filename,
73                                 apr_pool_t *scratch_pool);
74
75 /* Inform the BATCH that a file or directory has been created at PATH.
76  * "Created" means either newly created to renamed to PATH - even if another
77  * item with the same name existed before.  Depending on the OS, the correct
78  * path will scheduled for fsync.
79  *
80  * Use SCRATCH_POOL for temporaries. */
81 svn_error_t *
82 svn_fs_x__batch_fsync_new_path(svn_fs_x__batch_fsync_t *batch,
83                                const char *path,
84                                apr_pool_t *scratch_pool);
85
86 /* For all files and directories in BATCH, flush all changes to disk and
87  * close the file handles.  Use SCRATCH_POOL for temporaries. */
88 svn_error_t *
89 svn_fs_x__batch_fsync_run(svn_fs_x__batch_fsync_t *batch,
90                           apr_pool_t *scratch_pool);
91
92 #endif