[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RESEND PATCH 12/12] golang/xenlight: add NotifyDomainDeath method to Context


  • To: Nick Rosbrook <rosbrookn@xxxxxxxxx>
  • From: George Dunlap <George.Dunlap@xxxxxxxxxx>
  • Date: Fri, 18 Jun 2021 18:28:47 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M70gTATHOyQFtqqrtQeN05DFbaJkhmQ4gWznLU+T/Bc=; b=T6WDL5xISxg9X2i4bUn5VYloBcZira2dHuSS1JY2W7l83E5kGMg72G1ZuyHPSYzrPVWeKGdi9AruhJC0M2WzbAZ+mf3quJSkfiOMd2TZppmSPDF4E32F178psTR0z6ABhtdPaDdaKNm7oFVpeTHof813afk8XSalYvB32c/MVHRc2U2o6HsaiKX4PWQ10G3TSGHr4tyI2wNpuXXXp8Y/wYI8kd0U6h3OfYq/yablzPlsDucFRcDRM2TfUobpBupUhy7HnvFVye2HEKq6TIxBFKU8vmMUxinhr+XMyUOz+tzy2N1NrNWERn0XZ8msgxMH2uaO3FU74HrgZg394u3oJA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KfS/prxqV3f1b7hP7Mvp+ANlYuiJmaz1bj0otmJX14z05joWQMC+mKdClK6jKSM5/1NfUd9B5H2yD6d76l3OPKtR4ouKbOYnbGNt149lVBQX7RX0Gd5QIy2/U0aOVk+HG2BKI5huoDSQb2RfAg1mkbt95Ly1JOiL3dLLNbNEf6ApPH1JYuvX4QSuUQI/Pz4Jj5CiHUt0jTdyJT31PNbSyKskro8xGZLUWJtiexFmvcd5nXhlxPZFD0xIuipCmtPLGEy4iFcc83wZDW4+1BOmS6Qzi17K/URsEGO82jey7h8/8W8UN3V6Aei2U98v5DOLDSgZAmAV8cx7sJPJnYd/+Q==
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Fri, 18 Jun 2021 18:29:08 +0000
  • Ironport-hdrordr: A9a23:wLZUAqDcQp+esv3lHegZsceALOsnbusQ8zAXPh9KJCC9I/bzqy nxpp8mPEfP+U4ssQIb6Ku90ci7MD3hHPtOjbX5Uo3SODUO1FHIEGgm1/qa/9SCIVy+ygc+79 YGT0EWMrSZYjZHZITBkW+F+r0bsbq6GdWT9ILjJgBWPGNXgs9bjztRO0K+KAlbVQNGDZ02GN 63/cxcvQetfnwRc4CSGmQFd/KrnayJqLvWJTo9QzI34giHij2lrJTgFQKD4xsYWzRThZ8/7G n+lRDj7KnLiYD49vac7R6X031loqqn9jJxPr3LtiHTEES0tu+cXvUkZ1RFhkFsnAjg0idwrD CGmWZbAy060QKtQojym2qs5+Co6kde15c7pGXo/kcKeqHCNUwH4xAtv/MkTjLJr0ElppV7iv 0Wm3+UsJJREHr77VPAzsmNWBdwmkWup30+1eYVknxESIMbLKRctIoF4SpuYd099Q/Bmcga+d NVfYrhDTdtACenRmGcunMqzM2nX3w1EBvDSk8eutaN2zwTmHxi1UMXyMEWg39FrfsGOtV5zv WBNr4tmKBFT8cQY644DOAdQdGvAmiIRR7XKmqdLVnuCalCMXPQrJz85qkz+YiRCdE1JVsJ6d 38uXZjxCEPkm7VeL+zNaxwg2bwqT+GLEfQI+lllu1EU5PHNcrWDRE=
  • Ironport-sdr: p1yKKSg80IUkElYVko/bszzkkhCpRy57MqVSOfWh1lWIHSuGJk2yMgScsZoPduPMT2ujAwco7T tVYPW+L6BIdHLtPN/OybwXqzAcBnOfWw4moIkj5GK9J2rkNbBeq0BFeU6f4ORJt1XHGLfZzzS/ 5tK/gbDAZjo1esMAACbTFyOSjvbz7N1/zdyR8X3dwZXDXGk80etk3s+dm3AoYnlVb+V19SHuZq q/kJovfijwBtJ+ZCvCsg1NN5rQunRnRUd3599eh03OyPdDNy/ZwfFBFMzX68C7sv4xVRH3j1ab oP8=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHXUNy1vChg4LMpNU6QjEPyRTou1KsaPdIA
  • Thread-topic: [RESEND PATCH 12/12] golang/xenlight: add NotifyDomainDeath method to Context


> On May 24, 2021, at 9:36 PM, Nick Rosbrook <rosbrookn@xxxxxxxxx> wrote:
> 
> Add a helper function to wait for domain death events, and then write
> the events to a provided channel. This handles the enabling/disabling of
> the event type, freeing the event, and converting it to a Go type. The
> caller can then handle the event however they need to. This function
> will run until a provided context.Context is cancelled.
> 
> NotifyDomainDeath spawns two goroutines that return when the
> context.Context is done. The first will make sure that the domain death
> event is disabled, and that the corresponding event queue is cleared.
> The second calls libxl_event_wait, and writes the event to the provided
> channel.
> 
> With this, callers should be able to manage a full domain life cycle.
> Add to the comment of DomainCreateNew so that package uses know they
> should use this method in conjunction with DomainCreateNew.
> 
> Signed-off-by: Nick Rosbrook <rosbrookn@xxxxxxxxxxxx>
> ---
> tools/golang/xenlight/xenlight.go | 83 ++++++++++++++++++++++++++++++-
> 1 file changed, 82 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/golang/xenlight/xenlight.go 
> b/tools/golang/xenlight/xenlight.go
> index 6fb22665cc..8406883433 100644
> --- a/tools/golang/xenlight/xenlight.go
> +++ b/tools/golang/xenlight/xenlight.go
> @@ -53,6 +53,7 @@ import "C"
>  */
> 
> import (
> +     "context"
>       "fmt"
>       "os"
>       "os/signal"
> @@ -1340,7 +1341,9 @@ func (ctx *Context) DeviceUsbdevRemove(domid Domid, 
> usbdev *DeviceUsbdev) error
>       return nil
> }
> 
> -// DomainCreateNew creates a new domain.
> +// DomainCreateNew creates a new domain. Callers of DomainCreateNew are
> +// responsible for handling the death of the resulting domain. This should be
> +// done using NotifyDomainDeath.
> func (ctx *Context) DomainCreateNew(config *DomainConfig) (Domid, error) {
>       var cdomid C.uint32_t
>       var cconfig C.libxl_domain_config
> @@ -1358,6 +1361,84 @@ func (ctx *Context) DomainCreateNew(config 
> *DomainConfig) (Domid, error) {
>       return Domid(cdomid), nil
> }
> 
> +// NotifyDomainDeath registers an event handler for domain death events for a
> +// given domnid, and writes events received to ec. NotifyDomainDeath returns 
> an
> +// error if it cannot register the event handler, but other errors 
> encountered
> +// are just logged. The goroutine spawned by calling NotifyDomainDeath runs
> +// until the provided context.Context's Done channel is closed.
> +func (ctx *Context) NotifyDomainDeath(c context.Context, domid Domid, ec 
> chan<- Event) error {
> +     var deathw *C.libxl_evgen_domain_death
> +
> +     ret := C.libxl_evenable_domain_death(ctx.ctx, C.uint32_t(domid), 0, 
> &deathw)
> +     if ret != 0 {
> +             return Error(ret)
> +     }
> +
> +     // Spawn a goroutine that is responsible for cleaning up when the
> +     // passed context.Context's Done channel is closed.
> +     go func() {
> +             <-c.Done()
> +
> +             ctx.logd("cleaning up domain death event handler for domain 
> %d", domid)
> +
> +             // Disable the event generation.
> +             C.libxl_evdisable_domain_death(ctx.ctx, deathw)
> +
> +             // Make sure any events that were generated get cleaned up so 
> they
> +             // do not linger in the libxl event queue.
> +             var evc *C.libxl_event
> +             for {
> +                     ret := C.libxl_event_check(ctx.ctx, &evc, 
> C.LIBXL_EVENTMASK_ALL, nil, nil)
> +                     if ret != 0 {
> +                             return
> +                     }
> +                     C.libxl_event_free(ctx.ctx, evc)

I have to admit, I don’t really understand how the libxl event stuff is 
supposed to work.  But it looks like this will drain all events of any type, 
for any domain, associated with this context?

So if you had two domains, and called NotifyDomainDeath() on both with 
different contexts, and you closed the one context, you might miss events from 
the other context?

Or, suppose you did this:
 * ctx.NotifyDomainDeath(ctx1, dom1, ec1)
 * ctx.NotifyDiskEject(ctx2, dom1, ec2)
 * ctx1CancelFunc()

Wouldn’t there be a risk that the disk eject message would get lost?

Ian, any suggestions for the right way to use these functions in this scenario?

 -George


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.