[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 09 of 23] libxl: nic: use _init/_setdefault
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1329148132 0 # Node ID 69c16a2a8927d81acc0cf0e127a5a4b7a9a1a886 # Parent 575cccbd3dc1c74cafb319fe82998c5fa619b428 libxl: nic: use _init/_setdefault Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> diff -r 575cccbd3dc1 -r 69c16a2a8927 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Mon Feb 13 15:48:52 2012 +0000 +++ b/tools/libxl/libxl.c Mon Feb 13 15:48:52 2012 +0000 @@ -1676,32 +1676,43 @@ int libxl_device_disk_local_detach(libxl } /******************************************************************************/ -int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic) +void libxl_device_nic_init(libxl_device_nic *nic) { - const uint8_t *r; - libxl_uuid uuid; - - libxl_uuid_generate(&uuid); - r = libxl_uuid_bytearray(&uuid); memset(nic, '\0', sizeof(*nic)); - - nic->backend_domid = 0; - nic->devid = -1; - nic->mtu = 1492; - nic->model = strdup("rtl8139"); - nic->mac[0] = 0x00; - nic->mac[1] = 0x16; - nic->mac[2] = 0x3e; - nic->mac[3] = r[0] & 0x7f; - nic->mac[4] = r[1]; - nic->mac[5] = r[2]; - nic->ifname = NULL; - nic->bridge = strdup("xenbr0"); - nic->ip = NULL; - if ( asprintf(&nic->script, "%s/vif-bridge", - libxl_xen_script_dir_path()) < 0 ) +} + +int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic) +{ + if (!nic->mtu) + nic->mtu = 1492; + if (!nic->model) { + nic->model = strdup("rtl8139"); + if (!nic->model) return ERROR_NOMEM; + } + if (!nic->mac[0] && !nic->mac[1] && !nic->mac[2] && + !nic->mac[3] && !nic->mac[4] && !nic->mac[5]) { + const uint8_t *r; + libxl_uuid uuid; + + libxl_uuid_generate(&uuid); + r = libxl_uuid_bytearray(&uuid); + + nic->mac[0] = 0x00; + nic->mac[1] = 0x16; + nic->mac[2] = 0x3e; + nic->mac[3] = r[0] & 0x7f; + nic->mac[4] = r[1]; + nic->mac[5] = r[2]; + } + if (!nic->bridge) { + nic->bridge = strdup("xenbr0"); + if (!nic->bridge) return ERROR_NOMEM; + } + if ( !nic->script && asprintf(&nic->script, "%s/vif-bridge", + libxl_xen_script_dir_path()) < 0 ) return ERROR_FAIL; - nic->nictype = LIBXL_NIC_TYPE_IOEMU; + if (!nic->nictype) + nic->nictype = LIBXL_NIC_TYPE_IOEMU; return 0; } @@ -1728,6 +1739,9 @@ int libxl_device_nic_add(libxl_ctx *ctx, char *dompath, **l; unsigned int nb, rc; + rc = libxl__device_nic_setdefault(gc, nic); + if (rc) goto out; + front = flexarray_make(16, 1); if (!front) { rc = ERROR_NOMEM; diff -r 575cccbd3dc1 -r 69c16a2a8927 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Mon Feb 13 15:48:52 2012 +0000 +++ b/tools/libxl/libxl.h Mon Feb 13 15:48:52 2012 +0000 @@ -528,7 +528,7 @@ char * libxl_device_disk_local_attach(li int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk); /* Network Interfaces */ -int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic); +void libxl_device_nic_init(libxl_device_nic *nic); int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic); int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic, diff -r 575cccbd3dc1 -r 69c16a2a8927 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Mon Feb 13 15:48:52 2012 +0000 +++ b/tools/libxl/libxl_internal.h Mon Feb 13 15:48:52 2012 +0000 @@ -193,6 +193,7 @@ _hidden int libxl__domain_build_info_set libxl_domain_build_info *b_info); _hidden int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk); +_hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic); struct libxl__evgen_domain_death { uint32_t domid; diff -r 575cccbd3dc1 -r 69c16a2a8927 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Mon Feb 13 15:48:52 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Mon Feb 13 15:48:52 2012 +0000 @@ -842,7 +842,7 @@ static void parse_config_data(const char d_config->vifs = (libxl_device_nic *) realloc(d_config->vifs, sizeof (libxl_device_nic) * (d_config->num_vifs+1)); nic = d_config->vifs + d_config->num_vifs; - CHK_ERRNO( libxl_device_nic_init(ctx, nic) ); + libxl_device_nic_init(nic); nic->devid = d_config->num_vifs; if (default_vifscript) { @@ -4602,7 +4602,7 @@ int main_networkattach(int argc, char ** fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]); return 1; } - libxl_device_nic_init(ctx, &nic); + libxl_device_nic_init(&nic); for (argv += optind+1, argc -= optind+1; argc > 0; ++argv, --argc) { if (MATCH_OPTION("type", *argv, oparg)) { if (!strcmp("vif", oparg)) { _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |