summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2010-03-12 10:27:33 -0800
committerBen Pfaff <blp@nicira.com>2010-03-17 14:24:55 -0700
commit80af01eda87eaaf16369642d2733e561b3d56b71 (patch)
treeb63a855a28257fe1abe4b1187e4ecc3413dc3304 /lib
parentb405dcfb4ee1d105ffcf3931873fb13121375aa8 (diff)
downloadopenvswitch-80af01eda87eaaf16369642d2733e561b3d56b71.tar.gz
New function ovsdb_error_assert() for verifying that no error occurred.
Diffstat (limited to 'lib')
-rw-r--r--lib/ovsdb-error.c22
-rw-r--r--lib/ovsdb-error.h4
-rw-r--r--lib/vlog-modules.def1
3 files changed, 25 insertions, 2 deletions
diff --git a/lib/ovsdb-error.c b/lib/ovsdb-error.c
index c0eddf280..c9221493d 100644
--- a/lib/ovsdb-error.c
+++ b/lib/ovsdb-error.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +23,10 @@
#include "dynamic-string.h"
#include "json.h"
#include "util.h"
+#include "vlog.h"
+
+#define THIS_MODULE VLM_ovsdb_error
+#include "vlog.h"
struct ovsdb_error {
const char *tag; /* String for "error" member. */
@@ -219,3 +223,19 @@ ovsdb_error_get_tag(const struct ovsdb_error *error)
{
return error->tag;
}
+
+/* If 'error' is nonnull, logs it as an error and frees it. To be used in
+ * situations where an error should never occur, but an 'ovsdb_error *' gets
+ * passed back anyhow. */
+void
+ovsdb_error_assert(struct ovsdb_error *error)
+{
+ if (error) {
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
+ char *s = ovsdb_error_to_string(error);
+ VLOG_ERR_RL(&rl, "unexpected ovsdb error: %s", s);
+ free(s);
+ ovsdb_error_destroy(error);
+ }
+}
+
diff --git a/lib/ovsdb-error.h b/lib/ovsdb-error.h
index 7e2523e3c..2bff3ae56 100644
--- a/lib/ovsdb-error.h
+++ b/lib/ovsdb-error.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,4 +50,6 @@ struct json *ovsdb_error_to_json(const struct ovsdb_error *);
const char *ovsdb_error_get_tag(const struct ovsdb_error *);
+void ovsdb_error_assert(struct ovsdb_error *);
+
#endif /* ovsdb-error.h */
diff --git a/lib/vlog-modules.def b/lib/vlog-modules.def
index f012e10c7..e3a0ebd23 100644
--- a/lib/vlog-modules.def
+++ b/lib/vlog-modules.def
@@ -51,6 +51,7 @@ VLOG_MODULE(ovs_discover)
VLOG_MODULE(ofproto)
VLOG_MODULE(openflowd)
VLOG_MODULE(ovsdb_client)
+VLOG_MODULE(ovsdb_error)
VLOG_MODULE(ovsdb_file)
VLOG_MODULE(ovsdb_idl)
VLOG_MODULE(ovsdb_log)