libxl: trigger attach events for devices attached before xl devd startup
PATCH 1/1 libxl: trigger attach events for devices attached before xl devd startup
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domain
End result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
--- tools/libxl/libxl.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
tools/libxl/libxl.c +40 -0
@@ -4743,8 +4743,16 @@ int libxl_device_events_handler(libxl_ctx *ctx,uint32_t domid;libxl__ddomain ddomain;char *be_path; +char **kinds =NULL , **domains =NULL , **devs =NULL ; +const char *sstate; +char *state_path; +int state; +unsigned int nkinds, ndomains, ndevs; +int i, j, k; +xs_transaction_t t; ddomain.ao = ao; +FILLZERO (ddomain.watch);LIBXL_SLIST_INIT (&ddomain.guests); rc =libxl__get_domid (gc, &domid);
@@ -4762,9 +4770,41 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path);if (rc) goto out; + rc =libxl__xs_transaction_start (gc, &t); +if (rc) goto out; + kinds =libxl__xs_directory (gc, t, be_path, &nkinds); +if (kinds) { +for (i =0 ; i < nkinds; i++) { + domains =libxl__xs_directory (gc, t, +GCSPRINTF ("%s/%s" , be_path, kinds[i]), &ndomains); +if (!domains) +continue ; +for (j =0 ; j < ndomains; j++) { + devs =libxl__xs_directory (gc, t, +GCSPRINTF ("%s/%s/%s" , be_path, kinds[i], domains[j]), &ndevs); +if (!devs) +continue ; +for (k =0 ; k < ndevs; k++) { + state_path =GCSPRINTF ("%s/%s/%s/%s/state" , + be_path, kinds[i], domains[j], devs[k]); + rc =libxl__xs_read_checked (gc, t, state_path, &sstate); +if (rc) +continue ; + state =atoi (sstate); +if (state == XenbusStateInitWait) +backend_watch_callback (egc, &ddomain.watch, + be_path, state_path); + } + } + } + } + +libxl__xs_transaction_abort (gc, &t); +return AO_INPROGRESS ; out: +libxl__ev_xswatch_deregister (gc, &ddomain.watch);return AO_CREATE_FAIL (rc); }
Signature · 7 lines
2.5.5 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 10 lines · Marek Marczykowski-Górecki
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domain
Quoted 7 lines
End result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
Thanks!
Quoted 15 lines
Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Signed-off-by Marek Marczykowski-Górecki <[email protected]>--- tools/libxl/libxl.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tools/libxl/libxl.c +0
-0@@ -4743,8 +4743,16 @@ int libxl_device_events_handler(libxl_ctx *ctx,uint32_t domid;libxl__ddomain ddomain;char *be_path;
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4755
Quoted 10 lines
tools/libxl/libxl.c +8
-0+char **kinds =NULL , **domains =NULL , **devs =NULL ; +const char *sstate; +char *state_path; +int state; +unsigned int nkinds, ndomains, ndevs; +int i, j, k; +xs_transaction_t t; ddomain.ao = ao; +FILLZERO (ddomain.watch);
Is this a different bugfix or stray change?
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4774
Quoted 9 lines
tools/libxl/libxl.c +2
-0LIBXL_SLIST_INIT (&ddomain.guests); rc =libxl__get_domid (gc, &domid);@@ -4762,9 +4770,41 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path);if (rc) goto out; + rc =libxl__xs_transaction_start (gc, &t); +if (rc) goto out;
Why do you need to start a transaction here if you end up aborting it when finished?
Quoted 23 lines
tools/libxl/libxl.c +23
-0+ kinds =libxl__xs_directory (gc, t, be_path, &nkinds); +if (kinds) { +for (i =0 ; i < nkinds; i++) { + domains =libxl__xs_directory (gc, t, +GCSPRINTF ("%s/%s" , be_path, kinds[i]), &ndomains); +if (!domains) +continue ; +for (j =0 ; j < ndomains; j++) { + devs =libxl__xs_directory (gc, t, +GCSPRINTF ("%s/%s/%s" , be_path, kinds[i], domains[j]), &ndevs); +if (!devs) +continue ; +for (k =0 ; k < ndevs; k++) { + state_path =GCSPRINTF ("%s/%s/%s/%s/state" , + be_path, kinds[i], domains[j], devs[k]); + rc =libxl__xs_read_checked (gc, t, state_path, &sstate); +if (rc) +continue ; + state =atoi (sstate); +if (state == XenbusStateInitWait) +backend_watch_callback (egc, &ddomain.watch, + be_path, state_path); + }
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4807
Quoted 10 lines
tools/libxl/libxl.c +7
-0+ } + } + } + +libxl__xs_transaction_abort (gc, &t); +return AO_INPROGRESS ; out: +libxl__ev_xswatch_deregister (gc, &ddomain.watch);
This seems to be part of a different bugfix also.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 44 lines · Roger Pau Monné
Quoted 10 lines · Marek Marczykowski-Górecki
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domainQuoted 7 lines
End result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
Thanks!
Quoted 23 lines
Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Signed-off-by Marek Marczykowski-Górecki <[email protected]>--- tools/libxl/libxl.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tools/libxl/libxl.c +7
-0@@ -4743,8 +4743,16 @@ int libxl_device_events_handler(libxl_ctx *ctx,uint32_t domid;libxl__ddomain ddomain;char *be_path; +char **kinds =NULL , **domains =NULL , **devs =NULL ; +const char *sstate; +char *state_path; +int state; +unsigned int nkinds, ndomains, ndevs; +int i, j, k; +xs_transaction_t t;
Quoted 4 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4755
Quoted 2 lines
tools/libxl/libxl.c +1
-0ddomain.ao = ao; +FILLZERO (ddomain.watch);Is this a different bugfix or stray change?
To cleanly unregister watch and not do nothing if wasn't registered at all. If it isn't initialized, libxl__ev_xswatch_deregister call on not registered watch isn't harmless.
Quoted 7 lines
Quoted 7 lines
tools/libxl/libxl.c +0
-0LIBXL_SLIST_INIT (&ddomain.guests); rc =libxl__get_domid (gc, &domid);@@ -4762,9 +4770,41 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path);if (rc) goto out;
Quoted 5 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4774
Quoted 2 lines
tools/libxl/libxl.c +2
-0+ rc =libxl__xs_transaction_start (gc, &t); +if (rc) goto out;Why do you need to start a transaction here if you end up aborting it when finished?
Mostly to ease error checking. Because below code does three level listing, I don't want to deal with races where some entry was removed between those calls, at least not here. Like this:
xs_directory('backend/vif') -> 3, 4, 5xs_directory('backend/vif/3') -> 0, 1xs_read('backend/vif/3/0/state') -> ...xs_read('backend/vif/3/1/state') -> ...
toolstack removes backend/vif/4 herexs_directory('backend/vif/4') -> fail
Of course backend_watch_callback would fail anyway in such a case, which is ok. But having snapshot of xenstore during this multi-level listing looks like avoiding some corner cases during listing itself.
Quoted 31 lines
Quoted 31 lines
tools/libxl/libxl.c +29
-0+ kinds =libxl__xs_directory (gc, t, be_path, &nkinds); +if (kinds) { +for (i =0 ; i < nkinds; i++) { + domains =libxl__xs_directory (gc, t, +GCSPRINTF ("%s/%s" , be_path, kinds[i]), &ndomains); +if (!domains) +continue ; +for (j =0 ; j < ndomains; j++) { + devs =libxl__xs_directory (gc, t, +GCSPRINTF ("%s/%s/%s" , be_path, kinds[i], domains[j]), &ndevs); +if (!devs) +continue ; +for (k =0 ; k < ndevs; k++) { + state_path =GCSPRINTF ("%s/%s/%s/%s/state" , + be_path, kinds[i], domains[j], devs[k]); + rc =libxl__xs_read_checked (gc, t, state_path, &sstate); +if (rc) +continue ; + state =atoi (sstate); +if (state == XenbusStateInitWait) +backend_watch_callback (egc, &ddomain.watch, + be_path, state_path); + } + } + } + } + +libxl__xs_transaction_abort (gc, &t); +return AO_INPROGRESS ;
Quoted 4 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4807
Quoted 2 lines
tools/libxl/libxl.c +1
-0out: +libxl__ev_xswatch_deregister (gc, &ddomain.watch);This seems to be part of a different bugfix also.
No, this code previously wasn't reachable if xswatch was correctly registered.
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 45 lines · Marek Marczykowski-Górecki
Quoted 44 lines · Roger Pau Monné
Quoted 10 lines · Marek Marczykowski-Górecki
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domainQuoted 7 lines
End result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
Thanks!
Quoted 23 lines
Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Signed-off-by Marek Marczykowski-Górecki <[email protected]>--- tools/libxl/libxl.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tools/libxl/libxl.c +7
-0@@ -4743,8 +4743,16 @@ int libxl_device_events_handler(libxl_ctx *ctx,uint32_t domid;libxl__ddomain ddomain;char *be_path; +char **kinds =NULL , **domains =NULL , **devs =NULL ; +const char *sstate; +char *state_path; +int state; +unsigned int nkinds, ndomains, ndevs; +int i, j, k; +xs_transaction_t t;
Quoted 8 lines
Quoted 4 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4755
Quoted 2 lines
tools/libxl/libxl.c +1
-0ddomain.ao = ao; +FILLZERO (ddomain.watch);Is this a different bugfix or stray change?
To cleanly unregister watch and not do nothing if wasn't registered at all. If it isn't initialized,
libxl__ev_xswatch_deregistercall on not registered watch isn't harmless.
Right, I've realized that before your changes the function only registered the watch and exited, this is needed now.
Quoted 24 lines
Quoted 7 lines
Quoted 7 lines
tools/libxl/libxl.c +0
-0LIBXL_SLIST_INIT (&ddomain.guests); rc =libxl__get_domid (gc, &domid);@@ -4762,9 +4770,41 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path);if (rc) goto out;Quoted 5 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4774
Quoted 2 lines
tools/libxl/libxl.c +2
-0+ rc =libxl__xs_transaction_start (gc, &t); +if (rc) goto out;Why do you need to start a transaction here if you end up aborting it when finished?
Mostly to ease error checking. Because below code does three level listing, I don't want to deal with races where some entry was removed between those calls, at least not here. Like this:
xs_directory('backend/vif')-> 3, 4, 5xs_directory('backend/vif/3')-> 0, 1xs_read('backend/vif/3/0/state')-> ...xs_read('backend/vif/3/1/state')-> ...
toolstack removes backend/vif/4 herexs_directory('backend/vif/4')-> fail
Quoted 3 lines
Of course
backend_watch_callbackwould fail anyway in such a case, which is ok. But having snapshot of xenstore during this multi-level listing looks like avoiding some corner cases during listing itself.
AFAICT your code seems to be prepared to deal with entries disappearing in the middle of the tree walk, so I would just remove the transaction.
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
tools/libxl/libxl.c +29
-0+ kinds =libxl__xs_directory (gc, t, be_path, &nkinds); +if (kinds) { +for (i =0 ; i < nkinds; i++) { + domains =libxl__xs_directory (gc, t, +GCSPRINTF ("%s/%s" , be_path, kinds[i]), &ndomains); +if (!domains) +continue ; +for (j =0 ; j < ndomains; j++) { + devs =libxl__xs_directory (gc, t, +GCSPRINTF ("%s/%s/%s" , be_path, kinds[i], domains[j]), &ndevs); +if (!devs) +continue ; +for (k =0 ; k < ndevs; k++) { + state_path =GCSPRINTF ("%s/%s/%s/%s/state" , + be_path, kinds[i], domains[j], devs[k]); + rc =libxl__xs_read_checked (gc, t, state_path, &sstate); +if (rc) +continue ; + state =atoi (sstate); +if (state == XenbusStateInitWait) +backend_watch_callback (egc, &ddomain.watch, + be_path, state_path); + } + } + } + } + +libxl__xs_transaction_abort (gc, &t); +return AO_INPROGRESS ;
Quoted 7 lines
Quoted 4 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4807
Quoted 2 lines
tools/libxl/libxl.c +1
-0out: +libxl__ev_xswatch_deregister (gc, &ddomain.watch);This seems to be part of a different bugfix also.
No, this code previously wasn't reachable if xswatch was correctly registered.
Right, thanks.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 82 lines · Roger Pau Monné
Quoted 45 lines · Marek Marczykowski-Górecki
Quoted 44 lines · Roger Pau Monné
Quoted 10 lines · Marek Marczykowski-Górecki
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domainQuoted 7 lines
End result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
Thanks!
Quoted 23 lines
Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Signed-off-by Marek Marczykowski-Górecki <[email protected]>--- tools/libxl/libxl.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tools/libxl/libxl.c +7
-0@@ -4743,8 +4743,16 @@ int libxl_device_events_handler(libxl_ctx *ctx,uint32_t domid;libxl__ddomain ddomain;char *be_path; +char **kinds =NULL , **domains =NULL , **devs =NULL ; +const char *sstate; +char *state_path; +int state; +unsigned int nkinds, ndomains, ndevs; +int i, j, k; +xs_transaction_t t;Quoted 8 lines
Quoted 4 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4755
Quoted 2 lines
tools/libxl/libxl.c +1
-0ddomain.ao = ao; +FILLZERO (ddomain.watch);Is this a different bugfix or stray change?
To cleanly unregister watch and not do nothing if wasn't registered at all. If it isn't initialized,
libxl__ev_xswatch_deregistercall on not registered watch isn't harmless.Right, I've realized that before your changes the function only registered the watch and exited, this is needed now.
Quoted 24 lines
Quoted 7 lines
Quoted 7 lines
tools/libxl/libxl.c +0
-0LIBXL_SLIST_INIT (&ddomain.guests); rc =libxl__get_domid (gc, &domid);@@ -4762,9 +4770,41 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path);if (rc) goto out;Quoted 5 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4774
Quoted 2 lines
tools/libxl/libxl.c +2
-0+ rc =libxl__xs_transaction_start (gc, &t); +if (rc) goto out;Why do you need to start a transaction here if you end up aborting it when finished?
Mostly to ease error checking. Because below code does three level listing, I don't want to deal with races where some entry was removed between those calls, at least not here. Like this:
xs_directory('backend/vif')-> 3, 4, 5xs_directory('backend/vif/3')-> 0, 1xs_read('backend/vif/3/0/state')-> ...xs_read('backend/vif/3/1/state')-> ...
toolstack removes backend/vif/4 herexs_directory('backend/vif/4')-> fail
Quoted 6 lines
Quoted 3 lines
Of course
backend_watch_callbackwould fail anyway in such a case, which is ok. But having snapshot of xenstore during this multi-level listing looks like avoiding some corner cases during listing itself.AFAICT your code seems to be prepared to deal with entries disappearing in the middle of the tree walk, so I would just remove the transaction.
Actually I'm considering changing error handling below to "goto out" instead of "continue", as race condition should be eliminated by the transaction, other errors (permission denied for example) maybe should be considered fatal. So, IMO there two options:
- ignore failed reads and remove transaction
- error on failed reads and keep transaction
Which one would be better?
Quoted 42 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
tools/libxl/libxl.c +29
-0+ kinds =libxl__xs_directory (gc, t, be_path, &nkinds); +if (kinds) { +for (i =0 ; i < nkinds; i++) { + domains =libxl__xs_directory (gc, t, +GCSPRINTF ("%s/%s" , be_path, kinds[i]), &ndomains); +if (!domains) +continue ; +for (j =0 ; j < ndomains; j++) { + devs =libxl__xs_directory (gc, t, +GCSPRINTF ("%s/%s/%s" , be_path, kinds[i], domains[j]), &ndevs); +if (!devs) +continue ; +for (k =0 ; k < ndevs; k++) { + state_path =GCSPRINTF ("%s/%s/%s/%s/state" , + be_path, kinds[i], domains[j], devs[k]); + rc =libxl__xs_read_checked (gc, t, state_path, &sstate); +if (rc) +continue ; + state =atoi (sstate); +if (state == XenbusStateInitWait) +backend_watch_callback (egc, &ddomain.watch, + be_path, state_path); + } + } + } + } + +libxl__xs_transaction_abort (gc, &t); +return AO_INPROGRESS ;Quoted 7 lines
Quoted 4 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4807
Quoted 2 lines
tools/libxl/libxl.c +1
-0out: +libxl__ev_xswatch_deregister (gc, &ddomain.watch);This seems to be part of a different bugfix also.
No, this code previously wasn't reachable if xswatch was correctly registered.
Right, thanks.
Roger.
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 90 lines · Marek Marczykowski-Górecki
Quoted 82 lines · Roger Pau Monné
Quoted 45 lines · Marek Marczykowski-Górecki
Quoted 44 lines · Roger Pau Monné
Quoted 10 lines · Marek Marczykowski-Górecki
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domainQuoted 7 lines
End result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
Thanks!
Quoted 23 lines
Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Signed-off-by Marek Marczykowski-Górecki <[email protected]>--- tools/libxl/libxl.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)tools/libxl/libxl.c +7
-0@@ -4743,8 +4743,16 @@ int libxl_device_events_handler(libxl_ctx *ctx,uint32_t domid;libxl__ddomain ddomain;char *be_path; +char **kinds =NULL , **domains =NULL , **devs =NULL ; +const char *sstate; +char *state_path; +int state; +unsigned int nkinds, ndomains, ndevs; +int i, j, k; +xs_transaction_t t;Quoted 8 lines
Quoted 4 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4755
Quoted 2 lines
tools/libxl/libxl.c +1
-0ddomain.ao = ao; +FILLZERO (ddomain.watch);Is this a different bugfix or stray change?
To cleanly unregister watch and not do nothing if wasn't registered at all. If it isn't initialized,
libxl__ev_xswatch_deregistercall on not registered watch isn't harmless.Right, I've realized that before your changes the function only registered the watch and exited, this is needed now.
Quoted 24 lines
Quoted 7 lines
Quoted 7 lines
tools/libxl/libxl.c +0
-0LIBXL_SLIST_INIT (&ddomain.guests); rc =libxl__get_domid (gc, &domid);@@ -4762,9 +4770,41 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path);if (rc) goto out;Quoted 5 lines
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4774
Quoted 2 lines
tools/libxl/libxl.c +2
-0+ rc =libxl__xs_transaction_start (gc, &t); +if (rc) goto out;Why do you need to start a transaction here if you end up aborting it when finished?
Mostly to ease error checking. Because below code does three level listing, I don't want to deal with races where some entry was removed between those calls, at least not here. Like this:
xs_directory('backend/vif')-> 3, 4, 5xs_directory('backend/vif/3')-> 0, 1xs_read('backend/vif/3/0/state')-> ...xs_read('backend/vif/3/1/state')-> ...
toolstack removes backend/vif/4 herexs_directory('backend/vif/4')-> failQuoted 6 lines
Quoted 3 lines
Of course
backend_watch_callbackwould fail anyway in such a case, which is ok. But having snapshot of xenstore during this multi-level listing looks like avoiding some corner cases during listing itself.AFAICT your code seems to be prepared to deal with entries disappearing in the middle of the tree walk, so I would just remove the transaction.
Quoted 8 lines
Actually I'm considering changing error handling below to "goto out" instead of "continue", as race condition should be eliminated by the transaction, other errors (permission denied for example) maybe should be considered fatal. So, IMO there two options:
- ignore failed reads and remove transaction
- error on failed reads and keep transactionWhich one would be better?
IMHO, I think the first option is better, and you already have it coded.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v2 1/1 libxl: trigger attach events for devices attached before xl devd startup
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domain
End result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
--- tools/libxl/libxl.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
tools/libxl/libxl.c +33 -0
@@ -4743,6 +4743,12 @@ int libxl_device_events_handler(libxl_ctx *ctx,uint32_t domid;libxl__ddomain ddomain;char *be_path; +char **kinds =NULL , **domains =NULL , **devs =NULL ; +const char *sstate; +char *state_path; +int state; +unsigned int nkinds, ndomains, ndevs; +int i, j, k; ddomain.ao = ao;LIBXL_SLIST_INIT (&ddomain.guests);
@@ -4762,6 +4768,33 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path);if (rc) goto out; + kinds =libxl__xs_directory (gc,XBT_NULL , be_path, &nkinds); +if (kinds) { +for (i =0 ; i < nkinds; i++) { + domains =libxl__xs_directory (gc,XBT_NULL , +GCSPRINTF ("%s/%s" , be_path, kinds[i]), &ndomains); +if (!domains) +continue ; +for (j =0 ; j < ndomains; j++) { + devs =libxl__xs_directory (gc,XBT_NULL , +GCSPRINTF ("%s/%s/%s" , be_path, kinds[i], domains[j]), &ndevs); +if (!devs) +continue ; +for (k =0 ; k < ndevs; k++) { + state_path =GCSPRINTF ("%s/%s/%s/%s/state" , + be_path, kinds[i], domains[j], devs[k]); + rc =libxl__xs_read_checked (gc,XBT_NULL , state_path, &sstate); +if (rc) +continue ; + state =atoi (sstate); +if (state == XenbusStateInitWait) +backend_watch_callback (egc, &ddomain.watch, + be_path, state_path); + } + } + } + } +return AO_INPROGRESS ; out:
Signature · 7 lines
2.5.5 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 13 lines · Marek Marczykowski-Górecki
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domainEnd result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Quoted 8 lines
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Signed-off-by Marek Marczykowski-Górecki <[email protected]>
Thanks, this looks fine to me:
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Quoted 55 lines · Marek Marczykowski-Górecki
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domainEnd result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Signed-off-by Marek Marczykowski-Górecki <[email protected]>--- tools/libxl/libxl.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)tools/libxl/libxl.c +15
-0@@ -4743,6 +4743,12 @@ int libxl_device_events_handler(libxl_ctx *ctx,uint32_t domid;libxl__ddomain ddomain;char *be_path; +char **kinds =NULL , **domains =NULL , **devs =NULL ; +const char *sstate; +char *state_path; +int state; +unsigned int nkinds, ndomains, ndevs; +int i, j, k; ddomain.ao = ao;LIBXL_SLIST_INIT (&ddomain.guests);@@ -4762,6 +4768,33 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path);if (rc) goto out; + kinds =libxl__xs_directory (gc,XBT_NULL , be_path, &nkinds); +if (kinds) { +for (i =0 ; i < nkinds; i++) { + domains =libxl__xs_directory (gc,XBT_NULL , +GCSPRINTF ("%s/%s" , be_path, kinds[i]), &ndomains); +if (!domains) +continue ; +for (j =0 ; j < ndomains; j++) { + devs = libxl__xs_directory(gc, XBT_NULL,
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4789
Quoted 10 lines
tools/libxl/libxl.c +10
-0+ GCSPRINTF("%s/%s/%s", be_path, kinds[i], domains[j]), &ndevs); +if (!devs) +continue ; +for (k =0 ; k < ndevs; k++) { + state_path =GCSPRINTF ("%s/%s/%s/%s/state" , + be_path, kinds[i], domains[j], devs[k]); + rc =libxl__xs_read_checked (gc,XBT_NULL , state_path, &sstate); +if (rc) +continue ; + state =atoi (sstate);
Need to check sstate != NULL before passing it to atoi, because libxl__xs_read_checked can return NULL if there is no such entry in xenstore.
tools/libxl/libxl.c int libxl_device_events_handler(libxl_ctx *ctx, · line 4792
Quoted 3 lines
tools/libxl/libxl.c +3
-0+if (state == XenbusStateInitWait) +backend_watch_callback (egc, &ddomain.watch, + be_path, state_path);
Nit, indentation.
Wei.
Quoted 11 lines
tools/libxl/libxl.c +5
-0+ } + } + } + } +return AO_INPROGRESS ; out:Signature · 1 line
2.5.5
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
PATCH v3 1/1 libxl: trigger attach events for devices attached before xl devd startup
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domain
End result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
---
Changes since v2:
- check for sstate being NULL
- minor indentation
tools/libxl/libxl.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
tools/libxl/libxl.c +33 -0
@@ -4743,6 +4743,12 @@ int libxl_device_events_handler(libxl_ctx *ctx,uint32_t domid;libxl__ddomain ddomain;char *be_path; +char **kinds =NULL , **domains =NULL , **devs =NULL ; +const char *sstate; +char *state_path; +int state; +unsigned int nkinds, ndomains, ndevs; +int i, j, k; ddomain.ao = ao;LIBXL_SLIST_INIT (&ddomain.guests);
@@ -4762,6 +4768,33 @@ int libxl_device_events_handler(libxl_ctx *ctx, be_path);if (rc) goto out; + kinds =libxl__xs_directory (gc,XBT_NULL , be_path, &nkinds); +if (kinds) { +for (i =0 ; i < nkinds; i++) { + domains =libxl__xs_directory (gc,XBT_NULL , +GCSPRINTF ("%s/%s" , be_path, kinds[i]), &ndomains); +if (!domains) +continue ; +for (j =0 ; j < ndomains; j++) { + devs =libxl__xs_directory (gc,XBT_NULL , +GCSPRINTF ("%s/%s/%s" , be_path, kinds[i], domains[j]), &ndevs); +if (!devs) +continue ; +for (k =0 ; k < ndevs; k++) { + state_path =GCSPRINTF ("%s/%s/%s/%s/state" , + be_path, kinds[i], domains[j], devs[k]); + rc =libxl__xs_read_checked (gc,XBT_NULL , state_path, &sstate); +if (rc || !sstate) +continue ; + state =atoi (sstate); +if (state == XenbusStateInitWait) +backend_watch_callback (egc, &ddomain.watch, + be_path, state_path); + } + } + } + } +return AO_INPROGRESS ; out:
Signature · 7 lines
2.5.5 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Quoted 13 lines · Marek Marczykowski-Górecki
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domainEnd result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Quoted 8 lines
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Signed-off-by Marek Marczykowski-Górecki <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Wei Liu
AppliedQuoted 19 lines · Wei Liu
Quoted 18 lines · Marek Marczykowski-Górecki
When this daemon is started after creating backend device, that device will not be configured.
Racy situation:
1. driver domain is started
2. frontend domain is started (just after kicking driver domain off)
3. device in frontend domain is connected to the backend (as specified in frontend domain configuration)
4. xl devd is started in driver domainEnd result is that backend device in driver domain is not configured (like network interface is not enabled), so the device doesn't work.
Fix this by artifically triggering events for devices already present in xenstore before xl devd is started. Do this only after xenstore watch is already registered, and only for devices not already initialized (in XenbusStateInitWait state).
Quoted 5 lines
Quoted 3 lines
Cc Ian Jackson <[email protected]>Cc Wei Liu <[email protected]>Signed-off-by Marek Marczykowski-Górecki <[email protected]>Acked-by Wei Liu <[email protected]>
Queued. Thanks.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel