* [PATCH] Expose exception thrown by xen.lowlevel.xc
@ 2006-05-19 16:16 Anthony Liguori
2006-05-19 16:31 ` Ewan Mellor
0 siblings, 1 reply; 5+ messages in thread
From: Anthony Liguori @ 2006-05-19 16:16 UTC (permalink / raw)
To: xen-devel; +Cc: Ewan Mellor, Kaleb Pederson
[-- Attachment #1: Type: text/plain, Size: 508 bytes --]
The attached patch exposes the exception thrown by xen.lowlevel.xc as
the type xen.lowlevel.xc.Error which is an exception that inherits from
RuntimeError.
I only had a few minutes this morning so I didn't get to xen.lowlevel.xs
but hopefully someone else can use this as a guide on what needs to be
done. If noone else gets to it, I'll be able to submit another one in
about a week.
I've only done very basic testing but I don't expect that this should
break anything...
Regards,
Anthony Liguori
[-- Attachment #2: xc-lowlevel-exc.diff --]
[-- Type: text/plain, Size: 1358 bytes --]
# HG changeset patch
# User Anthony Liguori <anthony@codemonkey.ws>
# Node ID 352f6cc97066af5a50906a2c4b47794434a7cc30
# Parent 91c77df11b43894a2940b03029be46f6a1c85319
Expose the exceptions thrown by xen.lowlevel.xc so they can be caught.
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff -r 91c77df11b43 -r 352f6cc97066 tools/python/xen/lowlevel/xc/xc.c
--- a/tools/python/xen/lowlevel/xc/xc.c Wed May 10 17:30:42 2006 +0100
+++ b/tools/python/xen/lowlevel/xc/xc.c Fri May 19 11:13:28 2006 -0500
@@ -1172,7 +1172,7 @@ PyXc_init(XcObject *self, PyObject *args
PyXc_init(XcObject *self, PyObject *args, PyObject *kwds)
{
if ((self->xc_handle = xc_interface_open()) == -1) {
- PyErr_SetFromErrno(PyExc_RuntimeError);
+ PyErr_SetFromErrno(xc_error);
return -1;
}
@@ -1245,7 +1245,7 @@ PyMODINIT_FUNC initxc(void)
if (m == NULL)
return;
- xc_error = PyErr_NewException(PKG ".error", NULL, NULL);
+ xc_error = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL);
zero = PyInt_FromLong(0);
/* KAF: This ensures that we get debug output in a timely manner. */
@@ -1254,6 +1254,9 @@ PyMODINIT_FUNC initxc(void)
Py_INCREF(&PyXcType);
PyModule_AddObject(m, CLS, (PyObject *)&PyXcType);
+
+ Py_INCREF(xc_error);
+ PyModule_AddObject(m, "Error", xc_error);
}
[-- Attachment #3: 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] 5+ messages in thread
* Re: [PATCH] Expose exception thrown by xen.lowlevel.xc
2006-05-19 16:16 [PATCH] Expose exception thrown by xen.lowlevel.xc Anthony Liguori
@ 2006-05-19 16:31 ` Ewan Mellor
2006-05-19 16:35 ` [PATCH] Expose exception thrown by xen.lowlevel.xs (Was Re: [PATCH] Expose exception thrown by xen.lowlevel.xc) Anthony Liguori
0 siblings, 1 reply; 5+ messages in thread
From: Ewan Mellor @ 2006-05-19 16:31 UTC (permalink / raw)
To: Anthony Liguori; +Cc: xen-devel, Kaleb Pederson
On Fri, May 19, 2006 at 11:16:41AM -0500, Anthony Liguori wrote:
> The attached patch exposes the exception thrown by xen.lowlevel.xc as
> the type xen.lowlevel.xc.Error which is an exception that inherits from
> RuntimeError.
>
> I only had a few minutes this morning so I didn't get to xen.lowlevel.xs
> but hopefully someone else can use this as a guide on what needs to be
> done. If noone else gets to it, I'll be able to submit another one in
> about a week.
>
> I've only done very basic testing but I don't expect that this should
> break anything...
Thanks Anthony -- applied.
Ewan.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] Expose exception thrown by xen.lowlevel.xs (Was Re: [PATCH] Expose exception thrown by xen.lowlevel.xc)
2006-05-19 16:31 ` Ewan Mellor
@ 2006-05-19 16:35 ` Anthony Liguori
2006-05-19 19:44 ` Kaleb Pederson
2006-06-01 11:13 ` Ewan Mellor
0 siblings, 2 replies; 5+ messages in thread
From: Anthony Liguori @ 2006-05-19 16:35 UTC (permalink / raw)
To: Ewan Mellor; +Cc: xen-devel, Kaleb Pederson
[-- Attachment #1: Type: text/plain, Size: 1103 bytes --]
Ewan Mellor wrote:
> On Fri, May 19, 2006 at 11:16:41AM -0500, Anthony Liguori wrote:
>
>
>> The attached patch exposes the exception thrown by xen.lowlevel.xc as
>> the type xen.lowlevel.xc.Error which is an exception that inherits from
>> RuntimeError.
>>
>> I only had a few minutes this morning so I didn't get to xen.lowlevel.xs
>> but hopefully someone else can use this as a guide on what needs to be
>> done. If noone else gets to it, I'll be able to submit another one in
>> about a week.
>>
>> I've only done very basic testing but I don't expect that this should
>> break anything...
>>
>
> Thanks Anthony -- applied.
>
Got a little more time than I expected to. This one's quite a bit more
invasive but I think it's needed to at least be consistent with
xen.lowlevel.xc. I don't think we should be tossing an exception with
different formats (sometimes we threw a RuntimeError with (errno, msg)
and other times just a string--I've changed it to always be (errno, msg)).
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Regards,
Anthony Liguori
> Ewan.
>
[-- Attachment #2: xs-lowlevel-exc.diff --]
[-- Type: text/plain, Size: 9352 bytes --]
# HG changeset patch
# User Anthony Liguori <anthony@codemonkey.ws>
# Node ID 6d7dee5a1f2b6552e41578e3a8fcf5eb804f66ab
# Parent 352f6cc97066af5a50906a2c4b47794434a7cc30
Expose the exception thrown by xen.lowlevel.xs.
diff -r 352f6cc97066 -r 6d7dee5a1f2b tools/python/xen/lowlevel/xs/xs.c
--- a/tools/python/xen/lowlevel/xs/xs.c Fri May 19 11:13:28 2006 -0500
+++ b/tools/python/xen/lowlevel/xs/xs.c Fri May 19 11:32:21 2006 -0500
@@ -28,6 +28,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <errno.h>
#include <xenctrl.h>
#include "xs.h"
@@ -43,6 +44,8 @@
#define PKG "xen.lowlevel.xs"
#define CLS "xs"
+
+static PyObject *xs_error;
/** Python wrapper round an xs handle.
*/
@@ -52,11 +55,17 @@ typedef struct XsHandle {
PyObject *watches;
} XsHandle;
+static void xs_set_error(int value)
+{
+ errno = value;
+ PyErr_SetFromErrno(xs_error);
+}
+
static inline struct xs_handle *xshandle(XsHandle *self)
{
struct xs_handle *xh = self->xh;
if (!xh)
- PyErr_SetString(PyExc_RuntimeError, "invalid xenstore daemon handle");
+ xs_set_error(EINVAL);
return xh;
}
@@ -77,7 +86,7 @@ static int parse_transaction_path(XsHand
"\n" \
"Returns: [string] data read.\n" \
" None if key doesn't exist.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_read(XsHandle *self, PyObject *args)
@@ -113,7 +122,7 @@ static PyObject *xspy_read(XsHandle *sel
" data [string] : data to write.\n" \
"\n" \
"Returns None on success.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_write(XsHandle *self, PyObject *args)
@@ -149,7 +158,7 @@ static PyObject *xspy_write(XsHandle *se
"\n" \
"Returns: [string array] list of subdirectory names.\n" \
" None if key doesn't exist.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_ls(XsHandle *self, PyObject *args)
@@ -187,7 +196,7 @@ static PyObject *xspy_ls(XsHandle *self,
" path [string]: path to directory to create.\n" \
"\n" \
"Returns None on success.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_mkdir(XsHandle *self, PyObject *args)
@@ -215,7 +224,7 @@ static PyObject *xspy_mkdir(XsHandle *se
" path [string] : path to remove\n" \
"\n" \
"Returns None on success.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_rm(XsHandle *self, PyObject *args)
@@ -243,7 +252,7 @@ static PyObject *xspy_rm(XsHandle *self,
" path [string]: xenstore path.\n" \
"\n" \
"Returns: permissions array.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_get_permissions(XsHandle *self, PyObject *args)
@@ -284,7 +293,7 @@ static PyObject *xspy_get_permissions(Xs
return val;
}
else {
- PyErr_SetFromErrno(PyExc_RuntimeError);
+ PyErr_SetFromErrno(xs_error);
return NULL;
}
}
@@ -296,7 +305,7 @@ static PyObject *xspy_get_permissions(Xs
" perms : permissions.\n" \
"\n" \
"Returns None on success.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_set_permissions(XsHandle *self, PyObject *args)
@@ -323,13 +332,13 @@ static PyObject *xspy_set_permissions(Xs
th = strtoul(thstr, NULL, 16);
if (!PyList_Check(perms)) {
- PyErr_SetString(PyExc_RuntimeError, "perms must be a list");
+ xs_set_error(EINVAL);
goto exit;
}
xsperms_n = PyList_Size(perms);
xsperms = calloc(xsperms_n, sizeof(struct xs_permissions));
if (!xsperms) {
- PyErr_SetString(PyExc_RuntimeError, "out of memory");
+ xs_set_error(ENOMEM);
goto exit;
}
tuple0 = PyTuple_New(0);
@@ -351,7 +360,7 @@ static PyObject *xspy_set_permissions(Xs
result = xs_set_permissions(xh, th, path, xsperms, xsperms_n);
Py_END_ALLOW_THREADS
if (!result) {
- PyErr_SetFromErrno(PyExc_RuntimeError);
+ PyErr_SetFromErrno(xs_error);
goto exit;
}
@@ -370,7 +379,7 @@ static PyObject *xspy_set_permissions(Xs
" token [string] : returned in watch notification.\n" \
"\n" \
"Returns None on success.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
/* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */
@@ -420,7 +429,7 @@ static PyObject *xspy_watch(XsHandle *se
"Read a watch notification.\n" \
"\n" \
"Returns: [tuple] (path, token).\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_read_watch(XsHandle *self, PyObject *args)
@@ -440,11 +449,11 @@ again:
xsval = xs_read_watch(xh, &num);
Py_END_ALLOW_THREADS
if (!xsval) {
- PyErr_SetFromErrno(PyExc_RuntimeError);
+ PyErr_SetFromErrno(xs_error);
goto exit;
}
if (sscanf(xsval[XS_WATCH_TOKEN], "%li", (unsigned long *)&token) != 1) {
- PyErr_SetString(PyExc_RuntimeError, "invalid token");
+ xs_set_error(EINVAL);
goto exit;
}
for (i = 0; i < PyList_Size(self->watches); i++) {
@@ -473,7 +482,7 @@ again:
" token [string] : token from the watch.\n" \
"\n" \
"Returns None on success.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_unwatch(XsHandle *self, PyObject *args)
@@ -503,7 +512,7 @@ static PyObject *xspy_unwatch(XsHandle *
"Start a transaction.\n" \
"\n" \
"Returns transaction handle on success.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_transaction_start(XsHandle *self)
@@ -520,7 +529,7 @@ static PyObject *xspy_transaction_start(
Py_END_ALLOW_THREADS
if (th == XBT_NULL) {
- PyErr_SetFromErrno(PyExc_RuntimeError);
+ PyErr_SetFromErrno(xs_error);
return NULL;
}
@@ -534,7 +543,7 @@ static PyObject *xspy_transaction_start(
" abort [int]: abort flag (default 0).\n" \
"\n" \
"Returns True on success, False if you need to try again.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_transaction_end(XsHandle *self, PyObject *args,
@@ -571,7 +580,7 @@ static PyObject *xspy_transaction_end(Xs
return Py_False;
}
else {
- PyErr_SetFromErrno(PyExc_RuntimeError);
+ PyErr_SetFromErrno(xs_error);
return NULL;
}
}
@@ -584,7 +593,7 @@ static PyObject *xspy_transaction_end(Xs
" port [int] : port the domain is using for xenstore\n" \
"\n" \
"Returns None on success.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_introduce_domain(XsHandle *self, PyObject *args)
@@ -615,7 +624,7 @@ static PyObject *xspy_introduce_domain(X
" dom [int]: domain id\n" \
"\n" \
"Returns None on success.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_release_domain(XsHandle *self, PyObject *args)
@@ -642,7 +651,7 @@ static PyObject *xspy_release_domain(XsH
"Close the connection to xenstore.\n" \
"\n" \
"Returns None on success.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_close(XsHandle *self)
@@ -671,7 +680,7 @@ static PyObject *xspy_close(XsHandle *se
" domid [int]: domain id\n" \
"\n" \
"Returns: [string] domain store path.\n" \
- "Raises RuntimeError on error.\n" \
+ "Raises xen.lowlevel.xs.Error on error.\n" \
"\n"
static PyObject *xspy_get_domain_path(XsHandle *self, PyObject *args)
@@ -753,7 +762,7 @@ static PyObject *none(bool result)
return Py_None;
}
else {
- PyErr_SetFromErrno(PyExc_RuntimeError);
+ PyErr_SetFromErrno(xs_error);
return NULL;
}
}
@@ -829,7 +838,7 @@ xshandle_init(XsHandle *self, PyObject *
return 0;
fail:
- PyErr_SetFromErrno(PyExc_RuntimeError);
+ PyErr_SetFromErrno(xs_error);
return -1;
}
@@ -901,8 +910,13 @@ PyMODINIT_FUNC initxs(void)
if (m == NULL)
return;
+ xs_error = PyErr_NewException(PKG ".Error", PyExc_RuntimeError, NULL);
+
Py_INCREF(&xshandle_type);
PyModule_AddObject(m, CLS, (PyObject *)&xshandle_type);
+
+ Py_INCREF(xs_error);
+ PyModule_AddObject(m, "Error", xs_error);
}
[-- Attachment #3: 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] 5+ messages in thread
* Re: [PATCH] Expose exception thrown by xen.lowlevel.xs (Was Re: [PATCH] Expose exception thrown by xen.lowlevel.xc)
2006-05-19 16:35 ` [PATCH] Expose exception thrown by xen.lowlevel.xs (Was Re: [PATCH] Expose exception thrown by xen.lowlevel.xc) Anthony Liguori
@ 2006-05-19 19:44 ` Kaleb Pederson
2006-06-01 11:13 ` Ewan Mellor
1 sibling, 0 replies; 5+ messages in thread
From: Kaleb Pederson @ 2006-05-19 19:44 UTC (permalink / raw)
To: Anthony Liguori; +Cc: xen-devel, Ewan Mellor
Thanks Anthony and Ewan! Both the consistency and deriving from
RuntimeError will work much better for me -- and many others I'm sure.
--Kaleb
On 11:35 Fri 19 May , Anthony Liguori wrote:
> Got a little more time than I expected to. This one's quite a bit more
> invasive but I think it's needed to at least be consistent with
> xen.lowlevel.xc. I don't think we should be tossing an exception with
> different formats (sometimes we threw a RuntimeError with (errno, msg)
> and other times just a string--I've changed it to always be (errno, msg)).
>
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
>
> Regards,
>
> Anthony Liguori
>
> >Ewan.
> >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Expose exception thrown by xen.lowlevel.xs (Was Re: [PATCH] Expose exception thrown by xen.lowlevel.xc)
2006-05-19 16:35 ` [PATCH] Expose exception thrown by xen.lowlevel.xs (Was Re: [PATCH] Expose exception thrown by xen.lowlevel.xc) Anthony Liguori
2006-05-19 19:44 ` Kaleb Pederson
@ 2006-06-01 11:13 ` Ewan Mellor
1 sibling, 0 replies; 5+ messages in thread
From: Ewan Mellor @ 2006-06-01 11:13 UTC (permalink / raw)
To: Anthony Liguori; +Cc: xen-devel, Kaleb Pederson
On Fri, May 19, 2006 at 11:35:13AM -0500, Anthony Liguori wrote:
> Ewan Mellor wrote:
> >On Fri, May 19, 2006 at 11:16:41AM -0500, Anthony Liguori wrote:
> >
> >
> >>The attached patch exposes the exception thrown by xen.lowlevel.xc as
> >>the type xen.lowlevel.xc.Error which is an exception that inherits from
> >>RuntimeError.
> >>
> >>I only had a few minutes this morning so I didn't get to xen.lowlevel.xs
> >>but hopefully someone else can use this as a guide on what needs to be
> >>done. If noone else gets to it, I'll be able to submit another one in
> >>about a week.
> >>
> >>I've only done very basic testing but I don't expect that this should
> >>break anything...
> >>
> >
> >Thanks Anthony -- applied.
> >
>
> Got a little more time than I expected to. This one's quite a bit more
> invasive but I think it's needed to at least be consistent with
> xen.lowlevel.xc. I don't think we should be tossing an exception with
> different formats (sometimes we threw a RuntimeError with (errno, msg)
> and other times just a string--I've changed it to always be (errno, msg)).
>
> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Applied, thank you.
Ewan.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-06-01 11:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-19 16:16 [PATCH] Expose exception thrown by xen.lowlevel.xc Anthony Liguori
2006-05-19 16:31 ` Ewan Mellor
2006-05-19 16:35 ` [PATCH] Expose exception thrown by xen.lowlevel.xs (Was Re: [PATCH] Expose exception thrown by xen.lowlevel.xc) Anthony Liguori
2006-05-19 19:44 ` Kaleb Pederson
2006-06-01 11:13 ` Ewan Mellor
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.