From patchwork Tue Jul 18 14:25:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Grytsov X-Patchwork-Id: 9848529 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 946CC602C8 for ; Tue, 18 Jul 2017 14:28:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 869FA26E74 for ; Tue, 18 Jul 2017 14:28:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BA6328599; Tue, 18 Jul 2017 14:28:06 +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 5469A26E74 for ; Tue, 18 Jul 2017 14:28:05 +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-0002jQ-92; Tue, 18 Jul 2017 14:25:56 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXTRi-0002gJ-Gl for xen-devel@lists.xenproject.org; Tue, 18 Jul 2017 14:25:54 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id E5/F1-03612-17A1E695; Tue, 18 Jul 2017 14:25:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLIsWRWlGSWpSXmKPExsVyMfS6s26hVF6 kwbNeJovvWyYzOTB6HP5whSWAMYo1My8pvyKBNeP8tX7WgrepFa/O7GZvYFzu1cXIxSEkMJ1R 4tbmtYwgDovASxaJF4emsYI4EgL9rBKnn09h6WLkBHKSJD5P/MQIYZdLdE46xQZiCwnISxxsu cwOYU9jkmh9kwpiswloSdy/vQKsRkRASeLeqslMIDazQIrE3nVtYHOEBTwkrr7fAxZnEVCVeD v9BCuIzSvgKPH7zmqovXISN891MncxcnBwAsW3ziiHWOUgcaP1FfsERoEFjAyrGDWKU4vKUot 0DQ31kooy0zNKchMzc3QNDcz0clOLixPTU3MSk4r1kvNzNzECA4sBCHYwfloWcIhRkoNJSZR3 9YHcSCG+pPyUyozE4oz4otKc1OJDjBocHAI/n/5tYZRiycvPS1WS4F0lkRcpJFiUmp5akZaZA wx9mFIJDh4lEd58kDRvcUFibnFmOkTqFKM9x5Ur674wcWxYvR5ITjmwHUi+mvD/G5MQ2FQpcV 4FSaA2AZC2jNI8uKGwWL3EKCslzMsIdLIQT0FqUW5mCar8K0ZxDkYlYd5GkOU8mXklcLtfAZ3 FBHSWsG8OyFkliQgpqQZGgcUTSpt/PcveUpGxsn/h0pn/vny+tc68iEm1fdGquuRelZ8xf0NZ nqR0Pzhz7oV3o7HaFL9zu07sNQ2P9PjFvv+86DHvX0tL1BVUnpTsfrnrS+CcCJFJh99yMTcym D7QD+9hv3Gh6b8AR1vy5urYz6lxVx+sOBd63kLbboJi9ZedD/9MXfZGUomlOCPRUIu5qDgRAC PhF7TQAgAA X-Env-Sender: al1img@gmail.com X-Msg-Ref: server-13.tower-21.messagelabs.com!1500387952!67953551!1 X-Originating-IP: [209.85.215.67] 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 36721 invoked from network); 18 Jul 2017 14:25:52 -0000 Received: from mail-lf0-f67.google.com (HELO mail-lf0-f67.google.com) (209.85.215.67) by server-13.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 18 Jul 2017 14:25:52 -0000 Received: by mail-lf0-f67.google.com with SMTP id z78so1999286lff.2 for ; Tue, 18 Jul 2017 07:25:52 -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=ebG5rKkHMK4/jUAksIuWb8EBLXo1/7Lo0wP2p9mb7dg=; b=bk4Gi9+0uBW7sZB2u2LW5Htenz4T1WFHTWPfyuvpq3+PVQh1IMOWd9GZyrq0Hb9qx+ /YL1u/mkdDJfPLERw2dONWV+lsS3keY0741Z39/Ly5XCChatDXZQNSce8tpWSCZEGsjs oYACjIquVZQvLHjuz5aPcRRgOo9GrmPB0sO1UTy+7y1E1U3Ej53YWAjpufKm9lh+djQk 4YeSrj7r5zLvvESJtPHo7YTWUtcl/Zsqs48URFuQxSub6b+E8FXYce/V2OyNuJHtwTGU NH4i8mWihDY7fnUmcj2Gx+kFQSSX3oRxLbpVcYKjWj/jqDDj4smx0QtVBrK2aVJoV7Eu n37Q== 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=ebG5rKkHMK4/jUAksIuWb8EBLXo1/7Lo0wP2p9mb7dg=; b=fmjP91F27+36nAMcThgxv3mCFxdxP30AVx53BI5RyhvHzUAofonVlrVJec6FJE8jkf SK6OTLipLvWhza28sn4YIZtWg5guzJO72hQUArPFQ8ICLTOLluWxzShtw/AEvIXdgXDB vtuQm2IQI+/DzYzFzhRwSsFJdG0VnyLQWFtFpEkPjLlhuY54/L+PflOQoLkf2uXvgDRw bypGmh/g7DQMqv6hjCTlbTqMnUok3ve172gL9ZZ4iffTBxEMZgk0MtEOaUxy/F32lb1I 132adhQsx10oVD485xbOZg5Tp2ydzB3YDIrHjy6SdNXCzlfeskz7oYE6c2Jsj6tBvl0A KTmQ== X-Gm-Message-State: AIVw112B6irmb2mCuYhIJFRUmMgw6Fvf78whXyqs7HIiiq+4dUqKL29D gcJKYrV0dhkcDr8JdwU= X-Received: by 10.25.168.18 with SMTP id r18mr705881lfe.85.1500387951900; Tue, 18 Jul 2017 07:25:51 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 07:25:51 -0700 (PDT) From: Oleksandr Grytsov To: xen-devel@lists.xenproject.org Date: Tue, 18 Jul 2017 17:25:28 +0300 Message-Id: <1500387930-16317-12-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 11/13] libxl: change vtpm 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 Acked-by: Wei Liu --- tools/libxl/libxl.h | 12 ++- tools/libxl/libxl_vtpm.c | 231 +++++++++++++---------------------------------- tools/xl/xl_vtpm.c | 3 +- 3 files changed, 73 insertions(+), 173 deletions(-) diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 4a29b43..c169eff 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1580,9 +1580,6 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid, int *nb_vcpu, int *nr_cpus_out); void libxl_vcpuinfo_list_free(libxl_vcpuinfo *, int nr_vcpus); -void libxl_device_vtpm_list_free(libxl_device_vtpm*, int nr_vtpms); -void libxl_vtpminfo_list_free(libxl_vtpminfo *, int nr_vtpms); - /* * Devices * ======= @@ -1857,9 +1854,14 @@ int libxl_device_vtpm_destroy(libxl_ctx *ctx, uint32_t domid, const libxl_asyncop_how *ao_how) LIBXL_EXTERNAL_CALLERS_ONLY; -libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx, uint32_t domid, int *num); +libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx, + uint32_t domid, int *num) + LIBXL_EXTERNAL_CALLERS_ONLY; +void libxl_device_vtpm_list_free(libxl_device_vtpm*, int num) + LIBXL_EXTERNAL_CALLERS_ONLY; int libxl_device_vtpm_getinfo(libxl_ctx *ctx, uint32_t domid, - libxl_device_vtpm *vtpm, libxl_vtpminfo *vtpminfo); + libxl_device_vtpm *vtpm, libxl_vtpminfo *vtpminfo) + LIBXL_EXTERNAL_CALLERS_ONLY; /* Virtual displays */ int libxl_device_vdispl_add(libxl_ctx *ctx, uint32_t domid, diff --git a/tools/libxl/libxl_vtpm.c b/tools/libxl/libxl_vtpm.c index cbd5461..0661a30 100644 --- a/tools/libxl/libxl_vtpm.c +++ b/tools/libxl/libxl_vtpm.c @@ -17,7 +17,9 @@ #include "libxl_internal.h" -static int libxl__device_vtpm_setdefault(libxl__gc *gc, libxl_device_vtpm *vtpm) +static int libxl__device_vtpm_setdefault(libxl__gc *gc, uint32_t domid, + libxl_device_vtpm *vtpm, + bool hotplug) { int rc; if (libxl_uuid_is_nil(&vtpm->uuid)) { @@ -48,169 +50,73 @@ static void libxl__update_config_vtpm(libxl__gc *gc, libxl_device_vtpm *dst, libxl_uuid_copy(CTX, &dst->uuid, &src->uuid); } -static void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid, - libxl_device_vtpm *vtpm, - libxl__ao_device *aodev) +static int libxl__set_xenstore_vtpm(libxl__gc *gc, uint32_t domid, + libxl_device_vtpm *vtpm, + 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_vtpm vtpm_saved; - libxl__domain_userdata_lock *lock = NULL; - - libxl_domain_config_init(&d_config); - libxl_device_vtpm_init(&vtpm_saved); - libxl_device_vtpm_copy(CTX, &vtpm_saved, vtpm); + flexarray_append_pair(back, "handle", GCSPRINTF("%d", vtpm->devid)); + flexarray_append_pair(back, "uuid", + GCSPRINTF(LIBXL_UUID_FMT, + LIBXL_UUID_BYTES(vtpm->uuid))); + flexarray_append_pair(back, "resume", "False"); - rc = libxl__device_vtpm_setdefault(gc, vtpm); - if (rc) goto out; + flexarray_append_pair(front, "handle", GCSPRINTF("%d", vtpm->devid)); - front = flexarray_make(gc, 16, 1); - back = flexarray_make(gc, 16, 1); + return 0; +} - if (vtpm->devid == -1) { - if ((vtpm->devid = libxl__device_nextid(gc, domid, "vtpm")) < 0) { - rc = ERROR_FAIL; - goto out; - } - } - libxl__update_config_vtpm(gc, &vtpm_saved, vtpm); - - GCNEW(device); - rc = libxl__device_from_vtpm(gc, domid, vtpm, 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)); - flexarray_append(back, "handle"); - flexarray_append(back, GCSPRINTF("%d", vtpm->devid)); - - flexarray_append(back, "uuid"); - flexarray_append(back, GCSPRINTF(LIBXL_UUID_FMT, LIBXL_UUID_BYTES(vtpm->uuid))); - flexarray_append(back, "resume"); - flexarray_append(back, "False"); - - flexarray_append(front, "backend-id"); - flexarray_append(front, GCSPRINTF("%d", vtpm->backend_domid)); - flexarray_append(front, "state"); - flexarray_append(front, GCSPRINTF("%d", XenbusStateInitialising)); - flexarray_append(front, "handle"); - flexarray_append(front, GCSPRINTF("%d", vtpm->devid)); - - if (aodev->update_json) { - lock = libxl__lock_domain_userdata(gc, domid); - if (!lock) { - rc = ERROR_LOCK_FAIL; - goto out; - } +static void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid, + libxl_device_vtpm *vtpm, + libxl__ao_device *aodev) +{ + libxl__device_add_async(egc, domid, &libxl__vtpm_devtype, vtpm, aodev); +} - rc = libxl__get_domain_configuration(gc, domid, &d_config); - if (rc) goto out; +static int libxl__vtpm_from_xenstore(libxl__gc *gc, const char *libxl_path, + libxl_devid devid, + libxl_device_vtpm *vtpm) +{ + int rc; + char *be_path; + char *uuid; - DEVICE_ADD(vtpm, vtpms, domid, &vtpm_saved, COMPARE_DEVID, &d_config); + vtpm->devid = devid; - rc = libxl__dm_check_start(gc, &d_config, domid); - if (rc) goto out; - } + be_path = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/backend", libxl_path)); - 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; - } + rc = libxl__backendpath_parse_domid(gc, be_path, &vtpm->backend_domid); + if (rc) return rc; - if (aodev->update_json) { - rc = libxl__set_domain_configuration(gc, domid, &d_config); - if (rc) goto out; + uuid = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/uuid", be_path)); + if (uuid) { + if(libxl_uuid_from_string(&(vtpm->uuid), uuid)) { + LOGD(ERROR, vtpm->backend_domid, "%s/uuid is a malformed uuid?? " + "(%s) Probably a bug!!\n", be_path, uuid); + return ERROR_FAIL; } - - 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); - - rc = 0; -out: - libxl__xs_transaction_abort(gc, &t); - if (lock) libxl__unlock_domain_userdata(lock); - libxl_device_vtpm_dispose(&vtpm_saved); - libxl_domain_config_dispose(&d_config); - aodev->rc = rc; - if(rc) aodev->callback(egc, aodev); - return; + return 0; } libxl_device_vtpm *libxl_device_vtpm_list(libxl_ctx *ctx, uint32_t domid, int *num) { + libxl_device_vtpm *r; + GC_INIT(ctx); - libxl_device_vtpm* vtpms = NULL; - char *libxl_path; - char** dir = NULL; - unsigned int ndirs = 0; - int rc; - - *num = 0; - - libxl_path = GCSPRINTF("%s/device/vtpm", libxl__xs_libxl_path(gc, domid)); - dir = libxl__xs_directory(gc, XBT_NULL, libxl_path, &ndirs); - if (dir && ndirs) { - vtpms = malloc(sizeof(*vtpms) * ndirs); - libxl_device_vtpm* vtpm; - libxl_device_vtpm* end = vtpms + ndirs; - for(vtpm = vtpms; vtpm < end; ++vtpm, ++dir) { - char* tmp; - const char* be_path = libxl__xs_read(gc, XBT_NULL, - GCSPRINTF("%s/%s/backend", - libxl_path, *dir)); - - libxl_device_vtpm_init(vtpm); - - vtpm->devid = atoi(*dir); - - rc = libxl__backendpath_parse_domid(gc, be_path, - &vtpm->backend_domid); - if (rc) return NULL; - - tmp = libxl__xs_read(gc, XBT_NULL, GCSPRINTF("%s/uuid", libxl_path)); - if (tmp) { - if(libxl_uuid_from_string(&(vtpm->uuid), tmp)) { - LOGD(ERROR, domid, "%s/uuid is a malformed uuid?? (%s) Probably a bug!!\n", be_path, tmp); - free(vtpms); - return NULL; - } - } - } - } - *num = ndirs; + r = libxl__device_list(gc, &libxl__vtpm_devtype, domid, "vtpm", num); GC_FREE; - return vtpms; + + return r; +} + +void libxl_device_vtpm_list_free(libxl_device_vtpm* list, int num) +{ + libxl__device_list_free(&libxl__vtpm_devtype, list, num); } int libxl_device_vtpm_getinfo(libxl_ctx *ctx, @@ -282,11 +188,12 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx, int devid, libxl_device_vtpm *vtpm) { + GC_INIT(ctx); libxl_device_vtpm *vtpms; int nb, i; int rc; - vtpms = libxl_device_vtpm_list(ctx, domid, &nb); + vtpms = libxl__device_list(gc, &libxl__vtpm_devtype, domid, "vtpm", &nb); if (!vtpms) return ERROR_FAIL; @@ -302,7 +209,8 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx, } } - libxl_device_vtpm_list_free(vtpms, nb); + libxl__device_list_free(&libxl__vtpm_devtype, vtpms, nb); + GC_FREE; return rc; } @@ -315,11 +223,12 @@ static int libxl_device_vtpm_compare(libxl_device_vtpm *d1, int libxl_uuid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid, libxl_uuid* uuid, libxl_device_vtpm *vtpm) { + GC_INIT(ctx); libxl_device_vtpm *vtpms; int nb, i; int rc; - vtpms = libxl_device_vtpm_list(ctx, domid, &nb); + vtpms = libxl__device_list(gc, &libxl__vtpm_devtype, domid, "vtpm", &nb); if (!vtpms) return ERROR_FAIL; @@ -335,26 +244,11 @@ int libxl_uuid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid, } } - libxl_device_vtpm_list_free(vtpms, nb); + libxl__device_list_free(&libxl__vtpm_devtype, vtpms, nb); + GC_FREE; return rc; } -void libxl_vtpminfo_list_free(libxl_vtpminfo* list, int nr) -{ - int i; - for (i = 0; i < nr; i++) - libxl_vtpminfo_dispose(&list[i]); - free(list); -} - -void libxl_device_vtpm_list_free(libxl_device_vtpm* list, int nr) -{ - int i; - for (i = 0; i < nr; i++) - libxl_device_vtpm_dispose(&list[i]); - free(list); -} - static void libxl_device_vtpm_update_config(libxl__gc *gc, void *d, void *s) { libxl__update_config_vtpm(gc, d, s); @@ -363,11 +257,16 @@ static void libxl_device_vtpm_update_config(libxl__gc *gc, void *d, void *s) LIBXL_DEFINE_DEVICE_ADD(vtpm) static LIBXL_DEFINE_DEVICES_ADD(vtpm) LIBXL_DEFINE_DEVICE_REMOVE(vtpm) - -#define libxl__device_vtpm_update_devid NULL +static LIBXL_DEFINE_UPDATE_DEVID(vtpm, "vtpm") DEFINE_DEVICE_TYPE_STRUCT(vtpm, - .update_config = libxl_device_vtpm_update_config + .update_config = libxl_device_vtpm_update_config, + .from_xenstore = (int (*)(libxl__gc *, const char *, libxl_devid, void *)) + libxl__vtpm_from_xenstore, + .set_xenstore_config = (int (*)(libxl__gc *, uint32_t, void *, + flexarray_t *back, flexarray_t *front, + flexarray_t *ro_front)) + libxl__set_xenstore_vtpm ); /* diff --git a/tools/xl/xl_vtpm.c b/tools/xl/xl_vtpm.c index 6f56be0..0ba5041 100644 --- a/tools/xl/xl_vtpm.c +++ b/tools/xl/xl_vtpm.c @@ -105,9 +105,8 @@ int main_vtpmlist(int argc, char **argv) libxl_vtpminfo_dispose(&vtpminfo); } - libxl_device_vtpm_dispose(&vtpms[i]); } - free(vtpms); + libxl_device_vtpm_list_free(vtpms, nb); } return 0; }