All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 8/12] VTPM mini-os: vtpm hotplug fixes
@ 2011-03-11 23:03 Matthew Fioravante
  0 siblings, 0 replies; only message in thread
From: Matthew Fioravante @ 2011-03-11 23:03 UTC (permalink / raw)
  To: xen-devel@lists.xensource.com


[-- Attachment #1.1.1: Type: text/plain, Size: 628 bytes --]

This patch provides several bug fixes to the vtpm hotplug scripts that 
run in dom0. Previously there were many different cases that would cause 
them to either crash or hang. Mishandled lock files and improperly used 
ipc were the culprits.

With this patch the hotplug code uses the vtpmmgrtalk program (included 
in the last patch) to talk to the vtpm manager and determine if it is 
running and ready to receive commands.

With this patch and the previous vtpm_manager patch the tradition vtpm 
implementation in xen is very stable and usable.

Signed off by: Matthew Fioravante <matthew.fioravante@jhuapl.edu>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.1.2: 8-hotplug.patch --]
[-- Type: text/x-patch; name="8-hotplug.patch", Size: 7642 bytes --]

diff -Naur xen-unstable-trp-sdp-pristine/tools/hotplug/Linux/vtpm xen-unstable-trp-sdp/tools/hotplug/Linux/vtpm
--- xen-unstable-trp-sdp-pristine/tools/hotplug/Linux/vtpm	2011-02-23 14:47:26.000000000 -0500
+++ xen-unstable-trp-sdp/tools/hotplug/Linux/vtpm	2011-02-23 14:42:11.000000000 -0500
@@ -1,22 +1,18 @@
 #!/bin/bash
 
+export PATH=$PATH:/usr/sbin:/sbin
+
 dir=$(dirname "$0")
 . "$dir/vtpm-hotplug-common.sh"
 
-vtpm_fatal_error=0
-
 case "$command" in
   add)
     vtpm_create_instance
+    success
   ;;
   remove)
     vtpm_remove_instance
+    success
   ;;
 esac
 
-if [ $vtpm_fatal_error -eq 0 ]; then
-	log debug "Successful vTPM operation '$command'."
-	success
-else
-	fatal "Error while executing vTPM operation '$command'."
-fi
diff -Naur xen-unstable-trp-sdp-pristine/tools/hotplug/Linux/vtpm-common.sh xen-unstable-trp-sdp/tools/hotplug/Linux/vtpm-common.sh
--- xen-unstable-trp-sdp-pristine/tools/hotplug/Linux/vtpm-common.sh	2011-02-23 14:47:26.000000000 -0500
+++ xen-unstable-trp-sdp/tools/hotplug/Linux/vtpm-common.sh	2011-02-23 14:42:11.000000000 -0500
@@ -98,7 +98,7 @@
 		avail=0
 	else
 		instances=$(cat $VTPMDB |                \
-		           awk                          \
+		           gawk                          \
 		           '{                            \
 		               if (1 != index($1,"#")) { \
 		                 printf("%s ",$2);       \
@@ -120,7 +120,7 @@
 function vtpmdb_get_free_instancenum () {
 	local ctr instances don found
 	instances=$(cat $VTPMDB |                \
-	           awk                          \
+	           gawk                          \
 	           '{                            \
 	               if (1 != index($1,"#")) { \
 	                 printf("%s ",$2);       \
@@ -174,7 +174,7 @@
 	inst=$2
 
 	res=$(cat $VTPMDB |            \
-	     awk -vvmname=$vmname     \
+	     gawk -vvmname=$vmname     \
 	          -vinst=$inst         \
 	     '{                        \
 	         if ( 1 == index($1,"#")) {\
@@ -209,7 +209,7 @@
 	VTPMDB_TMP="$VTPMDB".tmp
 
 	$(cat $VTPMDB |            \
-	 awk -vvmname=$vmname     \
+	 gawk -vvmname=$vmname     \
 	 '{                        \
 	    if ( $1 != vmname ) {  \
 	      print $0;            \
@@ -276,12 +276,10 @@
 
 		vtpm_create $instance
 
-		if [ $vtpm_fatal_error -eq 0 ]; then
-			if [ "$uuid" != "" ]; then
-				vtpmdb_add_instance $uuid $instance
-			else
-				vtpmdb_add_instance $domname $instance
-			fi
+		if [ "$uuid" != "" ]; then
+			vtpmdb_add_instance $uuid $instance
+		else
+			vtpmdb_add_instance $domname $instance
 		fi
 	else
 		if [ "$reason" == "resume" ]; then
@@ -290,7 +288,6 @@
 			vtpm_start $instance
 		fi
 	fi
-
 	release_lock vtpmdb
 
 	xenstore_write $XENBUS_PATH/instance $instance
@@ -322,8 +319,8 @@
 	if [ "$instance" != "0" ]; then
 		vtpm_suspend $instance
 	fi
-
 	release_lock vtpmdb
+
 }
 
 
@@ -350,13 +347,13 @@
 function vtpm_isLocalAddress() {
 	local addr res
 	addr=$(ping $1 -c 1 |  \
-	       awk '{ print substr($3,2,length($3)-2); exit }')
+	       gawk '{ print substr($3,2,length($3)-2); exit }')
 	if [ "$addr" == "" ]; then
 		echo "-1"
 		return
 	fi
 	res=$(ifconfig | grep "inet addr" |  \
-	     awk -vaddr=$addr               \
+	     gawk -vaddr=$addr               \
 	     '{                              \
 	        if ( addr == substr($2, 6)) {\
 	          print "1";                 \
diff -Naur xen-unstable-trp-sdp-pristine/tools/hotplug/Linux/vtpm-delete xen-unstable-trp-sdp/tools/hotplug/Linux/vtpm-delete
--- xen-unstable-trp-sdp-pristine/tools/hotplug/Linux/vtpm-delete	2011-02-23 14:47:26.000000000 -0500
+++ xen-unstable-trp-sdp/tools/hotplug/Linux/vtpm-delete	2011-02-23 14:42:11.000000000 -0500
@@ -5,6 +5,8 @@
 # or
 # vtpm-delete --vmname <vm name>
 
+export PATH=$PATH:/usr/sbin:/sbin
+
 dir=$(dirname "$0")
 . "$dir/vtpm-common.sh"
 
diff -Naur xen-unstable-trp-sdp-pristine/tools/hotplug/Linux/vtpm-impl xen-unstable-trp-sdp/tools/hotplug/Linux/vtpm-impl
--- xen-unstable-trp-sdp-pristine/tools/hotplug/Linux/vtpm-impl	2011-02-23 14:47:26.000000000 -0500
+++ xen-unstable-trp-sdp/tools/hotplug/Linux/vtpm-impl	2011-02-23 14:42:11.000000000 -0500
@@ -32,14 +32,16 @@
 # OF THE POSSIBILITY OF SUCH DAMAGE.
 # ===================================================================
 
-#            |        SRC        |    TAG  |      CMD SIZE     |        ORD       |mtype|strt
-TPM_CMD_OPEN=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x11\\x01\\x00\\x00\\x01\\x01\\x01
-TPM_CMD_RESM=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x11\\x01\\x00\\x00\\x01\\x01\\x02
-TPM_CMD_CLOS=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x0e\\x01\\x00\\x00\\x02
-TPM_CMD_DELE=\\x00\\x00\\x00\\x00\\x01\\xc1\\x00\\x00\\x00\\x0e\\x01\\x00\\x00\\x03
+export PATH=$PATH:/usr/sbin:/sbin
 
-TPM_TYPE_PVM=\\x01
-TPM_TYPE_HVM=\\x02
+#             | SRC  |TAG| CMD SZ|| ORD  |mtype|strt
+TPM_CMD_OPEN="0000000001C100000011010000010101"
+TPM_CMD_RESM="0000000001C100000011010000010102"
+TPM_CMD_CLOS="0000000001C10000000E01000002"
+TPM_CMD_DELE="0000000001C10000000E01000003"
+
+TPM_TYPE_PVM=01
+TPM_TYPE_HVM=02
 
 TPM_SUCCESS=00000000
 
@@ -70,24 +72,19 @@
  local inst=$2;
  local inst_bin=$(hex32_to_bin $inst);
 
- claim_lock vtpm_mgr
-
- #send cmd to vtpm_manager
- printf "$cmd$inst_bin" > $TX_VTPM_MANAGER
-
- #recv response
- set +e
- local resp_hex=`dd skip=10 bs=1 count=4 if=$RX_VTPM_MANAGER 2> /dev/null | xxd -ps`
- set -e
+ local resp_hex
+ #send cmd to vtpm_manager and get response
+ if ! resp_hex=`echo "$cmd$(str_to_hex32 $inst)" | vtpmmgrtalk `; then
+   release_lock vtpmdb
+   fatal "Error communicating with vTPM Manager"
+ fi
 
- release_lock vtpm_mgr
+ resp_hex=`echo $resp_hex | cut -b 21-`
 
  #return whether the command was successful
- if [ $resp_hex -ne $TPM_SUCCESS ]; then
-   vtpm_fatal_error=1
-   false
-  else
-   true
+ if [ "$resp_hex" != "$TPM_SUCCESS" ]; then
+   release_lock vtpmdb
+   fatal "vTPM Manager returned failure code $resp_hex"
  fi
 }
 
@@ -142,13 +139,8 @@
 
 function vtpm_delete() {
  local inst=$1
- if $(vtpm_manager_cmd $TPM_CMD_DELE $inst); then
-   rm -f /var/vtpm/vtpm_dm_$1.data
-   true
- else 
-   vtpm_fatal_error=1
-   false
- fi
+ $(vtpm_manager_cmd $TPM_CMD_DELE $inst)
+ rm -f /var/vtpm/vtpm_dm_$1.data
 }
 
 # Perform a migration step. This function differentiates between migration
diff -Naur xen-unstable-trp-sdp-pristine/tools/python/xen/xend/server/tpmif.py xen-unstable-trp-sdp/tools/python/xen/xend/server/tpmif.py
--- xen-unstable-trp-sdp-pristine/tools/python/xen/xend/server/tpmif.py	2011-02-23 14:47:26.000000000 -0500
+++ xen-unstable-trp-sdp/tools/python/xen/xend/server/tpmif.py	2011-02-23 19:40:48.000000000 -0500
@@ -44,6 +44,22 @@
         DevController.__init__(self, vm)
 
 
+    def createDevice(self, config):
+        #Disable hotplug scripts if backend is not dom0
+        import xen.xend.XendDomain
+        xd = xen.xend.XendDomain.instance()
+        backdom_name = config.get('backend')
+        if backdom_name is None:
+            backdom = xen.xend.XendDomain.DOM0_ID
+        else:
+            bd = xd.domain_lookup_nr(backdom_name)
+            backdom = bd.getDomid()
+
+	if backdom != xen.xend.XendDomain.DOM0_ID:
+	   self.hotplug = False
+
+        return DevController.createDevice(self, config)
+
     def getDeviceDetails(self, config):
         """@see DevController.getDeviceDetails"""
 

[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 2518 bytes --]

[-- Attachment #2: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-03-11 23:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-11 23:03 [PATCH 8/12] VTPM mini-os: vtpm hotplug fixes Matthew Fioravante

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.