-/* Copyright (c) 2009, 2010, 2011 Nicira, Inc.
+/* Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "ovsdb-error.h"
#include "ovsdb-parser.h"
#include "ovsdb-types.h"
+#include "simap.h"
#include "table.h"
#include "transaction.h"
return NULL;
}
-static struct ovsdb_error * WARN_UNUSED_RESULT
+static struct ovsdb_error * OVS_WARN_UNUSED_RESULT
ovsdb_schema_check_ref_table(struct ovsdb_column *column,
const struct shash *tables,
const struct ovsdb_base_type *base,
is_valid_version(const char *s)
{
int n = -1;
- ignore(sscanf(s, "%*[0-9].%*[0-9].%*[0-9]%n", &n));
+ ignore(ovs_scan(s, "%*[0-9].%*[0-9].%*[0-9]%n", &n));
return n != -1 && s[n] == '\0';
}
db = xmalloc(sizeof *db);
db->schema = schema;
- list_init(&db->replicas);
- list_init(&db->triggers);
+ ovs_list_init(&db->replicas);
+ ovs_list_init(&db->triggers);
db->run_triggers = false;
shash_init(&db->tables);
struct shash_node *node;
/* Remove all the replicas. */
- while (!list_is_empty(&db->replicas)) {
+ while (!ovs_list_is_empty(&db->replicas)) {
struct ovsdb_replica *r
- = CONTAINER_OF(list_pop_back(&db->replicas),
+ = CONTAINER_OF(ovs_list_pop_back(&db->replicas),
struct ovsdb_replica, node);
ovsdb_remove_replica(db, r);
}
}
}
+/* Adds some memory usage statistics for 'db' into 'usage', for use with
+ * memory_report(). */
+void
+ovsdb_get_memory_usage(const struct ovsdb *db, struct simap *usage)
+{
+ const struct shash_node *node;
+ unsigned int cells = 0;
+
+ SHASH_FOR_EACH (node, &db->tables) {
+ const struct ovsdb_table *table = node->data;
+ unsigned int n_columns = shash_count(&table->schema->columns);
+ unsigned int n_rows = hmap_count(&table->rows);
+
+ cells += n_rows * n_columns;
+ }
+
+ simap_increase(usage, "cells", cells);
+}
+
struct ovsdb_table *
ovsdb_get_table(const struct ovsdb *db, const char *name)
{
void
ovsdb_add_replica(struct ovsdb *db, struct ovsdb_replica *r)
{
- list_push_back(&db->replicas, &r->node);
+ ovs_list_push_back(&db->replicas, &r->node);
}
void
ovsdb_remove_replica(struct ovsdb *db OVS_UNUSED, struct ovsdb_replica *r)
{
- list_remove(&r->node);
+ ovs_list_remove(&r->node);
(r->class->destroy)(r);
}