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-changelog

[Xen-changelog] [xen-unstable] libxl/xl: Use libxl_device_nic_destroy an

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 26 Aug 2010 03:30:47 -0700
Delivery-date: Thu, 26 Aug 2010 03:33:47 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1282228348 -3600
# Node ID 4c9ef5ec91461d10878321c40e47b60dde97cdaf
# Parent  597da2edfe301d1f46a0f093fbc4f017045b984d
libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy

Replaces libxl_free_nics_list

[PATCH 14 of 16 of
 libxl: autogenerate type definitions and destructor functions]

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/libxl.c       |   11 ----------
 tools/libxl/libxl.h       |    1 
 tools/libxl/libxl_utils.c |   47 +++++++++++++++++++++++-----------------------
 tools/libxl/xl_cmdimpl.c  |   23 ++++++++++++----------
 4 files changed, 37 insertions(+), 45 deletions(-)

diff -r 597da2edfe30 -r 4c9ef5ec9146 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Thu Aug 19 15:31:46 2010 +0100
+++ b/tools/libxl/libxl.c       Thu Aug 19 15:32:28 2010 +0100
@@ -2045,17 +2045,6 @@ int libxl_device_nic_del(libxl_ctx *ctx,
     device.kind             = DEVICE_VIF;
 
     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)
diff -r 597da2edfe30 -r 4c9ef5ec9146 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Thu Aug 19 15:31:46 2010 +0100
+++ b/tools/libxl/libxl.h       Thu Aug 19 15:32:28 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 597da2edfe30 -r 4c9ef5ec9146 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Thu Aug 19 15:31:46 2010 +0100
+++ b/tools/libxl/libxl_utils.c Thu Aug 19 15:32:28 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;
-        }
-    }
-
-    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;
+        }
+    }
+
+    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 597da2edfe30 -r 4c9ef5ec9146 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c  Thu Aug 19 15:31:46 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c  Thu Aug 19 15:32:28 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))) {
+        if (!(nics = libxl_list_nics(&ctx, domid, &nb))) {
             continue;
         }
-        for (i = 0; i < nb; ++i, ++nics) {
+        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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy, Xen patchbot-unstable <=