static int
qemuDomainDetachDeviceUnlink(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
virDomainObjPtr vm,
- const char *file)
+ const char *file,
+ char * const *devMountsPath,
+ size_t ndevMountsPath)
{
- if (virProcessRunInMountNamespace(vm->pid,
- qemuDomainDetachDeviceUnlinkHelper,
- (void *)file) < 0)
- return -1;
+ int ret = -1;
+ size_t i;
- return 0;
+ if (STRPREFIX(file, DEVPREFIX)) {
+ for (i = 0; i < ndevMountsPath; i++) {
+ if (STREQ(devMountsPath[i], "/dev"))
+ continue;
+ if (STRPREFIX(file, devMountsPath[i]))
+ break;
+ }
+
+ if (i == ndevMountsPath) {
+ if (virProcessRunInMountNamespace(vm->pid,
+ qemuDomainDetachDeviceUnlinkHelper,
+ (void *)file) < 0)
+ goto cleanup;
+ }
+ }
+
+ ret = 0;
+ cleanup:
+ 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;
&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 (qemuDomainDetachDeviceUnlink(driver, vm, path[i]) < 0)
+ if (qemuDomainDetachDeviceUnlink(driver, vm, 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 (qemuDomainDetachDeviceUnlink(driver, vm, mem->nvdimmPath) < 0)
+ cfg = virQEMUDriverGetConfig(driver);
+ if (qemuDomainGetPreservedMounts(cfg, vm,
+ &devMountsPath, NULL,
+ &ndevMountsPath) < 0)
+ goto cleanup;
+
+ if (qemuDomainDetachDeviceUnlink(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;
int ret = -1;
const char *path = NULL;
path = chr->source->data.file.path;
- if (qemuDomainDetachDeviceUnlink(driver, vm, path) < 0)
+ cfg = virQEMUDriverGetConfig(driver);
+ if (qemuDomainGetPreservedMounts(cfg, vm,
+ &devMountsPath, NULL,
+ &ndevMountsPath) < 0)
+ goto cleanup;
+
+ if (qemuDomainDetachDeviceUnlink(driver, vm, 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;
int ret = -1;
const char *path = NULL;
goto cleanup;
}
- if (qemuDomainDetachDeviceUnlink(driver, vm, path) < 0)
+ cfg = virQEMUDriverGetConfig(driver);
+ if (qemuDomainGetPreservedMounts(cfg, vm,
+ &devMountsPath, NULL,
+ &ndevMountsPath) < 0)
+ goto cleanup;
+
+ if (qemuDomainDetachDeviceUnlink(driver, vm, path,
+ devMountsPath, ndevMountsPath) < 0)
goto cleanup;
ret = 0;
cleanup:
+ virStringListFreeCount(devMountsPath, ndevMountsPath);
+ virObjectUnref(cfg);
return ret;
}