All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dario Faggioli <raistlin@linux.it>
To: Ian Campbell <Ian.Campbell@citrix.com>
Cc: Christoph Egger <Christoph.Egger@amd.com>,
	Roger Pau Monne <roger.pau@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH v4] libxl: introduce LIBXL_DOMAIN_TYPE_INVALID
Date: Fri, 25 May 2012 12:26:40 +0200	[thread overview]
Message-ID: <1337941600.5761.19.camel@Solace> (raw)
In-Reply-To: <1337939090.22311.22.camel@zakaz.uk.xensource.com>


[-- Attachment #1.1: Type: text/plain, Size: 4336 bytes --]

On Fri, 2012-05-25 at 10:44 +0100, Ian Campbell wrote:
> > diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
> > --- a/tools/libxl/libxl_dm.c
> > +++ b/tools/libxl/libxl_dm.c
> > @@ -257,6 +257,10 @@ static char ** libxl__build_device_model
> >          for (i = 0; b_info->extra_hvm && b_info->extra_hvm[i] != NULL; i++)
> >              flexarray_append(dm_args, b_info->extra_hvm[i]);
> >          break;
> > +    case LIBXL_DOMAIN_TYPE_INVALID:
> > +        LIBXL__LOG(CTX, LIBXL__LOG_ERROR, "invalid domain type");
> > +        flexarray_free(dm_args);
> > +        return NULL;
> 
> In some cases, like here, the code is entitled to assume that type is
> either PV or HVM, due to the checks in
> libxl__domain_build_info_setdefault. I think if we see an invalid here
> then that is an abort() worthy event.
> 
As you wish, although it seems to me that this case above is the only
possible situation where we are returning NULL from that function.
Nevertheless, a NULL return value is handled and considered (and
propagated) as error by the caller. That's why, when Roger suggested
going this way (i.e., retuning NULL), I liked the idea very much and
went for it.

That being said, I'm very very very few confident with these code paths,
so I'm just thought it might worth pointing the above out, but I'll
definitely cope with your request if you really thing this is they
correct thing o do.

> There are a bunch of places where we look a b_info->type with if
> statements instead of switch. Plain ifs are ok, but it might be worth
> checking the ones with an else clause (not else if) too? I suspect in
> many cases they are entitled that !HVM == PV due to the setdefault
> thing.
> 

Right, and many of them I can take care of. Perhaps the problem is there
are some places where the event of libxl__domain_type "failing" (i.e.,
returning something different from HVM or PV) is somewhat considered
impossible, or at least neglected, like this one here:

int libxl_domain_suspend(libxl_ctx *ctx, libxl_domain_suspend_info *info,
                         uint32_t domid, int fd)
{
    GC_INIT(ctx);
    libxl_domain_type type = libxl__domain_type(gc, domid);
    int live = info != NULL && info->flags & XL_SUSPEND_LIVE;
    int debug = info != NULL && info->flags & XL_SUSPEND_DEBUG;
    int rc = 0;

    rc = libxl__domain_suspend_common(gc, domid, fd, type, live, debug,
                                      /* No Remus */ NULL);

    if (!rc && type == LIBXL_DOMAIN_TYPE_HVM)
        rc = libxl__domain_save_device_model(gc, domid, fd);
    GC_FREE;
    return rc;
}


Of course that can be right because of your argument about _sefdefault,
but I'm not sure how to make sure of that and what to do about them...
Thoughts?


On a related note, re what we where discussing yesterday on IRC about
putting a 'default' clause on those switches, there already is some
heterogeneity here. For example:


int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid)
{
    ...
    switch (libxl__domain_type(gc, domid)) {
    case LIBXL_DOMAIN_TYPE_HVM:
        ...
        break;
    case LIBXL_DOMAIN_TYPE_PV:
        ...
        break;
    default:
        abort();
    }
    ...
}

or:

int libxl_primary_console_exec(libxl_ctx *ctx, uint32_t domid_vm)
{
    ...
    else {
        switch (libxl__domain_type(gc, domid_vm)) {
        case LIBXL_DOMAIN_TYPE_HVM:
            ...
            break;
        case LIBXL_DOMAIN_TYPE_PV:
            ...
            break;
        case LIBXL_DOMAIN_TYPE_INVALID:
            ...
            break;
        default:
            abort();
        }
    ...
}

Should we leave it like this? Is it worth/reasonable to convert all the
'default:' into 'case LIBXL_DOMAIN_TYPE_INVALID:' (if yes, what do we do
with the places that have both? :O) ? Or perhaps vice versa?

If we can gather consensus on an alternative, I can go ahead and put it
down all over the places...

Thanks and Regards,
Dario

-- 
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://retis.sssup.it/people/faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)


[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2012-05-25 10:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-24 15:37 [PATCH v4] libxl: introduce LIBXL_DOMAIN_TYPE_INVALID Dario Faggioli
2012-05-25  9:44 ` Ian Campbell
2012-05-25 10:26   ` Dario Faggioli [this message]
2012-05-25 10:36     ` Ian Campbell
2012-05-25 11:03       ` Ian Jackson
2012-05-25 13:10         ` Dario Faggioli
2012-05-25 14:00           ` Ian Campbell
2012-06-04 13:11             ` Christoph Egger
2012-06-04 14:03               ` Dario Faggioli

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=1337941600.5761.19.camel@Solace \
    --to=raistlin@linux.it \
    --cc=Christoph.Egger@amd.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=roger.pau@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.