[PATCH v2 1/3] qemu: Check for existing file in namespace

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

 



Signed-off-by: Kristina Hanicova <khanicov@xxxxxxxxxx>
---
 src/qemu/qemu_namespace.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c
index 98495e8ef8..eb048a2faa 100644
--- a/src/qemu/qemu_namespace.c
+++ b/src/qemu/qemu_namespace.c
@@ -929,6 +929,10 @@ qemuNamespaceMknodOne(qemuNamespaceMknodItem *data)
     bool isDev = S_ISCHR(data->sb.st_mode) || S_ISBLK(data->sb.st_mode);
     bool isReg = S_ISREG(data->sb.st_mode) || S_ISFIFO(data->sb.st_mode) || S_ISSOCK(data->sb.st_mode);
     bool isDir = S_ISDIR(data->sb.st_mode);
+    bool exists = false;
+
+    if (virFileExists(data->file))
+        exists = true;
 
     if (virFileMakeParentPath(data->file) < 0) {
         virReportSystemError(errno,
@@ -1039,7 +1043,7 @@ qemuNamespaceMknodOne(qemuNamespaceMknodItem *data)
         virFileMoveMount(data->target, data->file) < 0)
         goto cleanup;
 
-    ret = 0;
+    ret = exists ? 1 : 0;
  cleanup:
     if (ret < 0 && delDevice) {
         if (isDir)
@@ -1069,15 +1073,21 @@ qemuNamespaceMknodHelper(pid_t pid G_GNUC_UNUSED,
     qemuNamespaceMknodData *data = opaque;
     size_t i;
     int ret = -1;
+    bool exists = false;
 
     qemuSecurityPostFork(data->driver->securityManager);
 
     for (i = 0; i < data->nitems; i++) {
-        if (qemuNamespaceMknodOne(&data->items[i]) < 0)
+        int rc = 0;
+
+        if ((rc = qemuNamespaceMknodOne(&data->items[i])) < 0)
             goto cleanup;
+
+        if (rc > 0)
+            exists = true;
     }
 
-    ret = 0;
+    ret = exists ? 1 : 0;
  cleanup:
     qemuNamespaceMknodDataClear(data);
     return ret;
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux