[ovs-dev] [PATCH] Fix non-static instances of "struct vlog_rate_limit" and add check.

Ben Pfaff blp at nicira.com
Fri Jan 7 17:47:58 UTC 2011


A non-static vlog_rate_limit is not actually going to rate-limit anything.
---
 Makefile.am              |   14 +++++++++++++-
 lib/dpif-netdev.c        |    4 ++--
 lib/socket-util.c        |    6 +++---
 ofproto/ofproto.c        |    4 ++--
 vswitchd/ovs-brcompatd.c |    4 ++--
 5 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index eef8eb6..ccf5756 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-# Copyright (C) 2007, 2008, 2009, 2010 Nicira Networks, Inc.
+# Copyright (C) 2007, 2008, 2009, 2010, 2011 Nicira Networks, Inc.
 #
 # Copying and distribution of this file, with or without modification,
 # are permitted in any medium without royalty provided the copyright
@@ -122,6 +122,18 @@ distfiles: Makefile
 	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t" | sort -u > $@
 CLEANFILES += distfiles
 
+# Check that "struct vlog_ratelimit" is always declared "static".
+ALL_LOCAL += rate-limit-check
+rate-limit-check:
+	@if test -e $(srcdir)/.git && (git --version) >/dev/null 2>&1; then	\
+	  if git grep -n -E '^[ 	]+struct vlog_rate_limit.*=' $(srcdir);	\
+          then									\
+	    echo "See above for list of violations of the rule that ";		\
+	    echo "'struct vlog_rate_limit' must always be 'static'";		\
+	    exit 1;								\
+	  fi;									\
+	fi
+
 dist-hook: $(DIST_HOOKS)
 all-local: $(ALL_LOCAL)
 .PHONY: $(DIST_HOOKS)
diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index a52accc..82d7d74 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -966,7 +966,7 @@ dp_netdev_run(void)
             if (!error) {
                 dp_netdev_port_input(dp, port, &packet);
             } else if (error != EAGAIN && error != EOPNOTSUPP) {
-                struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+                static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
                 VLOG_ERR_RL(&rl, "error receiving data from %s: %s",
                             netdev_get_name(port->netdev), strerror(error));
             }
diff --git a/lib/socket-util.c b/lib/socket-util.c
index f74e43b..e97e7c9 100644
--- a/lib/socket-util.c
+++ b/lib/socket-util.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -114,7 +114,7 @@ int
 lookup_ip(const char *host_name, struct in_addr *addr)
 {
     if (!inet_aton(host_name, addr)) {
-        struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
         VLOG_ERR_RL(&rl, "\"%s\" is not a valid IP address", host_name);
         return ENOENT;
     }
@@ -129,7 +129,7 @@ get_socket_error(int fd)
     int error;
     socklen_t len = sizeof(error);
     if (getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0) {
-        struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 10);
+        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 10);
         error = errno;
         VLOG_ERR_RL(&rl, "getsockopt(SO_ERROR): %s", strerror(error));
     }
diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c
index 6ebda01..52a1964 100644
--- a/ofproto/ofproto.c
+++ b/ofproto/ofproto.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010 Nicira Networks.
+ * Copyright (c) 2009, 2010, 2011 Nicira Networks.
  * Copyright (c) 2010 Jean Tourrilhes - HP-Labs.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -2681,7 +2681,7 @@ xlate_table_action(struct action_xlate_ctx *ctx, uint16_t in_port)
             ctx->recurse--;
         }
     } else {
-        struct vlog_rate_limit recurse_rl = VLOG_RATE_LIMIT_INIT(1, 1);
+        static struct vlog_rate_limit recurse_rl = VLOG_RATE_LIMIT_INIT(1, 1);
 
         VLOG_ERR_RL(&recurse_rl, "NXAST_RESUBMIT recursed over %d times",
                     MAX_RESUBMIT_RECURSION);
diff --git a/vswitchd/ovs-brcompatd.c b/vswitchd/ovs-brcompatd.c
index bed2747..24b28a2 100644
--- a/vswitchd/ovs-brcompatd.c
+++ b/vswitchd/ovs-brcompatd.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2009, 2010 Nicira Networks
+/* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -917,7 +917,7 @@ handle_fdb_query_cmd(const struct ovsrec_open_vswitch *ovs,
         if (sscanf(line, "%d %d "ETH_ADDR_SCAN_FMT" %d",
                    &port, &vlan, ETH_ADDR_SCAN_ARGS(mac), &age)
             != 2 + ETH_ADDR_SCAN_COUNT + 1) {
-            struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
+            static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
             VLOG_INFO_RL(&rl, "fdb/show output has invalid format: %s", line);
             continue;
         }
-- 
1.7.1





More information about the dev mailing list