Skip to contentSkip to conversation

Not raising an API error in VTPM destroy method

PATCH In review Stefan Berger 2 participants 6 messages Feb 7, 2007 – Feb 8, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Not raising an API error in VTPM destroy method

Don't return an API error if vTPM cannot be destroyed due to a running VM, but a value indicating failure instead. Adapt python code, libxen and documentation.

xen-unstable.hg/tools/libxen/include/xen_vtpm.h +1 -1
Index: root/xen-unstable.hg/tools/libxen/include/xen_vtpm.h
===================================================================
@@ -172,7 +172,7 @@ xen_vtpm_create(xen_session *session, xe
  * Destroy the specified VTPM instance.
  */
 extern bool
-xen_vtpm_destroy(xen_session *session, xen_vtpm vtpm);
+xen_vtpm_destroy(xen_session *session, int64_t *result, xen_vtpm vtpm);
 
 
 /**
xen-unstable.hg/tools/libxen/src/xen_vtpm.c +5 -2
Index: root/xen-unstable.hg/tools/libxen/src/xen_vtpm.c
===================================================================
@@ -132,7 +132,7 @@ xen_vtpm_create(xen_session *session, xe
 
 
 bool
-xen_vtpm_destroy(xen_session *session, xen_vtpm vtpm)
+xen_vtpm_destroy(xen_session *session, int64_t *result, xen_vtpm vtpm)
 {
     abstract_value param_values[] =
         {
@@ -140,7 +140,10 @@ xen_vtpm_destroy(xen_session *session, x
               .u.string_val = vtpm }
         };
 
-    xen_call_(session, "VTPM.destroy", param_values, 1, NULL, NULL);
+    abstract_type result_type = abstract_type_int;
+
+    *result = 0;
+    XEN_CALL_("VTPM.destroy");
     return session->ok;
 }
 
xen-unstable.hg/tools/python/xen/xend/XendAPI.py +1 -3
Index: root/xen-unstable.hg/tools/python/xen/xend/XendAPI.py
===================================================================
@@ -1834,9 +1834,7 @@ class XendAPI(object):
         if dom:
             if dom.state != XEN_API_VM_POWER_STATE_HALTED:
                 vm_ref = dom.get_dev_property('vtpm', vtpm_ref, 'VM')
-                return xen_api_error(['VM_BAD_POWER_STATE', vm_ref,
-                 XendDomain.POWER_STATE_NAMES[XEN_API_VM_POWER_STATE_HALTED],
-                 XendDomain.POWER_STATE_NAMES[dom.state]])
+                return xen_api_success(False)
             from xen.xend.server import tpmif
             tpmif.destroy_vtpmstate(dom.getName())
             return xen_api_success(True)
xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex +3 -3
Index: root/xen-unstable.hg/docs/xen-api/xenapi-datamodel.tex
===================================================================
@@ -10880,7 +10880,7 @@ reference to the newly created object
 Destroy the specified VTPM instance.
 
  \noindent {\bf Signature:} 
-\begin{verbatim} void destroy (session_id s, VTPM ref self)\end{verbatim}
+\begin{verbatim} int destroy (session_id s, VTPM ref self)\end{verbatim}
 
 
 \noindent{\bf Arguments:}
@@ -10898,11 +10898,11 @@ Destroy the specified VTPM instance.
 
  \noindent {\bf Return Type:} 
 {\tt 
-void
+int
 }
 
 
-
+Success (1) or failure of the operation.
 \vspace{0.3cm}
 \vspace{0.3cm}
 \vspace{0.3cm}
xen-unstable.hg/tools/xm-test/tests/vtpm/09_vtpm-xapi.py +7 -10
Index: root/xen-unstable.hg/tools/xm-test/tests/vtpm/09_vtpm-xapi.py
===================================================================
@@ -112,22 +112,19 @@ if not re.search("PCR-00:",run["output"]
     saveLog(console.getHistory())
     FAIL("1. Virtual TPM is not working correctly on /dev/vtpm on backend side: \n%s" % run["output"])
 
-try:
-    rc = session.xenapi.VTPM.destroy(vtpm_uuid)
-    #Should never get here
+rc = session.xenapi.VTPM.destroy(vtpm_uuid)
+if int(rc) != 0:
+    #Should not be able to destroy the VTPM with the VM running
     FAIL("Could destroy vTPM while VM is running")
-except:
-    pass
 
 rc = session.xenapi.VM.suspend(vm_uuid)
 if rc:
     FAIL("Could not suspend VM")
 
-try:
-    rc = session.xenapi.VTPM.destroy(vtpm_uuid)
-    #May not throw an exception in 'suspend' state
-except:
-    pass
+rc = session.xenapi.VTPM.destroy(vtpm_uuid)
+if int(rc) != 0:
+    #Should not be able to destroy the VTPM with the VM running
+    print "Could destroy vTPM while VM is suspended?!"
 
 rc = session.xenapi.VM.resume(vm_uuid, False)
 if rc:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 5 lines · Stefan Berger

Don't return an API error if vTPM cannot be destroyed due to a running VM, but a value indicating failure instead. Adapt python code, libxen and documentation.

We have a separate error-returning mechanism -- you should be using that rather than returning an error code. Take a look at the end of xenapi-datamodel.tex; the error code definitions are there. In XendAPI.py, you have xen_api_error available, which will marshall an error code and arguments, and in xen/xm/messages there is a translation database for those error messages.

Cheers,

Ewan.

#2 lore raw

[email protected] wrote on 02/08/2007 10:53:24 AM:

Quoted 11 lines · Stefan Berger
Quoted 6 lines

Don't return an API error if vTPM cannot be destroyed due to a running VM, but a value indicating failure instead. Adapt python code, libxen and documentation.

We have a separate error-returning mechanism -- you should be using that rather than returning an error code. Take a look at the end of xenapi-datamodel.tex; the error code definitions are there. In

XendAPI.py,

Quoted 2 lines

you have xen_api_error available, which will marshall an error code and arguments, and in xen/xm/messages there is a translation database for

those

Quoted 1 line

error messages.

Thanks for pointing this out. I looked at the xenapi-datamodel.tex, of course, but I mostly find information related to the errors in 1.3.1 and towards the end of the document there's the debug class, but I don't think you are referring to that one.

The reason why I am actually trying to get rid of the 'return xen_api_error(...)' statement is that if I am using the C client library ,libxen, the session->ok parameter changes to 'false' if this error comes back when for example trying to delete a vTPM from a running VM. I have tried to make the session usable again by doing 'session->ok = true' so I don't have to establish yet another session -- not sure whether that is an allowed usage model of the session, though. Although this session works for further transactions the program fails at the point when the session is cleaned up with glibc complaining about bad memory. So the easiest way to circumvent this is to have the API return an error code for failure of the operation using xen_api_success().

Cheers,
Stefan

Quoted 9 lines

Cheers,

Ewan.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

1.3

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#3 lore raw
Quoted 16 lines · Stefan Berger

[email protected] wrote on 02/08/2007 10:53:24 AM:

Quoted 11 lines · Stefan Berger
Quoted 6 lines

Don't return an API error if vTPM cannot be destroyed due to a running VM, but a value indicating failure instead. Adapt python code, libxen and documentation.

We have a separate error-returning mechanism -- you should be using that rather than returning an error code. Take a look at the end of xenapi-datamodel.tex; the error code definitions are there. In

XendAPI.py,

Quoted 2 lines

you have xen_api_error available, which will marshall an error code and arguments, and in xen/xm/messages there is a translation database for

Quoted 7 lines

those

Quoted 1 line

error messages.

Thanks for pointing this out. I looked at the xenapi-datamodel.tex, of course, but I mostly find information related to the errors in 1.3.1 and towards the end of the document there's the debug class, but I don't think you are referring to that one.

No, I mean the version that's in xen-unstable. There's section 2.24 on error handling in there.

Quoted 11 lines

The reason why I am actually trying to get rid of the 'return xen_api_error(...)' statement is that if I am using the C client library ,libxen, the session->ok parameter changes to 'false' if this error comes back when for example trying to delete a vTPM from a running VM. I have tried to make the session usable again by doing 'session->ok = true' so I don't have to establish yet another session -- not sure whether that is an allowed usage model of the session, though. Although this session works for further transactions the program fails at the point when the session is cleaned up with glibc complaining about bad memory. So the easiest way to circumvent this is to have the API return an error code for failure of the operation using xen_api_success().

That might be the easiest way, but it's certainly the wrong one!

This has been discussed a little on the xen-api list before, though I agree that the documentation needs to be updated. Setting session->ok back to true when you've handled the error is fine. The intention is to allow you to chain together short groups of calls, and then check for errors at appropriate points. (If you prefer, you can check for errors after every single call, that's fine too.)

If you're getting a segfault or a glibc-detected error, then that's clearly a bug. Could you post your code so that I can try it?

Ewan.

#4 lore raw

[email protected] wrote on 02/08/2007 02:00:14 PM:

Quoted 7 lines · Stefan Berger
Quoted 6 lines

[email protected] wrote on 02/08/2007 10:53:24 AM:

Quoted 3 lines · Stefan Berger
Quoted 2 lines

Don't return an API error if vTPM cannot be destroyed due to a

running

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

VM, but a value indicating failure instead. Adapt python code,

libxen

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

and documentation.

We have a separate error-returning mechanism -- you should be using

that

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

rather than returning an error code. Take a look at the end of xenapi-datamodel.tex; the error code definitions are there. In

XendAPI.py,

Quoted 1 line

you have xen_api_error available, which will marshall an error code

and

Quoted 1 line
Quoted 1 line
Quoted 1 line

arguments, and in xen/xm/messages there is a translation database

for

Quoted 5 lines
Quoted 5 lines

those

Quoted 1 line

error messages.

Thanks for pointing this out. I looked at the xenapi-datamodel.tex, of course, but I mostly find information related to the errors in 1.3.1

and

Quoted 1 line
Quoted 1 line

towards the end of the document there's the debug class, but I don't

think

Quoted 3 lines
Quoted 1 line

you are referring to that one.

No, I mean the version that's in xen-unstable. There's section 2.24 on

error

Quoted 4 lines

handling in there.

Quoted 2 lines

The reason why I am actually trying to get rid of the 'return xen_api_error(...)' statement is that if I am using the C client

library

Quoted 1 line
Quoted 1 line

,libxen, the session->ok parameter changes to 'false' if this error

comes

Quoted 1 line
Quoted 1 line

back when for example trying to delete a vTPM from a running VM. I

have

Quoted 1 line
Quoted 1 line

tried to make the session usable again by doing 'session->ok = true'

so I

Quoted 1 line
Quoted 1 line

don't have to establish yet another session -- not sure whether that

is an

Quoted 1 line
Quoted 1 line

allowed usage model of the session, though. Although this session

works

Quoted 1 line
Quoted 1 line

for further transactions the program fails at the point when the

session

Quoted 1 line
Quoted 1 line

is cleaned up with glibc complaining about bad memory. So the easiest

way

Quoted 1 line
Quoted 1 line

to circumvent this is to have the API return an error code for failure

of

Quoted 5 lines
Quoted 1 line

the operation using xen_api_success().

That might be the easiest way, but it's certainly the wrong one!

This has been discussed a little on the xen-api list before, though I

agree

Quoted 1 line

that the documentation needs to be updated. Setting session->ok back to

true

Quoted 1 line

when you've handled the error is fine. The intention is to allow you to

chain

Quoted 2 lines

together short groups of calls, and then check for errors at appropriate points. (If you prefer, you can check for errors after every single

call,

Quoted 3 lines

that's fine too.)

If you're getting a segfault or a glibc-detected error, then that's

clearly a

Quoted 8 lines

bug. Could you post your code so that I can try it?

Ewan.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#5 lore raw
In reply to Ewan Mellor

[email protected] wrote on 02/08/2007 02:00:14 PM:

Quoted 7 lines · Stefan Berger
Quoted 6 lines

[email protected] wrote on 02/08/2007 10:53:24 AM:

Quoted 3 lines · Stefan Berger
Quoted 2 lines

Don't return an API error if vTPM cannot be destroyed due to a

running

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

VM, but a value indicating failure instead. Adapt python code,

libxen

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

and documentation.

We have a separate error-returning mechanism -- you should be using

that

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

rather than returning an error code. Take a look at the end of xenapi-datamodel.tex; the error code definitions are there. In

XendAPI.py,

Quoted 1 line

you have xen_api_error available, which will marshall an error code

and

Quoted 1 line
Quoted 1 line
Quoted 1 line

arguments, and in xen/xm/messages there is a translation database

for

Quoted 5 lines
Quoted 5 lines

those

Quoted 1 line

error messages.

Thanks for pointing this out. I looked at the xenapi-datamodel.tex, of course, but I mostly find information related to the errors in 1.3.1

and

Quoted 1 line
Quoted 1 line

towards the end of the document there's the debug class, but I don't

think

Quoted 3 lines
Quoted 1 line

you are referring to that one.

No, I mean the version that's in xen-unstable. There's section 2.24 on

error

Quoted 4 lines

handling in there.

Quoted 2 lines

The reason why I am actually trying to get rid of the 'return xen_api_error(...)' statement is that if I am using the C client

library

Quoted 1 line
Quoted 1 line

,libxen, the session->ok parameter changes to 'false' if this error

comes

Quoted 1 line
Quoted 1 line

back when for example trying to delete a vTPM from a running VM. I

have

Quoted 1 line
Quoted 1 line

tried to make the session usable again by doing 'session->ok = true'

so I

Quoted 1 line
Quoted 1 line

don't have to establish yet another session -- not sure whether that

is an

Quoted 1 line
Quoted 1 line

allowed usage model of the session, though. Although this session

works

Quoted 1 line
Quoted 1 line

for further transactions the program fails at the point when the

session

Quoted 1 line
Quoted 1 line

is cleaned up with glibc complaining about bad memory. So the easiest

way

Quoted 1 line
Quoted 1 line

to circumvent this is to have the API return an error code for failure

of

Quoted 5 lines
Quoted 1 line

the operation using xen_api_success().

That might be the easiest way, but it's certainly the wrong one!

This has been discussed a little on the xen-api list before, though I

agree

Quoted 1 line

that the documentation needs to be updated. Setting session->ok back to

true

Quoted 1 line

when you've handled the error is fine. The intention is to allow you to

chain

Quoted 2 lines

together short groups of calls, and then check for errors at appropriate points. (If you prefer, you can check for errors after every single

call,

Quoted 3 lines

that's fine too.)

If you're getting a segfault or a glibc-detected error, then that's

clearly a

Quoted 1 line

bug. Could you post your code so that I can try it?

I'll try to put something in your test case that triggers this error.

Stefan

Quoted 7 lines

Ewan.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel