X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ovsdb%2Fovsdb.c;h=e27d0def49d1e41b391f0abc83fd282b4585ef36;hb=c5cf10598f8c9f4428291e9df3ecd72a05fb1ccf;hp=abe88e9f9fb86df34ac13025d716fb91c0a00460;hpb=42a49b96013c6a149ad0bdd9799b22db59630ae7;p=sliver-openvswitch.git diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c index abe88e9f9..e27d0def4 100644 --- a/ovsdb/ovsdb.c +++ b/ovsdb/ovsdb.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010, 2011 Nicira Networks +/* 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. @@ -22,6 +22,7 @@ #include "ovsdb-error.h" #include "ovsdb-parser.h" #include "ovsdb-types.h" +#include "simap.h" #include "table.h" #include "transaction.h" @@ -139,7 +140,7 @@ static bool 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'; } @@ -253,7 +254,7 @@ ovsdb_schema_from_json(struct json *json, struct ovsdb_schema **schemap) } *schemap = schema; - return 0; + return NULL; } struct json * @@ -384,6 +385,25 @@ ovsdb_destroy(struct ovsdb *db) } } +/* 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) {