From: Roger Pau Monne <roger.pau@citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH v10 07/19] libxl: convert libxl__device_disk_local_attach to an async op
Date: Mon, 23 Jul 2012 12:32:50 +0100 [thread overview]
Message-ID: <500D3662.2000807@citrix.com> (raw)
In-Reply-To: <20489.40301.406175.139605@mariner.uk.xensource.com>
Ian Jackson wrote:
> Roger Pau Monne writes ("[PATCH v10 07/19] libxl: convert libxl__device_disk_local_attach to an async op"):
>> This will be needed in future patches, when libxl__device_disk_add
>> becomes async also. Create a new status structure that defines the
>> local attach of a disk device and use it in
>> libxl__device_disk_local_attach.
>>
>> This is done in this patch to split the changes introduced when
>> libxl__device_disk_add becomes async.
>
> Thanks for this. See my other comment earlier today about the error
> handling. The rest of my comments are below. Very nearly there I
> think.
>
> Thanks,
> Ian.
>
>> @@ -2234,39 +2237,102 @@ char * libxl__device_disk_local_attach(libxl__gc *gc,
>> goto out;
>> }
>> if (dev != NULL)
>> - ret = strdup(dev);
>> - return ret;
>> + dls->diskpath = strdup(dev);
>
> libxl__strdup, surely. And I'm not sure I understand why this string
> can't be from the gc. In any case the memory allocation strategy
> should be documented in the struct. Eg:
>
>> +struct libxl__disk_local_state {
> ...
>> + /* filled by libxl__device_disk_local_initiate_attach */
>> + char *diskpath;
>
> + char *diskpath; /* from the gc */
> or
> + char *diskpath; /* non-0 whenever Attached, disposed by detach */
> or something.
I've changed diskpath to be allocated from the gc.
>> +void libxl__device_disk_local_initiate_detach(libxl__egc *egc,
>> + libxl__disk_local_state *dls)
>> {
> ...
>> +out:
>> + if (dls->diskpath) {
>> + free(dls->diskpath);
>> + dls->diskpath = 0;
>> + }
>> + /*
>> + * If there was an error in dls->rc, it means we have been called from
>> + * a failed execution of libxl__device_disk_local_initiate_attach,
>> + * so return the original error.
>> + */
>> + rc = dls->rc ? dls->rc : rc;
>> + dls->callback(egc, dls, rc);
>> + return;
>
> This seems to occur twice. Once here and once in
> local_device_detach_cb. Clearly they should be unified, probably by
> dismembering local_device_detach_cb:
I'm calling local_device_detach_cb instead of the callback directly.
> ...
>> +static void local_device_detach_cb(libxl__egc *egc, libxl__ao_device *aodev)
>> +{
>> + STATE_AO_GC(aodev->ao);
>> + libxl__disk_local_state *dls = CONTAINER_OF(aodev, *dls, aodev);
>> + int rc;
>> +
>> + if (dls->diskpath) {
>> + free(dls->diskpath);
>> + dls->diskpath = 0;
>> + }
>> +
>> + if (aodev->rc) {
> ...
>> + }
>> +
>> +out:
>> + /*
>> + * If there was an error in dls->rc, it means we have been called from
>> + * a failed execution of libxl__device_disk_local_initiate_attach,
>> + * so return the original error.
>> + */
>> + rc = dls->rc ? dls->rc : aodev->rc;
>> + dls->callback(egc, dls, rc);
>> + return;
>
>
>> diff --git a/tools/libxl/libxl_bootloader.c b/tools/libxl/libxl_bootloader.c
>> index 7ebc0df..4bcca3d 100644
>> --- a/tools/libxl/libxl_bootloader.c
>> +++ b/tools/libxl/libxl_bootloader.c
>> @@ -249,10 +245,32 @@ static void bootloader_setpaths(libxl__gc *gc, libxl__bootloader_state *bl)
> ...
>> +/* Callbacks */
>> +
>> +static void bootloader_finished_cb(libxl__egc *egc,
>> + libxl__disk_local_state *dls,
>> + int rc);
>
> Wouldn't this be better named
> bootloader_local_detached_cb
> or something ? Because the function called when the bootloader
> finishes is bootloader_callback.
Yes, changed to bootloader_local_detached_cb.
>> static void bootloader_callback(libxl__egc *egc, libxl__bootloader_state *bl,
>> int rc)
>> {
>> bootloader_cleanup(egc, bl);
>> +
>> + bl->dls.callback = bootloader_finished_cb;
>> + libxl__device_disk_local_initiate_detach(egc, &bl->dls);
>> +}
>
>> diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
>> index 4f3a232..ab590be 100644
> ...
>> +/*
>> + * Clears the internal error code, can be called multiple times, and
>> + * must be called before libxl__device_disk_local_initiate_attach.
>> + */
>> +static inline void libxl__device_disk_local_init(libxl__disk_local_state *dls)
>
> "Clears the internal error code" should not be in interface
> documentation, since it refers to an implementation detail.
>
> Perhaps you mean "Prepares a dls for use". You should explicitly
> state which of the documented states it transitions between. I guess
> "Undefined -> Idle" ?
Changed the comment, and added the state transition.
>> +/* Make a disk available in this (the control) domain. Always calls
>> + * dls->callback when finished.
>> + * State Idle -> Attaching
>> + *
>> + * The state on which the device is when in the callback depends
>> + * on the passed value of rc:
>> + * Attached if rc == 0
>> + * Idle if rc != 0
>
> A nit: this would be slightly easier to read if there the two
> subordinate options were indented.
>
> Also correct English would be "the state in which the device is" but
> really you mean the state of the dls, not of the device. I would
> write:
> + * The state of dls on entry to the callback depends on the value
> + * of rc passed to the callback:
> + * rc == 0: Attached if rc == 0
> + * rc != 0: Idle
>
>> +_hidden void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
>> + libxl__disk_local_state *dls);
>> +
>> +/* Disconnects a disk device form the control domain. If the passed
>> + * dls is not attached (or has already been detached),
>> + * libxl__device_disk_local_initiate_detach will just call the callback
>> + * directly.
>> + * State Idle/Attached -> Detaching
>> + *
>> + * The state on which the device is when in the callback is Idle.
>
> Again, "in which", "dls" or reword as above.
I've addressed both comments.
>> @@ -2097,10 +2142,10 @@ struct libxl__bootloader_state {
>> /* Should be zeroed by caller on entry. Will be filled in by
>> * bootloader machinery; represents the local attachment of the
>> * disk for the benefit of the bootloader. Must be detached by
>> - * the caller using libxl__device_disk_local_detach, but only
>> + * the caller using libxl__device_disk_local_initiate_detach, but only
>> * after the domain's kernel and initramfs have been loaded into
>> * memory and the file references disposed of. */
>
> Is this last comment, which I wrote, wrong ? That is, as previously
> discussed, is it legal to detach the disk before the kernel and
> initramfs have been loaded into the domain's memory ?
>
> I think it probably is. If so perhaps I should write a separate
> patch to fix it.
I didn't change this comment, but if you want I can do that in this
patch. The bootloader makes a copy of the kernel/initramfs to somewhere,
and that is what we load to the memory.
next prev parent reply other threads:[~2012-07-23 11:32 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-20 14:12 [PATCH v10 01/19] execute hotplug scripts from libxl v10 Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 01/19] libxl: check backend state before setting it to "closing" Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 02/19] libxl: change ao_device_remove to ao_device Roger Pau Monne
2012-07-20 16:35 ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 03/19] libxl: move device model creation prototypes Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 04/19] libxl: convert libxl_domain_destroy to an async op Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 05/19] libxl: move bootloader data strucutres and prototypes Roger Pau Monne
2012-07-20 17:21 ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 06/19] libxl: refactor disk addition to take a helper Roger Pau Monne
2012-07-20 17:24 ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 07/19] libxl: convert libxl__device_disk_local_attach to an async op Roger Pau Monne
2012-07-20 18:03 ` Ian Jackson
2012-07-23 11:32 ` Roger Pau Monne [this message]
2012-07-20 14:12 ` [PATCH v10 08/19] libxl: rename vifs to nics Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 09/19] libxl: convert libxl_device_disk_add to an async op Roger Pau Monne
2012-07-20 18:04 ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 10/19] libxl: convert libxl_device_nic_add to an async operation Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 11/19] libxl: add option to choose who executes hotplug scripts Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 12/19] libxl: rename _IOEMU nic type to VIF_IOEMU Roger Pau Monne
2012-07-20 16:34 ` Ian Campbell
2012-07-20 16:39 ` Ian Campbell
2012-07-20 14:12 ` [PATCH v10 13/19] libxl: set correct nic type depending on the guest Roger Pau Monne
2012-07-20 18:06 ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 14/19] libxl: use libxl__xs_path_cleanup on device_destroy Roger Pau Monne
2012-07-20 15:38 ` Ian Campbell
2012-07-20 14:12 ` [PATCH v10 15/19] libxl: call hotplug scripts for disk devices from libxl Roger Pau Monne
2012-07-20 15:20 ` Ian Campbell
2012-07-20 14:12 ` [PATCH v10 16/19] libxl: call hotplug scripts for nic " Roger Pau Monne
2012-07-20 16:01 ` Ian Campbell
2012-07-20 16:12 ` Ian Campbell
2012-07-20 16:36 ` Ian Campbell
2012-07-23 9:22 ` Roger Pau Monne
2012-07-20 16:03 ` Ian Campbell
2012-07-20 14:12 ` [PATCH v10 17/19] libxl: convert libxl_device_vkb_add to an async operation Roger Pau Monne
2012-07-20 18:08 ` Ian Jackson
2012-07-23 8:58 ` Roger Pau Monne
2012-07-23 9:26 ` Ian Campbell
2012-07-23 11:44 ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 18/19] libxl: convert libxl_device_vfb_add " Roger Pau Monne
2012-07-20 18:11 ` Ian Jackson
2012-07-23 11:58 ` Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 19/19] xl: main_blockdetach don't call destroy if remove succeeds Roger Pau Monne
2012-07-20 14:55 ` Ian Campbell
2012-07-23 12:17 ` [PATCH v10 01/19] execute hotplug scripts from libxl v10 Ian Campbell
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=500D3662.2000807@citrix.com \
--to=roger.pau@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=Stefano.Stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
/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.