Skip to contentSkip to conversation

linux: allow netback to be a module

PATCH New Jan Beulich 1 participant 1 message Feb 28, 2006 Xen hypervisor interface

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux: allow netback to be a module

This is only a first step. netback uses add_timer_on(), which isn't being exported, and which I don't think would be a good idea to export. Someone knowing the code better than me should check whether that function can be reasonably replaced by __mod_timer(). All other build issues preventing modular use should be resolved with this patch.

Jan

drivers/xen/Kconfig +9 -1
Index: head-2006-02-23/drivers/xen/Kconfig
===================================================================
@@ -89,7 +89,7 @@ config XEN_BLKDEV_TAP_BE
           modified to use grant tables.
 
 config XEN_NETDEV_BACKEND
-	bool "Network-device backend driver"
+	tristate "Network-device backend driver"
 	default y
 	help
 	  The network-device backend driver allows the kernel to export its
@@ -161,6 +161,14 @@ config XEN_TPMDEV_FRONTEND
 	help
 	  The TPM-device frontend driver.
 
+config XEN_NETDEV_LOOPBACK
+	tristate "Network-device loopback driver"
+	depends on XEN_NETDEV_BACKEND && XEN_NETDEV_FRONTEND
+	default y
+	help
+	  A two-interface loopback device to emulate a local netfront-netback
+	  connection.
+
 config XEN_SCRUB_PAGES
 	bool "Scrub memory before freeing it to Xen"
 	default y
drivers/xen/core/skbuff.c +1 -0
Index: head-2006-02-23/drivers/xen/core/skbuff.c
===================================================================
@@ -16,6 +16,7 @@
 
 /* Referenced in netback.c. */
 /*static*/ kmem_cache_t *skbuff_cachep;
+EXPORT_SYMBOL(skbuff_cachep);
 
 #define MAX_SKBUFF_ORDER 4
 static kmem_cache_t *skbuff_order_cachep[MAX_SKBUFF_ORDER + 1];
drivers/xen/netback/Makefile +4 -1
Index: head-2006-02-23/drivers/xen/netback/Makefile
===================================================================
@@ -1,2 +1,5 @@
+obj-$(CONFIG_XEN_NETDEV_BACKEND) := netbk.o
+obj-$(CONFIG_XEN_NETDEV_LOOPBACK) += netloop.o
 
-obj-y	:= netback.o xenbus.o interface.o loopback.o
+netbk-y   := netback.o xenbus.o interface.o
+netloop-y := loopback.o
drivers/xen/netback/loopback.c +29 -0
Index: head-2006-02-23/drivers/xen/netback/loopback.c
===================================================================
@@ -178,6 +178,23 @@ static int __init make_loopback(int i)
 	return err;
 }
 
+static void __init clean_loopback(int i)
+{
+	struct net_device *dev1, *dev2;
+	char dev_name[IFNAMSIZ];
+
+	sprintf(dev_name, "vif0.%d", i);
+	dev1 = dev_get_by_name(dev_name);
+	sprintf(dev_name, "veth%d", i);
+	dev2 = dev_get_by_name(dev_name);
+	if (dev1 && dev2) {
+		unregister_netdev(dev2);
+		unregister_netdev(dev1);
+		free_netdev(dev2);
+		free_netdev(dev1);
+	}
+}
+
 static int __init loopback_init(void)
 {
 	int i, err = 0;
@@ -191,6 +208,18 @@ static int __init loopback_init(void)
 
 module_init(loopback_init);
 
+static void __exit loopback_exit(void)
+{
+	int i;
+
+	for (i = nloopbacks; i-- > 0; )
+		clean_loopback(i);
+}
+
+module_exit(loopback_exit);
+
+MODULE_LICENSE("Dual BSD/GPL");
+
 /*
  * Local variables:
  *  c-file-style: "linux"
drivers/xen/netback/netback.c +4 -0
Index: head-2006-02-23/drivers/xen/netback/netback.c
===================================================================
@@ -811,6 +811,8 @@ static int __init netback_init(void)
 		&netif_be_dbg);
 #endif
 
+	__unsafe(THIS_MODULE);
+
 	return 0;
 }
 
@@ -822,6 +824,8 @@ static void netback_cleanup(void)
 module_init(netback_init);
 module_exit(netback_cleanup);
 
+MODULE_LICENSE("Dual BSD/GPL");
+
 /*
  * Local variables:
  *  c-file-style: "linux"

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel