[libvirt] [PATCH 07/10] qemuDomainCreateDevice: Properly deal with symlinks
Martin Kletzander
mkletzan at redhat.com
Tue Feb 7 10:18:47 UTC 2017
On Fri, Jan 20, 2017 at 10:42:47AM +0100, Michal Privoznik wrote:
>Imagine you have a disk with the following source set up:
>
>/dev/disk/by-uuid/$uuid (symlink to) -> /dev/sda
>
>After cbc45525cb21 the transitive end of the symlink chain is
>created (/dev/sda), but we need to create any item in chain too.
>Others might rely on that.
>In this case, /dev/disk/by-uuid/$uuid comes from domain XML thus
>it is this path that secdriver tries to relabel. Not the resolved
>one.
>
>Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
>---
> src/qemu/qemu_domain.c | 150 +++++++++++++++++++++++++++++++++++--------------
> 1 file changed, 108 insertions(+), 42 deletions(-)
>
>diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
>index 0f45f753e..8cbfb2d16 100644
>--- a/src/qemu/qemu_domain.c
>+++ b/src/qemu/qemu_domain.c
>@@ -68,6 +68,7 @@
> #endif
>
> #include <libxml/xpathInternals.h>
>+#include "dosname.h"
>
> #define VIR_FROM_THIS VIR_FROM_QEMU
>
>@@ -6958,70 +6959,135 @@ qemuDomainCreateDevice(const char *device,
> bool allow_noent)
> {
> char *devicePath = NULL;
>- char *canonDevicePath = NULL;
>+ char *target = NULL;
> struct stat sb;
> int ret = -1;
>+ bool isLink = false;
>+ bool create = false;
> #ifdef WITH_SELINUX
> char *tcon = NULL;
> #endif
>
>- if (virFileResolveAllLinks(device, &canonDevicePath) < 0) {
>+ if (lstat(device, &sb) < 0) {
> if (errno == ENOENT && allow_noent) {
> /* Ignore non-existent device. */
>- ret = 0;
>- goto cleanup;
>+ return 0;
> }
>-
>- virReportError(errno, _("Unable to canonicalize %s"), device);
>- goto cleanup;
>- }
>-
>- if (!STRPREFIX(canonDevicePath, DEVPREFIX)) {
>- ret = 0;
>- goto cleanup;
>+ virReportSystemError(errno, _("Unable to stat %s"), device);
>+ return ret;
> }
>
>- if (virAsprintf(&devicePath, "%s/%s",
>- path, canonDevicePath + strlen(DEVPREFIX)) < 0)
>- goto cleanup;
>+ isLink = S_ISLNK(sb.st_mode);
>
>- if (stat(canonDevicePath, &sb) < 0) {
>- if (errno == ENOENT && allow_noent) {
>- /* Ignore non-existent device. */
>- ret = 0;
>+ /* Here, @device might be whatever path in the system. We
>+ * should create the path in the namespace iff its "/dev"
s/its/it's/
ACK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170207/5058a6fb/attachment-0001.sig>
More information about the libvir-list
mailing list