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 14 of 16] libxl/xl: Use libxl_device_nic_destroy and

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 14 of 16] libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Wed, 18 Aug 2010 16:44:37 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Wed, 18 Aug 2010 09:07:31 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1282146263@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>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1282143678 -3600
# Node ID 9dfdd32ce1282c4f9ca38e8735dd2cea97d39b19
# Parent  96473378234f500d368fa5afe8230d608272b852
libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy

Replaces libxl_free_nics_list

diff -r 96473378234f -r 9dfdd32ce128 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Wed Aug 18 16:01:18 2010 +0100
+++ b/tools/libxl/libxl.c       Wed Aug 18 16:01:18 2010 +0100
@@ -2039,17 +2039,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 96473378234f -r 9dfdd32ce128 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed Aug 18 16:01:18 2010 +0100
+++ b/tools/libxl/libxl.h       Wed Aug 18 16:01:18 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 96473378234f -r 9dfdd32ce128 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Wed Aug 18 16:01:18 2010 +0100
+++ b/tools/libxl/libxl_utils.c Wed Aug 18 16:01:18 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 96473378234f -r 9dfdd32ce128 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Wed Aug 18 16:01:18 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Wed Aug 18 16:01:18 2010 +0100
@@ -4091,13 +4091,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) {
@@ -4123,22 +4124,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;
 }
@@ -4183,6 +4185,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