lldp: Miscellaneous coding style fixes.
[cascardo/ovs.git] / lib / ovsdb-idl.c
index 3366523..9c25dbc 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
+/* Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
  *
  * 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,7 @@
 #include <stdlib.h>
 
 #include "bitmap.h"
+#include "coverage.h"
 #include "dynamic-string.h"
 #include "fatal-signal.h"
 #include "json.h"
 #include "poll-loop.h"
 #include "shash.h"
 #include "util.h"
-#include "vlog.h"
+#include "openvswitch/vlog.h"
 
 VLOG_DEFINE_THIS_MODULE(ovsdb_idl);
 
+COVERAGE_DEFINE(txn_uncommitted);
+COVERAGE_DEFINE(txn_unchanged);
+COVERAGE_DEFINE(txn_incomplete);
+COVERAGE_DEFINE(txn_aborted);
+COVERAGE_DEFINE(txn_success);
+COVERAGE_DEFINE(txn_try_again);
+COVERAGE_DEFINE(txn_not_locked);
+COVERAGE_DEFINE(txn_error);
+
 /* An arc from one idl_row to another.  When row A contains a UUID that
  * references row B, this is represented by an arc from A (the source) to B
  * (the destination).
@@ -55,8 +65,8 @@ VLOG_DEFINE_THIS_MODULE(ovsdb_idl);
  * tables.
  */
 struct ovsdb_idl_arc {
-    struct list src_node;       /* In src->src_arcs list. */
-    struct list dst_node;       /* In dst->dst_arcs list. */
+    struct ovs_list src_node;   /* In src->src_arcs list. */
+    struct ovs_list dst_node;   /* In dst->dst_arcs list. */
     struct ovsdb_idl_row *src;  /* Source row. */
     struct ovsdb_idl_row *dst;  /* Destination row. */
 };
@@ -394,6 +404,14 @@ ovsdb_idl_has_ever_connected(const struct ovsdb_idl *idl)
     return ovsdb_idl_get_seqno(idl) != 0;
 }
 
+/* Reconfigures 'idl' so that it would reconnect to the database, if
+ * connection was dropped. */
+void
+ovsdb_idl_enable_reconnect(struct ovsdb_idl *idl)
+{
+    jsonrpc_session_enable_reconnect(idl->session);
+}
+
 /* Forces 'idl' to drop its connection to the database and reconnect.  In the
  * meantime, the contents of 'idl' will not change. */
 void
@@ -441,7 +459,7 @@ ovsdb_idl_get_mode(struct ovsdb_idl *idl,
         }
     }
 
-    NOT_REACHED();
+    OVS_NOT_REACHED();
 }
 
 static void
@@ -505,7 +523,7 @@ ovsdb_idl_add_table(struct ovsdb_idl *idl,
         }
     }
 
-    NOT_REACHED();
+    OVS_NOT_REACHED();
 }
 
 /* Turns off OVSDB_IDL_ALERT for 'column' in 'idl'.
@@ -1178,6 +1196,21 @@ ovsdb_idl_get(const struct ovsdb_idl_row *row,
     return ovsdb_idl_read(row, column);
 }
 
+/* Returns true if the field represented by 'column' in 'row' may be modified,
+ * false if it is immutable.
+ *
+ * Normally, whether a field is mutable is controlled by its column's schema.
+ * However, an immutable column can be set to any initial value at the time of
+ * insertion, so if 'row' is a new row (one that is being added as part of the
+ * current transaction, supposing that a transaction is in progress) then even
+ * its "immutable" fields are actually mutable. */
+bool
+ovsdb_idl_is_mutable(const struct ovsdb_idl_row *row,
+                     const struct ovsdb_idl_column *column)
+{
+    return column->mutable || (row->new && !row->old);
+}
+
 /* Returns false if 'row' was obtained from the IDL, true if it was initialized
  * to all-zero-bits by some other entity.  If 'row' was set up some other way
  * then the return value is indeterminate. */
@@ -1516,14 +1549,13 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn)
     bool any_updates;
 
     if (txn != txn->idl->txn) {
-        return txn->status;
+        goto coverage_out;
     }
 
     /* If we need a lock but don't have it, give up quickly. */
     if (txn->idl->lock_name && !ovsdb_idl_has_lock(txn->idl)) {
         txn->status = TXN_NOT_LOCKED;
-        ovsdb_idl_txn_disassemble(txn);
-        return txn->status;
+        goto disassemble_out;
     }
 
     operations = json_array_create_1(
@@ -1707,7 +1739,20 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn)
         txn->status = TXN_TRY_AGAIN;
     }
 
+disassemble_out:
     ovsdb_idl_txn_disassemble(txn);
+coverage_out:
+    switch (txn->status) {
+    case TXN_UNCOMMITTED:   COVERAGE_INC(txn_uncommitted);    break;
+    case TXN_UNCHANGED:     COVERAGE_INC(txn_unchanged);      break;
+    case TXN_INCOMPLETE:    COVERAGE_INC(txn_incomplete);     break;
+    case TXN_ABORTED:       COVERAGE_INC(txn_aborted);        break;
+    case TXN_SUCCESS:       COVERAGE_INC(txn_success);        break;
+    case TXN_TRY_AGAIN:     COVERAGE_INC(txn_try_again);      break;
+    case TXN_NOT_LOCKED:    COVERAGE_INC(txn_not_locked);     break;
+    case TXN_ERROR:         COVERAGE_INC(txn_error);          break;
+    }
+
     return txn->status;
 }
 
@@ -2105,7 +2150,7 @@ ovsdb_idl_txn_process_inc_reply(struct ovsdb_idl_txn *txn,
 
     if (txn->inc_index + 2 > results->n) {
         VLOG_WARN_RL(&syntax_rl, "reply does not contain enough operations "
-                     "for increment (has %zu, needs %u)",
+                     "for increment (has %"PRIuSIZE", needs %u)",
                      results->n, txn->inc_index + 2);
         return false;
     }
@@ -2130,7 +2175,7 @@ ovsdb_idl_txn_process_inc_reply(struct ovsdb_idl_txn *txn,
         return false;
     }
     if (rows->u.array.n != 1) {
-        VLOG_WARN_RL(&syntax_rl, "\"select\" reply \"rows\" has %zu elements "
+        VLOG_WARN_RL(&syntax_rl, "\"select\" reply \"rows\" has %"PRIuSIZE" elements "
                      "instead of 1",
                      rows->u.array.n);
         return false;
@@ -2160,7 +2205,7 @@ ovsdb_idl_txn_process_insert_reply(struct ovsdb_idl_txn_insert *insert,
 
     if (insert->op_index >= results->n) {
         VLOG_WARN_RL(&syntax_rl, "reply does not contain enough operations "
-                     "for insert (has %zu, needs %u)",
+                     "for insert (has %"PRIuSIZE", needs %u)",
                      results->n, insert->op_index);
         return false;
     }