net: print net_device name/state more often
Subsystems (4)
v3 cover net: print net_device name/state more often
Hi,
Currently we use net_device->name only if it's the NETREG_REGISTERED reg_state, otherwise we return "(unregistered device)".
However, we always populate net_device->name on creation, so it's always available to us for use. The only caveat is that we might have a name like "eth%d", in which case we cannot use it as it might change in the future.
Also, the net_device might not be NETREG_UNREGISTERED when the function is called (_UNINITIALIZED, _UNREGISTERING, _RELEASED, _DUMMY), so it's misleading.
So, a better way would be to always return the dev->name in netdev_name(), unless it's in the form of "eth%d" or it's empty, then return "unnamed net_device". This way we'll always return the name in NETREG_REGISTERED reg_state, and also return it in other states, when possible.
Also, to be more verbose on non-NETREG_REGISTERED states, add a function netdev_reg_state(), which returns a string describing the state, and use it in netdev_printk()-related functions. If the dev is in NETREG_REGISTERED state then a void string is regurned and, thus, nothing changes.
After these two patches we'll have the same behaviour in the usual cases, and more verbose in non-standardad/buggy ones.
v2->v3:
Correct the string for _UNINITIALIZED and warn on a bad reg_state, per Joe Perches's comments.
v1->v2:
As Tom Gundersen suggested, there might be a case when we have an empty string as a name for a device, so account this also and return "unnamed device" for that case too.
--- include/linux/netdevice.h | 22 +++++++++++++++++++--- lib/dynamic_debug.c | 8 +++++--- net/core/dev.c | 8 +++++--- 3 files changed, 29 insertions(+), 9 deletions(-)
PATCH v3 1/2 net: use dev->name in netdev_pr* when it's available
netdev_name() returns dev->name only when the net_device is in NETREG_REGISTERED state.
However, dev->name is always populated on creation, so we can easily use it.
There are two cases when there's no real name - when it's an empty string or when the name is in form of "eth%d", then netdev_name() returns "unnamed net_device".
---
Notes:
v1->v2:
Also account for an empty string, as Tom Gundersen suggested.
include/linux/netdevice.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/netdevice.h +2 -2
@@ -3383,8 +3383,8 @@ extern struct pernet_operations __net_initdata loopback_net_ops;static inline const char *netdev_name (const struct net_device *dev) { -if (dev->reg_state !=NETREG_REGISTERED ) -return "(unregistered net_device)" ; +if (!dev->name[0 ] ||strchr (dev->name,'%' )) +return "(unnamed net_device)" ;return dev->name; }
Signature · 1 line
1.8.4
Re: [PATCH v3 net-next 1/2] net: use dev->name in netdev_pr* when it's available
Quoted 6 lines · Veaceslav Falico
netdev_name()returnsdev->nameonly when thenet_deviceis inNETREG_REGISTEREDstate.However,
dev->nameis always populated on creation, so we can easily use it.
Quoted 6 lines
There are two cases when there's no real name - when it's an empty string or when the name is in form of "eth%d", then
netdev_name()returns "unnamednet_device".CC "David S. Miller" <[email protected]>CC Tom Gundersen <[email protected]>
Quoted 28 lines
Signed-off-by Veaceslav Falico <[email protected]>---
Notes:
v1->v2:
Also account for an empty string, as Tom Gundersen suggested.include/linux/netdevice.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/linux/netdevice.h +2
-3@@ -3383,8 +3383,8 @@ extern struct pernet_operations __net_initdata loopback_net_ops;static inline const char *netdev_name (const struct net_device *dev) { -if (dev->reg_state !=NETREG_REGISTERED ) -return "(unregistered net_device)" ; +if (!dev->name[0 ] ||strchr (dev->name,'%' )) +return "(unnamed net_device)" ;return dev->name; } --1.8.4
PATCH v3 2/2 net: print net_device reg_state in netdev_* unless it's registered
In reply to Veaceslav FalicoThis 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.
---
Notes:
v2->v3:
Correct the string for _UNINITIALIZED and warn on a bad reg_state, per Joe Perches's comments.
include/linux/netdevice.h | 18 +++++++++++++++++- lib/dynamic_debug.c | 8 +++++--- net/core/dev.c | 8 +++++--- 3 files changed, 27 insertions(+), 7 deletions(-)
include/linux/netdevice.h +17 -1
@@ -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 */
lib/dynamic_debug.c +5 -3
@@ -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); }
net/core/dev.c +5 -3
@@ -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); }
Signature · 1 line
1.8.4
Re: [PATCH v3 net-next 2/2] net: print net_device reg_state in netdev_* unless it's registered
On Thu, 2014-07-17 at 19:46 +0200, Veaceslav Falico wrote:
[]
include/linux/netdevice.h
Quoted 1 line
include/linux/netdevice.h +0
-0
[]
include/linux/netdevice.h do { \ · line 3463
Quoted 7 lines
include/linux/netdevice.h +2
-1@@ -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)
trivia:
My preference for style here is to have the format and args on one line when it fits and separate the format and args lines when they don't.
WARN(1, "netdevice: %s%s\n" format, netdev_name(dev), netdev_reg_state(dev), ##args)
Unrelated: maybe it'd be better to change the '\n' to ": "
lib/dynamic_debug.c
Quoted 1 line
lib/dynamic_debug.c +0
-0
[]
lib/dynamic_debug.c int __dynamic_netdev_dbg(struct _ddebug *descriptor, · line 625
Quoted 3 lines
lib/dynamic_debug.c +2
-1- 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);
etc...
Re: [PATCH v3 net-next 2/2] net: print net_device reg_state in netdev_* unless it's registered
Quoted 14 lines · Joe Perches
On Thu, 2014-07-17 at 19:46 +0200, Veaceslav Falico wrote:
[]include/linux/netdevice.h
Quoted 1 line
include/linux/netdevice.h +0
-0[]
include/linux/netdevice.h do { \ · line 3463
Quoted 7 lines
include/linux/netdevice.h +2
-1@@ -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)trivia:
Quoted 8 lines
My preference for style here is to have the format and args on one line when it fits and separate the format and args lines when they don't.
WARN(1, "netdevice: %s%s\n" format, netdev_name(dev), netdev_reg_state(dev), ##args)Unrelated: maybe it'd be better to change the '\n' to ": "
Good points, but I guess they're minor. If I'll send v4 I'll include them.
Quoted 10 lines
lib/dynamic_debug.c
Quoted 2 lines
lib/dynamic_debug.c +0
-0[]
lib/dynamic_debug.c int __dynamic_netdev_dbg(struct _ddebug *descriptor, · line 625
Quoted 3 lines
lib/dynamic_debug.c +2
-1- 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);etc...
David Miller
maintainerFrom: Veaceslav Falico <[email protected]>
Date: Thu, 17 Jul 2014 19:46:08 +0200
Quoted 25 lines
Currently we use
net_device->nameonly if it's theNETREG_REGISTEREDreg_state, otherwise we return "(unregistered device)".However, we always populate
net_device->nameon creation, so it's always available to us for use. The only caveat is that we might have a name like "eth%d", in which case we cannot use it as it might change in the future.Also, the
net_devicemight not beNETREG_UNREGISTEREDwhen the function is called (_UNINITIALIZED,_UNREGISTERING,_RELEASED,_DUMMY), so it's misleading.So, a better way would be to always return the
dev->nameinnetdev_name(), unless it's in the form of "eth%d" or it's empty, then return "unnamednet_device". This way we'll always return the name inNETREG_REGISTEREDreg_state, and also return it in other states, when possible.Also, to be more verbose on non-NETREG_REGISTERED states, add a function
netdev_reg_state(), which returns a string describing the state, and use it in netdev_printk()-related functions. If the dev is inNETREG_REGISTEREDstate then a void string is regurned and, thus, nothing changes.After these two patches we'll have the same behaviour in the usual cases, and more verbose in non-standardad/buggy ones.
Quoted 8 lines
v2->v3:
Correct the string for_UNINITIALIZEDand warn on a badreg_state, per Joe Perches's comments.
v1->v2:
As Tom Gundersen suggested, there might be a case when we have an empty string as a name for a device, so account this also and return "unnamed device" for that case too.
Series applied, thanks.