virDomainDimmFind - to find a dimm within VM def virDomainDimmInsert - wrapper for inserting a new dimm into VM def virDomainDimmRemove - wrapper for removing dimm from VM def Signed-off-by: Zhu Guihua <zhugh.fnst@xxxxxxxxxxxxxx> --- src/conf/domain_conf.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 13 +++++++++++ src/libvirt_private.syms | 3 +++ 3 files changed, 76 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d4da728..ff39b70 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11790,6 +11790,66 @@ virDomainHasDiskMirror(virDomainObjPtr vm) return false; } +int +virDomainDimmInsert(virDomainDefPtr vmdef, + virDomainDimmDefPtr dimm) +{ + return VIR_APPEND_ELEMENT(vmdef->dimms, vmdef->ndimms, dimm); +} + +bool +virDomainDimmEquals(virDomainDimmDefPtr src, + virDomainDimmDefPtr tgt) +{ + bool ret = false; + + if (!src || !tgt) + return src == tgt; + + if (src->slot == tgt->slot) + ret = true; + + return ret; +} + +virDomainDimmDefPtr +virDomainDimmFind(virDomainDefPtr def, + virDomainDimmDefPtr target) +{ + virDomainDimmDefPtr dimm; + size_t i; + + for (i = 0; i < def->ndimms; i++) { + dimm = def->dimms[i]; + + if (virDomainDimmEquals(dimm, target)) + return dimm; + } + + return NULL; +} + +virDomainDimmDefPtr +virDomainDimmRemove(virDomainDefPtr vmdef, + virDomainDimmDefPtr dimm) +{ + virDomainDimmDefPtr ret; + size_t i; + + for (i = 0; i < vmdef->ndimms; i++) { + ret = vmdef->dimms[i]; + + if (virDomainDimmEquals(ret, dimm)) + break; + } + + if (i == vmdef->ndimms) + return NULL; + + VIR_DELETE_ELEMENT(vmdef->dimms, i, vmdef->ndimms); + return ret; +} + int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net) { /* hostdev net devices must also exist in the hostdevs array */ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4864dc3..b46b28a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2602,6 +2602,19 @@ int virDomainDiskSourceParse(xmlNodePtr node, bool virDomainHasDiskMirror(virDomainObjPtr vm); +int +virDomainDimmInsert(virDomainDefPtr vmdef, + virDomainDimmDefPtr dimm); +bool +virDomainDimmEquals(virDomainDimmDefPtr src, + virDomainDimmDefPtr tgt); +virDomainDimmDefPtr +virDomainDimmFind(virDomainDefPtr def, + virDomainDimmDefPtr dimm); +virDomainDimmDefPtr +virDomainDimmRemove(virDomainDefPtr def, + virDomainDimmDefPtr dimm); + int virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net); virDomainNetDefPtr virDomainNetFind(virDomainDefPtr def, const char *device); int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c5daf5b..092c1c6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -217,6 +217,9 @@ virDomainDeviceInfoCopy; virDomainDeviceInfoIterate; virDomainDeviceTypeToString; virDomainDimmDefFree; +virDomainDimmFind; +virDomainDimmInsert; +virDomainDimmRemove; virDomainDiskBusTypeToString; virDomainDiskCacheTypeFromString; virDomainDiskCacheTypeToString; -- 1.9.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list