1 /* Copyright (c) 2013 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #ifndef ASYNC_APPEND_H
17 #define ASYNC_APPEND_H 1
21 /* This module defines a simple, abstract interface to asynchronous file I/O.
22 * It is currently used only for logging. Thus, for now the interface only
23 * supports appending to a file. Multiple implementations are possible
24 * depending on the operating system's degree and form of support for
27 * The comments below document the requirements on any implementation.
32 * Only a single thread may use a given 'struct async_append' at one time.
35 /* Creates and returns a new asynchronous appender for file descriptor 'fd',
36 * which the caller must have opened in append mode (O_APPEND). If the system
37 * is for some reason unable to support asynchronous I/O on 'fd' this function
39 struct async_append *async_append_create(int fd);
41 /* Destroys 'ap', without closing its underlying file descriptor. */
42 void async_append_destroy(struct async_append *ap);
44 /* Appends the 'size' bytes of 'data' to 'ap', asynchronously if possible. */
45 void async_append_write(struct async_append *ap,
46 const void *data, size_t size);
48 /* Blocks until all data asynchronously written to 'ap' with
49 * async_append_write() has been committed to the point that it will be written
50 * to disk barring an operating system or hardware failure. */
51 void async_append_flush(struct async_append *ap);
53 #endif /* async-append.h */