Skip to contentSkip to conversation

Xenstore watch interface in the kernel

DISCUSSION Juergen Gross 4 participants 6 messages Dec 22, 2016

lore
Share & tools
lore
#0 lore raw

While working on the Linux xenbus kernel driver I stumbled over a rather strange interface: a Xenstore watch event is delivered via a callback defined as:

void (*callback)(struct xenbus_watch *,

                         const char **vec, unsigned int len);

vec is an array of strings and len the number of strings in that array.

Looking at the Xenstore interface I don't see how there could ever be an array with another len than 2 be presented (the first string being the modified path, the second the token specified when registering the watch).

I'd like to modify the callback's prototype to:

void (*callback)(struct xenbus_watch *,

                         const char *path, const char *token);

This would make it easier to avoid some memory allocation when reading a Xenstore reply, as in case of a watch event I'd know how many strings are expected.

Is there any reason not to change the interface in the kernel?

BTW: The handling of more than 2 strings as watch event parameters is even repeated in the interface to libxenstore. I looked through the Xen sources and could find no use of the number of strings returned in case of a watch event. While we can't change the interface of libxenstore I don't think we have to be prepared for an arbitrary number of strings for a watch event at the kernel interface.

Juergen

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#1 lore raw

Juergen Gross writes ("Xenstore watch interface in the kernel"):

Quoted 7 lines

While working on the Linux xenbus kernel driver I stumbled over a rather strange interface: a Xenstore watch event is delivered via a callback defined as:

void (*callback)(struct xenbus_watch *,

                         const char **vec, unsigned int len);
Quoted 7 lines

vec is an array of strings and len the number of strings in that array.

Looking at the Xenstore interface I don't see how there could ever be an array with another len than 2 be presented (the first string being the modified path, the second the token specified when registering the watch).

Yes, this is an anomaly.

IIRC (from the last time I looked at this) a long time ago in a galaxy far far away someone thought it might be a good idea to introduce some kind of payload to watch events, so that watches could be explicitly fired with a payload.

However, this wasn't in any deployed implementation.

Quoted 4 lines

I'd like to modify the callback's prototype to:

void (*callback)(struct xenbus_watch *,

                         const char *path, const char *token);

I think this would be a fine idea.

Quoted 1 line

Is there any reason not to change the interface in the kernel?

No.

Quoted 6 lines

BTW: The handling of more than 2 strings as watch event parameters is even repeated in the interface to libxenstore. I looked through the Xen sources and could find no use of the number of strings returned in case of a watch event. While we can't change the interface of libxenstore I don't think we have to be prepared for an arbitrary number of strings for a watch event at the kernel interface.

Yes.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 16 lines · you

Juergen Gross writes ("Xenstore watch interface in the kernel"):

Quoted 7 lines

While working on the Linux xenbus kernel driver I stumbled over a rather strange interface: a Xenstore watch event is delivered via a callback defined as:

void (*callback)(struct xenbus_watch *,

                         const char **vec, unsigned int len);
Quoted 7 lines

vec is an array of strings and len the number of strings in that array.

Looking at the Xenstore interface I don't see how there could ever be an array with another len than 2 be presented (the first string being the modified path, the second the token specified when registering the watch).

Quoted 8 lines

Yes, this is an anomaly.

IIRC (from the last time I looked at this) a long time ago in a galaxy far far away someone thought it might be a good idea to introduce some kind of payload to watch events, so that watches could be explicitly fired with a payload.

However, this wasn't in any deployed implementation.

Something I did ran into while trying to use xenstore, was that the callbacks don't give back the previous and current value.
So you don't really know *how* the state changed, unless you keep all change locally as well.
I have circumvented it the dirty way, by setting the token as the current value, but it isn't very pretty and all setters must adhere to that, so it's not working for the general Xen entries and therefor only useful for my own entries.

Any idea as to why the callback doesn't return the current and previous value directly ?
--
Sander

Quoted 18 lines
Quoted 4 lines

I'd like to modify the callback's prototype to:

void (*callback)(struct xenbus_watch *,

                         const char *path, const char *token);

I think this would be a fine idea.

Quoted 1 line

Is there any reason not to change the interface in the kernel?

No.

Quoted 6 lines

BTW: The handling of more than 2 strings as watch event parameters is even repeated in the interface to libxenstore. I looked through the Xen sources and could find no use of the number of strings returned in case of a watch event. While we can't change the interface of libxenstore I don't think we have to be prepared for an arbitrary number of strings for a watch event at the kernel interface.

Quoted 3 lines

Yes.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 36 lines · Sander Eikelenboom
Quoted 16 lines · you

Juergen Gross writes ("Xenstore watch interface in the kernel"):

Quoted 7 lines

While working on the Linux xenbus kernel driver I stumbled over a rather strange interface: a Xenstore watch event is delivered via a callback defined as:

void (*callback)(struct xenbus_watch *,

                         const char **vec, unsigned int len);
Quoted 7 lines

vec is an array of strings and len the number of strings in that array.

Looking at the Xenstore interface I don't see how there could ever be an array with another len than 2 be presented (the first string being the modified path, the second the token specified when registering the watch).

Quoted 8 lines

Yes, this is an anomaly.

IIRC (from the last time I looked at this) a long time ago in a galaxy far far away someone thought it might be a good idea to introduce some kind of payload to watch events, so that watches could be explicitly fired with a payload.

However, this wasn't in any deployed implementation.

Something I did ran into while trying to use xenstore, was that the callbacks don't give back the previous and current value.
So you don't really know *how* the state changed, unless you keep all change locally as well.
I have circumvented it the dirty way, by setting the token as the current value, but it isn't very pretty and all setters must adhere to that, so it's not working for the general Xen entries and therefor only useful for my own entries.

Quoted 2 lines

Any idea as to why the callback doesn't return the current and previous value directly ?

This can't work: imagine two changes of the same node made in a very short time. There is no guarantee which watch event would reach you first, so the information regarding the old and new contents could be really confusing:

node has value A
is changed to B
and then to C

You could see the watch events:

value changed from B->C
value changed from A->B

So either you would end up with the wrong new value "B" or you could track the contents in order to detect the reverse order of events, but this wouldn't be better than now.

Juergen

Quoted 28 lines

--
Sander

Quoted 21 lines
Quoted 4 lines

I'd like to modify the callback's prototype to:

void (*callback)(struct xenbus_watch *,

                         const char *path, const char *token);

I think this would be a fine idea.

Quoted 1 line

Is there any reason not to change the interface in the kernel?

No.

Quoted 6 lines

BTW: The handling of more than 2 strings as watch event parameters is even repeated in the interface to libxenstore. I looked through the Xen sources and could find no use of the number of strings returned in case of a watch event. While we can't change the interface of libxenstore I don't think we have to be prepared for an arbitrary number of strings for a watch event at the kernel interface.

Yes.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
Quoted 43 lines · Juergen Gross
Quoted 31 lines · Sander Eikelenboom
Quoted 15 lines · you

Juergen Gross writes ("Xenstore watch interface in the kernel"):

Quoted 7 lines

While working on the Linux xenbus kernel driver I stumbled over a rather strange interface: a Xenstore watch event is delivered via a callback defined as:

void (*callback)(struct xenbus_watch *,

                          const char **vec, unsigned int len);
Quoted 7 lines

vec is an array of strings and len the number of strings in that array.

Looking at the Xenstore interface I don't see how there could ever be an array with another len than 2 be presented (the first string being the modified path, the second the token specified when registering the watch).

Quoted 6 lines

Yes, this is an anomaly.
IIRC (from the last time I looked at this) a long time ago in a galaxy far far away someone thought it might be a good idea to introduce some kind of payload to watch events, so that watches could be explicitly fired with a payload.
However, this wasn't in any deployed implementation.

Something I did ran into while trying to use xenstore, was that the callbacks don't give back the previous and current value.
So you don't really know *how* the state changed, unless you keep all change locally as well.
I have circumvented it the dirty way, by setting the token as the current value, but it isn't very pretty and all setters must adhere to that, so it's not working for the general Xen entries and therefor only useful for my own entries.

Quoted 2 lines

Any idea as to why the callback doesn't return the current and previous value directly ?

This can't work: imagine two changes of the same node made in a very short time. There is no guarantee which watch event would reach you first, so the information regarding the old and new contents could be really confusing:

node has value A
is changed to B
and then to C

Quoted 8 lines

You could see the watch events:

value changed from B->C
value changed from A->B

So either you would end up with the wrong new value "B" or you could track the contents in order to detect the reverse order of events, but this wouldn't be better than now.

You can also set watches on keys which don't exist yet, and have they watch fire when the key appears. Distinguishing between not existing and having an empty value can't be done with just the previous content being sent.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#5 lore raw
In reply to Sander Eikelenboom

Sander Eikelenboom writes ("Re: [Xen-devel] Xenstore watch interface in the kernel"):

Quoted 2 lines

Something I did ran into while trying to use xenstore, was that the callbacks don't give back the previous and current value.

Others have replied to this, and I agree with them, but: this makes me think you are probably writing an incorrect algorithm or state machine.

The correct way to use a xenstore watch is to treat it a bit like an
interrupt: your code should use it as a prompt to read the value(s) it cares about. (In a transaction, if multiple reads are needed.)

The update, which reads the xenstore keys and "makes it so", should be idempotent.

Obviously your code needs to keep track of what situation it currently implements, anyway. So you shouldn't need to explicitly retain the previous xenstore contents.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel