All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Fioravante <matthew.fioravante@jhuapl.edu>
To: Ian Campbell <Ian.Campbell@citrix.com>,
	"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: PATCH [base vtpm and libxl patches 3/6] Fix bugs in vtpm hotplug scripts
Date: Fri, 21 Sep 2012 14:59:36 -0400	[thread overview]
Message-ID: <505CB918.3030108@jhuapl.edu> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 5692 bytes --]

This patch fixes IO deadlocks in the vtpm hotplug scripts.

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

---
Changed since previous:
* rebased off of latest xen stable
* replaced instances of gawk with awk

diff --git a/tools/hotplug/Linux/vtpm b/tools/hotplug/Linux/vtpm
--- a/tools/hotplug/Linux/vtpm
+++ b/tools/hotplug/Linux/vtpm
@@ -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 --git a/tools/hotplug/Linux/vtpm-common.sh
b/tools/hotplug/Linux/vtpm-common.sh
--- a/tools/hotplug/Linux/vtpm-common.sh
+++ b/tools/hotplug/Linux/vtpm-common.sh
@@ -276,12 +276,10 @@ function vtpm_create_instance () {
 
         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 @@ function vtpm_create_instance () {
             vtpm_start $instance
         fi
     fi
-
     release_lock vtpmdb
 
     xenstore_write $XENBUS_PATH/instance $instance
@@ -322,8 +319,8 @@ function vtpm_remove_instance () {
     if [ "$instance" != "0" ]; then
         vtpm_suspend $instance
     fi
-
     release_lock vtpmdb
+
 }
 
 
diff --git a/tools/hotplug/Linux/vtpm-delete
b/tools/hotplug/Linux/vtpm-delete
--- a/tools/hotplug/Linux/vtpm-delete
+++ b/tools/hotplug/Linux/vtpm-delete
@@ -5,6 +5,8 @@
 # or
 # vtpm-delete --vmname <vm name>
 
+export PATH=$PATH:/usr/sbin:/sbin
+
 dir=$(dirname "$0")
 . "$dir/vtpm-common.sh"
 
diff --git a/tools/hotplug/Linux/vtpm-impl b/tools/hotplug/Linux/vtpm-impl
--- a/tools/hotplug/Linux/vtpm-impl
+++ b/tools/hotplug/Linux/vtpm-impl
@@ -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 @@ function vtpm_manager_cmd() {
  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_suspend() {
 
 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 --git a/tools/python/xen/xend/server/tpmif.py
b/tools/python/xen/xend/server/tpmif.py
--- a/tools/python/xen/xend/server/tpmif.py
+++ b/tools/python/xen/xend/server/tpmif.py
@@ -44,6 +44,22 @@ class TPMifController(DevController):
         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: 1459 bytes --]

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

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

             reply	other threads:[~2012-09-21 18:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-21 18:59 Matthew Fioravante [this message]
2012-09-25 10:27 ` PATCH [base vtpm and libxl patches 3/6] Fix bugs in vtpm hotplug scripts Ian Campbell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=505CB918.3030108@jhuapl.edu \
    --to=matthew.fioravante@jhuapl.edu \
    --cc=Ian.Campbell@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.