tools/xenstored: add support for watch depth feature
v2 cover tools/xenstored: add support for watch depth feature
In order to reduce excessive number of watch events the watch depth feature has been defined, allowing the user to limit the number of node levels below the watched node to cause events.
This series is implementing this feature for xenstored (including the PV and PVH stubdom variants).
Possible users are:
- xl/libxl: use domid information for the special @introduceDomain and @releaseDomain watches, which will be available when using depth = 1
- xenconsoled, like xl/libxl
- any PV-device backends watching directories for added devices (no watch events when any device specific node is modified)
- any PV-device frontend and backend watching the "state" node of the other side, in case the other side plays dirty games by building large sub-trees beneath the "state" node
Changes in V2:
- some minor stale changes reverted
- last patch covered by the series now, man page updated
Juergen Gross (9):
tools/xenstored: allow domU to get own features
docs: clarify Xenstore watch depth feature tools/libs/store: add support to use watches with a depth parameter tools/xenstored: add depth information to watches tools/xenstored: add depth handling to XS_WATCH tools/xenstored: replace the fire_watches() exact parameter tools/xenstored: expand special watch handling with depth feature tools/xenstored: make XENSTORE_SERVER_FEATURE_WATCHDEPTH available tools/xs-clients: support depth with xenstore-watch
docs/man/xenstore-watch.1.pod | 9 ++ docs/man/xl.cfg.5.pod.in | 6 ++ docs/misc/xenstore.txt | 14 ++- tools/include/xenstore.h | 16 +++ tools/libs/store/libxenstore.map | 2 + tools/libs/store/xs.c | 102 +++++++++++++++--- tools/xenstored/core.c | 15 ++- tools/xenstored/domain.c | 61 ++++++++--- tools/xenstored/domain.h | 2 + tools/xenstored/lu.c | 3 + tools/xenstored/transaction.c | 14 +-- tools/xenstored/transaction.h | 4 +- tools/xenstored/watch.c | 161 ++++++++++++++++++++--------- tools/xenstored/watch.h | 10 +- tools/xs-clients/xenstore_client.c | 19 +++- xen/include/public/io/xs_wire.h | 2 + 16 files changed, 343 insertions(+), 97 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/9 tools/xenstored: allow domU to get own features
Expand the XS_GET_FEATURE command to allow an unprivileged domain to read its own available features. While this information is available via the related field in the shared page used for communication with Xenstore, user land components of the domU would need special support in the related kernel driver to obtain that data. With supporting the XS_GET_FEATURE for that purpose, only an up to date libxenstore is needed.
--- docs/misc/xenstore.txt | 9 +++++---- tools/xenstored/core.c | 3 +-- tools/xenstored/domain.c | 16 +++++++++++----- 3 files changed, 17 insertions(+), 11 deletions(-)
docs/misc/xenstore.txt +5 -4
@@ -427,13 +427,14 @@ SET_FEATURE <domid>|<value>| to set a bit for a feature not being supported by the running Xenstore will be denied. Providing no <domid> with the GET_FEATURE command will return the features which are supported - by Xenstore. + by Xenstore for the domain issuing the command. SET_FEATURE for a domain will be rejected after the INTRODUCE - command for this domain has been sent to xenstored. + command for this domain has been sent to xenstored. This has the + effect that dom0 will always have all supported features enabled. - xenstored prevents the use of GET_FEATURE and SET_FEATURE other - than by dom0. + xenstored prevents the use of GET_FEATURE with a domid specified + and SET_FEATURE other than by dom0. GET_QUOTA [[<domid>|]<quota>|] <value>| SET_QUOTA [<domid>|]<quota>|<value>|
tools/xenstored/core.c +1 -2
@@ -2031,8 +2031,7 @@ static struct { { "SET_TARGET", do_set_target, XS_FLAG_PRIV }, [XS_RESET_WATCHES] = { "RESET_WATCHES", do_reset_watches }, [XS_DIRECTORY_PART] = { "DIRECTORY_PART", send_directory_part }, - [XS_GET_FEATURE ] = - { "GET_FEATURE", do_get_feature, XS_FLAG_PRIV }, + [XS_GET_FEATURE] = { "GET_FEATURE", do_get_feature }, [XS_SET_FEATURE ] = { "SET_FEATURE", do_set_feature, XS_FLAG_PRIV }, [XS_GET_QUOTA] =
tools/xenstored/domain.c +11 -5
@@ -1323,10 +1323,17 @@ int do_get_feature(const void *ctx, struct connection *conn,char *result; n_args =get_strings (in, vec,ARRAY_SIZE (vec)); -if (n_args >1 ) -return EINVAL ; -if (n_args ==1 ) { +if (!n_args) { + features = conn->domain ? conn->domain->features + :XENSTORE_FEATURES ; + }else { +if (domain_is_unprivileged (conn)) +return EACCES ; + +if (n_args >1 ) +return EINVAL ; + domid =parse_domid (vec[0 ]);if (errno)return errno;
@@ -1334,8 +1341,7 @@ int do_get_feature(const void *ctx, struct connection *conn,if (!domain)return ENOENT ; features = domain->features; - }else - features =XENSTORE_FEATURES ; + } result =talloc_asprintf (ctx,"%u" , features);if (!result)
Signature · 1 line
2.53.0
PATCH v2 2/9 docs: clarify Xenstore watch depth feature
In reply to Juergen GrossMake it explicit that for watching the @releaseDomain/<domid> special node, the XENSTORE_SERVER_FEATURE_WATCHDEPTH is needed.
--- docs/misc/xenstore.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
docs/misc/xenstore.txt +4 -1
@@ -266,7 +266,8 @@ WATCH <wpath>|<token>|[<depth>|]? decimal value of 0 or larger): it denotes the directory levels below <wpath> to consider for a match ("0" would not match for a child of <wpath>, "1" would match only for a direct child, - etc.). + etc.). The depth specification is possible only, if the + XENSTORE_SERVER_FEATURE_WATCHDEPTH feature is available. <wpath> can be a <path> to watch or @<wspecial>. In the latter case <wspecial> may have any syntax but it matches
@@ -284,6 +285,8 @@ WATCH <wpath>|<token>|[<depth>|]? values are not supported. For @releaseDomain it is possible to watch only for a specific domain by specifying @releaseDomain/<domid> for the path. + This requires the XENSTORE_SERVER_FEATURE_WATCHDEPTH to be + available. When a watch is first set up it is triggered once straight away, with <path> equal to <wpath>. Watches may be triggered
Signature · 1 line
2.53.0
PATCH v2 3/9 tools/libs/store: add support to use watches with a depth parameter
In reply to Juergen GrossAdd a new xs_watch_depth() function to libxenstore allowing to limit the scope of a Xenstore watch. It can be used only in case Xenstore is supporting the XENSTORE_SERVER_FEATURE_WATCHDEPTH feature.
For convenience add a xs_watch_try_depth() wrapper, which will call xs_watch_depth() if supported and xs_watch() otherwise.
Cache the supported features of Xenstore in order not having to get them from Xenstore for each call of one of the new functions.
---
V2:
- undo unmotivated change of variable scope (Jason Andryuk)
--- docs/man/xl.cfg.5.pod.in | 6 ++ tools/include/xenstore.h | 16 +++++ tools/libs/store/libxenstore.map | 2 + tools/libs/store/xs.c | 102 +++++++++++++++++++++++++++---- xen/include/public/io/xs_wire.h | 2 + 5 files changed, 116 insertions(+), 12 deletions(-)
docs/man/xl.cfg.5.pod.in +6 -0
@@ -740,6 +740,12 @@ Xenstore is capable to reconnect to a guest. Xenstore will present an error value in case it disconnects due to an error condition. +=item B<0x00000004> + +Xenstore supports to set watches with a limited depth (depth 0 matches +only the watched node, depth 1 matches the node and its direct children, +etc.). + =back The features supported by the running Xenstore instance can be retrieved
tools/include/xenstore.h +16 -0
@@ -177,6 +177,22 @@ bool xs_set_permissions(struct xs_handle *h, xs_transaction_t t,*/ bool xs_watch (struct xs_handle *h,const char *path,const char *token); +/* Same as xs_watch(), but with limiting the matching for modified +* children to a specified depth (depth 0 only matches the node itself, +* depth 1 will additionally match direct children of the node, etc.). +* Only supported if the XENSTORE_SERVER_FEATURE_WATCHDEPTH (4) is set +* in the returned features of xs_get_features_supported(). +*/ +bool xs_watch_depth (struct xs_handle *h,const char *path,const char *token, +unsigned int depth); + +/* If supported, same as xs_watch_depth(), use xs_watch() otherwise. +* As a result watches might trigger for nodes below the watched path, too. +* Not to be used for special watches! +*/ +bool xs_watch_try_depth (struct xs_handle *h,const char *path, +const char *token,unsigned int depth); +/* Return the FD to poll on to see if a watch has fired. */ int xs_fileno (struct xs_handle *h);
tools/libs/store/libxenstore.map +2 -0
@@ -52,4 +52,6 @@ VERS_4.2 { xs_set_global_quota; xs_get_domain_quota; xs_set_domain_quota; + xs_watch_depth; + xs_watch_try_depth; } VERS_4.1;
tools/libs/store/xs.c +90 -12
143 lines not on this page · raw message
xen/include/public/io/xs_wire.h +2 -0
@@ -124,6 +124,8 @@ struct xenstore_domain_interface {#define XENSTORE_SERVER_FEATURE_RECONNECTION 1/* The presence of the "error" field in the ring page */ #define XENSTORE_SERVER_FEATURE_ERROR 2 +/* The XS_WATCH command can be used with a <depth> parameter */ +#define XENSTORE_SERVER_FEATURE_WATCHDEPTH 4/* Valid values for the connection field */ #define XENSTORE_CONNECTED 0/* the steady-state */
Signature · 1 line
2.53.0
Re: [PATCH v2 3/9] tools/libs/store: add support to use watches with a depth parameter
Quoted 19 lines · Juergen Gross
Add a new
xs_watch_depth()function to libxenstore allowing to limit the scope of a Xenstore watch. It can be used only in case Xenstore is supporting theXENSTORE_SERVER_FEATURE_WATCHDEPTHfeature.For convenience add a
xs_watch_try_depth()wrapper, which will callxs_watch_depth()if supported andxs_watch()otherwise.Cache the supported features of Xenstore in order not having to get them from Xenstore for each call of one of the new functions.
Signed-off-by Juergen Gross <[email protected]>tools/libs/store/xs.c +0
-0
tools/libs/store/xs.c bool xs_watch(struct xs_handle *h, const char *path, const char *token) · line 997
Quoted 7 lines
tools/libs/store/xs.c +2
-2@@ -1001,8 +993,8 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token)# define PTHREAD_STACK_MIN 0#endif -#define READ_THREAD_STACKSIZE \ - ((DEFAULT_THREAD_STACKSIZE < PTHREAD_STACK_MIN) ? \ +#define READ_THREAD_STACKSIZE \ + ((DEFAULT_THREAD_STACKSIZE < PTHREAD_STACK_MIN) ? \
This is an unrelated whitespace change, and not mentioned in the commit message. It should probably be dropped since the surrounding lines are no longer touched. Alternatively kept and mentioned. With either of those:
Thanks,
Jason
Quoted 3 lines
tools/libs/store/xs.c +0
-0PTHREAD_STACK_MIN : DEFAULT_THREAD_STACKSIZE)/* We dynamically create a reader thread on demand. */
Re: [PATCH v2 3/9] tools/libs/store: add support to use watches with a depth parameter
Quoted 30 lines · Jason Andryuk
Quoted 19 lines · Juergen Gross
Add a new
xs_watch_depth()function to libxenstore allowing to limit the scope of a Xenstore watch. It can be used only in case Xenstore is supporting theXENSTORE_SERVER_FEATURE_WATCHDEPTHfeature.For convenience add a
xs_watch_try_depth()wrapper, which will callxs_watch_depth()if supported andxs_watch()otherwise.Cache the supported features of Xenstore in order not having to get them from Xenstore for each call of one of the new functions.
Signed-off-by Juergen Gross <[email protected]>tools/libs/store/xs.c +0
-0tools/libs/store/xs.c bool xs_watch(struct xs_handle *h, const char *path, · line 997
Quoted 7 lines
tools/libs/store/xs.c +2
-2@@ -1001,8 +993,8 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token) # define PTHREAD_STACK_MIN 0 #endif -#define READ_THREAD_STACKSIZE \ - ((DEFAULT_THREAD_STACKSIZE < PTHREAD_STACK_MIN) ? \ +#define READ_THREAD_STACKSIZE \ + ((DEFAULT_THREAD_STACKSIZE < PTHREAD_STACK_MIN) ? \This is an unrelated whitespace change, and not mentioned in the commit message. It should probably be dropped since the surrounding lines are no longer touched. Alternatively kept and mentioned. With either of those:
Quoted 1 line
Reviewed-by Jason Andryuk <[email protected]>
Thanks.
Whoever is committing this: I'd rather expand the commit message with:
While touching the file fix a whitespace issue.
Shall I resubmit this patch, or can this be amended while committing?
Juergen
Re: [PATCH v2 3/9] tools/libs/store: add support to use watches with a depth parameter
Quoted 35 lines · Jürgen Groß
Quoted 32 lines · Jason Andryuk
Quoted 19 lines · Juergen Gross
Add a new
xs_watch_depth()function to libxenstore allowing to limit the scope of a Xenstore watch. It can be used only in case Xenstore is supporting theXENSTORE_SERVER_FEATURE_WATCHDEPTHfeature.For convenience add a
xs_watch_try_depth()wrapper, which will callxs_watch_depth()if supported andxs_watch()otherwise.Cache the supported features of Xenstore in order not having to get them from Xenstore for each call of one of the new functions.
Signed-off-by Juergen Gross <[email protected]>tools/libs/store/xs.c +0
-0tools/libs/store/xs.c bool xs_watch(struct xs_handle *h, const char *path, · line 997
Quoted 7 lines
tools/libs/store/xs.c +2
-2@@ -1001,8 +993,8 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token) # define PTHREAD_STACK_MIN 0 #endif -#define READ_THREAD_STACKSIZE \ - ((DEFAULT_THREAD_STACKSIZE < PTHREAD_STACK_MIN) ? \ +#define READ_THREAD_STACKSIZE \ + ((DEFAULT_THREAD_STACKSIZE < PTHREAD_STACK_MIN) ? \This is an unrelated whitespace change, and not mentioned in the commit message. It should probably be dropped since the surrounding lines are no longer touched. Alternatively kept and mentioned. With either of those:
Quoted 1 line
Reviewed-by Jason Andryuk <[email protected]>
Quoted 7 lines
Thanks.
Whoever is committing this: I'd rather expand the commit message with:
While touching the file fix a whitespace issue.
Shall I resubmit this patch, or can this be amended while committing?
Of course it can be.
Jan
PATCH v2 4/9 tools/xenstored: add depth information to watches
In reply to Juergen GrossAdd the depth for matching subdirectories of a watch to the watch handling. A depth value of -1 is used for the current model of no limit.
--- tools/xenstored/lu.c | 3 ++ tools/xenstored/watch.c | 110 ++++++++++++++++++++++++++++------------ tools/xenstored/watch.h | 1 + 3 files changed, 81 insertions(+), 33 deletions(-)
tools/xenstored/lu.c +3 -0
@@ -183,6 +183,9 @@ void lu_read_state(void)case XS_STATE_TYPE_WATCH :read_state_watch (ctx, state.buf);break ; +case XS_STATE_TYPE_WATCH_EXT : +read_state_watch_ext (ctx, state.buf); +break ;case XS_STATE_TYPE_TA :xprintf ("live-update: ignore transaction record\n" );break ;
tools/xenstored/watch.c +77 -33
191 lines not on this page · raw message
tools/xenstored/watch.h +1 -0
@@ -37,5 +37,6 @@ const char *dump_state_watches(FILE *fp, struct connection *conn, unsigned int conn_id);void read_state_watch (const void *ctx,const void *state); +void read_state_watch_ext (const void *ctx,const void *state);#endif /* _XENSTORED_WATCH_H */
Signature · 1 line
2.53.0
PATCH v2 5/9 tools/xenstored: add depth handling to XS_WATCH
In reply to Juergen GrossIn case XENSTORE_SERVER_FEATURE_WATCHDEPTH is set, allow XS_WATCH to have "depth" as 3rd parameter.
--- tools/xenstored/domain.c | 8 ++++++++ tools/xenstored/domain.h | 2 ++ tools/xenstored/watch.c | 11 +++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-)
tools/xenstored/domain.c +8 -0
@@ -390,6 +390,14 @@ void wrl_apply_debit_trans_commit(struct connection *conn)wrl_apply_debit_actual (conn->domain); } +bool feature_available (const struct connection *conn,unsigned int feature) +{ +if (!conn->domain) +return XENSTORE_FEATURES & feature; + +return conn->domain->features & feature; +} +static unsigned int domain_get_soft_quota (struct domain *d,enum accitem what) {if (d && d->acc[what].val[Q_IDX_SOFT ] !=Q_VAL_DISABLED )
tools/xenstored/domain.h +2 -0
@@ -188,4 +188,6 @@ struct hashtable *domain_check_acc_init(void);void domain_check_acc_add (const struct node *node,struct hashtable *domains);void domain_check_acc (struct hashtable *domains); +bool feature_available (const struct connection *conn,unsigned int feature); +#endif /* _XENSTORED_DOMAIN_H */
tools/xenstored/watch.c +9 -2
@@ -213,11 +213,18 @@ static struct watch *add_watch(struct connection *conn, const char *path,int do_watch (const void *ctx,struct connection *conn,struct buffered_data *in) {struct watch *watch; -const char *vec[2 ]; +const char *vec[3 ]; +unsigned int n_pars;int depth =-1 ;bool relative; -if (get_strings (in, vec,ARRAY_SIZE (vec)) !=ARRAY_SIZE (vec)) + n_pars =get_strings (in, vec,ARRAY_SIZE (vec)); +if (n_pars ==3 && +feature_available (conn,XENSTORE_SERVER_FEATURE_WATCHDEPTH )) { + depth =atoi (vec[2 ]); +if (depth <0 ) +return EINVAL ; + }else if (n_pars !=2 )return EINVAL ; errno =check_watch_path (conn, ctx, &(vec[0 ]), &relative);
Signature · 1 line
2.53.0
PATCH v2 6/9 tools/xenstored: replace the fire_watches() exact parameter
In reply to Juergen GrossToday fire_watches() has the boolean "exact" parameter specifying how the matching of the modified node with registered watches is to be handled (only the exact node name is matching or all nodes being in the subtree beneath the watched node).
For the handling of <special-watch>/<domid> watch events 2 additional matching possibility needs to be added, as those events should only be delivered to clients having requested such events, either by watching <special-watch> with the depth=1 parameter, or by directly watching for <special-watch>/<domid>, while the traditional special watch events should NOT delivered to those watchers.
For this purpose rename the "exact" parameter to "match" and make it an enum with four possible values.
--- tools/xenstored/core.c | 12 +++++----- tools/xenstored/transaction.c | 14 +++++++----- tools/xenstored/transaction.h | 4 +++- tools/xenstored/watch.c | 42 +++++++++++++++++++++++++---------- tools/xenstored/watch.h | 9 +++++++- 5 files changed, 55 insertions(+), 26 deletions(-)
tools/xenstored/core.c +6 -6
@@ -1613,7 +1613,7 @@ static int do_write(const void *ctx, struct connection *conn,return errno; } -fire_watches (conn, ctx, name, node, false,NULL ); +fire_watches (conn, ctx, name, node,MATCH_SUBTREE ,NULL );send_ack (conn,XS_WRITE );return 0 ;
@@ -1637,7 +1637,7 @@ static int do_mkdir(const void *ctx, struct connection *conn, node =create_node (conn, ctx, name,NULL ,0 );if (!node)return errno; -fire_watches (conn, ctx, name, node, false,NULL ); +fire_watches (conn, ctx, name, node,MATCH_SUBTREE ,NULL ); }send_ack (conn,XS_MKDIR );
@@ -1683,7 +1683,7 @@ static int delnode_sub(const void *ctx, struct connection *conn, struct node *node, void *arg) {const char *root = arg; -bool watch_exact; +enum watch_match watch_match;int ret;const char *db_name;
@@ -1703,8 +1703,8 @@ static int delnode_sub(const void *ctx, struct connection *conn,* This fine as we are single threaded and the next possible read will * be handled only after the node has been really removed. */ - watch_exact =strcmp (root, node->name); -fire_watches (conn, ctx, node->name, node, watch_exact,NULL ); + watch_match =strcmp (root, node->name) ?MATCH_EXACT :MATCH_SUBTREE ; +fire_watches (conn, ctx, node->name, node, watch_match,NULL );return WALK_TREE_RM_CHILDENTRY ; }
@@ -1858,7 +1858,7 @@ static int do_set_perms(const void *ctx, struct connection *conn,if (write_node (conn, node,NODE_MODIFY , false))return errno; -fire_watches (conn, ctx, name, node, false, &old_perms); +fire_watches (conn, ctx, name, node,MATCH_SUBTREE , &old_perms);send_ack (conn,XS_SET_PERMS );return 0 ;
tools/xenstored/transaction.c +8 -6
@@ -134,7 +134,7 @@ struct accessed_node/* Watch event flags. */ bool fire_watch; -bool watch_exact; +enum watch_match watch_match; };struct transaction
@@ -327,8 +327,10 @@ err:* A watch event should be fired for a node modified inside a transaction. * Set the corresponding information. A non-exact event is replacing an exact * one, but not the other way round. +* No special watch handling needed here, so MATCH_DEPTH is no issue. */ -void queue_watches (struct connection *conn,const char *name,bool watch_exact) +void queue_watches (struct connection *conn,const char *name, +enum watch_match watch_match) {struct accessed_node *i;
@@ -340,9 +342,9 @@ void queue_watches(struct connection *conn, const char *name, bool watch_exact)if (!i->fire_watch) { i->fire_watch = true; - i->watch_exact = watch_exact; - }else if (!watch_exact) { - i->watch_exact = false; + i->watch_match = watch_match; + }else if (watch_match ==MATCH_SUBTREE ) { + i->watch_match =MATCH_SUBTREE ; } }
@@ -419,7 +421,7 @@ static int finalize_transaction(struct connection *conn,db_delete (conn, i->node,NULL ); }if (i->fire_watch) -fire_watches (conn, trans, i->node,NULL , i->watch_exact, +fire_watches (conn, trans, i->node,NULL , i->watch_match, i->perms.p ? &i->perms :NULL );list_del (&i->list);
tools/xenstored/transaction.h +3 -1
@@ -18,6 +18,7 @@#ifndef _XENSTORED_TRANSACTION_H#define _XENSTORED_TRANSACTION_H#include "core.h" +#include "watch.h" enum node_access_type { NODE_ACCESS_READ,
@@ -44,7 +45,8 @@ int __must_check access_node(struct connection *conn, struct node *node, enum node_access_type type, const char **db_name);/* Queue watches for a modified node. */ -void queue_watches (struct connection *conn,const char *name,bool watch_exact); +void queue_watches (struct connection *conn,const char *name, +enum watch_match watch_match);/* Prepend the transaction to name if appropriate. */ const char *transaction_prepend (struct connection *conn,const char *name);
tools/xenstored/watch.c +30 -12
61 lines not on this page · raw message
tools/xenstored/watch.h +8 -1
@@ -27,8 +27,15 @@ int do_unwatch(const void *ctx, struct connection *conn, struct buffered_data *in);/* Fire all watches: !exact means all the children are affected (ie. rm). */ +enum watch_match { +MATCH_EXACT , +MATCH_SUBTREE , +MATCH_DEPTH ,/* watches with depth > 0, MATCH_SUBTREE semantics */ +MATCH_NODEPTH /* watches with no depth, MATCH_EXACT semantics */ +}; +void fire_watches (struct connection *conn,const void *tmp,const char *name, -const struct node *node,bool exact, +const struct node *node,enum watch_match match,struct node_perms *perms);void conn_delete_all_watches (struct connection *conn);
Signature · 1 line
2.53.0
PATCH v2 7/9 tools/xenstored: expand special watch handling with depth feature
In reply to Juergen GrossWith XENSTORE_SERVER_FEATURE_WATCHDEPTH available, special watch handling needs to be extended:
- when a special watch is set with depth = 1, the domid is added to the watch event
- it is possible to watch for @releaseDomain/<domid>
---
V2:
- remove stray {} addition (Jason Andryuk)
--- tools/xenstored/domain.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-)
tools/xenstored/domain.c +26 -8
@@ -616,7 +616,12 @@ static void domain_tree_remove(struct domain *domain)walk_node_tree (domain,NULL ,"@introduceDomain" , &walkfuncs, domain); } -static void fire_special_watches (const char *name) +#define WATCH_NODOM 1/* Fire watches without <domid> extension. */ +#define WATCH_DOM 2/* Fire watches with <domid> extension. */ +#define WATCH_BOTH (WATCH_NODOM | WATCH_DOM) + +static void fire_special_watches (const char *name,unsigned int domid, +unsigned int watchdom_flag) {void *ctx =talloc_new (NULL );const struct node *node;
@@ -626,9 +631,19 @@ static void fire_special_watches(const char *name) node =read_node_const (NULL , ctx, name); -if (node) -fire_watches (NULL , ctx, name, node, true,NULL ); -else +if (node) { +if (watchdom_flag &WATCH_NODOM ) +fire_watches (NULL , ctx, name, node,MATCH_NODEPTH , +NULL ); +if (watchdom_flag &WATCH_DOM ) { +char name_dom[24 ];/* max. "@introduceDomain/domid" */ + +snprintf (name_dom,sizeof (name_dom), +"%s/%u" , name, domid); +fire_watches (NULL , ctx, name_dom, node,MATCH_DEPTH , +NULL ); + } + }else log ("special node %s not found\n" , name);talloc_free (ctx);
@@ -653,7 +668,7 @@ static int destroy_domain(void *_domain)if (domain->interface)unmap_interface (domain->domid, domain->interface); -fire_special_watches ("@releaseDomain" ); +fire_special_watches ("@releaseDomain" , domain->domid,WATCH_BOTH );wrl_domain_destroy (domain);
@@ -681,6 +696,8 @@ static int do_check_domain(struct domain *domain, bool *notify,if ((state &XENMANAGE_GETDOMSTATE_STATE_SHUTDOWN ) && !domain->shutdown) { domain->shutdown = true; +fire_special_watches ("@releaseDomain" , domain->domid, +WATCH_DOM ); *notify = true; }if (!(state &XENMANAGE_GETDOMSTATE_STATE_DEAD ))
@@ -723,7 +740,7 @@ void check_domains(void) ;if (notify) -fire_special_watches ("@releaseDomain" ); +fire_special_watches ("@releaseDomain" ,0 ,WATCH_NODOM ); }static struct domain *find_domain_struct (unsigned int domid)
@@ -747,7 +764,7 @@ static void do_check_domains(void) }if (notify) -fire_special_watches ("@releaseDomain" ); +fire_special_watches ("@releaseDomain" ,0 ,WATCH_NODOM ); }/* We scan all domains rather than use the information given here. */
@@ -1112,7 +1129,8 @@ static struct domain *introduce_domain(const void *ctx,talloc_steal (domain->conn, domain);if (!is_priv_domain && !restore) -fire_special_watches ("@introduceDomain" ); +fire_special_watches ("@introduceDomain" , domid, +WATCH_BOTH ); }else {/* Use XS_INTRODUCE for recreating the xenbus event-channel. */ if (domain->port)
Signature · 1 line
2.53.0
PATCH v2 8/9 tools/xenstored: make XENSTORE_SERVER_FEATURE_WATCHDEPTH available
In reply to Juergen GrossAdd XENSTORE_SERVER_FEATURE_WATCHDEPTH to the available features now that all needed support has been added.
--- tools/xenstored/domain.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/xenstored/domain.c +2 -1
@@ -43,7 +43,8 @@#include <mini-os/xenbus.h> #endif -#define XENSTORE_FEATURES XENSTORE_SERVER_FEATURE_ERROR +#define XENSTORE_FEATURES (XENSTORE_SERVER_FEATURE_ERROR | \ + XENSTORE_SERVER_FEATURE_WATCHDEPTH)static xenmanage_handle *xm_handle;xengnttab_handle **xgt_handle;
Signature · 1 line
2.53.0
PATCH v2 9/9 tools/xs-clients: support depth with xenstore-watch
In reply to Juergen GrossAdd a "-d <depth>" parameter to xenstore-watch, allowing to specify the depth parameter of the XS_WATCH command.
Using "-d" without support of depth by xenstored will refuse to set the watch(es).
---
V2:
- add new flag to man page (Jason Andryuk)
--- docs/man/xenstore-watch.1.pod | 9 +++++++++ tools/xs-clients/xenstore_client.c | 19 +++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-)
docs/man/xenstore-watch.1.pod +9 -0
@@ -17,6 +17,15 @@ event happening. Show the usage information for xenstore-watch and exit the program. +=item B<-d> B<depth> + +Limit the number of sub-directories below the specified I<PATH>s to be +watched. A B<depth> of 0 will watch only the specified nodes, a B<depth> +of 1 will watch the specified nodes and their direct children, etc. + +Using this option requires xenstored to support the Xenstore watch depth +feature. In case it is not supported, the B<-d> usage will be rejected. + =item B<-n> B<NR> Stop waiting after having received B<NR> watch events.
tools/xs-clients/xenstore_client.c +15 -4
@@ -445,7 +445,7 @@ do_watch(struct xs_handle *xsh, int max_events)static int perform (enum mode mode,int optind,int argc,char **argv,struct xs_handle *xsh,xs_transaction_t xth,int prefix,int tidy,int upto,int recurse,int nr_watches, -int raw) +int raw,int depth) {switch (mode) {case MODE_ls:
@@ -627,8 +627,11 @@ perform(enum mode mode, int optind, int argc, char **argv, struct xs_handle *xshfor (; argv[optind]; optind++) {const char *w = argv[optind]; -if (!xs_watch (xsh, w, w)) +if (depth <0 && !xs_watch (xsh, w, w))errx (1 ,"Unable to add watch on %s\n" , w); +if (depth >=0 && !xs_watch_depth (xsh, w, w, depth)) +errx (1 ,"Unable to add watch on %s with depth %d\n" , w, + depth); }do_watch (xsh, nr_watches); }
@@ -676,6 +679,7 @@ main(int argc, char **argv)int nr_watches =-1 ;int transaction;int raw =0 ; +int depth =-1 ;struct winsize ws;enum mode mode;
@@ -709,10 +713,11 @@ main(int argc, char **argv) {"recurse", 0, 0, 'r'}, /* MODE_chmod */ {"number", 1, 0, 'n'}, /* MODE_watch */ {"raw", 0, 0, 'R'}, /* MODE_read || MODE_write */ + {"depth", 1, 0, 'd'}, /* MODE_watch */ {0, 0, 0, 0} }; - c =getopt_long (argc - switch_argv, argv + switch_argv,"hfspturn:R" , + c =getopt_long (argc - switch_argv, argv + switch_argv,"hfspturn:Rd:" , long_options, &index);if (c ==-1 )break ;
@@ -766,6 +771,12 @@ main(int argc, char **argv)else usage (1 , mode, switch_argv, argv[0 ]);break ; +case 'd' : +if ( mode == MODE_watch ) + depth =atoi (optarg); +else +usage (1 , mode, switch_argv, argv[0 ]); +break ; } }
@@ -819,7 +830,7 @@ again:errx (1 ,"couldn't start transaction" ); } - ret =perform (mode, optind, argc - switch_argv, argv + switch_argv, xsh, xth, prefix, tidy, upto, recurse, nr_watches, raw); + ret =perform (mode, optind, argc - switch_argv, argv + switch_argv, xsh, xth, prefix, tidy, upto, recurse, nr_watches, raw, depth);if (transaction && !xs_transaction_end (xsh, xth, ret)) {if (ret ==0 && errno ==EAGAIN ) {
Signature · 1 line
2.53.0
Quoted 17 lines · Juergen Gross
In order to reduce excessive number of watch events the watch depth feature has been defined, allowing the user to limit the number of node levels below the watched node to cause events.
This series is implementing this feature for xenstored (including the PV and PVH stubdom variants).
Possible users are:
- xl/libxl: use domid information for the special @introduceDomain and @releaseDomain watches, which will be available when using depth = 1
- xenconsoled, like xl/libxl
- any PV-device backends watching directories for added devices (no watch events when any device specific node is modified)
Quoted 7 lines
- any PV-device frontend and backend watching the "state" node of the other side, in case the other side plays dirty games by building large sub-trees beneath the "state" node
Changes in V2:
- some minor stale changes reverted
- last patch covered by the series now, man page updated
Is this really everything that changed? I wanted to commit the first two patches from v1, but I had to leave out patch 1 as it didn't apply. Patch 2 I have in pre-push testing already, but as mentioned on Matrix there's a so far unexplained build issue (definitely not related to this series, though).
Jan
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Juergen Gross
In order to reduce excessive number of watch events the watch depth feature has been defined, allowing the user to limit the number of node levels below the watched node to cause events.
This series is implementing this feature for xenstored (including the PV and PVH stubdom variants).
Possible users are:
- xl/libxl: use domid information for the special @introduceDomain and @releaseDomain watches, which will be available when using depth = 1
- xenconsoled, like xl/libxl
- any PV-device backends watching directories for added devices (no watch events when any device specific node is modified)
- any PV-device frontend and backend watching the "state" node of the other side, in case the other side plays dirty games by building large sub-trees beneath the "state" node
Quoted 6 lines
Quoted 3 lines
Changes in V2:
- some minor stale changes reverted
- last patch covered by the series now, man page updatedIs this really everything that changed? I wanted to commit the first two patches from v1, but I had to leave out patch 1 as it didn't apply. Patch
Ah, there was change in the patch context due to the per-domain quota series:
a literal atoi() was replaced by a parse_domid().
Juergen