ia64/xen-unstable

changeset 7359:00a324b3a2db

Ignore any watches that fire for which we do not have a registration. This can
happen if there are watches in flight at the same time as a deregistration, and
also seems to happen spuriously on xend restart.

This fixes the Invalid token error that has been seen on xend restart.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Wed Oct 12 13:00:55 2005 +0100 (2005-10-12)
parents 09447f91ab49
children b938c4965a8f
files tools/python/xen/lowlevel/xs/xs.c tools/python/xen/xend/xenstore/xswatch.py
line diff
     1.1 --- a/tools/python/xen/lowlevel/xs/xs.c	Wed Oct 12 12:56:52 2005 +0100
     1.2 +++ b/tools/python/xen/lowlevel/xs/xs.c	Wed Oct 12 13:00:55 2005 +0100
     1.3 @@ -513,6 +513,7 @@ static PyObject *xspy_read_watch(PyObjec
     1.4          goto exit;
     1.5      if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec))
     1.6          goto exit;
     1.7 +again:
     1.8      Py_BEGIN_ALLOW_THREADS
     1.9      xsval = xs_read_watch(xh, &num);
    1.10      Py_END_ALLOW_THREADS
    1.11 @@ -529,8 +530,13 @@ static PyObject *xspy_read_watch(PyObjec
    1.12              break;
    1.13      }
    1.14      if (i == PyList_Size(xsh->watches)) {
    1.15 -        PyErr_SetString(PyExc_RuntimeError, "invalid token");
    1.16 -        goto exit;
    1.17 +      /* We do not have a registered watch for the one that has just fired.
    1.18 +         Ignore this -- a watch that has been recently deregistered can still
    1.19 +         have watches in transit.  This is a blocking method, so go back to
    1.20 +         read again.
    1.21 +      */
    1.22 +      free(xsval);
    1.23 +      goto again;
    1.24      }
    1.25      /* Create tuple (path, token). */
    1.26      val = Py_BuildValue("(sO)", xsval[XS_WATCH_PATH], token);
     2.1 --- a/tools/python/xen/xend/xenstore/xswatch.py	Wed Oct 12 12:56:52 2005 +0100
     2.2 +++ b/tools/python/xen/xend/xenstore/xswatch.py	Wed Oct 12 13:00:55 2005 +0100
     2.3 @@ -10,6 +10,9 @@ import threading
     2.4  from xen.lowlevel import xs
     2.5  from xen.xend.xenstore.xsutil import xshandle
     2.6  
     2.7 +from xen.xend.XendLogging import log
     2.8 +
     2.9 +
    2.10  class xswatch:
    2.11  
    2.12      watchThread = None
    2.13 @@ -41,10 +44,13 @@ class xswatch:
    2.14          while True:
    2.15              try:
    2.16                  we = cls.xs.read_watch()
    2.17 -            except RuntimeError, ex:
    2.18 -                print ex
    2.19 -                raise
    2.20 -            watch = we[1]
    2.21 -            watch.fn(*watch.args, **watch.kwargs)
    2.22 +                watch = we[1]
    2.23 +                watch.fn(*watch.args, **watch.kwargs)
    2.24 +            except:
    2.25 +                log.exception("read_watch failed")
    2.26 +                # Ignore this exception -- there's no point throwing it
    2.27 +                # further on because that will just kill the watcher thread,
    2.28 +                # which achieves nothing.
    2.29 +
    2.30  
    2.31      watchMain = classmethod(watchMain)