Message ID | 1468233882-9507-1-git-send-email-marmarek@invisiblethingslab.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Mon, Jul 11, 2016 at 12:44:42PM +0200, Marek Marczykowski-Górecki wrote: > 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). > > Cc: Ian Jackson <ian.jackson@eu.citrix.com> > Cc: Wei Liu <wei.liu2@citrix.com> > Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> Thanks, this looks fine to me: Acked-by: Roger Pau Monné <roger.pau@citrix.com> Roger.
On Mon, Jul 11, 2016 at 12:44:42PM +0200, Marek Marczykowski-Górecki wrote: > 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). > > Cc: Ian Jackson <ian.jackson@eu.citrix.com> > Cc: Wei Liu <wei.liu2@citrix.com> > Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> > --- > tools/libxl/libxl.c | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c > index 1c81239..dd20e29 100644 > --- a/tools/libxl/libxl.c > +++ b/tools/libxl/libxl.c > @@ -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); 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. > + if (state == XenbusStateInitWait) > + backend_watch_callback(egc, &ddomain.watch, > + be_path, state_path); Nit, indentation. Wei. > + } > + } > + } > + } > + > return AO_INPROGRESS; > > out: > -- > 2.5.5 >
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 1c81239..dd20e29 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -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:
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). Cc: Ian Jackson <ian.jackson@eu.citrix.com> Cc: Wei Liu <wei.liu2@citrix.com> Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> --- tools/libxl/libxl.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)