[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] Move the content of the script file vtpm-addtodb into the



# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Node ID 28b766e3bcca126b3f19281765c33fb1c4118d8f
# Parent  3243ab41b09eeee6ac8d950fee41e99a56cb140b
Move the content of the script file vtpm-addtodb into the
vtpm-common.sh
script. The newly created function 'vtpm_add_and_activate' also
assigns
the instance number to the xenstore entry to activate the backend. 
Renaming of isLocalAddress function to vtpm_isLocalAddress.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx>
---
 tools/examples/vtpm-addtodb   |   10 --------
 tools/examples/Makefile       |    2 -
 tools/examples/README         |    1 
 tools/examples/vtpm-common.sh |   48 +++++++++++++++++++++++++++++++++++-------
 tools/examples/vtpm-impl      |    2 -
 5 files changed, 42 insertions(+), 21 deletions(-)

diff -r 3243ab41b09e -r 28b766e3bcca tools/examples/Makefile
--- a/tools/examples/Makefile   Mon Jul 10 17:33:45 2006 +0100
+++ b/tools/examples/Makefile   Mon Jul 10 17:36:41 2006 +0100
@@ -26,7 +26,7 @@ XEN_SCRIPTS += network-nat vif-nat
 XEN_SCRIPTS += network-nat vif-nat
 XEN_SCRIPTS += block
 XEN_SCRIPTS += block-enbd block-nbd
-XEN_SCRIPTS += vtpm vtpm-delete vtpm-addtodb
+XEN_SCRIPTS += vtpm vtpm-delete
 XEN_SCRIPTS += xen-hotplug-cleanup
 XEN_SCRIPTS += external-device-migrate
 XEN_SCRIPT_DATA = xen-script-common.sh locking.sh logging.sh
diff -r 3243ab41b09e -r 28b766e3bcca tools/examples/README
--- a/tools/examples/README     Mon Jul 10 17:33:45 2006 +0100
+++ b/tools/examples/README     Mon Jul 10 17:36:41 2006 +0100
@@ -25,7 +25,6 @@ vif-nat             - xen virtual networ
 vif-nat             - xen virtual network start/stop script in NAT mode 
 vif-route           - xen virtual network start/stop script in routed mode
 vtpm                - called by xen-backend.agent to bind/unbind vTPM devices
-vtpm-addtodb        - script for adding a vTPM instance to the vTPM table
 vtpm-common.sh      - common code for vTPM handling
 vtpm-delete         - remove an entry from the vTPM table given the
                       domain's name
diff -r 3243ab41b09e -r 28b766e3bcca tools/examples/vtpm-common.sh
--- a/tools/examples/vtpm-common.sh     Mon Jul 10 17:33:45 2006 +0100
+++ b/tools/examples/vtpm-common.sh     Mon Jul 10 17:36:41 2006 +0100
@@ -24,12 +24,9 @@ VTPMDB="/etc/xen/vtpm.db"
 
 #In the vtpm-impl file some commands should be defined:
 #      vtpm_create, vtpm_setup, vtpm_start, etc. (see below)
-#This should be indicated by setting VTPM_IMPL_DEFINED.
 if [ -r "$dir/vtpm-impl" ]; then
        . "$dir/vtpm-impl"
-fi
-
-if [ -z "$VTPM_IMPL_DEFINED" ]; then
+else
        function vtpm_create () {
                true
        }
@@ -245,6 +242,12 @@ function vtpm_create_instance () {
 
        claim_lock vtpmdb
        instance=$(vtpmdb_find_instance $domname)
+
+       if [ "$instance" == "0" -a "$reason" != "create" ]; then
+               release_lock vtpmdb
+               return
+       fi
+
        if [ "$instance" == "0" ]; then
                #Try to give the preferred instance to the domain
                instance=$(xenstore_read "$XENBUS_PATH"/pref_instance)
@@ -317,7 +320,7 @@ function vtpm_delete_instance () {
 #  "-1" : the given machine name is invalid
 #  "0"  : this is not an address of this machine
 #  "1"  : this is an address local to this machine
-function isLocalAddress() {
+function vtpm_isLocalAddress() {
        local addr res
        addr=$(ping $1 -c 1 |  \
               gawk '{ print substr($3,2,length($3)-2); exit }')
@@ -347,7 +350,7 @@ function isLocalAddress() {
 # 2nd: name of the domain to migrate
 # 3rd: the migration step to perform
 function vtpm_migration_step() {
-       local res=$(isLocalAddress $1)
+       local res=$(vtpm_isLocalAddress $1)
        if [ "$res" == "0" ]; then
                vtpm_migrate $1 $2 $3
        fi
@@ -361,8 +364,39 @@ function vtpm_migration_step() {
 # 3rd: the last successful migration step that was done
 function vtpm_recover() {
        local res
-       res=$(isLocalAddress $1)
+       res=$(vtpm_isLocalAddress $1)
        if [ "$res" == "0" ]; then
                vtpm_migrate_recover $1 $2 $3
        fi
 }
+
+
+#Determine the domain id given a domain's name.
+#1st parameter: name of the domain
+#return value: domain id  or -1 if domain id could not be determined
+function vtpm_domid_from_name () {
+       local id name ids
+       ids=$(xenstore-list /local/domain)
+       for id in $ids; do
+               name=$(xenstore-read /local/domain/$id/name)
+               if [ "$name" == "$1" ]; then
+                       echo "$id"
+                       return
+               fi
+       done
+       echo "-1"
+}
+
+
+#Add a virtual TPM instance number and its associated domain name
+#to the VTPMDB file and activate usage of this virtual TPM instance
+#by writing the instance number into the xenstore
+#1st parm: name of virtual machine
+#2nd parm: instance of assoicate virtual TPM
+function vtpm_add_and_activate() {
+       local domid=$(vtpm_domid_from_name $1)
+       if [ "$domid" != "-1" ]; then
+               vtpmdb_add_instance $1 $2
+               xenstore-write backend/vtpm/$domid/0/instance $2
+       fi
+}
diff -r 3243ab41b09e -r 28b766e3bcca tools/examples/vtpm-impl
--- a/tools/examples/vtpm-impl  Mon Jul 10 17:33:45 2006 +0100
+++ b/tools/examples/vtpm-impl  Mon Jul 10 17:36:41 2006 +0100
@@ -31,8 +31,6 @@
 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 # OF THE POSSIBILITY OF SUCH DAMAGE.
 # ===================================================================
-
-VTPM_IMPL_DEFINED=1
 
 #            |        SRC        |    TAG  |      CMD SIZE     |        ORD    
   | type| mode
 
TPM_CMD_OPEN=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x10\\x01\\x00\\x00\\x01\\x01\\x01
diff -r 3243ab41b09e -r 28b766e3bcca tools/examples/vtpm-addtodb
--- a/tools/examples/vtpm-addtodb       Mon Jul 10 17:33:45 2006 +0100
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-# This script must be called with the following parameters to have
-# an entry added to the TPM-to-domain associations table in /etc/xen/vtpm.db
-# vtpm-addtodb <dom name> <instance number>
-
-dir=$(dirname "$0")
-. "$dir/vtpm-common.sh"
-
-vtpmdb_add_instance $1 $2

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.