]>
git.proxmox.com Git - mirror_ovs.git/blob - lib/ovsdb-idl-provider.h
1 /* Copyright (c) 2009, 2010, 2011, 2012, 2016 Nicira, Inc.
2 * Copyright (C) 2016 Hewlett Packard Enterprise Development LP
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef OVSDB_IDL_PROVIDER_H
18 #define OVSDB_IDL_PROVIDER_H 1
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"
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.)
39 * When no transaction is in progress:
41 * - 'old_datum' points to the data committed to the database and currently
44 * - 'new_datum == old_datum'.
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:
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.)
53 * - If the transaction does not modify the row, 'new_datum == old_datum'.
55 * - If the transaction modifies the row, 'new_datum' points to the
58 * - If the transaction deletes the row, 'new_datum' is NULL.
62 * - 'old_datum' always points to committed data, except that it is NULL if
63 * the row is inserted within the current transaction.
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.
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. */
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. */
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. */
95 struct ovsdb_idl_column
{
97 struct ovsdb_type type
;
100 void (*parse
)(struct ovsdb_idl_row
*, const struct ovsdb_datum
*);
101 void (*unparse
)(struct ovsdb_idl_row
*);
104 struct ovsdb_idl_table_class
{
108 const struct ovsdb_idl_column
*columns
;
110 size_t allocation_size
;
111 void (*row_init
)(struct ovsdb_idl_row
*);
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
127 struct ovsdb_idl_condition
*req_cond
; /* Last condition requested to the
129 struct ovsdb_idl_condition
*new_cond
; /* Latest condition set by the IDL
133 struct ovsdb_idl_class
{
134 const char *database
; /* <db-name> for this database. */
135 const struct ovsdb_idl_table_class
*tables
;
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
);
144 void ovsdb_idl_txn_verify(const struct ovsdb_idl_row
*,
145 const struct ovsdb_idl_column
*);
147 struct ovsdb_idl_txn
*ovsdb_idl_txn_get(const struct ovsdb_idl_row
*);
149 /* Index internals. */
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. */
157 /* Skiplist with pointers to rows. */
158 struct skiplist
*skiplist
;
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. */
166 int ovsdb_idl_index_compare(struct ovsdb_idl_index
*,
167 const struct ovsdb_idl_row
*a
,
168 const struct ovsdb_idl_row
*b
);
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
*);
181 #endif /* ovsdb-idl-provider.h */