[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 07/10] qemuDomainCreateDevice: Properly deal with symlinks



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 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

Attachment: signature.asc
Description: Digital signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]