[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 19:31:46 +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=x0fOnCH0yAQs/bd9+Sl21d26qdj9CFx97Mu0niP1xfE=; b=TNzrltIqP0cZz3N4kFdcdhHyGUde4BDyxOi1yJjzgqC7PdT/UpL/l+Ki0NcaCM8ls2/w8WiDsPfRoGrDYaY2G0LU85IafRkbsgmkYxEXOP881dLb4quioBWRWsy1/J9SFg7lqjaWGM2jZMhQnD4QrIrP35rYG8aoIFdmv/TAYMQVl/1CGLh8emhjE+WQ8ILPhAWcGoUygR+scBm1p0yMrDGw+Saqygz06SAGAVf+nHKNet+Zo1Et4OtK25ECfzfU/SvrrDqB4Ojsg7RrdhUq7wpvD+flE64ylBNwPgSeAQd7edE+uW2hN3ANi4ZJizGRosz6LL62Iiz4o5QlGHacQQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z2mUstABdH14gWlOy93+fQBCkAGI8DJ89Uuaj62oYa/9O5JyTj76CkJOdGU5OZHEyrLCtMiunPcwGgp8U13L5DERc6RcgPsfExFFVeiNbLoMW/6x5zJgVkpWOFp95+Dvty0/WKYqpDMxHFgC80ZMP7yk8nKw8qjWstsbx34OF0jeDnhHTRTu2UXrBRbeJYlq1taX3xWW9AkewhPEQ4NEujmwMzXynUFg2zm72IGX5W93o1r3tgeoiRTRrm1yUwNR2nWaz003QwGXSIyUeMiy1m7oWaoFO75djgqMQKHoYZzKxUmT2G4s3bKuuQIMH6qh1lxKHWX96ihyTvj0u1IfTQ==
  • Authentication-results: esa5.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 19:32:08 +0000
  • Ironport-hdrordr: A9a23:LwXOJ6kahREvkQTYP44Hvne0i4HpDfNqiWdD5ihNYBxZY6Wkfp +V8sjzhCWatN9OYh0dcIi7SdW9qXO1z+8Q3WBjB8bcYOCGghrnEGgG1+GC/9SOIVyHygcw79 YDT0E6MqyMMbEYt7e63ODbKada/DDvysnB7oq/vhRQpENRGttdBmxCe2Gm+zhNNXB77O0CZf yhD6R81l+dUEVSSv7+KmgOXuDFqdGOvonhewQ6Cxku7xTLpS+06ZbheiLonSs2Yndq+/MP4G LFmwv26uGIqPeg0CLR0GfV8tB/hMbh8N1eH8aB4/JlaAkEyzzYIbiJaYfy+wzdk9vfrmrCV+ O8+ivICv4Dr085uFvF+ScFlTOQiwrGoEWSt2NwyUGT0PARAghKS/ZptMZhaR3e5FMnvNZglI x2/0/xjesMMTrw2B3n4d7GThdrkVfxh0EDv6o8s1xzOLFuNYN5nMgn50VSH44HHCXmrLocN4 BVfZ7hDNA/SyLHU5mRhBge/PW8Gns0BRuIWU4Ep4ic1CVXhmlwyw8CyNUYhWpozuN2d3Bo3Z WNDk1TrsAEcibWV9MLOM4RBc+sTmDdSxPFN2yfZVzhCaEcInrI75r6+q886u2mcIEBiMJaou WMbHpI8WopP07+A8yH25NGthjLXWWmRDzojsVT/YJwtLHwTKfidSeDVFctmc29pOh3OLyXZx 9yAuMePxbHFxqgJW9k5XyKZ3BiEwhpbCROgKdIZ7unmLO+FmTFjJ2pTMru
  • Ironport-sdr: 9dHkLl3LBTTtm8y7cZlnwtjI9Bcvr4oWJxUVGlkzUPbIsLQkpEKpMlUlDGUMOubkA/UmRT8J46 xU25OjhtklKp2rfu4KT5RCW9vT7SNwH66IacraQB6OgwLgZQ+GYD4oKaAf2RJVEZU7QSLBH/nQ IwV6Ae/B0CqJT8Bx3i49ZNSthblLFwaEiVu/G1ouV1H3tjEQ+iwRCUjFkcBoVE8AMAYRmQ6Dax HsdnLbGpH/rCHMUI9ehPBSqKTgJO/gH5V9Znn75tToEtczinz3bqbvDpQNZ4xX4LB4K6ZA3ioS zb8=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHXUNy1vChg4LMpNU6QjEPyRTou1KsaPdIAgAARmAA=
  • Thread-topic: [RESEND PATCH 12/12] golang/xenlight: add NotifyDomainDeath method to Context


> On Jun 18, 2021, at 7:28 PM, George Dunlap <george.dunlap@xxxxxxxxxx> wrote:
> 
> 
> 
>> 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?

It looks like one option would be to add a “predicate” function filter, to 
filter by type and domid.

It looks like the other option would be to try to use 
libxl_event_register_callbacks().  We could have the C callback pass all the 
events to a goroutine which would act as a dispatcher.

 -George

 


Rackspace

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