qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
virDomainObjPtr vm,
const char *file,
+ char * const *devMountsPath,
+ size_t ndevMountsPath,
unsigned int ttl)
{
struct qemuDomainAttachDeviceMknodData data;
#endif
if (STRPREFIX(file, DEVPREFIX)) {
- if (qemuSecurityPreFork(driver->securityManager) < 0)
- goto cleanup;
+ size_t i;
+
+ for (i = 0; i < ndevMountsPath; i++) {
+ if (STREQ(devMountsPath[i], "/dev"))
+ continue;
+ if (STRPREFIX(file, devMountsPath[i]))
+ break;
+ }
+
+ if (i == ndevMountsPath) {
+ if (qemuSecurityPreFork(driver->securityManager) < 0)
+ goto cleanup;
- if (virProcessRunInMountNamespace(vm->pid,
- qemuDomainAttachDeviceMknodHelper,
- &data) < 0) {
+ if (virProcessRunInMountNamespace(vm->pid,
+ qemuDomainAttachDeviceMknodHelper,
+ &data) < 0) {
+ qemuSecurityPostFork(driver->securityManager);
+ goto cleanup;
+ }
qemuSecurityPostFork(driver->securityManager);
- goto cleanup;
+ } else {
+ VIR_DEBUG("Skipping dev %s because of %s mount point",
+ file, devMountsPath[i]);
}
- qemuSecurityPostFork(driver->securityManager);
}
if (isLink &&
- qemuDomainAttachDeviceMknodRecursive(driver, vm, target, ttl -1) < 0)
+ qemuDomainAttachDeviceMknodRecursive(driver, vm, target,
+ devMountsPath, ndevMountsPath,
+ ttl -1) < 0)
goto cleanup;
ret = 0;
static int
qemuDomainAttachDeviceMknod(virQEMUDriverPtr driver,
virDomainObjPtr vm,
- const char *file)
+ const char *file,
+ char * const *devMountsPath,
+ size_t ndevMountsPath)
{
long symloop_max = sysconf(_SC_SYMLOOP_MAX);
- return qemuDomainAttachDeviceMknodRecursive(driver, vm, file, symloop_max);
+ return qemuDomainAttachDeviceMknodRecursive(driver, vm, file,
+ devMountsPath, ndevMountsPath,
+ symloop_max);
}
virDomainObjPtr vm,
virStorageSourcePtr src)
{
+ virQEMUDriverConfigPtr cfg = NULL;
+ char **devMountsPath = NULL;
+ size_t ndevMountsPath = 0;
virStorageSourcePtr next;
struct stat sb;
int ret = -1;
if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
return 0;
+ cfg = virQEMUDriverGetConfig(driver);
+ if (qemuDomainGetPreservedMounts(cfg, vm,
+ &devMountsPath, NULL,
+ &ndevMountsPath) < 0)
+ goto cleanup;
+
for (next = src; next; next = next->backingStore) {
if (virStorageSourceIsEmpty(next) ||
!virStorageSourceIsLocalStorage(next)) {
if (qemuDomainAttachDeviceMknod(driver,
vm,
- next->path) < 0)
+ next->path,
+ devMountsPath, ndevMountsPath) < 0)
goto cleanup;
}
ret = 0;
cleanup:
+ virStringListFreeCount(devMountsPath, ndevMountsPath);
+ virObjectUnref(cfg);
return ret;
}
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
{
+ virQEMUDriverConfigPtr cfg = NULL;
+ char **devMountsPath = NULL;
+ size_t ndevMountsPath = 0;
int ret = -1;
char **path = NULL;
size_t i, npaths = 0;
if (qemuDomainGetHostdevPath(NULL, hostdev, false, &npaths, &path, NULL) < 0)
goto cleanup;
+ cfg = virQEMUDriverGetConfig(driver);
+ if (qemuDomainGetPreservedMounts(cfg, vm,
+ &devMountsPath, NULL,
+ &ndevMountsPath) < 0)
+ goto cleanup;
+
for (i = 0; i < npaths; i++) {
if (qemuDomainAttachDeviceMknod(driver,
vm,
- path[i]) < 0)
+ path[i],
+ devMountsPath, ndevMountsPath) < 0)
goto cleanup;
}
for (i = 0; i < npaths; i++)
VIR_FREE(path[i]);
VIR_FREE(path);
+ virStringListFreeCount(devMountsPath, ndevMountsPath);
+ virObjectUnref(cfg);
return ret;
}
virDomainObjPtr vm,
virDomainMemoryDefPtr mem)
{
+ virQEMUDriverConfigPtr cfg = NULL;
+ char **devMountsPath = NULL;
+ size_t ndevMountsPath = 0;
int ret = -1;
if (mem->model != VIR_DOMAIN_MEMORY_MODEL_NVDIMM)
if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
return 0;
- if (qemuDomainAttachDeviceMknod(driver, vm, mem->nvdimmPath) < 0)
+ cfg = virQEMUDriverGetConfig(driver);
+ if (qemuDomainGetPreservedMounts(cfg, vm,
+ &devMountsPath, NULL,
+ &ndevMountsPath) < 0)
+ goto cleanup;
+
+ if (qemuDomainAttachDeviceMknod(driver, vm, mem->nvdimmPath,
+ devMountsPath, ndevMountsPath) < 0)
goto cleanup;
ret = 0;
cleanup:
+ virStringListFreeCount(devMountsPath, ndevMountsPath);
+ virObjectUnref(cfg);
return ret;
}
virDomainObjPtr vm,
virDomainChrDefPtr chr)
{
+ virQEMUDriverConfigPtr cfg = NULL;
+ char **devMountsPath = NULL;
+ size_t ndevMountsPath = 0;
const char *path;
int ret = -1;
path = chr->source->data.file.path;
+ cfg = virQEMUDriverGetConfig(driver);
+ if (qemuDomainGetPreservedMounts(cfg, vm,
+ &devMountsPath, NULL,
+ &ndevMountsPath) < 0)
+ goto cleanup;
+
if (qemuDomainAttachDeviceMknod(driver,
vm,
- path) < 0)
+ path,
+ devMountsPath, ndevMountsPath) < 0)
goto cleanup;
ret = 0;
cleanup:
+ virStringListFreeCount(devMountsPath, ndevMountsPath);
+ virObjectUnref(cfg);
return ret;
}
virDomainObjPtr vm,
virDomainRNGDefPtr rng)
{
+ virQEMUDriverConfigPtr cfg = NULL;
+ char **devMountsPath = NULL;
+ size_t ndevMountsPath = 0;
const char *path = NULL;
int ret = -1;
goto cleanup;
}
+ cfg = virQEMUDriverGetConfig(driver);
+ if (qemuDomainGetPreservedMounts(cfg, vm,
+ &devMountsPath, NULL,
+ &ndevMountsPath) < 0)
+ goto cleanup;
+
if (qemuDomainAttachDeviceMknod(driver,
vm,
- path) < 0)
+ path,
+ devMountsPath, ndevMountsPath) < 0)
goto cleanup;
ret = 0;
cleanup:
+ virStringListFreeCount(devMountsPath, ndevMountsPath);
+ virObjectUnref(cfg);
return ret;
}