summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Pfaff <blp@ovn.org>2016-02-03 13:21:10 -0800
committerBen Pfaff <blp@ovn.org>2016-02-10 13:35:56 -0800
commit922fed065e65ad8388528976d631445f9e768f55 (patch)
tree4ce22727b222aed78846fae48a2ae046a7b8d2fb
parent3ca6cc76c3f3d171fcc7361a7ad4edd452834b7c (diff)
downloadopenvswitch-922fed065e65ad8388528976d631445f9e768f55.tar.gz
vlog: Make the most common module reference more direct.
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>
-rw-r--r--include/openvswitch/vlog.h73
-rw-r--r--lib/bfd.c4
-rw-r--r--lib/db-ctl-base.c2
-rw-r--r--lib/dpif.c8
-rw-r--r--lib/jsonrpc.c4
-rw-r--r--lib/ofp-prop.h2
-rw-r--r--lib/stream-ssl.c4
-rw-r--r--lib/vconn-stream.c4
-rw-r--r--lib/vlog.c3
-rw-r--r--ovn/utilities/ovn-nbctl.c2
-rw-r--r--ovn/utilities/ovn-sbctl.c4
-rw-r--r--tests/test-reconnect.c2
-rw-r--r--utilities/ovs-vsctl.c2
-rw-r--r--vtep/vtep-ctl.c4
14 files changed, 59 insertions, 59 deletions
diff --git a/include/openvswitch/vlog.h b/include/openvswitch/vlog.h
index 899ad4664..feade728c 100644
--- a/include/openvswitch/vlog.h
+++ b/include/openvswitch/vlog.h
@@ -170,46 +170,45 @@ void vlog_rate_limit(const struct vlog_module *, enum vlog_level,
struct vlog_rate_limit *, const char *, ...)
OVS_PRINTF_FORMAT (4, 5);
-/* Creates and initializes a global instance of a module named MODULE, and
- * defines a static variable named THIS_MODULE that points to it, for use with
- * the convenience macros below. */
+/* Defines a logging module whose name is MODULE, which should generally be
+ * roughly the name of the source file, and makes it the module used by the
+ * logging convenience macros defined below. */
#define VLOG_DEFINE_THIS_MODULE(MODULE) \
- /* This extra "extern" declaration makes sparse happy. */ \
- extern struct vlog_module VLM_##MODULE; \
- struct vlog_module VLM_##MODULE = \
- { \
- OVS_LIST_INITIALIZER(&VLM_##MODULE.list), \
+ static struct vlog_module this_module = { \
+ OVS_LIST_INITIALIZER(&this_module.list), \
#MODULE, /* name */ \
{ VLL_INFO, VLL_INFO, VLL_INFO }, /* levels */ \
VLL_INFO, /* min_level */ \
true /* honor_rate_limits */ \
}; \
- OVS_CONSTRUCTOR(init_##MODULE) { \
- vlog_insert_module(&VLM_##MODULE.list); \
+ OVS_CONSTRUCTOR(init_this_module) { \
+ vlog_insert_module(&this_module.list); \
} \
- static struct vlog_module *const THIS_MODULE = &VLM_##MODULE
-
-/* Convenience macros. These assume that THIS_MODULE points to a "struct
- * vlog_module" for the current module, as set up by e.g. the
- * VLOG_DEFINE_THIS_MODULE macro above.
+ \
+ /* Prevent duplicate module names, via linker error. \
+ * The extra "extern" declaration makes sparse happy. */ \
+ extern struct vlog_module *VLM_##MODULE; \
+ struct vlog_module *VLM_##MODULE = &this_module;
+
+/* Macros for the current module as set up by VLOG_DEFINE_THIS_MODULE.
+ * These are usually what you want to use.
*
* Guaranteed to preserve errno.
*/
-#define VLOG_FATAL(...) vlog_fatal(THIS_MODULE, __VA_ARGS__)
-#define VLOG_ABORT(...) vlog_abort(THIS_MODULE, __VA_ARGS__)
+#define VLOG_FATAL(...) vlog_fatal(&this_module, __VA_ARGS__)
+#define VLOG_ABORT(...) vlog_abort(&this_module, __VA_ARGS__)
#define VLOG_EMER(...) VLOG(VLL_EMER, __VA_ARGS__)
#define VLOG_ERR(...) VLOG(VLL_ERR, __VA_ARGS__)
#define VLOG_WARN(...) VLOG(VLL_WARN, __VA_ARGS__)
#define VLOG_INFO(...) VLOG(VLL_INFO, __VA_ARGS__)
#define VLOG_DBG(...) VLOG(VLL_DBG, __VA_ARGS__)
-/* More convenience macros, for testing whether a given level is enabled in
- * THIS_MODULE. When constructing a log message is expensive, this enables it
- * to be skipped. */
-#define VLOG_IS_ERR_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_ERR)
-#define VLOG_IS_WARN_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_WARN)
-#define VLOG_IS_INFO_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_INFO)
-#define VLOG_IS_DBG_ENABLED() vlog_is_enabled(THIS_MODULE, VLL_DBG)
+/* More convenience macros, for testing whether a given level is enabled. When
+ * constructing a log message is expensive, this enables it to be skipped. */
+#define VLOG_IS_ERR_ENABLED() vlog_is_enabled(&this_module, VLL_ERR)
+#define VLOG_IS_WARN_ENABLED() vlog_is_enabled(&this_module, VLL_WARN)
+#define VLOG_IS_INFO_ENABLED() vlog_is_enabled(&this_module, VLL_INFO)
+#define VLOG_IS_DBG_ENABLED() vlog_is_enabled(&this_module, VLL_DBG)
/* Convenience macros for rate-limiting.
* Guaranteed to preserve errno.
@@ -224,10 +223,10 @@ void vlog_rate_limit(const struct vlog_module *, enum vlog_level,
#define VLOG_ERR_BUF(ERRP, ...) VLOG_ERRP(ERRP, VLL_ERR, __VA_ARGS__)
#define VLOG_WARN_BUF(ERRP, ...) VLOG_ERRP(ERRP, VLL_WARN, __VA_ARGS__)
-#define VLOG_DROP_ERR(RL) vlog_should_drop(THIS_MODULE, VLL_ERR, RL)
-#define VLOG_DROP_WARN(RL) vlog_should_drop(THIS_MODULE, VLL_WARN, RL)
-#define VLOG_DROP_INFO(RL) vlog_should_drop(THIS_MODULE, VLL_INFO, RL)
-#define VLOG_DROP_DBG(RL) vlog_should_drop(THIS_MODULE, VLL_DBG, RL)
+#define VLOG_DROP_ERR(RL) vlog_should_drop(&this_module, VLL_ERR, RL)
+#define VLOG_DROP_WARN(RL) vlog_should_drop(&this_module, VLL_WARN, RL)
+#define VLOG_DROP_INFO(RL) vlog_should_drop(&this_module, VLL_INFO, RL)
+#define VLOG_DROP_DBG(RL) vlog_should_drop(&this_module, VLL_DBG, RL)
/* Macros for logging at most once per execution. */
#define VLOG_ERR_ONCE(...) VLOG_ONCE(VLL_ERR, __VA_ARGS__)
@@ -267,22 +266,22 @@ void vlog_usage(void);
#define VLOG(LEVEL, ...) \
do { \
enum vlog_level level__ = LEVEL; \
- if (THIS_MODULE->min_level >= level__) { \
- vlog(THIS_MODULE, level__, __VA_ARGS__); \
+ if (this_module.min_level >= level__) { \
+ vlog(&this_module, level__, __VA_ARGS__); \
} \
} while (0)
-#define VLOG_RL(RL, LEVEL, ...) \
- do { \
- enum vlog_level level__ = LEVEL; \
- if (THIS_MODULE->min_level >= level__) { \
- vlog_rate_limit(THIS_MODULE, level__, RL, __VA_ARGS__); \
- } \
+#define VLOG_RL(RL, LEVEL, ...) \
+ do { \
+ enum vlog_level level__ = LEVEL; \
+ if (this_module.min_level >= level__) { \
+ vlog_rate_limit(&this_module, level__, RL, __VA_ARGS__); \
+ } \
} while (0)
#define VLOG_ONCE(LEVEL, ...) \
do { \
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER; \
if (ovsthread_once_start(&once)) { \
- vlog(THIS_MODULE, LEVEL, __VA_ARGS__); \
+ vlog(&this_module, LEVEL, __VA_ARGS__); \
ovsthread_once_done(&once); \
} \
} while (0)
diff --git a/lib/bfd.c b/lib/bfd.c
index 66c99fb8c..8b5daffad 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013, 2014, 2015 Nicira, Inc.
+/* Copyright (c) 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1073,7 +1073,7 @@ log_msg(enum vlog_level level, const struct msg *p, const char *message,
{
struct ds ds = DS_EMPTY_INITIALIZER;
- if (vlog_should_drop(THIS_MODULE, level, &rl)) {
+ if (vlog_should_drop(&this_module, level, &rl)) {
return;
}
diff --git a/lib/db-ctl-base.c b/lib/db-ctl-base.c
index cf49ac071..e3a1de95a 100644
--- a/lib/db-ctl-base.c
+++ b/lib/db-ctl-base.c
@@ -1992,7 +1992,7 @@ ctl_fatal(const char *format, ...)
message = xvasprintf(format, args);
va_end(args);
- vlog_set_levels(&VLM_db_ctl_base, VLF_CONSOLE, VLL_OFF);
+ vlog_set_levels(&this_module, VLF_CONSOLE, VLL_OFF);
VLOG_ERR("%s", message);
ovs_error(0, "%s", message);
ctl_exit(EXIT_FAILURE);
diff --git a/lib/dpif.c b/lib/dpif.c
index 81cbe1181..a86649951 100644
--- a/lib/dpif.c
+++ b/lib/dpif.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -1583,7 +1583,7 @@ flow_message_log_level(int error)
static bool
should_log_flow_message(int error)
{
- return !vlog_should_drop(THIS_MODULE, flow_message_log_level(error),
+ return !vlog_should_drop(&this_module, flow_message_log_level(error),
error ? &error_rl : &dpmsg_rl);
}
@@ -1616,7 +1616,7 @@ log_flow_message(const struct dpif *dpif, int error, const char *operation,
ds_put_cstr(&ds, ", actions:");
format_odp_actions(&ds, actions, actions_len);
}
- vlog(THIS_MODULE, flow_message_log_level(error), "%s", ds_cstr(&ds));
+ vlog(&this_module, flow_message_log_level(error), "%s", ds_cstr(&ds));
ds_destroy(&ds);
}
@@ -1696,7 +1696,7 @@ log_execute_message(struct dpif *dpif, const struct dpif_execute *execute,
}
ds_put_format(&ds, " on packet %s", packet);
ds_put_format(&ds, " mtu %d", execute->mtu);
- vlog(THIS_MODULE, error ? VLL_WARN : VLL_DBG, "%s", ds_cstr(&ds));
+ vlog(&this_module, error ? VLL_WARN : VLL_DBG, "%s", ds_cstr(&ds));
ds_destroy(&ds);
free(packet);
}
diff --git a/lib/jsonrpc.c b/lib/jsonrpc.c
index e6ee195c7..35428a67e 100644
--- a/lib/jsonrpc.c
+++ b/lib/jsonrpc.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -343,7 +343,7 @@ jsonrpc_recv(struct jsonrpc *rpc, struct jsonrpc_msg **msgp)
const struct byteq *q = &rpc->input;
if (q->head <= q->size) {
stream_report_content(q->buffer, q->head, STREAM_JSONRPC,
- THIS_MODULE, rpc->name);
+ &this_module, rpc->name);
}
return rpc->status;
}
diff --git a/lib/ofp-prop.h b/lib/ofp-prop.h
index 2f07d072a..921b6c13b 100644
--- a/lib/ofp-prop.h
+++ b/lib/ofp-prop.h
@@ -129,6 +129,6 @@ void ofpprop_end(struct ofpbuf *, size_t start_ofs);
enum ofperr ofpprop_unknown(struct vlog_module *, bool loose, const char *msg,
uint64_t type);
#define OFPPROP_UNKNOWN(LOOSE, MSG, TYPE) \
- ofpprop_unknown(THIS_MODULE, LOOSE, MSG, TYPE)
+ ofpprop_unknown(&this_module, LOOSE, MSG, TYPE)
#endif /* ofp-prop.h */
diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c
index 0015fc3cb..26996338a 100644
--- a/lib/stream-ssl.c
+++ b/lib/stream-ssl.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -455,7 +455,7 @@ ssl_connect(struct stream *stream)
: "SSL_accept"), retval, error, &unused);
shutdown(sslv->fd, SHUT_RDWR);
stream_report_content(sslv->head, sslv->n_head, STREAM_SSL,
- THIS_MODULE, stream_get_name(stream));
+ &this_module, stream_get_name(stream));
return EPROTO;
}
} else if (bootstrap_ca_cert) {
diff --git a/lib/vconn-stream.c b/lib/vconn-stream.c
index 23c0aaecd..2858462be 100644
--- a/lib/vconn-stream.c
+++ b/lib/vconn-stream.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,7 +104,7 @@ vconn_stream_close(struct vconn *vconn)
if ((vconn->error == EPROTO || s->n_packets < 1) && s->rxbuf) {
stream_report_content(s->rxbuf->data, s->rxbuf->size, STREAM_OPENFLOW,
- THIS_MODULE, vconn_get_name(vconn));
+ &this_module, vconn_get_name(vconn));
}
stream_close(s->stream);
diff --git a/lib/vlog.c b/lib/vlog.c
index 3d0b87c48..f514d65b5 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -209,7 +209,8 @@ vlog_get_destination_val(const char *name)
return i;
}
-void vlog_insert_module(struct ovs_list *vlog)
+void
+vlog_insert_module(struct ovs_list *vlog)
{
list_insert(&vlog_modules, vlog);
}
diff --git a/ovn/utilities/ovn-nbctl.c b/ovn/utilities/ovn-nbctl.c
index 324a0a40e..c0b698186 100644
--- a/ovn/utilities/ovn-nbctl.c
+++ b/ovn/utilities/ovn-nbctl.c
@@ -218,7 +218,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
break;
case OPT_NO_SYSLOG:
- vlog_set_levels(&VLM_nbctl, VLF_SYSLOG, VLL_WARN);
+ vlog_set_levels(&this_module, VLF_SYSLOG, VLL_WARN);
break;
case OPT_DRY_RUN:
diff --git a/ovn/utilities/ovn-sbctl.c b/ovn/utilities/ovn-sbctl.c
index b428a3524..b9e3c10fe 100644
--- a/ovn/utilities/ovn-sbctl.c
+++ b/ovn/utilities/ovn-sbctl.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015 Nicira, Inc.
+ * Copyright (c) 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -231,7 +231,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
break;
case OPT_NO_SYSLOG:
- vlog_set_levels(&VLM_sbctl, VLF_SYSLOG, VLL_WARN);
+ vlog_set_levels(&this_module, VLF_SYSLOG, VLL_WARN);
break;
case OPT_DRY_RUN:
diff --git a/tests/test-reconnect.c b/tests/test-reconnect.c
index b70a7d550..76e43ea0f 100644
--- a/tests/test-reconnect.c
+++ b/tests/test-reconnect.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010, 2011, 2012, 2014 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2014, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/utilities/ovs-vsctl.c b/utilities/ovs-vsctl.c
index 00ac45894..eeb711f15 100644
--- a/utilities/ovs-vsctl.c
+++ b/utilities/ovs-vsctl.c
@@ -269,7 +269,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
break;
case OPT_NO_SYSLOG:
- vlog_set_levels(&VLM_vsctl, VLF_SYSLOG, VLL_WARN);
+ vlog_set_levels(&this_module, VLF_SYSLOG, VLL_WARN);
break;
case OPT_NO_WAIT:
diff --git a/vtep/vtep-ctl.c b/vtep/vtep-ctl.c
index 2f13dc6c1..bf42f1c25 100644
--- a/vtep/vtep-ctl.c
+++ b/vtep/vtep-ctl.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2009, 2010, 2011, 2012, 2014, 2015 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2014, 2015, 2016 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -223,7 +223,7 @@ parse_options(int argc, char *argv[], struct shash *local_options)
break;
case OPT_NO_SYSLOG:
- vlog_set_levels(&VLM_vtep_ctl, VLF_SYSLOG, VLL_WARN);
+ vlog_set_levels(&this_module, VLF_SYSLOG, VLL_WARN);
break;
case OPT_DRY_RUN: