ia64/xen-unstable

changeset 6603:edd1616cf8cb

Restore configurability of vif bring up script and passing arguments to the script.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Fri Sep 02 14:15:49 2005 +0000 (2005-09-02)
parents af78c9d526e0
children 291e816acbf4
files linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c linux-2.6-xen-sparse/include/asm-xen/xenbus.h tools/examples/xen-backend.agent tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Thu Sep 01 10:45:50 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Fri Sep 02 14:15:49 2005 +0000
     1.3 @@ -160,11 +160,49 @@ static void backend_changed(struct xenbu
     1.4  		}
     1.5  #endif
     1.6  
     1.7 +		kobject_hotplug(&dev->dev.kobj, KOBJ_ONLINE);
     1.8 +
     1.9  		/* Pass in NULL node to skip exist test. */
    1.10  		frontend_changed(&be->watch, NULL);
    1.11  	}
    1.12  }
    1.13  
    1.14 +static int netback_hotplug(struct xenbus_device *xdev, char **envp,
    1.15 +			   int num_envp, char *buffer, int buffer_size)
    1.16 +{
    1.17 +	struct backend_info *be;
    1.18 +	netif_t *netif;
    1.19 +	char **key, *val;
    1.20 +	int i = 0, length = 0;
    1.21 +	static char *env_vars[] = { "script", "domain", "mac", "bridge", "ip",
    1.22 +				    NULL };
    1.23 +
    1.24 +	be = xdev->data;
    1.25 +	netif = be->netif;
    1.26 +
    1.27 +	add_hotplug_env_var(envp, num_envp, &i,
    1.28 +			    buffer, buffer_size, &length,
    1.29 +			    "vif=%s", netif->dev->name);
    1.30 +
    1.31 +	key = env_vars;
    1.32 +	while (*key != NULL) {
    1.33 +		val = xenbus_read(xdev->nodename, *key, NULL);
    1.34 +		if (!IS_ERR(val)) {
    1.35 +			char buf[strlen(*key) + 4];
    1.36 +			sprintf(buf, "%s=%%s", *key);
    1.37 +			add_hotplug_env_var(envp, num_envp, &i,
    1.38 +					    buffer, buffer_size, &length,
    1.39 +					    buf, val);
    1.40 +			kfree(val);
    1.41 +		}
    1.42 +		key++;
    1.43 +	}
    1.44 +
    1.45 +	envp[i] = NULL;
    1.46 +
    1.47 +	return 0;
    1.48 +}
    1.49 +
    1.50  static int netback_probe(struct xenbus_device *dev,
    1.51  			 const struct xenbus_device_id *id)
    1.52  {
    1.53 @@ -249,6 +287,7 @@ static struct xenbus_driver netback = {
    1.54  	.ids = netback_ids,
    1.55  	.probe = netback_probe,
    1.56  	.remove = netback_remove,
    1.57 +	.hotplug = netback_hotplug,
    1.58  };
    1.59  
    1.60  void netif_xenbus_init(void)
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Thu Sep 01 10:45:50 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c	Fri Sep 02 14:15:49 2005 +0000
     2.3 @@ -147,6 +147,39 @@ static int backend_bus_id(char bus_id[BU
     2.4  	return 0;
     2.5  }
     2.6  
     2.7 +static int xenbus_hotplug_backend(struct device *dev, char **envp,
     2.8 +				  int num_envp, char *buffer, int buffer_size)
     2.9 +{
    2.10 +	struct xenbus_device *xdev;
    2.11 +	int i = 0;
    2.12 +	int length = 0;
    2.13 +
    2.14 +	if (dev == NULL)
    2.15 +		return -ENODEV;
    2.16 +
    2.17 +	xdev = to_xenbus_device(dev);
    2.18 +	if (xdev == NULL)
    2.19 +		return -ENODEV;
    2.20 +
    2.21 +	/* stuff we want to pass to /sbin/hotplug */
    2.22 +	add_hotplug_env_var(envp, num_envp, &i,
    2.23 +			    buffer, buffer_size, &length,
    2.24 +			    "XENBUS_TYPE=%s", xdev->devicetype);
    2.25 +
    2.26 +	/* terminate, set to next free slot, shrink available space */
    2.27 +	envp[i] = NULL;
    2.28 +	envp = &envp[i];
    2.29 +	num_envp -= i;
    2.30 +	buffer = &buffer[length];
    2.31 +	buffer_size -= length;
    2.32 +
    2.33 +	if (dev->driver && to_xenbus_driver(dev->driver)->hotplug)
    2.34 +		return to_xenbus_driver(dev->driver)->hotplug
    2.35 +			(xdev, envp, num_envp, buffer, buffer_size);
    2.36 +
    2.37 +	return 0;
    2.38 +}
    2.39 +
    2.40  static int xenbus_probe_backend(const char *type, const char *uuid);
    2.41  static struct xen_bus_type xenbus_backend = {
    2.42  	.root = "backend",
    2.43 @@ -156,6 +189,7 @@ static struct xen_bus_type xenbus_backen
    2.44  	.bus = {
    2.45  		.name  = "xen-backend",
    2.46  		.match = xenbus_match,
    2.47 +		.hotplug = xenbus_hotplug_backend,
    2.48  	},
    2.49  	.dev = {
    2.50  		.bus_id = "xen-backend",
     3.1 --- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h	Thu Sep 01 10:45:50 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h	Fri Sep 02 14:15:49 2005 +0000
     3.3 @@ -64,6 +64,7 @@ struct xenbus_driver {
     3.4  	int (*remove)(struct xenbus_device *dev);
     3.5  	int (*suspend)(struct xenbus_device *dev);
     3.6  	int (*resume)(struct xenbus_device *dev);
     3.7 +	int (*hotplug)(struct xenbus_device *, char **, int, char *, int);
     3.8  	struct device_driver driver;
     3.9  };
    3.10  
     4.1 --- a/tools/examples/xen-backend.agent	Thu Sep 01 10:45:50 2005 +0000
     4.2 +++ b/tools/examples/xen-backend.agent	Fri Sep 02 14:15:49 2005 +0000
     4.3 @@ -1,21 +1,25 @@
     4.4  #! /bin/sh
     4.5  
     4.6 +#ACTION=add
     4.7  #DEVPATH=/devices/xen-backend/vif-1-0
     4.8 -#ACTION=add
     4.9 +#PHYSDEVDRIVER=vif
    4.10 +#XENBUS_TYPE=vif
    4.11  
    4.12  PATH=/etc/xen/scripts:$PATH
    4.13  
    4.14 -DEV=$(basename "$DEVPATH")
    4.15  case "$ACTION" in
    4.16    add)
    4.17 -    case "$DEV" in
    4.18 -      vif-*)
    4.19 -        vif=$(echo "$DEV" | sed 's/-\([0-9]*\)-\([0-9]*\)/\1.\2/')
    4.20 -        vif-bridge up domain=unknown vif="$vif" mac=fe:ff:ff:ff:ff:ff bridge=xen-br0 >/dev/null 2>&1
    4.21 +    ;;
    4.22 +  remove)
    4.23 +    ;;
    4.24 +  online)
    4.25 +    case "$PHYSDEVDRIVER" in
    4.26 +      vif)
    4.27 +        [ -n "$script" ] && $script up
    4.28          ;;
    4.29      esac
    4.30      ;;
    4.31 -  remove)
    4.32 +  offline)
    4.33      ;;
    4.34  esac
    4.35  
     5.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Sep 01 10:45:50 2005 +0000
     5.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Fri Sep 02 14:15:49 2005 +0000
     5.3 @@ -430,6 +430,15 @@ class XendDomainInfo:
     5.4              return
     5.5  
     5.6          if type == 'vif':
     5.7 +            from xen.xend import XendRoot
     5.8 +            xroot = XendRoot.instance()
     5.9 +
    5.10 +            def _get_config_ipaddr(config):
    5.11 +                val = []
    5.12 +                for ipaddr in sxp.children(config, elt='ip'):
    5.13 +                    val.append(sxp.child0(ipaddr))
    5.14 +                return val
    5.15 +
    5.16              backdom = domain_exists(sxp.child_value(devconfig, 'backend', '0'))
    5.17  
    5.18              log.error(devconfig)
    5.19 @@ -437,6 +446,14 @@ class XendDomainInfo:
    5.20              devnum = self.netif_idx
    5.21              self.netif_idx += 1
    5.22  
    5.23 +            script = sxp.child_value(devconfig, 'script',
    5.24 +                                     xroot.get_vif_script())
    5.25 +            script = os.path.join(xroot.network_script_dir, script)
    5.26 +            bridge = sxp.child_value(devconfig, 'bridge',
    5.27 +                                     xroot.get_vif_bridge())
    5.28 +            mac = sxp.child_value(devconfig, 'mac')
    5.29 +            ipaddr = _get_config_ipaddr(devconfig)
    5.30 +
    5.31              # create backend db
    5.32              backdb = backdom.db.addChild("/backend/%s/%s/%d" %
    5.33                                           (type, self.uuid, devnum))
    5.34 @@ -444,6 +461,12 @@ class XendDomainInfo:
    5.35              # create frontend db
    5.36              db = self.db.addChild("/device/%s/%d" % (type, devnum))
    5.37              
    5.38 +            backdb['script'] = script
    5.39 +            backdb['domain'] = self.name
    5.40 +            backdb['mac'] = mac
    5.41 +            backdb['bridge'] = bridge
    5.42 +            if ipaddr:
    5.43 +                backdb['ip'] = ' '.join(ipaddr)
    5.44              backdb['frontend'] = db.getPath()
    5.45              backdb['frontend-id'] = "%i" % self.id
    5.46              backdb['handle'] = "%i" % devnum
    5.47 @@ -452,8 +475,7 @@ class XendDomainInfo:
    5.48              db['backend'] = backdb.getPath()
    5.49              db['backend-id'] = "%i" % backdom.id
    5.50              db['handle'] = "%i" % devnum
    5.51 -            log.error(sxp.child_value(devconfig, 'mac'))
    5.52 -            db['mac'] = sxp.child_value(devconfig, 'mac')
    5.53 +            db['mac'] = mac
    5.54  
    5.55              db.saveDB(save=True)
    5.56