Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx> --- Notes: Version 2: - new patch src/conf/domain_conf.c | 14 +++++++++----- src/conf/domain_conf.h | 6 +++++- src/parallels/parallels_sdk.c | 4 ++-- src/qemu/qemu_command.c | 4 ++-- src/vbox/vbox_common.c | 4 ++-- src/vbox/vbox_tmpl.c | 6 +++--- src/vmx/vmx.c | 2 +- src/xenconfig/xen_sxpr.c | 6 +++--- src/xenconfig/xen_xl.c | 2 +- src/xenconfig/xen_xm.c | 4 ++-- 10 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index add857c..d3a9093 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1275,7 +1275,7 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def) virDomainDiskDefPtr -virDomainDiskDefNew(void) +virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt) { virDomainDiskDefPtr ret; @@ -1285,6 +1285,11 @@ virDomainDiskDefNew(void) if (VIR_ALLOC(ret->src) < 0) goto error; + if (xmlopt && + xmlopt->privateData.diskNew && + !(ret->privateData = xmlopt->privateData.diskNew())) + goto error; + if (virCondInit(&ret->blockJobSyncCond) < 0) { virReportSystemError(errno, "%s", _("Failed to initialize condition")); goto error; @@ -1293,9 +1298,7 @@ virDomainDiskDefNew(void) return ret; error: - virStorageSourceFree(ret->src); - VIR_FREE(ret); - + virDomainDiskDefFree(ret); return NULL; } @@ -1315,6 +1318,7 @@ virDomainDiskDefFree(virDomainDiskDefPtr def) VIR_FREE(def->product); VIR_FREE(def->domain_name); virDomainDeviceInfoClear(&def->info); + virObjectUnref(def->privateData); virCondDestroy(&def->blockJobSyncCond); VIR_FREE(def); @@ -6121,7 +6125,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, int auth_secret_usage = -1; int ret = 0; - if (!(def = virDomainDiskDefNew())) + if (!(def = virDomainDiskDefNew(xmlopt))) return NULL; def->geometry.cylinders = 0; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 2cd105a7..f57f3c9 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -683,6 +683,8 @@ typedef enum { struct _virDomainDiskDef { virStorageSourcePtr src; /* non-NULL. XXX Allow NULL for empty cdrom? */ + virObjectPtr privateData; + int device; /* enum virDomainDiskDevice */ int bus; /* enum virDomainDiskBus */ char *dst; @@ -2332,6 +2334,7 @@ typedef virDomainXMLOption *virDomainXMLOptionPtr; typedef void *(*virDomainXMLPrivateDataAllocFunc)(void); typedef void (*virDomainXMLPrivateDataFreeFunc)(void *); +typedef virObjectPtr (*virDomainXMLPrivateDataNewFunc)(void); typedef int (*virDomainXMLPrivateDataFormatFunc)(virBufferPtr, void *); typedef int (*virDomainXMLPrivateDataParseFunc)(xmlXPathContextPtr, void *); @@ -2368,6 +2371,7 @@ typedef virDomainXMLPrivateDataCallbacks *virDomainXMLPrivateDataCallbacksPtr; struct _virDomainXMLPrivateDataCallbacks { virDomainXMLPrivateDataAllocFunc alloc; virDomainXMLPrivateDataFreeFunc free; + virDomainXMLPrivateDataNewFunc diskNew; virDomainXMLPrivateDataFormatFunc format; virDomainXMLPrivateDataParseFunc parse; }; @@ -2420,7 +2424,7 @@ void virDomainPanicDefFree(virDomainPanicDefPtr panic); void virDomainResourceDefFree(virDomainResourceDefPtr resource); void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def); void virDomainInputDefFree(virDomainInputDefPtr def); -virDomainDiskDefPtr virDomainDiskDefNew(void); +virDomainDiskDefPtr virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt); void virDomainDiskDefFree(virDomainDiskDefPtr def); void virDomainLeaseDefFree(virDomainLeaseDefPtr def); int virDomainDiskGetType(virDomainDiskDefPtr def); diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c index ad744c9..08d4a48 100644 --- a/src/parallels/parallels_sdk.c +++ b/src/parallels/parallels_sdk.c @@ -626,7 +626,7 @@ prlsdkAddDomainHardDisksInfo(PRL_HANDLE sdkdom, virDomainDefPtr def) PrlHandle_Free(hdd); hdd = PRL_INVALID_HANDLE; } else { - if (!(disk = virDomainDiskDefNew())) + if (!(disk = virDomainDiskDefNew(NULL))) goto error; if (prlsdkGetDiskInfo(hdd, disk, false) < 0) @@ -666,7 +666,7 @@ prlsdkAddDomainOpticalDisksInfo(PRL_HANDLE sdkdom, virDomainDefPtr def) pret = PrlVmCfg_GetOpticalDisk(sdkdom, i, &cdrom); prlsdkCheckRetGoto(pret, error); - if (!(disk = virDomainDiskDefNew())) + if (!(disk = virDomainDiskDefNew(NULL))) goto error; if (prlsdkGetDiskInfo(cdrom, disk, true) < 0) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 5d0a167..2939f8d 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -12566,7 +12566,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, STRPREFIX(arg, "-fd") || STREQ(arg, "-cdrom")) { WANT_VALUE(); - if (!(disk = virDomainDiskDefNew())) + if (!(disk = virDomainDiskDefNew(xmlopt))) goto error; if (STRPREFIX(val, "/dev/")) { @@ -12868,7 +12868,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, goto error; } } else if (STRPREFIX(val, "disk:")) { - if (!(disk = virDomainDiskDefNew())) + if (!(disk = virDomainDiskDefNew(xmlopt))) goto error; if (VIR_STRDUP(disk->src->path, val + strlen("disk:")) < 0) goto error; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index e3a1739..ba0b039 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -3126,7 +3126,7 @@ vboxDumpIDEHDDsNew(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine) /* Allocate mem, if fails return error */ if (VIR_ALLOC_N(def->disks, def->ndisks) >= 0) { for (i = 0; i < def->ndisks; i++) { - virDomainDiskDefPtr disk = virDomainDiskDefNew(); + virDomainDiskDefPtr disk = virDomainDiskDefNew(NULL); if (!disk) { error = true; break; @@ -5850,7 +5850,7 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot, /* Allocate mem, if fails return error */ if (VIR_ALLOC_N(def->dom->disks, def->dom->ndisks) >= 0) { for (i = 0; i < def->dom->ndisks; i++) { - virDomainDiskDefPtr diskDef = virDomainDiskDefNew(); + virDomainDiskDefPtr diskDef = virDomainDiskDefNew(NULL); if (!diskDef) goto cleanup; def->dom->disks[i] = diskDef; diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 22eecd4..409ecef 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2187,7 +2187,7 @@ _dumpIDEHDDsOld(virDomainDefPtr def, if ((def->ndisks > 0) && (VIR_ALLOC_N(def->disks, def->ndisks) >= 0)) { size_t i; for (i = 0; i < def->ndisks; i++) { - if ((def->disks[i] = virDomainDiskDefNew())) { + if ((def->disks[i] = virDomainDiskDefNew(NULL))) { def->disks[i]->device = VIR_DOMAIN_DISK_DEVICE_DISK; def->disks[i]->bus = VIR_DOMAIN_DISK_BUS_IDE; virDomainDiskSetType(def->disks[i], @@ -2295,7 +2295,7 @@ _dumpDVD(virDomainDefPtr def, def->ndisks++; if (VIR_REALLOC_N(def->disks, def->ndisks) >= 0) { - if ((def->disks[def->ndisks - 1] = virDomainDiskDefNew())) { + if ((def->disks[def->ndisks - 1] = virDomainDiskDefNew(NULL))) { def->disks[def->ndisks - 1]->device = VIR_DOMAIN_DISK_DEVICE_CDROM; def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_IDE; virDomainDiskSetType(def->disks[def->ndisks - 1], @@ -2437,7 +2437,7 @@ _dumpFloppy(virDomainDefPtr def, def->ndisks++; if (VIR_REALLOC_N(def->disks, def->ndisks) >= 0) { - if ((def->disks[def->ndisks - 1] = virDomainDiskDefNew())) { + if ((def->disks[def->ndisks - 1] = virDomainDiskDefNew(NULL))) { def->disks[def->ndisks - 1]->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY; def->disks[def->ndisks - 1]->bus = VIR_DOMAIN_DISK_BUS_FDC; virDomainDiskSetType(def->disks[def->ndisks - 1], diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index cacc951..aede2ad 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1980,7 +1980,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con return -1; } - if (!(*def = virDomainDiskDefNew())) + if (!(*def = virDomainDiskDefNew(xmlopt))) return -1; (*def)->device = device; diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c index 5f58fd8..8985295 100644 --- a/src/xenconfig/xen_sxpr.c +++ b/src/xenconfig/xen_sxpr.c @@ -372,7 +372,7 @@ xenParseSxprDisks(virDomainDefPtr def, bootable = sexpr_node(node, "device/tap/bootable"); } - if (!(disk = virDomainDiskDefNew())) + if (!(disk = virDomainDiskDefNew(NULL))) goto error; if (dst == NULL) { @@ -1316,7 +1316,7 @@ xenParseSxpr(const struct sexpr *root, tmp = sexpr_node(root, "domain/image/hvm/cdrom"); if ((tmp != NULL) && (tmp[0] != 0)) { virDomainDiskDefPtr disk; - if (!(disk = virDomainDiskDefNew())) + if (!(disk = virDomainDiskDefNew(NULL))) goto error; if (virDomainDiskSetSource(disk, tmp) < 0) { virDomainDiskDefFree(disk); @@ -1351,7 +1351,7 @@ xenParseSxpr(const struct sexpr *root, tmp = sexpr_fmt_node(root, "domain/image/hvm/%s", fds[i]); if ((tmp != NULL) && (tmp[0] != 0)) { virDomainDiskDefPtr disk; - if (!(disk = virDomainDiskDefNew())) + if (!(disk = virDomainDiskDefNew(NULL))) goto error; if (virDomainDiskSetSource(disk, tmp) < 0) { virDomainDiskDefFree(disk); diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index db554b2..b12d306 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -286,7 +286,7 @@ xenParseXLDisk(virConfPtr conf, virDomainDefPtr def) if (xlu_disk_parse(xluconf, 1, &disk_spec, libxldisk)) goto fail; - if (!(disk = virDomainDiskDefNew())) + if (!(disk = virDomainDiskDefNew(NULL))) goto fail; if (VIR_STRDUP(disk->dst, libxldisk->vdev) < 0) diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c index fafe662..a4d1203 100644 --- a/src/xenconfig/xen_xm.c +++ b/src/xenconfig/xen_xm.c @@ -123,7 +123,7 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion) goto skipdisk; head = list->str; - if (!(disk = virDomainDiskDefNew())) + if (!(disk = virDomainDiskDefNew(NULL))) return -1; /* @@ -275,7 +275,7 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion) if (xenConfigGetString(conf, "cdrom", &str, NULL) < 0) goto cleanup; if (str) { - if (!(disk = virDomainDiskDefNew())) + if (!(disk = virDomainDiskDefNew(NULL))) goto cleanup; virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); -- 2.4.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list