debuggers.hg

view tools/python/xen/xend/server/tpmif.py @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
16 # Copyright (C) 2005 IBM Corporation
17 # Author: Stefan Berger, stefanb@us.ibm.com
18 # Copyright (C) 2005 XenSource Ltd
19 #============================================================================
21 """Support for virtual TPM interfaces."""
23 from xen.xend import XendOptions
24 from xen.xend.XendLogging import log
25 from xen.xend.XendError import XendError
26 from xen.xend.XendConstants import DEV_MIGRATE_TEST, VTPM_DELETE_SCRIPT
27 from xen.xend.server.DevController import DevController
29 import os
30 import re
32 xoptions = XendOptions.instance()
34 def destroy_vtpmstate(uuids):
35 if os.path.exists(VTPM_DELETE_SCRIPT):
36 for uuid in uuids:
37 os.system(VTPM_DELETE_SCRIPT + " " + uuid)
39 class TPMifController(DevController):
40 """TPM interface controller. Handles all TPM devices for a domain.
41 """
43 def __init__(self, vm):
44 DevController.__init__(self, vm)
47 def getDeviceDetails(self, config):
48 """@see DevController.getDeviceDetails"""
50 devid = self.allocateDeviceID()
51 inst = int(config.get('pref_instance', -1))
52 if inst == -1:
53 inst = int(config.get('instance', 0))
55 typ = config.get('type')
56 uuid = config.get('uuid')
58 log.info("The domain has a TPM with pref. instance %d and devid %d.",
59 inst, devid)
60 back = { 'pref_instance' : "%i" % inst,
61 'resume' : "%s" % (self.vm.getResume()) }
62 if typ:
63 back['type'] = typ
64 if uuid:
65 back['uuid'] = uuid
67 data = self.vm.info['devices'].get(uuid)
68 if data:
69 other = data[1].get('other_config')
70 if type(other) == dict:
71 for key, item in other.items():
72 back['oc_' + key] = item
74 front = { 'handle' : "%i" % devid }
76 return (devid, back, front)
78 def getDeviceConfiguration(self, devid, transaction = None):
79 """Returns the configuration of a device"""
80 result = DevController.getDeviceConfiguration(self, devid, transaction)
82 (instance, uuid, type) = \
83 self.readBackend(devid, 'instance',
84 'uuid',
85 'type')
87 if instance:
88 result['instance'] = instance
89 if uuid:
90 result['uuid'] = uuid
91 if type:
92 result['type'] = type
94 if uuid:
95 data = self.vm.info['devices'].get(uuid)
96 if data:
97 other = data[1].get('other_config')
98 if other:
99 result['other_config'] = other
101 return result
103 def migrate(self, deviceConfig, network, dst, step, domName):
104 """@see DevContoller.migrate"""
105 if network:
106 tool = xoptions.get_external_migration_tool()
107 if tool != '':
108 log.info("Request to network-migrate device to %s. step=%d.",
109 dst, step)
111 if step == DEV_MIGRATE_TEST:
112 """Assuming for now that everything is ok and migration
113 with the given tool can proceed.
114 """
115 return 0
116 else:
117 fd = os.popen("%s -type vtpm -step %d -host %s -domname %s" %
118 (tool, step, dst, domName),
119 'r')
120 for line in fd.readlines():
121 mo = re.search('Error', line)
122 if mo:
123 raise XendError("vtpm: Fatal error in migration step %d: %s" %
124 (step, line))
125 return 0
126 else:
127 log.debug("External migration tool not in configuration.")
128 return -1
129 return 0
131 def recover_migrate(self, deviceConfig, network, dst, step, domName):
132 """@see DevContoller.recover_migrate"""
133 if network:
134 tool = xoptions.get_external_migration_tool()
135 if tool != '':
136 log.info("Request to recover network-migrated device. last good step=%d.",
137 step)
138 fd = os.popen("%s -type vtpm -step %d -host %s -domname %s -recover" %
139 (tool, step, dst, domName),
140 'r')
141 return 0