]>
git.proxmox.com Git - mirror_ovs.git/blob - ovsdb/log.h
1 /* Copyright (c) 2009, 2010, 2011, 2017 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.
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).
27 * Log writes are atomic. A client may use ovsdb_log_commit() to ensure that
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.
39 #include <sys/types.h>
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. */
54 /* 'magic' for use with ovsdb_log_open() for OVSDB databases (see ovsdb(5)). */
55 #define OVSDB_MAGIC "JSON"
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
*);
63 const char *ovsdb_log_get_magic(const struct ovsdb_log
*);
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
*);
69 void ovsdb_log_compose_record(const struct json
*, const char *magic
,
70 struct ds
*header
, struct ds
*data
);
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
;
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
;
83 void ovsdb_log_mark_base(struct ovsdb_log
*);
84 bool ovsdb_log_grew_lots(const struct ovsdb_log
*);
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);
98 void ovsdb_log_disable_renaming_open_files(void);
100 #endif /* ovsdb/log.h */