net: print net_device reg_state in netdev_* unless it's registered
authorVeaceslav Falico <vfalico@gmail.com>
Thu, 17 Jul 2014 17:46:10 +0000 (19:46 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 21 Jul 2014 03:38:43 +0000 (20:38 -0700)
This way we'll always know in what status the device is, unless it's
running normally (i.e. NETDEV_REGISTERED).

Also, emit a warning once in case of a bad reg_state.

CC: "David S. Miller" <davem@davemloft.net>
CC: Jason Baron <jbaron@akamai.com>
CC: Eric Dumazet <edumazet@google.com>
CC: Vlad Yasevich <vyasevic@redhat.com>
CC: stephen hemminger <stephen@networkplumber.org>
CC: Jerry Chu <hkchu@google.com>
CC: Ben Hutchings <bhutchings@solarflare.com>
CC: Joe Perches <joe@perches.com>
Signed-off-by: Veaceslav Falico <vfalico@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netdevice.h
lib/dynamic_debug.c
net/core/dev.c

index 70256aa2ae81da5934bc91b1c44be7632f426148..8e8fb3ed574b43d32867acbaa5b7f218b24c17d7 100644 (file)
@@ -3388,6 +3388,21 @@ static inline const char *netdev_name(const struct net_device *dev)
        return dev->name;
 }
 
+static inline const char *netdev_reg_state(const struct net_device *dev)
+{
+       switch (dev->reg_state) {
+       case NETREG_UNINITIALIZED: return " (uninitialized)";
+       case NETREG_REGISTERED: return "";
+       case NETREG_UNREGISTERING: return " (unregistering)";
+       case NETREG_UNREGISTERED: return " (unregistered)";
+       case NETREG_RELEASED: return " (released)";
+       case NETREG_DUMMY: return " (dummy)";
+       }
+
+       WARN_ONCE(1, "%s: unknown reg_state %d\n", dev->name, dev->reg_state);
+       return " (unknown)";
+}
+
 __printf(3, 4)
 int netdev_printk(const char *level, const struct net_device *dev,
                  const char *format, ...);
@@ -3444,7 +3459,8 @@ do {                                                              \
  * file/line information and a backtrace.
  */
 #define netdev_WARN(dev, format, args...)                      \
-       WARN(1, "netdevice: %s\n" format, netdev_name(dev), ##args)
+       WARN(1, "netdevice: %s%s\n" format, netdev_name(dev),   \
+            netdev_reg_state(dev), ##args)
 
 /* netif printk helpers, similar to netdev_printk */
 
index 7288e38e17575952664af1df3a69ba488812c8e3..c9afbe2c445af155e2d2912ca362efae4ce02950 100644 (file)
@@ -614,13 +614,15 @@ int __dynamic_netdev_dbg(struct _ddebug *descriptor,
                char buf[PREFIX_SIZE];
 
                res = dev_printk_emit(7, dev->dev.parent,
-                                     "%s%s %s %s: %pV",
+                                     "%s%s %s %s%s: %pV",
                                      dynamic_emit_prefix(descriptor, buf),
                                      dev_driver_string(dev->dev.parent),
                                      dev_name(dev->dev.parent),
-                                     netdev_name(dev), &vaf);
+                                     netdev_name(dev), netdev_reg_state(dev),
+                                     &vaf);
        } else if (dev) {
-               res = printk(KERN_DEBUG "%s: %pV", netdev_name(dev), &vaf);
+               res = printk(KERN_DEBUG "%s%s: %pV", netdev_name(dev),
+                            netdev_reg_state(dev), &vaf);
        } else {
                res = printk(KERN_DEBUG "(NULL net_device): %pV", &vaf);
        }
index 239722af098dc559eadc48976d3a39c1cbab7c5f..81d61014fd9b30bb0bc0e9cf34b856293ac2e9cd 100644 (file)
@@ -6950,12 +6950,14 @@ static int __netdev_printk(const char *level, const struct net_device *dev,
        if (dev && dev->dev.parent) {
                r = dev_printk_emit(level[1] - '0',
                                    dev->dev.parent,
-                                   "%s %s %s: %pV",
+                                   "%s %s %s%s: %pV",
                                    dev_driver_string(dev->dev.parent),
                                    dev_name(dev->dev.parent),
-                                   netdev_name(dev), vaf);
+                                   netdev_name(dev), netdev_reg_state(dev),
+                                   vaf);
        } else if (dev) {
-               r = printk("%s%s: %pV", level, netdev_name(dev), vaf);
+               r = printk("%s%s%s: %pV", level, netdev_name(dev),
+                          netdev_reg_state(dev), vaf);
        } else {
                r = printk("%s(NULL net_device): %pV", level, vaf);
        }