ia64/xen-unstable

changeset 4180:b097821b390f

bitkeeper revision 1.1159.269.5 (42386371nvHctvk3SHgDUG4w3o9URw)

Add support for specifying the interface name to be used by a netif
backend driver instead of the default vifD.N.

Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Wed Mar 16 16:48:49 2005 +0000 (2005-03-16)
parents c07e188e4cea
children 700e62ea1297
files linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c tools/python/xen/lowlevel/xu/xu.c tools/python/xen/xend/server/netif.py tools/python/xen/xm/create.py xen/include/public/io/domain_controller.h
line diff
     1.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c	Tue Mar 15 11:58:01 2005 +0000
     1.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c	Wed Mar 16 16:48:49 2005 +0000
     1.3 @@ -119,9 +119,13 @@ void netif_create(netif_be_create_t *cre
     1.4      unsigned int       handle = create->netif_handle;
     1.5      struct net_device *dev;
     1.6      netif_t          **pnetif, *netif;
     1.7 -    char               name[IFNAMSIZ];
     1.8 +    char               name[IFNAMSIZ] = {};
     1.9  
    1.10 -    snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
    1.11 +    if(create->vifname[0] == '\0'){
    1.12 +        snprintf(name, IFNAMSIZ - 1, "vif%u.%u", domid, handle);
    1.13 +    } else {
    1.14 +        snprintf(name, IFNAMSIZ - 1, "%s", create->vifname);
    1.15 +    }
    1.16      dev = alloc_netdev(sizeof(netif_t), name, ether_setup);
    1.17      if ( dev == NULL )
    1.18      {
     2.1 --- a/tools/python/xen/lowlevel/xu/xu.c	Tue Mar 15 11:58:01 2005 +0000
     2.2 +++ b/tools/python/xen/lowlevel/xu/xu.c	Wed Mar 16 16:48:49 2005 +0000
     2.3 @@ -259,6 +259,7 @@ static PyTypeObject xu_notifier_type = {
     2.4   */
     2.5  
     2.6  #define TYPE(_x,_y) (((_x)<<8)|(_y))
     2.7 +
     2.8  #define P2C(_struct, _field, _ctype)                                      \
     2.9      do {                                                                  \
    2.10          PyObject *obj;                                                    \
    2.11 @@ -279,6 +280,29 @@ static PyTypeObject xu_notifier_type = {
    2.12          }                                                                 \
    2.13          xum->msg.length = sizeof(_struct);                                \
    2.14      } while ( 0 )
    2.15 +
    2.16 +/** Set a char[] field in a struct from a Python string.
    2.17 + * Can't do this in P2C because of the typing.
    2.18 + */
    2.19 +#define P2CSTRING(_struct, _field)                                        \
    2.20 +    do {                                                                  \
    2.21 +        PyObject *obj;                                                    \
    2.22 +        if ( (obj = PyDict_GetItemString(payload, #_field)) != NULL )     \
    2.23 +        {                                                                 \
    2.24 +            if ( PyString_Check(obj) )                                    \
    2.25 +            {                                                             \
    2.26 +                _struct * _cobj = (_struct *)&xum->msg.msg[0];            \
    2.27 +                int _field_n = sizeof(_cobj->_field);                     \
    2.28 +                memset(_cobj->_field, 0, _field_n);                       \
    2.29 +                strncpy(_cobj->_field,                                    \
    2.30 +                        PyString_AsString(obj),                           \
    2.31 +                        _field_n - 1);                                    \
    2.32 +                dict_items_parsed++;                                      \
    2.33 +            }                                                             \
    2.34 +        }                                                                 \
    2.35 +        xum->msg.length = sizeof(_struct);                                \
    2.36 +    } while ( 0 )
    2.37 +
    2.38  #define C2P(_struct, _field, _pytype, _ctype)                             \
    2.39      do {                                                                  \
    2.40          PyObject *obj = Py ## _pytype ## _From ## _ctype                  \
    2.41 @@ -456,6 +480,7 @@ static PyObject *xu_message_get_payload(
    2.42          C2P(netif_be_create_t, domid,        Int, Long);
    2.43          C2P(netif_be_create_t, netif_handle, Int, Long);
    2.44          C2P(netif_be_create_t, status,       Int, Long);
    2.45 +        C2P(netif_be_create_t, vifname,      String, String);
    2.46          return dict;
    2.47      case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
    2.48          C2P(netif_be_destroy_t, domid,        Int, Long);
    2.49 @@ -623,6 +648,7 @@ static PyObject *xu_message_new(PyObject
    2.50          P2C(netif_be_create_t, mac[3],       u8);
    2.51          P2C(netif_be_create_t, mac[4],       u8);
    2.52          P2C(netif_be_create_t, mac[5],       u8);
    2.53 +        P2CSTRING(netif_be_create_t, vifname);
    2.54          break;
    2.55      case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_DESTROY):
    2.56          P2C(netif_be_destroy_t, domid,        u32);
     3.1 --- a/tools/python/xen/xend/server/netif.py	Tue Mar 15 11:58:01 2005 +0000
     3.2 +++ b/tools/python/xen/xend/server/netif.py	Wed Mar 16 16:48:49 2005 +0000
     3.3 @@ -130,7 +130,13 @@ class NetDev(controller.SplitDev):
     3.4          self.bridge = None
     3.5          self.script = None
     3.6          self.ipaddr = []
     3.7 +        self.vifname = None
     3.8  
     3.9 +        self.vifname = sxp.child_value(config, 'vifname')
    3.10 +        if self.vifname is None:
    3.11 +            self.vifname = "vif%d.%d" % (self.controller.dom, self.vif)
    3.12 +        if len(self.vifname) > 15:
    3.13 +            raise XendError('invalid vifname: too long: ' + self.vifname)
    3.14          mac = self._get_config_mac(config)
    3.15          if mac is None:
    3.16              raise XendError("invalid mac")
    3.17 @@ -189,7 +195,9 @@ class NetDev(controller.SplitDev):
    3.18          val = ['vif',
    3.19                 ['idx', self.idx],
    3.20                 ['vif', vif],
    3.21 -               ['mac', mac]]
    3.22 +               ['mac', mac],
    3.23 +               ['vifname', self.vifname],
    3.24 +               ]
    3.25          if self.bridge:
    3.26              val.append(['bridge', self.bridge])
    3.27          if self.script:
    3.28 @@ -207,7 +215,7 @@ class NetDev(controller.SplitDev):
    3.29      def get_vifname(self):
    3.30          """Get the virtual interface device name.
    3.31          """
    3.32 -        return "vif%d.%d" % (self.controller.dom, self.vif)
    3.33 +        return self.vifname
    3.34  
    3.35      def get_mac(self):
    3.36          """Get the MAC address as a string.
    3.37 @@ -267,7 +275,9 @@ class NetDev(controller.SplitDev):
    3.38          msg = packMsg('netif_be_create_t',
    3.39                        { 'domid'        : self.controller.dom,
    3.40                          'netif_handle' : self.vif,
    3.41 -                        'mac'          : self.mac })
    3.42 +                        'mac'          : self.mac,
    3.43 +                        'vifname'      : self.vifname
    3.44 +                        })
    3.45          self.getBackendInterface().writeRequest(msg, response=d)
    3.46          return d
    3.47  
     4.1 --- a/tools/python/xen/xm/create.py	Tue Mar 15 11:58:01 2005 +0000
     4.2 +++ b/tools/python/xen/xm/create.py	Wed Mar 16 16:48:49 2005 +0000
     4.3 @@ -151,7 +151,7 @@ gopts.var('ipaddr', val="IPADDR",
     4.4            fn=append_value, default=[],
     4.5            use="Add an IP address to the domain.")
     4.6  
     4.7 -gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM",
     4.8 +gopts.var('vif', val="mac=MAC,bridge=BRIDGE,script=SCRIPT,backend=DOM,vifname=NAME",
     4.9            fn=append_value, default=[],
    4.10            use="""Add a network interface with the given MAC address and bridge.
    4.11            The vif is configured by calling the given configuration script.
    4.12 @@ -159,6 +159,8 @@ gopts.var('vif', val="mac=MAC,bridge=BRI
    4.13            If bridge is not specified the default bridge is used.
    4.14            If script is not specified the default script is used.
    4.15            If backend is not specified the default backend driver domain is used.
    4.16 +          If vifname is not specified the backend virtual interface will have name vifD.N
    4.17 +          where D is the domain id and N is the interface id.
    4.18            This option may be repeated to add more than one vif.
    4.19            Specifying vifs will increase the number of interfaces as needed.""")
    4.20  
    4.21 @@ -289,14 +291,18 @@ def configure_vifs(config_devs, vals):
    4.22              script = d.get('script')
    4.23              backend = d.get('backend')
    4.24              ip = d.get('ip')
    4.25 +            vifname = d.get('vifname')
    4.26          else:
    4.27              mac = randomMAC()
    4.28              bridge = None
    4.29              script = None
    4.30              backend = None
    4.31              ip = None
    4.32 +            vifname = None
    4.33          config_vif = ['vif']
    4.34          config_vif.append(['mac', mac])
    4.35 +        if vifname:
    4.36 +            config_vif.append(['vifname', vifname])
    4.37          if bridge:
    4.38              config_vif.append(['bridge', bridge])
    4.39          if script:
    4.40 @@ -383,7 +389,7 @@ def preprocess_vifs(opts, vals):
    4.41              (k, v) = b.strip().split('=', 1)
    4.42              k = k.strip()
    4.43              v = v.strip()
    4.44 -            if k not in ['mac', 'bridge', 'script', 'backend', 'ip']:
    4.45 +            if k not in ['mac', 'bridge', 'script', 'backend', 'ip', 'vifname']:
    4.46                  opts.err('Invalid vif specifier: ' + vif)
    4.47              d[k] = v
    4.48          vifs.append(d)
     5.1 --- a/xen/include/public/io/domain_controller.h	Tue Mar 15 11:58:01 2005 +0000
     5.2 +++ b/xen/include/public/io/domain_controller.h	Wed Mar 16 16:48:49 2005 +0000
     5.3 @@ -477,9 +477,10 @@ typedef struct {
     5.4      u32        netif_handle;  /*  4: Domain-specific interface handle.   */
     5.5      u8         mac[6];        /*  8 */
     5.6      u16        __pad1;        /* 14 */
     5.7 +    char       vifname[16];   /* 16 */
     5.8      /* OUT */
     5.9 -    u32        status;        /* 16 */
    5.10 -} PACKED netif_be_create_t; /* 20 bytes */
    5.11 +    u32        status;        /* 32 */
    5.12 +} PACKED netif_be_create_t; /* 36 bytes */
    5.13  
    5.14  /*
    5.15   * CMSG_NETIF_BE_DESTROY: