svn commit: r225708 - head/sys/dev/xen/netfront

Justin T. Gibbs gibbs at FreeBSD.org
Wed Sep 21 00:13:04 UTC 2011


Author: gibbs
Date: Wed Sep 21 00:13:04 2011
New Revision: 225708
URL: http://svn.freebsd.org/changeset/base/225708

Log:
  Modify the netfront driver so it can successfully attach to
  PV devices with the ioemu attribute set.
  
  sys/dev/xen/netfront/netfront.c:
  	o If a mac address for the interface cannot be found
  	  in the front-side XenStore tree, look for an entry
  	  in the back-side tree.  With ioemu devices, the
  	  emulator does not populate the front side tree and
  	  neither does Xend.
  	o Return an error rather than panic when an attach
  	  attempt fails.
  
  Reported by:	Janne Snabb (fix inspired by patch provided)
  PR:		kern/154302
  Approved by:	re

Modified:
  head/sys/dev/xen/netfront/netfront.c

Modified: head/sys/dev/xen/netfront/netfront.c
==============================================================================
--- head/sys/dev/xen/netfront/netfront.c	Wed Sep 21 00:08:25 2011	(r225707)
+++ head/sys/dev/xen/netfront/netfront.c	Wed Sep 21 00:13:04 2011	(r225708)
@@ -406,11 +406,33 @@ xen_net_read_mac(device_t dev, uint8_t m
 {
 	int error, i;
 	char *s, *e, *macstr;
+	const char *path;
 
-	error = xs_read(XST_NIL, xenbus_get_node(dev), "mac", NULL,
-	    (void **) &macstr);
-	if (error)
+	path = xenbus_get_node(dev);
+	error = xs_read(XST_NIL, path, "mac", NULL, (void **) &macstr);
+	if (error == ENOENT) {
+		/*
+		 * Deal with missing mac XenStore nodes on devices with
+		 * HVM emulation (the 'ioemu' configuration attribute)
+		 * enabled.
+		 *
+		 * The HVM emulator may execute in a stub device model
+		 * domain which lacks the permission, only given to Dom0,
+		 * to update the guest's XenStore tree.  For this reason,
+		 * the HVM emulator doesn't even attempt to write the
+		 * front-side mac node, even when operating in Dom0.
+		 * However, there should always be a mac listed in the
+		 * backend tree.  Fallback to this version if our query
+		 * of the front side XenStore location doesn't find
+		 * anything.
+		 */
+		path = xenbus_get_otherend_path(dev);
+		error = xs_read(XST_NIL, path, "mac", NULL, (void **) &macstr);
+	}
+	if (error != 0) {
+		xenbus_dev_fatal(dev, error, "parsing %s/mac", path);
 		return (error);
+	}
 
 	s = macstr;
 	for (i = 0; i < ETHER_ADDR_LEN; i++) {
@@ -451,7 +473,7 @@ netfront_attach(device_t dev)
 	err = create_netdev(dev);
 	if (err) {
 		xenbus_dev_fatal(dev, err, "creating netdev");
-		return err;
+		return (err);
 	}
 
 #if __FreeBSD_version >= 700000
@@ -461,7 +483,7 @@ netfront_attach(device_t dev)
 	    &xn_enable_lro, 0, "Large Receive Offload");
 #endif
 
-	return 0;
+	return (0);
 }
 
 static int
@@ -2067,11 +2089,8 @@ create_netdev(device_t dev)
 	}
 	
 	err = xen_net_read_mac(dev, np->mac);
-	if (err) {
-		xenbus_dev_fatal(dev, err, "parsing %s/mac",
-		    xenbus_get_node(dev));
+	if (err)
 		goto out;
-	}
 	
 	/* Set up ifnet structure */
 	ifp = np->xn_ifp = if_alloc(IFT_ETHER);
@@ -2105,8 +2124,7 @@ create_netdev(device_t dev)
 exit:
 	gnttab_free_grant_references(np->gref_tx_head);
 out:
-	panic("do something smart");
-
+	return (err);
 }
 
 /**


More information about the svn-src-head mailing list