]> git.proxmox.com Git - mirror_ovs.git/blob - lib/ovsdb-idl-provider.h
netdev-offload-tc: Use single 'once' variable for probing tc features
[mirror_ovs.git] / lib / ovsdb-idl-provider.h
1 /* Copyright (c) 2009, 2010, 2011, 2012, 2016 Nicira, Inc.
2 * Copyright (C) 2016 Hewlett Packard Enterprise Development LP
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef OVSDB_IDL_PROVIDER_H
18 #define OVSDB_IDL_PROVIDER_H 1
19
20 #include "openvswitch/hmap.h"
21 #include "openvswitch/list.h"
22 #include "ovsdb-idl.h"
23 #include "ovsdb-map-op.h"
24 #include "ovsdb-set-op.h"
25 #include "ovsdb-types.h"
26 #include "openvswitch/shash.h"
27 #include "uuid.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /* A local copy of a row in an OVSDB table, replicated from an OVSDB server.
34 * This structure is used as a header for a larger structure that translates
35 * the "struct ovsdb_datum"s into easier-to-use forms, via the ->parse() and
36 * ->unparse functions in struct ovsdb_idl_column. (Those functions are
37 * generated automatically via ovsdb-idlc.)
38 *
39 * When no transaction is in progress:
40 *
41 * - 'old_datum' points to the data committed to the database and currently
42 * in the row.
43 *
44 * - 'new_datum == old_datum'.
45 *
46 * When a transaction is in progress, the situation is a little different. For
47 * a row inserted in the transaction, 'old_datum' is NULL and 'new_datum'
48 * points to the row's initial contents. Otherwise:
49 *
50 * - 'old_datum' points to the data committed to the database and currently
51 * in the row. (This is the same as when no transaction is in progress.)
52 *
53 * - If the transaction does not modify the row, 'new_datum == old_datum'.
54 *
55 * - If the transaction modifies the row, 'new_datum' points to the
56 * modified data.
57 *
58 * - If the transaction deletes the row, 'new_datum' is NULL.
59 *
60 * Thus:
61 *
62 * - 'old_datum' always points to committed data, except that it is NULL if
63 * the row is inserted within the current transaction.
64 *
65 * - 'new_datum' always points to the newest, possibly uncommitted version
66 * of the row's data, except that it is NULL if the row is deleted within
67 * the current transaction.
68 */
69 struct ovsdb_idl_row {
70 struct hmap_node hmap_node; /* In struct ovsdb_idl_table's 'rows'. */
71 struct uuid uuid; /* Row "_uuid" field. */
72 struct ovs_list src_arcs; /* Forward arcs (ovsdb_idl_arc.src_node). */
73 struct ovs_list dst_arcs; /* Backward arcs (ovsdb_idl_arc.dst_node). */
74 struct ovsdb_idl_table *table; /* Containing table. */
75 struct ovsdb_datum *old_datum; /* Committed data (null if orphaned). */
76 bool parsed; /* Whether the row is parsed. */
77
78 /* Transactional data. */
79 struct ovsdb_datum *new_datum; /* Modified data (null to delete row). */
80 unsigned long int *prereqs; /* Bitmap of "old_datum" columns to verify. */
81 unsigned long int *written; /* Bitmap of "new_datum" columns to write. */
82 struct hmap_node txn_node; /* Node in ovsdb_idl_txn's list. */
83 unsigned long int *map_op_written; /* Bitmap of columns pending map ops. */
84 struct map_op_list **map_op_lists; /* Per-column map operations. */
85 unsigned long int *set_op_written; /* Bitmap of columns pending set ops. */
86 struct set_op_list **set_op_lists; /* Per-column set operations. */
87
88 /* Tracking data */
89 unsigned int change_seqno[OVSDB_IDL_CHANGE_MAX];
90 struct ovs_list track_node; /* Rows modified/added/deleted by IDL */
91 unsigned long int *updated; /* Bitmap of columns updated by IDL */
92 struct ovsdb_datum *tracked_old_datum; /* Old deleted data. */
93 };
94
95 struct ovsdb_idl_column {
96 char *name;
97 struct ovsdb_type type;
98 bool is_mutable;
99 bool is_synthetic;
100 void (*parse)(struct ovsdb_idl_row *, const struct ovsdb_datum *);
101 void (*unparse)(struct ovsdb_idl_row *);
102 };
103
104 struct ovsdb_idl_table_class {
105 char *name;
106 bool is_root;
107 bool is_singleton;
108 const struct ovsdb_idl_column *columns;
109 size_t n_columns;
110 size_t allocation_size;
111 void (*row_init)(struct ovsdb_idl_row *);
112 };
113
114 struct ovsdb_idl_table {
115 const struct ovsdb_idl_table_class *class_;
116 unsigned char *modes; /* OVSDB_IDL_* bitmasks, indexed by column. */
117 bool need_table; /* Monitor table even if no columns are selected
118 * for replication. */
119 struct shash columns; /* Contains "const struct ovsdb_idl_column *"s. */
120 struct hmap rows; /* Contains "struct ovsdb_idl_row"s. */
121 struct ovsdb_idl_db *db; /* Containing db. */
122 unsigned int change_seqno[OVSDB_IDL_CHANGE_MAX];
123 struct ovs_list indexes; /* Contains "struct ovsdb_idl_index"s */
124 struct ovs_list track_list; /* Tracked rows (ovsdb_idl_row.track_node). */
125 struct ovsdb_idl_condition *ack_cond; /* Last condition acked by the
126 * server. */
127 struct ovsdb_idl_condition *req_cond; /* Last condition requested to the
128 * server. */
129 struct ovsdb_idl_condition *new_cond; /* Latest condition set by the IDL
130 * client. */
131 };
132
133 struct ovsdb_idl_class {
134 const char *database; /* <db-name> for this database. */
135 const struct ovsdb_idl_table_class *tables;
136 size_t n_tables;
137 };
138
139 struct ovsdb_idl_row *ovsdb_idl_get_row_arc(
140 struct ovsdb_idl_row *src,
141 const struct ovsdb_idl_table_class *dst_table,
142 const struct uuid *dst_uuid);
143
144 void ovsdb_idl_txn_verify(const struct ovsdb_idl_row *,
145 const struct ovsdb_idl_column *);
146
147 struct ovsdb_idl_txn *ovsdb_idl_txn_get(const struct ovsdb_idl_row *);
148 \f
149 /* Index internals. */
150
151 struct ovsdb_idl_index {
152 struct ovs_list node; /* In ->table->indexes. */
153 struct ovsdb_idl_table *table; /* The indexed table. */
154 struct ovsdb_idl_index_column *columns; /* The indexed columns. */
155 size_t n_columns;
156
157 /* Skiplist with pointers to rows. */
158 struct skiplist *skiplist;
159
160 /* True if a row in the index is being inserted or deleted. If true, the
161 search key is augmented with the UUID and address to discriminate
162 between entries with identical keys. */
163 bool ins_del;
164 };
165
166 int ovsdb_idl_index_compare(struct ovsdb_idl_index *,
167 const struct ovsdb_idl_row *a,
168 const struct ovsdb_idl_row *b);
169
170 void ovsdb_idl_index_write(struct ovsdb_idl_row *,
171 const struct ovsdb_idl_column *,
172 struct ovsdb_datum *,
173 const struct ovsdb_idl_table_class *);
174 struct ovsdb_idl_row *ovsdb_idl_index_init_row(struct ovsdb_idl_index *);
175 void ovsdb_idl_index_destroy_row(const struct ovsdb_idl_row *);
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #endif /* ovsdb-idl-provider.h */