[libvirt] [PATCH] qemuDomainBuildNamespace: Handle file mount points

Michal Privoznik posted 1 patch 7 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/290a00e41dac64cfd3d4b57e99dc718222fbae2d.1489408668.git.mprivozn@redhat.com
src/qemu/qemu_domain.c | 37 +++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
[libvirt] [PATCH] qemuDomainBuildNamespace: Handle file mount points
Posted by Michal Privoznik 7 years ago
https://bugzilla.redhat.com/show_bug.cgi?id=1431112

Yeah, that's right. A mount point doesn't have to be a directory.
It can be a file too. However, the code that tries to preserve
mount points under /dev for new namespace for qemu does not count
with that option.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 37 +++++++++++++++++++++++++++++++++----
 1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index d5833b026..07ce22417 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -7741,10 +7741,21 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
 
     /* Save some mount points because we want to share them with the host */
     for (i = 0; i < ndevMountsPath; i++) {
+        struct stat sb;
+
         if (devMountsSavePath[i] == devPath)
             continue;
 
-        if (virFileMakePath(devMountsSavePath[i]) < 0) {
+        if (stat(devMountsPath[i], &sb) < 0) {
+            virReportSystemError(errno,
+                                 _("Unable to stat: %s"),
+                                 devMountsPath[i]);
+            goto cleanup;
+        }
+
+        /* At this point, devMountsPath is either a regular file or a directory. */
+        if ((S_ISDIR(sb.st_mode) && virFileMakePath(devMountsSavePath[i]) < 0) ||
+            (S_ISREG(sb.st_mode) && virFileTouch(devMountsSavePath[i], sb.st_mode) < 0)) {
             virReportSystemError(errno,
                                  _("Failed to create %s"),
                                  devMountsSavePath[i]);
@@ -7780,15 +7791,33 @@ qemuDomainBuildNamespace(virQEMUDriverConfigPtr cfg,
         goto cleanup;
 
     for (i = 0; i < ndevMountsPath; i++) {
+        struct stat sb;
+
         if (devMountsSavePath[i] == devPath)
             continue;
 
-        if (virFileMakePath(devMountsPath[i]) < 0) {
-            virReportSystemError(errno, _("Cannot create %s"),
-                                 devMountsPath[i]);
+        if (stat(devMountsSavePath[i], &sb) < 0) {
+            virReportSystemError(errno,
+                                 _("Unable to stat: %s"),
+                                 devMountsSavePath[i]);
             goto cleanup;
         }
 
+        if (S_ISDIR(sb.st_mode)) {
+            if (virFileMakePath(devMountsPath[i]) < 0) {
+                virReportSystemError(errno, _("Cannot create %s"),
+                                     devMountsPath[i]);
+                goto cleanup;
+            }
+        } else {
+            if (virFileMakeParentPath(devMountsPath[i]) < 0 ||
+                virFileTouch(devMountsPath[i], sb.st_mode) < 0) {
+                virReportSystemError(errno, _("Cannot create %s"),
+                                     devMountsPath[i]);
+                goto cleanup;
+            }
+        }
+
         if (virFileMoveMount(devMountsSavePath[i], devMountsPath[i]) < 0)
             goto cleanup;
     }
-- 
2.11.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemuDomainBuildNamespace: Handle file mount points
Posted by Daniel P. Berrange 7 years ago
On Mon, Mar 13, 2017 at 01:37:48PM +0100, Michal Privoznik wrote:
> https://bugzilla.redhat.com/show_bug.cgi?id=1431112
> 
> Yeah, that's right. A mount point doesn't have to be a directory.
> It can be a file too. However, the code that tries to preserve
> mount points under /dev for new namespace for qemu does not count
> with that option.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_domain.c | 37 +++++++++++++++++++++++++++++++++----
>  1 file changed, 33 insertions(+), 4 deletions(-)

ACK, looks correct to me.


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list