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

[Xen-devel] [PATCH 22 of 26] libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1281969065 -3600
# Node ID 3b72249bb27c9bd73cf40a09d42ae8f8d663a8f5
# Parent  b37efbc62265ee7e0967ae856bfff9e9953f62f4
libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy

Replaces libxl_free_nics_list

diff -r b37efbc62265 -r 3b72249bb27c tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxl.c       Mon Aug 16 15:31:05 2010 +0100
@@ -2063,17 +2063,6 @@ int libxl_device_nic_del(libxl_ctx *ctx,
     return libxl_device_del(ctx, &device, wait);
 }
 
-void libxl_free_nics_list(libxl_nicinfo *nics, unsigned int nb)
-{
-    unsigned int i;
-    for(i = 0; i < nb; i++) {
-        free(nics[i].backend);
-        free(nics[i].frontend);
-        free(nics[i].script);
-    }
-    free(nics);
-}
-
 libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int 
*nb)
 {
     libxl_gc gc = LIBXL_INIT_GC(ctx);
diff -r b37efbc62265 -r 3b72249bb27c tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxl.h       Mon Aug 16 15:31:05 2010 +0100
@@ -373,7 +373,6 @@ int libxl_device_nic_add(libxl_ctx *ctx,
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic 
*nic);
 int libxl_device_nic_del(libxl_ctx *ctx, libxl_device_nic *nic, int wait);
 libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int 
*nb);
-void libxl_free_nics_list(libxl_nicinfo *nics, unsigned int nb);
 
 int libxl_device_console_add(libxl_ctx *ctx, uint32_t domid, 
libxl_device_console *console);
 
diff -r b37efbc62265 -r 3b72249bb27c tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/libxl_utils.c Mon Aug 16 15:31:05 2010 +0100
@@ -405,42 +405,44 @@ int libxl_mac_to_device_nic(libxl_ctx *c
 int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
                             const char *mac, libxl_device_nic *nic)
 {
-    libxl_nicinfo *nics, *list;
-    unsigned int nb, i, j;
+    libxl_nicinfo *nics;
+    unsigned int nb, i;
+    int found;
     uint8_t mac_n[6];
     uint8_t *a, *b;
     const char *tok;
     char *endptr;
 
-    list = nics = libxl_list_nics(ctx, domid, &nb);
-    if (!nics) {
+    nics = libxl_list_nics(ctx, domid, &nb);
+    if (!nics)
         return ERROR_FAIL;
-    }
 
     for (i = 0, tok = mac; *tok && (i < 6); ++i, tok += 3) {
         mac_n[i] = strtol(tok, &endptr, 16);
-        if (endptr != (tok + 2)) {
+        if (endptr != (tok + 2))
             return ERROR_INVAL;
-        }
     }
     memset(nic, 0, sizeof (libxl_device_nic));
-    for (j = 0; j < nb; ++j, ++nics) {
-        for (i = 0, a = nics->mac, b = mac_n;
+    found = 0;
+    for (i = 0; i < nb; ++i) {
+        for (i = 0, a = nics[i].mac, b = mac_n;
              (b < mac_n + 6) && (*a == *b); ++a, ++b)
             ;
         if ((b >= mac_n + 6) && (*a == *b)) {
-            nic->backend_domid = nics->backend_id;
-            nic->domid = nics->frontend_id;
-            nic->devid = nics->devid;
-            memcpy(nic->mac, nics->mac, sizeof (nic->mac));
-            nic->script = nics->script;
-            libxl_free_nics_list(list, nb);
-            return 0;
+            nic->backend_domid = nics[i].backend_id;
+            nic->domid = nics[i].frontend_id;
+            nic->devid = nics[i].devid;
+            memcpy(nic->mac, nics[i].mac, sizeof (nic->mac));
+            nic->script = strdup(nics[i].script);
+            found = 1;
+            break;
         }
     }
 
-    libxl_free_nics_list(list, nb);
-    return 0;
+    for (i=0; i<nb; i++)
+        libxl_nicinfo_destroy(&nics[i]);
+    free(nics);
+    return found;
 }
 
 int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid,
@@ -472,8 +474,7 @@ int libxl_devid_to_device_nic(libxl_ctx 
          ++i, tok = strtok(NULL, ":")) {
         nic->mac[i] = strtoul(tok, NULL, 16);
     }
-    nic->script = libxl_xs_read(&gc, XBT_NULL,
-                                libxl_sprintf(&gc, "%s/script", nic_path_be));
+    nic->script = xs_read(ctx->xsh, XBT_NULL, libxl_sprintf(&gc, "%s/script", 
nic_path_be), NULL);
     rc = 0;
 out:
     libxl_free_all(&gc);
diff -r b37efbc62265 -r 3b72249bb27c tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Mon Aug 16 15:31:05 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Mon Aug 16 15:31:05 2010 +0100
@@ -4089,13 +4089,14 @@ int main_networkattach(int argc, char **
         fprintf(stderr, "libxl_device_nic_add failed.\n");
         return 1;
     }
+    libxl_device_nic_destroy(&nic);
     return 0;
 }
 
 int main_networklist(int argc, char **argv)
 {
     int opt;
-    libxl_nicinfo *nics, *list;
+    libxl_nicinfo *nics;
     unsigned int nb, i;
 
     if (argc < 3) {
@@ -4121,22 +4122,23 @@ int main_networklist(int argc, char **ar
             fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
             continue;
         }
-        if (!(list = nics = libxl_list_nics(&ctx, domid, &nb))) {
-            continue;
-        }
-        for (i = 0; i < nb; ++i, ++nics) {
+        if (!(nics = libxl_list_nics(&ctx, domid, &nb))) {
+            continue;
+        }
+        for (i = 0; i < nb; ++i) {
             /* Idx BE */
-            printf("%-3d %-2d ", nics->devid, nics->backend_id);
+            printf("%-3d %-2d ", nics[i].devid, nics[i].backend_id);
             /* MAC */
             printf("%02x:%02x:%02x:%02x:%02x:%02x ",
-                   nics->mac[0], nics->mac[1], nics->mac[2],
-                   nics->mac[3], nics->mac[4], nics->mac[5]);
+                   nics[i].mac[0], nics[i].mac[1], nics[i].mac[2],
+                   nics[i].mac[3], nics[i].mac[4], nics[i].mac[5]);
             /* Hdl  Sta  evch txr/rxr  BE-path */
             printf("%6d %5d %6d %5d/%-11d %-30s\n",
-                   nics->devid, nics->state, nics->evtch,
-                   nics->rref_tx, nics->rref_rx, nics->backend);
-        }
-        libxl_free_nics_list(list, nb);
+                   nics[i].devid, nics[i].state, nics[i].evtch,
+                   nics[i].rref_tx, nics[i].rref_rx, nics[i].backend);
+            libxl_nicinfo_destroy(&nics[i]);
+        }
+        free(nics);
     }
     return 0;
 }
@@ -4181,6 +4183,7 @@ int main_networkdetach(int argc, char **
         fprintf(stderr, "libxl_device_nic_del failed.\n");
         return 1;
     }
+    libxl_device_nic_destroy(&nic);
     return 0;
 }
 

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


 


Rackspace

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