WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 18 of 23] libxl: convert NIC handling to device API

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 18 of 23] libxl: convert NIC handling to device API
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Fri, 30 Sep 2011 14:33:31 +0100
Cc: Jim Fehlig <jfehlig@xxxxxxxxxx>, Mike McClurg <mike.mcclurg@xxxxxxxxxx>, Dave Scott <Dave.Scott@xxxxxxxxxxxxx>, Jonathan Ludlam <Jonathan.Ludlam@xxxxxxxxxxxxx>
Delivery-date: Fri, 30 Sep 2011 06:53:40 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1317389593@xxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1317389593@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1317389248 -3600
# Node ID 9b58180714357f9879f7ff88a267e7d1f5dfdbb2
# Parent  1892dad72518f5253af2282db650cdd70c56a218
libxl: convert NIC handling to device API

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 1892dad72518 -r 9b5818071435 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.c       Fri Sep 30 14:27:28 2011 +0100
@@ -1184,32 +1184,46 @@ int libxl_device_disk_local_detach(libxl
 }
 
 
/******************************************************************************/
-int libxl_device_nic_init(libxl_device_nic *nic_info, int devnum)
+int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic)
 {
     const uint8_t *r;
     libxl_uuid uuid;
 
     libxl_uuid_generate(&uuid);
     r = libxl_uuid_bytearray(&uuid);
-    memset(nic_info, '\0', sizeof(*nic_info));
-
-    nic_info->backend_domid = 0;
-    nic_info->devid = devnum;
-    nic_info->mtu = 1492;
-    nic_info->model = strdup("rtl8139");
-    nic_info->mac[0] = 0x00;
-    nic_info->mac[1] = 0x16;
-    nic_info->mac[2] = 0x3e;
-    nic_info->mac[3] = r[0] & 0x7f;
-    nic_info->mac[4] = r[1];
-    nic_info->mac[5] = r[2];
-    nic_info->ifname = NULL;
-    nic_info->bridge = strdup("xenbr0");
-    nic_info->ip = NULL;
-    if ( asprintf(&nic_info->script, "%s/vif-bridge",
+    memset(nic, '\0', sizeof(*nic));
+
+    nic->backend_domid = 0;
+    nic->devid = -1;
+    nic->mtu = 1492;
+    nic->model = strdup("rtl8139");
+    nic->mac[0] = 0x00;
+    nic->mac[1] = 0x16;
+    nic->mac[2] = 0x3e;
+    nic->mac[3] = r[0] & 0x7f;
+    nic->mac[4] = r[1];
+    nic->mac[5] = r[2];
+    nic->ifname = NULL;
+    nic->bridge = strdup("xenbr0");
+    nic->ip = NULL;
+    if ( asprintf(&nic->script, "%s/vif-bridge",
                libxl_xen_script_dir_path()) < 0 )
         return ERROR_FAIL;
-    nic_info->nictype = LIBXL_NIC_TYPE_IOEMU;
+    nic->nictype = LIBXL_NIC_TYPE_IOEMU;
+    return 0;
+}
+
+static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
+                                  libxl_device_nic *nic,
+                                  libxl__device *device)
+{
+    device->backend_devid    = nic->devid;
+    device->backend_domid    = nic->backend_domid;
+    device->backend_kind     = LIBXL__DEVICE_KIND_VIF;
+    device->devid            = nic->devid;
+    device->domid            = domid;
+    device->kind             = LIBXL__DEVICE_KIND_VIF;
+
     return 0;
 }
 
@@ -1246,12 +1260,8 @@ int libxl_device_nic_add(libxl_ctx *ctx,
         }
     }
 
-    device.backend_devid = nic->devid;
-    device.backend_domid = nic->backend_domid;
-    device.backend_kind = LIBXL__DEVICE_KIND_VIF;
-    device.devid = nic->devid;
-    device.domid = domid;
-    device.kind = LIBXL__DEVICE_KIND_VIF;
+    rc = libxl__device_from_nic(&gc, domid, nic, &device);
+    if ( rc != 0 ) goto out_free;
 
     flexarray_append(back, "frontend-id");
     flexarray_append(back, libxl__sprintf(&gc, "%d", domid));
@@ -1302,29 +1312,37 @@ out:
     return rc;
 }
 
-int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid,
-                         libxl_device_nic *nic, int wait)
+int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
+                            libxl_device_nic *nic)
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     libxl__device device;
     int rc;
 
-    device.backend_devid    = nic->devid;
-    device.backend_domid    = nic->backend_domid;
-    device.backend_kind     = LIBXL__DEVICE_KIND_VIF;
-    device.devid            = nic->devid;
-    device.domid            = domid;
-    device.kind             = LIBXL__DEVICE_KIND_VIF;
-
-    if (wait)
-        rc = libxl__device_remove(&gc, &device, wait);
-    else
-        rc = libxl__device_force_remove(&gc, &device);
-
+    rc = libxl__device_from_nic(&gc, domid, nic, &device);
+    if (rc != 0) goto out;
+
+    rc = libxl__device_remove(&gc, &device, 1);
+out:
     libxl__free_all(&gc);
     return rc;
 }
 
+int libxl_device_nic_force_remove(libxl_ctx *ctx, uint32_t domid,
+                                  libxl_device_nic *nic)
+{
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+    libxl__device device;
+    int rc;
+
+    rc = libxl__device_from_nic(&gc, domid, nic, &device);
+    if (rc != 0) goto out;
+
+    rc = libxl__device_force_remove(&gc, &device);
+out:
+    libxl__free_all(&gc);
+    return rc;
+}
 static void libxl__device_nic_from_xs_be(libxl__gc *gc,
                                          const char *be_path,
                                          libxl_device_nic *nic)
diff -r 1892dad72518 -r 9b5818071435 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/libxl.h       Fri Sep 30 14:27:28 2011 +0100
@@ -476,9 +476,12 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
 char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk);
 int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk);
 
-int libxl_device_nic_init(libxl_device_nic *nic, int dev_num);
+/* Network Interfaces */
+int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic);
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic 
*nic);
-int libxl_device_nic_del(libxl_ctx *ctx, uint32_t domid, libxl_device_nic 
*nic, int wait);
+int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_nic 
*nic);
+int libxl_device_nic_force_remove(libxl_ctx *ctx, uint32_t domid, 
libxl_device_nic *nic);
+
 libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int 
*num);
 int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
                               libxl_device_nic *nic, libxl_nicinfo *nicinfo);
diff -r 1892dad72518 -r 9b5818071435 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Fri Sep 30 14:27:28 2011 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Fri Sep 30 14:27:28 2011 +0100
@@ -822,7 +822,8 @@ static void parse_config_data(const char
 
             d_config->vifs = (libxl_device_nic *) realloc(d_config->vifs, 
sizeof (libxl_device_nic) * (d_config->num_vifs+1));
             nic = d_config->vifs + d_config->num_vifs;
-            CHK_ERRNO( libxl_device_nic_init(nic, d_config->num_vifs) );
+            CHK_ERRNO( libxl_device_nic_init(ctx, nic) );
+            nic->devid = d_config->num_vifs;
 
             if (default_vifscript) {
                 free(nic->script);
@@ -4032,7 +4033,7 @@ int main_networkattach(int argc, char **
         fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]);
         return 1;
     }
-    libxl_device_nic_init(&nic, -1);
+    libxl_device_nic_init(ctx, &nic);
     for (argv += optind+1, argc -= optind+1; argc > 0; ++argv, --argc) {
         if (MATCH_OPTION("type", *argv, oparg)) {
             if (!strcmp("vif", oparg)) {
@@ -4149,7 +4150,7 @@ int main_networkdetach(int argc, char **
             return 1;
         }
     }
-    if (libxl_device_nic_del(ctx, domid, &nic, 1)) {
+    if (libxl_device_nic_remove(ctx, domid, &nic)) {
         fprintf(stderr, "libxl_device_nic_del failed.\n");
         return 1;
     }

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>