[libvirt] [RFC PATCH 0/5] another <disk> refactoring

I'm about to reuse the <mirror> sub-element of <disk> for my pending series on active block commit, but to do that, I wanted to get some refactoring out of the way first. Patches 1-4 are pretty straightforward, and 5 may be controversial (I'm sending it now, even though it still needs more work, to make sure I'm not doing something bad). I'm aware that this will probably cause some rebase pain for Peter's work with gluster, but at the same time, it will ease some of the work that Benoit wants for introducing quorums. Eric Blake (5): conf: store snapshot source as pointer, for easier manipulation conf: consolidate disk def allocation conf: store disk source as pointer, for easier manipulation conf: store mirroring information in virStorageSource conf: alter disk mirror xml output docs/schemas/domaincommon.rng | 29 +- src/conf/domain_conf.c | 254 ++++++++------ src/conf/domain_conf.h | 6 +- src/conf/snapshot_conf.c | 56 ++-- src/conf/snapshot_conf.h | 2 +- src/libvirt_private.syms | 1 + src/lxc/lxc_controller.c | 8 +- src/lxc/lxc_driver.c | 8 +- src/parallels/parallels_driver.c | 2 +- src/qemu/qemu_command.c | 290 ++++++++-------- src/qemu/qemu_conf.c | 88 ++--- src/qemu/qemu_domain.c | 18 +- src/qemu/qemu_driver.c | 372 +++++++++++---------- src/qemu/qemu_migration.c | 4 +- src/qemu/qemu_process.c | 8 +- src/security/security_selinux.c | 4 +- src/vbox/vbox_tmpl.c | 6 +- src/vmx/vmx.c | 2 +- src/xenxs/xen_sxpr.c | 8 +- src/xenxs/xen_xm.c | 4 +- .../qemuxml2argv-disk-mirror-old.xml | 47 +++ .../qemuxml2argvdata/qemuxml2argv-disk-mirror.xml | 9 +- .../qemuxml2xmlout-disk-mirror-old-inactive.xml | 41 +++ .../qemuxml2xmlout-disk-mirror-old.xml | 52 +++ tests/qemuxml2xmltest.c | 1 + tests/securityselinuxlabeltest.c | 6 +- 26 files changed, 778 insertions(+), 548 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-mirror-old.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old-inactive.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old.xml -- 1.9.0

As part of the work on backing chains, I'm finding that it would be easier to directly manipulate chains of pointers (adding a snapshot merely adjusts pointers to form the correct list) rather than copy data from one struct to another. This patch converts snapshot source to be a pointer. In this patch, the pointer is ALWAYS allocated (any code that increases ndisks now also allocates a source pointer for each new disk), and all other changes are just mechanical fallout of the new type; there should be no functional change. It is possible that we may want to leave the pointer NULL for internal snapshots in a later patch, but as that requires a closer audit of the source to ensure we don't fault on a null dereference, I didn't do it here. * src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Change type of src. * src/conf/snapshot_conf.c: Adjust all clients. * src/qemu/qemu_conf.c: Likewise. * src/qemu/qemu_driver.c: Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/snapshot_conf.c | 56 ++++++++++++++------------ src/conf/snapshot_conf.h | 2 +- src/qemu/qemu_conf.c | 2 +- src/qemu/qemu_driver.c | 100 +++++++++++++++++++++++------------------------ 4 files changed, 83 insertions(+), 77 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index b0e4700..441162c 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -83,7 +83,8 @@ static void virDomainSnapshotDiskDefClear(virDomainSnapshotDiskDefPtr disk) { VIR_FREE(disk->name); - virStorageSourceClear(&disk->src); + virStorageSourceFree(disk->src); + disk->src = NULL; } void virDomainSnapshotDefFree(virDomainSnapshotDefPtr def) @@ -113,6 +114,9 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, char *type = NULL; xmlNodePtr cur; + if (VIR_ALLOC(def->src) < 0) + goto cleanup; + def->name = virXMLPropString(node, "name"); if (!def->name) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -132,35 +136,35 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, } if ((type = virXMLPropString(node, "type"))) { - if ((def->src.type = virStorageTypeFromString(type)) <= 0 || - def->src.type == VIR_STORAGE_TYPE_VOLUME || - def->src.type == VIR_STORAGE_TYPE_DIR) { + if ((def->src->type = virStorageTypeFromString(type)) <= 0 || + def->src->type == VIR_STORAGE_TYPE_VOLUME || + def->src->type == VIR_STORAGE_TYPE_DIR) { virReportError(VIR_ERR_XML_ERROR, _("unknown disk snapshot type '%s'"), type); goto cleanup; } } else { - def->src.type = VIR_STORAGE_TYPE_FILE; + def->src->type = VIR_STORAGE_TYPE_FILE; } for (cur = node->children; cur; cur = cur->next) { if (cur->type != XML_ELEMENT_NODE) continue; - if (!def->src.path && + if (!def->src->path && xmlStrEqual(cur->name, BAD_CAST "source")) { - if (virDomainDiskSourceParse(cur, &def->src) < 0) + if (virDomainDiskSourceParse(cur, def->src) < 0) goto cleanup; - } else if (!def->src.format && + } else if (!def->src->format && xmlStrEqual(cur->name, BAD_CAST "driver")) { char *driver = virXMLPropString(cur, "type"); if (driver) { - def->src.format = virStorageFileFormatTypeFromString(driver); - if (def->src.format < VIR_STORAGE_FILE_BACKING) { + def->src->format = virStorageFileFormatTypeFromString(driver); + if (def->src->format < VIR_STORAGE_FILE_BACKING) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - def->src.format <= 0 + def->src->format <= 0 ? _("unknown disk snapshot driver '%s'") : _("disk format '%s' lacks backing file " "support"), @@ -173,7 +177,7 @@ virDomainSnapshotDiskDefParseXML(xmlNodePtr node, } } - if (!def->snapshot && (def->src.path || def->src.format)) + if (!def->snapshot && (def->src->path || def->src->format)) def->snapshot = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL; ret = 0; @@ -506,12 +510,12 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, disk->name, tmp); goto cleanup; } - if (disk->src.path && + if (disk->src->path && disk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("file '%s' for disk '%s' requires " "use of external snapshot mode"), - disk->src.path, disk->name); + disk->src->path, disk->name); goto cleanup; } if (STRNEQ(disk->name, def->dom->disks[idx]->dst)) { @@ -534,11 +538,13 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, if (inuse) continue; disk = &def->disks[ndisks++]; + if (VIR_ALLOC(disk->src) < 0) + goto cleanup; if (VIR_STRDUP(disk->name, def->dom->disks[i]->dst) < 0) goto cleanup; disk->index = i; disk->snapshot = def->dom->disks[i]->snapshot; - disk->src.type = VIR_STORAGE_TYPE_FILE; + disk->src->type = VIR_STORAGE_TYPE_FILE; if (!disk->snapshot) disk->snapshot = default_snapshot; } @@ -551,17 +557,17 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, virDomainSnapshotDiskDefPtr disk = &def->disks[i]; if (disk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL && - !disk->src.path) { + !disk->src->path) { const char *original = virDomainDiskGetSource(def->dom->disks[i]); const char *tmp; struct stat sb; - if (disk->src.type != VIR_STORAGE_TYPE_FILE) { + if (disk->src->type != VIR_STORAGE_TYPE_FILE) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("cannot generate external snapshot name " "for disk '%s' on a '%s' device"), disk->name, - virStorageTypeToString(disk->src.type)); + virStorageTypeToString(disk->src->type)); goto cleanup; } @@ -583,7 +589,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, tmp = strrchr(original, '.'); if (!tmp || strchr(tmp, '/')) { - if (virAsprintf(&disk->src.path, "%s.%s", original, + if (virAsprintf(&disk->src->path, "%s.%s", original, def->name) < 0) goto cleanup; } else { @@ -592,7 +598,7 @@ virDomainSnapshotAlignDisks(virDomainSnapshotDefPtr def, _("integer overflow")); goto cleanup; } - if (virAsprintf(&disk->src.path, "%.*s.%s", + if (virAsprintf(&disk->src->path, "%.*s.%s", (int) (tmp - original), original, def->name) < 0) goto cleanup; @@ -611,7 +617,7 @@ static void virDomainSnapshotDiskDefFormat(virBufferPtr buf, virDomainSnapshotDiskDefPtr disk) { - int type = disk->src.type; + int type = disk->src->type; if (!disk->name) return; @@ -621,7 +627,7 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " snapshot='%s'", virDomainSnapshotLocationTypeToString(disk->snapshot)); - if (!disk->src.path && disk->src.format == 0) { + if (!disk->src->path && disk->src->format == 0) { virBufferAddLit(buf, "/>\n"); return; } @@ -629,10 +635,10 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, virBufferAsprintf(buf, " type='%s'>\n", virStorageTypeToString(type)); virBufferAdjustIndent(buf, 2); - if (disk->src.format > 0) + if (disk->src->format > 0) virBufferEscapeString(buf, "<driver type='%s'/>\n", - virStorageFileFormatTypeToString(disk->src.format)); - virDomainDiskSourceFormat(buf, &disk->src, 0, 0); + virStorageFileFormatTypeToString(disk->src->format)); + virDomainDiskSourceFormat(buf, disk->src, 0, 0); virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</disk>\n"); diff --git a/src/conf/snapshot_conf.h b/src/conf/snapshot_conf.h index 1eb697f..21b5b62 100644 --- a/src/conf/snapshot_conf.h +++ b/src/conf/snapshot_conf.h @@ -52,7 +52,7 @@ struct _virDomainSnapshotDiskDef { int index; /* index within snapshot->dom->disks that matches name */ int snapshot; /* virDomainSnapshotLocation */ - virStorageSource src; /* new wrapper file when snapshot is external */ + virStorageSourcePtr src; /* new wrapper file when snapshot is external */ }; /* Stores the complete snapshot metadata */ diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index f273056..c14d700 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1427,7 +1427,7 @@ int qemuTranslateSnapshotDiskSourcePool(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainSnapshotDiskDefPtr def) { - if (def->src.type != VIR_STORAGE_TYPE_VOLUME) + if (def->src->type != VIR_STORAGE_TYPE_VOLUME) return 0; virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6fda50d..bf46d5d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -12190,14 +12190,14 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, if (snapdisk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) continue; - if (!snapdisk->src.format) - snapdisk->src.format = VIR_STORAGE_FILE_QCOW2; + if (!snapdisk->src->format) + snapdisk->src->format = VIR_STORAGE_FILE_QCOW2; /* creates cmd line args: qemu-img create -f qcow2 -o */ if (!(cmd = virCommandNewArgList(qemuImgPath, "create", "-f", - virStorageFileFormatTypeToString(snapdisk->src.format), + virStorageFileFormatTypeToString(snapdisk->src->format), "-o", NULL))) goto cleanup; @@ -12221,10 +12221,10 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, } /* adds cmd line args: /path/to/target/file */ - virCommandAddArg(cmd, snapdisk->src.path); + virCommandAddArg(cmd, snapdisk->src->path); /* If the target does not exist, we're going to create it possibly */ - if (!virFileExists(snapdisk->src.path)) + if (!virFileExists(snapdisk->src->path)) ignore_value(virBitmapSetBit(created, i)); if (virCommandRun(cmd, NULL) < 0) @@ -12241,11 +12241,11 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { VIR_FREE(defdisk->src.path); - if (VIR_STRDUP(defdisk->src.path, snapdisk->src.path) < 0) { + if (VIR_STRDUP(defdisk->src.path, snapdisk->src->path) < 0) { /* we cannot rollback here in a sane way */ goto cleanup; } - defdisk->src.format = snapdisk->src.format; + defdisk->src.format = snapdisk->src->format; } } @@ -12259,9 +12259,9 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, ssize_t bit = -1; while ((bit = virBitmapNextSetBit(created, bit)) >= 0) { snapdisk = &(snap->def->disks[bit]); - if (unlink(snapdisk->src.path) < 0) + if (unlink(snapdisk->src->path) < 0) VIR_WARN("Failed to remove snapshot image '%s'", - snapdisk->src.path); + snapdisk->src->path); } } virBitmapFree(created); @@ -12422,7 +12422,7 @@ qemuDomainSnapshotPrepareDiskExternalBackingActive(virDomainDiskDefPtr disk) static int qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr disk) { - int actualType = virStorageSourceGetActualType(&disk->src); + int actualType = virStorageSourceGetActualType(disk->src); switch ((virStorageType) actualType) { case VIR_STORAGE_TYPE_BLOCK: @@ -12430,7 +12430,7 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d return 0; case VIR_STORAGE_TYPE_NETWORK: - switch ((virStorageNetProtocol) disk->src.protocol) { + switch ((virStorageNetProtocol) disk->src->protocol) { case VIR_STORAGE_NET_PROTOCOL_GLUSTER: return 0; @@ -12447,7 +12447,7 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d virReportError(VIR_ERR_INTERNAL_ERROR, _("external active snapshots are not supported on " "'network' disks using '%s' protocol"), - virStorageNetProtocolTypeToString(disk->src.protocol)); + virStorageNetProtocolTypeToString(disk->src->protocol)); return -1; } @@ -12470,7 +12470,7 @@ qemuDomainSnapshotPrepareDiskExternalOverlayActive(virDomainSnapshotDiskDefPtr d static int qemuDomainSnapshotPrepareDiskExternalOverlayInactive(virDomainSnapshotDiskDefPtr disk) { - int actualType = virStorageSourceGetActualType(&disk->src); + int actualType = virStorageSourceGetActualType(disk->src); switch ((virStorageType) actualType) { case VIR_STORAGE_TYPE_BLOCK: @@ -12522,33 +12522,33 @@ qemuDomainSnapshotPrepareDiskExternal(virConnectPtr conn, return -1; } - if (virStorageFileInit(&snapdisk->src) < 0) + if (virStorageFileInit(snapdisk->src) < 0) return -1; - if (virStorageFileStat(&snapdisk->src, &st) < 0) { + if (virStorageFileStat(snapdisk->src, &st) < 0) { if (errno != ENOENT) { virReportSystemError(errno, _("unable to stat for disk %s: %s"), - snapdisk->name, snapdisk->src.path); + snapdisk->name, snapdisk->src->path); goto cleanup; } else if (reuse) { virReportSystemError(errno, _("missing existing file for disk %s: %s"), - snapdisk->name, snapdisk->src.path); + snapdisk->name, snapdisk->src->path); goto cleanup; } } else if (!S_ISBLK(st.st_mode) && st.st_size && !reuse) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("external snapshot file for disk %s already " "exists and is not a block device: %s"), - snapdisk->name, snapdisk->src.path); + snapdisk->name, snapdisk->src->path); goto cleanup; } ret = 0; cleanup: - virStorageFileDeinit(&snapdisk->src); + virStorageFileDeinit(snapdisk->src); return ret; } @@ -12670,15 +12670,15 @@ qemuDomainSnapshotPrepare(virConnectPtr conn, break; case VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL: - if (!disk->src.format) { - disk->src.format = VIR_STORAGE_FILE_QCOW2; - } else if (disk->src.format != VIR_STORAGE_FILE_QCOW2 && - disk->src.format != VIR_STORAGE_FILE_QED) { + if (!disk->src->format) { + disk->src->format = VIR_STORAGE_FILE_QCOW2; + } else if (disk->src->format != VIR_STORAGE_FILE_QCOW2 && + disk->src->format != VIR_STORAGE_FILE_QED) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("external snapshot format for disk %s " "is unsupported: %s"), disk->name, - virStorageFileFormatTypeToString(disk->src.format)); + virStorageFileFormatTypeToString(disk->src->format)); goto cleanup; } @@ -12777,7 +12777,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, char *newsource = NULL; virStorageNetHostDefPtr newhosts = NULL; virStorageNetHostDefPtr persistHosts = NULL; - int format = snap->src.format; + int format = snap->src->format; const char *formatStr = NULL; char *persistSource = NULL; int ret = -1; @@ -12793,27 +12793,27 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, if (virAsprintf(&device, "drive-%s", disk->info.alias) < 0) goto cleanup; - /* XXX Here, we know we are about to alter disk->src.backingStore if + /* XXX Here, we know we are about to alter disk->src->backingStore if * successful, so we nuke the existing chain so that future commands will * recompute it. Better would be storing the chain ourselves rather than * reprobing, but this requires modifying domain_conf and our XML to fully * track the chain across libvirtd restarts. */ virStorageSourceClearBackingStore(&disk->src); - if (virStorageFileInit(&snap->src) < 0) + if (virStorageFileInit(snap->src) < 0) goto cleanup; - if (qemuGetDriveSourceString(&snap->src, NULL, &source) < 0) + if (qemuGetDriveSourceString(snap->src, NULL, &source) < 0) goto cleanup; - if (VIR_STRDUP(newsource, snap->src.path) < 0) + if (VIR_STRDUP(newsource, snap->src->path) < 0) goto cleanup; if (persistDisk && - VIR_STRDUP(persistSource, snap->src.path) < 0) + VIR_STRDUP(persistSource, snap->src->path) < 0) goto cleanup; - switch ((virStorageType)snap->src.type) { + switch ((virStorageType)snap->src->type) { case VIR_STORAGE_TYPE_BLOCK: reuse = true; /* fallthrough */ @@ -12838,15 +12838,15 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, break; case VIR_STORAGE_TYPE_NETWORK: - switch (snap->src.protocol) { + switch (snap->src->protocol) { case VIR_STORAGE_NET_PROTOCOL_GLUSTER: - if (!(newhosts = virStorageNetHostDefCopy(snap->src.nhosts, - snap->src.hosts))) + if (!(newhosts = virStorageNetHostDefCopy(snap->src->nhosts, + snap->src->hosts))) goto cleanup; if (persistDisk && - !(persistHosts = virStorageNetHostDefCopy(snap->src.nhosts, - snap->src.hosts))) + !(persistHosts = virStorageNetHostDefCopy(snap->src->nhosts, + snap->src->hosts))) goto cleanup; break; @@ -12855,7 +12855,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("snapshots on volumes using '%s' protocol " "are not supported"), - virStorageNetProtocolTypeToString(snap->src.protocol)); + virStorageNetProtocolTypeToString(snap->src->protocol)); goto cleanup; } break; @@ -12866,13 +12866,13 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, case VIR_STORAGE_TYPE_LAST: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("snapshots are not supported on '%s' volumes"), - virStorageTypeToString(snap->src.type)); + virStorageTypeToString(snap->src->type)); goto cleanup; } /* create the actual snapshot */ - if (snap->src.format) - formatStr = virStorageFileFormatTypeToString(snap->src.format); + if (snap->src->format) + formatStr = virStorageFileFormatTypeToString(snap->src->format); /* The monitor is only accessed if qemu doesn't support transactions. * Otherwise the following monitor command only constructs the command. @@ -12904,9 +12904,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, disk->src.path = newsource; disk->src.format = format; - disk->src.type = snap->src.type; - disk->src.protocol = snap->src.protocol; - disk->src.nhosts = snap->src.nhosts; + disk->src.type = snap->src->type; + disk->src.protocol = snap->src->protocol; + disk->src.nhosts = snap->src->nhosts; disk->src.hosts = newhosts; newsource = NULL; @@ -12919,9 +12919,9 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, persistDisk->src.path = persistSource; persistDisk->src.format = format; - persistDisk->src.type = snap->src.type; - persistDisk->src.protocol = snap->src.protocol; - persistDisk->src.nhosts = snap->src.nhosts; + persistDisk->src.type = snap->src->type; + persistDisk->src.protocol = snap->src->protocol; + persistDisk->src.nhosts = snap->src->nhosts; persistDisk->src.hosts = persistHosts; persistSource = NULL; @@ -12929,15 +12929,15 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, } cleanup: - if (need_unlink && virStorageFileUnlink(&snap->src)) + if (need_unlink && virStorageFileUnlink(snap->src)) VIR_WARN("unable to unlink just-created %s", source); - virStorageFileDeinit(&snap->src); + virStorageFileDeinit(snap->src); VIR_FREE(device); VIR_FREE(source); VIR_FREE(newsource); VIR_FREE(persistSource); - virStorageNetHostDefFree(snap->src.nhosts, newhosts); - virStorageNetHostDefFree(snap->src.nhosts, persistHosts); + virStorageNetHostDefFree(snap->src->nhosts, newhosts); + virStorageNetHostDefFree(snap->src->nhosts, persistHosts); return ret; } -- 1.9.0

A future patch wants to create disk definitions with non-zero default contents; to avoid crashes, all callers that allocate a disk definition should go through a common point. I found allocation points by looking for any code that increments ndisks, as well as any matches for ALLOC.*disk. Most places that modified ndisks were covered by the parse from XML to domain/device definition by initial domain creation or device hotplug; I also hand-checked all drivers that generate a device struct on the fly during getXMLDesc. * src/conf/domain_conf.h (virDomainDiskDefNew): New prototype. * src/conf/domain_conf.c (virDomainDiskDefNew): New function. (virDomainDiskDefParseXML): Use it. * src/parallels/parallels_driver.c (parallelsAddHddInfo): Likewise. * src/qemu/qemu_command.c (qemuParseCommandLine): Likewise. * src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc): Likewise. * src/vmx/vmx.c (virVMXParseDisk): Likewise. * src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr): Likewise. * src/xenxs/xen_xm.c (xenParseXM): Likewise. * src/libvirt_private.syms (domain_conf.h): Export it. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 12 +++++++++++- src/conf/domain_conf.h | 1 + src/libvirt_private.syms | 1 + src/parallels/parallels_driver.c | 2 +- src/qemu/qemu_command.c | 4 ++-- src/vbox/vbox_tmpl.c | 6 +++--- src/vmx/vmx.c | 2 +- src/xenxs/xen_sxpr.c | 8 ++++---- src/xenxs/xen_xm.c | 4 ++-- 9 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 40c385e..97968b4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1181,6 +1181,16 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def) } +virDomainDiskDefPtr +virDomainDiskDefNew(void) +{ + virDomainDiskDefPtr ret; + + ignore_value(VIR_ALLOC(ret)); + return ret; +} + + void virDomainDiskDefFree(virDomainDiskDefPtr def) { @@ -5211,7 +5221,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, int expected_secret_usage = -1; int auth_secret_usage = -1; - if (VIR_ALLOC(def) < 0) + if (!(def = virDomainDiskDefNew())) return NULL; def->geometry.cylinders = 0; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index bde303c..4f4ce02 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2127,6 +2127,7 @@ void virDomainPanicDefFree(virDomainPanicDefPtr panic); void virDomainResourceDefFree(virDomainResourceDefPtr resource); void virDomainGraphicsDefFree(virDomainGraphicsDefPtr def); void virDomainInputDefFree(virDomainInputDefPtr def); +virDomainDiskDefPtr virDomainDiskDefNew(void); void virDomainDiskDefFree(virDomainDiskDefPtr def); void virDomainLeaseDefFree(virDomainLeaseDefPtr def); int virDomainDiskGetType(virDomainDiskDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c3332c9..009d286 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -207,6 +207,7 @@ virDomainDiskDefAssignAddress; virDomainDiskDefForeachPath; virDomainDiskDefFree; virDomainDiskDefGetSecurityLabelDef; +virDomainDiskDefNew; virDomainDiskDeviceTypeToString; virDomainDiskDiscardTypeToString; virDomainDiskErrorPolicyTypeFromString; diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index ab59599..a2665dd 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -381,7 +381,7 @@ parallelsAddHddInfo(virDomainDefPtr def, const char *key, virJSONValuePtr value) { virDomainDiskDefPtr disk = NULL; - if (VIR_ALLOC(disk) < 0) + if (!(disk = virDomainDiskDefNew())) goto error; if (parallelsGetHddInfo(def, disk, key, value)) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 193959f..f5b81c0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -10969,7 +10969,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, STRPREFIX(arg, "-fd") || STREQ(arg, "-cdrom")) { WANT_VALUE(); - if (VIR_ALLOC(disk) < 0) + if (!(disk = virDomainDiskDefNew())) goto error; if (STRPREFIX(val, "/dev/")) @@ -11268,7 +11268,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, goto error; } } else if (STRPREFIX(val, "disk:")) { - if (VIR_ALLOC(disk) < 0) + if (!(disk = virDomainDiskDefNew())) goto error; if (VIR_STRDUP(disk->src.path, val + strlen("disk:")) < 0) goto error; diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index e124e69..6fef074 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -2768,7 +2768,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { if ((def->ndisks > 0) && (VIR_ALLOC_N(def->disks, def->ndisks) >= 0)) { for (i = 0; i < def->ndisks; i++) { - if (VIR_ALLOC(def->disks[i]) >= 0) { + if ((def->disks[i] = virDomainDiskDefNew())) { def->disks[i]->device = VIR_DOMAIN_DISK_DEVICE_DISK; def->disks[i]->bus = VIR_DOMAIN_DISK_BUS_IDE; virDomainDiskSetType(def->disks[i], @@ -3247,7 +3247,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def->ndisks++; if (VIR_REALLOC_N(def->disks, def->ndisks) >= 0) { - if (VIR_ALLOC(def->disks[def->ndisks - 1]) >= 0) { + if ((def->disks[def->ndisks - 1] = virDomainDiskDefNew())) { 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], @@ -3294,7 +3294,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) { def->ndisks++; if (VIR_REALLOC_N(def->disks, def->ndisks) >= 0) { - if (VIR_ALLOC(def->disks[def->ndisks - 1]) >= 0) { + if ((def->disks[def->ndisks - 1] = virDomainDiskDefNew())) { 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 169440c..9b576f7 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1998,7 +1998,7 @@ virVMXParseDisk(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virConfPtr con return -1; } - if (VIR_ALLOC(*def) < 0) + if (!(*def = virDomainDiskDefNew())) return -1; (*def)->device = device; diff --git a/src/xenxs/xen_sxpr.c b/src/xenxs/xen_sxpr.c index 29316a4..aacf74c 100644 --- a/src/xenxs/xen_sxpr.c +++ b/src/xenxs/xen_sxpr.c @@ -370,7 +370,7 @@ xenParseSxprDisks(virDomainDefPtr def, bootable = sexpr_node(node, "device/tap/bootable"); } - if (VIR_ALLOC(disk) < 0) + if (!(disk = virDomainDiskDefNew())) goto error; if (dst == NULL) { @@ -1304,7 +1304,7 @@ xenParseSxpr(const struct sexpr *root, tmp = sexpr_node(root, "domain/image/hvm/cdrom"); if ((tmp != NULL) && (tmp[0] != 0)) { virDomainDiskDefPtr disk; - if (VIR_ALLOC(disk) < 0) + if (!(disk = virDomainDiskDefNew())) goto error; if (virDomainDiskSetSource(disk, tmp) < 0) { virDomainDiskDefFree(disk); @@ -1339,10 +1339,10 @@ 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 (VIR_ALLOC(disk) < 0) + if (!(disk = virDomainDiskDefNew())) goto error; if (virDomainDiskSetSource(disk, tmp) < 0) { - VIR_FREE(disk); + virDomainDiskDefFree(disk); goto error; } virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index c0422cf..b2db97d 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -486,7 +486,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto skipdisk; head = list->str; - if (VIR_ALLOC(disk) < 0) + if (!(disk = virDomainDiskDefNew())) goto cleanup; /* @@ -632,7 +632,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (xenXMConfigGetString(conf, "cdrom", &str, NULL) < 0) goto cleanup; if (str) { - if (VIR_ALLOC(disk) < 0) + if (!(disk = virDomainDiskDefNew())) goto cleanup; virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); -- 1.9.0

As part of the work on backing chains, I'm finding that it would be easier to directly manipulate chains of pointers (adding a snapshot merely adjusts pointers to form the correct list) rather than copy data from one struct to another. This patch converts domain disk source to be a pointer. In this patch, the pointer is ALWAYS allocated (thanks in part to the previous patch forwarding all disk def allocation through a common point), and all other changse are just mechanical fallout of the new type; there should be no functional change. It is possible that we may want to leave the pointer NULL for a cdrom with no medium in a later patch, but as that requires a closer audit of the source to ensure we don't fault on a null dereference, I didn't do it here. * src/conf/domain_conf.h (_virDomainDiskDef): Change type of src. * src/conf/domain_conf.c: Adjust all clients. * src/security/security_selinux.c: Likewise. * src/qemu/qemu_domain.c: Likewise. * src/qemu/qemu_command.c: Likewise. * src/qemu/qemu_conf.c: Likewise. * src/qemu/qemu_process.c: Likewise. * src/qemu/qemu_migration.c: Likewise. * src/qemu/qemu_driver.c: Likewise. * src/lxc/lxc_driver.c: Likewise. * src/lxc/lxc_controller.c: Likewise. * tests/securityselinuxlabeltest.c: Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 143 ++++++++++---------- src/conf/domain_conf.h | 2 +- src/lxc/lxc_controller.c | 8 +- src/lxc/lxc_driver.c | 8 +- src/qemu/qemu_command.c | 286 ++++++++++++++++++++------------------- src/qemu/qemu_conf.c | 86 ++++++------ src/qemu/qemu_domain.c | 10 +- src/qemu/qemu_driver.c | 236 ++++++++++++++++---------------- src/qemu/qemu_migration.c | 4 +- src/qemu/qemu_process.c | 8 +- src/security/security_selinux.c | 4 +- tests/securityselinuxlabeltest.c | 6 +- 12 files changed, 403 insertions(+), 398 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 97968b4..45f2691 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1186,7 +1186,10 @@ virDomainDiskDefNew(void) { virDomainDiskDefPtr ret; - ignore_value(VIR_ALLOC(ret)); + if (VIR_ALLOC(ret) < 0) + return NULL; + if (VIR_ALLOC(ret->src) < 0) + VIR_FREE(ret); return ret; } @@ -1197,7 +1200,7 @@ virDomainDiskDefFree(virDomainDiskDefPtr def) if (!def) return; - virStorageSourceClear(&def->src); + virStorageSourceFree(def->src); VIR_FREE(def->serial); VIR_FREE(def->dst); VIR_FREE(def->mirror); @@ -1213,21 +1216,21 @@ virDomainDiskDefFree(virDomainDiskDefPtr def) int virDomainDiskGetType(virDomainDiskDefPtr def) { - return def->src.type; + return def->src->type; } void virDomainDiskSetType(virDomainDiskDefPtr def, int type) { - def->src.type = type; + def->src->type = type; } const char * virDomainDiskGetSource(virDomainDiskDefPtr def) { - return def->src.path; + return def->src->path; } @@ -1235,11 +1238,11 @@ int virDomainDiskSetSource(virDomainDiskDefPtr def, const char *src) { int ret; - char *tmp = def->src.path; + char *tmp = def->src->path; - ret = VIR_STRDUP(def->src.path, src); + ret = VIR_STRDUP(def->src->path, src); if (ret < 0) - def->src.path = tmp; + def->src->path = tmp; else VIR_FREE(tmp); return ret; @@ -1249,7 +1252,7 @@ virDomainDiskSetSource(virDomainDiskDefPtr def, const char *src) const char * virDomainDiskGetDriver(virDomainDiskDefPtr def) { - return def->src.driverName; + return def->src->driverName; } @@ -1257,11 +1260,11 @@ int virDomainDiskSetDriver(virDomainDiskDefPtr def, const char *name) { int ret; - char *tmp = def->src.driverName; + char *tmp = def->src->driverName; - ret = VIR_STRDUP(def->src.driverName, name); + ret = VIR_STRDUP(def->src->driverName, name); if (ret < 0) - def->src.driverName = tmp; + def->src->driverName = tmp; else VIR_FREE(tmp); return ret; @@ -1271,14 +1274,14 @@ virDomainDiskSetDriver(virDomainDiskDefPtr def, const char *name) int virDomainDiskGetFormat(virDomainDiskDefPtr def) { - return def->src.format; + return def->src->format; } void virDomainDiskSetFormat(virDomainDiskDefPtr def, int format) { - def->src.format = format; + def->src->format = format; } @@ -5236,13 +5239,13 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, type = virXMLPropString(node, "type"); if (type) { - if ((def->src.type = virStorageTypeFromString(type)) <= 0) { + if ((def->src->type = virStorageTypeFromString(type)) <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown disk type '%s'"), type); goto error; } } else { - def->src.type = VIR_STORAGE_TYPE_FILE; + def->src->type = VIR_STORAGE_TYPE_FILE; } snapshot = virXMLPropString(node, "snapshot"); @@ -5253,18 +5256,18 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, cur = node->children; while (cur != NULL) { if (cur->type == XML_ELEMENT_NODE) { - if (!source && !def->src.hosts && !def->src.srcpool && + if (!source && !def->src->hosts && !def->src->srcpool && xmlStrEqual(cur->name, BAD_CAST "source")) { sourceNode = cur; - if (virDomainDiskSourceParse(cur, &def->src) < 0) + if (virDomainDiskSourceParse(cur, def->src) < 0) goto error; - source = def->src.path; + source = def->src->path; - if (def->src.type == VIR_STORAGE_TYPE_NETWORK) { - if (def->src.protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI) + if (def->src->type == VIR_STORAGE_TYPE_NETWORK) { + if (def->src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI) expected_secret_usage = VIR_SECRET_USAGE_TYPE_ISCSI; - else if (def->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD) + else if (def->src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD) expected_secret_usage = VIR_SECRET_USAGE_TYPE_CEPH; } @@ -5373,7 +5376,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } - def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_NONE; + def->src->auth.secretType = VIR_STORAGE_SECRET_TYPE_NONE; child = cur->children; while (child != NULL) { if (child->type == XML_ELEMENT_NODE && @@ -5410,17 +5413,17 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } if (authUUID != NULL) { - def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_UUID; + def->src->auth.secretType = VIR_STORAGE_SECRET_TYPE_UUID; if (virUUIDParse(authUUID, - def->src.auth.secret.uuid) < 0) { + def->src->auth.secret.uuid) < 0) { virReportError(VIR_ERR_XML_ERROR, _("malformed uuid %s"), authUUID); goto error; } } else if (authUsage != NULL) { - def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_USAGE; - def->src.auth.secret.usage = authUsage; + def->src->auth.secretType = VIR_STORAGE_SECRET_TYPE_USAGE; + def->src->auth.secret.usage = authUsage; authUsage = NULL; } } @@ -5565,7 +5568,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, /* Only CDROM and Floppy devices are allowed missing source path * to indicate no media present. LUN is for raw access CD-ROMs * that are not attached to a physical device presently */ - if (source == NULL && def->src.hosts == NULL && !def->src.srcpool && + if (source == NULL && def->src->hosts == NULL && !def->src->srcpool && def->device != VIR_DOMAIN_DISK_DEVICE_CDROM && def->device != VIR_DOMAIN_DISK_DEVICE_LUN && def->device != VIR_DOMAIN_DISK_DEVICE_FLOPPY) { @@ -5578,8 +5581,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, if (sourceNode) { xmlNodePtr saved_node = ctxt->node; ctxt->node = sourceNode; - if (virSecurityDeviceLabelDefParseXML(&def->src.seclabels, - &def->src.nseclabels, + if (virSecurityDeviceLabelDefParseXML(&def->src->seclabels, + &def->src->nseclabels, vmSeclabels, nvmSeclabels, ctxt, @@ -5589,10 +5592,10 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } if (target == NULL) { - if (def->src.srcpool) { + if (def->src->srcpool) { char *tmp; if (virAsprintf(&tmp, "pool = '%s', volume = '%s'", - def->src.srcpool->pool, def->src.srcpool->volume) < 0) + def->src->srcpool->pool, def->src->srcpool->volume) < 0) goto error; virReportError(VIR_ERR_NO_TARGET, "%s", tmp); @@ -5857,7 +5860,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, goto error; } - if (def->src.type == VIR_STORAGE_TYPE_NETWORK) { + if (def->src->type == VIR_STORAGE_TYPE_NETWORK) { virReportError(VIR_ERR_XML_ERROR, _("Setting disk %s is not allowed for " "disk of network type"), @@ -5878,14 +5881,14 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, def->dst = target; target = NULL; - def->src.auth.username = authUsername; + def->src->auth.username = authUsername; authUsername = NULL; - def->src.driverName = driverName; + def->src->driverName = driverName; driverName = NULL; def->mirror = mirror; mirror = NULL; def->mirroring = mirroring; - def->src.encryption = encryption; + def->src->encryption = encryption; encryption = NULL; def->serial = serial; serial = NULL; @@ -5897,8 +5900,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, product = NULL; if (driverType) { - def->src.format = virStorageFileFormatTypeFromString(driverType); - if (def->src.format <= 0) { + def->src->format = virStorageFileFormatTypeFromString(driverType); + if (def->src->format <= 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown driver format value '%s'"), driverType); @@ -5920,7 +5923,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, && virDomainDiskDefAssignAddress(xmlopt, def) < 0) goto error; - if (virDomainDiskBackingStoreParse(ctxt, &def->src) < 0) + if (virDomainDiskBackingStoreParse(ctxt, def->src) < 0) goto error; cleanup: @@ -14997,7 +15000,7 @@ virDomainDiskDefFormat(virBufferPtr buf, virDomainDiskDefPtr def, unsigned int flags) { - const char *type = virStorageTypeToString(def->src.type); + const char *type = virStorageTypeToString(def->src->type); const char *device = virDomainDiskDeviceTypeToString(def->device); const char *bus = virDomainDiskBusTypeToString(def->bus); const char *cachemode = virDomainDiskCacheTypeToString(def->cachemode); @@ -15012,9 +15015,9 @@ virDomainDiskDefFormat(virBufferPtr buf, char uuidstr[VIR_UUID_STRING_BUFLEN]; - if (!type || !def->src.type) { + if (!type || !def->src->type) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected disk type %d"), def->src.type); + _("unexpected disk type %d"), def->src->type); return -1; } if (!device) { @@ -15064,16 +15067,16 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); - if (def->src.driverName || def->src.format > 0 || def->cachemode || + if (def->src->driverName || def->src->format > 0 || def->cachemode || def->error_policy || def->rerror_policy || def->iomode || def->ioeventfd || def->event_idx || def->copy_on_read || def->discard) { virBufferAddLit(buf, "<driver"); - if (def->src.driverName) - virBufferAsprintf(buf, " name='%s'", def->src.driverName); - if (def->src.format > 0) + if (def->src->driverName) + virBufferAsprintf(buf, " name='%s'", def->src->driverName); + if (def->src->format > 0) virBufferAsprintf(buf, " type='%s'", - virStorageFileFormatTypeToString(def->src.format)); + virStorageFileFormatTypeToString(def->src->format)); if (def->cachemode) virBufferAsprintf(buf, " cache='%s'", cachemode); if (def->error_policy) @@ -15093,37 +15096,37 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } - if (def->src.auth.username) { + if (def->src->auth.username) { virBufferEscapeString(buf, "<auth username='%s'>\n", - def->src.auth.username); + def->src->auth.username); virBufferAdjustIndent(buf, 2); - if (def->src.protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI) { + if (def->src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI) { virBufferAddLit(buf, "<secret type='iscsi'"); - } else if (def->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { + } else if (def->src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { virBufferAddLit(buf, "<secret type='ceph'"); } - if (def->src.auth.secretType == VIR_STORAGE_SECRET_TYPE_UUID) { - virUUIDFormat(def->src.auth.secret.uuid, uuidstr); + if (def->src->auth.secretType == VIR_STORAGE_SECRET_TYPE_UUID) { + virUUIDFormat(def->src->auth.secret.uuid, uuidstr); virBufferAsprintf(buf, " uuid='%s'/>\n", uuidstr); } - if (def->src.auth.secretType == VIR_STORAGE_SECRET_TYPE_USAGE) { + if (def->src->auth.secretType == VIR_STORAGE_SECRET_TYPE_USAGE) { virBufferEscapeString(buf, " usage='%s'/>\n", - def->src.auth.secret.usage); + def->src->auth.secret.usage); } virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</auth>\n"); } - if (virDomainDiskSourceFormat(buf, &def->src, def->startupPolicy, + if (virDomainDiskSourceFormat(buf, def->src, def->startupPolicy, flags) < 0) return -1; /* Don't format backingStore to inactive XMLs until the code for * persistent storage of backing chains is ready. */ if (!(flags & VIR_DOMAIN_XML_INACTIVE) && - virDomainDiskBackingStoreFormat(buf, def->src.backingStore, - def->src.backingStoreRaw, 1) < 0) + virDomainDiskBackingStoreFormat(buf, def->src->backingStore, + def->src->backingStoreRaw, 1) < 0) return -1; virDomainDiskGeometryDefFormat(buf, def); @@ -15209,8 +15212,8 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferEscapeString(buf, "<wwn>%s</wwn>\n", def->wwn); virBufferEscapeString(buf, "<vendor>%s</vendor>\n", def->vendor); virBufferEscapeString(buf, "<product>%s</product>\n", def->product); - if (def->src.encryption && - virStorageEncryptionFormat(buf, def->src.encryption) < 0) + if (def->src->encryption && + virStorageEncryptionFormat(buf, def->src->encryption) < 0) return -1; if (virDomainDeviceInfoFormat(buf, &def->info, flags | VIR_DOMAIN_XML_INTERNAL_ALLOW_BOOT) < 0) @@ -18670,14 +18673,14 @@ virDomainDiskDefForeachPath(virDomainDiskDefPtr disk, if (!path || type == VIR_STORAGE_TYPE_NETWORK || (type == VIR_STORAGE_TYPE_VOLUME && - disk->src.srcpool && - disk->src.srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT)) + disk->src->srcpool && + disk->src->srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT)) return 0; if (iter(disk, path, 0, opaque) < 0) goto cleanup; - tmp = disk->src.backingStore; + tmp = disk->src->backingStore; while (tmp && virStorageIsFile(tmp->path)) { if (!ignoreOpenFailure && tmp->backingStoreRaw && !tmp->backingStore) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -19433,9 +19436,9 @@ virDomainDiskDefGetSecurityLabelDef(virDomainDiskDefPtr def, const char *model) if (def == NULL) return NULL; - for (i = 0; i < def->src.nseclabels; i++) { - if (STREQ_NULLABLE(def->src.seclabels[i]->model, model)) - return def->src.seclabels[i]; + for (i = 0; i < def->src->nseclabels; i++) { + if (STREQ_NULLABLE(def->src->seclabels[i]->model, model)) + return def->src->seclabels[i]; } return NULL; } @@ -19526,14 +19529,14 @@ virDomainDiskSourceIsBlockType(virDomainDiskDefPtr def) * If it's a block type source pool, then it's possible */ if (virDomainDiskGetType(def) == VIR_STORAGE_TYPE_VOLUME && - def->src.srcpool && - def->src.srcpool->voltype == VIR_STORAGE_VOL_BLOCK) { + def->src->srcpool && + def->src->srcpool->voltype == VIR_STORAGE_VOL_BLOCK) { /* We don't think the volume accessed by remote URI is * block type source, since we can't/shouldn't manage it * (e.g. set sgio=filtered|unfiltered for it) in libvirt. */ - if (def->src.srcpool->pooltype == VIR_STORAGE_POOL_ISCSI && - def->src.srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT) + if (def->src->srcpool->pooltype == VIR_STORAGE_POOL_ISCSI && + def->src->srcpool->mode == VIR_STORAGE_SOURCE_POOL_MODE_DIRECT) return false; return true; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4f4ce02..f388865 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -598,7 +598,7 @@ typedef virDomainBlockIoTuneInfo *virDomainBlockIoTuneInfoPtr; /* Stores the virtual disk configuration */ struct _virDomainDiskDef { - virStorageSource src; + virStorageSourcePtr src; int device; /* enum virDomainDiskDevice */ int bus; /* enum virDomainDiskBus */ diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 5521c6e..fe2a5dc 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1669,7 +1669,7 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl, int ret = -1; struct stat sb; mode_t mode; - char *tmpsrc = def->src.path; + char *tmpsrc = def->src->path; if (virDomainDiskGetType(def) != VIR_STORAGE_TYPE_BLOCK) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -1686,7 +1686,7 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl, LXC_STATE_DIR, ctrl->def->name, def->dst) < 0) goto cleanup; - if (stat(def->src.path, &sb) < 0) { + if (stat(def->src->path, &sb) < 0) { virReportSystemError(errno, _("Unable to access %s"), tmpsrc); goto cleanup; @@ -1726,14 +1726,14 @@ static int virLXCControllerSetupDisk(virLXCControllerPtr ctrl, /* Labelling normally operates on src, but we need * to actually label the dst here, so hack the config */ - def->src.path = dst; + def->src->path = dst; if (virSecurityManagerSetImageLabel(securityDriver, ctrl->def, def) < 0) goto cleanup; ret = 0; cleanup: - def->src.path = tmpsrc; + def->src->path = tmpsrc; VIR_FREE(dst); return ret; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 1086289..d2852a7 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -3897,14 +3897,14 @@ lxcDomainAttachDeviceMknodHelper(pid_t pid ATTRIBUTE_UNUSED, switch (data->def->type) { case VIR_DOMAIN_DEVICE_DISK: { virDomainDiskDefPtr def = data->def->data.disk; - char *tmpsrc = def->src.path; - def->src.path = data->file; + char *tmpsrc = def->src->path; + def->src->path = data->file; if (virSecurityManagerSetImageLabel(data->driver->securityManager, data->vm->def, def) < 0) { - def->src.path = tmpsrc; + def->src->path = tmpsrc; goto cleanup; } - def->src.path = tmpsrc; + def->src->path = tmpsrc; } break; case VIR_DOMAIN_DEVICE_HOSTDEV: { diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f5b81c0..21703e2 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2699,7 +2699,7 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport) size_t skip; char **parts; - if (VIR_EXPAND_N(disk->src.hosts, disk->src.nhosts, 1) < 0) + if (VIR_EXPAND_N(disk->src->hosts, disk->src->nhosts, 1) < 0) return -1; if ((port = strchr(hostport, ']'))) { @@ -2714,29 +2714,29 @@ static int qemuAddRBDHost(virDomainDiskDefPtr disk, char *hostport) if (port) { *port = '\0'; port += skip; - if (VIR_STRDUP(disk->src.hosts[disk->src.nhosts - 1].port, port) < 0) + if (VIR_STRDUP(disk->src->hosts[disk->src->nhosts - 1].port, port) < 0) goto error; } else { - if (VIR_STRDUP(disk->src.hosts[disk->src.nhosts - 1].port, "6789") < 0) + if (VIR_STRDUP(disk->src->hosts[disk->src->nhosts - 1].port, "6789") < 0) goto error; } parts = virStringSplit(hostport, "\\:", 0); if (!parts) goto error; - disk->src.hosts[disk->src.nhosts-1].name = virStringJoin((const char **)parts, ":"); + disk->src->hosts[disk->src->nhosts-1].name = virStringJoin((const char **)parts, ":"); virStringFreeList(parts); - if (!disk->src.hosts[disk->src.nhosts-1].name) + if (!disk->src->hosts[disk->src->nhosts-1].name) goto error; - disk->src.hosts[disk->src.nhosts-1].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; - disk->src.hosts[disk->src.nhosts-1].socket = NULL; + disk->src->hosts[disk->src->nhosts-1].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; + disk->src->hosts[disk->src->nhosts-1].socket = NULL; return 0; error: - VIR_FREE(disk->src.hosts[disk->src.nhosts-1].port); - VIR_FREE(disk->src.hosts[disk->src.nhosts-1].name); + VIR_FREE(disk->src->hosts[disk->src->nhosts-1].port); + VIR_FREE(disk->src->hosts[disk->src->nhosts-1].name); return -1; } @@ -2746,7 +2746,7 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk) char *options = NULL; char *p, *e, *next; - p = strchr(disk->src.path, ':'); + p = strchr(disk->src->path, ':'); if (p) { if (VIR_STRDUP(options, p + 1) < 0) goto error; @@ -2775,7 +2775,7 @@ static int qemuParseRBDString(virDomainDiskDefPtr disk) } if (STRPREFIX(p, "id=") && - VIR_STRDUP(disk->src.auth.username, p + strlen("id=")) < 0) + VIR_STRDUP(disk->src->auth.username, p + strlen("id=")) < 0) goto error; if (STRPREFIX(p, "mon_host=")) { char *h, *sep; @@ -2818,7 +2818,7 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, char *volimg = NULL; char *secret = NULL; - if (VIR_ALLOC(def->src.hosts) < 0) + if (VIR_ALLOC(def->src->hosts) < 0) goto error; transp = strchr(uri->scheme, '+'); @@ -2832,30 +2832,30 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, } if (!transp) { - def->src.hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; + def->src->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; } else { - def->src.hosts->transport = virStorageNetHostTransportTypeFromString(transp); - if (def->src.hosts->transport < 0) { + def->src->hosts->transport = virStorageNetHostTransportTypeFromString(transp); + if (def->src->hosts->transport < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Invalid %s transport type '%s'"), scheme, transp); goto error; } } - def->src.nhosts = 0; /* set to 1 once everything succeeds */ + def->src->nhosts = 0; /* set to 1 once everything succeeds */ - if (def->src.hosts->transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) { - if (VIR_STRDUP(def->src.hosts->name, uri->server) < 0) + if (def->src->hosts->transport != VIR_STORAGE_NET_HOST_TRANS_UNIX) { + if (VIR_STRDUP(def->src->hosts->name, uri->server) < 0) goto error; - if (virAsprintf(&def->src.hosts->port, "%d", uri->port) < 0) + if (virAsprintf(&def->src->hosts->port, "%d", uri->port) < 0) goto error; } else { - def->src.hosts->name = NULL; - def->src.hosts->port = 0; + def->src->hosts->name = NULL; + def->src->hosts->port = 0; if (uri->query) { if (STRPREFIX(uri->query, "socket=")) { sock = strchr(uri->query, '=') + 1; - if (VIR_STRDUP(def->src.hosts->socket, sock) < 0) + if (VIR_STRDUP(def->src->hosts->socket, sock) < 0) goto error; } else { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2866,11 +2866,11 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, } if (uri->path) { volimg = uri->path + 1; /* skip the prefix slash */ - VIR_FREE(def->src.path); - if (VIR_STRDUP(def->src.path, volimg) < 0) + VIR_FREE(def->src->path); + if (VIR_STRDUP(def->src->path, volimg) < 0) goto error; } else { - VIR_FREE(def->src.path); + VIR_FREE(def->src->path); } if (uri->user) { @@ -2878,11 +2878,11 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, if (secret) *secret = '\0'; - if (VIR_STRDUP(def->src.auth.username, uri->user) < 0) + if (VIR_STRDUP(def->src->auth.username, uri->user) < 0) goto error; } - def->src.nhosts = 1; + def->src->nhosts = 1; ret = 0; cleanup: @@ -2891,8 +2891,8 @@ qemuParseDriveURIString(virDomainDiskDefPtr def, virURIPtr uri, return ret; error: - virStorageNetHostDefClear(def->src.hosts); - VIR_FREE(def->src.hosts); + virStorageNetHostDefClear(def->src->hosts); + VIR_FREE(def->src->hosts); goto cleanup; } @@ -2901,7 +2901,7 @@ qemuParseGlusterString(virDomainDiskDefPtr def) { virURIPtr uri = NULL; - if (!(uri = virURIParse(def->src.path))) + if (!(uri = virURIParse(def->src->path))) return -1; return qemuParseDriveURIString(def, uri, "gluster"); @@ -2914,7 +2914,7 @@ qemuParseISCSIString(virDomainDiskDefPtr def) char *slash; unsigned lun; - if (!(uri = virURIParse(def->src.path))) + if (!(uri = virURIParse(def->src->path))) return -1; if (uri->path && @@ -2925,7 +2925,7 @@ qemuParseISCSIString(virDomainDiskDefPtr def) else if (virStrToLong_ui(slash + 1, NULL, 10, &lun) == -1) { virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid name '%s' for iSCSI disk"), - def->src.path); + def->src->path); return -1; } } @@ -2942,8 +2942,8 @@ qemuParseNBDString(virDomainDiskDefPtr disk) virURIPtr uri = NULL; - if (strstr(disk->src.path, "://")) { - if (!(uri = virURIParse(disk->src.path))) + if (strstr(disk->src->path, "://")) { + if (!(uri = virURIParse(disk->src->path))) return -1; return qemuParseDriveURIString(disk, uri, "nbd"); } @@ -2951,7 +2951,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk) if (VIR_ALLOC(h) < 0) goto error; - host = disk->src.path + strlen("nbd:"); + host = disk->src->path + strlen("nbd:"); if (STRPREFIX(host, "unix:/")) { src = strchr(host + strlen("unix:"), ':'); if (src) @@ -2964,7 +2964,7 @@ qemuParseNBDString(virDomainDiskDefPtr disk) port = strchr(host, ':'); if (!port) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse nbd filename '%s'"), disk->src.path); + _("cannot parse nbd filename '%s'"), disk->src->path); goto error; } @@ -2987,10 +2987,10 @@ qemuParseNBDString(virDomainDiskDefPtr disk) src = NULL; } - VIR_FREE(disk->src.path); - disk->src.path = src; - disk->src.nhosts = 1; - disk->src.hosts = h; + VIR_FREE(disk->src->path); + disk->src->path = src; + disk->src->nhosts = 1; + disk->src->hosts = h; return 0; error: @@ -3357,7 +3357,7 @@ qemuBuildDriveStr(virConnectPtr conn, int idx = virDiskNameToIndex(disk->dst); int busid = -1, unitid = -1; char *source = NULL; - int actualType = virStorageSourceGetActualType(&disk->src); + int actualType = virStorageSourceGetActualType(disk->src); if (idx < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3439,7 +3439,7 @@ qemuBuildDriveStr(virConnectPtr conn, break; } - if (qemuGetDriveSourceString(&disk->src, conn, &source) < 0) + if (qemuGetDriveSourceString(disk->src, conn, &source) < 0) goto error; if (source && @@ -3452,11 +3452,11 @@ qemuBuildDriveStr(virConnectPtr conn, switch (actualType) { case VIR_STORAGE_TYPE_DIR: /* QEMU only supports magic FAT format for now */ - if (disk->src.format > 0 && - disk->src.format != VIR_STORAGE_FILE_FAT) { + if (disk->src->format > 0 && + disk->src->format != VIR_STORAGE_FILE_FAT) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported disk driver type for '%s'"), - virStorageFileFormatTypeToString(disk->src.format)); + virStorageFileFormatTypeToString(disk->src->format)); goto error; } @@ -3476,7 +3476,7 @@ qemuBuildDriveStr(virConnectPtr conn, case VIR_STORAGE_TYPE_BLOCK: if (disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - disk->src.type == VIR_STORAGE_TYPE_VOLUME ? + disk->src->type == VIR_STORAGE_TYPE_VOLUME ? _("tray status 'open' is invalid for block type volume") : _("tray status 'open' is invalid for block type disk")); goto error; @@ -3536,11 +3536,11 @@ qemuBuildDriveStr(virConnectPtr conn, _("transient disks not supported yet")); goto error; } - if (disk->src.format > 0 && - disk->src.type != VIR_STORAGE_TYPE_DIR && + if (disk->src->format > 0 && + disk->src->type != VIR_STORAGE_TYPE_DIR && virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_FORMAT)) virBufferAsprintf(&opt, ",format=%s", - virStorageFileFormatTypeToString(disk->src.format)); + virStorageFileFormatTypeToString(disk->src->format)); /* generate geometry command string */ if (disk->geometry.cylinders > 0 && @@ -3751,11 +3751,11 @@ qemuBuildDriveDevStr(virDomainDefPtr def, bus); goto error; } - if (disk->src.type == VIR_STORAGE_TYPE_NETWORK) { - if (disk->src.protocol != VIR_STORAGE_NET_PROTOCOL_ISCSI) { + if (disk->src->type == VIR_STORAGE_TYPE_NETWORK) { + if (disk->src->protocol != VIR_STORAGE_NET_PROTOCOL_ISCSI) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("disk device='lun' is not supported for protocol='%s'"), - virStorageNetProtocolTypeToString(disk->src.protocol)); + virStorageNetProtocolTypeToString(disk->src->protocol)); goto error; } } else if (!virDomainDiskSourceIsBlockType(disk)) { @@ -7880,11 +7880,11 @@ qemuBuildCommandLine(virConnectPtr conn, for (i = 0; i < def->ndisks; i++) { virDomainDiskDefPtr disk = def->disks[i]; - if (disk->src.driverName != NULL && - !STREQ(disk->src.driverName, "qemu")) { + if (disk->src->driverName != NULL && + !STREQ(disk->src->driverName, "qemu")) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported driver name '%s' for disk '%s'"), - disk->src.driverName, disk->src.path); + disk->src->driverName, disk->src->path); goto error; } } @@ -8009,11 +8009,11 @@ qemuBuildCommandLine(virConnectPtr conn, !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) { virCommandAddArg(cmd, "-usbdevice"); - virCommandAddArgFormat(cmd, "disk:%s", disk->src.path); + virCommandAddArgFormat(cmd, "disk:%s", disk->src->path); } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported usb disk type for '%s'"), - disk->src.path); + disk->src->path); goto error; } continue; @@ -8099,7 +8099,7 @@ qemuBuildCommandLine(virConnectPtr conn, const char *fmt; virDomainDiskDefPtr disk = def->disks[i]; - if ((disk->src.type == VIR_STORAGE_TYPE_BLOCK) && + if ((disk->src->type == VIR_STORAGE_TYPE_BLOCK) && (disk->tray_status == VIR_DOMAIN_DISK_TRAY_OPEN)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("tray status 'open' is invalid for " @@ -8110,11 +8110,11 @@ qemuBuildCommandLine(virConnectPtr conn, if (disk->bus == VIR_DOMAIN_DISK_BUS_USB) { if (disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) { virCommandAddArg(cmd, "-usbdevice"); - virCommandAddArgFormat(cmd, "disk:%s", disk->src.path); + virCommandAddArgFormat(cmd, "disk:%s", disk->src->path); } else { virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported usb disk type for '%s'"), - disk->src.path); + disk->src->path); goto error; } continue; @@ -8122,7 +8122,7 @@ qemuBuildCommandLine(virConnectPtr conn, if (STREQ(disk->dst, "hdc") && disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) { - if (disk->src.path) { + if (disk->src->path) { snprintf(dev, NAME_MAX, "-%s", "cdrom"); } else { continue; @@ -8138,13 +8138,13 @@ qemuBuildCommandLine(virConnectPtr conn, } } - if (disk->src.type == VIR_STORAGE_TYPE_DIR) { + if (disk->src->type == VIR_STORAGE_TYPE_DIR) { /* QEMU only supports magic FAT format for now */ - if (disk->src.format > 0 && - disk->src.format != VIR_STORAGE_FILE_FAT) { + if (disk->src->format > 0 && + disk->src->format != VIR_STORAGE_FILE_FAT) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported disk driver type for '%s'"), - virStorageFileFormatTypeToString(disk->src.format)); + virStorageFileFormatTypeToString(disk->src->format)); goto error; } if (!disk->readonly) { @@ -8159,12 +8159,12 @@ qemuBuildCommandLine(virConnectPtr conn, if (virAsprintf(&file, fmt, disk->src) < 0) goto error; - } else if (disk->src.type == VIR_STORAGE_TYPE_NETWORK) { + } else if (disk->src->type == VIR_STORAGE_TYPE_NETWORK) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("network disks are only supported with -drive")); goto error; } else { - if (VIR_STRDUP(file, disk->src.path) < 0) { + if (VIR_STRDUP(file, disk->src->path) < 0) { goto error; } } @@ -9665,6 +9665,8 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, if (VIR_ALLOC(def) < 0) goto cleanup; + if (VIR_ALLOC(def->src) < 0) + goto error; if (((dom->os.arch == VIR_ARCH_PPC64) && dom->os.machine && STREQ(dom->os.machine, "pseries"))) @@ -9672,28 +9674,28 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, else def->bus = VIR_DOMAIN_DISK_BUS_IDE; def->device = VIR_DOMAIN_DISK_DEVICE_DISK; - def->src.type = VIR_STORAGE_TYPE_FILE; + def->src->type = VIR_STORAGE_TYPE_FILE; for (i = 0; i < nkeywords; i++) { if (STREQ(keywords[i], "file")) { if (values[i] && STRNEQ(values[i], "")) { - def->src.path = values[i]; + def->src->path = values[i]; values[i] = NULL; - if (STRPREFIX(def->src.path, "/dev/")) - def->src.type = VIR_STORAGE_TYPE_BLOCK; - else if (STRPREFIX(def->src.path, "nbd:") || - STRPREFIX(def->src.path, "nbd+")) { - def->src.type = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_STORAGE_NET_PROTOCOL_NBD; + if (STRPREFIX(def->src->path, "/dev/")) + def->src->type = VIR_STORAGE_TYPE_BLOCK; + else if (STRPREFIX(def->src->path, "nbd:") || + STRPREFIX(def->src->path, "nbd+")) { + def->src->type = VIR_STORAGE_TYPE_NETWORK; + def->src->protocol = VIR_STORAGE_NET_PROTOCOL_NBD; if (qemuParseNBDString(def) < 0) goto error; - } else if (STRPREFIX(def->src.path, "rbd:")) { - char *p = def->src.path; + } else if (STRPREFIX(def->src->path, "rbd:")) { + char *p = def->src->path; - def->src.type = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_STORAGE_NET_PROTOCOL_RBD; - if (VIR_STRDUP(def->src.path, p + strlen("rbd:")) < 0) + def->src->type = VIR_STORAGE_TYPE_NETWORK; + def->src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD; + if (VIR_STRDUP(def->src->path, p + strlen("rbd:")) < 0) goto error; /* old-style CEPH_ARGS env variable is parsed later */ if (!old_style_ceph_args && qemuParseRBDString(def) < 0) { @@ -9702,31 +9704,31 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, } VIR_FREE(p); - } else if (STRPREFIX(def->src.path, "gluster:") || - STRPREFIX(def->src.path, "gluster+")) { - def->src.type = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER; + } else if (STRPREFIX(def->src->path, "gluster:") || + STRPREFIX(def->src->path, "gluster+")) { + def->src->type = VIR_STORAGE_TYPE_NETWORK; + def->src->protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER; if (qemuParseGlusterString(def) < 0) goto error; - } else if (STRPREFIX(def->src.path, "iscsi:")) { - def->src.type = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; + } else if (STRPREFIX(def->src->path, "iscsi:")) { + def->src->type = VIR_STORAGE_TYPE_NETWORK; + def->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; if (qemuParseISCSIString(def) < 0) goto error; - } else if (STRPREFIX(def->src.path, "sheepdog:")) { - char *p = def->src.path; + } else if (STRPREFIX(def->src->path, "sheepdog:")) { + char *p = def->src->path; char *port, *vdi; - def->src.type = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_STORAGE_NET_PROTOCOL_SHEEPDOG; - if (VIR_STRDUP(def->src.path, p + strlen("sheepdog:")) < 0) + def->src->type = VIR_STORAGE_TYPE_NETWORK; + def->src->protocol = VIR_STORAGE_NET_PROTOCOL_SHEEPDOG; + if (VIR_STRDUP(def->src->path, p + strlen("sheepdog:")) < 0) goto error; VIR_FREE(p); - /* def->src.path must be [vdiname] or [host]:[port]:[vdiname] */ - port = strchr(def->src.path, ':'); + /* def->src->path must be [vdiname] or [host]:[port]:[vdiname] */ + port = strchr(def->src->path, ':'); if (port) { *port = '\0'; vdi = strchr(port + 1, ':'); @@ -9734,26 +9736,26 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, *port = ':'; virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot parse sheepdog filename '%s'"), - def->src.path); + def->src->path); goto error; } port++; *vdi++ = '\0'; - if (VIR_ALLOC(def->src.hosts) < 0) + if (VIR_ALLOC(def->src->hosts) < 0) goto error; - def->src.nhosts = 1; - def->src.hosts->name = def->src.path; - if (VIR_STRDUP(def->src.hosts->port, port) < 0) + def->src->nhosts = 1; + def->src->hosts->name = def->src->path; + if (VIR_STRDUP(def->src->hosts->port, port) < 0) goto error; - def->src.hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; - def->src.hosts->socket = NULL; - if (VIR_STRDUP(def->src.path, vdi) < 0) + def->src->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; + def->src->hosts->socket = NULL; + if (VIR_STRDUP(def->src->path, vdi) < 0) goto error; } } else - def->src.type = VIR_STORAGE_TYPE_FILE; + def->src->type = VIR_STORAGE_TYPE_FILE; } else { - def->src.type = VIR_STORAGE_TYPE_FILE; + def->src->type = VIR_STORAGE_TYPE_FILE; } } else if (STREQ(keywords[i], "if")) { if (STREQ(values[i], "ide")) { @@ -9779,9 +9781,9 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, } else if (STREQ(values[i], "floppy")) def->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY; } else if (STREQ(keywords[i], "format")) { - if (VIR_STRDUP(def->src.driverName, "qemu") < 0) + if (VIR_STRDUP(def->src->driverName, "qemu") < 0) goto error; - def->src.format = virStorageFileFormatTypeFromString(values[i]); + def->src->format = virStorageFileFormatTypeFromString(values[i]); } else if (STREQ(keywords[i], "cache")) { if (STREQ(values[i], "off") || STREQ(values[i], "none")) @@ -9886,9 +9888,9 @@ qemuParseCommandLineDisk(virDomainXMLOptionPtr xmlopt, if (def->rerror_policy == def->error_policy) def->rerror_policy = 0; - if (!def->src.path && + if (!def->src->path && def->device == VIR_DOMAIN_DISK_DEVICE_DISK && - def->src.type != VIR_STORAGE_TYPE_NETWORK) { + def->src->type != VIR_STORAGE_TYPE_NETWORK) { virReportError(VIR_ERR_INTERNAL_ERROR, _("missing file parameter in drive '%s'"), val); goto error; @@ -10973,23 +10975,23 @@ qemuParseCommandLine(virCapsPtr qemuCaps, goto error; if (STRPREFIX(val, "/dev/")) - disk->src.type = VIR_STORAGE_TYPE_BLOCK; + disk->src->type = VIR_STORAGE_TYPE_BLOCK; else if (STRPREFIX(val, "nbd:")) { - disk->src.type = VIR_STORAGE_TYPE_NETWORK; - disk->src.protocol = VIR_STORAGE_NET_PROTOCOL_NBD; + disk->src->type = VIR_STORAGE_TYPE_NETWORK; + disk->src->protocol = VIR_STORAGE_NET_PROTOCOL_NBD; } else if (STRPREFIX(val, "rbd:")) { - disk->src.type = VIR_STORAGE_TYPE_NETWORK; - disk->src.protocol = VIR_STORAGE_NET_PROTOCOL_RBD; + disk->src->type = VIR_STORAGE_TYPE_NETWORK; + disk->src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD; val += strlen("rbd:"); } else if (STRPREFIX(val, "gluster")) { - disk->src.type = VIR_STORAGE_TYPE_NETWORK; - disk->src.protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER; + disk->src->type = VIR_STORAGE_TYPE_NETWORK; + disk->src->protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER; } else if (STRPREFIX(val, "sheepdog:")) { - disk->src.type = VIR_STORAGE_TYPE_NETWORK; - disk->src.protocol = VIR_STORAGE_NET_PROTOCOL_SHEEPDOG; + disk->src->type = VIR_STORAGE_TYPE_NETWORK; + disk->src->protocol = VIR_STORAGE_NET_PROTOCOL_SHEEPDOG; val += strlen("sheepdog:"); } else - disk->src.type = VIR_STORAGE_TYPE_FILE; + disk->src->type = VIR_STORAGE_TYPE_FILE; if (STREQ(arg, "-cdrom")) { disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; if (((def->os.arch == VIR_ARCH_PPC64) && @@ -11015,13 +11017,13 @@ qemuParseCommandLine(virCapsPtr qemuCaps, if (VIR_STRDUP(disk->dst, arg + 1) < 0) goto error; } - if (VIR_STRDUP(disk->src.path, val) < 0) + if (VIR_STRDUP(disk->src->path, val) < 0) goto error; - if (disk->src.type == VIR_STORAGE_TYPE_NETWORK) { + if (disk->src->type == VIR_STORAGE_TYPE_NETWORK) { char *port; - switch ((virStorageNetProtocol) disk->src.protocol) { + switch ((virStorageNetProtocol) disk->src->protocol) { case VIR_STORAGE_NET_PROTOCOL_NBD: if (qemuParseNBDString(disk) < 0) goto error; @@ -11033,7 +11035,7 @@ qemuParseCommandLine(virCapsPtr qemuCaps, break; case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: /* disk->src must be [vdiname] or [host]:[port]:[vdiname] */ - port = strchr(disk->src.path, ':'); + port = strchr(disk->src->path, ':'); if (port) { char *vdi; @@ -11045,13 +11047,13 @@ qemuParseCommandLine(virCapsPtr qemuCaps, goto error; } *vdi++ = '\0'; - if (VIR_ALLOC(disk->src.hosts) < 0) + if (VIR_ALLOC(disk->src->hosts) < 0) goto error; - disk->src.nhosts = 1; - disk->src.hosts->name = disk->src.path; - if (VIR_STRDUP(disk->src.hosts->port, port) < 0) + disk->src->nhosts = 1; + disk->src->hosts->name = disk->src->path; + if (VIR_STRDUP(disk->src->hosts->port, port) < 0) goto error; - if (VIR_STRDUP(disk->src.path, vdi) < 0) + if (VIR_STRDUP(disk->src->path, vdi) < 0) goto error; } break; @@ -11270,12 +11272,12 @@ qemuParseCommandLine(virCapsPtr qemuCaps, } else if (STRPREFIX(val, "disk:")) { if (!(disk = virDomainDiskDefNew())) goto error; - if (VIR_STRDUP(disk->src.path, val + strlen("disk:")) < 0) + if (VIR_STRDUP(disk->src->path, val + strlen("disk:")) < 0) goto error; - if (STRPREFIX(disk->src.path, "/dev/")) - disk->src.type = VIR_STORAGE_TYPE_BLOCK; + if (STRPREFIX(disk->src->path, "/dev/")) + disk->src->type = VIR_STORAGE_TYPE_BLOCK; else - disk->src.type = VIR_STORAGE_TYPE_FILE; + disk->src->type = VIR_STORAGE_TYPE_FILE; disk->device = VIR_DOMAIN_DISK_DEVICE_DISK; disk->bus = VIR_DOMAIN_DISK_BUS_USB; disk->removable = VIR_DOMAIN_FEATURE_STATE_DEFAULT; @@ -11506,8 +11508,8 @@ qemuParseCommandLine(virCapsPtr qemuCaps, char *hosts, *port, *saveptr = NULL, *token; virDomainDiskDefPtr first_rbd_disk = NULL; for (i = 0; i < def->ndisks; i++) { - if (def->disks[i]->src.type == VIR_STORAGE_TYPE_NETWORK && - def->disks[i]->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { + if (def->disks[i]->src->type == VIR_STORAGE_TYPE_NETWORK && + def->disks[i]->src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { first_rbd_disk = def->disks[i]; break; } @@ -11527,11 +11529,11 @@ qemuParseCommandLine(virCapsPtr qemuCaps, } if (VIR_STRDUP(hosts, strchr(ceph_args, ' ') + 1) < 0) goto error; - first_rbd_disk->src.nhosts = 0; + first_rbd_disk->src->nhosts = 0; token = strtok_r(hosts, ",", &saveptr); while (token != NULL) { - if (VIR_REALLOC_N(first_rbd_disk->src.hosts, - first_rbd_disk->src.nhosts + 1) < 0) { + if (VIR_REALLOC_N(first_rbd_disk->src->hosts, + first_rbd_disk->src->nhosts + 1) < 0) { VIR_FREE(hosts); goto error; } @@ -11543,21 +11545,21 @@ qemuParseCommandLine(virCapsPtr qemuCaps, goto error; } } - first_rbd_disk->src.hosts[first_rbd_disk->src.nhosts].port = port; - if (VIR_STRDUP(first_rbd_disk->src.hosts[first_rbd_disk->src.nhosts].name, + first_rbd_disk->src->hosts[first_rbd_disk->src->nhosts].port = port; + if (VIR_STRDUP(first_rbd_disk->src->hosts[first_rbd_disk->src->nhosts].name, token) < 0) { VIR_FREE(hosts); goto error; } - first_rbd_disk->src.hosts[first_rbd_disk->src.nhosts].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; - first_rbd_disk->src.hosts[first_rbd_disk->src.nhosts].socket = NULL; + first_rbd_disk->src->hosts[first_rbd_disk->src->nhosts].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; + first_rbd_disk->src->hosts[first_rbd_disk->src->nhosts].socket = NULL; - first_rbd_disk->src.nhosts++; + first_rbd_disk->src->nhosts++; token = strtok_r(NULL, ",", &saveptr); } VIR_FREE(hosts); - if (first_rbd_disk->src.nhosts == 0) { + if (first_rbd_disk->src->nhosts == 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("found no rbd hosts in CEPH_ARGS '%s'"), ceph_args); goto error; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index c14d700..8a3bdef 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -802,8 +802,8 @@ qemuCheckSharedDevice(virHashTablePtr sharedDevices, virReportError(VIR_ERR_OPERATION_INVALID, _("sgio of shared disk 'pool=%s' 'volume=%s' conflicts " "with other active domains"), - disk->src.srcpool->pool, - disk->src.srcpool->volume); + disk->src->srcpool->pool, + disk->src->srcpool->volume); } else { virReportError(VIR_ERR_OPERATION_INVALID, _("sgio of shared disk '%s' conflicts with other " @@ -1163,33 +1163,33 @@ qemuAddISCSIPoolSourceHost(virDomainDiskDefPtr def, } /* iscsi pool only supports one host */ - def->src.nhosts = 1; + def->src->nhosts = 1; - if (VIR_ALLOC_N(def->src.hosts, def->src.nhosts) < 0) + if (VIR_ALLOC_N(def->src->hosts, def->src->nhosts) < 0) goto cleanup; - if (VIR_STRDUP(def->src.hosts[0].name, pooldef->source.hosts[0].name) < 0) + if (VIR_STRDUP(def->src->hosts[0].name, pooldef->source.hosts[0].name) < 0) goto cleanup; - if (virAsprintf(&def->src.hosts[0].port, "%d", + if (virAsprintf(&def->src->hosts[0].port, "%d", pooldef->source.hosts[0].port ? pooldef->source.hosts[0].port : 3260) < 0) goto cleanup; /* iscsi volume has name like "unit:0:0:1" */ - if (!(tokens = virStringSplit(def->src.srcpool->volume, ":", 0))) + if (!(tokens = virStringSplit(def->src->srcpool->volume, ":", 0))) goto cleanup; if (virStringListLength(tokens) != 4) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected iscsi volume name '%s'"), - def->src.srcpool->volume); + def->src->srcpool->volume); goto cleanup; } /* iscsi pool has only one source device path */ - if (virAsprintf(&def->src.path, "%s/%s", + if (virAsprintf(&def->src->path, "%s/%s", pooldef->source.devices[0].path, tokens[3]) < 0) goto cleanup; @@ -1197,10 +1197,10 @@ qemuAddISCSIPoolSourceHost(virDomainDiskDefPtr def, /* Storage pool have not supported these 2 attributes yet, * use the defaults. */ - def->src.hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; - def->src.hosts[0].socket = NULL; + def->src->hosts[0].transport = VIR_STORAGE_NET_HOST_TRANS_TCP; + def->src->hosts[0].socket = NULL; - def->src.protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; + def->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; ret = 0; @@ -1225,34 +1225,34 @@ qemuTranslateDiskSourcePoolAuth(virDomainDiskDefPtr def, * into the virDomainDiskDef */ if (pooldef->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) { - if (VIR_STRDUP(def->src.auth.username, + if (VIR_STRDUP(def->src->auth.username, pooldef->source.auth.chap.username) < 0) goto cleanup; if (pooldef->source.auth.chap.secret.uuidUsable) { - def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_UUID; - memcpy(def->src.auth.secret.uuid, + def->src->auth.secretType = VIR_STORAGE_SECRET_TYPE_UUID; + memcpy(def->src->auth.secret.uuid, pooldef->source.auth.chap.secret.uuid, VIR_UUID_BUFLEN); } else { - if (VIR_STRDUP(def->src.auth.secret.usage, + if (VIR_STRDUP(def->src->auth.secret.usage, pooldef->source.auth.chap.secret.usage) < 0) goto cleanup; - def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_USAGE; + def->src->auth.secretType = VIR_STORAGE_SECRET_TYPE_USAGE; } } else if (pooldef->source.authType == VIR_STORAGE_POOL_AUTH_CEPHX) { - if (VIR_STRDUP(def->src.auth.username, + if (VIR_STRDUP(def->src->auth.username, pooldef->source.auth.cephx.username) < 0) goto cleanup; if (pooldef->source.auth.cephx.secret.uuidUsable) { - def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_UUID; - memcpy(def->src.auth.secret.uuid, + def->src->auth.secretType = VIR_STORAGE_SECRET_TYPE_UUID; + memcpy(def->src->auth.secret.uuid, pooldef->source.auth.cephx.secret.uuid, VIR_UUID_BUFLEN); } else { - if (VIR_STRDUP(def->src.auth.secret.usage, + if (VIR_STRDUP(def->src->auth.secret.usage, pooldef->source.auth.cephx.secret.usage) < 0) goto cleanup; - def->src.auth.secretType = VIR_STORAGE_SECRET_TYPE_USAGE; + def->src->auth.secretType = VIR_STORAGE_SECRET_TYPE_USAGE; } } ret = 0; @@ -1274,24 +1274,24 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, int ret = -1; virErrorPtr savedError = NULL; - if (def->src.type != VIR_STORAGE_TYPE_VOLUME) + if (def->src->type != VIR_STORAGE_TYPE_VOLUME) return 0; - if (!def->src.srcpool) + if (!def->src->srcpool) return 0; - if (!(pool = virStoragePoolLookupByName(conn, def->src.srcpool->pool))) + if (!(pool = virStoragePoolLookupByName(conn, def->src->srcpool->pool))) return -1; if (virStoragePoolIsActive(pool) != 1) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("storage pool '%s' containing volume '%s' " "is not active"), - def->src.srcpool->pool, def->src.srcpool->volume); + def->src->srcpool->pool, def->src->srcpool->volume); goto cleanup; } - if (!(vol = virStorageVolLookupByName(pool, def->src.srcpool->volume))) + if (!(vol = virStorageVolLookupByName(pool, def->src->srcpool->volume))) goto cleanup; if (virStorageVolGetInfo(vol, &info) < 0) @@ -1303,19 +1303,19 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, if (!(pooldef = virStoragePoolDefParseString(poolxml))) goto cleanup; - def->src.srcpool->pooltype = pooldef->type; - def->src.srcpool->voltype = info.type; + def->src->srcpool->pooltype = pooldef->type; + def->src->srcpool->voltype = info.type; - if (def->src.srcpool->mode && pooldef->type != VIR_STORAGE_POOL_ISCSI) { + if (def->src->srcpool->mode && pooldef->type != VIR_STORAGE_POOL_ISCSI) { virReportError(VIR_ERR_XML_ERROR, "%s", _("disk source mode is only valid when " "storage pool is of iscsi type")); goto cleanup; } - VIR_FREE(def->src.path); - virStorageNetHostDefFree(def->src.nhosts, def->src.hosts); - virStorageSourceAuthClear(&def->src); + VIR_FREE(def->src->path); + virStorageNetHostDefFree(def->src->nhosts, def->src->hosts); + virStorageSourceAuthClear(def->src); switch ((virStoragePoolType) pooldef->type) { case VIR_STORAGE_POOL_DIR: @@ -1324,7 +1324,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, case VIR_STORAGE_POOL_LOGICAL: case VIR_STORAGE_POOL_DISK: case VIR_STORAGE_POOL_SCSI: - if (!(def->src.path = virStorageVolGetPath(vol))) + if (!(def->src->path = virStorageVolGetPath(vol))) goto cleanup; if (def->startupPolicy && info.type != VIR_STORAGE_VOL_FILE) { @@ -1337,15 +1337,15 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, switch (info.type) { case VIR_STORAGE_VOL_FILE: - def->src.srcpool->actualtype = VIR_STORAGE_TYPE_FILE; + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_FILE; break; case VIR_STORAGE_VOL_DIR: - def->src.srcpool->actualtype = VIR_STORAGE_TYPE_DIR; + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_DIR; break; case VIR_STORAGE_VOL_BLOCK: - def->src.srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; break; case VIR_STORAGE_VOL_NETWORK: @@ -1368,20 +1368,20 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, goto cleanup; } - switch (def->src.srcpool->mode) { + switch (def->src->srcpool->mode) { case VIR_STORAGE_SOURCE_POOL_MODE_DEFAULT: case VIR_STORAGE_SOURCE_POOL_MODE_LAST: - def->src.srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST; + def->src->srcpool->mode = VIR_STORAGE_SOURCE_POOL_MODE_HOST; /* fallthrough */ case VIR_STORAGE_SOURCE_POOL_MODE_HOST: - def->src.srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; - if (!(def->src.path = virStorageVolGetPath(vol))) + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_BLOCK; + if (!(def->src->path = virStorageVolGetPath(vol))) goto cleanup; break; case VIR_STORAGE_SOURCE_POOL_MODE_DIRECT: - def->src.srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK; - def->src.protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; + def->src->srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK; + def->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; if (qemuTranslateDiskSourcePoolAuth(def, pooldef) < 0) goto cleanup; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 78cfdc6..0cc8b9a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2256,7 +2256,7 @@ qemuDiskChainCheckBroken(virDomainDiskDefPtr disk) if (!virDomainDiskGetSource(disk)) return 0; - if (virStorageFileChainGetBroken(&disk->src, &brokenFile) < 0) + if (virStorageFileChainGetBroken(disk->src, &brokenFile) < 0) return -1; if (brokenFile) { @@ -2284,7 +2284,7 @@ qemuDomainCheckDiskPresence(virQEMUDriverPtr driver, virDomainDiskDefPtr disk = vm->def->disks[idx]; const char *path = virDomainDiskGetSource(disk); virStorageFileFormat format = virDomainDiskGetFormat(disk); - virStorageType type = virStorageSourceGetActualType(&disk->src); + virStorageType type = virStorageSourceGetActualType(disk->src); if (!path) continue; @@ -2434,16 +2434,16 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, type == VIR_STORAGE_TYPE_VOLUME) goto cleanup; - if (disk->src.backingStore) { + if (disk->src->backingStore) { if (force) - virStorageSourceClearBackingStore(&disk->src); + virStorageSourceClearBackingStore(disk->src); else goto cleanup; } qemuDomainGetImageIds(cfg, vm, disk, &uid, &gid); - if (virStorageFileGetMetadata(&disk->src, + if (virStorageFileGetMetadata(disk->src, uid, gid, cfg->allowDiskFormatProbing) < 0) ret = -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index bf46d5d..0f946d1 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6873,18 +6873,18 @@ qemuDomainUpdateDeviceConfig(virQEMUCapsPtr qemuCaps, * Update 'orig' * We allow updating src/type//driverType/cachemode/ */ - VIR_FREE(orig->src.path); - orig->src.path = disk->src.path; - orig->src.type = disk->src.type; + VIR_FREE(orig->src->path); + orig->src->path = disk->src->path; + orig->src->type = disk->src->type; orig->cachemode = disk->cachemode; - if (disk->src.driverName) { - VIR_FREE(orig->src.driverName); - orig->src.driverName = disk->src.driverName; - disk->src.driverName = NULL; + if (disk->src->driverName) { + VIR_FREE(orig->src->driverName); + orig->src->driverName = disk->src->driverName; + disk->src->driverName = NULL; } - if (disk->src.format) - orig->src.format = disk->src.format; - disk->src.path = NULL; + if (disk->src->format) + orig->src->format = disk->src->format; + disk->src->path = NULL; break; case VIR_DOMAIN_DEVICE_NET: @@ -9462,8 +9462,8 @@ qemuDomainBlockResize(virDomainPtr dom, /* qcow2 and qed must be sized on 512 byte blocks/sectors, * so adjust size if necessary to round up. */ - if (disk->src.format == VIR_STORAGE_FILE_QCOW2 || - disk->src.format == VIR_STORAGE_FILE_QED) + if (disk->src->format == VIR_STORAGE_FILE_QCOW2 || + disk->src->format == VIR_STORAGE_FILE_QED) size = VIR_ROUND_UP(size, 512); if (virAsprintf(&device, "%s%s", QEMU_DRIVE_HOST_PREFIX, @@ -12026,27 +12026,27 @@ qemuDomainPrepareDiskChainElement(virQEMUDriverPtr driver, /* The easiest way to label a single file with the same * permissions it would have as if part of the disk chain is to * temporarily modify the disk in place. */ - char *origsrc = disk->src.path; - int origformat = disk->src.format; - virStorageSourcePtr origchain = disk->src.backingStore; + char *origsrc = disk->src->path; + int origformat = disk->src->format; + virStorageSourcePtr origchain = disk->src->backingStore; bool origreadonly = disk->readonly; int ret = -1; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - disk->src.path = (char *) file; /* casting away const is safe here */ - disk->src.format = VIR_STORAGE_FILE_RAW; - disk->src.backingStore = NULL; + disk->src->path = (char *) file; /* casting away const is safe here */ + disk->src->format = VIR_STORAGE_FILE_RAW; + disk->src->backingStore = NULL; disk->readonly = mode == VIR_DISK_CHAIN_READ_ONLY; if (mode == VIR_DISK_CHAIN_NO_ACCESS) { if (virSecurityManagerRestoreImageLabel(driver->securityManager, vm->def, disk) < 0) - VIR_WARN("Unable to restore security label on %s", disk->src.path); + VIR_WARN("Unable to restore security label on %s", disk->src->path); if (qemuTeardownDiskCgroup(vm, disk) < 0) VIR_WARN("Failed to teardown cgroup for disk path %s", - disk->src.path); + disk->src->path); if (virDomainLockDiskDetach(driver->lockManager, vm, disk) < 0) - VIR_WARN("Unable to release lock on %s", disk->src.path); + VIR_WARN("Unable to release lock on %s", disk->src->path); } else if (virDomainLockDiskAttach(driver->lockManager, cfg->uri, vm, disk) < 0 || qemuSetupDiskCgroup(vm, disk) < 0 || @@ -12058,9 +12058,9 @@ qemuDomainPrepareDiskChainElement(virQEMUDriverPtr driver, ret = 0; cleanup: - disk->src.path = origsrc; - disk->src.format = origformat; - disk->src.backingStore = origchain; + disk->src->path = origsrc; + disk->src->format = origformat; + disk->src->backingStore = origchain; disk->readonly = origreadonly; virObjectUnref(cfg); return ret; @@ -12202,22 +12202,22 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, NULL))) goto cleanup; - if (defdisk->src.format > 0) { + if (defdisk->src->format > 0) { /* adds cmd line arg: backing_file=/path/to/backing/file,backing_fmd=format */ virCommandAddArgFormat(cmd, "backing_file=%s,backing_fmt=%s", - defdisk->src.path, - virStorageFileFormatTypeToString(defdisk->src.format)); + defdisk->src->path, + virStorageFileFormatTypeToString(defdisk->src->format)); } else { if (!cfg->allowDiskFormatProbing) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown image format of '%s' and " "format probing is disabled"), - defdisk->src.path); + defdisk->src->path); goto cleanup; } /* adds cmd line arg: backing_file=/path/to/backing/file */ - virCommandAddArgFormat(cmd, "backing_file=%s", defdisk->src.path); + virCommandAddArgFormat(cmd, "backing_file=%s", defdisk->src->path); } /* adds cmd line args: /path/to/target/file */ @@ -12240,12 +12240,12 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, defdisk = vm->def->disks[snapdisk->index]; if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { - VIR_FREE(defdisk->src.path); - if (VIR_STRDUP(defdisk->src.path, snapdisk->src->path) < 0) { + VIR_FREE(defdisk->src->path); + if (VIR_STRDUP(defdisk->src->path, snapdisk->src->path) < 0) { /* we cannot rollback here in a sane way */ goto cleanup; } - defdisk->src.format = snapdisk->src->format; + defdisk->src->format = snapdisk->src->format; } } @@ -12360,7 +12360,7 @@ qemuDomainSnapshotCreateActiveInternal(virConnectPtr conn, static int qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk) { - int actualType = virStorageSourceGetActualType(&disk->src); + int actualType = virStorageSourceGetActualType(disk->src); switch ((virStorageType) actualType) { case VIR_STORAGE_TYPE_BLOCK: @@ -12368,7 +12368,7 @@ qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk) return 0; case VIR_STORAGE_TYPE_NETWORK: - switch ((virStorageNetProtocol) disk->src.protocol) { + switch ((virStorageNetProtocol) disk->src->protocol) { case VIR_STORAGE_NET_PROTOCOL_NBD: case VIR_STORAGE_NET_PROTOCOL_RBD: case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: @@ -12383,7 +12383,7 @@ qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk) virReportError(VIR_ERR_INTERNAL_ERROR, _("external inactive snapshots are not supported on " "'network' disks using '%s' protocol"), - virStorageNetProtocolTypeToString(disk->src.protocol)); + virStorageNetProtocolTypeToString(disk->src->protocol)); return -1; } break; @@ -12405,7 +12405,7 @@ qemuDomainSnapshotPrepareDiskExternalBackingInactive(virDomainDiskDefPtr disk) static int qemuDomainSnapshotPrepareDiskExternalBackingActive(virDomainDiskDefPtr disk) { - int actualType = virStorageSourceGetActualType(&disk->src); + int actualType = virStorageSourceGetActualType(disk->src); if (actualType == VIR_STORAGE_TYPE_BLOCK && disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { @@ -12567,7 +12567,7 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn, if (qemuTranslateDiskSourcePool(conn, disk) < 0) return -1; - actualType = virStorageSourceGetActualType(&disk->src); + actualType = virStorageSourceGetActualType(disk->src); switch ((virStorageType) actualType) { case VIR_STORAGE_TYPE_BLOCK: @@ -12575,7 +12575,7 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn, return 0; case VIR_STORAGE_TYPE_NETWORK: - switch ((virStorageNetProtocol) disk->src.protocol) { + switch ((virStorageNetProtocol) disk->src->protocol) { case VIR_STORAGE_NET_PROTOCOL_NBD: case VIR_STORAGE_NET_PROTOCOL_RBD: case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: @@ -12590,7 +12590,7 @@ qemuDomainSnapshotPrepareDiskInternal(virConnectPtr conn, virReportError(VIR_ERR_INTERNAL_ERROR, _("internal inactive snapshots are not supported on " "'network' disks using '%s' protocol"), - virStorageNetProtocolTypeToString(disk->src.protocol)); + virStorageNetProtocolTypeToString(disk->src->protocol)); return -1; } break; @@ -12652,19 +12652,19 @@ qemuDomainSnapshotPrepare(virConnectPtr conn, active) < 0) goto cleanup; - if (dom_disk->src.type == VIR_STORAGE_TYPE_NETWORK && - (dom_disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_SHEEPDOG || - dom_disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD)) { + if (dom_disk->src->type == VIR_STORAGE_TYPE_NETWORK && + (dom_disk->src->protocol == VIR_STORAGE_NET_PROTOCOL_SHEEPDOG || + dom_disk->src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD)) { break; } - if (vm->def->disks[i]->src.format > 0 && - vm->def->disks[i]->src.format != VIR_STORAGE_FILE_QCOW2) { + if (vm->def->disks[i]->src->format > 0 && + vm->def->disks[i]->src->format != VIR_STORAGE_FILE_QCOW2) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("internal snapshot for disk %s unsupported " "for storage type %s"), disk->name, virStorageFileFormatTypeToString( - vm->def->disks[i]->src.format)); + vm->def->disks[i]->src->format)); goto cleanup; } break; @@ -12798,7 +12798,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, * recompute it. Better would be storing the chain ourselves rather than * reprobing, but this requires modifying domain_conf and our XML to fully * track the chain across libvirtd restarts. */ - virStorageSourceClearBackingStore(&disk->src); + virStorageSourceClearBackingStore(disk->src); if (virStorageFileInit(snap->src) < 0) goto cleanup; @@ -12892,37 +12892,37 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, } } - virDomainAuditDisk(vm, disk->src.path, source, "snapshot", ret >= 0); + virDomainAuditDisk(vm, disk->src->path, source, "snapshot", ret >= 0); if (ret < 0) goto cleanup; /* Update vm in place to match changes. */ need_unlink = false; - VIR_FREE(disk->src.path); - virStorageNetHostDefFree(disk->src.nhosts, disk->src.hosts); + VIR_FREE(disk->src->path); + virStorageNetHostDefFree(disk->src->nhosts, disk->src->hosts); - disk->src.path = newsource; - disk->src.format = format; - disk->src.type = snap->src->type; - disk->src.protocol = snap->src->protocol; - disk->src.nhosts = snap->src->nhosts; - disk->src.hosts = newhosts; + disk->src->path = newsource; + disk->src->format = format; + disk->src->type = snap->src->type; + disk->src->protocol = snap->src->protocol; + disk->src->nhosts = snap->src->nhosts; + disk->src->hosts = newhosts; newsource = NULL; newhosts = NULL; if (persistDisk) { - VIR_FREE(persistDisk->src.path); - virStorageNetHostDefFree(persistDisk->src.nhosts, - persistDisk->src.hosts); + VIR_FREE(persistDisk->src->path); + virStorageNetHostDefFree(persistDisk->src->nhosts, + persistDisk->src->hosts); - persistDisk->src.path = persistSource; - persistDisk->src.format = format; - persistDisk->src.type = snap->src->type; - persistDisk->src.protocol = snap->src->protocol; - persistDisk->src.nhosts = snap->src->nhosts; - persistDisk->src.hosts = persistHosts; + persistDisk->src->path = persistSource; + persistDisk->src->format = format; + persistDisk->src->type = snap->src->type; + persistDisk->src->protocol = snap->src->protocol; + persistDisk->src->nhosts = snap->src->nhosts; + persistDisk->src->hosts = persistHosts; persistSource = NULL; persistHosts = NULL; @@ -12956,46 +12956,46 @@ qemuDomainSnapshotUndoSingleDiskActive(virQEMUDriverPtr driver, char *persistSource = NULL; struct stat st; - ignore_value(virStorageFileInit(&disk->src)); + ignore_value(virStorageFileInit(disk->src)); - if (VIR_STRDUP(source, origdisk->src.path) < 0 || + if (VIR_STRDUP(source, origdisk->src->path) < 0 || (persistDisk && VIR_STRDUP(persistSource, source) < 0)) goto cleanup; - qemuDomainPrepareDiskChainElement(driver, vm, disk, disk->src.path, + qemuDomainPrepareDiskChainElement(driver, vm, disk, disk->src->path, VIR_DISK_CHAIN_NO_ACCESS); if (need_unlink && - virStorageFileStat(&disk->src, &st) == 0 && S_ISREG(st.st_mode) && - virStorageFileUnlink(&disk->src) < 0) - VIR_WARN("Unable to remove just-created %s", disk->src.path); + virStorageFileStat(disk->src, &st) == 0 && S_ISREG(st.st_mode) && + virStorageFileUnlink(disk->src) < 0) + VIR_WARN("Unable to remove just-created %s", disk->src->path); /* Update vm in place to match changes. */ - VIR_FREE(disk->src.path); - disk->src.path = source; + VIR_FREE(disk->src->path); + disk->src->path = source; source = NULL; - disk->src.format = origdisk->src.format; - disk->src.type = origdisk->src.type; - disk->src.protocol = origdisk->src.protocol; - virStorageNetHostDefFree(disk->src.nhosts, disk->src.hosts); - disk->src.nhosts = origdisk->src.nhosts; - disk->src.hosts = virStorageNetHostDefCopy(origdisk->src.nhosts, - origdisk->src.hosts); + disk->src->format = origdisk->src->format; + disk->src->type = origdisk->src->type; + disk->src->protocol = origdisk->src->protocol; + virStorageNetHostDefFree(disk->src->nhosts, disk->src->hosts); + disk->src->nhosts = origdisk->src->nhosts; + disk->src->hosts = virStorageNetHostDefCopy(origdisk->src->nhosts, + origdisk->src->hosts); if (persistDisk) { - VIR_FREE(persistDisk->src.path); - persistDisk->src.path = persistSource; + VIR_FREE(persistDisk->src->path); + persistDisk->src->path = persistSource; persistSource = NULL; - persistDisk->src.format = origdisk->src.format; - persistDisk->src.type = origdisk->src.type; - persistDisk->src.protocol = origdisk->src.protocol; - virStorageNetHostDefFree(persistDisk->src.nhosts, - persistDisk->src.hosts); - persistDisk->src.nhosts = origdisk->src.nhosts; - persistDisk->src.hosts = virStorageNetHostDefCopy(origdisk->src.nhosts, - origdisk->src.hosts); + persistDisk->src->format = origdisk->src->format; + persistDisk->src->type = origdisk->src->type; + persistDisk->src->protocol = origdisk->src->protocol; + virStorageNetHostDefFree(persistDisk->src->nhosts, + persistDisk->src->hosts); + persistDisk->src->nhosts = origdisk->src->nhosts; + persistDisk->src->hosts = virStorageNetHostDefCopy(origdisk->src->nhosts, + origdisk->src->hosts); } cleanup: - virStorageFileDeinit(&disk->src); + virStorageFileDeinit(disk->src); VIR_FREE(source); VIR_FREE(persistSource); } @@ -14850,16 +14850,16 @@ qemuDomainBlockPivot(virConnectPtr conn, * label the entire chain. This action is safe even if the * backing chain has already been labeled; but only necessary when * we know for sure that there is a backing chain. */ - oldsrc = disk->src.path; - oldformat = disk->src.format; - oldchain = disk->src.backingStore; - disk->src.path = disk->mirror; - disk->src.format = disk->mirrorFormat; - disk->src.backingStore = NULL; + oldsrc = disk->src->path; + oldformat = disk->src->format; + oldchain = disk->src->backingStore; + disk->src->path = disk->mirror; + disk->src->format = disk->mirrorFormat; + disk->src->backingStore = NULL; if (qemuDomainDetermineDiskChain(driver, vm, disk, false) < 0) { - disk->src.path = oldsrc; - disk->src.format = oldformat; - disk->src.backingStore = oldchain; + disk->src->path = oldsrc; + disk->src->format = oldformat; + disk->src->backingStore = oldchain; goto cleanup; } if (disk->mirrorFormat && disk->mirrorFormat != VIR_STORAGE_FILE_RAW && @@ -14868,9 +14868,9 @@ qemuDomainBlockPivot(virConnectPtr conn, qemuSetupDiskCgroup(vm, disk) < 0 || virSecurityManagerSetImageLabel(driver->securityManager, vm->def, disk) < 0)) { - disk->src.path = oldsrc; - disk->src.format = oldformat; - disk->src.backingStore = oldchain; + disk->src->path = oldsrc; + disk->src->format = oldformat; + disk->src->backingStore = oldchain; goto cleanup; } @@ -14899,10 +14899,10 @@ qemuDomainBlockPivot(virConnectPtr conn, * 'query-block', to see what state we really got left in * before killing the mirroring job? And just as on the * success case, there's security labeling to worry about. */ - disk->src.path = oldsrc; - disk->src.format = oldformat; - virStorageSourceFree(disk->src.backingStore); - disk->src.backingStore = oldchain; + disk->src->path = oldsrc; + disk->src->format = oldformat; + virStorageSourceFree(disk->src->backingStore); + disk->src->backingStore = oldchain; VIR_FREE(disk->mirror); } disk->mirrorFormat = VIR_STORAGE_FILE_NONE; @@ -15008,8 +15008,8 @@ qemuDomainBlockJobImpl(virDomainObjPtr vm, if (base && (virStorageFileParseChainIndex(disk->dst, base, &baseIndex) < 0 || - !(baseSource = virStorageFileChainLookup(&disk->src, - disk->src.backingStore, + !(baseSource = virStorageFileChainLookup(disk->src, + disk->src->backingStore, base, baseIndex, NULL)))) goto endjob; @@ -15046,7 +15046,7 @@ qemuDomainBlockJobImpl(virDomainObjPtr vm, if (!async) { int type = VIR_DOMAIN_BLOCK_JOB_TYPE_PULL; int status = VIR_DOMAIN_BLOCK_JOB_CANCELED; - event = virDomainEventBlockJobNewFromObj(vm, disk->src.path, type, + event = virDomainEventBlockJobNewFromObj(vm, disk->src->path, type, status); } else if (!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC)) { while (1) { @@ -15219,7 +15219,7 @@ qemuDomainBlockCopy(virDomainObjPtr vm, if ((flags & VIR_DOMAIN_BLOCK_REBASE_SHALLOW) && STREQ_NULLABLE(format, "raw") && - disk->src.backingStore->path) { + disk->src->backingStore->path) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("disk '%s' has backing file, so raw shallow copy " "is not possible"), @@ -15255,7 +15255,7 @@ qemuDomainBlockCopy(virDomainObjPtr vm, goto endjob; VIR_FORCE_CLOSE(fd); if (!format) - disk->mirrorFormat = disk->src.format; + disk->mirrorFormat = disk->src->format; } else if (format) { disk->mirrorFormat = virStorageFileFormatTypeFromString(format); if (disk->mirrorFormat <= 0) { @@ -15419,7 +15419,7 @@ qemuDomainBlockCommit(virDomainPtr dom, goto endjob; disk = vm->def->disks[idx]; - if (!disk->src.path) { + if (!disk->src->path) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("disk %s has no source file to be committed"), disk->dst); @@ -15429,10 +15429,10 @@ qemuDomainBlockCommit(virDomainPtr dom, goto endjob; if (!top) - topSource = &disk->src; + topSource = disk->src; else if (virStorageFileParseChainIndex(disk->dst, top, &topIndex) < 0 || - !(topSource = virStorageFileChainLookup(&disk->src, - disk->src.backingStore, + !(topSource = virStorageFileChainLookup(disk->src, + disk->src->backingStore, top, topIndex, &top_parent))) goto endjob; @@ -15447,7 +15447,7 @@ qemuDomainBlockCommit(virDomainPtr dom, if (!base && (flags & VIR_DOMAIN_BLOCK_COMMIT_SHALLOW)) baseSource = topSource->backingStore; else if (virStorageFileParseChainIndex(disk->dst, base, &baseIndex) < 0 || - !(baseSource = virStorageFileChainLookup(&disk->src, topSource, + !(baseSource = virStorageFileChainLookup(disk->src, topSource, base, baseIndex, NULL))) goto endjob; @@ -15470,7 +15470,7 @@ qemuDomainBlockCommit(virDomainPtr dom, clean_access = true; if (qemuDomainPrepareDiskChainElement(driver, vm, disk, baseSource->path, VIR_DISK_CHAIN_READ_WRITE) < 0 || - (top_parent && top_parent != disk->src.path && + (top_parent && top_parent != disk->src->path && qemuDomainPrepareDiskChainElement(driver, vm, disk, top_parent, VIR_DISK_CHAIN_READ_WRITE) < 0)) @@ -15493,7 +15493,7 @@ qemuDomainBlockCommit(virDomainPtr dom, /* Revert access to read-only, if possible. */ qemuDomainPrepareDiskChainElement(driver, vm, disk, baseSource->path, VIR_DISK_CHAIN_READ_ONLY); - if (top_parent && top_parent != disk->src.path) + if (top_parent && top_parent != disk->src->path) qemuDomainPrepareDiskChainElement(driver, vm, disk, top_parent, VIR_DISK_CHAIN_READ_ONLY); diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index d6271fb..26843d2 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1542,8 +1542,8 @@ qemuMigrationIsSafe(virDomainDefPtr def) return false; else if (rc == 1) continue; - } else if (disk->src.type == VIR_STORAGE_TYPE_NETWORK && - disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { + } else if (disk->src->type == VIR_STORAGE_TYPE_NETWORK && + disk->src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { continue; } diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index a83780f..7c5d213 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -421,13 +421,13 @@ qemuProcessGetVolumeQcowPassphrase(virConnectPtr conn, int ret = -1; virStorageEncryptionPtr enc; - if (!disk->src.encryption) { + if (!disk->src->encryption) { virReportError(VIR_ERR_INTERNAL_ERROR, _("disk %s does not have any encryption information"), - disk->src.path); + disk->src->path); return -1; } - enc = disk->src.encryption; + enc = disk->src->encryption; if (!conn) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -2218,7 +2218,7 @@ qemuProcessInitPasswords(virConnectPtr conn, size_t secretLen; const char *alias; - if (!vm->def->disks[i]->src.encryption || + if (!vm->def->disks[i]->src->encryption || !virDomainDiskGetSource(vm->def->disks[i])) continue; diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c index 04dbfbb..8380bba 100644 --- a/src/security/security_selinux.c +++ b/src/security/security_selinux.c @@ -1148,7 +1148,7 @@ virSecuritySELinuxRestoreSecurityImageLabelInt(virSecurityManagerPtr mgr, * be tracked in domain XML, at which point labelskip should be a * per-file attribute instead of a disk attribute. */ if (disk_seclabel && disk_seclabel->labelskip && - !disk->src.backingStore) + !disk->src->backingStore) return 0; /* Don't restore labels on readoly/shared disks, because @@ -1236,7 +1236,7 @@ virSecuritySELinuxSetSecurityFileLabel(virDomainDiskDefPtr disk, if (!disk_seclabel) return -1; disk_seclabel->labelskip = true; - if (VIR_APPEND_ELEMENT(disk->src.seclabels, disk->src.nseclabels, + if (VIR_APPEND_ELEMENT(disk->src->seclabels, disk->src->nseclabels, disk_seclabel) < 0) { virSecurityDeviceLabelDefFree(disk_seclabel); return -1; diff --git a/tests/securityselinuxlabeltest.c b/tests/securityselinuxlabeltest.c index 047356e..88ec35a 100644 --- a/tests/securityselinuxlabeltest.c +++ b/tests/securityselinuxlabeltest.c @@ -169,11 +169,11 @@ testSELinuxLoadDef(const char *testname) goto cleanup; for (i = 0; i < def->ndisks; i++) { - if (def->disks[i]->src.type != VIR_STORAGE_TYPE_FILE && - def->disks[i]->src.type != VIR_STORAGE_TYPE_BLOCK) + if (def->disks[i]->src->type != VIR_STORAGE_TYPE_FILE && + def->disks[i]->src->type != VIR_STORAGE_TYPE_BLOCK) continue; - if (testSELinuxMungePath(&def->disks[i]->src.path) < 0) + if (testSELinuxMungePath(&def->disks[i]->src->path) < 0) goto cleanup; } -- 1.9.0

The current implementation of 'virsh blockcopy' (virDomainBlockRebase) is limited to copying to a local file name. But future patches want to extend it to also copy to network disks. This patch converts over to a virStorageSourcePtr, although it should have no semantic change visible to the user, in anticipation of those future patches being able to use more fields for non-file destinations. * src/conf/domain_conf.h (_virDomainDiskDef): Change type of mirror information. * src/conf/domain_conf.c (virDomainDiskDefParseXML): Localize mirror parsing into new object. (virDomainDiskDefFormat): Adjust clients. * src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse): Likewise. * src/qemu/qemu_driver.c (qemuDomainBlockPivot) (qemuDomainBlockJobImpl, qemuDomainBlockCopy): Likewise. Signed-off-by: Eric Blake <eblake@redhat.com> --- src/conf/domain_conf.c | 50 +++++++++++++++++++++---------------------- src/conf/domain_conf.h | 3 +-- src/qemu/qemu_domain.c | 8 +++---- src/qemu/qemu_driver.c | 58 +++++++++++++++++++++++++++++++------------------- 4 files changed, 66 insertions(+), 53 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 45f2691..57142cb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5202,9 +5202,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, char *ioeventfd = NULL; char *event_idx = NULL; char *copy_on_read = NULL; - char *mirror = NULL; - char *mirrorFormat = NULL; - bool mirroring = false; char *devaddr = NULL; virStorageEncryptionPtr encryption = NULL; char *serial = NULL; @@ -5353,19 +5350,37 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, event_idx = virXMLPropString(cur, "event_idx"); copy_on_read = virXMLPropString(cur, "copy_on_read"); discard = virXMLPropString(cur, "discard"); - } else if (!mirror && xmlStrEqual(cur->name, BAD_CAST "mirror") && + } else if (!def->mirror && + xmlStrEqual(cur->name, BAD_CAST "mirror") && !(flags & VIR_DOMAIN_XML_INACTIVE)) { char *ready; - mirror = virXMLPropString(cur, "file"); - if (!mirror) { + char *mirrorFormat; + + if (VIR_ALLOC(def->mirror) < 0) + goto error; + def->mirror->type = VIR_STORAGE_TYPE_FILE; + def->mirror->path = virXMLPropString(cur, "file"); + if (!def->mirror->path) { virReportError(VIR_ERR_XML_ERROR, "%s", _("mirror requires file name")); goto error; } mirrorFormat = virXMLPropString(cur, "format"); + if (mirrorFormat) { + def->mirror->format = + virStorageFileFormatTypeFromString(mirrorFormat); + if (def->mirror->format <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown mirror format value '%s'"), + mirrorFormat); + VIR_FREE(mirrorFormat); + goto error; + } + VIR_FREE(mirrorFormat); + } ready = virXMLPropString(cur, "ready"); if (ready) { - mirroring = true; + def->mirroring = true; VIR_FREE(ready); } } else if (xmlStrEqual(cur->name, BAD_CAST "auth")) { @@ -5885,9 +5900,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, authUsername = NULL; def->src->driverName = driverName; driverName = NULL; - def->mirror = mirror; - mirror = NULL; - def->mirroring = mirroring; def->src->encryption = encryption; encryption = NULL; def->serial = serial; @@ -5909,16 +5921,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, } } - if (mirrorFormat) { - def->mirrorFormat = virStorageFileFormatTypeFromString(mirrorFormat); - if (def->mirrorFormat <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown mirror format value '%s'"), - driverType); - goto error; - } - } - if (def->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE && virDomainDiskDefAssignAddress(xmlopt, def) < 0) goto error; @@ -5943,8 +5945,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, VIR_FREE(authUsage); VIR_FREE(driverType); VIR_FREE(driverName); - VIR_FREE(mirror); - VIR_FREE(mirrorFormat); VIR_FREE(cachetag); VIR_FREE(error_policy); VIR_FREE(rerror_policy); @@ -15136,10 +15136,10 @@ virDomainDiskDefFormat(virBufferPtr buf, * for live domains, therefore we ignore it on input except for * the internal parse on libvirtd restart. */ if (def->mirror && !(flags & VIR_DOMAIN_XML_INACTIVE)) { - virBufferEscapeString(buf, "<mirror file='%s'", def->mirror); - if (def->mirrorFormat) + virBufferEscapeString(buf, "<mirror file='%s'", def->mirror->path); + if (def->mirror->format) virBufferAsprintf(buf, " format='%s'", - virStorageFileFormatTypeToString(def->mirrorFormat)); + virStorageFileFormatTypeToString(def->mirror->format)); if (def->mirroring) virBufferAddLit(buf, " ready='yes'"); virBufferAddLit(buf, "/>\n"); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index f388865..ca145a6 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -606,8 +606,7 @@ struct _virDomainDiskDef { int tray_status; /* enum virDomainDiskTray */ int removable; /* enum virDomainFeatureState */ - char *mirror; - int mirrorFormat; /* virStorageFileFormat */ + virStorageSourcePtr mirror; bool mirroring; struct { diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 0cc8b9a..4b6de62 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -885,8 +885,8 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, /* default disk format for mirrored drive */ if (disk->mirror && - disk->mirrorFormat == VIR_STORAGE_FILE_NONE) - disk->mirrorFormat = VIR_STORAGE_FILE_AUTO; + disk->mirror->format == VIR_STORAGE_FILE_NONE) + disk->mirror->format = VIR_STORAGE_FILE_AUTO; } else { /* default driver if probing is forbidden */ if (!virDomainDiskGetDriver(disk) && @@ -901,8 +901,8 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, /* default disk format for mirrored drive */ if (disk->mirror && - disk->mirrorFormat == VIR_STORAGE_FILE_NONE) - disk->mirrorFormat = VIR_STORAGE_FILE_RAW; + disk->mirror->format == VIR_STORAGE_FILE_NONE) + disk->mirror->format = VIR_STORAGE_FILE_RAW; } } } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 0f946d1..4a9dee9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14789,13 +14789,22 @@ qemuDomainBlockPivot(virConnectPtr conn, int ret = -1, rc; qemuDomainObjPrivatePtr priv = vm->privateData; virDomainBlockJobInfo info; - const char *format = virStorageFileFormatTypeToString(disk->mirrorFormat); + const char *format = NULL; bool resume = false; char *oldsrc = NULL; int oldformat; virStorageSourcePtr oldchain = NULL; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + if (!disk->mirror) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("pivot of disk '%s' requires an active copy job"), + disk->dst); + goto cleanup; + } + + format = virStorageFileFormatTypeToString(disk->mirror->format); + /* Probe the status, if needed. */ if (!disk->mirroring) { qemuDomainObjEnterMonitor(driver, vm); @@ -14853,8 +14862,8 @@ qemuDomainBlockPivot(virConnectPtr conn, oldsrc = disk->src->path; oldformat = disk->src->format; oldchain = disk->src->backingStore; - disk->src->path = disk->mirror; - disk->src->format = disk->mirrorFormat; + disk->src->path = disk->mirror->path; + disk->src->format = disk->mirror->format; disk->src->backingStore = NULL; if (qemuDomainDetermineDiskChain(driver, vm, disk, false) < 0) { disk->src->path = oldsrc; @@ -14862,7 +14871,7 @@ qemuDomainBlockPivot(virConnectPtr conn, disk->src->backingStore = oldchain; goto cleanup; } - if (disk->mirrorFormat && disk->mirrorFormat != VIR_STORAGE_FILE_RAW && + if (disk->mirror->format && disk->mirror->format != VIR_STORAGE_FILE_RAW && (virDomainLockDiskAttach(driver->lockManager, cfg->uri, vm, disk) < 0 || qemuSetupDiskCgroup(vm, disk) < 0 || @@ -14876,7 +14885,7 @@ qemuDomainBlockPivot(virConnectPtr conn, /* Attempt the pivot. */ qemuDomainObjEnterMonitor(driver, vm); - ret = qemuMonitorDrivePivot(priv->mon, device, disk->mirror, format); + ret = qemuMonitorDrivePivot(priv->mon, device, disk->mirror->path, format); qemuDomainObjExitMonitor(driver, vm); if (ret == 0) { @@ -14889,7 +14898,7 @@ qemuDomainBlockPivot(virConnectPtr conn, * for now, we leak the access to the original. */ VIR_FREE(oldsrc); virStorageSourceFree(oldchain); - disk->mirror = NULL; + disk->mirror->path = NULL; } else { /* On failure, qemu abandons the mirror, and reverts back to * the source disk (RHEL 6.3 has a bug where the revert could @@ -14903,9 +14912,9 @@ qemuDomainBlockPivot(virConnectPtr conn, disk->src->format = oldformat; virStorageSourceFree(disk->src->backingStore); disk->src->backingStore = oldchain; - VIR_FREE(disk->mirror); } - disk->mirrorFormat = VIR_STORAGE_FILE_NONE; + virStorageSourceFree(disk->mirror); + disk->mirror = NULL; disk->mirroring = false; cleanup: @@ -15031,8 +15040,8 @@ qemuDomainBlockJobImpl(virDomainObjPtr vm, if (mode == BLOCK_JOB_ABORT && disk->mirror) { /* XXX We should also revoke security labels and disk lease on * the mirror, and audit that fact, before dropping things. */ - VIR_FREE(disk->mirror); - disk->mirrorFormat = VIR_STORAGE_FILE_NONE; + virStorageSourceFree(disk->mirror); + disk->mirror = NULL; disk->mirroring = false; } @@ -15167,7 +15176,7 @@ qemuDomainBlockCopy(virDomainObjPtr vm, int idx; struct stat st; bool need_unlink = false; - char *mirror = NULL; + virStorageSourcePtr mirror = NULL; virQEMUDriverConfigPtr cfg = NULL; /* Preliminaries: find the disk we are editing, sanity checks */ @@ -15248,6 +15257,9 @@ qemuDomainBlockCopy(virDomainObjPtr vm, goto endjob; } + if (VIR_ALLOC(mirror) < 0) + goto endjob; + if (!(flags & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)) { int fd = qemuOpenFile(driver, vm, dest, O_WRONLY | O_TRUNC | O_CREAT, &need_unlink, NULL); @@ -15255,10 +15267,10 @@ qemuDomainBlockCopy(virDomainObjPtr vm, goto endjob; VIR_FORCE_CLOSE(fd); if (!format) - disk->mirrorFormat = disk->src->format; + disk->mirror->format = disk->src->format; } else if (format) { - disk->mirrorFormat = virStorageFileFormatTypeFromString(format); - if (disk->mirrorFormat <= 0) { + disk->mirror->format = virStorageFileFormatTypeFromString(format); + if (disk->mirror->format <= 0) { virReportError(VIR_ERR_INVALID_ARG, _("unrecognized format '%s'"), format); goto endjob; @@ -15268,12 +15280,12 @@ qemuDomainBlockCopy(virDomainObjPtr vm, * also passed the RAW flag (and format is non-NULL), or it is * safe for us to probe the format from the file that we will * be using. */ - disk->mirrorFormat = virStorageFileProbeFormat(dest, cfg->user, - cfg->group); + disk->mirror->format = virStorageFileProbeFormat(dest, cfg->user, + cfg->group); } - if (!format && disk->mirrorFormat > 0) - format = virStorageFileFormatTypeToString(disk->mirrorFormat); - if (VIR_STRDUP(mirror, dest) < 0) + if (!format && disk->mirror->format > 0) + format = virStorageFileFormatTypeToString(disk->mirror->format); + if (VIR_STRDUP(mirror->path, dest) < 0) goto endjob; if (qemuDomainPrepareDiskChainElement(driver, vm, disk, dest, @@ -15303,9 +15315,11 @@ qemuDomainBlockCopy(virDomainObjPtr vm, endjob: if (need_unlink && unlink(dest)) VIR_WARN("unable to unlink just-created %s", dest); - if (ret < 0 && disk) - disk->mirrorFormat = VIR_STORAGE_FILE_NONE; - VIR_FREE(mirror); + if (ret < 0 && disk) { + virStorageSourceFree(disk->mirror); + disk->mirror = NULL; + } + virStorageSourceFree(mirror); if (!qemuDomainObjEndJob(driver, vm)) vm = NULL; -- 1.9.0

Now that we track a disk mirror as a virStorageSource, we might as well update the XML to theoretically allow any type of mirroring destination (not just a local file). A later patch will also be reusing <mirror> to track the block commit of the top layer of a chain, which is another case where libvirt needs to update the backing chain after the job is finally pivoted, and since backing chains can have network backing files as the destination to commit into, it makes more sense to display that in the XML. TODO: this patch still needs to update formatdomain.html.in to document the new output, as well as provide more justification why we can drop the old output without breaking things (or alternatively, we must continue to provide the old output in parallel with type='file'). * docs/schemas/domaincommon.rng (diskMirror): Alter definition. * src/conf/domain_conf.c (virDomainDiskDefParseXML): Parse two styles of mirror elements. (virDomainDiskDefFormat): Output new style. * tests/qemuxml2argvdata/qemuxml2argv-disk-mirror-old.xml: New file, copied from... * tests/qemuxml2argvdata/qemuxml2argv-disk-mirror.xml: ...here before modernizing. * tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old*: New files. * tests/qemuxml2xmltest.c (mymain): Test both styles. Signed-off-by: Eric Blake <eblake@redhat.com> --- docs/schemas/domaincommon.rng | 29 ++++++--- src/conf/domain_conf.c | 69 ++++++++++++++++------ .../qemuxml2argv-disk-mirror-old.xml | 47 +++++++++++++++ .../qemuxml2argvdata/qemuxml2argv-disk-mirror.xml | 9 ++- .../qemuxml2xmlout-disk-mirror-old-inactive.xml | 41 +++++++++++++ .../qemuxml2xmlout-disk-mirror-old.xml | 52 ++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 7 files changed, 221 insertions(+), 27 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-mirror-old.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old-inactive.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old.xml diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 4249ed5..7de5832 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4172,16 +4172,29 @@ <empty/> </element> </define> + <define name='diskMirror'> <element name='mirror'> - <attribute name='file'> - <ref name='absFilePath'/> - </attribute> - <optional> - <attribute name='format'> - <ref name='storageFormat'/> - </attribute> - </optional> + <choice> + <group> + <attribute name='file'> + <ref name='absFilePath'/> + </attribute> + <optional> + <attribute name='format'> + <ref name='storageFormat'/> + </attribute> + </optional> + </group> + <group> + <interleave> + <ref name="diskSource"/> + <optional> + <ref name="diskFormat"/> + </optional> + </interleave> + </group> + </choice> <optional> <attribute name='ready'> <value>yes</value> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 57142cb..f477c19 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -5218,6 +5218,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, char *vendor = NULL; char *product = NULL; char *discard = NULL; + char *mirrorFormat = NULL; + char *mirrorType = NULL; int expected_secret_usage = -1; int auth_secret_usage = -1; @@ -5354,18 +5356,34 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, xmlStrEqual(cur->name, BAD_CAST "mirror") && !(flags & VIR_DOMAIN_XML_INACTIVE)) { char *ready; - char *mirrorFormat; if (VIR_ALLOC(def->mirror) < 0) goto error; - def->mirror->type = VIR_STORAGE_TYPE_FILE; - def->mirror->path = virXMLPropString(cur, "file"); - if (!def->mirror->path) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("mirror requires file name")); - goto error; + + mirrorType = virXMLPropString(cur, "type"); + if (mirrorType) { + def->mirror->type = virStorageTypeFromString(mirrorType); + if (def->mirror->type <= 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown mirror backing store " + "type '%s'"), mirrorType); + goto cleanup; + } + mirrorFormat = virXPathString("string(./mirror/format/@type)", + ctxt); + } else { + /* For back-compat reasons, we handle a file name + * encoded as attributes, even though we prefer + * modern output in the style of backingStore */ + def->mirror->type = VIR_STORAGE_TYPE_FILE; + def->mirror->path = virXMLPropString(cur, "file"); + if (!def->mirror->path) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("mirror requires file name")); + goto error; + } + mirrorFormat = virXMLPropString(cur, "format"); } - mirrorFormat = virXMLPropString(cur, "format"); if (mirrorFormat) { def->mirror->format = virStorageFileFormatTypeFromString(mirrorFormat); @@ -5373,10 +5391,19 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown mirror format value '%s'"), mirrorFormat); - VIR_FREE(mirrorFormat); goto error; } - VIR_FREE(mirrorFormat); + } + if (mirrorType) { + xmlNodePtr mirrorNode; + + if (!(mirrorNode = virXPathNode("./mirror/source", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("mirror requires source element")); + goto error; + } + if (virDomainDiskSourceParse(mirrorNode, def->mirror) < 0) + goto error; } ready = virXMLPropString(cur, "ready"); if (ready) { @@ -5962,6 +5989,8 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, VIR_FREE(wwn); VIR_FREE(vendor); VIR_FREE(product); + VIR_FREE(mirrorType); + VIR_FREE(mirrorFormat); ctxt->node = save_ctxt; return def; @@ -15134,15 +15163,21 @@ virDomainDiskDefFormat(virBufferPtr buf, /* For now, mirroring is currently output-only: we only output it * for live domains, therefore we ignore it on input except for - * the internal parse on libvirtd restart. */ + * the internal parse on libvirtd restart. We only output the + * new style similar to backingStore, even though the parser + * code still accepts old style across libvirtd upgrades. */ if (def->mirror && !(flags & VIR_DOMAIN_XML_INACTIVE)) { - virBufferEscapeString(buf, "<mirror file='%s'", def->mirror->path); + virBufferAsprintf(buf, "<mirror type='%s'%s>\n", + virStorageTypeToString(def->mirror->type), + def->mirroring ? " ready='yes'" : ""); + virBufferAdjustIndent(buf, 2); + if (virDomainDiskSourceFormat(buf, def->mirror, 0, 0) < 0) + return -1; if (def->mirror->format) - virBufferAsprintf(buf, " format='%s'", - virStorageFileFormatTypeToString(def->mirror->format)); - if (def->mirroring) - virBufferAddLit(buf, " ready='yes'"); - virBufferAddLit(buf, "/>\n"); + virBufferEscapeString(buf, "<format type='%s'/>\n", + virStorageFileFormatTypeToString(def->mirror->format)); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "</mirror>\n"); } virBufferAsprintf(buf, "<target dev='%s' bus='%s'", diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-mirror-old.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-mirror-old.xml new file mode 100644 index 0000000..faa0b8c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-mirror-old.xml @@ -0,0 +1,47 @@ +<domain type='qemu' id='1'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <source dev='/dev/HostVG/QEMUGuest1'/> + <backingStore/> + <mirror file='/dev/HostVG/QEMUGuest1Copy' ready='yes'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <disk type='block' device='cdrom'> + <source dev='/dev/HostVG/QEMUGuest2'/> + <backingStore/> + <target dev='hdc' bus='ide'/> + <readonly/> + <address type='drive' controller='0' bus='1' target='0' unit='0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/data.img'/> + <backingStore/> + <mirror file='/tmp/copy.img' format='qcow2'/> + <target dev='vda' bus='virtio'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/logs.img'/> + <backingStore/> + <target dev='vdb' bus='virtio'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-mirror.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-mirror.xml index faa0b8c..338e3c3 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-disk-mirror.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-mirror.xml @@ -17,7 +17,9 @@ <disk type='block' device='disk'> <source dev='/dev/HostVG/QEMUGuest1'/> <backingStore/> - <mirror file='/dev/HostVG/QEMUGuest1Copy' ready='yes'/> + <mirror type='file' ready='yes'> + <source file='/dev/HostVG/QEMUGuest1Copy'/> + </mirror> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> @@ -31,7 +33,10 @@ <disk type='file' device='disk'> <source file='/tmp/data.img'/> <backingStore/> - <mirror file='/tmp/copy.img' format='qcow2'/> + <mirror type='file'> + <source file='/tmp/copy.img'/> + <format type='qcow2'/> + </mirror> <target dev='vda' bus='virtio'/> </disk> <disk type='file' device='disk'> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old-inactive.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old-inactive.xml new file mode 100644 index 0000000..b3d8c59 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old-inactive.xml @@ -0,0 +1,41 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <disk type='block' device='cdrom'> + <source dev='/dev/HostVG/QEMUGuest2'/> + <target dev='hdc' bus='ide'/> + <readonly/> + <address type='drive' controller='0' bus='1' target='0' unit='0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/data.img'/> + <target dev='vda' bus='virtio'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/logs.img'/> + <target dev='vdb' bus='virtio'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old.xml new file mode 100644 index 0000000..338e3c3 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-mirror-old.xml @@ -0,0 +1,52 @@ +<domain type='qemu' id='1'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <source dev='/dev/HostVG/QEMUGuest1'/> + <backingStore/> + <mirror type='file' ready='yes'> + <source file='/dev/HostVG/QEMUGuest1Copy'/> + </mirror> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <disk type='block' device='cdrom'> + <source dev='/dev/HostVG/QEMUGuest2'/> + <backingStore/> + <target dev='hdc' bus='ide'/> + <readonly/> + <address type='drive' controller='0' bus='1' target='0' unit='0'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/data.img'/> + <backingStore/> + <mirror type='file'> + <source file='/tmp/copy.img'/> + <format type='qcow2'/> + </mirror> + <target dev='vda' bus='virtio'/> + </disk> + <disk type='file' device='disk'> + <source file='/tmp/logs.img'/> + <backingStore/> + <target dev='vdb' bus='virtio'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index da528da..200d50f 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -224,6 +224,7 @@ mymain(void) DO_TEST("disk-scsi-virtio-scsi"); DO_TEST("disk-virtio-scsi-num_queues"); DO_TEST("disk-scsi-megasas"); + DO_TEST_DIFFERENT("disk-mirror-old"); DO_TEST_FULL("disk-mirror", false, WHEN_ACTIVE); DO_TEST_FULL("disk-mirror", true, WHEN_INACTIVE); DO_TEST("graphics-listen-network"); -- 1.9.0

On Wed, May 21, 2014 at 22:50:43 -0600, Eric Blake wrote:
I'm about to reuse the <mirror> sub-element of <disk> for my pending series on active block commit, but to do that, I wanted to get some refactoring out of the way first. Patches 1-4 are pretty straightforward, and 5 may be controversial (I'm sending it now, even though it still needs more work, to make sure I'm not doing something bad). I'm aware that this will probably cause some rebase pain for Peter's work with gluster, but at the same time, it will ease some of the work that Benoit wants for introducing quorums.
I think we all agree that we need to do this refactoring. However, the timing is not very good given that Peter already has lots of patches mostly ready to be submitted to the list while Benoit's work on quorums is only in its XML design phase. In other words, we should first wait for Peter's patches and Benoit may in the mean time work on his patches which will count with your refactoring. But pushing this refactoring now is not going to help anyone. In other words, NACK to patches 1-3 until patches for gluster snapshots and relative backing chains land in. Jirka
participants (2)
-
Eric Blake
-
Jiri Denemark