Some of the functions are not called on non-linux platforms which makes them useless there. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/qemu/qemu_domain.c | 372 +++++++++++++++++++++++++------------------------ 1 file changed, 191 insertions(+), 181 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d92b303c6..ecf72a84d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -6781,186 +6781,6 @@ qemuDomainSupportsVideoVga(virDomainVideoDefPtr video, } -static int -qemuDomainCreateDevice(const char *device, - const char *path, - bool allow_noent) -{ - char *devicePath = NULL; - struct stat sb; - int ret = -1; - - if (!STRPREFIX(device, "/dev")) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid device: %s"), - device); - goto cleanup; - } - - if (virAsprintf(&devicePath, "%s/%s", - path, device + 4) < 0) - goto cleanup; - - if (stat(device, &sb) < 0) { - if (errno == ENOENT && allow_noent) { - /* Ignore non-existent device. */ - ret = 0; - goto cleanup; - } - - virReportSystemError(errno, _("Unable to stat %s"), device); - goto cleanup; - } - - if (virFileMakeParentPath(devicePath) < 0) { - virReportSystemError(errno, - _("Unable to create %s"), - devicePath); - goto cleanup; - } - - if (mknod(devicePath, sb.st_mode, sb.st_rdev) < 0) { - virReportSystemError(errno, - _("Failed to make device %s"), - devicePath); - goto cleanup; - } - - if (chown(devicePath, sb.st_uid, sb.st_gid) < 0) { - virReportSystemError(errno, - _("Failed to chown device %s"), - devicePath); - goto cleanup; - } - - if (virFileCopyACLs(device, devicePath) < 0 && - errno != ENOTSUP) { - virReportSystemError(errno, - _("Failed to copy ACLs on device %s"), - devicePath); - goto cleanup; - } - - ret = 0; - cleanup: - VIR_FREE(devicePath); - return ret; -} - - - -static int -qemuDomainPopulateDevices(virQEMUDriverPtr driver, - virDomainObjPtr vm ATTRIBUTE_UNUSED, - const char *path) -{ - virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); - const char *const *devices = (const char *const *) cfg->cgroupDeviceACL; - size_t i; - int ret = -1; - - if (!devices) - devices = defaultDeviceACL; - - for (i = 0; devices[i]; i++) { - if (qemuDomainCreateDevice(devices[i], path, true) < 0) - goto cleanup; - } - - ret = 0; - cleanup: - virObjectUnref(cfg); - return ret; -} - - -static int -qemuDomainSetupDev(virQEMUDriverPtr driver, - virDomainObjPtr vm, - const char *path) -{ - char *mount_options = NULL; - char *opts = NULL; - int ret = -1; - - VIR_DEBUG("Setting up /dev/ for domain %s", vm->def->name); - - mount_options = virSecurityManagerGetMountOptions(driver->securityManager, - vm->def); - - if (!mount_options && - VIR_STRDUP(mount_options, "") < 0) - goto cleanup; - - /* - * tmpfs is limited to 64kb, since we only have device nodes in there - * and don't want to DOS the entire OS RAM usage - */ - if (virAsprintf(&opts, - "mode=755,size=65536%s", mount_options) < 0) - goto cleanup; - - if (virFileSetupDev(path, opts) < 0) - goto cleanup; - - if (qemuDomainPopulateDevices(driver, vm, path) < 0) - goto cleanup; - - ret = 0; - cleanup: - VIR_FREE(opts); - VIR_FREE(mount_options); - return ret; -} - - -static int -qemuDomainSetupDisk(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, - virDomainDiskDefPtr disk, - const char *devPath) -{ - virStorageSourcePtr next; - char *dst = NULL; - int ret = -1; - - for (next = disk->src; next; next = next->backingStore) { - if (!next->path || !virStorageSourceIsLocalStorage(next) || - !STRPREFIX(next->path, "/dev")) { - /* Not creating device. Just continue. */ - continue; - } - - if (qemuDomainCreateDevice(next->path, devPath, false) < 0) - goto cleanup; - } - - ret = 0; - cleanup: - VIR_FREE(dst); - return ret; -} - - -static int -qemuDomainSetupAllDisks(virQEMUDriverPtr driver, - virDomainObjPtr vm, - const char *devPath) -{ - size_t i; - VIR_DEBUG("Setting up disks"); - - for (i = 0; i < vm->def->ndisks; i++) { - if (qemuDomainSetupDisk(driver, - vm->def->disks[i], - devPath) < 0) - return -1; - } - - VIR_DEBUG("Setup all disks"); - return 0; -} - - static int qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, char **path) @@ -7073,6 +6893,187 @@ qemuDomainGetHostdevPath(virDomainHostdevDefPtr dev, } +#if defined(__linux__) +static int +qemuDomainCreateDevice(const char *device, + const char *path, + bool allow_noent) +{ + char *devicePath = NULL; + struct stat sb; + int ret = -1; + + if (!STRPREFIX(device, "/dev")) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid device: %s"), + device); + goto cleanup; + } + + if (virAsprintf(&devicePath, "%s/%s", + path, device + 4) < 0) + goto cleanup; + + if (stat(device, &sb) < 0) { + if (errno == ENOENT && allow_noent) { + /* Ignore non-existent device. */ + ret = 0; + goto cleanup; + } + + virReportSystemError(errno, _("Unable to stat %s"), device); + goto cleanup; + } + + if (virFileMakeParentPath(devicePath) < 0) { + virReportSystemError(errno, + _("Unable to create %s"), + devicePath); + goto cleanup; + } + + if (mknod(devicePath, sb.st_mode, sb.st_rdev) < 0) { + virReportSystemError(errno, + _("Failed to make device %s"), + devicePath); + goto cleanup; + } + + if (chown(devicePath, sb.st_uid, sb.st_gid) < 0) { + virReportSystemError(errno, + _("Failed to chown device %s"), + devicePath); + goto cleanup; + } + + if (virFileCopyACLs(device, devicePath) < 0 && + errno != ENOTSUP) { + virReportSystemError(errno, + _("Failed to copy ACLs on device %s"), + devicePath); + goto cleanup; + } + + ret = 0; + cleanup: + VIR_FREE(devicePath); + return ret; +} + + + +static int +qemuDomainPopulateDevices(virQEMUDriverPtr driver, + virDomainObjPtr vm ATTRIBUTE_UNUSED, + const char *path) +{ + virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); + const char *const *devices = (const char *const *) cfg->cgroupDeviceACL; + size_t i; + int ret = -1; + + if (!devices) + devices = defaultDeviceACL; + + for (i = 0; devices[i]; i++) { + if (qemuDomainCreateDevice(devices[i], path, true) < 0) + goto cleanup; + } + + ret = 0; + cleanup: + virObjectUnref(cfg); + return ret; +} + + +static int +qemuDomainSetupDev(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *path) +{ + char *mount_options = NULL; + char *opts = NULL; + int ret = -1; + + VIR_DEBUG("Setting up /dev/ for domain %s", vm->def->name); + + mount_options = virSecurityManagerGetMountOptions(driver->securityManager, + vm->def); + + if (!mount_options && + VIR_STRDUP(mount_options, "") < 0) + goto cleanup; + + /* + * tmpfs is limited to 64kb, since we only have device nodes in there + * and don't want to DOS the entire OS RAM usage + */ + if (virAsprintf(&opts, + "mode=755,size=65536%s", mount_options) < 0) + goto cleanup; + + if (virFileSetupDev(path, opts) < 0) + goto cleanup; + + if (qemuDomainPopulateDevices(driver, vm, path) < 0) + goto cleanup; + + ret = 0; + cleanup: + VIR_FREE(opts); + VIR_FREE(mount_options); + return ret; +} + + +static int +qemuDomainSetupDisk(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, + virDomainDiskDefPtr disk, + const char *devPath) +{ + virStorageSourcePtr next; + char *dst = NULL; + int ret = -1; + + for (next = disk->src; next; next = next->backingStore) { + if (!next->path || !virStorageSourceIsLocalStorage(next) || + !STRPREFIX(next->path, "/dev")) { + /* Not creating device. Just continue. */ + continue; + } + + if (qemuDomainCreateDevice(next->path, devPath, false) < 0) + goto cleanup; + } + + ret = 0; + cleanup: + VIR_FREE(dst); + return ret; +} + + +static int +qemuDomainSetupAllDisks(virQEMUDriverPtr driver, + virDomainObjPtr vm, + const char *devPath) +{ + size_t i; + VIR_DEBUG("Setting up disks"); + + for (i = 0; i < vm->def->ndisks; i++) { + if (qemuDomainSetupDisk(driver, + vm->def->disks[i], + devPath) < 0) + return -1; + } + + VIR_DEBUG("Setup all disks"); + return 0; +} + + static int qemuDomainSetupHostdev(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, virDomainHostdevDefPtr dev, @@ -7355,7 +7356,6 @@ qemuDomainBuildNamespace(virQEMUDriverPtr driver, } -#if defined(__linux__) int qemuDomainCreateNamespace(virQEMUDriverPtr driver, virDomainObjPtr vm) @@ -7415,6 +7415,16 @@ qemuDomainCreateNamespace(virQEMUDriverPtr driver, #else /* !defined(__linux__) */ +int +qemuDomainBuildNamespace(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, + virDomainObjPtr vm ATTRIBUTE_UNUSED) +{ + /* Namespaces are Linux specific. On other platforms just + * carry on with the old behaviour. */ + return 0; +} + + int qemuDomainCreateNamespace(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, virDomainObjPtr vm ATTRIBUTE_UNUSED) -- 2.11.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list