[ovs-dev] [ovsdb speedup 01/18] ovsdb: refactoring jsonrpc-server.c

Andy Zhou azhou at nicira.com
Thu Mar 19 07:08:17 UTC 2015


jsonrpc-server.c has two main functions. One deals with handling the
jsonrpc connections, the other deals with monitoring the database.

Currently, each jsonrpc connections has its own set of DB monitors.
This can be wasteful if a number of connections shares the same
monitors.

This patch, and a few following refactoring patches attempts to
split the jsonrpc handling front end off the main monitoring
functions within jsonrpc.c.

This patch changes the monitoring functions and data structures from
'ovsdb_jsonrpc_monitor_xxx' into 'ovsdb_monitor_xxx'

Signed-off-by: Andy Zhou <azhou at nicira.com>

------
The end goal of those refactoring patches is to move ovsdb_monitor
functions into its own file.
---
 ovsdb/jsonrpc-server.c | 221 +++++++++++++++++++++++++++----------------------
 1 file changed, 124 insertions(+), 97 deletions(-)

diff --git a/ovsdb/jsonrpc-server.c b/ovsdb/jsonrpc-server.c
index 2ba5ddd..5fdf08b 100644
--- a/ovsdb/jsonrpc-server.c
+++ b/ovsdb/jsonrpc-server.c
@@ -1026,9 +1026,9 @@ ovsdb_jsonrpc_trigger_complete_done(struct ovsdb_jsonrpc_session *s)
     }
 }
 
-/* JSON-RPC database table monitors. */
+/* database table monitors. */
 
-enum ovsdb_jsonrpc_monitor_selection {
+enum ovsdb_monitor_selection {
     OJMS_INITIAL = 1 << 0,      /* All rows when monitor is created. */
     OJMS_INSERT = 1 << 1,       /* New rows. */
     OJMS_DELETE = 1 << 2,       /* Deleted rows. */
@@ -1036,13 +1036,13 @@ enum ovsdb_jsonrpc_monitor_selection {
 };
 
 /* A particular column being monitored. */
-struct ovsdb_jsonrpc_monitor_column {
+struct ovsdb_monitor_column {
     const struct ovsdb_column *column;
-    enum ovsdb_jsonrpc_monitor_selection select;
+    enum ovsdb_monitor_selection select;
 };
 
 /* A row that has changed in a monitored table. */
-struct ovsdb_jsonrpc_monitor_row {
+struct ovsdb_monitor_row {
     struct hmap_node hmap_node; /* In ovsdb_jsonrpc_monitor_table.changes. */
     struct uuid uuid;           /* UUID of row that changed. */
     struct ovsdb_datum *old;    /* Old data, NULL for an inserted row. */
@@ -1050,38 +1050,49 @@ struct ovsdb_jsonrpc_monitor_row {
 };
 
 /* A particular table being monitored. */
-struct ovsdb_jsonrpc_monitor_table {
+struct ovsdb_monitor_table {
     const struct ovsdb_table *table;
 
     /* This is the union (bitwise-OR) of the 'select' values in all of the
      * members of 'columns' below. */
-    enum ovsdb_jsonrpc_monitor_selection select;
+    enum ovsdb_monitor_selection select;
 
     /* Columns being monitored. */
-    struct ovsdb_jsonrpc_monitor_column *columns;
+    struct ovsdb_monitor_column *columns;
     size_t n_columns;
 
-    /* Contains 'struct ovsdb_jsonrpc_monitor_row's for rows that have been
+    /* Contains 'struct ovsdb_monitor_row's for rows that have been
      * updated but not yet flushed to the jsonrpc connection. */
     struct hmap changes;
 };
 
+struct ovsdb_jsonrpc_monitor;
+/*  Backend monitor.
+ *
+ *  ovsdb_monitor keep track of the ovsdb changes.
+ */
 /* A collection of tables being monitored. */
-struct ovsdb_jsonrpc_monitor {
+struct ovsdb_monitor {
     struct ovsdb_replica replica;
+    struct shash tables;     /* Holds "struct ovsdb_monitor_table"s. */
+    struct ovsdb_jsonrpc_monitor *jsonrpc_monitor;
+};
+
+/* Jsonrpc front end monitor. */
+struct ovsdb_jsonrpc_monitor {
     struct ovsdb_jsonrpc_session *session;
     struct ovsdb *db;
     struct hmap_node node;      /* In ovsdb_jsonrpc_session's "monitors". */
 
     struct json *monitor_id;
-    struct shash tables;     /* Holds "struct ovsdb_jsonrpc_monitor_table"s. */
+    struct ovsdb_monitor *dbmon;
 };
 
 static const struct ovsdb_replica_class ovsdb_jsonrpc_replica_class;
 
 struct ovsdb_jsonrpc_monitor *ovsdb_jsonrpc_monitor_find(
     struct ovsdb_jsonrpc_session *, const struct json *monitor_id);
-static void ovsdb_jsonrpc_monitor_destroy(struct ovsdb_replica *);
+static void ovsdb_monitor_destroy(struct ovsdb_replica *);
 static struct json *ovsdb_jsonrpc_monitor_get_initial(
     const struct ovsdb_jsonrpc_monitor *);
 
@@ -1110,12 +1121,12 @@ ovsdb_jsonrpc_monitor_find(struct ovsdb_jsonrpc_session *s,
 }
 
 static void
-ovsdb_jsonrpc_add_monitor_column(struct ovsdb_jsonrpc_monitor_table *mt,
-                                 const struct ovsdb_column *column,
-                                 enum ovsdb_jsonrpc_monitor_selection select,
-                                 size_t *allocated_columns)
+ovsdb_add_monitor_column(struct ovsdb_monitor_table *mt,
+                         const struct ovsdb_column *column,
+                         enum ovsdb_monitor_selection select,
+                         size_t *allocated_columns)
 {
-    struct ovsdb_jsonrpc_monitor_column *c;
+    struct ovsdb_monitor_column *c;
 
     if (mt->n_columns >= *allocated_columns) {
         mt->columns = x2nrealloc(mt->columns, allocated_columns,
@@ -1128,21 +1139,21 @@ ovsdb_jsonrpc_add_monitor_column(struct ovsdb_jsonrpc_monitor_table *mt,
 }
 
 static int
-compare_ovsdb_jsonrpc_monitor_column(const void *a_, const void *b_)
+compare_ovsdb_monitor_column(const void *a_, const void *b_)
 {
-    const struct ovsdb_jsonrpc_monitor_column *a = a_;
-    const struct ovsdb_jsonrpc_monitor_column *b = b_;
+    const struct ovsdb_monitor_column *a = a_;
+    const struct ovsdb_monitor_column *b = b_;
 
     return a->column < b->column ? -1 : a->column > b->column;
 }
 
 static struct ovsdb_error * OVS_WARN_UNUSED_RESULT
-ovsdb_jsonrpc_parse_monitor_request(struct ovsdb_jsonrpc_monitor_table *mt,
+ovsdb_jsonrpc_parse_monitor_request(struct ovsdb_monitor_table *mt,
                                     const struct json *monitor_request,
                                     size_t *allocated_columns)
 {
     const struct ovsdb_table_schema *ts = mt->table->schema;
-    enum ovsdb_jsonrpc_monitor_selection select;
+    enum ovsdb_monitor_selection select;
     const struct json *columns, *select_json;
     struct ovsdb_parser parser;
     struct ovsdb_error *error;
@@ -1203,8 +1214,7 @@ ovsdb_jsonrpc_parse_monitor_request(struct ovsdb_jsonrpc_monitor_table *mt,
                 return ovsdb_syntax_error(columns, NULL, "%s is not a valid "
                                           "column name", s);
             }
-            ovsdb_jsonrpc_add_monitor_column(mt, column, select,
-                                             allocated_columns);
+            ovsdb_add_monitor_column(mt, column, select, allocated_columns);
         }
     } else {
         struct shash_node *node;
@@ -1212,8 +1222,8 @@ ovsdb_jsonrpc_parse_monitor_request(struct ovsdb_jsonrpc_monitor_table *mt,
         SHASH_FOR_EACH (node, &ts->columns) {
             const struct ovsdb_column *column = node->data;
             if (column->index != OVSDB_COL_UUID) {
-                ovsdb_jsonrpc_add_monitor_column(mt, column, select,
-                                                 allocated_columns);
+                ovsdb_add_monitor_column(mt, column, select,
+                                         allocated_columns);
             }
         }
     }
@@ -1221,6 +1231,23 @@ ovsdb_jsonrpc_parse_monitor_request(struct ovsdb_jsonrpc_monitor_table *mt,
     return NULL;
 }
 
+static struct ovsdb_monitor *
+ovsdb_monitor_create(struct ovsdb *db,
+                     struct ovsdb_jsonrpc_monitor *jsonrpc_monitor,
+                     const struct ovsdb_replica_class *replica_class)
+{
+    struct ovsdb_monitor *m;
+
+    m = xzalloc(sizeof *m);
+
+    ovsdb_replica_init(&m->replica, replica_class);
+    ovsdb_add_replica(db, &m->replica);
+    m->jsonrpc_monitor = jsonrpc_monitor;
+    shash_init(&m->tables);
+
+    return m;
+}
+
 static struct json *
 ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
                              struct json *params)
@@ -1249,17 +1276,15 @@ ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
     }
 
     m = xzalloc(sizeof *m);
-    ovsdb_replica_init(&m->replica, &ovsdb_jsonrpc_replica_class);
-    ovsdb_add_replica(db, &m->replica);
     m->session = s;
     m->db = db;
+    m->dbmon = ovsdb_monitor_create(db, m, &ovsdb_jsonrpc_replica_class);
     hmap_insert(&s->monitors, &m->node, json_hash(monitor_id, 0));
     m->monitor_id = json_clone(monitor_id);
-    shash_init(&m->tables);
 
     SHASH_FOR_EACH (node, json_object(monitor_requests)) {
         const struct ovsdb_table *table;
-        struct ovsdb_jsonrpc_monitor_table *mt;
+        struct ovsdb_monitor_table *mt;
         size_t allocated_columns;
         const struct json *mr_value;
         size_t i;
@@ -1274,7 +1299,7 @@ ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
         mt = xzalloc(sizeof *mt);
         mt->table = table;
         hmap_init(&mt->changes);
-        shash_add(&m->tables, table->schema->name, mt);
+        shash_add(&m->dbmon->tables, table->schema->name, mt);
 
         /* Parse columns. */
         mr_value = node->data;
@@ -1299,7 +1324,7 @@ ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
 
         /* Check for duplicate columns. */
         qsort(mt->columns, mt->n_columns, sizeof *mt->columns,
-              compare_ovsdb_jsonrpc_monitor_column);
+              compare_ovsdb_monitor_column);
         for (i = 1; i < mt->n_columns; i++) {
             if (mt->columns[i].column == mt->columns[i - 1].column) {
                 error = ovsdb_syntax_error(mr_value, NULL, "column %s "
@@ -1314,7 +1339,7 @@ ovsdb_jsonrpc_monitor_create(struct ovsdb_jsonrpc_session *s, struct ovsdb *db,
 
 error:
     if (m) {
-        ovsdb_remove_replica(m->db, &m->replica);
+        ovsdb_remove_replica(m->db, &m->dbmon->replica);
     }
 
     json = ovsdb_error_to_json(error);
@@ -1338,7 +1363,7 @@ ovsdb_jsonrpc_monitor_cancel(struct ovsdb_jsonrpc_session *s,
             return jsonrpc_create_error(json_string_create("unknown monitor"),
                                         request_id);
         } else {
-            ovsdb_remove_replica(m->db, &m->replica);
+            ovsdb_remove_replica(m->db, &m->dbmon->replica);
             return jsonrpc_create_reply(json_object_create(), request_id);
         }
     }
@@ -1350,29 +1375,29 @@ ovsdb_jsonrpc_monitor_remove_all(struct ovsdb_jsonrpc_session *s)
     struct ovsdb_jsonrpc_monitor *m, *next;
 
     HMAP_FOR_EACH_SAFE (m, next, node, &s->monitors) {
-        ovsdb_remove_replica(m->db, &m->replica);
+        ovsdb_remove_replica(m->db, &m->dbmon->replica);
     }
 }
 
-static struct ovsdb_jsonrpc_monitor *
-ovsdb_jsonrpc_monitor_cast(struct ovsdb_replica *replica)
+static struct ovsdb_monitor *
+ovsdb_monitor_cast(struct ovsdb_replica *replica)
 {
     ovs_assert(replica->class == &ovsdb_jsonrpc_replica_class);
-    return CONTAINER_OF(replica, struct ovsdb_jsonrpc_monitor, replica);
+    return CONTAINER_OF(replica, struct ovsdb_monitor, replica);
 }
 
-struct ovsdb_jsonrpc_monitor_aux {
-    const struct ovsdb_jsonrpc_monitor *monitor;
-    struct ovsdb_jsonrpc_monitor_table *mt;
+struct ovsdb_monitor_aux {
+    const struct ovsdb_monitor *monitor;
+    struct ovsdb_monitor_table *mt;
 };
 
-/* Finds and returns the ovsdb_jsonrpc_monitor_row in 'mt->changes' for the
+/* Finds and returns the ovsdb_monitor_row in 'mt->changes' for the
  * given 'uuid', or NULL if there is no such row. */
-static struct ovsdb_jsonrpc_monitor_row *
-ovsdb_jsonrpc_monitor_row_find(const struct ovsdb_jsonrpc_monitor_table *mt,
-                               const struct uuid *uuid)
+static struct ovsdb_monitor_row *
+ovsdb_monitor_row_find(const struct ovsdb_monitor_table *mt,
+                       const struct uuid *uuid)
 {
-    struct ovsdb_jsonrpc_monitor_row *row;
+    struct ovsdb_monitor_row *row;
 
     HMAP_FOR_EACH_WITH_HASH (row, hmap_node, uuid_hash(uuid), &mt->changes) {
         if (uuid_equals(uuid, &row->uuid)) {
@@ -1388,7 +1413,7 @@ ovsdb_jsonrpc_monitor_row_find(const struct ovsdb_jsonrpc_monitor_table *mt,
  *
  * If 'row' is NULL, returns NULL. */
 static struct ovsdb_datum *
-clone_monitor_row_data(const struct ovsdb_jsonrpc_monitor_table *mt,
+clone_monitor_row_data(const struct ovsdb_monitor_table *mt,
                        const struct ovsdb_row *row)
 {
     struct ovsdb_datum *data;
@@ -1413,7 +1438,7 @@ clone_monitor_row_data(const struct ovsdb_jsonrpc_monitor_table *mt,
 /* Replaces the mt->n_columns ovsdb_datums in row[] by copies of the data from
  * in 'row' drawn from the columns represented by mt->columns[]. */
 static void
-update_monitor_row_data(const struct ovsdb_jsonrpc_monitor_table *mt,
+update_monitor_row_data(const struct ovsdb_monitor_table *mt,
                         const struct ovsdb_row *row,
                         struct ovsdb_datum *data)
 {
@@ -1435,7 +1460,7 @@ update_monitor_row_data(const struct ovsdb_jsonrpc_monitor_table *mt,
 /* Frees all of the mt->n_columns ovsdb_datums in data[], using the types taken
  * from mt->columns[], plus 'data' itself. */
 static void
-free_monitor_row_data(const struct ovsdb_jsonrpc_monitor_table *mt,
+free_monitor_row_data(const struct ovsdb_monitor_table *mt,
                       struct ovsdb_datum *data)
 {
     if (data) {
@@ -1452,8 +1477,8 @@ free_monitor_row_data(const struct ovsdb_jsonrpc_monitor_table *mt,
 
 /* Frees 'row', which must have been created from 'mt'. */
 static void
-ovsdb_jsonrpc_monitor_row_destroy(const struct ovsdb_jsonrpc_monitor_table *mt,
-                                  struct ovsdb_jsonrpc_monitor_row *row)
+ovsdb_monitor_row_destroy(const struct ovsdb_monitor_table *mt,
+                          struct ovsdb_monitor_row *row)
 {
     if (row) {
         free_monitor_row_data(mt, row->old);
@@ -1463,17 +1488,17 @@ ovsdb_jsonrpc_monitor_row_destroy(const struct ovsdb_jsonrpc_monitor_table *mt,
 }
 
 static bool
-ovsdb_jsonrpc_monitor_change_cb(const struct ovsdb_row *old,
-                                const struct ovsdb_row *new,
-                                const unsigned long int *changed OVS_UNUSED,
-                                void *aux_)
+ovsdb_monitor_change_cb(const struct ovsdb_row *old,
+                        const struct ovsdb_row *new,
+                        const unsigned long int *changed OVS_UNUSED,
+                        void *aux_)
 {
-    struct ovsdb_jsonrpc_monitor_aux *aux = aux_;
-    const struct ovsdb_jsonrpc_monitor *m = aux->monitor;
+    struct ovsdb_monitor_aux *aux = aux_;
+    const struct ovsdb_monitor *m = aux->monitor;
     struct ovsdb_table *table = new ? new->table : old->table;
     const struct uuid *uuid = ovsdb_row_get_uuid(new ? new : old);
-    struct ovsdb_jsonrpc_monitor_row *change;
-    struct ovsdb_jsonrpc_monitor_table *mt;
+    struct ovsdb_monitor_row *change;
+    struct ovsdb_monitor_table *mt;
 
     if (!aux->mt || table != aux->mt->table) {
         aux->mt = shash_find_data(&m->tables, table->schema->name);
@@ -1485,7 +1510,7 @@ ovsdb_jsonrpc_monitor_change_cb(const struct ovsdb_row *old,
     }
     mt = aux->mt;
 
-    change = ovsdb_jsonrpc_monitor_row_find(mt, uuid);
+    change = ovsdb_monitor_row_find(mt, uuid);
     if (!change) {
         change = xmalloc(sizeof *change);
         hmap_insert(&mt->changes, &change->hmap_node, uuid_hash(uuid));
@@ -1519,12 +1544,12 @@ ovsdb_jsonrpc_monitor_change_cb(const struct ovsdb_row *old,
  * 'changed' must be a scratch buffer for internal use that is at least
  * bitmap_n_bytes(mt->n_columns) bytes long. */
 static struct json *
-ovsdb_jsonrpc_monitor_compose_row_update(
-    const struct ovsdb_jsonrpc_monitor_table *mt,
-    const struct ovsdb_jsonrpc_monitor_row *row,
+ovsdb_monitor_compose_row_update(
+    const struct ovsdb_monitor_table *mt,
+    const struct ovsdb_monitor_row *row,
     bool initial, unsigned long int *changed)
 {
-    enum ovsdb_jsonrpc_monitor_selection type;
+    enum ovsdb_monitor_selection type;
     struct json *old_json, *new_json;
     struct json *row_json;
     size_t i;
@@ -1567,7 +1592,7 @@ ovsdb_jsonrpc_monitor_compose_row_update(
         json_object_put(row_json, "new", new_json);
     }
     for (i = 0; i < mt->n_columns; i++) {
-        const struct ovsdb_jsonrpc_monitor_column *c = &mt->columns[i];
+        const struct ovsdb_monitor_column *c = &mt->columns[i];
 
         if (!(type & c->select)) {
             /* We don't care about this type of change for this
@@ -1610,23 +1635,23 @@ ovsdb_jsonrpc_monitor_compose_table_update(
     size_t max_columns;
 
     max_columns = 0;
-    SHASH_FOR_EACH (node, &monitor->tables) {
-        struct ovsdb_jsonrpc_monitor_table *mt = node->data;
+    SHASH_FOR_EACH (node, &monitor->dbmon->tables) {
+        struct ovsdb_monitor_table *mt = node->data;
 
         max_columns = MAX(max_columns, mt->n_columns);
     }
     changed = xmalloc(bitmap_n_bytes(max_columns));
 
     json = NULL;
-    SHASH_FOR_EACH (node, &monitor->tables) {
-        struct ovsdb_jsonrpc_monitor_table *mt = node->data;
-        struct ovsdb_jsonrpc_monitor_row *row, *next;
+    SHASH_FOR_EACH (node, &monitor->dbmon->tables) {
+        struct ovsdb_monitor_table *mt = node->data;
+        struct ovsdb_monitor_row *row, *next;
         struct json *table_json = NULL;
 
         HMAP_FOR_EACH_SAFE (row, next, hmap_node, &mt->changes) {
             struct json *row_json;
 
-            row_json = ovsdb_jsonrpc_monitor_compose_row_update(
+            row_json = ovsdb_monitor_compose_row_update(
                 mt, row, initial, changed);
             if (row_json) {
                 char uuid[UUID_LEN + 1];
@@ -1648,7 +1673,7 @@ ovsdb_jsonrpc_monitor_compose_table_update(
             }
 
             hmap_remove(&mt->changes, &row->hmap_node);
-            ovsdb_jsonrpc_monitor_row_destroy(mt, row);
+            ovsdb_monitor_row_destroy(mt, row);
         }
     }
 
@@ -1665,8 +1690,8 @@ ovsdb_jsonrpc_monitor_needs_flush(struct ovsdb_jsonrpc_session *s)
     HMAP_FOR_EACH (m, node, &s->monitors) {
         struct shash_node *node;
 
-        SHASH_FOR_EACH (node, &m->tables) {
-            struct ovsdb_jsonrpc_monitor_table *mt = node->data;
+        SHASH_FOR_EACH (node, &m->dbmon->tables) {
+            struct ovsdb_monitor_table *mt = node->data;
 
             if (!hmap_is_empty(&mt->changes)) {
                 return true;
@@ -1698,23 +1723,23 @@ ovsdb_jsonrpc_monitor_flush_all(struct ovsdb_jsonrpc_session *s)
 }
 
 static void
-ovsdb_jsonrpc_monitor_init_aux(struct ovsdb_jsonrpc_monitor_aux *aux,
-                               const struct ovsdb_jsonrpc_monitor *m)
+ovsdb_monitor_init_aux(struct ovsdb_monitor_aux *aux,
+                       const struct ovsdb_monitor *m)
 {
     aux->monitor = m;
     aux->mt = NULL;
 }
 
 static struct ovsdb_error *
-ovsdb_jsonrpc_monitor_commit(struct ovsdb_replica *replica,
-                             const struct ovsdb_txn *txn,
-                             bool durable OVS_UNUSED)
+ovsdb_monitor_commit(struct ovsdb_replica *replica,
+                     const struct ovsdb_txn *txn,
+                     bool durable OVS_UNUSED)
 {
-    struct ovsdb_jsonrpc_monitor *m = ovsdb_jsonrpc_monitor_cast(replica);
-    struct ovsdb_jsonrpc_monitor_aux aux;
+    struct ovsdb_monitor *m = ovsdb_monitor_cast(replica);
+    struct ovsdb_monitor_aux aux;
 
-    ovsdb_jsonrpc_monitor_init_aux(&aux, m);
-    ovsdb_txn_for_each_change(txn, ovsdb_jsonrpc_monitor_change_cb, &aux);
+    ovsdb_monitor_init_aux(&aux, m);
+    ovsdb_txn_for_each_change(txn, ovsdb_monitor_change_cb, &aux);
 
     return NULL;
 }
@@ -1722,19 +1747,19 @@ ovsdb_jsonrpc_monitor_commit(struct ovsdb_replica *replica,
 static struct json *
 ovsdb_jsonrpc_monitor_get_initial(const struct ovsdb_jsonrpc_monitor *m)
 {
-    struct ovsdb_jsonrpc_monitor_aux aux;
+    struct ovsdb_monitor_aux aux;
     struct shash_node *node;
     struct json *json;
 
-    ovsdb_jsonrpc_monitor_init_aux(&aux, m);
-    SHASH_FOR_EACH (node, &m->tables) {
-        struct ovsdb_jsonrpc_monitor_table *mt = node->data;
+    ovsdb_monitor_init_aux(&aux, m->dbmon);
+    SHASH_FOR_EACH (node, &m->dbmon->tables) {
+        struct ovsdb_monitor_table *mt = node->data;
 
         if (mt->select & OJMS_INITIAL) {
             struct ovsdb_row *row;
 
             HMAP_FOR_EACH (row, hmap_node, &mt->table->rows) {
-                ovsdb_jsonrpc_monitor_change_cb(NULL, row, NULL, &aux);
+                ovsdb_monitor_change_cb(NULL, row, NULL, &aux);
             }
         }
     }
@@ -1743,19 +1768,20 @@ ovsdb_jsonrpc_monitor_get_initial(const struct ovsdb_jsonrpc_monitor *m)
 }
 
 static void
-ovsdb_jsonrpc_monitor_destroy(struct ovsdb_replica *replica)
+ovsdb_monitor_destroy(struct ovsdb_replica *replica)
 {
-    struct ovsdb_jsonrpc_monitor *m = ovsdb_jsonrpc_monitor_cast(replica);
+    struct ovsdb_monitor *m = ovsdb_monitor_cast(replica);
+    struct ovsdb_jsonrpc_monitor *jsonrpc_monitor = m->jsonrpc_monitor;
     struct shash_node *node;
 
-    json_destroy(m->monitor_id);
+    json_destroy(jsonrpc_monitor->monitor_id);
     SHASH_FOR_EACH (node, &m->tables) {
-        struct ovsdb_jsonrpc_monitor_table *mt = node->data;
-        struct ovsdb_jsonrpc_monitor_row *row, *next;
+        struct ovsdb_monitor_table *mt = node->data;
+        struct ovsdb_monitor_row *row, *next;
 
         HMAP_FOR_EACH_SAFE (row, next, hmap_node, &mt->changes) {
             hmap_remove(&mt->changes, &row->hmap_node);
-            ovsdb_jsonrpc_monitor_row_destroy(mt, row);
+            ovsdb_monitor_row_destroy(mt, row);
         }
         hmap_destroy(&mt->changes);
 
@@ -1763,11 +1789,12 @@ ovsdb_jsonrpc_monitor_destroy(struct ovsdb_replica *replica)
         free(mt);
     }
     shash_destroy(&m->tables);
-    hmap_remove(&m->session->monitors, &m->node);
+    hmap_remove(&jsonrpc_monitor->session->monitors, &jsonrpc_monitor->node);
+    free(jsonrpc_monitor);
     free(m);
 }
 
 static const struct ovsdb_replica_class ovsdb_jsonrpc_replica_class = {
-    ovsdb_jsonrpc_monitor_commit,
-    ovsdb_jsonrpc_monitor_destroy
+    ovsdb_monitor_commit,
+    ovsdb_monitor_destroy
 };
-- 
1.9.1




More information about the dev mailing list