mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemuDomainAttachDeviceMknodRecursive: Isolate bind mounted devices condition
When attaching a device into a domain, the corresponding /dev node might need to be created in the domain's namespace. For some types of files we call mknod(), for symlinks we call symlink(), but for others - which exist in the host namespace - we need to so called 'bind mount' them (which is a way of passing a file/directory between mount namespaces). There is this condition in qemuDomainAttachDeviceMknodRecursive() which decides whether a bind mount will be used, move it into a separate function so that it can be reused later. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
08277c2bc6
commit
bf9aeab4f0
@ -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
|
static int
|
||||||
qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
|
qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
@ -1266,8 +1277,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
g_autofree char *target = NULL;
|
g_autofree char *target = NULL;
|
||||||
bool isLink;
|
bool isLink;
|
||||||
bool isReg;
|
bool needsBindMount;
|
||||||
bool isDir;
|
|
||||||
|
|
||||||
if (!ttl) {
|
if (!ttl) {
|
||||||
virReportSystemError(ELOOP,
|
virReportSystemError(ELOOP,
|
||||||
@ -1289,10 +1299,9 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
isLink = S_ISLNK(data.sb.st_mode);
|
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);
|
needsBindMount = qemuNamespaceMknodItemNeedsBindMount(data.sb.st_mode);
|
||||||
isDir = S_ISDIR(data.sb.st_mode);
|
|
||||||
|
|
||||||
if ((isReg || isDir) && STRPREFIX(file, QEMU_DEVPREFIX)) {
|
if (needsBindMount && STRPREFIX(file, QEMU_DEVPREFIX)) {
|
||||||
cfg = virQEMUDriverGetConfig(driver);
|
cfg = virQEMUDriverGetConfig(driver);
|
||||||
if (!(target = qemuDomainGetPreservedMountPath(cfg, vm, file)))
|
if (!(target = qemuDomainGetPreservedMountPath(cfg, vm, file)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1382,7 +1391,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver,
|
|||||||
freecon(data.tcon);
|
freecon(data.tcon);
|
||||||
# endif
|
# endif
|
||||||
virFileFreeACLs(&data.acl);
|
virFileFreeACLs(&data.acl);
|
||||||
if (isReg && target)
|
if (needsBindMount && target)
|
||||||
umount(target);
|
umount(target);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user