debuggers.hg

changeset 22087:4c9ef5ec9146

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@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Thu Aug 19 15:32:28 2010 +0100 (2010-08-19)
parents 597da2edfe30
children 477abe597f6d
files tools/libxl/libxl.c tools/libxl/libxl.h tools/libxl/libxl_utils.c tools/libxl/xl_cmdimpl.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Thu Aug 19 15:31:46 2010 +0100
     1.2 +++ b/tools/libxl/libxl.c	Thu Aug 19 15:32:28 2010 +0100
     1.3 @@ -2047,17 +2047,6 @@ int libxl_device_nic_del(libxl_ctx *ctx,
     1.4      return libxl_device_del(ctx, &device, wait);
     1.5  }
     1.6  
     1.7 -void libxl_free_nics_list(libxl_nicinfo *nics, unsigned int nb)
     1.8 -{
     1.9 -    unsigned int i;
    1.10 -    for(i = 0; i < nb; i++) {
    1.11 -        free(nics[i].backend);
    1.12 -        free(nics[i].frontend);
    1.13 -        free(nics[i].script);
    1.14 -    }
    1.15 -    free(nics);
    1.16 -}
    1.17 -
    1.18  libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb)
    1.19  {
    1.20      libxl_gc gc = LIBXL_INIT_GC(ctx);
     2.1 --- a/tools/libxl/libxl.h	Thu Aug 19 15:31:46 2010 +0100
     2.2 +++ b/tools/libxl/libxl.h	Thu Aug 19 15:32:28 2010 +0100
     2.3 @@ -373,7 +373,6 @@ int libxl_device_disk_local_detach(libxl
     2.4  int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
     2.5  int libxl_device_nic_del(libxl_ctx *ctx, libxl_device_nic *nic, int wait);
     2.6  libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb);
     2.7 -void libxl_free_nics_list(libxl_nicinfo *nics, unsigned int nb);
     2.8  
     2.9  int libxl_device_console_add(libxl_ctx *ctx, uint32_t domid, libxl_device_console *console);
    2.10  
     3.1 --- a/tools/libxl/libxl_utils.c	Thu Aug 19 15:31:46 2010 +0100
     3.2 +++ b/tools/libxl/libxl_utils.c	Thu Aug 19 15:32:28 2010 +0100
     3.3 @@ -405,42 +405,44 @@ int libxl_pipe(libxl_ctx *ctx, int pipes
     3.4  int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
     3.5                              const char *mac, libxl_device_nic *nic)
     3.6  {
     3.7 -    libxl_nicinfo *nics, *list;
     3.8 -    unsigned int nb, i, j;
     3.9 +    libxl_nicinfo *nics;
    3.10 +    unsigned int nb, i;
    3.11 +    int found;
    3.12      uint8_t mac_n[6];
    3.13      uint8_t *a, *b;
    3.14      const char *tok;
    3.15      char *endptr;
    3.16  
    3.17 -    list = nics = libxl_list_nics(ctx, domid, &nb);
    3.18 -    if (!nics) {
    3.19 +    nics = libxl_list_nics(ctx, domid, &nb);
    3.20 +    if (!nics)
    3.21          return ERROR_FAIL;
    3.22 -    }
    3.23  
    3.24      for (i = 0, tok = mac; *tok && (i < 6); ++i, tok += 3) {
    3.25          mac_n[i] = strtol(tok, &endptr, 16);
    3.26 -        if (endptr != (tok + 2)) {
    3.27 +        if (endptr != (tok + 2))
    3.28              return ERROR_INVAL;
    3.29 -        }
    3.30      }
    3.31      memset(nic, 0, sizeof (libxl_device_nic));
    3.32 -    for (j = 0; j < nb; ++j, ++nics) {
    3.33 -        for (i = 0, a = nics->mac, b = mac_n;
    3.34 +    found = 0;
    3.35 +    for (i = 0; i < nb; ++i) {
    3.36 +        for (i = 0, a = nics[i].mac, b = mac_n;
    3.37               (b < mac_n + 6) && (*a == *b); ++a, ++b)
    3.38              ;
    3.39          if ((b >= mac_n + 6) && (*a == *b)) {
    3.40 -            nic->backend_domid = nics->backend_id;
    3.41 -            nic->domid = nics->frontend_id;
    3.42 -            nic->devid = nics->devid;
    3.43 -            memcpy(nic->mac, nics->mac, sizeof (nic->mac));
    3.44 -            nic->script = nics->script;
    3.45 -            libxl_free_nics_list(list, nb);
    3.46 -            return 0;
    3.47 +            nic->backend_domid = nics[i].backend_id;
    3.48 +            nic->domid = nics[i].frontend_id;
    3.49 +            nic->devid = nics[i].devid;
    3.50 +            memcpy(nic->mac, nics[i].mac, sizeof (nic->mac));
    3.51 +            nic->script = strdup(nics[i].script);
    3.52 +            found = 1;
    3.53 +            break;
    3.54          }
    3.55      }
    3.56  
    3.57 -    libxl_free_nics_list(list, nb);
    3.58 -    return 0;
    3.59 +    for (i=0; i<nb; i++)
    3.60 +        libxl_nicinfo_destroy(&nics[i]);
    3.61 +    free(nics);
    3.62 +    return found;
    3.63  }
    3.64  
    3.65  int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid,
    3.66 @@ -472,8 +474,7 @@ int libxl_devid_to_device_nic(libxl_ctx 
    3.67           ++i, tok = strtok(NULL, ":")) {
    3.68          nic->mac[i] = strtoul(tok, NULL, 16);
    3.69      }
    3.70 -    nic->script = libxl_xs_read(&gc, XBT_NULL,
    3.71 -                                libxl_sprintf(&gc, "%s/script", nic_path_be));
    3.72 +    nic->script = xs_read(ctx->xsh, XBT_NULL, libxl_sprintf(&gc, "%s/script", nic_path_be), NULL);
    3.73      rc = 0;
    3.74  out:
    3.75      libxl_free_all(&gc);
     4.1 --- a/tools/libxl/xl_cmdimpl.c	Thu Aug 19 15:31:46 2010 +0100
     4.2 +++ b/tools/libxl/xl_cmdimpl.c	Thu Aug 19 15:32:28 2010 +0100
     4.3 @@ -4091,13 +4091,14 @@ int main_networkattach(int argc, char **
     4.4          fprintf(stderr, "libxl_device_nic_add failed.\n");
     4.5          return 1;
     4.6      }
     4.7 +    libxl_device_nic_destroy(&nic);
     4.8      return 0;
     4.9  }
    4.10  
    4.11  int main_networklist(int argc, char **argv)
    4.12  {
    4.13      int opt;
    4.14 -    libxl_nicinfo *nics, *list;
    4.15 +    libxl_nicinfo *nics;
    4.16      unsigned int nb, i;
    4.17  
    4.18      if (argc < 3) {
    4.19 @@ -4123,22 +4124,23 @@ int main_networklist(int argc, char **ar
    4.20              fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
    4.21              continue;
    4.22          }
    4.23 -        if (!(list = nics = libxl_list_nics(&ctx, domid, &nb))) {
    4.24 +        if (!(nics = libxl_list_nics(&ctx, domid, &nb))) {
    4.25              continue;
    4.26          }
    4.27 -        for (i = 0; i < nb; ++i, ++nics) {
    4.28 +        for (i = 0; i < nb; ++i) {
    4.29              /* Idx BE */
    4.30 -            printf("%-3d %-2d ", nics->devid, nics->backend_id);
    4.31 +            printf("%-3d %-2d ", nics[i].devid, nics[i].backend_id);
    4.32              /* MAC */
    4.33              printf("%02x:%02x:%02x:%02x:%02x:%02x ",
    4.34 -                   nics->mac[0], nics->mac[1], nics->mac[2],
    4.35 -                   nics->mac[3], nics->mac[4], nics->mac[5]);
    4.36 +                   nics[i].mac[0], nics[i].mac[1], nics[i].mac[2],
    4.37 +                   nics[i].mac[3], nics[i].mac[4], nics[i].mac[5]);
    4.38              /* Hdl  Sta  evch txr/rxr  BE-path */
    4.39              printf("%6d %5d %6d %5d/%-11d %-30s\n",
    4.40 -                   nics->devid, nics->state, nics->evtch,
    4.41 -                   nics->rref_tx, nics->rref_rx, nics->backend);
    4.42 +                   nics[i].devid, nics[i].state, nics[i].evtch,
    4.43 +                   nics[i].rref_tx, nics[i].rref_rx, nics[i].backend);
    4.44 +            libxl_nicinfo_destroy(&nics[i]);
    4.45          }
    4.46 -        libxl_free_nics_list(list, nb);
    4.47 +        free(nics);
    4.48      }
    4.49      return 0;
    4.50  }
    4.51 @@ -4183,6 +4185,7 @@ int main_networkdetach(int argc, char **
    4.52          fprintf(stderr, "libxl_device_nic_del failed.\n");
    4.53          return 1;
    4.54      }
    4.55 +    libxl_device_nic_destroy(&nic);
    4.56      return 0;
    4.57  }
    4.58