1 /* batch_fsync.h --- efficiently fsync multiple targets
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_X__BATCH_FSYNC_H
24 #define SVN_LIBSVN_FS_X__BATCH_FSYNC_H
26 #include "svn_error.h"
28 /* Infrastructure for efficiently calling fsync on files and directories.
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.
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.
39 * To minimize the delay caused by the batch flush, run all fsync calls
40 * concurrently - if the OS supports multi-threading.
43 /* Opaque container type.
45 typedef struct svn_fs_x__batch_fsync_t svn_fs_x__batch_fsync_t;
47 /* Initialize the concurrent fsync infrastructure. Clean it up when
48 * OWNING_POOL gets cleared.
50 * This function must be called before using any of the other functions in
51 * in this module. It should only be called once.
54 svn_fs_x__batch_fsync_init(apr_pool_t *owning_pool);
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
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);
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.
68 * Use SCRATCH_POOL for temporaries. */
70 svn_fs_x__batch_fsync_open_file(apr_file_t **file,
71 svn_fs_x__batch_fsync_t *batch,
73 apr_pool_t *scratch_pool);
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.
80 * Use SCRATCH_POOL for temporaries. */
82 svn_fs_x__batch_fsync_new_path(svn_fs_x__batch_fsync_t *batch,
84 apr_pool_t *scratch_pool);
86 /* For all files and directories in BATCH, flush all changes to disk and
87 * close the file handles. Use SCRATCH_POOL for temporaries. */
89 svn_fs_x__batch_fsync_run(svn_fs_x__batch_fsync_t *batch,
90 apr_pool_t *scratch_pool);