[libvirt] [PATCH v2] host-validate: Improve CPU flags processing
Andrea Bolognani
abologna at redhat.com
Thu Apr 7 15:54:57 UTC 2016
On Tue, 2016-04-05 at 12:35 +0200, Ján Tomko wrote:
> > + /* Split the line using " " as a delimiter. The first token
> > + * will always be ":", but that's okay */
> > + if (!(tokens = virStringSplitCount(start, " ", 0, &ntokens)))
> > + continue;
> > +
> > + /* Go through all flags and check whether one of those we
> > + * might want to check for later on is present; if that's
> > + * the case, set the relevant bit in the bitmap */
> > + for (i = 0; i < ntokens; i++) {
> > + int value;
> > +
> > + if ((value = virHostValidateCPUFlagTypeFromString(tokens[i])) >= 0)
> > + ignore_value(virBitmapSetBit(flags, value));
> > }
> > +
> > + virStringFreeListCount(tokens, ntokens);
> > } while (1);
>
> We have already found the first 'flags' or 'Features' and parsed all the
> features. I doubt different processors on the system would have
> different features so I'd just use while (0) here.
Yeah, if different CPUs had different features we'd probably
be in for a word of pain anyway.
Turns out that gcc is smart enough to figure out that a
'do {} while (0);' loop is going to be executed only once,
and optimizes it accordingly.
Side effect: the 'continue' instructions behave the same as
the 'break' instructions, and everything stops working :(
I've pushed the patch as-is.
Cheers.
--
Andrea Bolognani
Software Engineer - Virtualization Team
More information about the libvir-list
mailing list