summaryrefslogtreecommitdiff
path: root/ovsdb/log.c
Commit message (Collapse)AuthorAgeFilesLines
* ovsdb-tool: Fix cluster-to-standalone for DB conversion records.Ilya Maximets2023-04-241-0/+17
| | | | | | | | | | | | | | | | | | | If database conversion happens, both schema and the new data are present in the database record. However, the schema is just silently ignored by ovsdb-tool cluster-to-standalone. This creates data inconsistency if the new data contains new columns, for example, so the resulting database file will not be readable, or data will be lost. Fix that by re-setting the database whenever a conversion record is found and actually writing a new schema that will match the actual data. The database file will not be that similar to the original, but there is no way to represent conversion in a standalone database file format otherwise. Fixes: 00de46f9ee42 ("ovsdb-tool: Convert clustered db to standalone db.") Reviewed-by: Simon Horman <simon.horman@corigine.com> Acked-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* sha1: Use implementation from openssl if available.Ilya Maximets2022-05-261-0/+1
| | | | | | | | | | | | | | | | | | | | | | | Implementation of SHA1 in OpenSSL library is much faster and optimized for all available CPU architectures and instruction sets. OVS should use it instead of internal implementation if possible. Depending on compiler options OpenSSL's version finishes our sha1 unit tests from 3 to 12 times faster. Performance of OpenSSL's version is constant, but OVS's implementation highly depends on compiler. Interestingly, default build with '-g -O2' works faster than optimized '-march=native -Ofast'. Tests with ovsdb-server on big databases shows ~5-10% improvement of the time needed for database compaction (sha1 is only a part of this operation), depending on compiler options. We still need internal implementation, because OpenSSL can be not available on some platforms. Tests enhanced to check both versions of API. Reviewed-by: Dumitru Ceara <dceara@redhat.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb: Remove read permission of *.db from others.Yi-Hung Wei2020-11-101-1/+1
| | | | | | | | | | | | Currently, when ovsdb *.db is created by ovsdb-tool it grants read permission to others. This may incur security concerns, for example, IPsec Pre-shared keys are stored in ovs-vsitchd.conf.db. This patch addresses the concerns by removing permission for others. Reported-by: Antonin Bas <abas@vmware.com> Acked-by: Mark Gray <mark.d.gray@redhat.com> Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
* ovsdb: Switch ovsdb log fsync to data only.Anton Ivanov2020-04-271-0/+9
| | | | | | | | | | We do not check metadata - mtime, atime, anywhere, so we do not need to update it every time we sync the log. if the system supports it, the log update should be data only Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com> Signed-off-by: William Tu <u9012063@gmail.com>
* Embrace anonymous unions.Ben Pfaff2018-05-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Several OVS structs contain embedded named unions, like this: struct { ... union { ... } u; }; C11 standardized a feature that many compilers already implemented anyway, where an embedded union may be unnamed, like this: struct { ... union { ... }; }; This is more convenient because it allows the programmer to omit "u." in many places. OVS already used this feature in several places. This commit embraces it in several others. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org> Tested-by: Alin Gabriel Serdean <aserdean@ovn.org> Acked-by: Alin Gabriel Serdean <aserdean@ovn.org>
* ovsdb: Introduce experimental support for clustered databases.Ben Pfaff2018-03-241-0/+8
| | | | | | | | | | | | | | | | | | | This commit adds support for OVSDB clustering via Raft. Please read ovsdb(7) for information on how to set up a clustered database. It is simple and boils down to running "ovsdb-tool create-cluster" on one server and "ovsdb-tool join-cluster" on each of the others and then starting ovsdb-server in the usual way on all of them. One you have a clustered database, you configure ovn-controller and ovn-northd to use it by pointing them to all of the servers, e.g. where previously you might have said "tcp:1.2.3.4" was the database server, now you say that it is "tcp:1.2.3.4,tcp:5.6.7.8,tcp:9.10.11.12". This also adds support for database clustering to ovs-sandbox. Acked-by: Justin Pettit <jpettit@ovn.org> Tested-by: aginwala <aginwala@asu.edu> Signed-off-by: Ben Pfaff <blp@ovn.org>
* log: Add async commit support.Ben Pfaff2018-03-241-4/+148
| | | | | | | | | | | The OVSDB log code has always had the ability to commit the log to disk and wait for the commit to finish. This patch introduces a new feature that allows the client to start a commit in the background and then to determine asynchronously that the commit has completed. This will be especially useful later for the distributed database feature. Signed-off-by: Ben Pfaff <blp@ovn.org> Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
* ovsdb: Loosen requirements for automatically compacting databases.Daniel Alvarez2018-03-091-1/+1
| | | | | | | | | | | | | | | | | | | | | Before this patch, the databases were automatically compacted when a transaction is logged when: * It's been > 10 minutes after last compaction AND * At least 100 commits have occurred AND * Database has grown at least 4x since last compaction (and it's > 10M) This patch changes the conditions as follows: * It's been > 10 minutes after last compaction AND * At least 100 commits have occurred AND either - It's been > 24 hours after the last compaction OR - Database has grown at least 2x since last compaction (and it's > 10M) Reported-by: Daniel Alvarez <dalvarez@redhat.com> Reported-at: https://mail.openvswitch.org/pipermail/ovs-discuss/2018-March/046309.html Signed-off-by: Daniel Alvarez <dalvarez@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* log: Use absolute name of log file.Ben Pfaff2017-12-241-33/+62
| | | | | | | | | | | | | | In ovsdb-server, the OVSDB log code is used to open the databases specified on the command line before ovsdb-server daemonizes itself. Afterward, it is occasionally necessary for ovsdb-server to reference those files by name again. When that happens, if daemonization changed the current directory to the root, any relative names are no longer valid and those references will fail. Until now, this was handled at a higher level in ovsdb-server, but in the future it will be convenient to handle it in the log code itself. This commit prepares for that by making the log code take the absolute name of log files itself. Signed-off-by: Ben Pfaff <blp@ovn.org>
* log: Replace ovsdb_log_get_offset() by a more abstract mechanism.Ben Pfaff2017-12-241-8/+33
| | | | | | | | | Upcoming support for clustered databases will need to provide a more abstract way to determine when a given file should be compacted, so this changes the standalone database support to use this mechanism in advance. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* log: Support multiple magic.Ben Pfaff2017-12-241-44/+111
| | | | | | | | | Some OVSDB tools will want to open files that might be standalone or clustered databases, and so it's better if ovsdb_log_open() can accept more than one valid "magic". This commit makes that possible. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* log: Support using /dev/stdin for opening logs read-only.Ben Pfaff2017-12-241-1/+7
| | | | | | | | | On Unix-like systems, usually /dev/stdin opens a duplicate of fd 0, and this will be convenient in a few places later on. This commit makes this support universal. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* log: New functions for replacing a log's contents.Ben Pfaff2017-12-241-28/+266
| | | | | | | | | | | | | | These functions will acquire users in future commits. This new functionality made the internal state machine of the log hard enough to understand that I thought that it was best to make it explicit with a 'state' variable, so this commit introduces one. This commit duplicates code and logic from ovsdb_rename() and ovsdb_compact() in ovsdb/file.c. A future commit removes this duplication. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* log: Make reading in writing mode less of an error.Ben Pfaff2017-12-241-1/+1
| | | | | | | | | | | | Clients are intended to use the OVSDB log code by reading zero or more records and then writing zero or more records, but not reading after any write has occurred. Until now, ovsdb_log_read() has signaled the latter behavior as an error. Upcoming changes to OVSDB are going to make it an expected behavior in some cases, so this commit changes it so that it just becomes an empty read. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* log: Add new open mode OVSDB_LOG_CREATE_EXCL.Ben Pfaff2017-12-241-5/+18
| | | | | | | | Until now, OVSDB_LOG_CREATE implied EXCL, but this commit breaks them apart. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* log: Log write errors.Ben Pfaff2017-12-241-0/+7
| | | | | | | This saves all the callers from logging them separately. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* log: Make json parameter to ovsdb_log_write() const.Ben Pfaff2017-12-241-1/+3
| | | | | Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* log: Require log entries to be JSON objects.Ben Pfaff2017-12-241-0/+17
| | | | | | | | | | | | The current and upcoming users of the OVSDB logging module only use JSON objects as records. This commit simplifies the users slightly by allowing them to always assume that the records are JSON objects. Unfortunately this resulted in a large number of updates to tests, which didn't always use JSON objects. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* log: Allow client to specify magic.Ben Pfaff2017-12-241-15/+42
| | | | | | | | | | | Until now, the logging code in ovsdb has only supported a single file format, for OVSDB standalone database files. Upcoming commits will add support for another, incompatible format, which uses a different magic string for identification. This commit allows the logging code to support both formats. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* log: New function ovsdb_log_compose_record().Ben Pfaff2017-12-141-23/+36
| | | | | | | This will acquire a new user later on. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Justin Pettit <jpettit@ovn.org>
* json: Move from lib to include/openvswitch.Terry Wilson2016-07-221-1/+1
| | | | | | | | | | | | | | | To easily allow both in- and out-of-tree building of the Python wrapper for the OVS JSON parser (e.g. w/ pip), move json.h to include/openvswitch. This also requires moving lib/{hmap,shash}.h. Both hmap.h and shash.h were #include-ing "util.h" even though the headers themselves did not use anything from there, but rather from include/openvswitch/util.h. Fixing that required including util.h in several C files mostly due to OVS_NOT_REACHED and things like xmalloc. Signed-off-by: Terry Wilson <twilson@redhat.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* ovsdb: Improve error message from ovsdb_log_open() open failure.Ben Pfaff2016-03-301-1/+1
| | | | | | | | | | | Previously, error messages ended up looking like: ovsdb-tool: I/O error: create: $DBFILE failed (File exists) which is hard to understand. This commit changes them to: ovsdb-tool: I/O error: $DBFILE: create failed (File exists) which makes more sense. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* ovsdb: Remove unused "struct ovsdb_log_read_cbdata".Ben Pfaff2016-03-281-7/+0
| | | | | Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* ovsdb: Open database in binary mode.Gurucharan Shetty2014-05-141-0/+3
| | | | | | | | | Some ovsdb-tool related unit tests fail with bad checksum errors while reading transactions from database. It is most likely because of the CR at the end of line. Using binary mode solves the problem. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* ovsdb: Do not look for symbolic links for db creation in Windows.Gurucharan Shetty2014-03-131-0/+4
| | | | | | | | We start with not supporting symbolic links for database creation in Windows. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* Rename NOT_REACHED to OVS_NOT_REACHEDHarold Lim2013-12-171-1/+1
| | | | | | | | 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>
* Avoid printf type modifiers not supported by MSVC C runtime library.Alin Serdean2013-11-251-1/+1
| | | | | | | | | | | | | 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>
* Remove unused variables and functions.Jarno Rajahalme2013-09-271-3/+0
| | | | | | | | Found by Clang. Signed-off-by: Jarno Rajahalme <jrajahalme@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* ovsdb: Allow recovery from transient write errors in log implementation.Ben Pfaff2013-03-121-8/+6
| | | | | | | | | | | | | Until now, the OVSDB data journaling implementation has made write errors "sticky", so that a single write error persists as long as ovsdb-server is alive. However, some kinds of write errors (such as ENOSPC) can be transient in practice. I don't know of a good reason to make such errors sticky, so this commit makes the journaling code retry writes even after an error occurs, allowing ovsdb-server to recover from transient errors. Reported-by: likunyun <kunyunli@hotmail.com> Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* Replace most uses of assert by ovs_assert.Ben Pfaff2013-01-161-3/+2
| | | | | | | | 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>
* lockfile: Remove lockfile_lock timeout argumentLeo Alterman2012-08-091-1/+1
| | | | | | | | | lockfile_lock() accepts a timeout argument but, aside from unit tests pertaining to timeout, its value is always 0. Since this feature relies on a periodic SIGALRM signal, which is not a given if we're not caching time, the cleanest solution is just to remove it. Signed-off-by: Leo Alterman <lalterman@nicira.com>
* ovsdb: Make "ovsdb-tool create" work through a dangling symlink.Ben Pfaff2012-08-011-2/+11
| | | | | | | | | | | | | | | open() with O_CREAT|O_EXCL yields EEXIST if the name passed in is a symlink, but we would like "ovsdb-tool create /etc/openvswitch/conf.db" to work if /etc/openvswitch/conf.db is a symlink to elsewhere in the file system. This commit fixes the problem. It introduces a theoretical race, but no one should be doing "ovsdb-tool create" in parallel anyhow; O_EXCL is just an idiot check here, not required to be fail-safe. Debian bug #681880. CC: 681880@bugs.debian.org Reported-by: Bastian Blank <waldi@debian.org> Signed-off-by: Ben Pfaff <blp@nicira.com> Reviewed-by: Simon Horman <horms@verge.net.au>
* Global replace of Nicira Networks.Raju Subramanian2012-05-021-1/+1
| | | | | | | | 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>
* Consistently write null pointer constants as NULL instead of 0.Ben Pfaff2011-05-161-3/+3
| | | | Found with sparse.
* ovsdb: Truncate bad transactions from database log.Ben Pfaff2011-03-311-1/+20
| | | | | | | | | | | | | | | | | When ovsdb-server reads a database file that is corrupted at the transaction level (that is, the transaction is valid JSON and has the correct SHA-1 hash, but it does not describe a valid database transaction), then ovsdb-server should truncate it and overwrite it by valid transactions. However, until now, it didn't. Instead, it would keep the invalid transaction and possibly every transaction in the database file (depending on in what way the transaction was invalid), which would just cause the same trouble again the next time the database was read. This fixes the problem. An invalid transaction will be deleted from the database file at the first write to the database. Bug #5144. Bug #5149.
* vlog: Make client supply semicolon for VLOG_DEFINE_THIS_MODULE.Ben Pfaff2010-10-291-1/+1
| | | | | It's kind of odd for VLOG_DEFINE_THIS_MODULE to supply its own semicolon, so this commit switches to the more common form.
* vlog: Introduce VLOG_DEFINE_THIS_MODULE for declaring vlog module in use.Ben Pfaff2010-07-211-2/+2
| | | | | | | 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.
* Add some missing "#include"s.Ben Pfaff2010-05-261-0/+1
| | | | These are required to build on FreeBSD 8.0.
* ovsdb: Compact databases online automatically and on-demand.Ben Pfaff2010-03-181-0/+8
| | | | | | | | | | | | If the database grows fairly large, and we've written a fair number of transactions to it, and it's been a while since the database was compacted, then (after the next commit) compact the database. Also, compact the database online if the "ovsdb-server/compact" command is issued via unixctl. I suspect that this feature will rarely if ever be used in practice, but it's easier to test than compacting automatically. Bug #2391.
* ovsdb: Factor out code to fsync a file's containing directory.Ben Pfaff2010-02-151-11/+2
| | | | | In an upcoming commit, another function wants to do the same thing, so break it out into a helper function.
* ovsdb: Allow ovsdb_log_open()'s caller to choose whether to lock.Ben Pfaff2010-02-151-8/+27
| | | | | | | | | | | | The current callers of ovsdb_log_open() always want to lock the file if they are accessing it for read/write access. An upcoming commit will add a new caller that does not fit this model (it wants to lock the file across a wider region) and so the caller should be able to choose whether to do locking. This commit adds that ability. Also, get rid of the use of <fcntl.h> flags to choose the open mode, which has always seemed somewhat crude and which this change would make even cruder.
* ovsdb: Remove write-only variable from parse_body() in log.c.Ben Pfaff2010-02-111-3/+1
| | | | Found by Clang (http://clang-analyzer.llvm.org/).
* Clean-up compiler warnings about ignoring return valuesJustin Pettit2009-12-151-1/+1
| | | | | | | Some systems complain when certain functions' return values are not checked. This commit fixes those warnings. Creating ignore() function suggested by Ben Pfaff.
* ovsdb: Rename ovsdb_file to ovsdb_log.Ben Pfaff2009-11-161-0/+363
This prepares for introducing a new, higher-level ovsdb_file that encapsulates ovsdb storage in a file.