debuggers.hg
changeset 13761:7fdfa020d4ed
Align vTPM support in the Xen-API, documentation and lib-xen
(after the recent changes).
Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
(after the recent changes).
Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author | kaf24@localhost.localdomain |
---|---|
date | Tue Jan 30 14:51:05 2007 +0000 (2007-01-30) |
parents | 8f1921600cfd |
children | 2f3794098e22 |
files | docs/xen-api/xenapi-datamodel.tex tools/libxen/include/xen_vtpm.h tools/libxen/src/xen_vtpm.c tools/python/scripts/xapi.py tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendDomainInfo.py tools/xm-test/tests/vtpm/09_vtpm-xapi.py |
line diff
1.1 --- a/docs/xen-api/xenapi-datamodel.tex Tue Jan 30 14:20:00 2007 +0000 1.2 +++ b/docs/xen-api/xenapi-datamodel.tex Tue Jan 30 14:51:05 2007 +0000 1.3 @@ -10119,38 +10119,6 @@ value of the field 1.4 \vspace{0.3cm} 1.5 \vspace{0.3cm} 1.6 \vspace{0.3cm} 1.7 -\subsubsection{RPC name:~get\_instance} 1.8 - 1.9 -{\bf Overview:} 1.10 -Get the instance field of the given VTPM. 1.11 - 1.12 - \noindent {\bf Signature:} 1.13 -\begin{verbatim} int get_instance (session_id s, VTPM ref self)\end{verbatim} 1.14 - 1.15 - 1.16 -\noindent{\bf Arguments:} 1.17 - 1.18 - 1.19 -\vspace{0.3cm} 1.20 -\begin{tabular}{|c|c|p{7cm}|} 1.21 - \hline 1.22 -{\bf type} & {\bf name} & {\bf description} \\ \hline 1.23 -{\tt VTPM ref } & self & reference to the object \\ \hline 1.24 - 1.25 -\end{tabular} 1.26 - 1.27 -\vspace{0.3cm} 1.28 - 1.29 - \noindent {\bf Return Type:} 1.30 -{\tt 1.31 -int 1.32 -} 1.33 - 1.34 - 1.35 -value of the field 1.36 -\vspace{0.3cm} 1.37 -\vspace{0.3cm} 1.38 -\vspace{0.3cm} 1.39 \subsubsection{RPC name:~create} 1.40 1.41 {\bf Overview:}
2.1 --- a/tools/libxen/include/xen_vtpm.h Tue Jan 30 14:20:00 2007 +0000 2.2 +++ b/tools/libxen/include/xen_vtpm.h Tue Jan 30 14:51:05 2007 +0000 2.3 @@ -196,12 +196,4 @@ xen_vtpm_get_vm(xen_session *session, xe 2.4 extern bool 2.5 xen_vtpm_get_backend(xen_session *session, xen_vm *result, xen_vtpm vtpm); 2.6 2.7 - 2.8 -/** 2.9 - * Get the instance field of the given VTPM. 2.10 - */ 2.11 -extern bool 2.12 -xen_vtpm_get_instance(xen_session *session, int64_t *result, xen_vtpm vtpm); 2.13 - 2.14 - 2.15 #endif
3.1 --- a/tools/libxen/src/xen_vtpm.c Tue Jan 30 14:20:00 2007 +0000 3.2 +++ b/tools/libxen/src/xen_vtpm.c Tue Jan 30 14:51:05 2007 +0000 3.3 @@ -47,9 +47,6 @@ static const struct_member xen_vtpm_reco 3.4 { .key = "backend", 3.5 .type = &abstract_type_ref, 3.6 .offset = offsetof(xen_vtpm_record, backend) }, 3.7 - { .key = "instance", 3.8 - .type = &abstract_type_int, 3.9 - .offset = offsetof(xen_vtpm_record, instance) } 3.10 }; 3.11 3.12 const abstract_type xen_vtpm_record_abstract_type_ = 3.13 @@ -183,22 +180,6 @@ xen_vtpm_get_backend(xen_session *sessio 3.14 3.15 3.16 bool 3.17 -xen_vtpm_get_instance(xen_session *session, int64_t *result, xen_vtpm vtpm) 3.18 -{ 3.19 - abstract_value param_values[] = 3.20 - { 3.21 - { .type = &abstract_type_string, 3.22 - .u.string_val = vtpm } 3.23 - }; 3.24 - 3.25 - abstract_type result_type = abstract_type_int; 3.26 - 3.27 - XEN_CALL_("VTPM.get_instance"); 3.28 - return session->ok; 3.29 -} 3.30 - 3.31 - 3.32 -bool 3.33 xen_vtpm_get_uuid(xen_session *session, char **result, xen_vtpm vtpm) 3.34 { 3.35 *result = session->ok ? xen_strdup_((char *)vtpm) : NULL;
4.1 --- a/tools/python/scripts/xapi.py Tue Jan 30 14:20:00 2007 +0000 4.2 +++ b/tools/python/scripts/xapi.py Tue Jan 30 14:51:05 2007 +0000 4.3 @@ -678,14 +678,6 @@ def xapi_vtpm_create(args, async = False 4.4 print "Creating vTPM with cfg = %s" % cfg 4.5 vtpm_uuid = execute(server, 'VTPM.create', (session, cfg)) 4.6 print "Done. (%s)" % vtpm_uuid 4.7 - vtpm_id = execute(server, 'VTPM.get_instance', (session, vtpm_uuid)) 4.8 - print "Has instance number '%s'" % vtpm_id 4.9 - vtpm_be = execute(server, 'VTPM.get_backend', (session, vtpm_uuid)) 4.10 - print "Has backend in '%s'" % vtpm_be 4.11 - driver = execute(server, 'VTPM.get_driver', (session, vtpm_uuid)) 4.12 - print "Has driver type '%s'" % driver 4.13 - vtpm_rec = execute(server, 'VTPM.get_record', (session, vtpm_uuid)) 4.14 - print "Has vtpm record '%s'" % vtpm_rec 4.15 4.16 4.17 def xapi_pif_list(args, async = False):
5.1 --- a/tools/python/xen/xend/XendAPI.py Tue Jan 30 14:20:00 2007 +0000 5.2 +++ b/tools/python/xen/xend/XendAPI.py Tue Jan 30 14:51:05 2007 +0000 5.3 @@ -1735,8 +1735,7 @@ class XendAPI(object): 5.4 5.5 VTPM_attr_rw = [ ] 5.6 VTPM_attr_ro = ['VM', 5.7 - 'backend', 5.8 - 'instance'] 5.9 + 'backend'] 5.10 5.11 VTPM_attr_inst = VTPM_attr_rw 5.12 5.13 @@ -1753,27 +1752,14 @@ class XendAPI(object): 5.14 return xen_api_error(['VTPM_HANDLE_INVALID', vtpm_ref]) 5.15 valid_vtpm_keys = self.VTPM_attr_ro + self.VTPM_attr_rw + \ 5.16 self.Base_attr_ro + self.Base_attr_rw 5.17 + return_cfg = {} 5.18 for k in cfg.keys(): 5.19 - if k not in valid_vtpm_keys: 5.20 - del cfg[k] 5.21 + if k in valid_vtpm_keys: 5.22 + return_cfg[k] = cfg[k] 5.23 5.24 - return xen_api_success(cfg) 5.25 + return xen_api_success(return_cfg) 5.26 5.27 # Class Functions 5.28 - def VTPM_get_instance(self, session, vtpm_ref): 5.29 - xendom = XendDomain.instance() 5.30 - vm = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref) 5.31 - if not vm: 5.32 - return xen_api_error(['VTPM_HANDLE_INVALID', vtpm_ref]) 5.33 - cfg = vm.get_dev_xenapi_config('vtpm', vtpm_ref) 5.34 - if not cfg: 5.35 - return xen_api_error(['VTPM_HANDLE_INVALID', vtpm_ref]) 5.36 - if cfg.has_key('instance'): 5.37 - instance = cfg['instance'] 5.38 - else: 5.39 - instance = -1 5.40 - return xen_api_success(instance) 5.41 - 5.42 def VTPM_get_backend(self, session, vtpm_ref): 5.43 xendom = XendDomain.instance() 5.44 vm = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref) 5.45 @@ -1782,11 +1768,9 @@ class XendAPI(object): 5.46 cfg = vm.get_dev_xenapi_config('vtpm', vtpm_ref) 5.47 if not cfg: 5.48 return xen_api_error(['VTPM_HANDLE_INVALID', vtpm_ref]) 5.49 - if cfg.has_key('backend'): 5.50 - backend = cfg['backend'] 5.51 - else: 5.52 - backend = "Domain-0" 5.53 - return xen_api_success(backend) 5.54 + if not cfg.has_key('backend'): 5.55 + return xen_api_error(['VTPM backend not set']) 5.56 + return xen_api_success(cfg['backend']) 5.57 5.58 def VTPM_get_VM(self, session, vtpm_ref): 5.59 xendom = XendDomain.instance() 5.60 @@ -1795,12 +1779,18 @@ class XendAPI(object): 5.61 5.62 def VTPM_destroy(self, session, vtpm_ref): 5.63 xendom = XendDomain.instance() 5.64 - vm = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref) 5.65 - if not vm: 5.66 - return xen_api_error(['VTPM_HANDLE_INVALID', vtpm_ref]) 5.67 - 5.68 - vm.destroy_vtpm(vtpm_ref) 5.69 - return xen_api_success_void() 5.70 + dom = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref) 5.71 + if dom: 5.72 + if dom.state != XEN_API_VM_POWER_STATE_HALTED: 5.73 + vm_ref = dom.get_dev_property('vtpm', vtpm_ref, 'VM') 5.74 + return xen_api_error(['VM_BAD_POWER_STATE', vm_ref, 5.75 + XendDomain.POWER_STATE_NAMES[XEN_API_VM_POWER_STATE_HALTED], 5.76 + XendDomain.POWER_STATE_NAMES[dom.state]]) 5.77 + from xen.xend.server import tpmif 5.78 + tpmif.destroy_vtpmstate(dom.getName()) 5.79 + return xen_api_success(True) 5.80 + else: 5.81 + return xen_api_error(['VM_HANDLE_INVALID', vtpm_struct['VM']]) 5.82 5.83 # class methods 5.84 def VTPM_create(self, session, vtpm_struct):
6.1 --- a/tools/python/xen/xend/XendDomainInfo.py Tue Jan 30 14:20:00 2007 +0000 6.2 +++ b/tools/python/xen/xend/XendDomainInfo.py Tue Jan 30 14:51:05 2007 +0000 6.3 @@ -2125,7 +2125,10 @@ class XendDomainInfo: 6.4 config['mode'] = 'RW' 6.5 6.6 if dev_class == 'vtpm': 6.7 - config['driver'] = 'paravirtualised' # TODO 6.8 + if not config.has_type('type'): 6.9 + config['type'] = 'paravirtualised' # TODO 6.10 + if not config.has_key('backend'): 6.11 + config['backend'] = "00000000-0000-0000-0000-000000000000" 6.12 6.13 return config 6.14
7.1 --- a/tools/xm-test/tests/vtpm/09_vtpm-xapi.py Tue Jan 30 14:20:00 2007 +0000 7.2 +++ b/tools/xm-test/tests/vtpm/09_vtpm-xapi.py Tue Jan 30 14:51:05 2007 +0000 7.3 @@ -4,14 +4,22 @@ 7.4 # Author: Stefan Berger <stefanb@us.ibm.com> 7.5 7.6 # Test to test the vtpm class through the Xen-API 7.7 +# 7.8 +# Tested methods: 7.9 +# VTPM: get_uuid, get_backend, get_by_uuid, get_record 7.10 +# create, destroy, get_VM 7.11 +# VM: get_VTPMS 7.12 7.13 from XmTestLib import xapi 7.14 from XmTestLib.XenAPIDomain import XmTestAPIDomain 7.15 from XmTestLib import * 7.16 +from xen.xend import XendDomain 7.17 from vtpm_utils import * 7.18 import commands 7.19 import os 7.20 7.21 +VTPM_RECORD_KEYS = [ 'backend', 'VM', 'uuid' ] 7.22 + 7.23 try: 7.24 # XmTestAPIDomain tries to establish a connection to XenD 7.25 domain = XmTestAPIDomain() 7.26 @@ -20,52 +28,131 @@ except Exception, e: 7.27 vm_uuid = domain.get_uuid() 7.28 7.29 vtpmcfg = {} 7.30 -vtpmcfg['type'] = "paravirtualised" 7.31 -vtpmcfg['backend'] = "Domain-0" 7.32 -vtpmcfg['instance'] = 1 7.33 +vtpmcfg['backend'] = XendDomain.DOM0_UUID 7.34 vtpmcfg['VM'] = vm_uuid 7.35 7.36 session = xapi.connect() 7.37 7.38 vtpm_uuid = session.xenapi.VTPM.create(vtpmcfg) 7.39 7.40 -vtpm_id = session.xenapi.VTPM.get_instance(vtpm_uuid) 7.41 vtpm_be = session.xenapi.VTPM.get_backend(vtpm_uuid) 7.42 if vtpm_be != vtpmcfg['backend']: 7.43 FAIL("vTPM's backend is in '%s', expected: '%s'" % 7.44 (vtpm_be, vtpmcfg['backend'])) 7.45 7.46 -driver = session.xenapi.VTPM.get_driver(vtpm_uuid) 7.47 -if driver != vtpmcfg['type']: 7.48 - FAIL("vTPM has driver type '%s', expected: '%s'" % 7.49 - (driver, vtpmcfg['type'])) 7.50 - 7.51 vtpm_rec = session.xenapi.VTPM.get_record(vtpm_uuid) 7.52 7.53 -if vtpm_rec['driver'] != vtpmcfg['type']: 7.54 - FAIL("vTPM record shows driver type '%s', expected: '%s'" % 7.55 - (vtpm_rec['driver'], vtpmcfg['type'])) 7.56 +miss_keys = [] 7.57 +for k in VTPM_RECORD_KEYS: 7.58 + if k not in vtpm_rec.keys(): 7.59 + miss_keys.append(k) 7.60 +if len(miss_keys) > 0: 7.61 + FAIL("vTPM record is missing key(s): %s" % miss_keys) 7.62 + 7.63 if vtpm_rec['uuid'] != vtpm_uuid: 7.64 FAIL("vTPM record shows vtpm uuid '%s', expected: '%s'" % 7.65 (vtpm_rec['uuid'], vtpm_uuid)) 7.66 if vtpm_rec['VM'] != vm_uuid: 7.67 FAIL("vTPM record shows VM uuid '%s', expected: '%s'" % 7.68 (vtpm_rec['VM'], vm_uuid)) 7.69 +if vtpm_rec['backend'] != vtpmcfg['backend']: 7.70 + FAIL("vTPM record shows VM bakcned '%s', expected: '%s'" % 7.71 + (vtpm_rev['backend'], vtpmcfg['backend'])) 7.72 7.73 -success = domain.start() 7.74 +badkeys = [] 7.75 +keys = vtpm_rec.keys() 7.76 +for k in keys: 7.77 + if k not in VTPM_RECORD_KEYS: 7.78 + badkeys.append(k) 7.79 +if len(badkeys) > 0: 7.80 + FAIL("Unexpected attributes in result: %s" % badkeys) 7.81 + 7.82 +if vm_uuid != session.xenapi.VTPM.get_VM(vtpm_uuid): 7.83 + FAIL("VM uuid from VTPM.get_VM different (%s) than expected (%s)." % 7.84 + (vm_ref, vm_uuid)) 7.85 + 7.86 +uuid = session.xenapi.VTPM.get_uuid(vtpm_uuid) 7.87 +if uuid != vtpm_uuid: 7.88 + FAIL("vTPM from VTPM.get_uuid different (%s) than expected (%s)." % 7.89 + (uuid, vtpm_uuid)) 7.90 7.91 -console = domain.getConsole() 7.92 +vtpm_ref = session.xenapi.VTPM.get_by_uuid(vtpm_uuid) 7.93 +if vtpm_ref != vtpm_uuid: 7.94 + FAIL("vTPM from VTPM.get_by_uuid different (%s) than expected (%s)." % 7.95 + (vtpm_ref, vtpm_uuid)) 7.96 + 7.97 +vm_vtpms = session.xenapi.VM.get_VTPMs(vm_uuid) 7.98 +if len(vm_vtpms) != 1: 7.99 + FAIL("Number of vTPMs from get_VTPMs is (%d) not what was expected (%d)" % 7.100 + (len(vm_vtpms), 1)) 7.101 +if vtpm_uuid not in vm_vtpms: 7.102 + FAIL("Other vTPM uuid (%s) returned from VM.get_VTPMs than expected (%s)" % 7.103 + (vm_vtpms[0], vtpm_uuid)) 7.104 + 7.105 +try: 7.106 + console = domain.start() 7.107 +except DomainError, e: 7.108 + FAIL("Unable to create domain (%s)" % domName) 7.109 + 7.110 +try: 7.111 + console.sendInput("input") 7.112 +except ConsoleError, e: 7.113 + saveLog(console.getHistory()) 7.114 + FAIL(str(e)) 7.115 7.116 try: 7.117 run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs") 7.118 except ConsoleError, e: 7.119 saveLog(console.getHistory()) 7.120 - vtpm_cleanup(domName) 7.121 - FAIL("No result from dumping the PCRs") 7.122 + FAIL("1. No result from dumping the PCRs") 7.123 7.124 if re.search("No such file",run["output"]): 7.125 - vtpm_cleanup(domName) 7.126 FAIL("TPM frontend support not compiled into (domU?) kernel") 7.127 7.128 +if not re.search("PCR-00:",run["output"]): 7.129 + saveLog(console.getHistory()) 7.130 + FAIL("1. Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"]) 7.131 + 7.132 +try: 7.133 + rc = session.xenapi.VTPM.destroy(vtpm_uuid) 7.134 + #Should never get here 7.135 + FAIL("Could destroy vTPM while VM is running") 7.136 +except: 7.137 + pass 7.138 + 7.139 +rc = session.xenapi.VM.suspend(vm_uuid) 7.140 +if rc: 7.141 + FAIL("Could not suspend VM") 7.142 + 7.143 +try: 7.144 + rc = session.xenapi.VTPM.destroy(vtpm_uuid) 7.145 + #May not throw an exception in 'suspend' state 7.146 +except: 7.147 + pass 7.148 + 7.149 +rc = session.xenapi.VM.resume(vm_uuid, False) 7.150 +if rc: 7.151 + FAIL("Could not resume VM") 7.152 + 7.153 +try: 7.154 + console = domain.getConsole() 7.155 +except ConsoleError, e: 7.156 + FAIL(str(e)) 7.157 + 7.158 +try: 7.159 + run = console.runCmd("cat /sys/devices/xen/vtpm-0/pcrs") 7.160 +except ConsoleError, e: 7.161 + saveLog(console.getHistory()) 7.162 + FAIL("2. No result from dumping the PCRs. vTPM has been removed?") 7.163 + 7.164 +if not re.search("PCR-00:",run["output"]): 7.165 + saveLog(console.getHistory()) 7.166 + FAIL("2. Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"]) 7.167 + 7.168 domain.stop() 7.169 + 7.170 +rc = session.xenapi.VTPM.destroy(vtpm_uuid) 7.171 +if not rc: 7.172 + FAIL("Could NOT destroy vTPM while domain is halted.") 7.173 + 7.174 domain.destroy()