]>
Commit | Line | Data |
---|---|---|
fed27759 | 1 | /* Copyright (c) 2009, 2010, 2011, 2017 Nicira, Inc. |
f85f8ebb BP |
2 | * |
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: | |
6 | * | |
7 | * http://www.apache.org/licenses/LICENSE-2.0 | |
8 | * | |
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. | |
14 | */ | |
15 | ||
41709ccc BP |
16 | #ifndef OVSDB_LOG_H |
17 | #define OVSDB_LOG_H 1 | |
f85f8ebb | 18 | |
4cc9d1f0 BP |
19 | /* OVSDB log. |
20 | * | |
21 | * A log consists of a series of records. After opening or creating a log with | |
22 | * ovsdb_log_open(), the client may use ovsdb_log_read() to read any existing | |
23 | * records, one by one. The client may also use ovsdb_log_write() to write new | |
24 | * records (if some records have not yet been read at this point, then the | |
25 | * first write truncates them). | |
26 | * | |
27 | * Log writes are atomic. A client may use ovsdb_log_commit() to ensure that | |
28 | * they are durable. | |
29 | * | |
30 | * Logs provide a mechansim to allow the client to tell when they have grown | |
31 | * enough that compacting may be warranted. After reading existing log | |
32 | * contents, the client uses ovsdb_log_mark_base() to mark the "base" to be | |
33 | * considered as the initial size of the log. Thereafter, a client may call | |
34 | * ovsdb_log_grew_lots() to get an indication whether the log has grown enough | |
35 | * that compacting is advised. | |
36 | */ | |
37 | ||
89c565fe | 38 | #include <stdint.h> |
f85f8ebb BP |
39 | #include <sys/types.h> |
40 | #include "compiler.h" | |
41 | ||
c9167341 | 42 | struct ds; |
f85f8ebb | 43 | struct json; |
41709ccc | 44 | struct ovsdb_log; |
f85f8ebb | 45 | |
7446f148 BP |
46 | /* Access mode for opening an OVSDB log. */ |
47 | enum ovsdb_log_open_mode { | |
48 | OVSDB_LOG_READ_ONLY, /* Open existing file, read-only. */ | |
49 | OVSDB_LOG_READ_WRITE, /* Open existing file, read/write. */ | |
1e0b7e94 BP |
50 | OVSDB_LOG_CREATE_EXCL, /* Create new file, read/write. */ |
51 | OVSDB_LOG_CREATE /* Create or open file, read/write. */ | |
7446f148 BP |
52 | }; |
53 | ||
fed27759 BP |
54 | /* 'magic' for use with ovsdb_log_open() for OVSDB databases (see ovsdb(5)). */ |
55 | #define OVSDB_MAGIC "JSON" | |
19b276cb BP |
56 | |
57 | struct ovsdb_error *ovsdb_log_open(const char *name, const char *magic, | |
58 | enum ovsdb_log_open_mode, | |
7446f148 | 59 | int locking, struct ovsdb_log **) |
cab50449 | 60 | OVS_WARN_UNUSED_RESULT; |
41709ccc | 61 | void ovsdb_log_close(struct ovsdb_log *); |
f85f8ebb | 62 | |
fed27759 BP |
63 | const char *ovsdb_log_get_magic(const struct ovsdb_log *); |
64 | ||
41709ccc | 65 | struct ovsdb_error *ovsdb_log_read(struct ovsdb_log *, struct json **) |
cab50449 | 66 | OVS_WARN_UNUSED_RESULT; |
43675e26 BP |
67 | void ovsdb_log_unread(struct ovsdb_log *); |
68 | ||
19b276cb | 69 | void ovsdb_log_compose_record(const struct json *, const char *magic, |
c9167341 BP |
70 | struct ds *header, struct ds *data); |
71 | ||
226600d9 | 72 | struct ovsdb_error *ovsdb_log_write(struct ovsdb_log *, const struct json *) |
fa9a6245 BP |
73 | OVS_WARN_UNUSED_RESULT; |
74 | struct ovsdb_error *ovsdb_log_write_and_free(struct ovsdb_log *, struct json *) | |
cab50449 | 75 | OVS_WARN_UNUSED_RESULT; |
89c565fe BP |
76 | |
77 | uint64_t ovsdb_log_commit_start(struct ovsdb_log *); | |
78 | uint64_t ovsdb_log_commit_progress(struct ovsdb_log *); | |
79 | void ovsdb_log_commit_wait(struct ovsdb_log *, uint64_t); | |
80 | struct ovsdb_error *ovsdb_log_commit_block(struct ovsdb_log *) | |
cab50449 | 81 | OVS_WARN_UNUSED_RESULT; |
f85f8ebb | 82 | |
4cc9d1f0 BP |
83 | void ovsdb_log_mark_base(struct ovsdb_log *); |
84 | bool ovsdb_log_grew_lots(const struct ovsdb_log *); | |
ada496b5 | 85 | |
421fc8a1 BP |
86 | struct ovsdb_error *ovsdb_log_replace(struct ovsdb_log *, |
87 | struct json **entries, size_t n) | |
88 | OVS_WARN_UNUSED_RESULT; | |
89 | struct ovsdb_error *ovsdb_log_replace_start(struct ovsdb_log *old, | |
90 | struct ovsdb_log **newp) | |
91 | OVS_WARN_UNUSED_RESULT; | |
92 | struct ovsdb_error *ovsdb_log_replace_commit(struct ovsdb_log *old, | |
93 | struct ovsdb_log *new) | |
94 | OVS_WARN_UNUSED_RESULT; | |
95 | void ovsdb_log_replace_abort(struct ovsdb_log *new); | |
96 | ||
97 | /* For testing. */ | |
98 | void ovsdb_log_disable_renaming_open_files(void); | |
99 | ||
41709ccc | 100 | #endif /* ovsdb/log.h */ |