From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 22 of 26] libxl/xl: Use libxl_device_nic_destroy and libxl_nicinfo_destroy
Date: Mon, 16 Aug 2010 15:33:46 +0100 [thread overview]
Message-ID: <3b72249bb27c9bd73cf4.1281969226@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1281969204@localhost.localdomain>
# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# 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;
}
next prev parent reply other threads:[~2010-08-16 14:33 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-16 14:33 [PATCH 00 of 26] libxl: autogenerate type definitions and destructor functions Ian Campbell
2010-08-16 14:33 ` [PATCH 01 of 26] xl: use the regular implicit rules to build the xl .o files Ian Campbell
2010-08-16 14:33 ` [PATCH 02 of 26] libxl: define specific types for string list and key, value list Ian Campbell
2010-08-16 14:33 ` [PATCH 03 of 26] libxl: move various enum and #defines above datastructure definitions Ian Campbell
2010-08-16 14:33 ` [PATCH 04 of 26] libxl: add specific type for cpumap Ian Campbell
2010-08-16 14:33 ` [PATCH 05 of 26] libxl: add specific type for hwcaps Ian Campbell
2010-08-16 14:33 ` [PATCH 06 of 26] libxl: make libxl_console_reader type opaque to users of libxl Ian Campbell
2010-08-16 14:33 ` [PATCH 07 of 26] lbixl: make libxl_device_model_starting " Ian Campbell
2010-08-16 14:33 ` [PATCH 08 of 26] libxl: ensure result of libxl_poolid_to_name is always dynamically allocated Ian Campbell
2010-08-16 14:33 ` [PATCH 09 of 26] libxl: move type definitions into _libxl_types.h Ian Campbell
2010-08-16 14:33 ` [PATCH 10 of 26] libxl: tweak formatting/whitespace of _libxl_types.h Ian Campbell
2010-08-16 14:33 ` [PATCH 11 of 26] libxl: autogenerate _libxl_types.h Ian Campbell
2010-08-17 11:53 ` Stefano Stabellini
2010-08-17 12:20 ` Ian Campbell
2010-08-16 14:33 ` [PATCH 12 of 26] libxl: generate destructors for each libxl defined type Ian Campbell
2010-08-16 14:33 ` [PATCH 13 of 26] libxl: libxl_device_console.build_state is const Ian Campbell
2010-08-16 14:33 ` [PATCH 14 of 26] libxl: build info bootloader{, _args} are not const Ian Campbell
2010-08-16 14:33 ` [PATCH 15 of 26] libxl: do not generate a destructor for data types which do not require one Ian Campbell
2010-08-16 14:33 ` [PATCH 16 of 26] libxl: implement destroy for libxl_file_reference builtin type Ian Campbell
2010-08-16 14:33 ` [PATCH 17 of 26] xl: free the libxl types contained in struct domain_config Ian Campbell
2010-08-16 14:33 ` [PATCH 18 of 26] libxl: use libxl_version_info_destroy instead of hand-coded do_free_version_info Ian Campbell
2010-08-16 14:33 ` [PATCH 19 of 26] xl: destroy device model info after creation Ian Campbell
2010-08-16 14:33 ` [PATCH 20 of 26] xl: free all data on exit from the domain monitor daemon Ian Campbell
2010-08-17 12:27 ` Stefano Stabellini
2010-08-17 12:33 ` Ian Campbell
2010-08-17 15:11 ` Ian Jackson
2010-08-17 15:12 ` Ian Campbell
2010-08-16 14:33 ` [PATCH 21 of 26] libxl/xl: use libxl_diskinfo_destroy and libxl_device_disk_destroy Ian Campbell
2010-08-16 14:33 ` Ian Campbell [this message]
2010-08-16 14:33 ` [PATCH 23 of 26] libxl/xl: Use libxl_vcpuinfo_destroy Ian Campbell
2010-08-16 14:33 ` [PATCH 24 of 26] xl: use libxl_device_pci_destroy Ian Campbell
2010-08-16 14:33 ` [PATCH 25 of 26] libxl: do not GC data returned to the caller by libxl_device_disk_getinfo Ian Campbell
2010-08-16 14:33 ` [PATCH 26 of 26] libxl: xs_read accepts NULL for *len parameter Ian Campbell
2010-08-17 12:14 ` [PATCH 00 of 26] libxl: autogenerate type definitions and destructor functions Gianni Tedesco
2010-08-17 12:25 ` Ian Campbell
2010-08-17 12:24 ` Gianni Tedesco
2010-08-17 12:34 ` Stefano Stabellini
2010-08-17 12:37 ` Ian Campbell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3b72249bb27c9bd73cf4.1281969226@localhost.localdomain \
--to=ian.campbell@citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).