[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH 18 of 27 v2] libxl: merge libxl__device_del into libxl__device_remove
2011/10/13 Ian Campbell <ian.campbell@xxxxxxxxxx>: > # HG changeset patch > # User Ian Campbell <ian.campbell@xxxxxxxxxx> > # Date 1318499565 -3600 > # Node ID 95b2f3977d439bba3a01db4a4403a4307f238377 > # Parent Âf60954a04df9acbddf68af4f2d46c3910f3b0afc > libxl: merge libxl__device_del into libxl__device_remove > > Note that the "wait" parameter added to libxl_device_remove is different to > the > wait paramter previously used by similar functions. In the past not-wait meant > forced whereas now in means wait for a graceful shutdown, as opposed to > setting > off a graceful shutdown but not waiting. > > Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx> > > diff -r f60954a04df9 -r 95b2f3977d43 tools/libxl/libxl.c > --- a/tools/libxl/libxl.c    Thu Oct 13 10:52:45 2011 +0100 > +++ b/tools/libxl/libxl.c    Thu Oct 13 10:52:45 2011 +0100 > @@ -1075,7 +1075,7 @@ int libxl_device_disk_del(libxl_ctx *ctx >   device.devid      Â= devid; >   device.kind       = LIBXL__DEVICE_KIND_VBD; >   if (wait) > -    Ârc = libxl__device_del(&gc, &device); > +    Ârc = libxl__device_remove(&gc, &device, wait); >   else >     rc = libxl__device_destroy(&gc, &device); > Âout_free: > @@ -1290,7 +1290,7 @@ int libxl_device_nic_del(libxl_ctx *ctx, >   device.kind       = LIBXL__DEVICE_KIND_VIF; > >   if (wait) > -    Ârc = libxl__device_del(&gc, &device); > +    Ârc = libxl__device_remove(&gc, &device, wait); >   else >     rc = libxl__device_destroy(&gc, &device); > > diff -r f60954a04df9 -r 95b2f3977d43 tools/libxl/libxl_device.c > --- a/tools/libxl/libxl_device.c    ÂThu Oct 13 10:52:45 2011 +0100 > +++ b/tools/libxl/libxl_device.c    ÂThu Oct 13 10:52:45 2011 +0100 > @@ -367,57 +367,6 @@ int libxl__device_disk_dev_number(const >   return -1; > Â} > > -int libxl__device_remove(libxl__gc *gc, libxl__device *dev) > -{ > -  Âlibxl_ctx *ctx = libxl__gc_owner(gc); > -  Âxs_transaction_t t; > -  Âchar *be_path = libxl__device_backend_path(gc, dev); > -  Âchar *state_path = libxl__sprintf(gc, "%s/state", be_path); > -  Âchar *state = libxl__xs_read(gc, XBT_NULL, state_path); > -  Âint rc = 0; > - > -  Âif (!state) > -    Âgoto out; > -  Âif (atoi(state) != 4) { > -    Âlibxl__device_destroy_tapdisk(gc, be_path); > -    Âxs_rm(ctx->xsh, XBT_NULL, be_path); > -    Âgoto out; > -  Â} > - > -retry_transaction: > -  Ât = xs_transaction_start(ctx->xsh); > -  Âxs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/online", be_path), "0", > strlen("0")); > -  Âxs_write(ctx->xsh, t, state_path, "5", strlen("5")); > -  Âif (!xs_transaction_end(ctx->xsh, t, 0)) { > -    Âif (errno == EAGAIN) > -      Âgoto retry_transaction; > -    Âelse { > -      Ârc = -1; > -      Âgoto out; > -    Â} > -  Â} > - > -  Âxs_watch(ctx->xsh, state_path, be_path); > -  Âlibxl__device_destroy_tapdisk(gc, be_path); > -  Ârc = 1; > -out: > -  Âreturn rc; > -} > - > -int libxl__device_destroy(libxl__gc *gc, libxl__device *dev) > -{ > -  Âlibxl_ctx *ctx = libxl__gc_owner(gc); > -  Âchar *be_path = libxl__device_backend_path(gc, dev); > -  Âchar *fe_path = libxl__device_frontend_path(gc, dev); > - > -  Âxs_rm(ctx->xsh, XBT_NULL, be_path); > -  Âxs_rm(ctx->xsh, XBT_NULL, fe_path); > - > -  Âlibxl__device_destroy_tapdisk(gc, be_path); > - > -  Âreturn 0; > -} > - > Âstatic int wait_for_dev_destroy(libxl__gc *gc, struct timeval *tv) > Â{ >   libxl_ctx *ctx = libxl__gc_owner(gc); > @@ -446,6 +395,67 @@ static int wait_for_dev_destroy(libxl__g >   return rc; > Â} > > +/* Returns 0 on success, ERROR_* on fail */ > +int libxl__device_remove(libxl__gc *gc, libxl__device *dev, int wait) > +{ > +  Âlibxl_ctx *ctx = libxl__gc_owner(gc); > +  Âxs_transaction_t t; > +  Âchar *be_path = libxl__device_backend_path(gc, dev); > +  Âchar *state_path = libxl__sprintf(gc, "%s/state", be_path); > +  Âchar *state = libxl__xs_read(gc, XBT_NULL, state_path); > +  Âint rc = 0; > + > +  Âif (!state) > +    Âgoto out; > +  Âif (atoi(state) != 4) { > +    Âlibxl__device_destroy_tapdisk(gc, be_path); > +    Âxs_rm(ctx->xsh, XBT_NULL, be_path); I think here we should return something different than 0 (possibly 1?) so the number of watches (n_watches) is not increased. > +    Âgoto out; > +  Â} > + > +retry_transaction: > +  Ât = xs_transaction_start(ctx->xsh); > +  Âxs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/online", be_path), "0", > strlen("0")); > +  Âxs_write(ctx->xsh, t, state_path, "5", strlen("5")); > +  Âif (!xs_transaction_end(ctx->xsh, t, 0)) { > +    Âif (errno == EAGAIN) > +      Âgoto retry_transaction; > +    Âelse { > +      Ârc = ERROR_FAIL; > +      Âgoto out; > +    Â} > +  Â} > + > +  Âxs_watch(ctx->xsh, state_path, be_path); > +  Âlibxl__device_destroy_tapdisk(gc, be_path); > + > +  Âif (wait) { > +    Âstruct timeval tv; > +    Âtv.tv_sec = LIBXL_DESTROY_TIMEOUT; > +    Âtv.tv_usec = 0; > +    Â(void)wait_for_dev_destroy(gc, &tv); > +    Âxs_rm(ctx->xsh, XBT_NULL, libxl__device_frontend_path(gc, dev)); Here we should check if the device is removed correctly or not, so that the number of watches is not increased: if(wait_for_dev_destroy(gc, &tv) != 0) /* device destroyed */ rc = 1; > +  Â} > + > +  Ârc = 0; This should also be removed, since rc is initialized to 0 already. > +out: > +  Âreturn rc; > +} > + > +int libxl__device_destroy(libxl__gc *gc, libxl__device *dev) > +{ > +  Âlibxl_ctx *ctx = libxl__gc_owner(gc); > +  Âchar *be_path = libxl__device_backend_path(gc, dev); > +  Âchar *fe_path = libxl__device_frontend_path(gc, dev); > + > +  Âxs_rm(ctx->xsh, XBT_NULL, be_path); > +  Âxs_rm(ctx->xsh, XBT_NULL, fe_path); > + > +  Âlibxl__device_destroy_tapdisk(gc, be_path); > + > +  Âreturn 0; > +} > + > Âint libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force) > Â{ >   libxl_ctx *ctx = libxl__gc_owner(gc); > @@ -485,7 +495,7 @@ int libxl__devices_destroy(libxl__gc *gc >         if (force) { >           libxl__device_destroy(gc, &dev); >         } else { > -          Âif (libxl__device_remove(gc, &dev) > 0) > +          Âif (libxl__device_remove(gc, &dev, 0) == 0) >             n_watches++; >         } >       } > @@ -504,7 +514,7 @@ int libxl__devices_destroy(libxl__gc *gc >     if (force) { >       libxl__device_destroy(gc, &dev); >     } else { > -      Âif (libxl__device_remove(gc, &dev) > 0) > +      Âif (libxl__device_remove(gc, &dev, 0) == 0) >         n_watches++; >     } >   } > @@ -530,29 +540,6 @@ out: >   return 0; > Â} > > -int libxl__device_del(libxl__gc *gc, libxl__device *dev) > -{ > -  Âlibxl_ctx *ctx = libxl__gc_owner(gc); > -  Âstruct timeval tv; > -  Âint rc; > - > -  Ârc = libxl__device_remove(gc, dev); > -  Âif (rc == -1) { > -    Ârc = ERROR_FAIL; > -    Âgoto out; > -  Â} > - > -  Âtv.tv_sec = LIBXL_DESTROY_TIMEOUT; > -  Âtv.tv_usec = 0; > -  Â(void)wait_for_dev_destroy(gc, &tv); > - > -  Âxs_rm(ctx->xsh, XBT_NULL, libxl__device_frontend_path(gc, dev)); > -  Ârc = 0; > - > -out: > -  Âreturn rc; > -} > - > Âint libxl__wait_for_device_model(libxl__gc *gc, >                 Âuint32_t domid, char *state, >                 Âlibxl__spawn_starting *spawning, > diff -r f60954a04df9 -r 95b2f3977d43 tools/libxl/libxl_internal.h > --- a/tools/libxl/libxl_internal.h   ÂThu Oct 13 10:52:45 2011 +0100 > +++ b/tools/libxl/libxl_internal.h   ÂThu Oct 13 10:52:45 2011 +0100 > @@ -242,8 +242,7 @@ _hidden char *libxl__device_backend_path > Â_hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device > *device); > Â_hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path, >                    libxl__device *dev); > -_hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev); > -_hidden int libxl__device_remove(libxl__gc *gc, libxl__device *dev); > +_hidden int libxl__device_remove(libxl__gc *gc, libxl__device *dev, int > wait); > Â_hidden int libxl__device_destroy(libxl__gc *gc, libxl__device *dev); > Â_hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force); > Â_hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char > *state); > > _______________________________________________ > Xen-devel mailing list > Xen-devel@xxxxxxxxxxxxxxxxxxx > http://lists.xensource.com/xen-devel > _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |