mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-04-01 20:05:19 +00:00
qemu: Translate the pool disk source earlier
To support "shareable" for volume type disk, we have to translate the source before trying to add the shared disk entry. To achieve the goal, this moves the helper qemuTranslateDiskSourcePool into src/qemu/qemu_conf.c, and introduce an internal only member (voltype) for struct _virDomainDiskSourcePoolDef, to record the underlying volume type for use when building the drive string. Later patch will support "shareable" volume type disk.
This commit is contained in:
parent
664270b849
commit
60b78b33e1
@ -611,6 +611,7 @@ typedef struct _virDomainDiskSourcePoolDef virDomainDiskSourcePoolDef;
|
||||
struct _virDomainDiskSourcePoolDef {
|
||||
char *pool; /* pool name */
|
||||
char *volume; /* volume name */
|
||||
int voltype; /* enum virStorageVolType, internal only */
|
||||
};
|
||||
typedef virDomainDiskSourcePoolDef *virDomainDiskSourcePoolDefPtr;
|
||||
|
||||
|
@ -2681,56 +2681,6 @@ qemuBuildNBDString(virConnectPtr conn, virDomainDiskDefPtr disk, virBufferPtr op
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
qemuTranslateDiskSourcePool(virConnectPtr conn,
|
||||
virDomainDiskDefPtr def,
|
||||
int *voltype)
|
||||
{
|
||||
virStoragePoolPtr pool = NULL;
|
||||
virStorageVolPtr vol = NULL;
|
||||
virStorageVolInfo info;
|
||||
int ret = -1;
|
||||
|
||||
if (def->type != VIR_DOMAIN_DISK_TYPE_VOLUME)
|
||||
return 0;
|
||||
|
||||
if (!(pool = virStoragePoolLookupByName(conn, def->srcpool->pool)))
|
||||
return -1;
|
||||
|
||||
if (!(vol = virStorageVolLookupByName(pool, def->srcpool->volume)))
|
||||
goto cleanup;
|
||||
|
||||
if (virStorageVolGetInfo(vol, &info) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (def->startupPolicy &&
|
||||
info.type != VIR_STORAGE_VOL_FILE) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("'startupPolicy' is only valid for 'file' type volume"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
switch (info.type) {
|
||||
case VIR_STORAGE_VOL_FILE:
|
||||
case VIR_STORAGE_VOL_BLOCK:
|
||||
case VIR_STORAGE_VOL_DIR:
|
||||
if (!(def->src = virStorageVolGetPath(vol)))
|
||||
goto cleanup;
|
||||
break;
|
||||
case VIR_STORAGE_VOL_NETWORK:
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Using network volume as disk source is not supported"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
*voltype = info.type;
|
||||
ret = 0;
|
||||
cleanup:
|
||||
virStoragePoolFree(pool);
|
||||
virStorageVolFree(vol);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *
|
||||
qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
virDomainDiskDefPtr disk,
|
||||
@ -2743,7 +2693,6 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
virDomainDiskGeometryTransTypeToString(disk->geometry.trans);
|
||||
int idx = virDiskNameToIndex(disk->dst);
|
||||
int busid = -1, unitid = -1;
|
||||
int voltype = -1;
|
||||
|
||||
if (idx < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
@ -2751,9 +2700,6 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (qemuTranslateDiskSourcePool(conn, disk, &voltype) < 0)
|
||||
goto error;
|
||||
|
||||
switch (disk->bus) {
|
||||
case VIR_DOMAIN_DISK_BUS_SCSI:
|
||||
if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
|
||||
@ -2889,7 +2835,7 @@ qemuBuildDriveStr(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||
break;
|
||||
}
|
||||
} else if (disk->type == VIR_DOMAIN_DISK_TYPE_VOLUME) {
|
||||
switch (voltype) {
|
||||
switch (disk->srcpool->voltype) {
|
||||
case VIR_STORAGE_VOL_DIR:
|
||||
if (!disk->readonly) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
|
@ -237,5 +237,4 @@ qemuParseKeywords(const char *str,
|
||||
char ***retvalues,
|
||||
int allowEmptyValue);
|
||||
|
||||
|
||||
#endif /* __QEMU_COMMAND_H__*/
|
||||
|
@ -1222,3 +1222,55 @@ int qemuDriverAllocateID(virQEMUDriverPtr driver)
|
||||
{
|
||||
return virAtomicIntInc(&driver->nextvmid);
|
||||
}
|
||||
|
||||
int
|
||||
qemuTranslateDiskSourcePool(virConnectPtr conn,
|
||||
virDomainDiskDefPtr def)
|
||||
{
|
||||
virStoragePoolPtr pool = NULL;
|
||||
virStorageVolPtr vol = NULL;
|
||||
virStorageVolInfo info;
|
||||
int ret = -1;
|
||||
|
||||
if (def->type != VIR_DOMAIN_DISK_TYPE_VOLUME)
|
||||
return 0;
|
||||
|
||||
if (!def->srcpool)
|
||||
return 0;
|
||||
|
||||
if (!(pool = virStoragePoolLookupByName(conn, def->srcpool->pool)))
|
||||
return -1;
|
||||
|
||||
if (!(vol = virStorageVolLookupByName(pool, def->srcpool->volume)))
|
||||
goto cleanup;
|
||||
|
||||
if (virStorageVolGetInfo(vol, &info) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (def->startupPolicy &&
|
||||
info.type != VIR_STORAGE_VOL_FILE) {
|
||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||
_("'startupPolicy' is only valid for 'file' type volume"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
switch (info.type) {
|
||||
case VIR_STORAGE_VOL_FILE:
|
||||
case VIR_STORAGE_VOL_BLOCK:
|
||||
case VIR_STORAGE_VOL_DIR:
|
||||
if (!(def->src = virStorageVolGetPath(vol)))
|
||||
goto cleanup;
|
||||
break;
|
||||
case VIR_STORAGE_VOL_NETWORK:
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
_("Using network volume as disk source is not supported"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
def->srcpool->voltype = info.type;
|
||||
ret = 0;
|
||||
cleanup:
|
||||
virStoragePoolFree(pool);
|
||||
virStorageVolFree(vol);
|
||||
return ret;
|
||||
}
|
||||
|
@ -303,5 +303,7 @@ void qemuSharedDiskEntryFree(void *payload, const void *name)
|
||||
int qemuDriverAllocateID(virQEMUDriverPtr driver);
|
||||
virDomainXMLOptionPtr virQEMUDriverCreateXMLConf(virQEMUDriverPtr driver);
|
||||
|
||||
int qemuTranslateDiskSourcePool(virConnectPtr conn,
|
||||
virDomainDiskDefPtr def);
|
||||
|
||||
#endif /* __QEMUD_CONF_H */
|
||||
|
@ -5738,6 +5738,9 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (qemuTranslateDiskSourcePool(conn, disk) < 0)
|
||||
goto end;
|
||||
|
||||
if (qemuAddSharedDisk(driver, disk, vm->def->name) < 0)
|
||||
goto end;
|
||||
|
||||
@ -6007,7 +6010,8 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
|
||||
}
|
||||
|
||||
static int
|
||||
qemuDomainChangeDiskMediaLive(virDomainObjPtr vm,
|
||||
qemuDomainChangeDiskMediaLive(virConnectPtr conn,
|
||||
virDomainObjPtr vm,
|
||||
virDomainDeviceDefPtr dev,
|
||||
virQEMUDriverPtr driver,
|
||||
bool force)
|
||||
@ -6020,6 +6024,9 @@ qemuDomainChangeDiskMediaLive(virDomainObjPtr vm,
|
||||
virCapsPtr caps = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (qemuTranslateDiskSourcePool(conn, disk) < 0)
|
||||
goto end;
|
||||
|
||||
if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
|
||||
goto end;
|
||||
|
||||
@ -6099,7 +6106,8 @@ end:
|
||||
}
|
||||
|
||||
static int
|
||||
qemuDomainUpdateDeviceLive(virDomainObjPtr vm,
|
||||
qemuDomainUpdateDeviceLive(virConnectPtr conn,
|
||||
virDomainObjPtr vm,
|
||||
virDomainDeviceDefPtr dev,
|
||||
virDomainPtr dom,
|
||||
bool force)
|
||||
@ -6109,7 +6117,7 @@ qemuDomainUpdateDeviceLive(virDomainObjPtr vm,
|
||||
|
||||
switch (dev->type) {
|
||||
case VIR_DOMAIN_DEVICE_DISK:
|
||||
ret = qemuDomainChangeDiskMediaLive(vm, dev, driver, force);
|
||||
ret = qemuDomainChangeDiskMediaLive(conn, vm, dev, driver, force);
|
||||
break;
|
||||
case VIR_DOMAIN_DEVICE_GRAPHICS:
|
||||
ret = qemuDomainChangeGraphics(driver, vm, dev->data.graphics);
|
||||
@ -6522,7 +6530,7 @@ qemuDomainModifyDeviceFlags(virDomainPtr dom, const char *xml,
|
||||
ret = qemuDomainDetachDeviceLive(vm, dev_copy, dom);
|
||||
break;
|
||||
case QEMU_DEVICE_UPDATE:
|
||||
ret = qemuDomainUpdateDeviceLive(vm, dev_copy, dom, force);
|
||||
ret = qemuDomainUpdateDeviceLive(dom->conn, vm, dev_copy, dom, force);
|
||||
break;
|
||||
default:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
|
@ -3008,6 +3008,8 @@ qemuProcessReconnect(void *opaque)
|
||||
* qemu_driver->sharedDisks.
|
||||
*/
|
||||
for (i = 0; i < obj->def->ndisks; i++) {
|
||||
if (qemuTranslateDiskSourcePool(conn, obj->def->disks[i]) < 0)
|
||||
goto error;
|
||||
if (qemuAddSharedDisk(driver, obj->def->disks[i],
|
||||
obj->def->name) < 0)
|
||||
goto error;
|
||||
@ -3556,6 +3558,11 @@ int qemuProcessStart(virConnectPtr conn,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
for (i = 0; i < vm->def->ndisks; i++) {
|
||||
if (qemuTranslateDiskSourcePool(conn, vm->def->disks[i]) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
VIR_DEBUG("Building emulator command line");
|
||||
if (!(cmd = qemuBuildCommandLine(conn, driver, vm->def, priv->monConfig,
|
||||
priv->monJSON != 0, priv->qemuCaps,
|
||||
|
Loading…
x
Reference in New Issue
Block a user