From patchwork Tue Apr 2 17:30:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 233106 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5A50F2C00B2 for ; Wed, 3 Apr 2013 04:32:44 +1100 (EST) Received: from localhost ([::1]:55069 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN54c-0005YD-FQ for incoming@patchwork.ozlabs.org; Tue, 02 Apr 2013 13:32:42 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55549) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN547-0005P7-50 for qemu-devel@nongnu.org; Tue, 02 Apr 2013 13:32:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UN53t-0001xK-Gf for qemu-devel@nongnu.org; Tue, 02 Apr 2013 13:32:10 -0400 Received: from e8.ny.us.ibm.com ([32.97.182.138]:45157) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN53t-0001cj-As for qemu-devel@nongnu.org; Tue, 02 Apr 2013 13:31:57 -0400 Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 2 Apr 2013 13:30:47 -0400 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e8.ny.us.ibm.com (192.168.1.108) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 2 Apr 2013 13:30:46 -0400 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 0C81D38C8054 for ; Tue, 2 Apr 2013 13:30:45 -0400 (EDT) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r32HUijV25559044 for ; Tue, 2 Apr 2013 13:30:45 -0400 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r32HUhl4019607 for ; Tue, 2 Apr 2013 14:30:43 -0300 Received: from [9.2.141.150] (k-d941e-10.watson.ibm.com [9.2.141.150]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r32HUhM8019589; Tue, 2 Apr 2013 14:30:43 -0300 Message-ID: <1364923843.339.2.camel@d941e-10> From: Stefan Berger To: "qemu-devel@nongnu.org" Date: Tue, 02 Apr 2013 13:30:43 -0400 X-Mailer: Evolution 3.2.3 (3.2.3-3.fc16) Mime-Version: 1.0 X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13040217-9360-0000-0000-000011914777 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.182.138 Cc: coreyb@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH] Move TPM passthrough specific command line options to backend structure X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Move the TPM passthrough specific command line options to the passthrough backend implementation and attach them to the backend's interface structure. Add code to tpm.c for validating the TPM command line options. Signed-off-by: Stefan Berger --- tpm/tpm.c | 10 +++++++++- tpm/tpm_int.h | 8 ++++++++ tpm/tpm_passthrough.c | 16 ++++++++++++++++ vl.c | 15 --------------- 4 files changed, 33 insertions(+), 16 deletions(-) Index: qemu-git.pt/vl.c =================================================================== --- qemu-git.pt.orig/vl.c +++ qemu-git.pt/vl.c @@ -502,21 +502,6 @@ static QemuOptsList qemu_tpmdev_opts = { .implied_opt_name = "type", .head = QTAILQ_HEAD_INITIALIZER(qemu_tpmdev_opts.head), .desc = { - { - .name = "type", - .type = QEMU_OPT_STRING, - .help = "Type of TPM backend", - }, - { - .name = "cancel-path", - .type = QEMU_OPT_STRING, - .help = "Sysfs file entry for canceling TPM commands", - }, - { - .name = "path", - .type = QEMU_OPT_STRING, - .help = "Path to TPM device on the host", - }, { /* end of list */ } }, }; Index: qemu-git.pt/tpm/tpm.c =================================================================== --- qemu-git.pt.orig/tpm/tpm.c +++ qemu-git.pt/tpm/tpm.c @@ -146,7 +146,7 @@ static int configure_tpm(QemuOpts *opts) const char *id; const TPMDriverOps *be; TPMBackend *drv; - Error *local_err = NULL; + Error *local_err = NULL, *errp = NULL; if (!QLIST_EMPTY(&tpm_backends)) { error_report("Only one TPM is allowed.\n"); @@ -174,6 +174,14 @@ static int configure_tpm(QemuOpts *opts) return 1; } + /* validate backend specific opts */ + qemu_opts_validate(opts, be->opts, &errp); + if (error_is_set(&errp)) { + qerror_report_err(errp); + error_free(errp); + return 1; + } + drv = be->create(opts, id); if (!drv) { return 1; Index: qemu-git.pt/tpm/tpm_passthrough.c =================================================================== --- qemu-git.pt.orig/tpm/tpm_passthrough.c +++ qemu-git.pt/tpm/tpm_passthrough.c @@ -512,8 +512,24 @@ static void tpm_passthrough_destroy(TPMB g_free(tpm_pt->tpm_dev); } +static const QemuOptDesc tpm_passthrough_cmdline_opts[] = { + TPM_STANDARD_CMDLINE_OPTS, + { + .name = "cancel-path", + .type = QEMU_OPT_STRING, + .help = "Sysfs file entry for canceling TPM commands", + }, + { + .name = "path", + .type = QEMU_OPT_STRING, + .help = "Path to TPM device on the host", + }, + { /* end of list */ }, +}; + const TPMDriverOps tpm_passthrough_driver = { .type = TPM_TYPE_PASSTHROUGH, + .opts = tpm_passthrough_cmdline_opts, .desc = tpm_passthrough_create_desc, .create = tpm_passthrough_create, .destroy = tpm_passthrough_destroy, Index: qemu-git.pt/tpm/tpm_int.h =================================================================== --- qemu-git.pt.orig/tpm/tpm_int.h +++ qemu-git.pt/tpm/tpm_int.h @@ -40,6 +40,7 @@ typedef void (TPMRecvDataCB)(TPMState *, struct TPMDriverOps { enum TpmType type; + const QemuOptDesc *opts; /* get a descriptive text of the backend to display to the user */ const char *(*desc)(void); @@ -64,6 +65,13 @@ struct TPMDriverOps { bool (*get_tpm_established_flag)(TPMBackend *t); }; +#define TPM_STANDARD_CMDLINE_OPTS \ + { \ + .name = "type", \ + .type = QEMU_OPT_STRING, \ + .help = "Type of TPM backend", \ + } + struct tpm_req_hdr { uint16_t tag; uint32_t len;