1 /* Copyright (c) 2009, 2010 Nicira Networks
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.
23 #include "ovsdb-data.h"
25 struct ovsdb_column_set;
27 /* A row in a database table. */
29 struct ovsdb_table *table; /* Table to which this belongs. */
30 struct hmap_node hmap_node; /* Element in ovsdb_table's 'rows' hmap. */
31 struct ovsdb_txn_row *txn_row; /* Transaction that row is in, if any. */
33 /* Number of refs to this row from other rows, in this table or other
34 * tables, through 'uuid' columns that have a 'refTable' constraint
35 * pointing to this table. A row with nonzero 'n_refs' cannot be deleted.
36 * Updated and checked only at transaction commit. */
39 struct ovsdb_datum fields[];
42 struct ovsdb_row *ovsdb_row_create(const struct ovsdb_table *);
43 struct ovsdb_row *ovsdb_row_clone(const struct ovsdb_row *);
44 void ovsdb_row_destroy(struct ovsdb_row *);
46 uint32_t ovsdb_row_hash_columns(const struct ovsdb_row *,
47 const struct ovsdb_column_set *,
49 bool ovsdb_row_equal_columns(const struct ovsdb_row *,
50 const struct ovsdb_row *,
51 const struct ovsdb_column_set *);
52 int ovsdb_row_compare_columns_3way(const struct ovsdb_row *,
53 const struct ovsdb_row *,
54 const struct ovsdb_column_set *);
55 void ovsdb_row_update_columns(struct ovsdb_row *, const struct ovsdb_row *,
56 const struct ovsdb_column_set *);
58 struct ovsdb_error *ovsdb_row_from_json(struct ovsdb_row *,
60 struct ovsdb_symbol_table *,
61 struct ovsdb_column_set *included)
63 struct json *ovsdb_row_to_json(const struct ovsdb_row *,
64 const struct ovsdb_column_set *include);
66 static inline const struct uuid *
67 ovsdb_row_get_uuid(const struct ovsdb_row *row)
69 return &row->fields[OVSDB_COL_UUID].keys[0].uuid;
72 static inline struct uuid *
73 ovsdb_row_get_uuid_rw(struct ovsdb_row *row)
75 return &row->fields[OVSDB_COL_UUID].keys[0].uuid;
78 static inline const struct uuid *
79 ovsdb_row_get_version(const struct ovsdb_row *row)
81 return &row->fields[OVSDB_COL_VERSION].keys[0].uuid;
84 static inline struct uuid *
85 ovsdb_row_get_version_rw(struct ovsdb_row *row)
87 return &row->fields[OVSDB_COL_VERSION].keys[0].uuid;
90 static inline uint32_t
91 ovsdb_row_hash(const struct ovsdb_row *row)
93 return uuid_hash(ovsdb_row_get_uuid(row));
96 /* An unordered collection of rows. */
97 struct ovsdb_row_set {
98 const struct ovsdb_row **rows;
99 size_t n_rows, allocated_rows;
102 #define OVSDB_ROW_SET_INITIALIZER { NULL, 0, 0 }
104 void ovsdb_row_set_init(struct ovsdb_row_set *);
105 void ovsdb_row_set_destroy(struct ovsdb_row_set *);
106 void ovsdb_row_set_add_row(struct ovsdb_row_set *, const struct ovsdb_row *);
108 struct json *ovsdb_row_set_to_json(const struct ovsdb_row_set *,
109 const struct ovsdb_column_set *);
111 void ovsdb_row_set_sort(struct ovsdb_row_set *,
112 const struct ovsdb_column_set *);
114 /* A hash table of rows. A specified set of columns is used for hashing and
117 * The row hash doesn't necessarily own its rows. They may be owned by, for
118 * example, an ovsdb_table. */
119 struct ovsdb_row_hash {
121 struct ovsdb_column_set columns;
124 #define OVSDB_ROW_HASH_INITIALIZER(RH) \
125 { HMAP_INITIALIZER(&(RH).rows), OVSDB_COLUMN_SET_INITIALIZER }
127 struct ovsdb_row_hash_node {
128 struct hmap_node hmap_node;
129 const struct ovsdb_row *row;
132 void ovsdb_row_hash_init(struct ovsdb_row_hash *,
133 const struct ovsdb_column_set *);
134 void ovsdb_row_hash_destroy(struct ovsdb_row_hash *, bool destroy_rows);
135 size_t ovsdb_row_hash_count(const struct ovsdb_row_hash *);
136 bool ovsdb_row_hash_contains(const struct ovsdb_row_hash *,
137 const struct ovsdb_row *);
138 bool ovsdb_row_hash_contains_all(const struct ovsdb_row_hash *,
139 const struct ovsdb_row_hash *);
140 bool ovsdb_row_hash_insert(struct ovsdb_row_hash *, const struct ovsdb_row *);
141 bool ovsdb_row_hash_contains__(const struct ovsdb_row_hash *,
142 const struct ovsdb_row *, size_t hash);
143 bool ovsdb_row_hash_insert__(struct ovsdb_row_hash *,
144 const struct ovsdb_row *, size_t hash);
146 #endif /* ovsdb/row.h */