]> git.proxmox.com Git - mirror_ovs.git/blob - ovsdb/log.h
dist-docs: Include manpages generated from rST.
[mirror_ovs.git] / ovsdb / log.h
1 /* Copyright (c) 2009, 2010, 2011, 2017 Nicira, Inc.
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
16 #ifndef OVSDB_LOG_H
17 #define OVSDB_LOG_H 1
18
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
38 #include <stdint.h>
39 #include <sys/types.h>
40 #include "compiler.h"
41
42 struct ds;
43 struct json;
44 struct ovsdb_log;
45
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. */
50 OVSDB_LOG_CREATE_EXCL, /* Create new file, read/write. */
51 OVSDB_LOG_CREATE /* Create or open file, read/write. */
52 };
53
54 /* 'magic' for use with ovsdb_log_open() for OVSDB databases (see ovsdb(5)). */
55 #define OVSDB_MAGIC "JSON"
56
57 struct ovsdb_error *ovsdb_log_open(const char *name, const char *magic,
58 enum ovsdb_log_open_mode,
59 int locking, struct ovsdb_log **)
60 OVS_WARN_UNUSED_RESULT;
61 void ovsdb_log_close(struct ovsdb_log *);
62
63 const char *ovsdb_log_get_magic(const struct ovsdb_log *);
64
65 struct ovsdb_error *ovsdb_log_read(struct ovsdb_log *, struct json **)
66 OVS_WARN_UNUSED_RESULT;
67 void ovsdb_log_unread(struct ovsdb_log *);
68
69 void ovsdb_log_compose_record(const struct json *, const char *magic,
70 struct ds *header, struct ds *data);
71
72 struct ovsdb_error *ovsdb_log_write(struct ovsdb_log *, const struct json *)
73 OVS_WARN_UNUSED_RESULT;
74 struct ovsdb_error *ovsdb_log_write_and_free(struct ovsdb_log *, struct json *)
75 OVS_WARN_UNUSED_RESULT;
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 *)
81 OVS_WARN_UNUSED_RESULT;
82
83 void ovsdb_log_mark_base(struct ovsdb_log *);
84 bool ovsdb_log_grew_lots(const struct ovsdb_log *);
85
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
100 #endif /* ovsdb/log.h */