diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d94308e5b3..1c162603e5 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2230,6 +2230,31 @@ qemuBuildBlockStorageSourceAttachDataCommandline(virCommandPtr cmd, } +static int +qemuBuildDiskSourceCommandLine(virCommandPtr cmd, + virDomainDiskDefPtr disk, + virQEMUCapsPtr qemuCaps, + bool driveBoot) +{ + qemuBlockStorageSourceAttachDataPtr data = NULL; + int ret = -1; + + if (!(data = qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps, + driveBoot))) + return -1; + + if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, data, qemuCaps) < 0 || + qemuBuildBlockStorageSourceAttachDataCommandline(cmd, data) < 0) + goto cleanup; + + ret = 0; + + cleanup: + qemuBlockStorageSourceAttachDataFree(data); + return ret; +} + + static int qemuBuildDiskCommandLine(virCommandPtr cmd, const virDomainDef *def, @@ -2238,21 +2263,11 @@ qemuBuildDiskCommandLine(virCommandPtr cmd, unsigned int bootindex, bool driveBoot) { - qemuBlockStorageSourceAttachDataPtr data = NULL; char *optstr; - if (!(data = qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps, - driveBoot))) + if (qemuBuildDiskSourceCommandLine(cmd, disk, qemuCaps, driveBoot) < 0) return -1; - if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, data, qemuCaps) < 0 || - qemuBuildBlockStorageSourceAttachDataCommandline(cmd, data) < 0) { - qemuBlockStorageSourceAttachDataFree(data); - return -1; - } - - qemuBlockStorageSourceAttachDataFree(data); - if (!qemuDiskBusNeedsDriveArg(disk->bus)) { if (disk->bus == VIR_DOMAIN_DISK_BUS_FDC) { if (qemuBuildFloppyCommandLineOptions(cmd, def, disk,