[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] libxl: set correct nic type depending on the guest


  • To: xen-changelog@xxxxxxxxxxxxxxxxxxx
  • From: Xen patchbot-unstable <patchbot@xxxxxxx>
  • Date: Sat, 28 Jul 2012 03:00:20 +0000
  • Delivery-date: Sat, 28 Jul 2012 03:00:29 +0000
  • List-id: "Change log for Mercurial \(receive only\)" <xen-changelog.lists.xen.org>

# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxx>
# Date 1343317653 -3600
# Node ID 0d98248a77ce87ed0a0766a2c50d884bb2687790
# Parent  2e21281b2c10074256f4f964f28ec851baff4244
libxl: set correct nic type depending on the guest

Fix the use of nic type, which results in the following for each type
of domain:

 * HVM: let the user choose, if none specified use VIF_IOEMU.
 * PV: use VIF is none provided, return error if VIF_IOEMU requested.

Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxx>
Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Committed-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---


diff -r 2e21281b2c10 -r 0d98248a77ce tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Thu Jul 26 16:47:32 2012 +0100
+++ b/tools/libxl/libxl.c       Thu Jul 26 16:47:33 2012 +0100
@@ -2457,7 +2457,8 @@ out:
 
 
/******************************************************************************/
 
-int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic)
+int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic,
+                                 uint32_t domid)
 {
     if (!nic->mtu)
         nic->mtu = 1492;
@@ -2487,8 +2488,25 @@ int libxl__device_nic_setdefault(libxl__
     if ( !nic->script && asprintf(&nic->script, "%s/vif-bridge",
                                   libxl__xen_script_dir_path()) < 0 )
         return ERROR_FAIL;
-    if (!nic->nictype)
-        nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU;
+
+    switch (libxl__domain_type(gc, domid)) {
+    case LIBXL_DOMAIN_TYPE_HVM:
+        if (!nic->nictype)
+            nic->nictype = LIBXL_NIC_TYPE_VIF_IOEMU;
+        break;
+    case LIBXL_DOMAIN_TYPE_PV:
+        if (nic->nictype == LIBXL_NIC_TYPE_VIF_IOEMU) {
+            LOG(ERROR, "trying to create PV guest with an emulated interface");
+            return ERROR_INVAL;
+        }
+        nic->nictype = LIBXL_NIC_TYPE_VIF;
+        break;
+    case LIBXL_DOMAIN_TYPE_INVALID:
+        return ERROR_FAIL;
+    default:
+        abort();
+    }
+
     return 0;
 }
 
@@ -2516,7 +2534,7 @@ void libxl__device_nic_add(libxl__egc *e
     char *dompath, **l;
     unsigned int nb, rc;
 
-    rc = libxl__device_nic_setdefault(gc, nic);
+    rc = libxl__device_nic_setdefault(gc, nic, domid);
     if (rc) goto out;
 
     front = flexarray_make(16, 1);
diff -r 2e21281b2c10 -r 0d98248a77ce tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c        Thu Jul 26 16:47:32 2012 +0100
+++ b/tools/libxl/libxl_create.c        Thu Jul 26 16:47:33 2012 +0100
@@ -943,7 +943,9 @@ static void domcreate_launch_dm(libxl__e
          * called libxl_device_nic_add at this point, but qemu needs
          * the nic information to be complete.
          */
-        libxl__device_nic_setdefault(gc, &d_config->nics[i]);
+        ret = libxl__device_nic_setdefault(gc, &d_config->nics[i], domid);
+        if (ret)
+            goto error_out;
     }
     switch (d_config->c_info.type) {
     case LIBXL_DOMAIN_TYPE_HVM:
diff -r 2e21281b2c10 -r 0d98248a77ce tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c    Thu Jul 26 16:47:32 2012 +0100
+++ b/tools/libxl/libxl_dm.c    Thu Jul 26 16:47:33 2012 +0100
@@ -898,7 +898,9 @@ static void spawn_stub_launch_dm(libxl__
          * called libxl_device_nic_add at this point, but qemu needs
          * the nic information to be complete.
          */
-        libxl__device_nic_setdefault(gc, &dm_config->nics[i]);
+        ret = libxl__device_nic_setdefault(gc, &dm_config->nics[i], dm_domid);
+        if (ret)
+            goto out;
     }
     ret = libxl_device_vfb_add(ctx, dm_domid, &dm_config->vfbs[0]);
     if (ret)
diff -r 2e21281b2c10 -r 0d98248a77ce tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Thu Jul 26 16:47:32 2012 +0100
+++ b/tools/libxl/libxl_internal.h      Thu Jul 26 16:47:33 2012 +0100
@@ -938,7 +938,8 @@ _hidden int libxl__domain_build_info_set
                                         libxl_domain_build_info *b_info);
 _hidden int libxl__device_disk_setdefault(libxl__gc *gc,
                                           libxl_device_disk *disk);
-_hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic);
+_hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic,
+                                         uint32_t domid);
 _hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb);
 _hidden int libxl__device_vkb_setdefault(libxl__gc *gc, libxl_device_vkb *vkb);
 _hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci);

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.