2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00

88 Commits

Author SHA1 Message Date
Thomas Graf
ca6ba70092 list: Rename struct list to struct ovs_list
struct list is a common name and can't be used in public headers.

Signed-off-by: Thomas Graf <tgraf@noironetworks.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2014-12-15 14:15:12 +01:00
Ben Pfaff
ff495b6378 ovs-vsctl: Allow modifying "immutable" columns if we just created the row.
OVSDB has the concept of "immutable" columns, which are columns whose
values are fixed once a row is inserted.  Until now, ovs-vsctl has not
allowed these columns to be modified at all.  However, this is a little too
strict, because these columns can be set to any value at the time that the
row is inserted.  This commit relaxes the ovs-vsctl requirement, then, to
allow an immutable column's value to be modified if its row has been
inserted within this transaction.

Requested-by: Mukesh Hira <mhira@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2014-10-08 13:12:45 -07:00
Ryan Wilson
60032110f1 ovsdb-idl: Add coverage counters for ovsdb commit return statuses.
Signed-off-by: Ryan Wilson <wryan@nicira.com>
Acked-by: Alex Wang <alexw@nicira.com>
Signed-off-by: Alex Wang <alexw@nicira.com>
2014-05-29 23:48:41 -07:00
Ansis Atteka
705d7a3930 ovs-vsctl: reconnect to the database if connection was dropped
If ovs-vsctl has to wait for ovs-vswitchd to reconfigure itself
according to the new database, then sometimes ovs-vsctl could
end up stuck in the event loop if OVSDB connection was dropped
while ovs-vsctl was still running.

This patch fixes this problem by letting ovs-vsctl to reconnect
to the OVSDB, if it has to wait cur_cfg field to be updated.

Issue: 1191997
Reported-by: Spiro Kourtessis <spiro@nicira.com>
Signed-Off-By: Ansis Atteka <aatteka@nicira.com>
2014-02-19 14:01:05 -08:00
Harold Lim
428b2eddc9 Rename NOT_REACHED to OVS_NOT_REACHED
This allows other libraries to use util.h that has already
defined NOT_REACHED.

Signed-off-by: Harold Lim <haroldl@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-12-17 13:16:39 -08:00
Alin Serdean
34582733d9 Avoid printf type modifiers not supported by MSVC C runtime library.
The MSVC C library printf() implementation does not support the 'z', 't',
'j', or 'hh' format specifiers.  This commit changes the Open vSwitch code
to avoid those format specifiers, switching to standard macros from
<inttypes.h> where available and inventing new macros resembling them
where necessary.  It also updates CodingStyle to specify the macros' use
and adds a Makefile rule to report violations.

Signed-off-by: Alin Serdean <aserdean@cloudbasesolutions.com>
Co-authored-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-11-25 23:38:59 -08:00
Joe Stringer
6647cb8ce7 lib: Remove unreachable JSONRPC case
jsonrpc_session_recv() handles echo replies prior to this.

Found by inspection.

Signed-off-by: Joe Stringer <joestringer@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-10-25 12:24:42 -07:00
Ben Pfaff
61d68589ec ovsdb-idl: Remove write-only member 'commit_seqno' from ovsdb_idl_txn.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
2013-10-08 15:12:24 -07:00
Ben Pfaff
fba6bd1d3f ovs-vsctl: Try connecting only once for active connections by default.
Until now, ovs-vsctl has kept trying to the database server until it
succeeded or the timeout expired (if one was specified with --timeout).
This meant that if ovsdb-server wasn't running, then ovs-vsctl would hang.
The result was that almost every ovs-vsctl invocation in scripts specified
a timeout on the off-chance that the database server might not be running.
But it's difficult to choose a good timeout.  A timeout that is too short
can cause spurious failures.  A timeout that is too long causes long delays
if the server really isn't running.

This commit should alleviate this problem.  It changes ovs-vsctl's behavior
so that, if it fails to connect to the server, it exits unsuccessfully.
This makes --timeout obsolete for the purpose of avoiding a hang if the
database server isn't running.  (--timeout is still useful to avoid a hang
if ovsdb-server is running but ovs-vswitchd is not, for ovs-vsctl commands
that modify the database.  --no-wait also avoids that issue.)

Bug #2393.
Bug #15594.
Reported-by: Jeff Merrick <jmerrick@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2013-03-15 16:26:47 -07:00
Ben Pfaff
fe19569ac5 ovsdb-idlc: Make no-op writes to write-only columns cheaper.
For 1000 tunnels with CFM enabled, this reduces CPU use from
about 36% to about 30%.

Bug #15171.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-03-05 21:35:41 -08:00
Ben Pfaff
9582c4f577 ovsdb-idl: Fix memory leak on error path.
Found by Coverity.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-31 14:13:17 -08:00
Ben Pfaff
cb22974d77 Replace most uses of assert by ovs_assert.
This is a straight search-and-replace, except that I also removed #include
<assert.h> from each file where there were no assert calls left.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Ethan Jackson <ethan@nicira.com>
2013-01-16 16:03:37 -08:00
Ethan Jackson
8cdec72569 idl: Optionally warn when writing to read-write columns.
ovs-vswitchd should only write to write-only columns.  Furthermore,
writing to a column which is not write-only can cause serious
performance degradations.  This patch causes ovs-vswitchd to log
and reject writes to read-write columns.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-09-27 17:23:17 -07:00
Ben Pfaff
da157f1ef4 ovsdb-idl: Fix memory leak.
Found by valgrind.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-08-16 08:22:00 -07:00
Ben Pfaff
ebc56baa41 util: New macro CONST_CAST.
Casts are sometimes necessary.  One common reason that they are necessary
is for discarding a "const" qualifier.  However, this can impede
maintenance: if the type of the expression being cast changes, then the
presence of the cast can hide a necessary change in the code that does the
cast.  Using CONST_CAST, instead of a bare cast, makes these changes
visible.

Inspired by my own work elsewhere:
http://git.savannah.gnu.org/cgit/pspp.git/tree/src/libpspp/cast.h#n80

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-08-03 13:33:13 -07:00
Ethan Jackson
a699f6143e lib: Utilize smaps in the idl.
String to string maps are used all over the Open vSwitch database.
Before this patch, they were implemented in the idl as parallel
string arrays.  This strategy has proven a bit cumbersome.  With
this patch, string to string maps are implemented using the smap
library.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
2012-06-14 16:41:44 -07:00
Raju Subramanian
e0edde6fee Global replace of Nicira Networks.
Replaced all instances of Nicira Networks(, Inc) to Nicira, Inc.

Feature #10593
Signed-off-by: Raju Subramanian <rsubramanian@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-05-02 17:08:02 -07:00
Ben Pfaff
2f92678735 ovsdb-idl: Improve documentation.
Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-12 08:28:14 -07:00
Ben Pfaff
94fbe1aae2 ovsdb-idl: Improve ovsdb_idl_txn_increment() interface.
The previous interface was just bizarre.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-12 08:28:13 -07:00
Ben Pfaff
854a94d9d2 ovsdb-idl: Simplify transaction retry.
Originally the IDL transaction state machine had a return value
TXN_TRY_AGAIN to signal the client to wait for a change in the database and
then retry its transaction.  However, this logic was incomplete, because
it was possible for the database to change before the reply to the
transaction RPC was received, in which case the client would wait for a
further change.  Commit 4fdfe5ccf84c (ovsdb-idl: Prevent occasional hang
when multiple database clients race.) fixed the problem by breaking
TXN_TRY_AGAIN into two status codes, TXN_AGAIN_WAIT that meant to wait for
a further change and TXN_AGAIN_NOW that meant that a change had already
occurred so try again immediately.

This is correct enough, but it is more complicated than necessary.  It is
simpler and just as correct to use a single "try again" status that
requires the client to wait for a change relative to the database contents
*before* the transaction was committed.  This commit makes that change.
It also changes ovsdb_idl_run()'s return type from bool to void because
its return type is hardly useful anymore.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-04-12 08:19:01 -07:00
Ben Pfaff
e787d2f427 ovsdb-idl: Fix memory leak writing synthetic rows in ovsdb_idl_txn_write().
This could cause a slow but steady memory leak in ovs-vswitchd.

Found by valgrind.

Signed-off-by: Ben Pfaff <blp@nicira.com>
2012-03-28 14:54:43 -07:00
Ben Pfaff
942d31c862 ovsdb-idl: Add assertion for synthetic records in ovsdb_idl_read().
This function doesn't support synthetic records but it probably isn't
obvious from looking at it, so add an actual assertion.
2011-11-23 15:32:37 -08:00
Ben Pfaff
4fdfe5ccf8 ovsdb-idl: Prevent occasional hang when multiple database clients race.
When a client of the IDL tries to commit a read-modify-write transaction
but the database has changed in the meantime, the IDL tells its client to
wait for the IDL to change and then try the transaction again by returning
TXN_TRY_AGAIN.  The "wait for the IDL to change" part is important because
there's no point in retrying the transaction before the IDL has received
the database updates (the transaction would fail in the same way all over
again).

However, the logic was incomplete: the database update can be received
*before* the reply to the transaction RPC (I think that in the current
ovsdb-server implementation this will always happen, in fact).  When this
happens, the right thing to do is to retry the transaction immediately;
if we wait, then we're waiting for an additional change to the database
that may never come, causing an indefinite hang.

This commit therefore breaks the "try again" IDL commit status code
into two, one that means "try again immediately" and another that means
"wait for a change then try again".  When an update is processed after a
transaction is committed but before the reply is received, the "try again
now" tells the IDL client not to wait for another database change before
retrying its transaction.

Bug #5980.
Reported-by: Ram Jothikumar <rjothikumar@nicira.com>
Reproduced-by: Alex Yip <alex@nicira.com>
2011-10-31 09:15:14 -07:00
Ben Pfaff
9b446bfaa2 ovsdb-idl: Don't even try to modify synthetic rows, instead of segfaulting.
Synthetic rows lack a lot of important metadata that the IDL adds to rows
actually obtained from the database, and it's impractical to add that
metadata to synthetic rows.  This means that the IDL functions to modify
these rows dereference null pointers and segfault.  So, it's really
important not to pass synthetic rows to such functions.  However, we've
screwed this up a number of times now and in the end it seems that it's
probably better to just ignore attempts to modify these rows.  This commit
implements that.

Feature #8013.
Reported-by: Ethan Jackson <ethan@nicira.com>
2011-10-27 10:36:30 -07:00
Ben Pfaff
d95d15107e ovsdb-idl: Code style improvements.
I noticed these opportunities for improvement while working on the Python
IDL.
2011-09-23 09:10:44 -07:00
Ben Pfaff
06b6d65132 vswitchd: Prevent multiple ovs-vswitchd processes from acting together.
Once in a while someone reports a problem caused by running multiple
ovs-vswitchd processes at the same time.  This fixes the problem by
requiring ovs-vswitchd to obtain a database lock before taking any actions.
2011-07-26 16:50:09 -07:00
Ben Pfaff
2096903b45 ovsdb-idl: Plug hole in state machine.
The state machine didn't have a proper state for "not yet committed or
aborted", which meant that destroying an ovsdb_idl_txn without committing
or aborting it caused a segfault.  This fixes the problem by adding a new
state TXN_UNCOMMITTED to the state machine.

This is related to commit 79554078d "ovsdb-idl: Fix bad logic in
ovsdb_idl_txn_commit() state transitions", which fixed a related bug.

Bug #2438.
2011-06-21 15:09:56 -07:00
Ben Pfaff
27a325164f ovsdb-idl: Improve comment. 2011-06-21 13:01:55 -07:00
Ben Pfaff
c15f1d11fa ovsdb-idl: Optimize out transactions that are complete no-ops.
Commit 1cc618c3252 "ovsdb-idl: Fix atomicity of writes that don't change a
column's value" fixed transactions that write the existing value to
some columns, ensuring that those columns still got written to the database
to avoid making the transaction nonatomic in the presence of writes that do
modify part of the database.

However, that commit was too conservative: we can still optimize out a
database transaction that writes *only* existing values to the database,
because if we drop such a transaction then the resulting database is still
one that could result from executing transactions in a serial order.  This
commit implements that optimization.

As an example of what this commit does, before this commit, an "ovs-vsctl
set" command that specified the existing value for a column would do a
round-trip to the database to write that existing value.  After this
commit, that round-trip would not occur.

Found by observing system startup.
2011-06-15 12:29:50 -07:00
Ben Pfaff
cfea354b81 bridge: Tolerate missing Port and Interface records for local port.
Until now, ovs-vswitchd has been unable to configure IP addresses and
routes for bridges whose Bridge records lack a Port and an Interface
record for the bridge's local port (e.g. OFPP_LOCAL, the port with the
same name as the bridge itself).  When such a bridge was reconfigured,
ovs-vswitchd would output a log message that worried people.

This commit fixes the internal limitation that led to the message being
printed.

Bug #5385.
2011-04-21 13:35:16 -07:00
Ben Pfaff
dcd1dbc5b3 ovsdb-idl: Suppress "delete" operations for garbage-collected tables.
Deciding what delete operations to issue on garbage-collected tables has
been a bit of a difficult issue for ovs-vsctl.  When garbage collection was
introduced in commit c5f341a "ovsdb: Implement garbage collection",
ovs-vsctl did not issue any deletions for these tables at all.  As a side
effect, ovs-vsctl did not notice that records were going to be deleted.
That meant that when multiple commands were issued in one ovs-vsctl run,
ovs-vsctl could get confused by apparent duplicate records that did not
in fact exist.  Commit 28a14bf "ovs-vsctl: Back out garbage collection
changes" fixed the problem by putting all of the explicit deletions back
into ovs-vsctl.

However, adding these explicit deletions had the price that it then became
(again) impossible to use ovs-vsctl commands to delete duplicates, for
example to use "ovs-vsctl del-br" to delete a bridge that points to the
same Port records that some other Bridge record also does.  This commit
makes that possible again, by implementing a compromise:

    * Internally, ovs-vsctl deletes the records that it believes should be
      deleted.

    * ovsdb-idl suppresses the deletions when it makes the RPC call into
      the database server.

Bug #5358.
Reported-by: Henrik Amren <henrik@nicira.com>
2011-04-12 11:31:58 -07:00
Ben Pfaff
1cc618c325 ovsdb-idl: Fix atomicity of writes that don't change a column's value.
The existing ovsdb_idl_txn_commit() drops any writes that don't change a
column's value from what was last reported by the database.  But this isn't
a valid optimization, because it breaks the atomicity of transactions.
Suppose columns A and B initially have values 1 and 2.  Client 1 writes
value 1 to both columns in one transaction.  Client 2 writes value 2 to
both columns in another transaction.  The only possible valid results for
any serial ordering of transactions are 1,1 or 2,2.  But if both clients
drop writes to columns that they have not modified, then 2,1 also becomes
possible (because client 1 just writes to B and client 2 just writes to A).

However, for write-only columns we can optimize this out because the IDL
can assume it is the only client writing to a column.

Found by inspection.
2011-04-08 13:56:56 -07:00
Ben Pfaff
0f0b102dcf ovsdb-idl: JSONRPC_REPLY message always has nonnull 'id'.
A JSONRPC_REPLY message always have a nonnull 'id' member, as ensured by
jsonrpc_msg_is_valid().  Checking for NULL here confused Coverity into
believing that the call to ovsdb_idl_txn_process_reply() just below could
cause a null pointer dereference, since ovsdb_idl_txn_process_reply() uses
the 'id' member without checking it for null.

Coverity #10713.
2011-02-23 15:14:42 -08:00
Justin Pettit
828cd4c7cd ovsdb-idl: Remove deadcode related to "reply" in ovsdb_idl_run().
Coverity #10705
2011-02-23 11:08:20 -08:00
Ben Pfaff
ee21cfa751 ovsdb-idl: Check prerequisites for ovsdb_idl_txn_verify() also.
The IDL can only verify prerequisites for columns that it is monitoring,
but it didn't check for that.  This assertion (which is the same as one in
ovsdb_idl_txn_write()) should alert us to such problems.

This would have found the problem fixed by the previous commit.
2010-12-08 17:09:29 -08:00
Ben Pfaff
ef73f86cd4 ovsdb-idl: Make selecting tables and columns to replicate more flexible.
Until now, by default the IDL replicated all tables and all columns in the
database, and a few functions made it possible to avoid replicating
selected columns.  This commit adds a mode in which nothing is replicated
by default and the client code is responsible for specifying each column
and table that it is interested in.  The following commit adds a user for
this mode.
2010-11-16 09:14:52 -08:00
Ben Pfaff
d98e600755 vlog: Make client supply semicolon for VLOG_DEFINE_THIS_MODULE.
It's kind of odd for VLOG_DEFINE_THIS_MODULE to supply its own semicolon,
so this commit switches to the more common form.
2010-10-29 09:48:47 -07:00
Ben Pfaff
b827c67b9e ovsdb-idl: Document some more functions.
Suggested-by: Justin Pettit <jpettit@nicira.com>
2010-10-27 09:27:19 -07:00
Ben Pfaff
4e8e4213a8 Switch many macros from using CONTAINER_OF to using OBJECT_CONTAINING.
These macros require one fewer argument by switching, which makes code
that uses them shorter and more readable.
2010-10-01 10:25:29 -07:00
Ben Pfaff
2a022368f4 Avoid shadowing local variable names.
All of these changes avoid using the same name for two local variables
within a same function.  None of them are actual bugs as far as I can tell,
but any of them could be confusing to the casual reader.

The one in lib/ovsdb-idl.c is particularly brilliant: inner and outer
loops both using (different) variables named 'i'.

Found with GCC -Wshadow.
2010-09-20 09:39:54 -07:00
Ben Pfaff
e85bbd75f7 bridge: Don't pay attention to columns that vswitchd doesn't need.
Not replicating unneeded columns has some value in avoiding CPU time and
bandwidth to the database.  In ovs-vswitchd, setting cur_cfg as write-only
also have great value in avoiding extra reconfiguration steps.  When
ovs-vsctl is used in its default mode this essentially avoids half of the
reconfigurations that ovs-vswitchd currently does.  What happens now is:

    1. ovs-vsctl updates the database and increments next_cfg.
    2. ovs-vswitchd notices the change to the database, reconfigures
       itself, then increments cur_cfg to match next_cfg.
    3. The database sends the change to cur_cfg back to ovs-vswitchd.
    4. ovs-vswitchd reconfigures itself a second time.

By not replicating cur_cfg we avoid step 3 and save a whole reconfiguration
step.

Also, now that the database contains interface statistics, this avoids
reconfiguring every time that statistics are updated.
2010-08-11 15:41:42 -07:00
Ben Pfaff
c547535a7c ovsdb-idl: Make it possible to omit or pay less attention to columns.
ovs-vswitchd has no need to replicate some parts of the database.  In
particular, it doesn't need to replicate the bits that it never reads,
such as the external_ids column in the Open_vSwitch table.  This saves
some memory, CPU time, and bandwidth to the database.

Another type of column that benefits from special treatment is "write-only
columns", that is, those that ovs-vswitchd writes and keeps up-to-date but
never expects another client to write, such as the cur_cfg column in the
Open_vSwitch table.  If the IDL reports that the database has changed when
ovs-vswitchd updates such a column, then ovs-vswitchd reconfigures itself
for no reason, wasting CPU time.  This commit also adds support for such
columns.
2010-08-11 15:41:41 -07:00
Ben Pfaff
5136ce492c vlog: Introduce VLOG_DEFINE_THIS_MODULE for declaring vlog module in use.
Adding a macro to define the vlog module in use adds a level of
indirection, which makes it easier to change how the vlog module must be
defined.  A followup commit needs to do that, so getting these widespread
changes out of the way first should make that commit easier to review.
2010-07-21 15:47:09 -07:00
Ben Pfaff
8c3c2f3000 ovsdb-idl: Transition to better interfaces for reading table columns.
The existing ovsdb_idl_txn_read() was somewhat difficult and expensive to
use, because it always made a copy of the data in the column.  This was
necessary at the time it was introduced, because there was no way for it
to return a "default" value for columns that had not yet been populated
without allocating data and hence requiring the caller to free it.

Now that ovsdb_datum_default() exists, this is no longer required.  This
commit introduces a pair of new functions, ovsdb_idl_read() and
ovsdb_idl_get(), that return a pointer to existing data and do not do any
copying.  It also transitions all of ovsdb_idl_txn_read()'s callers to
the new interfaces.
2010-07-12 10:13:53 -07:00
Ben Pfaff
efdd908807 Simplify shash_find() followed by shash_add() into shash_add_once().
This is just a cleanup.
2010-06-30 16:48:55 -07:00
Jesse Gross
35c2ce9849 ovsdb-idl: Check if row->written is valid.
Commit cde3f1 "ovsdb-idl: Drop unnecessary allocation from
ovsdb_idl_txn_insert()." does lazy allocation of row->written
on the assumption that ovsdb_idl_txn_write() will handle it.
However, this isn't the case for empty rows created by something
like "ovs-vsctl init" so add a check before reading the bitfield.
2010-06-24 15:48:03 -07:00
Ben Pfaff
cde3f1eebc ovsdb-idl: Drop unnecessary allocation from ovsdb_idl_txn_insert().
There's no need to allocate row->written ahead of time because the code
that can use it allocates it on demand if row->written is NULL.
2010-06-23 12:43:02 -07:00
Ben Pfaff
2ce42c885a ovsdb-idl: Start documenting the public interface.
Long overdue.
2010-06-23 12:43:02 -07:00
Ben Pfaff
4ea21243f5 ovsdb-idl: Simplify usage of ovsdb_idl_run().
It makes client code simpler if ovsdb_idl_run() simply lets the caller
know whether anything changed.
2010-06-23 12:43:02 -07:00
Ben Pfaff
ce5a3e38da ovs-vsctl: Support references among records at creation time.
This makes it easy to create a bunch of records that are all related to
each other in a single ovs-vsctl invocation.  It adds an example to the
ovs-vsctl manpage.
2010-06-17 10:30:18 -07:00