xs.watch and xs.unwatch are unreliable
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
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
from xen.lowlevel.xs import xs
h =xs()h.watch(“@introduceDomain”, “token”)h.unwatch(“@introduceDomain”, “token”)
or a small number
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
h.watch(“@introduceDomain”, 42)h.unwatch(“@introduceDomain”, 42)
But in the general case this is broken
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
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
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
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?
Regards,
Sergei
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
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...
Quoted 36 lines · Sergei Lebedev
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
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
from xen.lowlevel.xs import xs
h =xs()h.watch(“@introduceDomain”, “token”)h.unwatch(“@introduceDomain”, “token”)or a small number
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
h.watch(“@introduceDomain”, 42)h.unwatch(“@introduceDomain”, 42)But in the general case this is broken
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
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
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
token1 = str(100000000000000000000000000000)
token2 = str(100000000000000000000000000000)
token1 == token2
Quoted 9 lines
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.
Quoted 6 lines
Regards,
Sergei
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 5 lines · Sergei Lebedev
Hi list,
I’ve initially wanted to report another inconsistency in ``xen.lowlevel.xs`` documentation, but this time the issue is more subtle.
[...]
Quoted 12 lines
Here’s another example with a string token
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
token1 = str(100000000000000000000000000000)
token2 = str(100000000000000000000000000000)
token1 == token2True >>> 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’)
Quoted 3 lines
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?
I think you're stuck with this behaviour. If you fix it there's a risk of breaking existing applications by unwatch removing the wrong watch.
Perhaps you could extend the watch API to return a watch object that has an unwatch() method?
watch = h.watch("/some/path", "token")
...
watch.unwatch()
David
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 21 lines · David Vrabel
Quoted 5 lines · Sergei Lebedev
Hi list,
I’ve initially wanted to report another inconsistency in ``xen.lowlevel.xs`` documentation, but this time the issue is more subtle.
[...]
Quoted 12 lines
Here’s another example with a string token
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
token1 = str(100000000000000000000000000000)
token2 = str(100000000000000000000000000000)
token1 == token2True >>> 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’)
Quoted 7 lines
Quoted 3 lines
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?
I think you're stuck with this behaviour. If you fix it there's a risk of breaking existing applications by unwatch removing the wrong watch.
I'm not sure I follow this. Do you have an example why it would remove the wrong watch?
Wei.
Quoted 7 lines
Perhaps you could extend the watch API to return a watch object that has an
unwatch()method?watch =
h.watch("/some/path", "token")
...
watch.unwatch()
Quoted 6 lines
David
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 26 lines · Wei Liu
Quoted 25 lines · David Vrabel
Quoted 5 lines · Sergei Lebedev
Hi list,
I’ve initially wanted to report another inconsistency in ``xen.lowlevel.xs`` documentation, but this time the issue is more subtle.
[...]
Quoted 15 lines
Here’s another example with a string token
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
token1 = str(100000000000000000000000000000)
token2 = str(100000000000000000000000000000)
token1 == token2True >>> 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?
Quoted 6 lines
Quoted 3 lines
I think you're stuck with this behaviour. If you fix it there's a risk of breaking existing applications by unwatch removing the wrong watch.
I'm not sure I follow this. Do you have an example why it would remove the wrong watch?
token1 = str(100000000000000000000000000000)
token2 = str(100000000000000000000000000000)
h.watch("path", token1)
h.watch("path", token2)
Created two unique tokens.
h.unwatch("path", token1)
Which watch should be removed if token1 and token2 no longer have a unique token? Although, I'm not sure of the behaviour of adding two watches with the same token.
It also occurs to me that if this area is going to be improved, it should be the kernel that provides the token since it has to be unique across all users.
David
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 40 lines · David Vrabel
Quoted 26 lines · Wei Liu
Quoted 25 lines · David Vrabel
Quoted 5 lines · Sergei Lebedev
Hi list,
I’ve initially wanted to report another inconsistency in ``xen.lowlevel.xs`` documentation, but this time the issue is more subtle.
[...]
Quoted 15 lines
Here’s another example with a string token
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
token1 = str(100000000000000000000000000000)
token2 = str(100000000000000000000000000000)
token1 == token2True >>> 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?
Quoted 6 lines
Quoted 3 lines
I think you're stuck with this behaviour. If you fix it there's a risk of breaking existing applications by unwatch removing the wrong watch.
I'm not sure I follow this. Do you have an example why it would remove the wrong watch?
token1 = str(100000000000000000000000000000)
token2 = str(100000000000000000000000000000)
h.watch("path", token1)
h.watch("path", token2)
Quoted 8 lines
Created two unique tokens.
h.unwatch("path", token1)Which watch should be removed if token1 and token2 no longer have a unique token? Although, I'm not sure of the behaviour of adding two watches with the same token.
Right. I also have no idea what the behaviour should be...
But given the incarnation of the binding, user would expect it to behave the same as the underlying C API. Python binding is not responsible for covering up the undefined behaviour.
And a side note is that the bindings of xs_watch and xs_unwatch can only be used safely in very restricted way. That is, user needs to stash the exact token object somewhere, which is not impossible, but also very inconvenient.
Let's either document this behaviour or change it. I don't have preference here.
Quoted 4 lines
It also occurs to me that if this area is going to be improved, it should be the kernel that provides the token since it has to be unique across all users.
This would be good.
Wei.
Quoted 1 line
David
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel