[PATCH -mm 5/9] netconsole: Introduce dev_status member

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Satyam Sharma <[email protected]>

[5/9] netconsole: Introduce dev_status member

Introduce a new member in netconsole_target that tracks the status (up or
down) of the underlying interface network device that the specific logging
target netpoll is attached to.

We then join this up with the just-introduced net_device notifier, and
introduce NETDEV_UP and NETDEV_DOWN notifications. By disabling the target
when the corresponding local interface is down, we save the overhead of
unnecessarily disabling interrupts and calling into the netpoll stack in
console->write().

Signed-off-by: Satyam Sharma <[email protected]>
Cc: Keiichi Kii <[email protected]>
Cc: Takayoshi Kochi <[email protected]>

---

 drivers/net/netconsole.c |   42 +++++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 11 deletions(-)

---

diff -ruNp a/drivers/net/netconsole.c b/drivers/net/netconsole.c
--- a/drivers/net/netconsole.c	2007-07-03 22:05:51.000000000 +0530
+++ b/drivers/net/netconsole.c	2007-07-04 03:04:45.000000000 +0530
@@ -63,11 +63,23 @@ static int __init option_setup(char *opt
 __setup("netconsole=", option_setup);
 #endif
 
+/*
+ * Why no net_dev_is_up() in netdevice.h? The kernel could lose a lot of
+ * weight if only netdevice.h had the good sense to export such a function.
+ * Oh well ...
+ */
+static inline int net_dev_is_up(struct net_device *net_dev)
+{
+	return ((net_dev->flags & IFF_UP) == IFF_UP);
+}
+
 /**
  * struct netconsole_target - Represents a configured netconsole target.
+ * @dev_status:	Tracks whether the underlying interface is up or down.
  * @np:		The netpoll structure for this target.
  */
 struct netconsole_target {
+	int			dev_status;
 	struct netpoll		np;
 };
 
@@ -89,11 +101,17 @@ static int netconsole_netdev_event(struc
 	struct net_device *dev = ptr;
 	struct netconsole_target *nt = &default_target;
 
-	if (!(event == NETDEV_CHANGEADDR || event == NETDEV_CHANGENAME))
-		goto done;
+	if (!(event == NETDEV_UP || event == NETDEV_DOWN ||
+	      event == NETDEV_CHANGEADDR || event == NETDEV_CHANGENAME))
+	      	goto done;
 
 	if (nt->np.dev == dev) {
 		switch (event) {
+		case NETDEV_UP:
+		case NETDEV_DOWN:
+			nt->dev_status = net_dev_is_up(nt->np.dev);
+			break;
+
 		case NETDEV_CHANGEADDR:
 			memcpy(nt->np.local_mac, dev->dev_addr, ETH_ALEN);
 			break;
@@ -118,16 +136,16 @@ static void write_msg(struct console *co
 	unsigned long flags;
 	struct netconsole_target *nt = &default_target;
 
-	local_irq_save(flags);
-
-	for (left = len; left;) {
-		frag = min(left, MAX_PRINT_CHUNK);
-		netpoll_send_udp(&nt->np, msg, frag);
-		msg += frag;
-		left -= frag;
+	if (nt->dev_status) {
+		local_irq_save(flags);
+		for (left = len; left;) {
+			frag = min(left, MAX_PRINT_CHUNK);
+			netpoll_send_udp(&nt->np, msg, frag);
+			msg += frag;
+			left -= frag;
+		}
+		local_irq_restore(flags);
 	}
-
-	local_irq_restore(flags);
 }
 
 static struct console netconsole = {
@@ -154,6 +172,8 @@ static int __init init_netconsole(void)
 	if (err)
 		goto out;
 
+	nt->dev_status = net_dev_is_up(nt->np.dev);
+
 	err = register_netdevice_notifier(&netconsole_netdev_notifier);
 	if (err)
 		return err;
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux