On Fri, Oct 1, 2021 at 7:49 PM Daniel P. Berrangé <berrange(a)redhat.com> wrote:
> A GTree is used as a data structure in order to maintain key
ordering
> which will be important in XML to XML tests later.
Now, I've learnt a bit more about VPD and considering my comments on
the XML format in the last patch, I think this use of GTree is
unduly opaque and overkill
I think we should be representing the data we're extracting as
plan struct fields, in the same way that we handle SMBIOS in the
virsysinfo.h file....
....I feel like all of this can be reduced down to just a couple
of public structs and a single method:
typedef struct virPCIVPDResourceCustom virPCIVPDResourceCustom;
struct virPCIVPDResourceCustom {
char idx;
char *value;
};
typedef struct virPCIVPDResourceRO virPCIVPDResourceRO;
struct virPCIVPDResourceRO {
char *part_numer;
char *change_level;
char *fabric_geography;
char *location;
char *manufcatur_id;
char *pci_geography;
char *serial_number;
size_t nvendor_specific;
virPCIVPDResourceCustom *vendor_specific;
};
typedef struct virPCIVPDResourceRW virPCIVPDResourceRW;
struct virPCIVPDResourceRW {
char *asset_tag;
size_t nvendor_specific;
virPCIVPDResourceCustom *vendor_specific;
size_t nsystem_specific;
virPCIVPDResourceCustom *system_specific;
};
typedef struct virPCIVPDResource virPCIVPDResource;
struct virPCIVPDResource {
char *name;
virPCIVPDResourceRO *ro;
virPCIVPDResourceRW *rw;
}
virPCIVPDResource *virPCIVPDParse(int vpdFileFd);
void virPCIVPDResourceFree(virPCIVPDResource *res);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIVPDResource, virPCIVPDResourceFree);
Ack, I can rework it as you describe.
There will be a bit more work to do in XML serialization and
deserialization code to map struct fields to keyword names and vice
versa but I'll see what I can come up with.
My original goal with using Glib data structures was to use standard
iteration, insertion and lookup operations and also simplify automatic
cleanup implementation. On the other hand, there are some specifics of
working with them as my workaround for a bug with derived types shows.