direct-io.hg

changeset 11754:efea4c3b8bcc

[NET] back: Simplify probing of new interfaces. There's no need
to watch for creation of the handle node in xenstore, as it is
written by xend when creating the backend directory as part of
the same transaction.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Oct 13 17:10:27 2006 +0100 (2006-10-13)
parents d2f13c8b0819
children 7da100019e00
files linux-2.6-xen-sparse/drivers/xen/netback/common.h linux-2.6-xen-sparse/drivers/xen/netback/interface.c linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Fri Oct 13 17:07:39 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Fri Oct 13 17:10:27 2006 +0100
     1.3 @@ -106,7 +106,7 @@ typedef struct netif_st {
     1.4  
     1.5  void netif_disconnect(netif_t *netif);
     1.6  
     1.7 -netif_t *netif_alloc(domid_t domid, unsigned int handle, u8 be_mac[ETH_ALEN]);
     1.8 +netif_t *netif_alloc(domid_t domid, unsigned int handle);
     1.9  int netif_map(netif_t *netif, unsigned long tx_ring_ref,
    1.10  	      unsigned long rx_ring_ref, unsigned int evtchn);
    1.11  
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Fri Oct 13 17:07:39 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Fri Oct 13 17:10:27 2006 +0100
     2.3 @@ -126,7 +126,7 @@ static struct ethtool_ops network_ethtoo
     2.4  	.get_link = ethtool_op_get_link,
     2.5  };
     2.6  
     2.7 -netif_t *netif_alloc(domid_t domid, unsigned int handle, u8 be_mac[ETH_ALEN])
     2.8 +netif_t *netif_alloc(domid_t domid, unsigned int handle)
     2.9  {
    2.10  	int err = 0, i;
    2.11  	struct net_device *dev;
    2.12 @@ -169,20 +169,14 @@ netif_t *netif_alloc(domid_t domid, unsi
    2.13  		printk(KERN_WARNING "netbk: WARNING: device '%s' has non-zero "
    2.14  		       "queue length (%lu)!\n", dev->name, dev->tx_queue_len);
    2.15  
    2.16 -	for (i = 0; i < ETH_ALEN; i++)
    2.17 -		if (be_mac[i] != 0)
    2.18 -			break;
    2.19 -	if (i == ETH_ALEN) {
    2.20 -		/*
    2.21 -		 * Initialise a dummy MAC address. We choose the numerically
    2.22 -		 * largest non-broadcast address to prevent the address getting
    2.23 -		 * stolen by an Ethernet bridge for STP purposes.
    2.24 -		 * (FE:FF:FF:FF:FF:FF)
    2.25 -		 */ 
    2.26 -		memset(dev->dev_addr, 0xFF, ETH_ALEN);
    2.27 -		dev->dev_addr[0] &= ~0x01;
    2.28 -	} else
    2.29 -		memcpy(dev->dev_addr, be_mac, ETH_ALEN);
    2.30 +	/*
    2.31 +	 * Initialise a dummy MAC address. We choose the numerically
    2.32 +	 * largest non-broadcast address to prevent the address getting
    2.33 +	 * stolen by an Ethernet bridge for STP purposes.
    2.34 +	 * (FE:FF:FF:FF:FF:FF)
    2.35 +	 */ 
    2.36 +	memset(dev->dev_addr, 0xFF, ETH_ALEN);
    2.37 +	dev->dev_addr[0] &= ~0x01;
    2.38  
    2.39  	rtnl_lock();
    2.40  	err = register_netdevice(dev);
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Fri Oct 13 17:07:39 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Fri Oct 13 17:10:27 2006 +0100
     3.3 @@ -28,29 +28,20 @@
     3.4      printk("netback/xenbus (%s:%d) " fmt ".\n", __FUNCTION__, __LINE__, ##args)
     3.5  #endif
     3.6  
     3.7 -struct backend_info
     3.8 -{
     3.9 +struct backend_info {
    3.10  	struct xenbus_device *dev;
    3.11  	netif_t *netif;
    3.12 -	struct xenbus_watch backend_watch;
    3.13  	enum xenbus_state frontend_state;
    3.14  };
    3.15  
    3.16  static int connect_rings(struct backend_info *);
    3.17  static void connect(struct backend_info *);
    3.18 -static void maybe_connect(struct backend_info *);
    3.19 -static void backend_changed(struct xenbus_watch *, const char **,
    3.20 -			    unsigned int);
    3.21 +static void backend_create_netif(struct backend_info *be);
    3.22  
    3.23  static int netback_remove(struct xenbus_device *dev)
    3.24  {
    3.25  	struct backend_info *be = dev->dev.driver_data;
    3.26  
    3.27 -	if (be->backend_watch.node) {
    3.28 -		unregister_xenbus_watch(&be->backend_watch);
    3.29 -		kfree(be->backend_watch.node);
    3.30 -		be->backend_watch.node = NULL;
    3.31 -	}
    3.32  	if (be->netif) {
    3.33  		netif_disconnect(be->netif);
    3.34  		be->netif = NULL;
    3.35 @@ -63,8 +54,7 @@ static int netback_remove(struct xenbus_
    3.36  
    3.37  /**
    3.38   * Entry point to this code when a new device is created.  Allocate the basic
    3.39 - * structures, and watch the store waiting for the hotplug scripts to tell us
    3.40 - * the device's handle.  Switch to InitWait.
    3.41 + * structures and switch to InitWait.
    3.42   */
    3.43  static int netback_probe(struct xenbus_device *dev,
    3.44  			 const struct xenbus_device_id *id)
    3.45 @@ -83,11 +73,6 @@ static int netback_probe(struct xenbus_d
    3.46  	be->dev = dev;
    3.47  	dev->dev.driver_data = be;
    3.48  
    3.49 -	err = xenbus_watch_path2(dev, dev->nodename, "handle",
    3.50 -				 &be->backend_watch, backend_changed);
    3.51 -	if (err)
    3.52 -		goto fail;
    3.53 -
    3.54  	do {
    3.55  		err = xenbus_transaction_start(&xbt);
    3.56  		if (err) {
    3.57 @@ -108,7 +93,8 @@ static int netback_probe(struct xenbus_d
    3.58  			goto abort_transaction;
    3.59  		}
    3.60  
    3.61 -		err = xenbus_printf(xbt, dev->nodename, "feature-rx-copy", "%d", 1);
    3.62 +		err = xenbus_printf(xbt, dev->nodename,
    3.63 +				    "feature-rx-copy", "%d", 1);
    3.64  		if (err) {
    3.65  			message = "writing feature-copying";
    3.66  			goto abort_transaction;
    3.67 @@ -123,9 +109,11 @@ static int netback_probe(struct xenbus_d
    3.68  	}
    3.69  
    3.70  	err = xenbus_switch_state(dev, XenbusStateInitWait);
    3.71 -	if (err) {
    3.72 +	if (err)
    3.73  		goto fail;
    3.74 -	}
    3.75 +
    3.76 +	/* This kicks hotplug scripts, so do it immediately. */
    3.77 +	backend_create_netif(be);
    3.78  
    3.79  	return 0;
    3.80  
    3.81 @@ -175,48 +163,30 @@ static int netback_uevent(struct xenbus_
    3.82  }
    3.83  
    3.84  
    3.85 -/**
    3.86 - * Callback received when the hotplug scripts have placed the handle node.
    3.87 - * Read it, and create a netif structure.  If the frontend is ready, connect.
    3.88 - */
    3.89 -static void backend_changed(struct xenbus_watch *watch,
    3.90 -			    const char **vec, unsigned int len)
    3.91 +static void backend_create_netif(struct backend_info *be)
    3.92  {
    3.93  	int err;
    3.94  	long handle;
    3.95 -	struct backend_info *be
    3.96 -		= container_of(watch, struct backend_info, backend_watch);
    3.97  	struct xenbus_device *dev = be->dev;
    3.98  
    3.99 -	DPRINTK("");
   3.100 +	if (be->netif != NULL)
   3.101 +		return;
   3.102  
   3.103  	err = xenbus_scanf(XBT_NIL, dev->nodename, "handle", "%li", &handle);
   3.104 -	if (XENBUS_EXIST_ERR(err)) {
   3.105 -		/* Since this watch will fire once immediately after it is
   3.106 -		   registered, we expect this.  Ignore it, and wait for the
   3.107 -		   hotplug scripts. */
   3.108 -		return;
   3.109 -	}
   3.110  	if (err != 1) {
   3.111  		xenbus_dev_fatal(dev, err, "reading handle");
   3.112  		return;
   3.113  	}
   3.114  
   3.115 -	if (be->netif == NULL) {
   3.116 -		u8 be_mac[ETH_ALEN] = { 0, 0, 0, 0, 0, 0 };
   3.117 +	be->netif = netif_alloc(dev->otherend_id, handle);
   3.118 +	if (IS_ERR(be->netif)) {
   3.119 +		err = PTR_ERR(be->netif);
   3.120 +		be->netif = NULL;
   3.121 +		xenbus_dev_fatal(dev, err, "creating interface");
   3.122 +		return;
   3.123 +	}
   3.124  
   3.125 -		be->netif = netif_alloc(dev->otherend_id, handle, be_mac);
   3.126 -		if (IS_ERR(be->netif)) {
   3.127 -			err = PTR_ERR(be->netif);
   3.128 -			be->netif = NULL;
   3.129 -			xenbus_dev_fatal(dev, err, "creating interface");
   3.130 -			return;
   3.131 -		}
   3.132 -
   3.133 -		kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE);
   3.134 -
   3.135 -		maybe_connect(be);
   3.136 -	}
   3.137 +	kobject_uevent(&dev->dev.kobj, KOBJ_ONLINE);
   3.138  }
   3.139  
   3.140  
   3.141 @@ -249,11 +219,9 @@ static void frontend_changed(struct xenb
   3.142  		break;
   3.143  
   3.144  	case XenbusStateConnected:
   3.145 -		if (!be->netif) {
   3.146 -			/* reconnect: setup be->netif */
   3.147 -			backend_changed(&be->backend_watch, NULL, 0);
   3.148 -		}
   3.149 -		maybe_connect(be);
   3.150 +		backend_create_netif(be);
   3.151 +		if (be->netif)
   3.152 +			connect(be);
   3.153  		break;
   3.154  
   3.155  	case XenbusStateClosing:
   3.156 @@ -279,15 +247,6 @@ static void frontend_changed(struct xenb
   3.157  }
   3.158  
   3.159  
   3.160 -/* ** Connection ** */
   3.161 -
   3.162 -
   3.163 -static void maybe_connect(struct backend_info *be)
   3.164 -{
   3.165 -	if (be->netif && (be->frontend_state == XenbusStateConnected))
   3.166 -		connect(be);
   3.167 -}
   3.168 -
   3.169  static void xen_net_read_rate(struct xenbus_device *dev,
   3.170  			      unsigned long *bytes, unsigned long *usec)
   3.171  {