From patchwork Tue Jul 18 14:25:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9848539 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5FB35602C8 for ; Tue, 18 Jul 2017 14:28:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 507D1285A8 for ; Tue, 18 Jul 2017 14:28:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44DF8285B0; Tue, 18 Jul 2017 14:28:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 60F0C2852B for ; Tue, 18 Jul 2017 14:28:08 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXTRk-0002iu-1H; Tue, 18 Jul 2017 14:25:56 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXTRi-0002fz-Cs for xen-devel@lists.xenproject.org; Tue, 18 Jul 2017 14:25:54 +0000 Received: from [85.158.139.211] by server-9.bemta-5.messagelabs.com id B7/D9-01994-17A1E695; Tue, 18 Jul 2017 14:25:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrDIsWRWlGSWpSXmKPExsVyMfS6k26+VF6 kQfsjY4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPHv2OsBQdbGSu2LtnP0sC4PKGLkYtDSGA6 o8SkdZvZQRwWgZcsEh8uH2DuYuTkkBDoZ5VYeVocwk6SmLa0gQnCLpP4c+goI4gtJCAvcbDlM jvEpGlMEv0zGsGK2AS0JO7fXsEGYosIKEncWzUZLM4skCKxd10bWLOwgLtE2/M+sGUsAqoS06 c8AKrh4OAVcJTYuswSYpecxM1zncwgYU6Q8IxyiLUOEjdaX7FPYBRYwMiwilG9OLWoLLVI10Q vqSgzPaMkNzEzR9fQwFQvN7W4ODE9NScxqVgvOT93EyMwrBiAYAfjrT7nQ4ySHExKoryrD+RG CvEl5adUZiQWZ8QXleakFh9i1ODgEPj59G8LoxRLXn5eqpIEL49kXqSQYFFqempFWmYOMPBhS iU4eJREePMlgNK8xQWJucWZ6RCpU4z2HFeurPvCxLFh9XogOeXAdiD5asL/b0xCYFOlxHkVQK YKgLRllObBDYVF6iVGWSlhXkagk4V4ClKLcjNLUOVfMYpzMCoJ85qBTOHJzCuB2/0K6CwmoLO EfXNAzipJREhJNTCWv2Vq9A9Ubu+Z8XnX8cL2LTqfOl//rbMKVjt/9vwGt9YPHN/a/usveql+ pHDH923fY35q13GXzpR6O5t7bsWqi/P9tnxf/mzjP6FZcvdNWl6qCu7Kl16RXdQXM2Hqky9VH Dclvt05XDghUlolUv2Zgxeb0rSLG7u2p53qUQ6eZv53ifzhLd5sSizFGYmGWsxFxYkADXrbc8 8CAAA= X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-11.tower-206.messagelabs.com!1500387951!83635329!1 X-Originating-IP: [209.85.215.66] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 11319 invoked from network); 18 Jul 2017 14:25:51 -0000 Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by server-11.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 18 Jul 2017 14:25:51 -0000 Received: by mail-lf0-f66.google.com with SMTP id p11so1998649lfd.1 for ; Tue, 18 Jul 2017 07:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gbQLv6Abf0aryP+85RtAA+gTEJyUpNgVJOKIZ7c4Ci4=; b=JxY9kDNUtz0hImPzcI56+QGHex8rozyNth7ccR3harV5rwSNOCr5qZi9O+XDP7SHHM auKcA5HrwTvLLtynGBZb05Mcul/KsFOuG/sbd/lU3wxmPj1C94kTVCnvxjkNi8O0F+Z7 6w6ge2vfI+B6HBm7XwOOzMqkhS13LgcbpRTSTLzNGvDwWCIJsmlzkL1Vzw5d2v4783j7 x+mlsVj/xJGnT+z9MCImAkPBverzUppTAIS+u7FUASbhmlQRWxbT2vslRbSA2FOPSMWe YT6yeV7RxbPfOnG/tX/Enfol3XQ1sunp9T41TEb+x5A6Drl+8JxZS8//chEIQ03O0ACK wc4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gbQLv6Abf0aryP+85RtAA+gTEJyUpNgVJOKIZ7c4Ci4=; b=ZRwaDLHgEuCC3gYlNm3PGQn3HiXTGVAQaj6DvJj51w6f+8UxRDiV9AM4jaknXPIBrN cb6trE3bks+wecw3CeHqNU3OoXso7jPazV3kMo92KYrz6TfZPBMWX95nwT4wKUPfVI70 o916PPI5aq+bpKEqzO53z6Mzu0Iop79KKjLtX8T8mmkfr7EzOWh/uh6mMK4D3cHekdlP uPGttny2gn3CLSfSiYkInPNQvlvgqnbGKFEUxNcAcHYbpGwXkC3EAW4PL7qXB726DgNs msqmK2W66bDJVre6bySTtY4S7P2Q1lcdVdRpDUZmHMYvDrjCm+T6qfiaBuWUwltTDXdJ J5+A== X-Gm-Message-State: AIVw110tje6RXUnEZeDrHxAJ/ltiHOlr3H6VF/06TUDzXCnwiNgY672Q KxhXzlV+Pv7eptx4dSc= X-Received: by 10.25.94.79 with SMTP id z15mr718670lfi.72.1500387950660; Tue, 18 Jul 2017 07:25:50 -0700 (PDT) Received: from al1-pc.kyiv.epam.com (ll-58.209.223.85.sovam.net.ua. [85.223.209.58]) by smtp.gmail.com with ESMTPSA id s134sm620442lfe.27.2017.07.18.07.25.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 07:25:50 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Tue, 18 Jul 2017 17:25:27 +0300 Message-Id: <1500387930-16317-11-git-send-email-al1img@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500387930-16317-1-git-send-email-al1img@gmail.com> References: <1500387930-16317-1-git-send-email-al1img@gmail.com> Cc: ian.jackson@eu.citrix.com, wei.liu2@citrix.com, Oleksandr Grytsov Subject: [Xen-devel] [PATCH v4 10/13] libxl: change nic to use generec add function X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Grytsov Signed-off-by: Oleksandr Grytsov --- tools/libxl/libxl.h | 9 +- tools/libxl/libxl_checkpoint_device.c | 9 +- tools/libxl/libxl_colo_save.c | 4 +- tools/libxl/libxl_dm.c | 4 +- tools/libxl/libxl_internal.h | 2 - tools/libxl/libxl_nic.c | 212 +++++++--------------------------- tools/ocaml/libs/xl/xenlight_stubs.c | 3 +- tools/xl/xl_nic.c | 3 +- 8 files changed, 59 insertions(+), 187 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 991b947..4a29b43 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1824,9 +1824,14 @@ int libxl_device_nic_destroy(libxl_ctx *ctx, uint32_t domid, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY; -libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num); +libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, + uint32_t domid, int *num) + LIBXL_EXTERNAL_CALLERS_ONLY; +void libxl_device_nic_list_free(libxl_device_nic* list, int num) + LIBXL_EXTERNAL_CALLERS_ONLY; int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid, - libxl_device_nic *nic, libxl_nicinfo *nicinfo); + libxl_device_nic *nic, libxl_nicinfo *nicinfo) + LIBXL_EXTERNAL_CALLERS_ONLY; /* * Virtual Channels diff --git a/tools/libxl/libxl_checkpoint_device.c b/tools/libxl/libxl_checkpoint_device.c index 7bd832b..eb9c604 100644 --- a/tools/libxl/libxl_checkpoint_device.c +++ b/tools/libxl/libxl_checkpoint_device.c @@ -63,7 +63,8 @@ void libxl__checkpoint_devices_setup(libxl__egc *egc, cds->num_disks = 0; if (cds->device_kind_flags & (1 << LIBXL__DEVICE_KIND_VIF)) - cds->nics = libxl_device_nic_list(CTX, cds->domid, &cds->num_nics); + cds->nics = libxl__device_list(gc, &libxl__nic_devtype, cds->domid, + "vif", &cds->num_nics); if (cds->device_kind_flags & (1 << LIBXL__DEVICE_KIND_VBD)) cds->disks = libxl__device_list(gc, &libxl__disk_devtype, cds->domid, @@ -206,8 +207,6 @@ static void devices_teardown_cb(libxl__egc *egc, libxl__multidev *multidev, int rc) { - int i; - STATE_AO_GC(multidev->ao); /* Convenience aliases */ @@ -215,9 +214,7 @@ static void devices_teardown_cb(libxl__egc *egc, CONTAINER_OF(multidev, *cds, multidev); /* clean nic */ - for (i = 0; i < cds->num_nics; i++) - libxl_device_nic_dispose(&cds->nics[i]); - free(cds->nics); + libxl__device_list_free(&libxl__nic_devtype, cds->nics, cds->num_nics); cds->nics = NULL; cds->num_nics = 0; diff --git a/tools/libxl/libxl_colo_save.c b/tools/libxl/libxl_colo_save.c index f687d5a..8a9d37a 100644 --- a/tools/libxl/libxl_colo_save.c +++ b/tools/libxl/libxl_colo_save.c @@ -87,6 +87,7 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css) libxl__srm_save_autogen_callbacks *const callbacks = &dss->sws.shs.callbacks.save.a; libxl_device_nic *nics; + int nb; STATE_AO_GC(dss->ao); @@ -122,9 +123,10 @@ void libxl__colo_save_setup(libxl__egc *egc, libxl__colo_save_state *css) cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VBD); /* Use this args we can connect to qemu colo-compare */ - nics = libxl_device_nic_list(CTX, cds->domid, &cds->num_nics); + nics = libxl_device_nic_list(CTX, cds->domid, &nb); css->cps.checkpoint_host = nics->colo_checkpoint_host; css->cps.checkpoint_port = nics->colo_checkpoint_port; + libxl_device_nic_list_free(nics, nb); } else { cds->device_kind_flags = (1 << LIBXL__DEVICE_KIND_VIF) | (1 << LIBXL__DEVICE_KIND_VBD); diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 0a4f811..eee4c98 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -1970,8 +1970,8 @@ static void spawn_stub_launch_dm(libxl__egc *egc, * called libxl_device_nic_add at this point, but qemu needs * the nic information to be complete. */ - ret = libxl__device_nic_setdefault(gc, &dm_config->nics[i], dm_domid, - false); + ret = libxl__nic_devtype.set_default(gc, dm_domid, &dm_config->nics[i], + false); if (ret) goto out; } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 9f8b56a..4b1c5ab 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1242,8 +1242,6 @@ _hidden int libxl__domain_create_info_setdefault(libxl__gc *gc, libxl_domain_create_info *c_info); _hidden int libxl__domain_build_info_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info); -_hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic, - uint32_t domid, bool hotplug); _hidden int libxl__device_pci_setdefault(libxl__gc *gc, libxl_device_pci *pci); _hidden void libxl__rdm_setdefault(libxl__gc *gc, libxl_domain_build_info *b_info); diff --git a/tools/libxl/libxl_nic.c b/tools/libxl/libxl_nic.c index dd07a6c..16a6c8c 100644 --- a/tools/libxl/libxl_nic.c +++ b/tools/libxl/libxl_nic.c @@ -20,15 +20,18 @@ int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid, const char *mac, libxl_device_nic *nic) { + GC_INIT(ctx); libxl_device_nic *nics; int nb, rc, i; libxl_mac mac_n; + libxl_device_nic_init(nic); + rc = libxl__parse_mac(mac, mac_n); if (rc) return rc; - nics = libxl_device_nic_list(ctx, domid, &nb); + nics = libxl__device_list(gc, &libxl__nic_devtype, domid, "vif", &nb); if (!nics) return ERROR_FAIL; @@ -37,23 +40,18 @@ int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid, rc = ERROR_INVAL; for (i = 0; i < nb; ++i) { if (!libxl__compare_macs(&mac_n, &nics[i].mac)) { - *nic = nics[i]; + libxl_device_nic_copy(ctx, nic, &nics[i]); rc = 0; - i++; /* Do not dispose this NIC on exit path */ break; } - libxl_device_nic_dispose(&nics[i]); } - - for (; imac, &src->mac); } -static void libxl__device_nic_add(libxl__egc *egc, uint32_t domid, - libxl_device_nic *nic, - libxl__ao_device *aodev) +static int libxl__set_xenstore_nic(libxl__gc *gc, uint32_t domid, + libxl_device_nic *nic, + flexarray_t *back, flexarray_t *front, + flexarray_t *ro_front) { - STATE_AO_GC(aodev->ao); - flexarray_t *front; - flexarray_t *back; - libxl__device *device; - int rc; - xs_transaction_t t = XBT_NULL; - libxl_domain_config d_config; - libxl_device_nic nic_saved; - libxl__domain_userdata_lock *lock = NULL; - - libxl_domain_config_init(&d_config); - libxl_device_nic_init(&nic_saved); - libxl_device_nic_copy(CTX, &nic_saved, nic); - - rc = libxl__device_nic_setdefault(gc, nic, domid, aodev->update_json); - if (rc) goto out; + flexarray_grow(back, 2); - front = flexarray_make(gc, 16, 1); - back = flexarray_make(gc, 18, 1); - - if (nic->devid == -1) { - if ((nic->devid = libxl__device_nextid(gc, domid, "vif")) < 0) { - rc = ERROR_FAIL; - goto out; - } - } - - libxl__update_config_nic(gc, &nic_saved, nic); - - GCNEW(device); - rc = libxl__device_from_nic(gc, domid, nic, device); - if ( rc != 0 ) goto out; - - flexarray_append(back, "frontend-id"); - flexarray_append(back, GCSPRINTF("%d", domid)); - flexarray_append(back, "online"); - flexarray_append(back, "1"); - flexarray_append(back, "state"); - flexarray_append(back, GCSPRINTF("%d", XenbusStateInitialising)); if (nic->script) flexarray_append_pair(back, "script", libxl__abs_path(gc, nic->script, @@ -281,78 +243,24 @@ static void libxl__device_nic_add(libxl__egc *egc, uint32_t domid, flexarray_append(back, libxl__strdup(gc, libxl_nic_type_to_string(nic->nictype))); - flexarray_append(front, "backend-id"); - flexarray_append(front, GCSPRINTF("%d", nic->backend_domid)); - flexarray_append(front, "state"); - flexarray_append(front, GCSPRINTF("%d", XenbusStateInitialising)); flexarray_append(front, "handle"); flexarray_append(front, GCSPRINTF("%d", nic->devid)); flexarray_append(front, "mac"); flexarray_append(front, GCSPRINTF( LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); - if (aodev->update_json) { - lock = libxl__lock_domain_userdata(gc, domid); - if (!lock) { - rc = ERROR_LOCK_FAIL; - goto out; - } - - rc = libxl__get_domain_configuration(gc, domid, &d_config); - if (rc) goto out; - - DEVICE_ADD(nic, nics, domid, &nic_saved, COMPARE_DEVID, &d_config); - - rc = libxl__dm_check_start(gc, &d_config, domid); - if (rc) goto out; - } - - for (;;) { - rc = libxl__xs_transaction_start(gc, &t); - if (rc) goto out; - - rc = libxl__device_exists(gc, t, device); - if (rc < 0) goto out; - if (rc == 1) { /* already exists in xenstore */ - LOGD(ERROR, domid, "device already exists in xenstore"); - aodev->action = LIBXL__DEVICE_ACTION_ADD; /* for error message */ - rc = ERROR_DEVICE_EXISTS; - goto out; - } - - if (aodev->update_json) { - rc = libxl__set_domain_configuration(gc, domid, &d_config); - if (rc) goto out; - } - - libxl__device_generic_add(gc, t, device, - libxl__xs_kvs_of_flexarray(gc, back), - libxl__xs_kvs_of_flexarray(gc, front), - NULL); - - rc = libxl__xs_transaction_commit(gc, &t); - if (!rc) break; - if (rc < 0) goto out; - } - - aodev->dev = device; - aodev->action = LIBXL__DEVICE_ACTION_ADD; - libxl__wait_device_connection(egc, aodev); + return 0; +} - rc = 0; -out: - libxl__xs_transaction_abort(gc, &t); - if (lock) libxl__unlock_domain_userdata(lock); - libxl_device_nic_dispose(&nic_saved); - libxl_domain_config_dispose(&d_config); - aodev->rc = rc; - if (rc) aodev->callback(egc, aodev); - return; +static void libxl__device_nic_add(libxl__egc *egc, uint32_t domid, + libxl_device_nic *nic, + libxl__ao_device *aodev) +{ + libxl__device_add_async(egc, domid, &libxl__nic_devtype, nic, aodev); } -static int libxl__device_nic_from_xenstore(libxl__gc *gc, - const char *libxl_path, - libxl_device_nic *nic) +static int libxl__nic_from_xenstore(libxl__gc *gc, const char *libxl_path, + libxl_devid devid, libxl_device_nic *nic) { const char *tmp; int rc; @@ -498,7 +406,7 @@ int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid, libxl_path = GCSPRINTF("%s/device/vif/%d", libxl_dom_path, devid); - rc = libxl__device_nic_from_xenstore(gc, libxl_path, nic); + rc = libxl__nic_from_xenstore(gc, libxl_path, devid, nic); if (rc) goto out; rc = 0; @@ -507,64 +415,22 @@ out: return rc; } -static int libxl__append_nic_list(libxl__gc *gc, - uint32_t domid, - libxl_device_nic **nics, - int *nnics) -{ - char *libxl_dir_path = NULL; - char **dir = NULL; - unsigned int n = 0; - libxl_device_nic *pnic = NULL, *pnic_end = NULL; - int rc; - - libxl_dir_path = GCSPRINTF("%s/device/vif", - libxl__xs_libxl_path(gc, domid)); - dir = libxl__xs_directory(gc, XBT_NULL, libxl_dir_path, &n); - if (dir && n) { - libxl_device_nic *tmp; - tmp = realloc(*nics, sizeof (libxl_device_nic) * (*nnics + n)); - if (tmp == NULL) - return ERROR_NOMEM; - *nics = tmp; - pnic = *nics + *nnics; - pnic_end = *nics + *nnics + n; - for (; pnic < pnic_end; pnic++, dir++) { - const char *p; - p = GCSPRINTF("%s/%s", libxl_dir_path, *dir); - rc = libxl__device_nic_from_xenstore(gc, p, pnic); - if (rc) goto out; - } - *nnics += n; - } - return 0; - - out: - return rc; -} - libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num) { - GC_INIT(ctx); - libxl_device_nic *nics = NULL; - int rc; + libxl_device_nic *r; - *num = 0; + GC_INIT(ctx); - rc = libxl__append_nic_list(gc, domid, &nics, num); - if (rc) goto out_err; + r = libxl__device_list(gc, &libxl__nic_devtype, domid, "vif", num); GC_FREE; - return nics; -out_err: - LOGD(ERROR, domid, "Unable to list nics"); - while (*num) { - (*num)--; - libxl_device_nic_dispose(&nics[*num]); - } - free(nics); - return NULL; + return r; +} + +void libxl_device_nic_list_free(libxl_device_nic* list, int num) +{ + libxl__device_list_free(&libxl__nic_devtype, list, num); } int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid, @@ -646,7 +512,7 @@ int libxl__device_nic_set_devids(libxl__gc *gc, libxl_domain_config *d_config, * called libxl_device_nic_add when domcreate_launch_dm gets called, * but qemu needs the nic information to be complete. */ - ret = libxl__device_nic_setdefault(gc, &d_config->nics[i], domid, + ret = libxl__device_nic_setdefault(gc, domid, &d_config->nics[i], false); if (ret) { LOGD(ERROR, domid, "Unable to set nic defaults for nic %d", i); @@ -669,10 +535,16 @@ LIBXL_DEFINE_DEVICE_ADD(nic) LIBXL_DEFINE_DEVICES_ADD(nic) LIBXL_DEFINE_DEVICE_REMOVE(nic) -#define libxl__device_nic_update_devid NULL +static LIBXL_DEFINE_UPDATE_DEVID(nic, "vif") DEFINE_DEVICE_TYPE_STRUCT(nic, - .update_config = libxl_device_nic_update_config + .update_config = libxl_device_nic_update_config, + .from_xenstore = (int (*)(libxl__gc *, const char *, libxl_devid, void *)) + libxl__nic_from_xenstore, + .set_xenstore_config = (int (*)(libxl__gc *, uint32_t, void *, + flexarray_t *back, flexarray_t *front, + flexarray_t *ro_front)) + libxl__set_xenstore_nic ); /* diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c b/tools/ocaml/libs/xl/xenlight_stubs.c index 55f09d7..badf9c9 100644 --- a/tools/ocaml/libs/xl/xenlight_stubs.c +++ b/tools/ocaml/libs/xl/xenlight_stubs.c @@ -734,9 +734,8 @@ value stub_xl_device_nic_list(value ctx, value domid) Field(list, 1) = temp; temp = list; Store_field(list, 0, Val_device_nic(&c_list[i])); - libxl_device_nic_dispose(&c_list[i]); } - free(c_list); + libxl_device_nic_list_free(c_list, nb) CAMLreturn(list); } diff --git a/tools/xl/xl_nic.c b/tools/xl/xl_nic.c index a78d944..2315dcd 100644 --- a/tools/xl/xl_nic.c +++ b/tools/xl/xl_nic.c @@ -124,9 +124,8 @@ int main_networklist(int argc, char **argv) nicinfo.rref_tx, nicinfo.rref_rx, nicinfo.backend); libxl_nicinfo_dispose(&nicinfo); } - libxl_device_nic_dispose(&nics[i]); } - free(nics); + libxl_device_nic_list_free(nics, nb); } return 0; }