提交 0ea4fd7a 编写于 作者: P Peter Krempa

qemu: Kill qemuDiskPathToAlias

The function has terrible semantics. Split it into two functions.
上级 9f7d9891
...@@ -484,3 +484,19 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) ...@@ -484,3 +484,19 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
return 0; return 0;
} }
char *
qemuAliasFromDisk(const virDomainDiskDef *disk)
{
char *ret;
if (!disk->info.alias) {
virReportError(VIR_ERR_INVALID_ARG, "%s", _("disk does not have an alias"));
return NULL;
}
ignore_value(virAsprintf(&ret, "drive-%s", disk->info.alias));
return ret;
}
...@@ -61,4 +61,6 @@ int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps); ...@@ -61,4 +61,6 @@ int qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps);
int qemuDomainDeviceAliasIndex(const virDomainDeviceInfo *info, int qemuDomainDeviceAliasIndex(const virDomainDeviceInfo *info,
const char *prefix); const char *prefix);
char *qemuAliasFromDisk(const virDomainDiskDef *disk);
#endif /* __QEMU_ALIAS_H__*/ #endif /* __QEMU_ALIAS_H__*/
...@@ -4558,3 +4558,19 @@ qemuDomainNetVLAN(virDomainNetDefPtr def) ...@@ -4558,3 +4558,19 @@ qemuDomainNetVLAN(virDomainNetDefPtr def)
{ {
return qemuDomainDeviceAliasIndex(&def->info, "net"); return qemuDomainDeviceAliasIndex(&def->info, "net");
} }
virDomainDiskDefPtr
qemuDomainDiskByName(virDomainDefPtr def,
const char *name)
{
virDomainDiskDefPtr ret;
if (!(ret = virDomainDiskByName(def, name, true))) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("No device found for specified path"));
return NULL;
}
return ret;
}
...@@ -549,4 +549,7 @@ int qemuDomainSetPrivatePaths(char **domainLibDir, ...@@ -549,4 +549,7 @@ int qemuDomainSetPrivatePaths(char **domainLibDir,
const char *confChannelDir, const char *confChannelDir,
const char *domainName, const char *domainName,
int domainId); int domainId);
virDomainDiskDefPtr qemuDomainDiskByName(virDomainDefPtr def, const char *name);
#endif /* __QEMU_DOMAIN_H__ */ #endif /* __QEMU_DOMAIN_H__ */
...@@ -16164,33 +16164,6 @@ qemuDomainOpenChannel(virDomainPtr dom, ...@@ -16164,33 +16164,6 @@ qemuDomainOpenChannel(virDomainPtr dom,
return ret; return ret;
} }
static char *
qemuDiskPathToAlias(virDomainObjPtr vm, const char *path, int *idxret)
{
int idx;
char *ret = NULL;
virDomainDiskDefPtr disk;
idx = virDomainDiskIndexByName(vm->def, path, true);
if (idx < 0)
goto cleanup;
disk = vm->def->disks[idx];
if (idxret)
*idxret = idx;
if (virDomainDiskGetSource(disk)) {
if (virAsprintf(&ret, "drive-%s", disk->info.alias) < 0)
return NULL;
}
cleanup:
if (!ret) {
virReportError(VIR_ERR_INVALID_ARG,
"%s", _("No device found for specified path"));
}
return ret;
}
/* Called while holding the VM job lock, to implement a block job /* Called while holding the VM job lock, to implement a block job
* abort with pivot; this updates the VM definition as appropriate, on * abort with pivot; this updates the VM definition as appropriate, on
...@@ -16312,7 +16285,6 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver, ...@@ -16312,7 +16285,6 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = vm->privateData; qemuDomainObjPrivatePtr priv = vm->privateData;
char *device = NULL; char *device = NULL;
bool modern; bool modern;
int idx;
virDomainDiskDefPtr disk; virDomainDiskDefPtr disk;
virStorageSourcePtr baseSource = NULL; virStorageSourcePtr baseSource = NULL;
unsigned int baseIndex = 0; unsigned int baseIndex = 0;
...@@ -16356,9 +16328,11 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver, ...@@ -16356,9 +16328,11 @@ qemuDomainBlockPullCommon(virQEMUDriverPtr driver,
} }
} }
if (!(device = qemuDiskPathToAlias(vm, path, &idx))) if (!(disk = qemuDomainDiskByName(vm->def, path)))
goto endjob;
if (!(device = qemuAliasFromDisk(disk)))
goto endjob; goto endjob;
disk = vm->def->disks[idx];
if (qemuDomainDiskBlockJobIsActive(disk)) if (qemuDomainDiskBlockJobIsActive(disk))
goto endjob; goto endjob;
...@@ -16439,7 +16413,6 @@ qemuDomainBlockJobAbort(virDomainPtr dom, ...@@ -16439,7 +16413,6 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
virDomainDiskDefPtr disk = NULL; virDomainDiskDefPtr disk = NULL;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
bool save = false; bool save = false;
int idx;
bool modern; bool modern;
bool pivot = !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT); bool pivot = !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_PIVOT);
bool async = !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC); bool async = !!(flags & VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC);
...@@ -16467,9 +16440,11 @@ qemuDomainBlockJobAbort(virDomainPtr dom, ...@@ -16467,9 +16440,11 @@ qemuDomainBlockJobAbort(virDomainPtr dom,
if (qemuDomainSupportsBlockJobs(vm, &modern) < 0) if (qemuDomainSupportsBlockJobs(vm, &modern) < 0)
goto endjob; goto endjob;
if (!(device = qemuDiskPathToAlias(vm, path, &idx))) if (!(disk = qemuDomainDiskByName(vm->def, path)))
goto endjob;
if (!(device = qemuAliasFromDisk(disk)))
goto endjob; goto endjob;
disk = vm->def->disks[idx];
if (disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_NONE && if (disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_NONE &&
disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_READY) { disk->mirrorState != VIR_DOMAIN_DISK_MIRROR_STATE_READY) {
...@@ -16650,6 +16625,7 @@ qemuDomainBlockJobSetSpeed(virDomainPtr dom, ...@@ -16650,6 +16625,7 @@ qemuDomainBlockJobSetSpeed(virDomainPtr dom,
unsigned int flags) unsigned int flags)
{ {
virQEMUDriverPtr driver = dom->conn->privateData; virQEMUDriverPtr driver = dom->conn->privateData;
virDomainDiskDefPtr disk;
int ret = -1; int ret = -1;
virDomainObjPtr vm; virDomainObjPtr vm;
bool modern; bool modern;
...@@ -16687,7 +16663,10 @@ qemuDomainBlockJobSetSpeed(virDomainPtr dom, ...@@ -16687,7 +16663,10 @@ qemuDomainBlockJobSetSpeed(virDomainPtr dom,
if (qemuDomainSupportsBlockJobs(vm, &modern) < 0) if (qemuDomainSupportsBlockJobs(vm, &modern) < 0)
goto endjob; goto endjob;
if (!(device = qemuDiskPathToAlias(vm, path, NULL))) if (!(disk = qemuDomainDiskByName(vm->def, path)))
goto endjob;
if (!(device = qemuAliasFromDisk(disk)))
goto endjob; goto endjob;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
...@@ -16726,7 +16705,6 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, ...@@ -16726,7 +16705,6 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
char *device = NULL; char *device = NULL;
virDomainDiskDefPtr disk = NULL; virDomainDiskDefPtr disk = NULL;
int ret = -1; int ret = -1;
int idx;
struct stat st; struct stat st;
bool need_unlink = false; bool need_unlink = false;
virQEMUDriverConfigPtr cfg = NULL; virQEMUDriverConfigPtr cfg = NULL;
...@@ -16749,10 +16727,12 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, ...@@ -16749,10 +16727,12 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
goto endjob; goto endjob;
} }
device = qemuDiskPathToAlias(vm, path, &idx); if (!(disk = qemuDomainDiskByName(vm->def, path)))
if (!device)
goto endjob; goto endjob;
disk = vm->def->disks[idx];
if (!(device = qemuAliasFromDisk(disk)))
goto endjob;
if (qemuDomainDiskBlockJobIsActive(disk)) if (qemuDomainDiskBlockJobIsActive(disk))
goto endjob; goto endjob;
...@@ -17083,7 +17063,6 @@ qemuDomainBlockCommit(virDomainPtr dom, ...@@ -17083,7 +17063,6 @@ qemuDomainBlockCommit(virDomainPtr dom,
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
char *device = NULL; char *device = NULL;
int ret = -1; int ret = -1;
int idx;
virDomainDiskDefPtr disk = NULL; virDomainDiskDefPtr disk = NULL;
virStorageSourcePtr topSource; virStorageSourcePtr topSource;
unsigned int topIndex = 0; unsigned int topIndex = 0;
...@@ -17138,10 +17117,11 @@ qemuDomainBlockCommit(virDomainPtr dom, ...@@ -17138,10 +17117,11 @@ qemuDomainBlockCommit(virDomainPtr dom,
speed <<= 20; speed <<= 20;
} }
device = qemuDiskPathToAlias(vm, path, &idx); if (!(disk = qemuDomainDiskByName(vm->def, path)))
if (!device) goto endjob;
if (!(device = qemuAliasFromDisk(disk)))
goto endjob; goto endjob;
disk = vm->def->disks[idx];
if (!disk->src->path) { if (!disk->src->path) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
...@@ -17458,7 +17438,7 @@ qemuDomainOpenGraphicsFD(virDomainPtr dom, ...@@ -17458,7 +17438,7 @@ qemuDomainOpenGraphicsFD(virDomainPtr dom,
static int static int
qemuDomainSetBlockIoTune(virDomainPtr dom, qemuDomainSetBlockIoTune(virDomainPtr dom,
const char *disk, const char *path,
virTypedParameterPtr params, virTypedParameterPtr params,
int nparams, int nparams,
unsigned int flags) unsigned int flags)
...@@ -17472,8 +17452,8 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, ...@@ -17472,8 +17452,8 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
char *device = NULL; char *device = NULL;
int ret = -1; int ret = -1;
size_t i; size_t i;
int idx = -1;
virDomainDiskDefPtr conf_disk = NULL; virDomainDiskDefPtr conf_disk = NULL;
virDomainDiskDefPtr disk;
bool set_bytes = false; bool set_bytes = false;
bool set_iops = false; bool set_iops = false;
bool set_bytes_max = false; bool set_bytes_max = false;
...@@ -17542,7 +17522,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, ...@@ -17542,7 +17522,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
goto endjob; goto endjob;
if (virTypedParamsAddString(&eventParams, &eventNparams, &eventMaxparams, if (virTypedParamsAddString(&eventParams, &eventNparams, &eventMaxparams,
VIR_DOMAIN_TUNABLE_BLKDEV_DISK, disk) < 0) VIR_DOMAIN_TUNABLE_BLKDEV_DISK, path) < 0)
goto endjob; goto endjob;
for (i = 0; i < nparams; i++) { for (i = 0; i < nparams; i++) {
...@@ -17707,10 +17687,10 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, ...@@ -17707,10 +17687,10 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
} }
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
if (!(conf_disk = virDomainDiskByName(persistentDef, disk, true))) { if (!(conf_disk = virDomainDiskByName(persistentDef, path, true))) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("missing persistent configuration for disk '%s'"), _("missing persistent configuration for disk '%s'"),
disk); path);
goto endjob; goto endjob;
} }
} }
...@@ -17733,13 +17713,16 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, ...@@ -17733,13 +17713,16 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
goto endjob; goto endjob;
} }
if (!(device = qemuDiskPathToAlias(vm, disk, &idx))) if (!(disk = qemuDomainDiskByName(vm->def, path)))
goto endjob;
if (!(device = qemuAliasFromDisk(disk)))
goto endjob; goto endjob;
/* If the user didn't specify bytes limits, inherit previous /* If the user didn't specify bytes limits, inherit previous
* values; likewise if the user didn't specify iops * values; likewise if the user didn't specify iops
* limits. */ * limits. */
oldinfo = &vm->def->disks[idx]->blkdeviotune; oldinfo = &disk->blkdeviotune;
if (!set_bytes) { if (!set_bytes) {
info.total_bytes_sec = oldinfo->total_bytes_sec; info.total_bytes_sec = oldinfo->total_bytes_sec;
info.read_bytes_sec = oldinfo->read_bytes_sec; info.read_bytes_sec = oldinfo->read_bytes_sec;
...@@ -17769,7 +17752,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, ...@@ -17769,7 +17752,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
ret = -1; ret = -1;
if (ret < 0) if (ret < 0)
goto endjob; goto endjob;
vm->def->disks[idx]->blkdeviotune = info; disk->blkdeviotune = info;
ret = virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps); ret = virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps);
if (ret < 0) if (ret < 0)
...@@ -17816,11 +17799,12 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, ...@@ -17816,11 +17799,12 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
static int static int
qemuDomainGetBlockIoTune(virDomainPtr dom, qemuDomainGetBlockIoTune(virDomainPtr dom,
const char *disk, const char *path,
virTypedParameterPtr params, virTypedParameterPtr params,
int *nparams, int *nparams,
unsigned int flags) unsigned int flags)
{ {
virDomainDiskDefPtr disk;
virQEMUDriverPtr driver = dom->conn->privateData; virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm = NULL; virDomainObjPtr vm = NULL;
qemuDomainObjPrivatePtr priv = NULL; qemuDomainObjPrivatePtr priv = NULL;
...@@ -17880,8 +17864,10 @@ qemuDomainGetBlockIoTune(virDomainPtr dom, ...@@ -17880,8 +17864,10 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
} }
if (flags & VIR_DOMAIN_AFFECT_LIVE) { if (flags & VIR_DOMAIN_AFFECT_LIVE) {
device = qemuDiskPathToAlias(vm, disk, NULL); if (!(disk = qemuDomainDiskByName(vm->def, path)))
if (!device) goto endjob;
if (!(device = qemuAliasFromDisk(disk)))
goto endjob; goto endjob;
qemuDomainObjEnterMonitor(driver, vm); qemuDomainObjEnterMonitor(driver, vm);
ret = qemuMonitorGetBlockIoThrottle(priv->mon, device, &reply, supportMaxOptions); ret = qemuMonitorGetBlockIoThrottle(priv->mon, device, &reply, supportMaxOptions);
...@@ -17892,14 +17878,13 @@ qemuDomainGetBlockIoTune(virDomainPtr dom, ...@@ -17892,14 +17878,13 @@ qemuDomainGetBlockIoTune(virDomainPtr dom,
} }
if (flags & VIR_DOMAIN_AFFECT_CONFIG) { if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
virDomainDiskDefPtr diskDef; if (!(disk = virDomainDiskByName(persistentDef, path, true))) {
if (!(diskDef = virDomainDiskByName(persistentDef, disk, true))) {
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("disk '%s' was not found in the domain config"), _("disk '%s' was not found in the domain config"),
disk); path);
goto endjob; goto endjob;
} }
reply = diskDef->blkdeviotune; reply = disk->blkdeviotune;
} }
for (i = 0; i < QEMU_NB_BLOCK_IO_TUNE_PARAM_MAX && i < *nparams; i++) { for (i = 0; i < QEMU_NB_BLOCK_IO_TUNE_PARAM_MAX && i < *nparams; i++) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册