]>
Commit | Line | Data |
---|---|---|
239fa5bb | 1 | /* Copyright (c) 2009, 2010, 2011, 2012, 2016 Nicira, Inc. |
93fe0264 | 2 | * Copyright (C) 2016 Hewlett Packard Enterprise Development LP |
c3bb4bd7 BP |
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 | ||
ee89ea7b | 20 | #include "openvswitch/hmap.h" |
b19bab5b | 21 | #include "openvswitch/list.h" |
c3bb4bd7 | 22 | #include "ovsdb-idl.h" |
f199df26 | 23 | #include "ovsdb-map-op.h" |
f1ab6e06 | 24 | #include "ovsdb-set-op.h" |
c3bb4bd7 | 25 | #include "ovsdb-types.h" |
ee89ea7b | 26 | #include "openvswitch/shash.h" |
c3bb4bd7 BP |
27 | #include "uuid.h" |
28 | ||
9131abe2 YHW |
29 | #ifdef __cplusplus |
30 | extern "C" { | |
31 | #endif | |
32 | ||
c1ac745c BP |
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 | * | |
4e0b4acc | 41 | * - 'old_datum' points to the data committed to the database and currently |
c1ac745c BP |
42 | * in the row. |
43 | * | |
4e0b4acc | 44 | * - 'new_datum == old_datum'. |
c1ac745c BP |
45 | * |
46 | * When a transaction is in progress, the situation is a little different. For | |
4e0b4acc JS |
47 | * a row inserted in the transaction, 'old_datum' is NULL and 'new_datum' |
48 | * points to the row's initial contents. Otherwise: | |
c1ac745c | 49 | * |
4e0b4acc JS |
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.) | |
c1ac745c | 52 | * |
4e0b4acc | 53 | * - If the transaction does not modify the row, 'new_datum == old_datum'. |
c1ac745c | 54 | * |
fa50ab0b JS |
55 | * - If the transaction modifies the row, 'new_datum' points to the |
56 | * modified data. | |
c1ac745c | 57 | * |
fa50ab0b | 58 | * - If the transaction deletes the row, 'new_datum' is NULL. |
c1ac745c BP |
59 | * |
60 | * Thus: | |
61 | * | |
4e0b4acc JS |
62 | * - 'old_datum' always points to committed data, except that it is NULL if |
63 | * the row is inserted within the current transaction. | |
c1ac745c | 64 | * |
fa50ab0b JS |
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. | |
c1ac745c | 68 | */ |
c3bb4bd7 BP |
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. */ | |
ca6ba700 TG |
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). */ | |
c3bb4bd7 | 74 | struct ovsdb_idl_table *table; /* Containing table. */ |
4e0b4acc | 75 | struct ovsdb_datum *old_datum; /* Committed data (null if orphaned). */ |
72aeb243 | 76 | bool parsed; /* Whether the row is parsed. */ |
475281c0 BP |
77 | |
78 | /* Transactional data. */ | |
fa50ab0b | 79 | struct ovsdb_datum *new_datum; /* Modified data (null to delete row). */ |
4e0b4acc | 80 | unsigned long int *prereqs; /* Bitmap of "old_datum" columns to verify. */ |
fa50ab0b | 81 | unsigned long int *written; /* Bitmap of "new_datum" columns to write. */ |
475281c0 | 82 | struct hmap_node txn_node; /* Node in ovsdb_idl_txn's list. */ |
f199df26 EA |
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. */ | |
f1ab6e06 RM |
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. */ | |
932104f4 | 87 | |
32d37ce8 | 88 | /* Tracking data */ |
932104f4 | 89 | unsigned int change_seqno[OVSDB_IDL_CHANGE_MAX]; |
32d37ce8 SA |
90 | struct ovs_list track_node; /* Rows modified/added/deleted by IDL */ |
91 | unsigned long int *updated; /* Bitmap of columns updated by IDL */ | |
72aeb243 | 92 | struct ovsdb_datum *tracked_old_datum; /* Old deleted data. */ |
c3bb4bd7 BP |
93 | }; |
94 | ||
95 | struct ovsdb_idl_column { | |
96 | char *name; | |
97 | struct ovsdb_type type; | |
c6e5d064 | 98 | bool is_mutable; |
01928c96 | 99 | bool is_synthetic; |
979821c0 BP |
100 | void (*parse)(struct ovsdb_idl_row *, const struct ovsdb_datum *); |
101 | void (*unparse)(struct ovsdb_idl_row *); | |
c3bb4bd7 BP |
102 | }; |
103 | ||
104 | struct ovsdb_idl_table_class { | |
105 | char *name; | |
c5f341ab | 106 | bool is_root; |
25540a77 | 107 | bool is_singleton; |
c3bb4bd7 BP |
108 | const struct ovsdb_idl_column *columns; |
109 | size_t n_columns; | |
110 | size_t allocation_size; | |
a699f614 | 111 | void (*row_init)(struct ovsdb_idl_row *); |
c3bb4bd7 BP |
112 | }; |
113 | ||
114 | struct ovsdb_idl_table { | |
3eb14233 | 115 | const struct ovsdb_idl_table_class *class_; |
ef73f86c | 116 | unsigned char *modes; /* OVSDB_IDL_* bitmasks, indexed by column. */ |
cd26c1dc AE |
117 | bool need_table; /* Monitor table even if no columns are selected |
118 | * for replication. */ | |
c3bb4bd7 BP |
119 | struct shash columns; /* Contains "const struct ovsdb_idl_column *"s. */ |
120 | struct hmap rows; /* Contains "struct ovsdb_idl_row"s. */ | |
1456335d | 121 | struct ovsdb_idl_db *db; /* Containing db. */ |
932104f4 | 122 | unsigned int change_seqno[OVSDB_IDL_CHANGE_MAX]; |
d14e007c | 123 | struct ovs_list indexes; /* Contains "struct ovsdb_idl_index"s */ |
932104f4 | 124 | struct ovs_list track_list; /* Tracked rows (ovsdb_idl_row.track_node). */ |
16ebb90e LS |
125 | struct ovsdb_idl_condition condition; |
126 | bool cond_changed; | |
c3bb4bd7 BP |
127 | }; |
128 | ||
129 | struct ovsdb_idl_class { | |
9cb53f26 | 130 | const char *database; /* <db-name> for this database. */ |
c3bb4bd7 BP |
131 | const struct ovsdb_idl_table_class *tables; |
132 | size_t n_tables; | |
133 | }; | |
134 | ||
135 | struct ovsdb_idl_row *ovsdb_idl_get_row_arc( | |
136 | struct ovsdb_idl_row *src, | |
012d3762 | 137 | const struct ovsdb_idl_table_class *dst_table, |
c3bb4bd7 BP |
138 | const struct uuid *dst_uuid); |
139 | ||
475281c0 BP |
140 | void ovsdb_idl_txn_verify(const struct ovsdb_idl_row *, |
141 | const struct ovsdb_idl_column *); | |
475281c0 | 142 | |
76c91af9 | 143 | struct ovsdb_idl_txn *ovsdb_idl_txn_get(const struct ovsdb_idl_row *); |
d14e007c BP |
144 | \f |
145 | /* Index internals. */ | |
146 | ||
147 | struct ovsdb_idl_index { | |
148 | struct ovs_list node; /* In ->table->indexes. */ | |
149 | struct ovsdb_idl_table *table; /* The indexed table. */ | |
150 | struct ovsdb_idl_index_column *columns; /* The indexed columns. */ | |
151 | size_t n_columns; | |
152 | ||
153 | /* Skiplist with pointers to rows. */ | |
154 | struct skiplist *skiplist; | |
155 | ||
156 | /* True if a row in the index is being inserted or deleted. If true, the | |
157 | search key is augmented with the UUID and address to discriminate | |
158 | between entries with identical keys. */ | |
159 | bool ins_del; | |
160 | }; | |
161 | ||
162 | int ovsdb_idl_index_compare(struct ovsdb_idl_index *, | |
163 | const struct ovsdb_idl_row *a, | |
164 | const struct ovsdb_idl_row *b); | |
165 | ||
166 | void ovsdb_idl_index_write(struct ovsdb_idl_row *, | |
167 | const struct ovsdb_idl_column *, | |
168 | struct ovsdb_datum *, | |
169 | const struct ovsdb_idl_table_class *); | |
170 | struct ovsdb_idl_row *ovsdb_idl_index_init_row(struct ovsdb_idl_index *); | |
171 | void ovsdb_idl_index_destroy_row(const struct ovsdb_idl_row *); | |
76c91af9 | 172 | |
9131abe2 YHW |
173 | #ifdef __cplusplus |
174 | } | |
175 | #endif | |
176 | ||
c3bb4bd7 | 177 | #endif /* ovsdb-idl-provider.h */ |