mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
Introduce qemuDomainNamespaceMknodPaths
Separate the logic of creating devices from their gathering. Use this new function in qemuDomainNamespaceSetupHostdev and qemuDomainNamespaceSetupDisk.
This commit is contained in:
parent
bc50c99edf
commit
d3db304d2e
@ -9933,16 +9933,18 @@ qemuDomainDetachDeviceUnlink(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
static int
|
||||||
qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver,
|
qemuDomainNamespaceMknodPaths(virDomainObjPtr vm,
|
||||||
virDomainObjPtr vm,
|
const char **paths,
|
||||||
virStorageSourcePtr src)
|
size_t npaths)
|
||||||
{
|
{
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
|
virQEMUDriverPtr driver = priv->driver;
|
||||||
|
virQEMUDriverConfigPtr cfg;
|
||||||
char **devMountsPath = NULL;
|
char **devMountsPath = NULL;
|
||||||
size_t ndevMountsPath = 0;
|
size_t ndevMountsPath = 0;
|
||||||
virStorageSourcePtr next;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
|
if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
|
||||||
return 0;
|
return 0;
|
||||||
@ -9953,16 +9955,10 @@ qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver,
|
|||||||
&ndevMountsPath) < 0)
|
&ndevMountsPath) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (next = src; virStorageSourceIsBacking(next); next = next->backingStore) {
|
for (i = 0; i < npaths; i++) {
|
||||||
if (virStorageSourceIsEmpty(next) ||
|
|
||||||
!virStorageSourceIsLocalStorage(next)) {
|
|
||||||
/* Not creating device. Just continue. */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemuDomainAttachDeviceMknod(driver,
|
if (qemuDomainAttachDeviceMknod(driver,
|
||||||
vm,
|
vm,
|
||||||
next->path,
|
paths[i],
|
||||||
devMountsPath, ndevMountsPath) < 0)
|
devMountsPath, ndevMountsPath) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -9975,6 +9971,40 @@ qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
virStorageSourcePtr src)
|
||||||
|
{
|
||||||
|
virStorageSourcePtr next;
|
||||||
|
char **paths = NULL;
|
||||||
|
size_t npaths;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
for (next = src; virStorageSourceIsBacking(next); next = next->backingStore) {
|
||||||
|
if (virStorageSourceIsEmpty(next) ||
|
||||||
|
!virStorageSourceIsLocalStorage(next)) {
|
||||||
|
/* Not creating device. Just continue. */
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (VIR_APPEND_ELEMENT_COPY(paths, npaths, next->path) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qemuDomainNamespaceMknodPaths(vm, (const char **)paths, npaths) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(paths);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
qemuDomainNamespaceTeardownDisk(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
|
qemuDomainNamespaceTeardownDisk(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
|
||||||
virDomainObjPtr vm ATTRIBUTE_UNUSED,
|
virDomainObjPtr vm ATTRIBUTE_UNUSED,
|
||||||
@ -9991,13 +10021,10 @@ qemuDomainNamespaceTeardownDisk(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
qemuDomainNamespaceSetupHostdev(virQEMUDriverPtr driver,
|
qemuDomainNamespaceSetupHostdev(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
virDomainHostdevDefPtr hostdev)
|
virDomainHostdevDefPtr hostdev)
|
||||||
{
|
{
|
||||||
virQEMUDriverConfigPtr cfg = NULL;
|
|
||||||
char **devMountsPath = NULL;
|
|
||||||
size_t ndevMountsPath = 0;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char **paths = NULL;
|
char **paths = NULL;
|
||||||
size_t i, npaths = 0;
|
size_t i, npaths = 0;
|
||||||
@ -10008,27 +10035,14 @@ qemuDomainNamespaceSetupHostdev(virQEMUDriverPtr driver,
|
|||||||
if (qemuDomainGetHostdevPath(NULL, hostdev, false, &npaths, &paths, NULL) < 0)
|
if (qemuDomainGetHostdevPath(NULL, hostdev, false, &npaths, &paths, NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
cfg = virQEMUDriverGetConfig(driver);
|
if (qemuDomainNamespaceMknodPaths(vm, (const char **)paths, npaths) < 0)
|
||||||
if (qemuDomainGetPreservedMounts(cfg, vm,
|
|
||||||
&devMountsPath, NULL,
|
|
||||||
&ndevMountsPath) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < npaths; i++) {
|
|
||||||
if (qemuDomainAttachDeviceMknod(driver,
|
|
||||||
vm,
|
|
||||||
paths[i],
|
|
||||||
devMountsPath, ndevMountsPath) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
for (i = 0; i < npaths; i++)
|
for (i = 0; i < npaths; i++)
|
||||||
VIR_FREE(paths[i]);
|
VIR_FREE(paths[i]);
|
||||||
VIR_FREE(paths);
|
VIR_FREE(paths);
|
||||||
virStringListFreeCount(devMountsPath, ndevMountsPath);
|
|
||||||
virObjectUnref(cfg);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user