提交 4f05f188 编写于 作者: M Michal Privoznik

qemuDomainCreateDeviceRecursive: Support file mount points

https://bugzilla.redhat.com/show_bug.cgi?id=1462060

When building a qemu namespace we might be dealing with bare
regular files. Files that live under /dev. For instance
/dev/my_awesome_disk:

  <disk type='file' device='disk'>
    <driver name='qemu' type='qcow2'/>
    <source file='/dev/my_awesome_disk'/>
    <target dev='vdc' bus='virtio'/>
  </disk>

  # qemu-img create -f qcow2 /dev/my_awesome_disk 10M

So far we were mknod()-ing them which is
obviously wrong. We need to touch the file and bind mount it to
the original:

1) touch /var/run/libvirt/qemu/fedora.dev/my_awesome_disk
2) mount --bind /dev/my_awesome_disk /var/run/libvirt/qemu/fedora.dev/my_awesome_disk

Later, when the new /dev is built and replaces original /dev the
file is going to live at expected location.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJohn Ferlan <jferlan@redhat.com>
上级 4fedbac6
...@@ -7721,6 +7721,7 @@ qemuDomainCreateDeviceRecursive(const char *device, ...@@ -7721,6 +7721,7 @@ qemuDomainCreateDeviceRecursive(const char *device,
int ret = -1; int ret = -1;
bool isLink = false; bool isLink = false;
bool isDev = false; bool isDev = false;
bool isReg = false;
bool create = false; bool create = false;
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
char *tcon = NULL; char *tcon = NULL;
...@@ -7744,6 +7745,7 @@ qemuDomainCreateDeviceRecursive(const char *device, ...@@ -7744,6 +7745,7 @@ qemuDomainCreateDeviceRecursive(const char *device,
isLink = S_ISLNK(sb.st_mode); isLink = S_ISLNK(sb.st_mode);
isDev = S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode); isDev = S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode);
isReg = S_ISREG(sb.st_mode);
/* Here, @device might be whatever path in the system. We /* Here, @device might be whatever path in the system. We
* should create the path in the namespace iff it's "/dev" * should create the path in the namespace iff it's "/dev"
...@@ -7855,16 +7857,12 @@ qemuDomainCreateDeviceRecursive(const char *device, ...@@ -7855,16 +7857,12 @@ qemuDomainCreateDeviceRecursive(const char *device,
} }
goto cleanup; goto cleanup;
} }
} else if (isReg) {
/* Set the file permissions again: mknod() is affected by the
* current umask, and as such might not have set them correctly */
if (create && if (create &&
chmod(devicePath, sb.st_mode) < 0) { virFileTouch(devicePath, sb.st_mode) < 0)
virReportSystemError(errno,
_("Failed to set permissions for device %s"),
devicePath);
goto cleanup; goto cleanup;
} /* Just create the file here so that code below sets
* proper owner and mode. Bind mount only after that. */
} else { } else {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("unsupported device type %s 0%o"), _("unsupported device type %s 0%o"),
...@@ -7884,6 +7882,15 @@ qemuDomainCreateDeviceRecursive(const char *device, ...@@ -7884,6 +7882,15 @@ qemuDomainCreateDeviceRecursive(const char *device,
goto cleanup; goto cleanup;
} }
/* Symlinks don't have mode */
if (!isLink &&
chmod(devicePath, sb.st_mode) < 0) {
virReportSystemError(errno,
_("Failed to set permissions for device %s"),
devicePath);
goto cleanup;
}
/* Symlinks don't have ACLs. */ /* Symlinks don't have ACLs. */
if (!isLink && if (!isLink &&
virFileCopyACLs(device, devicePath) < 0 && virFileCopyACLs(device, devicePath) < 0 &&
...@@ -7916,6 +7923,11 @@ qemuDomainCreateDeviceRecursive(const char *device, ...@@ -7916,6 +7923,11 @@ qemuDomainCreateDeviceRecursive(const char *device,
} }
#endif #endif
/* Finish mount process started earlier. */
if (isReg &&
virFileBindMountDevice(device, devicePath) < 0)
goto cleanup;
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(target); VIR_FREE(target);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册