aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-03-10 11:15:01 -0800
committerBen Pfaff <blp@nicira.com>2011-03-10 11:24:00 -0800
commitc5f341ab193b9126dffef8c77bf8ed35e91290fd (patch)
treef44aae0db39ec6f5c1001535b19fe511333492d2 /lib
parent7f90cb0efe782cbbfb2557d81cf0f9de21e12435 (diff)
ovsdb: Implement garbage collection.
Diffstat (limited to 'lib')
-rw-r--r--lib/ovsdb-data.c60
-rw-r--r--lib/ovsdb-data.h2
-rw-r--r--lib/ovsdb-idl-provider.h3
3 files changed, 52 insertions, 13 deletions
diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c
index ac948641..150ae618 100644
--- a/lib/ovsdb-data.c
+++ b/lib/ovsdb-data.c
@@ -285,9 +285,28 @@ parse_json_pair(const struct json *json,
return NULL;
}
+static void
+ovsdb_symbol_referenced(struct ovsdb_symbol *symbol,
+ const struct ovsdb_base_type *base)
+{
+ assert(base->type == OVSDB_TYPE_UUID);
+
+ if (base->u.uuid.refTableName) {
+ switch (base->u.uuid.refType) {
+ case OVSDB_REF_STRONG:
+ symbol->strong_ref = true;
+ break;
+ case OVSDB_REF_WEAK:
+ symbol->weak_ref = true;
+ break;
+ }
+ }
+}
+
static struct ovsdb_error * WARN_UNUSED_RESULT
ovsdb_atom_parse_uuid(struct uuid *uuid, const struct json *json,
- struct ovsdb_symbol_table *symtab)
+ struct ovsdb_symbol_table *symtab,
+ const struct ovsdb_base_type *base)
{
struct ovsdb_error *error0;
const struct json *value;
@@ -304,14 +323,17 @@ ovsdb_atom_parse_uuid(struct uuid *uuid, const struct json *json,
error1 = unwrap_json(json, "named-uuid", JSON_STRING, &value);
if (!error1) {
- const char *name = json_string(value);
+ struct ovsdb_symbol *symbol;
ovsdb_error_destroy(error0);
- *uuid = ovsdb_symbol_table_insert(symtab, name)->uuid;
if (!ovsdb_parser_is_id(json_string(value))) {
return ovsdb_syntax_error(json, NULL, "named-uuid string is "
"not a valid <id>");
}
+
+ symbol = ovsdb_symbol_table_insert(symtab, json_string(value));
+ *uuid = symbol->uuid;
+ ovsdb_symbol_referenced(symbol, base);
return NULL;
}
ovsdb_error_destroy(error1);
@@ -321,10 +343,13 @@ ovsdb_atom_parse_uuid(struct uuid *uuid, const struct json *json,
}
static struct ovsdb_error * WARN_UNUSED_RESULT
-ovsdb_atom_from_json__(union ovsdb_atom *atom, enum ovsdb_atomic_type type,
+ovsdb_atom_from_json__(union ovsdb_atom *atom,
+ const struct ovsdb_base_type *base,
const struct json *json,
struct ovsdb_symbol_table *symtab)
{
+ enum ovsdb_atomic_type type = base->type;
+
switch (type) {
case OVSDB_TYPE_VOID:
NOT_REACHED();
@@ -364,7 +389,7 @@ ovsdb_atom_from_json__(union ovsdb_atom *atom, enum ovsdb_atomic_type type,
break;
case OVSDB_TYPE_UUID:
- return ovsdb_atom_parse_uuid(&atom->uuid, json, symtab);
+ return ovsdb_atom_parse_uuid(&atom->uuid, json, symtab, base);
case OVSDB_N_TYPES:
default:
@@ -384,7 +409,9 @@ ovsdb_atom_from_json__(union ovsdb_atom *atom, enum ovsdb_atomic_type type,
*
* If 'symtab' is nonnull, then named UUIDs in 'symtab' are accepted. Refer to
* ovsdb/SPECS for information about this, and for the syntax that this
- * function accepts. */
+ * function accepts. If 'base' is a reference and a symbol is parsed, then the
+ * symbol's 'strong_ref' or 'weak_ref' member is set to true, as
+ * appropriate. */
struct ovsdb_error *
ovsdb_atom_from_json(union ovsdb_atom *atom,
const struct ovsdb_base_type *base,
@@ -393,7 +420,7 @@ ovsdb_atom_from_json(union ovsdb_atom *atom,
{
struct ovsdb_error *error;
- error = ovsdb_atom_from_json__(atom, base->type, json, symtab);
+ error = ovsdb_atom_from_json__(atom, base, json, symtab);
if (error) {
return error;
}
@@ -440,9 +467,12 @@ ovsdb_atom_to_json(const union ovsdb_atom *atom, enum ovsdb_atomic_type type)
}
static char *
-ovsdb_atom_from_string__(union ovsdb_atom *atom, enum ovsdb_atomic_type type,
- const char *s, struct ovsdb_symbol_table *symtab)
+ovsdb_atom_from_string__(union ovsdb_atom *atom,
+ const struct ovsdb_base_type *base, const char *s,
+ struct ovsdb_symbol_table *symtab)
{
+ enum ovsdb_atomic_type type = base->type;
+
switch (type) {
case OVSDB_TYPE_VOID:
NOT_REACHED();
@@ -503,7 +533,9 @@ ovsdb_atom_from_string__(union ovsdb_atom *atom, enum ovsdb_atomic_type type,
case OVSDB_TYPE_UUID:
if (*s == '@') {
- atom->uuid = ovsdb_symbol_table_insert(symtab, s)->uuid;
+ struct ovsdb_symbol *symbol = ovsdb_symbol_table_insert(symtab, s);
+ atom->uuid = symbol->uuid;
+ ovsdb_symbol_referenced(symbol, base);
} else if (!uuid_from_string(&atom->uuid, s)) {
return xasprintf("\"%s\" is not a valid UUID", s);
}
@@ -535,7 +567,9 @@ ovsdb_atom_from_string__(union ovsdb_atom *atom, enum ovsdb_atomic_type type,
* then an identifier beginning with '@' is also acceptable. If the
* named identifier is already in 'symtab', then the associated UUID is
* used; otherwise, a new, random UUID is used and added to the symbol
- * table.
+ * table. If 'base' is a reference and a symbol is parsed, then the
+ * symbol's 'strong_ref' or 'weak_ref' member is set to true, as
+ * appropriate.
*
* Returns a null pointer if successful, otherwise an error message describing
* the problem. On failure, the contents of 'atom' are indeterminate. The
@@ -549,7 +583,7 @@ ovsdb_atom_from_string(union ovsdb_atom *atom,
struct ovsdb_error *error;
char *msg;
- msg = ovsdb_atom_from_string__(atom, base->type, s, symtab);
+ msg = ovsdb_atom_from_string__(atom, base, s, symtab);
if (msg) {
return msg;
}
@@ -1829,6 +1863,8 @@ ovsdb_symbol_table_put(struct ovsdb_symbol_table *symtab, const char *name,
symbol = xmalloc(sizeof *symbol);
symbol->uuid = *uuid;
symbol->created = created;
+ symbol->strong_ref = false;
+ symbol->weak_ref = false;
shash_add(&symtab->sh, name, symbol);
return symbol;
}
diff --git a/lib/ovsdb-data.h b/lib/ovsdb-data.h
index fe71f908..181df3b1 100644
--- a/lib/ovsdb-data.h
+++ b/lib/ovsdb-data.h
@@ -236,6 +236,8 @@ struct ovsdb_symbol_table {
struct ovsdb_symbol {
struct uuid uuid; /* The UUID that the symbol represents. */
bool created; /* Already used to create row? */
+ bool strong_ref; /* Parsed a strong reference to this row? */
+ bool weak_ref; /* Parsed a weak reference to this row? */
};
struct ovsdb_symbol_table *ovsdb_symbol_table_create(void);
diff --git a/lib/ovsdb-idl-provider.h b/lib/ovsdb-idl-provider.h
index 87f62d64..ef37d921 100644
--- a/lib/ovsdb-idl-provider.h
+++ b/lib/ovsdb-idl-provider.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009, 2010 Nicira Networks.
+/* Copyright (c) 2009, 2010, 2011 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,6 +47,7 @@ struct ovsdb_idl_column {
struct ovsdb_idl_table_class {
char *name;
+ bool is_root;
const struct ovsdb_idl_column *columns;
size_t n_columns;
size_t allocation_size;