diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index e78760df29..7b04691148 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -1253,6 +1253,17 @@ qemuDomainAttachDeviceMknodHelper(pid_t pid G_GNUC_UNUSED, } +static bool +qemuNamespaceMknodItemNeedsBindMount(mode_t st_mode) +{ + /* A block device S_ISBLK() or a chardev S_ISCHR() is intentionally not + * handled. We want to mknod() it instead of passing in through bind + * mounting. */ + return S_ISREG(st_mode) || S_ISFIFO(st_mode) || + S_ISSOCK(st_mode) || S_ISDIR(st_mode); +} + + static int qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -1266,8 +1277,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver, int ret = -1; g_autofree char *target = NULL; bool isLink; - bool isReg; - bool isDir; + bool needsBindMount; if (!ttl) { virReportSystemError(ELOOP, @@ -1289,10 +1299,9 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver, } isLink = S_ISLNK(data.sb.st_mode); - isReg = S_ISREG(data.sb.st_mode) || S_ISFIFO(data.sb.st_mode) || S_ISSOCK(data.sb.st_mode); - isDir = S_ISDIR(data.sb.st_mode); + needsBindMount = qemuNamespaceMknodItemNeedsBindMount(data.sb.st_mode); - if ((isReg || isDir) && STRPREFIX(file, QEMU_DEVPREFIX)) { + if (needsBindMount && STRPREFIX(file, QEMU_DEVPREFIX)) { cfg = virQEMUDriverGetConfig(driver); if (!(target = qemuDomainGetPreservedMountPath(cfg, vm, file))) goto cleanup; @@ -1382,7 +1391,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver, freecon(data.tcon); # endif virFileFreeACLs(&data.acl); - if (isReg && target) + if (needsBindMount && target) umount(target); return ret; }