On Thu, Mar 31, 2016 at 05:26:10PM +0200, Andrea Bolognani wrote:
Instead of relying on substring search, tokenize the input
and process each CPU flag separately. This ensures CPU flag
detection will continue to work correctly even if we start
looking for CPU flags whose name might appear as part of
other CPU flags' names.
The result of processing is stored in a virBitmap, which
means we don't have to parse /proc/cpuinfo in its entirety
for each single CPU flag we want to check.
Moreover, use of the newly-introduced virHostValidateCPUFlag
enumeration ensures we don't go looking for random CPU flags
which might actually be simple typos.
You could still put the typo in the enum impelmentation :)
---
Changes in v2:
* use virStringSplitCount() and STRPREFIX() instead of
strtok_r() and strcmp(), as suggested by Peter
tools/virt-host-validate-common.c | 67 ++++++++++++++++++++++++++++++++-------
tools/virt-host-validate-common.h | 13 +++++++-
tools/virt-host-validate-qemu.c | 12 +++++--
3 files changed, 77 insertions(+), 15 deletions(-)
ACK
+ /* 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.
Jan