[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] libxl: nic: use _init/_setdefault
# HG changeset patch # User Ian Campbell <ian.campbell@xxxxxxxxxx> # Date 1330604774 0 # Node ID bc49dfa119baa61a9fa22d44e26191f8d0fc24f6 # Parent 41731e865e399de1ff5a100ae7b6b139f232adfc libxl: nic: use _init/_setdefault Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- diff -r 41731e865e39 -r bc49dfa119ba tools/libxl/libxl.c --- a/tools/libxl/libxl.c Thu Mar 01 12:26:14 2012 +0000 +++ b/tools/libxl/libxl.c Thu Mar 01 12:26:14 2012 +0000 @@ -1677,32 +1677,43 @@ } /******************************************************************************/ -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; } @@ -1729,6 +1740,9 @@ 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 41731e865e39 -r bc49dfa119ba tools/libxl/libxl.h --- a/tools/libxl/libxl.h Thu Mar 01 12:26:14 2012 +0000 +++ b/tools/libxl/libxl.h Thu Mar 01 12:26:14 2012 +0000 @@ -524,7 +524,7 @@ 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 41731e865e39 -r bc49dfa119ba tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Thu Mar 01 12:26:14 2012 +0000 +++ b/tools/libxl/libxl_internal.h Thu Mar 01 12:26:14 2012 +0000 @@ -193,6 +193,7 @@ 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 41731e865e39 -r bc49dfa119ba tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Thu Mar 01 12:26:14 2012 +0000 +++ b/tools/libxl/xl_cmdimpl.c Thu Mar 01 12:26:14 2012 +0000 @@ -844,7 +844,7 @@ 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) { @@ -4614,7 +4614,7 @@ 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-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |