X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fovsdb-idl.c;h=be4b255a3a4367e84ee5ed7b281475c255e3edfb;hb=4cceacb94cfc1d75a961d3d746d2ae369c397ae5;hp=bb7da668aebce0f7478f346018ef037229354388;hpb=2f92678735d089e2d2a0cb9e5f6ff3aae7ed38c0;p=openvswitch diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index bb7da668..be4b255a 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2009, 2010, 2011, 2012 Nicira Networks. +/* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,6 +70,7 @@ struct ovsdb_idl { struct json *monitor_request_id; unsigned int last_monitor_request_seqno; unsigned int change_seqno; + bool verify_write_only; /* Database locking. */ char *lock_name; /* Name of lock we need, NULL if none. */ @@ -230,6 +231,7 @@ ovsdb_idl_destroy(struct ovsdb_idl *idl) json_destroy(idl->monitor_request_id); free(idl->lock_name); json_destroy(idl->lock_request_id); + hmap_destroy(&idl->outstanding_txns); free(idl); } } @@ -401,6 +403,16 @@ ovsdb_idl_force_reconnect(struct ovsdb_idl *idl) { jsonrpc_session_force_reconnect(idl->session); } + +/* Some IDL users should only write to write-only columns. Furthermore, + * writing to a column which is not write-only can cause serious performance + * degradations for these users. This function causes 'idl' to reject writes + * to columns which are not marked write only using ovsdb_idl_omit_alert(). */ +void +ovsdb_idl_verify_write_only(struct ovsdb_idl *idl) +{ + idl->verify_write_only = true; +} static unsigned char * ovsdb_idl_get_mode(struct ovsdb_idl *idl, @@ -906,6 +918,7 @@ static struct ovsdb_idl_row * ovsdb_idl_row_create__(const struct ovsdb_idl_table_class *class) { struct ovsdb_idl_row *row = xzalloc(class->allocation_size); + class->row_init(row); list_init(&row->src_arcs); list_init(&row->dst_arcs); hmap_node_nullify(&row->txn_node); @@ -1819,9 +1832,10 @@ ovsdb_idl_txn_write(const struct ovsdb_idl_row *row_, const struct ovsdb_idl_column *column, struct ovsdb_datum *datum) { - struct ovsdb_idl_row *row = (struct ovsdb_idl_row *) row_; + struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_); const struct ovsdb_idl_table_class *class; size_t column_idx; + bool write_only; if (ovsdb_idl_row_is_synthetic(row)) { ovsdb_datum_destroy(datum, &column->type); @@ -1830,12 +1844,20 @@ ovsdb_idl_txn_write(const struct ovsdb_idl_row *row_, class = row->table->class; column_idx = column - class->columns; + write_only = row->table->modes[column_idx] == OVSDB_IDL_MONITOR; assert(row->new != NULL); assert(column_idx < class->n_columns); assert(row->old == NULL || row->table->modes[column_idx] & OVSDB_IDL_MONITOR); + if (row->table->idl->verify_write_only && !write_only) { + VLOG_ERR("Bug: Attempt to write to a read/write column (%s:%s) when" + " explicitly configured not to.", class->name, column->name); + ovsdb_datum_destroy(datum, &column->type); + return; + } + /* If this is a write-only column and the datum being written is the same * as the one already there, just skip the update entirely. This is worth * optimizing because we have a lot of columns that get periodically @@ -1847,9 +1869,8 @@ ovsdb_idl_txn_write(const struct ovsdb_idl_row *row_, * transaction only does writes of existing values, without making any real * changes, we will drop the whole transaction later in * ovsdb_idl_txn_commit().) */ - if (row->table->modes[column_idx] == OVSDB_IDL_MONITOR - && ovsdb_datum_equals(ovsdb_idl_read(row, column), - datum, &column->type)) { + if (write_only && ovsdb_datum_equals(ovsdb_idl_read(row, column), + datum, &column->type)) { ovsdb_datum_destroy(datum, &column->type); return; } @@ -1906,7 +1927,7 @@ void ovsdb_idl_txn_verify(const struct ovsdb_idl_row *row_, const struct ovsdb_idl_column *column) { - struct ovsdb_idl_row *row = (struct ovsdb_idl_row *) row_; + struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_); const struct ovsdb_idl_table_class *class; size_t column_idx; @@ -1945,7 +1966,7 @@ ovsdb_idl_txn_verify(const struct ovsdb_idl_row *row_, void ovsdb_idl_txn_delete(const struct ovsdb_idl_row *row_) { - struct ovsdb_idl_row *row = (struct ovsdb_idl_row *) row_; + struct ovsdb_idl_row *row = CONST_CAST(struct ovsdb_idl_row *, row_); if (ovsdb_idl_row_is_synthetic(row)) { return;