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

[Xen-devel] [PATCH 12 of 26 V3] libxl: nic: use _init/_setdefault



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1330000276 0
# Node ID 001f5db5cdb8097051a1fb7b6f5c21a63cfd7872
# Parent  17abebd7ba97185f6dce327b6c29b3e380d55d20
libxl: nic: use _init/_setdefault

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

diff -r 17abebd7ba97 -r 001f5db5cdb8 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/libxl.c       Thu Feb 23 12:31:16 2012 +0000
@@ -1677,32 +1677,43 @@ int libxl_device_disk_local_detach(libxl
 }
 
 
/******************************************************************************/
-int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic)
+void libxl_device_nic_init(libxl_device_nic *nic)
 {
-    const uint8_t *r;
-    libxl_uuid uuid;
-
-    libxl_uuid_generate(&uuid);
-    r = libxl_uuid_bytearray(&uuid);
     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 )
+}
+
+int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic)
+{
+    if (!nic->mtu)
+        nic->mtu = 1492;
+    if (!nic->model) {
+        nic->model = strdup("rtl8139");
+        if (!nic->model) return ERROR_NOMEM;
+    }
+    if (!nic->mac[0] && !nic->mac[1] && !nic->mac[2] &&
+        !nic->mac[3] && !nic->mac[4] && !nic->mac[5]) {
+        const uint8_t *r;
+        libxl_uuid uuid;
+
+        libxl_uuid_generate(&uuid);
+        r = libxl_uuid_bytearray(&uuid);
+
+        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];
+    }
+    if (!nic->bridge) {
+        nic->bridge = strdup("xenbr0");
+        if (!nic->bridge) return ERROR_NOMEM;
+    }
+    if ( !nic->script && asprintf(&nic->script, "%s/vif-bridge",
+                                  libxl_xen_script_dir_path()) < 0 )
         return ERROR_FAIL;
-    nic->nictype = LIBXL_NIC_TYPE_IOEMU;
+    if (!nic->nictype)
+        nic->nictype = LIBXL_NIC_TYPE_IOEMU;
     return 0;
 }
 
@@ -1729,6 +1740,9 @@ int libxl_device_nic_add(libxl_ctx *ctx,
     char *dompath, **l;
     unsigned int nb, rc;
 
+    rc = libxl__device_nic_setdefault(gc, nic);
+    if (rc) goto out;
+
     front = flexarray_make(16, 1);
     if (!front) {
         rc = ERROR_NOMEM;
diff -r 17abebd7ba97 -r 001f5db5cdb8 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/libxl.h       Thu Feb 23 12:31:16 2012 +0000
@@ -524,7 +524,7 @@ char * libxl_device_disk_local_attach(li
 int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk);
 
 /* Network Interfaces */
-int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic);
+void libxl_device_nic_init(libxl_device_nic *nic);
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic 
*nic);
 int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
                             libxl_device_nic *nic,
diff -r 17abebd7ba97 -r 001f5db5cdb8 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/libxl_internal.h      Thu Feb 23 12:31:16 2012 +0000
@@ -193,6 +193,7 @@ _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);
 
 struct libxl__evgen_domain_death {
     uint32_t domid;
diff -r 17abebd7ba97 -r 001f5db5cdb8 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Thu Feb 23 12:31:16 2012 +0000
+++ b/tools/libxl/xl_cmdimpl.c  Thu Feb 23 12:31:16 2012 +0000
@@ -839,7 +839,7 @@ 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(ctx, nic) );
+            libxl_device_nic_init(nic);
             nic->devid = d_config->num_vifs;
 
             if (default_vifscript) {
@@ -4609,7 +4609,7 @@ int main_networkattach(int argc, char **
         fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]);
         return 1;
     }
-    libxl_device_nic_init(ctx, &nic);
+    libxl_device_nic_init(&nic);
     for (argv += optind+1, argc -= optind+1; argc > 0; ++argv, --argc) {
         if (MATCH_OPTION("type", *argv, oparg)) {
             if (!strcmp("vif", oparg)) {

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

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