[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 05/13] libxl: move libxl_device_nic_add to libxl_device
Move the code of this function to libxl_device.c so it can be made asyncronious later on the series. The static function libxl__device_from_nic also has to be moved to libxl_device and it is no longer static. The code will be fixed in a latter patch, replacing libxl__sprintf, LIBXL_LOG* and lines > 80. Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxx> --- tools/libxl/libxl.c | 108 +--------------------------------------- tools/libxl/libxl_device.c | 113 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 6 ++ 3 files changed, 121 insertions(+), 106 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 2d8abd0..d3b6a53 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1655,117 +1655,13 @@ int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic) return 0; } -static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid, - libxl_device_nic *nic, - libxl__device *device) -{ - device->backend_devid = nic->devid; - device->backend_domid = nic->backend_domid; - device->backend_kind = LIBXL__DEVICE_KIND_VIF; - device->devid = nic->devid; - device->domid = domid; - device->kind = LIBXL__DEVICE_KIND_VIF; - - return 0; -} - int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic) { GC_INIT(ctx); - flexarray_t *front; - flexarray_t *back; - libxl__device device; - 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; - goto out; - } - back = flexarray_make(16, 1); - if (!back) { - rc = ERROR_NOMEM; - goto out_free; - } - - if (nic->devid == -1) { - if (!(dompath = libxl__xs_get_dompath(gc, domid))) { - rc = ERROR_FAIL; - goto out_free; - } - if (!(l = libxl__xs_directory(gc, XBT_NULL, - libxl__sprintf(gc, "%s/device/vif", dompath), &nb))) { - nic->devid = 0; - } else { - nic->devid = strtoul(l[nb - 1], NULL, 10) + 1; - } - } - - rc = libxl__device_from_nic(gc, domid, nic, &device); - if ( rc != 0 ) goto out_free; - - flexarray_append(back, "frontend-id"); - flexarray_append(back, libxl__sprintf(gc, "%d", domid)); - flexarray_append(back, "online"); - flexarray_append(back, "1"); - flexarray_append(back, "state"); - flexarray_append(back, libxl__sprintf(gc, "%d", 1)); - if (nic->script) { - flexarray_append(back, "script"); - flexarray_append(back, nic->script[0]=='/' ? nic->script - : libxl__sprintf(gc, "%s/%s", - libxl__xen_script_dir_path(), - nic->script)); - } - - if (nic->ifname) { - flexarray_append(back, "vifname"); - flexarray_append(back, nic->ifname); - } - - flexarray_append(back, "mac"); - flexarray_append(back,libxl__sprintf(gc, - LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); - if (nic->ip) { - flexarray_append(back, "ip"); - flexarray_append(back, libxl__strdup(gc, nic->ip)); - } - - if (nic->rate_interval_usecs > 0) { - flexarray_append(back, "rate"); - flexarray_append(back, libxl__sprintf(gc, "%"PRIu64",%"PRIu32"", - nic->rate_bytes_per_interval, - nic->rate_interval_usecs)); - } - - flexarray_append(back, "bridge"); - flexarray_append(back, libxl__strdup(gc, nic->bridge)); - flexarray_append(back, "handle"); - flexarray_append(back, libxl__sprintf(gc, "%d", nic->devid)); + int rc; - flexarray_append(front, "backend-id"); - flexarray_append(front, libxl__sprintf(gc, "%d", nic->backend_domid)); - flexarray_append(front, "state"); - flexarray_append(front, libxl__sprintf(gc, "%d", 1)); - flexarray_append(front, "handle"); - flexarray_append(front, libxl__sprintf(gc, "%d", nic->devid)); - flexarray_append(front, "mac"); - flexarray_append(front, libxl__sprintf(gc, - LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); - libxl__device_generic_add(gc, &device, - libxl__xs_kvs_of_flexarray(gc, back, back->count), - libxl__xs_kvs_of_flexarray(gc, front, front->count)); + rc = libxl__device_nic_add(gc, domid, nic); - /* FIXME: wait for plug */ - rc = 0; -out_free: - flexarray_free(back); - flexarray_free(front); -out: GC_FREE; return rc; } diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 304929a..edc4ad1 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -408,6 +408,119 @@ out: return rc; } +int libxl__device_from_nic(libxl__gc *gc, uint32_t domid, + libxl_device_nic *nic, + libxl__device *device) +{ + device->backend_devid = nic->devid; + device->backend_domid = nic->backend_domid; + device->backend_kind = LIBXL__DEVICE_KIND_VIF; + device->devid = nic->devid; + device->domid = domid; + device->kind = LIBXL__DEVICE_KIND_VIF; + + return 0; +} + +int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic) +{ + flexarray_t *front; + flexarray_t *back; + libxl__device device; + 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; + goto out; + } + back = flexarray_make(16, 1); + if (!back) { + rc = ERROR_NOMEM; + goto out_free; + } + + if (nic->devid == -1) { + if (!(dompath = libxl__xs_get_dompath(gc, domid))) { + rc = ERROR_FAIL; + goto out_free; + } + if (!(l = libxl__xs_directory(gc, XBT_NULL, + libxl__sprintf(gc, "%s/device/vif", dompath), &nb))) { + nic->devid = 0; + } else { + nic->devid = strtoul(l[nb - 1], NULL, 10) + 1; + } + } + + rc = libxl__device_from_nic(gc, domid, nic, &device); + if ( rc != 0 ) goto out_free; + + flexarray_append(back, "frontend-id"); + flexarray_append(back, libxl__sprintf(gc, "%d", domid)); + flexarray_append(back, "online"); + flexarray_append(back, "1"); + flexarray_append(back, "state"); + flexarray_append(back, libxl__sprintf(gc, "%d", 1)); + if (nic->script) { + flexarray_append(back, "script"); + flexarray_append(back, nic->script[0]=='/' ? nic->script + : libxl__sprintf(gc, "%s/%s", + libxl__xen_script_dir_path(), + nic->script)); + } + + if (nic->ifname) { + flexarray_append(back, "vifname"); + flexarray_append(back, nic->ifname); + } + + flexarray_append(back, "mac"); + flexarray_append(back,libxl__sprintf(gc, + LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); + if (nic->ip) { + flexarray_append(back, "ip"); + flexarray_append(back, libxl__strdup(gc, nic->ip)); + } + + if (nic->rate_interval_usecs > 0) { + flexarray_append(back, "rate"); + flexarray_append(back, libxl__sprintf(gc, "%"PRIu64",%"PRIu32"", + nic->rate_bytes_per_interval, + nic->rate_interval_usecs)); + } + + flexarray_append(back, "bridge"); + flexarray_append(back, libxl__strdup(gc, nic->bridge)); + flexarray_append(back, "handle"); + flexarray_append(back, libxl__sprintf(gc, "%d", nic->devid)); + + flexarray_append(front, "backend-id"); + flexarray_append(front, libxl__sprintf(gc, "%d", nic->backend_domid)); + flexarray_append(front, "state"); + flexarray_append(front, libxl__sprintf(gc, "%d", 1)); + flexarray_append(front, "handle"); + flexarray_append(front, libxl__sprintf(gc, "%d", nic->devid)); + flexarray_append(front, "mac"); + flexarray_append(front, libxl__sprintf(gc, + LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); + libxl__device_generic_add(gc, &device, + libxl__xs_kvs_of_flexarray(gc, back, back->count), + libxl__xs_kvs_of_flexarray(gc, front, front->count)); + + /* FIXME: wait for plug */ + rc = 0; +out_free: + flexarray_free(back); + flexarray_free(front); +out: + return rc; +} + int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor) { struct stat buf; diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 87c9366..0ddfe72 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -786,6 +786,12 @@ _hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid, _hidden int libxl__device_disk_add(libxl__gc *gc, uint32_t domid, libxl_device_disk *disk); +_hidden int libxl__device_from_nic(libxl__gc *gc, uint32_t domid, + libxl_device_nic *nic, + libxl__device *device); +_hidden int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, + libxl_device_nic *nic); + _hidden int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor); _hidden int libxl__device_disk_dev_number(const char *virtpath, int *pdisk, int *ppartition); -- 1.7.7.5 (Apple Git-26) _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |