提交 5d300576 编写于 作者: M Michal Privoznik

qemuDomainGetPreservedMounts: Do not special case /dev

The c1140eb9 got me thinking. We don't want to special case /dev
in qemuDomainGetPreservedMounts(), but in all other places in the
code we special case it anyway. I mean,
/var/run/libvirt/$domain.dev path is constructed separately just
so that it is not constructed here. It makes only a little sense
(if any at all).
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 40ebbf72
...@@ -226,18 +226,17 @@ qemuDomainGetPreservedMounts(virQEMUDriverPtr driver, ...@@ -226,18 +226,17 @@ qemuDomainGetPreservedMounts(virQEMUDriverPtr driver,
return 0; return 0;
} }
/* Since the list is sorted and only has paths that start with /dev, the
* /dev itself can only be first. */
if (STREQ(mounts[0], "/dev"))
VIR_DELETE_ELEMENT(mounts, 0, nmounts);
if (VIR_ALLOC_N(paths, nmounts) < 0) if (VIR_ALLOC_N(paths, nmounts) < 0)
goto error; goto error;
for (i = 0; i < nmounts; i++) { for (i = 0; i < nmounts; i++) {
const char *suffix = mounts[i] + strlen(DEVPREFIX);
if (STREQ(mounts[i], "/dev"))
suffix = "dev";
if (virAsprintf(&paths[i], "%s/%s.%s", if (virAsprintf(&paths[i], "%s/%s.%s",
cfg->stateDir, vm->def->name, cfg->stateDir, vm->def->name, suffix) < 0)
mounts[i] + strlen(DEVPREFIX)) < 0)
goto error; goto error;
} }
...@@ -7344,20 +7343,32 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver, ...@@ -7344,20 +7343,32 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
if (virAsprintf(&devPath, "%s/%s.dev",
cfg->stateDir, vm->def->name) < 0)
goto cleanup;
if (qemuDomainGetPreservedMounts(driver, vm, if (qemuDomainGetPreservedMounts(driver, vm,
&devMountsPath, &devMountsSavePath, &devMountsPath, &devMountsSavePath,
&ndevMountsPath) < 0) &ndevMountsPath) < 0)
goto cleanup; goto cleanup;
for (i = 0; i < ndevMountsPath; i++) {
if (STREQ(devMountsPath[i], "/dev")) {
devPath = devMountsSavePath[i];
break;
}
}
if (!devPath) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Unable to find any /dev mount"));
goto cleanup;
}
if (qemuDomainSetupDev(driver, vm, devPath) < 0) if (qemuDomainSetupDev(driver, vm, devPath) < 0)
goto cleanup; goto cleanup;
/* Save some mount points because we want to share them with the host */ /* Save some mount points because we want to share them with the host */
for (i = 0; i < ndevMountsPath; i++) { for (i = 0; i < ndevMountsPath; i++) {
if (devMountsSavePath[i] == devPath)
continue;
if (mount(devMountsPath[i], devMountsSavePath[i], if (mount(devMountsPath[i], devMountsSavePath[i],
NULL, mount_flags, NULL) < 0) { NULL, mount_flags, NULL) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
...@@ -7393,6 +7404,9 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver, ...@@ -7393,6 +7404,9 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
} }
for (i = 0; i < ndevMountsPath; i++) { for (i = 0; i < ndevMountsPath; i++) {
if (devMountsSavePath[i] == devPath)
continue;
if (virFileMakePath(devMountsPath[i]) < 0) { if (virFileMakePath(devMountsPath[i]) < 0) {
virReportSystemError(errno, _("Cannot create %s"), virReportSystemError(errno, _("Cannot create %s"),
devMountsPath[i]); devMountsPath[i]);
...@@ -7412,7 +7426,6 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver, ...@@ -7412,7 +7426,6 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver,
ret = 0; ret = 0;
cleanup: cleanup:
virObjectUnref(cfg); virObjectUnref(cfg);
VIR_FREE(devPath);
virStringListFreeCount(devMountsPath, ndevMountsPath); virStringListFreeCount(devMountsPath, ndevMountsPath);
virStringListFreeCount(devMountsSavePath, ndevMountsPath); virStringListFreeCount(devMountsSavePath, ndevMountsPath);
return ret; return ret;
...@@ -7425,7 +7438,6 @@ qemuDomainCreateNamespace(virQEMUDriverPtr driver, ...@@ -7425,7 +7438,6 @@ qemuDomainCreateNamespace(virQEMUDriverPtr driver,
{ {
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
int ret = -1; int ret = -1;
char *devPath = NULL;
char **devMountsSavePath = NULL; char **devMountsSavePath = NULL;
size_t ndevMountsSavePath = 0, i; size_t ndevMountsSavePath = 0, i;
...@@ -7435,22 +7447,11 @@ qemuDomainCreateNamespace(virQEMUDriverPtr driver, ...@@ -7435,22 +7447,11 @@ qemuDomainCreateNamespace(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
} }
if (virAsprintf(&devPath, "%s/%s.dev",
cfg->stateDir, vm->def->name) < 0)
goto cleanup;
if (qemuDomainGetPreservedMounts(driver, vm, if (qemuDomainGetPreservedMounts(driver, vm,
NULL, &devMountsSavePath, NULL, &devMountsSavePath,
&ndevMountsSavePath) < 0) &ndevMountsSavePath) < 0)
goto cleanup; goto cleanup;
if (virFileMakePath(devPath) < 0) {
virReportSystemError(errno,
_("Failed to create %s"),
devPath);
goto cleanup;
}
for (i = 0; i < ndevMountsSavePath; i++) { for (i = 0; i < ndevMountsSavePath; i++) {
if (virFileMakePath(devMountsSavePath[i]) < 0) { if (virFileMakePath(devMountsSavePath[i]) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
...@@ -7466,13 +7467,10 @@ qemuDomainCreateNamespace(virQEMUDriverPtr driver, ...@@ -7466,13 +7467,10 @@ qemuDomainCreateNamespace(virQEMUDriverPtr driver,
ret = 0; ret = 0;
cleanup: cleanup:
if (ret < 0) { if (ret < 0) {
if (devPath)
rmdir(devPath);
for (i = 0; i < ndevMountsSavePath; i++) for (i = 0; i < ndevMountsSavePath; i++)
rmdir(devMountsSavePath[i]); rmdir(devMountsSavePath[i]);
} }
virStringListFreeCount(devMountsSavePath, ndevMountsSavePath); virStringListFreeCount(devMountsSavePath, ndevMountsSavePath);
VIR_FREE(devPath);
virObjectUnref(cfg); virObjectUnref(cfg);
return ret; return ret;
} }
...@@ -7513,22 +7511,11 @@ qemuDomainDeleteNamespace(virQEMUDriverPtr driver, ...@@ -7513,22 +7511,11 @@ qemuDomainDeleteNamespace(virQEMUDriverPtr driver,
if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT))
return; return;
if (virAsprintf(&devPath, "%s/%s.dev",
cfg->stateDir, vm->def->name) < 0)
goto cleanup;
if (qemuDomainGetPreservedMounts(driver, vm, if (qemuDomainGetPreservedMounts(driver, vm,
NULL, &devMountsSavePath, NULL, &devMountsSavePath,
&ndevMountsSavePath) < 0) &ndevMountsSavePath) < 0)
goto cleanup; goto cleanup;
if (rmdir(devPath) < 0) {
virReportSystemError(errno,
_("Unable to remove %s"),
devPath);
/* Bet effort. Fall through. */
}
for (i = 0; i < ndevMountsSavePath; i++) { for (i = 0; i < ndevMountsSavePath; i++) {
if (rmdir(devMountsSavePath[i]) < 0) { if (rmdir(devMountsSavePath[i]) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册