ia64/xen-unstable

changeset 12151:3d4a027bd04b

C bindings adding some basic vTPM extensions to the API that
make its handling similar to that of VBD etc.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author Ewan Mellor <ewan@xensource.com>
date Wed Oct 25 17:30:17 2006 +0100 (2006-10-25)
parents 6e78bed60b85
children a2d6e4a53e7a
files tools/libxen/Makefile tools/libxen/include/xen_vm.h tools/libxen/include/xen_vtpm.h tools/libxen/include/xen_vtpm_decl.h tools/libxen/src/xen_vm.c tools/libxen/src/xen_vtpm.c
line diff
     1.1 --- a/tools/libxen/Makefile	Wed Oct 25 16:06:29 2006 +0100
     1.2 +++ b/tools/libxen/Makefile	Wed Oct 25 17:30:17 2006 +0100
     1.3 @@ -19,7 +19,7 @@
     1.4  CFLAGS = -Iinclude                     \
     1.5           $(shell xml2-config --cflags) \
     1.6           $(shell curl-config --cflags) \
     1.7 -         -W -Wall -Werror -std=c99 -O2 -fPIC
     1.8 +         -W -Wall -Wmissing-prototypes -Werror -std=c99 -O2 -fPIC
     1.9  
    1.10  LDFLAGS = $(shell xml2-config --libs) \
    1.11            $(shell curl-config --libs)
     2.1 --- a/tools/libxen/include/xen_vm.h	Wed Oct 25 16:06:29 2006 +0100
     2.2 +++ b/tools/libxen/include/xen_vm.h	Wed Oct 25 17:30:17 2006 +0100
     2.3 @@ -29,6 +29,7 @@
     2.4  #include "xen_string_string_map.h"
     2.5  #include "xen_vbd_decl.h"
     2.6  #include "xen_vif_decl.h"
     2.7 +#include "xen_vtpm_decl.h"
     2.8  #include "xen_vm_decl.h"
     2.9  #include "xen_vm_power_state.h"
    2.10  
    2.11 @@ -406,17 +407,10 @@ xen_vm_get_vbds(xen_session *session, xe
    2.12  
    2.13  
    2.14  /**
    2.15 - * Get the TPM/instance field of the given VM.
    2.16 + * Get the VTPMs field of the given VM.
    2.17   */
    2.18  extern bool
    2.19 -xen_vm_get_tpm_instance(xen_session *session, uint64_t *result, xen_vm vm);
    2.20 -
    2.21 -
    2.22 -/**
    2.23 - * Get the TPM/backend field of the given VM.
    2.24 - */
    2.25 -extern bool
    2.26 -xen_vm_get_tpm_backend(xen_session *session, uint64_t *result, xen_vm vm);
    2.27 +xen_vm_get_vtpms(xen_session *session, xen_vtpm *result, xen_vm vm);
    2.28  
    2.29  
    2.30  /**
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/libxen/include/xen_vtpm.h	Wed Oct 25 17:30:17 2006 +0100
     3.3 @@ -0,0 +1,202 @@
     3.4 +/*
     3.5 + * Copyright (c) 2006, XenSource Inc.
     3.6 + * Copyright (c) 2006, IBM Corp.
     3.7 + *
     3.8 + * This library is free software; you can redistribute it and/or
     3.9 + * modify it under the terms of the GNU Lesser General Public
    3.10 + * License as published by the Free Software Foundation; either
    3.11 + * version 2.1 of the License, or (at your option) any later version.
    3.12 + *
    3.13 + * This library is distributed in the hope that it will be useful,
    3.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 + * Lesser General Public License for more details.
    3.17 + *
    3.18 + * You should have received a copy of the GNU Lesser General Public
    3.19 + * License along with this library; if not, write to the Free Software
    3.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
    3.21 + */
    3.22 +
    3.23 +#ifndef XEN_VTPM_H
    3.24 +#define XEN_VTPM_H
    3.25 +
    3.26 +#include "xen_common.h"
    3.27 +#include "xen_driver_type.h"
    3.28 +#include "xen_vtpm_decl.h"
    3.29 +#include "xen_vm_decl.h"
    3.30 +
    3.31 +
    3.32 +/*
    3.33 + * The VTPM class.
    3.34 + *
    3.35 + * A virtual TPM device.
    3.36 + */
    3.37 +
    3.38 +
    3.39 +/**
    3.40 + * Free the given xen_vtpm.  The given handle must have been allocated
    3.41 + * by this library.
    3.42 + */
    3.43 +extern void
    3.44 +xen_vtpm_free(xen_vtpm vtpm);
    3.45 +
    3.46 +
    3.47 +typedef struct xen_vtpm_set
    3.48 +{
    3.49 +    size_t size;
    3.50 +    xen_vtpm *contents[];
    3.51 +} xen_vtpm_set;
    3.52 +
    3.53 +/**
    3.54 + * Allocate a xen_vtpm_set of the given size.
    3.55 + */
    3.56 +extern xen_vtpm_set *
    3.57 +xen_vtpm_set_alloc(size_t size);
    3.58 +
    3.59 +/**
    3.60 + * Free the given xen_vtpm_set.  The given set must have been allocated
    3.61 + * by this library.
    3.62 + */
    3.63 +extern void
    3.64 +xen_vtpm_set_free(xen_vtpm_set *set);
    3.65 +
    3.66 +
    3.67 +typedef struct xen_vtpm_record
    3.68 +{
    3.69 +    xen_vtpm handle;
    3.70 +    char *uuid;
    3.71 +    struct xen_vm_record_opt *vm;
    3.72 +    struct xen_vm_record_opt *backend;
    3.73 +    int instance;
    3.74 +    enum xen_driver_type driver;
    3.75 +} xen_vtpm_record;
    3.76 +
    3.77 +/**
    3.78 + * Allocate a xen_vtpm_record.
    3.79 + */
    3.80 +extern xen_vtpm_record *
    3.81 +xen_vtpm_record_alloc(void);
    3.82 +
    3.83 +/**
    3.84 + * Free the given xen_vtpm_record, and all referenced values.  The given
    3.85 + * record must have been allocated by this library.
    3.86 + */
    3.87 +extern void
    3.88 +xen_vtpm_record_free(xen_vtpm_record *record);
    3.89 +
    3.90 +
    3.91 +typedef struct xen_vtpm_record_opt
    3.92 +{
    3.93 +    bool is_record;
    3.94 +    union
    3.95 +    {
    3.96 +        xen_vtpm handle;
    3.97 +        xen_vtpm_record *record;
    3.98 +    } u;
    3.99 +} xen_vtpm_record_opt;
   3.100 +
   3.101 +/**
   3.102 + * Allocate a xen_vtpm_record_opt.
   3.103 + */
   3.104 +extern xen_vtpm_record_opt *
   3.105 +xen_vtpm_record_opt_alloc(void);
   3.106 +
   3.107 +/**
   3.108 + * Free the given xen_vtpm_record_opt, and all referenced values.  The
   3.109 + * given record_opt must have been allocated by this library.
   3.110 + */
   3.111 +extern void
   3.112 +xen_vtpm_record_opt_free(xen_vtpm_record_opt *record_opt);
   3.113 +
   3.114 +
   3.115 +typedef struct xen_vtpm_record_set
   3.116 +{
   3.117 +    size_t size;
   3.118 +    xen_vtpm_record *contents[];
   3.119 +} xen_vtpm_record_set;
   3.120 +
   3.121 +/**
   3.122 + * Allocate a xen_vtpm_record_set of the given size.
   3.123 + */
   3.124 +extern xen_vtpm_record_set *
   3.125 +xen_vtpm_record_set_alloc(size_t size);
   3.126 +
   3.127 +/**
   3.128 + * Free the given xen_vtpm_record_set, and all referenced values.  The
   3.129 + * given set must have been allocated by this library.
   3.130 + */
   3.131 +extern void
   3.132 +xen_vtpm_record_set_free(xen_vtpm_record_set *set);
   3.133 +
   3.134 +
   3.135 +
   3.136 +typedef struct xen_vtpm_record_opt_set
   3.137 +{
   3.138 +    size_t size;
   3.139 +    xen_vtpm_record_opt *contents[];
   3.140 +} xen_vtpm_record_opt_set;
   3.141 +
   3.142 +/**
   3.143 + * Allocate a xen_vtpm_record_opt_set of the given size.
   3.144 + */
   3.145 +extern xen_vtpm_record_opt_set *
   3.146 +xen_vtpm_record_opt_set_alloc(size_t size);
   3.147 +
   3.148 +/**
   3.149 + * Free the given xen_vtpm_record_opt_set, and all referenced values.
   3.150 + * The given set must have been allocated by this library.
   3.151 + */
   3.152 +extern void
   3.153 +xen_vtpm_record_opt_set_free(xen_vtpm_record_opt_set *set);
   3.154 +
   3.155 +
   3.156 +/**
   3.157 + * Get the current state of the given VTPM.  !!!
   3.158 + */
   3.159 +extern bool
   3.160 +xen_vtpm_get_record(xen_session *session, xen_vtpm_record **result, xen_vtpm vtpm);
   3.161 +
   3.162 +
   3.163 +/**
   3.164 + * Get a reference to the object with the specified UUID.  !!!
   3.165 + */
   3.166 +extern bool
   3.167 +xen_vtpm_get_by_uuid(xen_session *session, xen_vtpm *result, char *uuid);
   3.168 +
   3.169 +
   3.170 +/**
   3.171 + * Create a new VTPM instance, and return its handle.
   3.172 + */
   3.173 +extern bool
   3.174 +xen_vtpm_create(xen_session *session, xen_vtpm *result, xen_vtpm_record *record);
   3.175 +
   3.176 +
   3.177 +/**
   3.178 + * Get the uuid field of the given VTPM.
   3.179 + */
   3.180 +extern bool
   3.181 +xen_vtpm_get_uuid(xen_session *session, char **result, xen_vtpm vtpm);
   3.182 +
   3.183 +
   3.184 +/**
   3.185 + * Get the VM field of the given VTPM.
   3.186 + */
   3.187 +extern bool
   3.188 +xen_vtpm_get_vm(xen_session *session, xen_vm *result, xen_vtpm vtpm);
   3.189 +
   3.190 +
   3.191 +/**
   3.192 + * Get the backend field of the given VTPM.
   3.193 + */
   3.194 +extern bool
   3.195 +xen_vtpm_get_backend(xen_session *session, xen_vm *result, xen_vtpm vtpm);
   3.196 +
   3.197 +
   3.198 +/**
   3.199 + * Get the instance field of the given VTPM.
   3.200 + */
   3.201 +extern bool
   3.202 +xen_vtpm_get_instance(xen_session *session, int *result, xen_vtpm vtpm);
   3.203 +
   3.204 +
   3.205 +#endif
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/libxen/include/xen_vtpm_decl.h	Wed Oct 25 17:30:17 2006 +0100
     4.3 @@ -0,0 +1,31 @@
     4.4 +/*
     4.5 + * Copyright (c) 2006, XenSource Inc.
     4.6 + * Copyright (c) 2006, IBM Corp.
     4.7 + *
     4.8 + * This library is free software; you can redistribute it and/or
     4.9 + * modify it under the terms of the GNU Lesser General Public
    4.10 + * License as published by the Free Software Foundation; either
    4.11 + * version 2.1 of the License, or (at your option) any later version.
    4.12 + *
    4.13 + * This library is distributed in the hope that it will be useful,
    4.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    4.16 + * Lesser General Public License for more details.
    4.17 + *
    4.18 + * You should have received a copy of the GNU Lesser General Public
    4.19 + * License along with this library; if not, write to the Free Software
    4.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
    4.21 + */
    4.22 +
    4.23 +#ifndef XEN_VTPM_DECL_H
    4.24 +#define XEN_VTPM_DECL_H
    4.25 +
    4.26 +typedef void *xen_vtpm;
    4.27 +
    4.28 +struct xen_vtpm_set;
    4.29 +struct xen_vtpm_record;
    4.30 +struct xen_vtpm_record_set;
    4.31 +struct xen_vtpm_record_opt;
    4.32 +struct xen_vtpm_record_opt_set;
    4.33 +
    4.34 +#endif
     5.1 --- a/tools/libxen/src/xen_vm.c	Wed Oct 25 16:06:29 2006 +0100
     5.2 +++ b/tools/libxen/src/xen_vm.c	Wed Oct 25 17:30:17 2006 +0100
     5.3 @@ -32,6 +32,7 @@
     5.4  #include "xen_string_string_map.h"
     5.5  #include "xen_vbd.h"
     5.6  #include "xen_vif.h"
     5.7 +#include "xen_vtpm.h"
     5.8  #include "xen_vm.h"
     5.9  #include "xen_vm_power_state_internal.h"
    5.10  
    5.11 @@ -125,12 +126,6 @@ static const struct_member xen_vm_record
    5.12          { .key = "vbds",
    5.13            .type = &abstract_type_ref_set,
    5.14            .offset = offsetof(xen_vm_record, vbds) },
    5.15 -        { .key = "tpm_instance",
    5.16 -          .type = &abstract_type_int,
    5.17 -          .offset = offsetof(xen_vm_record, tpm_instance) },
    5.18 -        { .key = "tpm_backend",
    5.19 -          .type = &abstract_type_int,
    5.20 -          .offset = offsetof(xen_vm_record, tpm_backend) },
    5.21          { .key = "bios_boot",
    5.22            .type = &abstract_type_string,
    5.23            .offset = offsetof(xen_vm_record, bios_boot) },
    5.24 @@ -711,7 +706,7 @@ xen_vm_get_vbds(xen_session *session, xe
    5.25  
    5.26  
    5.27  bool
    5.28 -xen_vm_get_tpm_instance(xen_session *session, uint64_t *result, xen_vm vm)
    5.29 +xen_vm_get_vtpms(xen_session *session, xen_vtpm *result, xen_vm vm)
    5.30  {
    5.31      abstract_value param_values[] =
    5.32          {
    5.33 @@ -719,25 +714,10 @@ xen_vm_get_tpm_instance(xen_session *ses
    5.34                .u.string_val = vm }
    5.35          };
    5.36  
    5.37 -    abstract_type result_type = abstract_type_int;
    5.38 -
    5.39 -    XEN_CALL_("VM.get_tpm_instance");
    5.40 -    return session->ok;
    5.41 -}
    5.42 -
    5.43 +    abstract_type result_type = abstract_type_string_set;
    5.44  
    5.45 -bool
    5.46 -xen_vm_get_tpm_backend(xen_session *session, uint64_t *result, xen_vm vm)
    5.47 -{
    5.48 -    abstract_value param_values[] =
    5.49 -        {
    5.50 -            { .type = &abstract_type_string,
    5.51 -              .u.string_val = vm }
    5.52 -        };
    5.53 -
    5.54 -    abstract_type result_type = abstract_type_int;
    5.55 -
    5.56 -    XEN_CALL_("VM.get_tpm_backend");
    5.57 +    *result = NULL;
    5.58 +    XEN_CALL_("VM.get_vtpms");
    5.59      return session->ok;
    5.60  }
    5.61  
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/libxen/src/xen_vtpm.c	Wed Oct 25 17:30:17 2006 +0100
     6.3 @@ -0,0 +1,186 @@
     6.4 +/*
     6.5 + * Copyright (c) 2006, XenSource Inc.
     6.6 + * Copyright (c) 2006, IBM Corp.
     6.7 + *
     6.8 + * This library is free software; you can redistribute it and/or
     6.9 + * modify it under the terms of the GNU Lesser General Public
    6.10 + * License as published by the Free Software Foundation; either
    6.11 + * version 2.1 of the License, or (at your option) any later version.
    6.12 + *
    6.13 + * This library is distributed in the hope that it will be useful,
    6.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 + * Lesser General Public License for more details.
    6.17 + *
    6.18 + * You should have received a copy of the GNU Lesser General Public
    6.19 + * License along with this library; if not, write to the Free Software
    6.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
    6.21 + */
    6.22 +
    6.23 +
    6.24 +#include <stddef.h>
    6.25 +#include <stdlib.h>
    6.26 +
    6.27 +#include "xen_common.h"
    6.28 +#include "xen_driver_type_internal.h"
    6.29 +#include "xen_internal.h"
    6.30 +#include "xen_vtpm.h"
    6.31 +#include "xen_vm.h"
    6.32 +
    6.33 +
    6.34 +XEN_FREE(xen_vtpm)
    6.35 +XEN_SET_ALLOC_FREE(xen_vtpm)
    6.36 +
    6.37 +
    6.38 +static const struct_member xen_vtpm_record_struct_members[] =
    6.39 +    {
    6.40 +        { .key = "uuid",
    6.41 +          .type = &abstract_type_string,
    6.42 +          .offset = offsetof(xen_vtpm_record, uuid) },
    6.43 +        { .key = "vm",
    6.44 +          .type = &abstract_type_ref,
    6.45 +          .offset = offsetof(xen_vtpm_record, vm) },
    6.46 +        { .key = "backend",
    6.47 +          .type = &abstract_type_ref,
    6.48 +          .offset = offsetof(xen_vtpm_record, backend) },
    6.49 +        { .key = "driver",
    6.50 +          .type = &xen_driver_type_abstract_type_,
    6.51 +          .offset = offsetof(xen_vtpm_record, driver) },
    6.52 +    };
    6.53 +
    6.54 +const abstract_type xen_vtpm_record_abstract_type_ =
    6.55 +    {
    6.56 +       .typename = STRUCT,
    6.57 +       .struct_size = sizeof(xen_vtpm_record),
    6.58 +       .member_count =
    6.59 +           sizeof(xen_vtpm_record_struct_members) / sizeof(struct_member),
    6.60 +       .members = xen_vtpm_record_struct_members
    6.61 +    };
    6.62 +
    6.63 +
    6.64 +void
    6.65 +xen_vtpm_record_free(xen_vtpm_record *record)
    6.66 +{
    6.67 +    free(record->handle);
    6.68 +    free(record->uuid);
    6.69 +    xen_vm_record_opt_free(record->vm);
    6.70 +    xen_vm_record_opt_free(record->backend);
    6.71 +    free(record);
    6.72 +}
    6.73 +
    6.74 +
    6.75 +bool
    6.76 +xen_vtpm_get_record(xen_session *session, xen_vtpm_record **result, xen_vtpm vtpm)
    6.77 +{
    6.78 +    abstract_value param_values[] =
    6.79 +        {
    6.80 +            { .type = &abstract_type_string,
    6.81 +              .u.string_val = vtpm }
    6.82 +        };
    6.83 +
    6.84 +    abstract_type result_type = xen_vtpm_record_abstract_type_;
    6.85 +
    6.86 +    *result = NULL;
    6.87 +    XEN_CALL_("VTPM.get_record");
    6.88 +
    6.89 +    if (session->ok)
    6.90 +    {
    6.91 +       (*result)->handle = xen_strdup_((*result)->uuid);
    6.92 +    }
    6.93 +
    6.94 +    return session->ok;
    6.95 +}
    6.96 +
    6.97 +
    6.98 +bool
    6.99 +xen_vtpm_get_by_uuid(xen_session *session, xen_vtpm *result, char *uuid)
   6.100 +{
   6.101 +    abstract_value param_values[] =
   6.102 +        {
   6.103 +            { .type = &abstract_type_string,
   6.104 +              .u.string_val = uuid }
   6.105 +        };
   6.106 +
   6.107 +    abstract_type result_type = abstract_type_string;
   6.108 +
   6.109 +    *result = NULL;
   6.110 +    XEN_CALL_("VTPM.get_by_uuid");
   6.111 +    return session->ok;
   6.112 +}
   6.113 +
   6.114 +
   6.115 +bool
   6.116 +xen_vtpm_create(xen_session *session, xen_vtpm *result, xen_vtpm_record *record)
   6.117 +{
   6.118 +    abstract_value param_values[] =
   6.119 +        {
   6.120 +            { .type = &xen_vtpm_record_abstract_type_,
   6.121 +              .u.struct_val = record }
   6.122 +        };
   6.123 +
   6.124 +    abstract_type result_type = abstract_type_string;
   6.125 +
   6.126 +    *result = NULL;
   6.127 +    XEN_CALL_("VTPM.create");
   6.128 +    return session->ok;
   6.129 +}
   6.130 +
   6.131 +
   6.132 +bool
   6.133 +xen_vtpm_get_vm(xen_session *session, xen_vm *result, xen_vtpm vtpm)
   6.134 +{
   6.135 +    abstract_value param_values[] =
   6.136 +        {
   6.137 +            { .type = &abstract_type_string,
   6.138 +              .u.string_val = vtpm }
   6.139 +        };
   6.140 +
   6.141 +    abstract_type result_type = abstract_type_string;
   6.142 +
   6.143 +    *result = NULL;
   6.144 +    XEN_CALL_("VTPM.get_vm");
   6.145 +    return session->ok;
   6.146 +}
   6.147 +
   6.148 +
   6.149 +bool
   6.150 +xen_vtpm_get_backend(xen_session *session, xen_vm *result, xen_vtpm vtpm)
   6.151 +{
   6.152 +    abstract_value param_values[] =
   6.153 +        {
   6.154 +            { .type = &abstract_type_string,
   6.155 +              .u.string_val = vtpm }
   6.156 +        };
   6.157 +
   6.158 +    abstract_type result_type = abstract_type_string;
   6.159 +
   6.160 +    *result = NULL;
   6.161 +    XEN_CALL_("VTPM.get_backend");
   6.162 +    return session->ok;
   6.163 +}
   6.164 +
   6.165 +
   6.166 +bool
   6.167 +xen_vtpm_get_instance(xen_session *session, int *result, xen_vtpm vtpm)
   6.168 +{
   6.169 +    abstract_value param_values[] =
   6.170 +        {
   6.171 +            { .type = &abstract_type_string,
   6.172 +              .u.string_val = vtpm }
   6.173 +        };
   6.174 +
   6.175 +    abstract_type result_type = abstract_type_int;
   6.176 +
   6.177 +    XEN_CALL_("VTPM.get_instance");
   6.178 +    return session->ok;
   6.179 +}
   6.180 +
   6.181 +
   6.182 +bool
   6.183 +xen_vtpm_get_uuid(xen_session *session, char **result, xen_vtpm vtpm)
   6.184 +{
   6.185 +    *result = session->ok ? xen_strdup_((char *)vtpm) : NULL;
   6.186 +    return session->ok;
   6.187 +}
   6.188 +
   6.189 +