[libvirt] [PATCH 6/7] qemu: remove failed create prior to root squash share path

John Ferlan jferlan at redhat.com
Wed Jan 28 22:25:05 UTC 2015


In qemuOpenFileAs if we fall into the path where we'll be opening / creating
the file using VIR_FILE_OPEN_FORK, we need to first unlink/delete the file
we created in the first path; otherwise, the attempt by the child process
to open as some specific user:group may fail because the file was already
created using nfsnobody:nfsnobody.

Signed-off-by: John Ferlan <jferlan at redhat.com>
 src/qemu/qemu_driver.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 89b54c8..91fefa9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2954,6 +2954,15 @@ qemuOpenFileAs(uid_t fallback_uid, gid_t fallback_gid,
                     goto error;
+            /* If we created the file above, then we need to remove it;
+             * otherwise, the next attempt to create will fail. If the
+             * file had already existed before we got here, then we also
+             * don't want to delete it and allow the following to succeed
+             * or fail based on existing protections
+             */
+            if (need_unlink)
+                unlink(path);
             /* Retry creating the file as qemu user */
             if ((fd = virFileOpenAs(path, oflags,

More information about the libvir-list mailing list