From 323b9f72efd7408fc0a3c0c58fc63b91534e2c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Wed, 15 Nov 2017 17:43:51 +0100 Subject: [PATCH] Introduce qemuDomainNamespaceMknodPath Use this function in qemuDomainNamespaceSetup* functions which only require creating one device. --- src/qemu/qemu_domain.c | 120 +++++++++-------------------------------- 1 file changed, 26 insertions(+), 94 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index fff63aeadb..72a8fa1301 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9971,6 +9971,16 @@ qemuDomainNamespaceMknodPaths(virDomainObjPtr vm, } +static int +qemuDomainNamespaceMknodPath(virDomainObjPtr vm, + const char *path) +{ + const char *paths[] = { path }; + + return qemuDomainNamespaceMknodPaths(vm, paths, 1); +} + + int qemuDomainNamespaceSetupDisk(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, virDomainObjPtr vm, @@ -10090,35 +10100,17 @@ qemuDomainNamespaceTeardownHostdev(virQEMUDriverPtr driver, int -qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver, +qemuDomainNamespaceSetupMemory(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, 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) return 0; - if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) - return 0; + if (qemuDomainNamespaceMknodPath(vm, mem->nvdimmPath) < 0) + return -1; - 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; + return 0; } @@ -10156,18 +10148,11 @@ qemuDomainNamespaceTeardownMemory(virQEMUDriverPtr driver, int -qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver, +qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, virDomainObjPtr vm, virDomainChrDefPtr chr) { - virQEMUDriverConfigPtr cfg = NULL; - char **devMountsPath = NULL; - size_t ndevMountsPath = 0; const char *path; - int ret = -1; - - if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) - return 0; if (!(path = virDomainChrSourceDefGetPath(chr->source))) return 0; @@ -10177,22 +10162,10 @@ qemuDomainNamespaceSetupChardev(virQEMUDriverPtr driver, chr->source->data.nix.listen) return 0; - cfg = virQEMUDriverGetConfig(driver); - if (qemuDomainGetPreservedMounts(cfg, vm, - &devMountsPath, NULL, - &ndevMountsPath) < 0) - goto cleanup; + if (qemuDomainNamespaceMknodPath(vm, path) < 0) + return -1; - if (qemuDomainAttachDeviceMknod(driver, - vm, - path, - devMountsPath, ndevMountsPath) < 0) - goto cleanup; - ret = 0; - cleanup: - virStringListFreeCount(devMountsPath, ndevMountsPath); - virObjectUnref(cfg); - return ret; + return 0; } @@ -10234,18 +10207,11 @@ qemuDomainNamespaceTeardownChardev(virQEMUDriverPtr driver, int -qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver, +qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, virDomainObjPtr vm, virDomainRNGDefPtr rng) { - virQEMUDriverConfigPtr cfg = NULL; - char **devMountsPath = NULL; - size_t ndevMountsPath = 0; const char *path = NULL; - int ret = -1; - - if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) - return 0; switch ((virDomainRNGBackend) rng->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: @@ -10254,26 +10220,13 @@ qemuDomainNamespaceSetupRNG(virQEMUDriverPtr driver, case VIR_DOMAIN_RNG_BACKEND_EGD: case VIR_DOMAIN_RNG_BACKEND_LAST: - ret = 0; - goto cleanup; + break; } - cfg = virQEMUDriverGetConfig(driver); - if (qemuDomainGetPreservedMounts(cfg, vm, - &devMountsPath, NULL, - &ndevMountsPath) < 0) - goto cleanup; + if (path && qemuDomainNamespaceMknodPath(vm, path) < 0) + return -1; - if (qemuDomainAttachDeviceMknod(driver, - vm, - path, - devMountsPath, ndevMountsPath) < 0) - goto cleanup; - ret = 0; - cleanup: - virStringListFreeCount(devMountsPath, ndevMountsPath); - virObjectUnref(cfg); - return ret; + return 0; } @@ -10324,35 +10277,14 @@ int qemuDomainNamespaceSetupInput(virDomainObjPtr vm, virDomainInputDefPtr input) { - qemuDomainObjPrivatePtr priv = vm->privateData; - virQEMUDriverPtr driver = priv->driver; - virQEMUDriverConfigPtr cfg = NULL; - char **devMountsPath = NULL; - size_t ndevMountsPath = 0; const char *path = NULL; - int ret = -1; if (!(path = virDomainInputDefGetPath(input))) return 0; - if (!qemuDomainNamespaceEnabled(vm, QEMU_DOMAIN_NS_MOUNT)) - return 0; - - cfg = virQEMUDriverGetConfig(driver); - if (qemuDomainGetPreservedMounts(cfg, vm, - &devMountsPath, NULL, - &ndevMountsPath) < 0) - goto cleanup; - - if (qemuDomainAttachDeviceMknod(driver, vm, path, - devMountsPath, ndevMountsPath) < 0) - goto cleanup; - - ret = 0; - cleanup: - virStringListFreeCount(devMountsPath, ndevMountsPath); - virObjectUnref(cfg); - return ret; + if (path && qemuDomainNamespaceMknodPath(vm, path) < 0) + return -1; + return 0; }