datapath: Add log level annotations to printk messages.
authorBen Pfaff <blp@nicira.com>
Sat, 10 Jan 2009 00:24:56 +0000 (16:24 -0800)
committerBen Pfaff <blp@nicira.com>
Sat, 10 Jan 2009 00:24:56 +0000 (16:24 -0800)
General approach is:

- KERN_EMERG: Conditions that prevent the modules from loading.

- KERN_ERR: Conditions that indicate an OpenFlow kernel code bug.

- KERN_WARNING: Conditions that might indicate a bug in OpenFlow kernel
  code or other kernel code.

- KERN_NOTICE: Conditions that might indicate a bug in secchan or the
  OpenFlow controller, or minor conditions that are typically transient.

datapath/chain.c
datapath/datapath.c
datapath/datapath.h
datapath/dp_act.c
datapath/forward.c
datapath/nx_act_snat.c
datapath/table-hash.c

index aec78e3ae6cf45d39fa4a846a93932e22d695090..229be65ce2966932dbd65c2f782887d7615490bd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Distributed under the terms of the GNU GPL version 2.
- * Copyright (c) 2007, 2008 The Board of Trustees of The Leland 
+ * Copyright (c) 2007, 2008, 2009 The Board of Trustees of The Leland 
  * Stanford Junior University
  */
 
@@ -25,7 +25,8 @@ static int add_table(struct sw_chain *chain, struct sw_table *table)
        if (table == NULL)
                return -ENOMEM;
        if (chain->n_tables >= CHAIN_MAX_TABLES) {
-               printk("%s: too many tables in chain\n", chain->dp->netdev->name);
+               printk(KERN_EMERG "%s: too many tables in chain\n",
+                      chain->dp->netdev->name);
                table->destroy(table);
                return -ENOBUFS;
        }
index 2e00091b0924faf17bd643eeb4e0194152f02e51..e5ed9df1b405cf3199396d731d2b14a08c707f73 100644 (file)
@@ -224,8 +224,9 @@ alloc_openflow_skb(struct datapath *dp, size_t openflow_len, uint8_t type,
 
        if ((openflow_len + sizeof(struct ofp_header)) > UINT16_MAX) {
                if (net_ratelimit())
-                       printk("%s: alloc_openflow_skb: openflow message too large: %zu\n", 
-                                       dp->netdev->name, openflow_len);
+                       printk(KERN_ERR "%s: alloc_openflow_skb: openflow "
+                              "message too large: %zu\n",
+                              dp->netdev->name, openflow_len);
                return NULL;
        }
 
@@ -234,9 +235,6 @@ alloc_openflow_skb(struct datapath *dp, size_t openflow_len, uint8_t type,
        genl_len += nla_total_size(openflow_len);    /* DP_GENL_A_OPENFLOW */
        skb = *pskb = genlmsg_new(genl_len, GFP_ATOMIC);
        if (!skb) {
-               if (net_ratelimit())
-                       printk("%s: alloc_openflow_skb: genlmsg_new failed\n", 
-                                       dp->netdev->name);
                return NULL;
        }
 
@@ -663,8 +661,8 @@ dp_xmit_skb(struct sk_buff *skb)
        int len = skb->len;
 
        if (packet_length(skb) > skb->dev->mtu && !skb_is_gso(skb)) {
-               printk("%s: dropped over-mtu packet: %d > %d\n",
-                          dp->netdev->name, packet_length(skb), skb->dev->mtu);
+               printk(KERN_WARNING "%s: dropped over-mtu packet: %d > %d\n",
+                      dp->netdev->name, packet_length(skb), skb->dev->mtu);
                kfree_skb(skb);
                return -E2BIG;
        }
@@ -686,8 +684,9 @@ int dp_output_port(struct datapath *dp, struct sk_buff *skb, int out_port,
                 * the skb. */
                if (!skb->dev) {
                        if (net_ratelimit())
-                               printk("%s: skb device not set forwarding to in_port\n",
-                                               dp->netdev->name);
+                               printk(KERN_NOTICE "%s: skb device not set "
+                                      "forwarding to in_port\n",
+                                      dp->netdev->name);
                        kfree_skb(skb);
                        return -ESRCH;
                }
@@ -727,8 +726,9 @@ int dp_output_port(struct datapath *dp, struct sk_buff *skb, int out_port,
                        /* To send to the input port, must use OFPP_IN_PORT */
                        kfree_skb(skb);
                        if (net_ratelimit())
-                               printk("%s: can't directly forward to input port\n", 
-                                               dp->netdev->name);
+                               printk(KERN_NOTICE "%s: can't directly "
+                                      "forward to input port\n",
+                                      dp->netdev->name);
                        return -EINVAL;
                }
                if (p->config & OFPPC_NO_FWD && !ignore_no_fwd) {
@@ -746,8 +746,8 @@ int dp_output_port(struct datapath *dp, struct sk_buff *skb, int out_port,
 bad_port:
        kfree_skb(skb);
        if (net_ratelimit())
-               printk("%s: can't forward to bad port %d\n", dp->netdev->name, 
-                               out_port);
+               printk(KERN_NOTICE "%s: can't forward to bad port %d\n",
+                      dp->netdev->name, out_port);
        return -ENOENT;
 }
 
index ffd045e8fa2fffcf0a3932387f2608f74054f04d..84eb5dc28520b652a2f0a8f52698a7cbb3dccd10 100644 (file)
 
 #define NL_FLOWS_PER_MESSAGE 100
 
-#ifdef NDEBUG
-#define dprintk(x...)
-#else
-#define dprintk(x...) printk(x)
-#endif
-
 /* Capabilities supported by this implementation. */
 #define OFP_SUPPORTED_CAPABILITIES ( OFPC_FLOW_STATS \
                | OFPC_TABLE_STATS \
index 32a1e42900c9ebdd9f22d89a1e860d077a996210..3b5086f6344d85d362fb56fa3ea3a43b1650cb86 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Distributed under the terms of the GNU GPL version 2.
- * Copyright (c) 2007, 2008 The Board of Trustees of The Leland 
+ * Copyright (c) 2007, 2008, 2009 The Board of Trustees of The Leland 
  * Stanford Junior University
  */
 
@@ -398,17 +398,8 @@ execute_ofpat(struct sk_buff *skb, struct sw_flow_key *key,
                const struct ofp_action_header *ah, uint16_t type)
 {
        const struct openflow_action *act = &of_actions[type];
-       struct datapath *dp = skb->dev->br_port->dp;
-
-       if (act->execute)  {
-               if (!make_writable(&skb)) {
-                       if (net_ratelimit())
-                               printk("%s: make_writable failed\n", dp->netdev->name);
-                       return skb;
-               }
+       if (act->execute && make_writable(&skb))
                skb = act->execute(skb, key, ah);
-       }
-
        return skb;
 }
 
@@ -432,8 +423,9 @@ execute_vendor(struct sk_buff *skb, const struct sw_flow_key *key,
        default:
                /* This should not be possible due to prior validation. */
                if (net_ratelimit())
-                       printk("%s: attempt to execute action with unknown vendor: %#x\n", 
-                                       dp->netdev->name, ntohl(avh->vendor));
+                       printk(KERN_WARNING "%s: attempt to execute action "
+                              "with unknown vendor: %#x\n",
+                              dp->netdev->name, ntohl(avh->vendor));
                break;
        }
 
@@ -483,8 +475,9 @@ void execute_actions(struct datapath *dp, struct sk_buff *skb,
 
                        if (!skb) {
                                if (net_ratelimit())
-                                       printk("%s: execute_actions lost skb\n", 
-                                                       dp->netdev->name);
+                                       printk(KERN_WARNING "%s: "
+                                              "execute_actions lost skb\n",
+                                              dp->netdev->name);
                                return;
                        }
                }
index 1ba291032ed90a9ab320703ba015c84ba7beb085..d8662397686b0d50402e716b8e76cbd838de27bd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Distributed under the terms of the GNU GPL version 2.
- * Copyright (c) 2007, 2008 The Board of Trustees of The Leland 
+ * Copyright (c) 2007, 2008, 2009 The Board of Trustees of The Leland 
  * Stanford Junior University
  */
 
@@ -128,8 +128,8 @@ recv_packet_out(struct sw_chain *chain, const struct sender *sender,
 
        if (actions_len > (ntohs(opo->header.length) - sizeof *opo)) {
                if (net_ratelimit()) 
-                       printk("%s: message too short for number of actions\n", 
-                                       chain->dp->netdev->name);
+                       printk(KERN_NOTICE "%s: message too short for number "
+                              "of actions\n", chain->dp->netdev->name);
                return -EINVAL;
        }
 
@@ -349,8 +349,8 @@ recv_vendor(struct sw_chain *chain, const struct sender *sender,
                return nx_recv_msg(chain, sender, msg);
        default:
                if (net_ratelimit())
-                       printk("%s: unknown vendor: 0x%x\n", chain->dp->netdev->name, 
-                                       ntohl(ovh->vendor));
+                       printk(KERN_NOTICE "%s: unknown vendor: 0x%x\n",
+                              chain->dp->netdev->name, ntohl(ovh->vendor));
                dp_send_error_msg(chain->dp, sender, OFPET_BAD_REQUEST,
                                  OFPBRC_BAD_VENDOR, msg, ntohs(ovh->header.length));
                return -EINVAL;
@@ -429,8 +429,9 @@ fwd_control_input(struct sw_chain *chain, const struct sender *sender,
        }
        if (ntohs(oh->length) != length) {
                if (net_ratelimit())
-                       printk("%s: received message length wrong: %d/%d\n", 
-                               chain->dp->netdev->name, ntohs(oh->length), length);
+                       printk(KERN_NOTICE "%s: received message length "
+                              "wrong: %d/%d\n", chain->dp->netdev->name,
+                              ntohs(oh->length), length);
                return -EINVAL;
        }
 
@@ -519,8 +520,9 @@ static struct sk_buff *retrieve_skb(uint32_t id)
                skb = p->skb;
                p->skb = NULL;
        } else {
-               printk("cookie mismatch: %x != %x\n",
-                               id >> PKT_BUFFER_BITS, p->cookie);
+               if (net_ratelimit())
+                       printk(KERN_NOTICE "cookie mismatch: %x != %x\n",
+                              id >> PKT_BUFFER_BITS, p->cookie);
        }
        spin_unlock_irqrestore(&buffer_lock, flags);
 
index 5db6f9d4cd79fa9e74940d887068ccb94dfb68d2..5b26c62578eb195862543048d2c41f0f55f70cbd 100644 (file)
@@ -1,7 +1,7 @@
 #ifdef SUPPORT_SNAT
 /*
  * Distributed under the terms of the GNU GPL version 2.
- * Copyright (c) 2008 Nicira Networks
+ * Copyright (c) 2008, 2009 Nicira Networks
  */
 
 #include <linux/netdevice.h>
@@ -127,12 +127,8 @@ dnat_mac(struct net_bridge_port *p, struct sk_buff *skb)
        list_for_each_entry (m, &sc->mappings, node) {
                if (m->ip_addr == iph->daddr){
                        /* Found it! */
-                       if (!make_writable(&skb)) {
-                               if (net_ratelimit())
-                                       printk("%s: make_writable failed\n", 
-                                                       p->dp->netdev->name);
+                       if (!make_writable(&skb))
                                return -EINVAL;
-                       }
                        m->used = jiffies;
                        memcpy(eh->h_dest, m->hw_addr, ETH_ALEN);
                        break;
@@ -268,12 +264,8 @@ handle_icmp_snat(struct sk_buff *skb)
 
        /* Send an echo reply in response */
        nskb = skb_copy(skb, GFP_ATOMIC);
-       if (!nskb) {
-               if (net_ratelimit())
-                       printk("%s: skb copy failed for icmp reply\n", 
-                                       p->dp->netdev->name);
+       if (!nskb)
                return -1;
-       }
 
        /* Update Ethernet header. */
        eh = eth_hdr(nskb);
@@ -486,8 +478,9 @@ snat_del_port(struct datapath *dp, uint16_t port)
 
        if (!p) {
                if (net_ratelimit()) 
-                       printk("%s: attempt to remove snat on non-existent port: %d\n", 
-                                       dp->netdev->name, port);
+                       printk(KERN_NOTICE "%s: attempt to remove snat on "
+                              "non-existent port: %d\n",
+                              dp->netdev->name, port);
                return -EINVAL;
        }
 
@@ -496,8 +489,8 @@ snat_del_port(struct datapath *dp, uint16_t port)
                /* SNAT not configured on this port */
                spin_unlock_irqrestore(&p->lock, flags);
                if (net_ratelimit()) 
-                       printk("%s: attempt to remove snat on non-snat port: %d\n", 
-                                       dp->netdev->name, port);
+                       printk(KERN_NOTICE "%s: attempt to remove snat on "
+                              "non-snat port: %d\n", dp->netdev->name, port);
                return -EINVAL;
        }
 
@@ -522,8 +515,9 @@ snat_add_port(struct datapath *dp, uint16_t port,
 
        if (!p) {
                if (net_ratelimit()) 
-                       printk("%s: attempt to add snat on non-existent port: %d\n", 
-                                       dp->netdev->name, port);
+                       printk(KERN_NOTICE "%s: attempt to add snat on "
+                              "non-existent port: %d\n",
+                              dp->netdev->name, port);
                return -EINVAL;
        }
        
index 588b5f56c08809572495e2d057d6a90d30966b97..a501c3caa26ede48dd6f333aae2e9036e1fad2f3 100644 (file)
@@ -242,7 +242,8 @@ struct sw_table *table_hash_create(unsigned int polynomial,
        BUG_ON(n_buckets & (n_buckets - 1));
        th->buckets = kmem_zalloc(n_buckets * sizeof *th->buckets);
        if (th->buckets == NULL) {
-               printk("failed to allocate %u buckets\n", n_buckets);
+               printk(KERN_EMERG "failed to allocate %u buckets\n",
+                      n_buckets);
                kfree(th);
                return NULL;
        }
@@ -422,8 +423,8 @@ kmem_alloc(size_t size)
        if (!ptr) {
                ptr = vmalloc(size);
                if (ptr)
-                       printk("openflow: used vmalloc for %lu bytes\n", 
-                                       (unsigned long)size);
+                       printk(KERN_NOTICE "openflow: used vmalloc for %lu "
+                              "bytes\n", (unsigned long)size);
        }
        return ptr;
 }