xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Wei Liu <wei.liu2@citrix.com>
To: Sergei Lebedev <sergei.a.lebedev@gmail.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	xen-devel@lists.xen.org
Subject: Re: [BUG] xs.watch and xs.unwatch are unreliable
Date: Wed, 2 Mar 2016 16:03:38 +0000	[thread overview]
Message-ID: <20160302160338.GA23172@citrix.com> (raw)
In-Reply-To: <834E88AE-F08A-415F-8C24-D4FDEFEB01B3@gmail.com>

I've CC'ed some people who might have an idea whether they are replying
on this behaviour. I doubt that but let's better be sure...

On Tue, Mar 01, 2016 at 11:17:54PM +0300, Sergei Lebedev wrote:
> Hi list,
> 
> I’ve initially wanted to report another inconsistency in ``xen.lowlevel.xs`` documentation, but this time the issue is more subtle.
> 
> Both ``xs.watch`` and ``xs.unwatch`` accept two arguments: a path to watch and a token. According to the documentation, the second argument must be a string, which makes sense, since the token should be sent directly to XenStore. Instead of doing the simple thing (transmitting the token as-is), the implementation makes a new token from *the pointer* to the token object and sends it instead:
> 
>     PyObject *token;
>     char token_str[MAX_STRLEN(unsigned long) + 1];
> 
>     snprintf(token_str, sizeof(token_str), "%li", (unsigned long)token);
> 
> This does work for simple cases, e.g. if a token is a string literal 
> 
>     >>> from xen.lowlevel.xs import xs
>     >>> h = xs()
>     >>> h.watch(“@introduceDomain”, “token”)
>     >>> h.unwatch(“@introduceDomain”, “token”)
> 
> or a small number
> 
>     >>> h.watch(“@introduceDomain”, 42)
>     >>> h.unwatch(“@introduceDomain”, 42)
> 
> But in the general case this is broken
> 
>     >>> h.watch("@introduceDomain", 100000000000000000000000000000)
>     >>> h.unwatch("@introduceDomain", 100000000000000000000000000000)
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>     xen.lowlevel.xs.Error: (2, 'No such file or directory’)
> 
> Here’s another example with a string token
> 
>     >>> token1 = str(100000000000000000000000000000)
>     >>> token2 = str(100000000000000000000000000000)
>     >>> token1 == token2
>     True
>     >>> h.watch("@introduceDomain", token1)
>     >>> h.unwatch("@introduceDomain", token2)
>     Traceback (most recent call last):
>       File "<stdin>", line 1, in <module>
>     xen.lowlevel.xs.Error: (2, 'No such file or directory’)
> 
> I’m not sure what would be the best way to handle this as there might be existing code relying on this undocumented behaviour. What do you think?
> 

In any case this looks like a real bug.

The fix (as you said) is to transmit the token. I don't think your
proposed fix would break existing users though.

Wei.


> Regards,
> Sergei
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel

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

  reply	other threads:[~2016-03-02 16:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-01 20:17 [BUG] xs.watch and xs.unwatch are unreliable Sergei Lebedev
2016-03-02 16:03 ` Wei Liu [this message]
2016-03-03 16:47 ` David Vrabel
2016-03-03 17:02   ` Wei Liu
2016-03-03 17:18     ` David Vrabel
2016-03-03 18:57       ` Wei Liu

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=20160302160338.GA23172@citrix.com \
    --to=wei.liu2@citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=sergei.a.lebedev@gmail.com \
    --cc=xen-devel@lists.xen.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).