]> git.proxmox.com Git - mirror_ovs.git/blob - lib/ovsdb-idl-provider.h
netdev-dpdk: add hotplug support
[mirror_ovs.git] / lib / ovsdb-idl-provider.h
1 /* Copyright (c) 2009, 2010, 2011, 2012, 2016 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_IDL_PROVIDER_H
17 #define OVSDB_IDL_PROVIDER_H 1
18
19 #include "openvswitch/hmap.h"
20 #include "openvswitch/list.h"
21 #include "ovsdb-idl.h"
22 #include "ovsdb-map-op.h"
23 #include "ovsdb-set-op.h"
24 #include "ovsdb-types.h"
25 #include "openvswitch/shash.h"
26 #include "uuid.h"
27
28 /* A local copy of a row in an OVSDB table, replicated from an OVSDB server.
29 * This structure is used as a header for a larger structure that translates
30 * the "struct ovsdb_datum"s into easier-to-use forms, via the ->parse() and
31 * ->unparse functions in struct ovsdb_idl_column. (Those functions are
32 * generated automatically via ovsdb-idlc.)
33 *
34 * When no transaction is in progress:
35 *
36 * - 'old' points to the data committed to the database and currently
37 * in the row.
38 *
39 * - 'new == old'.
40 *
41 * When a transaction is in progress, the situation is a little different. For
42 * a row inserted in the transaction, 'old' is NULL and 'new' points to the
43 * row's initial contents. Otherwise:
44 *
45 * - 'old' points to the data committed to the database and currently in
46 * the row. (This is the same as when no transaction is in progress.)
47 *
48 * - If the transaction does not modify the row, 'new == old'.
49 *
50 * - If the transaction modifies the row, 'new' points to the modified
51 * data.
52 *
53 * - If the transaction deletes the row, 'new' is NULL.
54 *
55 * Thus:
56 *
57 * - 'old' always points to committed data, except that it is NULL if the
58 * row is inserted within the current transaction.
59 *
60 * - 'new' always points to the newest, possibly uncommitted version of the
61 * row's data, except that it is NULL if the row is deleted within the
62 * current transaction.
63 */
64 struct ovsdb_idl_row {
65 struct hmap_node hmap_node; /* In struct ovsdb_idl_table's 'rows'. */
66 struct uuid uuid; /* Row "_uuid" field. */
67 struct ovs_list src_arcs; /* Forward arcs (ovsdb_idl_arc.src_node). */
68 struct ovs_list dst_arcs; /* Backward arcs (ovsdb_idl_arc.dst_node). */
69 struct ovsdb_idl_table *table; /* Containing table. */
70 struct ovsdb_datum *old; /* Committed data (null if orphaned). */
71
72 /* Transactional data. */
73 struct ovsdb_datum *new; /* Modified data (null to delete row). */
74 unsigned long int *prereqs; /* Bitmap of columns to verify in "old". */
75 unsigned long int *written; /* Bitmap of columns from "new" to write. */
76 struct hmap_node txn_node; /* Node in ovsdb_idl_txn's list. */
77 unsigned long int *map_op_written; /* Bitmap of columns pending map ops. */
78 struct map_op_list **map_op_lists; /* Per-column map operations. */
79 unsigned long int *set_op_written; /* Bitmap of columns pending set ops. */
80 struct set_op_list **set_op_lists; /* Per-column set operations. */
81
82 /* Tracking data */
83 unsigned int change_seqno[OVSDB_IDL_CHANGE_MAX];
84 struct ovs_list track_node; /* Rows modified/added/deleted by IDL */
85 unsigned long int *updated; /* Bitmap of columns updated by IDL */
86 };
87
88 struct ovsdb_idl_column {
89 char *name;
90 struct ovsdb_type type;
91 bool mutable;
92 void (*parse)(struct ovsdb_idl_row *, const struct ovsdb_datum *);
93 void (*unparse)(struct ovsdb_idl_row *);
94 };
95
96 struct ovsdb_idl_table_class {
97 char *name;
98 bool is_root;
99 const struct ovsdb_idl_column *columns;
100 size_t n_columns;
101 size_t allocation_size;
102 void (*row_init)(struct ovsdb_idl_row *);
103 };
104
105 struct ovsdb_idl_table {
106 const struct ovsdb_idl_table_class *class;
107 unsigned char *modes; /* OVSDB_IDL_* bitmasks, indexed by column. */
108 bool need_table; /* Monitor table even if no columns are selected
109 * for replication. */
110 struct shash columns; /* Contains "const struct ovsdb_idl_column *"s. */
111 struct hmap rows; /* Contains "struct ovsdb_idl_row"s. */
112 struct ovsdb_idl *idl; /* Containing idl. */
113 unsigned int change_seqno[OVSDB_IDL_CHANGE_MAX];
114 struct ovs_list track_list; /* Tracked rows (ovsdb_idl_row.track_node). */
115 struct ovsdb_idl_condition condition;
116 bool cond_changed;
117 };
118
119 struct ovsdb_idl_class {
120 const char *database; /* <db-name> for this database. */
121 const struct ovsdb_idl_table_class *tables;
122 size_t n_tables;
123 };
124
125 struct ovsdb_idl_row *ovsdb_idl_get_row_arc(
126 struct ovsdb_idl_row *src,
127 const struct ovsdb_idl_table_class *dst_table,
128 const struct uuid *dst_uuid);
129
130 void ovsdb_idl_txn_verify(const struct ovsdb_idl_row *,
131 const struct ovsdb_idl_column *);
132
133 struct ovsdb_idl_txn *ovsdb_idl_txn_get(const struct ovsdb_idl_row *);
134
135 #endif /* ovsdb-idl-provider.h */