All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Fehlig <jfehlig@novell.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: LibVir <libvir-list@redhat.com>,
	xen-devel <xen-devel@lists.xensource.com>,
	Markus Gross <gross@univention.de>
Subject: Re: [PATCH] libxenlight driver
Date: Tue, 22 Feb 2011 20:46:35 -0700	[thread overview]
Message-ID: <4D64831B.2030908@novell.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1102181059380.2826@kaball-desktop>

Stefano Stabellini wrote:
> On Fri, 18 Feb 2011, Jim Fehlig wrote:
>   
>> +static int
>> +libxlMakeDiskList(virDomainDefPtr def, libxl_domain_config *d_config)
>> +{
>> +    virDomainDiskDefPtr *l_disks = def->disks;
>> +    int ndisks = def->ndisks;
>> +    libxl_device_disk *x_disks;
>> +    int i;
>> +
>> +    if (VIR_ALLOC_N(x_disks, ndisks) < 0) {
>> +        virReportOOMError();
>> +        return -1;
>> +    }
>> +
>> +    for (i = 0; i < ndisks; i++) {
>> +        if (l_disks[i]->src &&
>> +             (x_disks[i].physpath = strdup(l_disks[i]->src)) == NULL) {
>> +            virReportOOMError();
>> +            goto error;
>> +        }
>> +
>> +        if (l_disks[i]->dst &&
>> +            (x_disks[i].virtpath = strdup(l_disks[i]->dst)) == NULL) {
>> +            virReportOOMError();
>> +            goto error;
>> +        }
>> +
>> +        if (l_disks[i]->driverName) {
>> +            if (STREQ(l_disks[i]->driverName, "tap") ||
>> +                STREQ(l_disks[i]->driverName, "tap2")) {
>> +                if (l_disks[i]->driverType &&
>> +                    STREQ(l_disks[i]->driverType, "qcow2"))
>> +                    x_disks[i].phystype = PHYSTYPE_QCOW2;
>> +                else if (l_disks[i]->driverType &&
>> +                         STREQ(l_disks[i]->driverType, "aio"))
>> +                    x_disks[i].phystype = PHYSTYPE_AIO;
>> +                else if (l_disks[i]->driverType &&
>> +                         STREQ(l_disks[i]->driverType, "vhd"))
>> +                    x_disks[i].phystype = PHYSTYPE_VHD;
>> +            } else if (STREQ(l_disks[i]->driverName, "file")) {
>> +                x_disks[i].phystype = PHYSTYPE_FILE;
>> +            } else if (STREQ(l_disks[i]->driverName, "phy")) {
>> +                x_disks[i].phystype = PHYSTYPE_PHY;
>> +            }
>> +        } else {
>> +            /* Default to file?? */
>> +            x_disks[i].phystype = PHYSTYPE_FILE;
>> +        }
>>     
>
> few days ago the patch that removes phystype and introduces backend and
> format has been applied, so this code needs an update
>   

Thanks for the review and comments.  I've posted a new version based on
xen-unstable c/s 22940.

>> +static void libxlEventHandler(int watch,
>> +                              int fd,
>> +                              int events,
>> +                              void *data)
>> +{
>> +    libxlDriverPrivatePtr driver = libxl_driver;
>> +    virDomainObjPtr vm = data;
>> +    libxlDomainObjPrivatePtr priv;
>> +    libxl_event event;
>> +    libxl_dominfo info;
>> +
>> +    libxlDriverLock(driver);
>> +    virDomainObjLock(vm);
>> +    libxlDriverUnlock(driver);
>> +
>> +    priv = vm->privateData;
>> +
>> +    memset(&event, 0, sizeof(event));
>> +    memset(&info, 0, sizeof(info));
>> +
>> +    if (priv->waiterFD != fd || priv->eventHdl != watch) {
>> +        virEventRemoveHandle(watch);
>> +        goto cleanup;
>> +    }
>> +
>> +    if (!(events & VIR_EVENT_HANDLE_READABLE)) {
>> +        goto cleanup;
>> +    }
>> +
>> +    if (libxl_get_event(&priv->ctx, &event)) {
>> +        goto cleanup;
>> +    }
>> +
>> +    if (event.type == LIBXL_EVENT_DOMAIN_DEATH) {
>> +        /* libxl_event_get_domain_death_info returns 1 if death
>> +         * event was for this domid */
>> +        if (libxl_event_get_domain_death_info(&priv->ctx,
>> +                                              vm->def->id,
>> +                                              &event,
>> +                                              &info) != 1) {
>> +            goto cleanup;
>> +        }
>> +
>> +        virEventRemoveHandle(watch);
>> +        if (info.shutdown_reason == SHUTDOWN_poweroff) {
>> +            libxl_domain_destroy(&priv->ctx, vm->def->id, 0);
>> +            if (vm->persistent) {
>> +                vm->def->id = -1;
>> +                vm->state = VIR_DOMAIN_SHUTOFF;
>> +            } else {
>> +                libxl_free_waiter(priv->dWaiter);
>> +                VIR_FREE(priv->dWaiter);
>> +                virDomainRemoveInactive(&driver->domains, vm);
>> +                vm = NULL;
>> +            }
>> +        } else if (info.shutdown_reason == SHUTDOWN_reboot) {
>> +            libxl_domain_destroy(&priv->ctx, vm->def->id, 0);
>> +            vm->def->id = -1;
>> +            vm->state = VIR_DOMAIN_SHUTOFF;
>> +            sleep(1);
>> +            libxlVmStart(vm, 0);
>>     
>
> we need to handle at least SHUTDOWN_suspend and SHUTDOWN_crash too
>   

The updated patch handles SHUTDOWN_crash similar to SHUTDOWN_poweroff. 
I've ignored SHUTDOWN_suspend since the driver does not yet implement
domainSave function.  Also notice I've ignored any user-specified
actions on these events, e.g. coredump and restart.  But IMO, these type
of improvements can be added incrementally.  I'd like to get a basic
driver upstream so others can easily contribute.

>   
>> +        } else {
>> +            VIR_INFO("Unhandled shutdown_reason %d", info.shutdown_reason);
>> +        }
>> +    }
>>     
>
> we should call libxl_free_event before returning, otherwise we leak two
> strings
>   

Fixed in updated patch.

[...]

>> +
>> +    libxl_driver->caps->privateDataAllocFunc = libxlDomainObjPrivateAlloc;
>> +    libxl_driver->caps->privateDataFreeFunc = libxlDomainObjPrivateFree;
>>     
>
> If I understand correctly privateDataAllocFunc is called at each domain creation
>   

It is called when a domain is introduced to libvirt, either by defining
a persistent domain (e.g. virsh define dom.xml) or creating a transient
domain (e.g. virsh create dom.xml).  The free func is called when a
domain is removed from libvirt, either by undefining a persistent domain
(e.g. virsh undefine dom-name) or poweroff of a transient domain. 
Starting/stopping a persistent domain does not invoke these functions.

Regards,
Jim

  reply	other threads:[~2011-02-23  3:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-18  1:28 [PATCH] libxenlight driver Jim Fehlig
2011-02-18 11:15 ` Stefano Stabellini
2011-02-23  3:46   ` Jim Fehlig [this message]
2011-02-21 17:15 ` [libvirt] " Daniel P. Berrange
  -- strict thread matches above, loose matches on Subject: below --
2011-02-14  2:01 Jim Fehlig
2011-02-14 12:15 ` Stefano Stabellini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4D64831B.2030908@novell.com \
    --to=jfehlig@novell.com \
    --cc=gross@univention.de \
    --cc=libvir-list@redhat.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.