summaryrefslogtreecommitdiff
path: root/lib/vlog.c
Commit message (Collapse)AuthorAgeFilesLines
* util: New function nullable_xstrdup().Ben Pfaff2016-06-261-1/+1
| | | | | | It's a pretty common pattern so create a function for it. Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/ofpbuf.h to include/openvswitch directoryBen Warren2016-03-301-1/+1
| | | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Acked-by: Ryan Moats <rmoats@us.ibm.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* list: Rename all functions in list.h with ovs_ prefix.Ben Warren2016-03-301-1/+1
| | | | | | | This attempts to prevent namespace collisions with other list libraries Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* Move lib/dynamic-string.h to include/openvswitch directoryBen Warren2016-03-191-1/+1
| | | | | Signed-off-by: Ben Warren <ben@skyportsystems.com> Signed-off-by: Ben Pfaff <blp@ovn.org>
* vlog: Use log_file_mutex to more consistently protect vlog_modules.Ben Pfaff2016-02-101-4/+15
| | | | | | | | | | This could be beneficial if we ever insert a new module at runtime (currently we only insert them at startup) and it should have negligible cost. Suggested-by: Russell Bryant <russell@ovn.org> Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* vlog: Add vlog/close command.Ben Pfaff2016-02-101-0/+24
| | | | | | | Requested-by: P R Dinesh Requested-at: https://github.com/openvswitch/ovs/pull/94 Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* vlog: Make the most common module reference more direct.Ben Pfaff2016-02-101-1/+2
| | | | | | | | | | | | | Most vlog calls are for the log module owned by the translation unit being compiled, but this module was referenced indirectly through a pointer variable. That seems silly, so this commit changes the code so that the local vlog module is referred to directly, as &this_module. We could get rid of the global variables for vlog modules entirely, but I like getting linker errors when there's a duplicate module name. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* vlog: Make 'vlog_modules' private to vlog.c.Ben Pfaff2016-02-031-2/+2
| | | | | | | | | I think we once used this variable from an inline function in vlog.h, so that we had to make it "extern", but these days it's only used from vlog.c, so it can be static now. Signed-off-by: Ben Pfaff <blp@ovn.org> Acked-by: Russell Bryant <russell@ovn.org>
* vlog: Fix a deadlock bug.Andy Zhou2015-11-191-5/+14
| | | | | | | | | | | | | | Calling VLOG_FATAL() while holding the 'log_file_mutex" may lead to deadlock since VLOG_FATAL() implementation tries to acquire the same lock. Fix this by building the error message first, then call VLOG_FATAL() after the 'log_file_mutex' has been released. This bug is not likely show up in practice since chown() usually won't fail. It is still better to have a correct implementation. Reported-by: Daniele Di Proietto <ddiproietto@vmware.com> Signed-off-by: Andy Zhou <azhou@ovn.org> Acked-by: Daniele Di Proietto <ddiproietto@vmware.com>
* vlog: fix clang warningsAndy Zhou2015-11-121-7/+4
| | | | | | | Make sure clang does not complain about accessing ovs_log_file outside of log_file_mutex protection. Signed-off-by: Andy Zhou <azhou@nicira.com>
* vlog: Only compile vlog_change_owner on Unix platformAndy Zhou2015-11-111-1/+3
| | | | | | uid_t and gid_t are not defined for Windows platform. Signed-off-by: Andy Zhou <azhou@nicira.com>
* vlog: change log file owner when switching userAndy Zhou2015-11-111-1/+22
| | | | | | | | | | | vlog log file can be created when parsing --log-file option, before switching user, in case the --user option is also specified. While this does not directly cause errors for the running daemons, it can leave the log files on the disk as created under the "root" user. This patch fix the log file ownership to the user specified with --user. Signed-off-by: Andy Zhou <azhou@nicira.com> Acked-by: Ansis Atteka <aatteka@nicira.com>
* vlog: deprecate --syslog-target argumentAnsis Atteka2015-09-291-0/+10
| | | | | | | | | | | | Commit fe089c0d1e18 ("vlog: abstract out interface to syslog daemon") introduced --syslog-method flag that supersedes --syslog-target flag by: 1. making logging format configurable 2. letting daemon to also talk over UNIX domain socket (this is handy when local rsyslog daemon is running in different network namespace on the same host) Signed-off-by: Ansis Atteka <aatteka@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* treewide: Change doubled ";;" to single ";" in C code.Ben Pfaff2015-07-221-2/+2
| | | | | | | Except in "for (;;)". Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Russell Bryant <rbryant@redhat.com>
* vlog: add "vlog/list-pattern" commandAnsis Atteka2015-06-271-0/+39
| | | | | | | | This patch allows to query logging format at the runtime for each destination with "vlog/list-pattern" command. Signed-off-by: Ansis Atteka <aatteka@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* vlog: abstract out interface to syslog daemonAnsis Atteka2015-06-271-11/+29
| | | | | | | | | | | | | | | | | | | | | | | | This patch helps to address two issues that are present on Ubuntu 15.04 (and most likely other Linux distributions) where rsyslog daemon is configured to relay log messages from OVS to a remote log collector and syslog format being used is something other than the one defined in RFC 3164. These two issues are: 1. libc syslog() function always adds RFC 3164 prefix to syslog messages before sending them over /dev/log Unix domain socket. This does not allow us to use libc syslog() function to log in RFC 5424 format; and 2. rsyslogd daemon that comes with Ubuntu 15.04 is too old and uses hardcoded syslog message parser when it received messages over /dev/log UNIX domain socket. Solution to those two issues would be to use the newly introduced --syslog-method=udp:127.0.0.1:514 command line argument when starting OVS. Signed-off-by: Ansis Atteka <aatteka@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* vlog: Ability to override the default log facility.Gurucharan Shetty2015-01-281-3/+72
| | | | | | | | | | | | | | | When Open vSwitch is run in hundreds of hypervisors, it is useful to collect log messages through log collectors. To collect log messages like this, it is useful to log them in a particular RFC5424 facility in the local system. The log collectors can then be used to collect logs anytime desired. This commit provides a sysadmin the ability to specify the facility through which the log messages are logged. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* vlog: Rename the currently used term 'facility' as 'destination'.Gurucharan Shetty2015-01-081-75/+83
| | | | | | | | | | | | In OVS, we currently use the term 'facility' to mean the place where we log (syslog, console or file). In Linux's syslog() and rfc5424, the term 'facility' is used to specify what type of program is logging the message (e.g: LOG_DAEMON). This causes confusion while reading vlog's code. This commit changes the term 'facility' to 'destination'. Signed-off-by: Gurucharan Shetty <gshetty@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
* lib: Move vlog.h to <openvswitch/vlog.h>Thomas Graf2014-12-151-1/+6
| | | | | | | | A new function vlog_insert_module() is introduced to avoid using list_insert() from the vlog.h header. Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Acked-by: Ben Pfaff <blp@nicira.com>
* lib: Expose struct ovs_list definition in <openvswitch/list.h>Thomas Graf2014-12-151-1/+1
| | | | | | | | Expose the struct ovs_list definition in <openvswitch/list.h>. Keep the list access API private for now. Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Acked-by: Ben Pfaff <blp@nicira.com>
* list: Rename struct list to struct ovs_listThomas Graf2014-12-151-1/+1
| | | | | | | 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>
* lib: Move compiler.h to <openvswitch/compiler.h>Thomas Graf2014-12-151-1/+1
| | | | | | | | | | The following macros are renamed to avoid conflicts with other headers: * WARN_UNUSED_RESULT to OVS_WARN_UNUSED_RESULT * PRINTF_FORMAT to OVS_PRINTF_FORMAT * NO_RETURN to OVS_NO_RETURN Signed-off-by: Thomas Graf <tgraf@noironetworks.com> Acked-by: Ben Pfaff <blp@nicira.com>
* vlog: Avoid deadlock in vlog_init__() corner case.Ben Pfaff2014-01-211-35/+41
| | | | | | | | | | | | | | | Anything inside vlog_init__() that tried to log a message was going to deadlock, since it would hit pthread_once() recursively and wait for the previous call to complete. Unfortunately, there was a VLOG_ERR call inside vlog_init__(), only called in the corner case where the system's clock was wrong. This fixes the problem by rearranging code so that the logging isn't inside the "once-only" region. Found by inspection. Signed-off-by: Ben Pfaff <blp@nicira.com>
* vlog: Use OVS_CONSTRUCTOR for vlog initializationHelmut Schaa2013-12-131-40/+23
| | | | | | | | | | | | | This allows to get rid of some special segment handling to allow distributed registering of vlog modules. Instead use a global list and vlog module constructor functions to build up the list. That means vlog modules reside within the compilation unit they are defined in and can be iterated upon by using the global list vlog_modules. Signed-off-by: Helmut Schaa <helmut.schaa@googlemail.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* vlog: Add option to send vlog syslog output to arbitrary UDP destination.Henry Mai2013-12-061-15/+82
| | | | | | Signed-off-by: Henry Mai <henrymai@nicira.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-2/+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>
* vlog: Report timestamps in millisecond resolution in log messages.Paul Ingram2013-09-131-8/+8
| | | | | | | To make debugging easier. Signed-off-by: Ben Pfaff <blp@nicira.com> Signed-off-by: Paul Ingram <pingram@nicira.com>
* sparse: Suppress sparse warnings for global variables.Alex Wang2013-08-201-0/+1
| | | | | | | | | | sparse warns if a non-static variable with external linkage has an initializer at first declaration. This commit suppresses the warnings issued when adding custom section is not supported by compiler. Signed-off-by: Alex Wang <alexw@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* Use "error-checking" mutexes in place of other kinds wherever possible.Ben Pfaff2013-08-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | We've seen a number of deadlocks in the tree since thread safety was introduced. So far, all of these are self-deadlocks, that is, a single thread acquiring a lock and then attempting to re-acquire the same lock recursively. When this has happened, the process simply hung, and it was somewhat difficult to find the cause. POSIX "error-checking" mutexes check for this specific problem (and others). This commit switches from other types of mutexes to error-checking mutexes everywhere that we can, that is, everywhere that we're not using recursive mutexes. This ought to help find problems more quickly in the future. There might be performance advantages to other kinds of mutexes in some cases. However, the existing mutex type choices were just guesses, so I'd rather go for easy detection of errors until we know that other mutex types actually perform better in specific cases. Also, I did a quick microbenchmark of glibc mutex types on my host and found that the error checking mutexes weren't any slower than the other types, at least when the mutex is uncontended. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* ovs-thread: Add support for globally visible per-thread data.Ben Pfaff2013-08-081-1/+1
| | | | | | | | | DEFINE_PER_THREAD_DATA always declared its data item as "static", meaning that it was only directly visible within a single translation unit. This commit adds additional forms of per-thread data that allow the data to be accessible from multiple translation units. Signed-off-by: Ben Pfaff <blp@nicira.com>
* async-append: Refactor to avoid requiring enabling while single threaded.Ben Pfaff2013-08-021-4/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Until now, the async append interface has required async_append_enable() to be called while the process was still single-threaded, with the rationale being that async_append_enable() could race with async_append_write() on some existing async_append object. This was a difficult problem when the async append interface was introduced, because at the time Open vSwitch did not have any infrastructure for inter-thread synchronization. Now it is easy to solve, by introducing synchronization into the async append module. However, that's more or less wasted, because the client is already required to serialize access to async append objects. Moreover, vlog, the only existing client, needs to serialize access for other reasons, so it wouldn't even be possible to just drop the client's synchronization. This commit therefore takes another approach. It drops the async_append_enable() interface entirely. Now any existing async_append object is always enabled. The responsibility for "enabling", then, now rests in whether the client creates and uses an async_append object, and so vlog now takes care of that by itself. Also, since vlog now has to deal with sometimes having an async_append and sometimes not having one, we might as well allow creating an async_append to fail, thereby slightly simplifying the "no async I/O" implementation from "write synchronously" to "always fail creating an async_append". Reported-by: Shih-Hao Li <shihli@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* clang: Add annotations for thread safety check.Ethan Jackson2013-07-301-34/+48
| | | | | | | | | | This commit adds annotations for thread safety check. And the check can be conducted by using -Wthread-safety flag in clang. Co-authored-by: Alex Wang <alexw@nicira.com> Signed-off-by: Alex Wang <alexw@nicira.com> Signed-off-by: Ethan Jackson <ethan@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* vlog: Make thread-safe.Ben Pfaff2013-07-181-74/+106
| | | | Signed-off-by: Ben Pfaff <blp@nicira.com>
* vlog: Use async I/O.Ben Pfaff2013-07-181-1/+11
| | | | Signed-off-by: Ben Pfaff <blp@nicira.com>
* vlog: Remove unused function vlog_exit().Ben Pfaff2013-07-121-10/+0
| | | | | | | This is harder to implement once threads are introduced. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ed Maste <emaste@freebsd.org>
* vlog: Remove unused function vlog_get_log_file().Ben Pfaff2013-07-121-10/+0
| | | | | Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ed Maste <emaste@freebsd.org>
* vlog: Make vlog_should_drop() thread-safe.Ben Pfaff2013-07-121-4/+10
| | | | | Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ed Maste <emaste@freebsd.org>
* util: Make subprogram_name thread-specific.Ben Pfaff2013-07-121-0/+3
| | | | Signed-off-by: Ben Pfaff <blp@nicira.com>
* vlog: Remove support for worker process.Ben Pfaff2013-07-111-63/+1
| | | | | | | | | The worker process implementation isn't thread-safe and, once OVS itself is threaded, it doesn't make much sense to have a worker process anyway. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ed Maste <emaste@freebsd.org>
* Replace all uses of strerror() by ovs_strerror(), for thread safety.Ben Pfaff2013-06-281-2/+2
| | | | Signed-off-by: Ben Pfaff <blp@nicira.com>
* Always check return value of strftime().Ben Pfaff2013-05-081-7/+4
| | | | | | | | | | | | strftime() returns 0 and leaves the contents of the output buffer unspecified if the output buffer is not big enough. Thus, one should check strftime()'s return value. Until now, OVS has had a few invocations of strftime() that did not check the return value. This commit fixes those. I believe that the buffers were always large enough in each case, but it's better to be safe. Reported-by: Andy Zhou <azhou@nicira.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
* vlog: Mark more static data const.Ben Pfaff2013-05-031-3/+3
| | | | | | | These data structures are never modified so this seems like a logical change. Signed-off-by: Ben Pfaff <blp@nicira.com>
* vlog: New function vlog_set_levels_from_string_assert().Ben Pfaff2013-02-011-0/+10
| | | | | | | | | | | Two of the users of vlog_set_levels_from_string() in the tests could have silently failed, if their arguments were invalid. This avoids that problem (and a memory leak). Found by Coverity. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* Makefile.am: add check that <assert.h> is not used from unexpected files.Ben Pfaff2013-01-161-13/+99
| | | | | | | | | In general, with a few specific exceptions, ovs_assert is now preferred over assert, so this commit adds a check for that in the top-level Makefile. 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-94/+13
| | | | | | | | 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>
* vlog: Avoid calling worker_request() reentrantly.Ben Pfaff2013-01-101-7/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | The following call stack was possible: vlog -> worker_request() -> poll_block() -> vlog -> worker_request() which caused problems because worker_request() is not reentrant. In a little more detail, the second worker_request() shoves its RPC protocol data into the middle of the first. This means that, first, you get some binary crud in the log (the header for the second RPC). And, second, text from the first RPC log message gets treated by the worker as the subsequent RPC's header. That, in turn, typically causes the worker to try to xmalloc() a huge number of bytes (0x20000000 or more, since "space" has ASCII value 0x20), which causes the worker to die with "virtual memory exhausted". The main process then dies because the worker's death closes the socket it uses to communicate with it ("connection reset"). Bug #14616. Signed-off-by: Ben Pfaff <blp@nicira.com> Acked-by: Ethan Jackson <ethan@nicira.com>
* vlog: New vlog/enable-rate-limit and vlog/disable-rate-limit commands.Ben Pfaff2012-12-081-6/+71
| | | | | | | | A few times while troubleshooting it would have been useful to get complete logs, rather than post-rate-limiting snapshots of them. These ovs-appctl commands make that possible. Signed-off-by: Ben Pfaff <blp@nicira.com>
* vlog: Ignore return value of some write() calls.Justin Pettit2012-08-071-2/+2
| | | | | | | | A couple of calls to write() would generate warnings when the "-Wunused-result" compiler option is enabled. This change ignores the return value, since we can't do anything about it in logging code. Signed-off-by: Justin Pettit <jpettit@nicira.com>
* util: New macro CONST_CAST.Ben Pfaff2012-08-031-1/+1
| | | | | | | | | | | | | | 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>
* vlog: Use worker process to write to log file.Ben Pfaff2012-07-181-1/+51
| | | | | | | | | | | | Writes to regular files under Unix-like kernels, including Linux, typically block until the write is complete, regardless of O_NONBLOCK. When the I/O subsystem is busy, this can cause indefinite delays. We have actually observed "write" calls sleep for 5 seconds or more for this reason. Delegating to a subprocess through the worker mechanism should solve the problem. Signed-off-by: Ben Pfaff <blp@nicira.com>