From: Michal Privoznik Date: Fri, 4 Oct 2019 19:01:49 +0000 (+0200) Subject: virfile: Handle directories in virFileBindMountDevice() X-Git-Tag: v6.2.0-rc1~107 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed8c503ae8166eeef9ba5c1f51bcc187b0b444b8;p=thirdparty%2Flibvirt.git virfile: Handle directories in virFileBindMountDevice() The @src is not always a file. It may also be a directory (for instance qemuDomainCreateDeviceRecursive() assumes that) - even though it doesn't happen usually. Anyway, mount() can mount only a dir onto a dir and a file onto a file. Signed-off-by: Michal Privoznik Reviewed-by: Pavel Mores --- diff --git a/src/util/virfile.c b/src/util/virfile.c index 0f31554323..20260a2e58 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3743,8 +3743,17 @@ int virFileBindMountDevice(const char *src, const char *dst) { - if (virFileTouch(dst, 0666) < 0) - return -1; + if (!virFileExists(dst)) { + if (virFileIsDir(src)) { + if (virFileMakePath(dst) < 0) { + virReportSystemError(errno, _("Unable to make dir %s"), dst); + return -1; + } + } else { + if (virFileTouch(dst, 0666) < 0) + return -1; + } + } if (mount(src, dst, "none", MS_BIND, NULL) < 0) { virReportSystemError(errno, _("Failed to bind %s on to %s"), src,