|
|
a41c76 |
From d4f90466fc4685b72ae9ca4bae1d022c04f0e2be Mon Sep 17 00:00:00 2001
|
|
|
a41c76 |
Message-Id: <d4f90466fc4685b72ae9ca4bae1d022c04f0e2be@dist-git>
|
|
|
a41c76 |
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
|
|
|
a41c76 |
Date: Wed, 4 Mar 2020 12:42:46 +0100
|
|
|
a41c76 |
Subject: [PATCH] qemu: add code for handling virtiofsd
|
|
|
a41c76 |
MIME-Version: 1.0
|
|
|
a41c76 |
Content-Type: text/plain; charset=UTF-8
|
|
|
a41c76 |
Content-Transfer-Encoding: 8bit
|
|
|
a41c76 |
|
|
|
a41c76 |
Start virtiofsd for each <filesystem> device using it.
|
|
|
a41c76 |
|
|
|
a41c76 |
Pre-create the socket for communication with QEMU and pass it
|
|
|
a41c76 |
to virtiofsd.
|
|
|
a41c76 |
|
|
|
a41c76 |
Note that virtiofsd needs to run as root.
|
|
|
a41c76 |
|
|
|
a41c76 |
https://bugzilla.redhat.com/show_bug.cgi?id=1694166
|
|
|
a41c76 |
|
|
|
a41c76 |
Introduced by QEMU commit a43efa34c7d7b628cbf1ec0fe60043e5c91043ea
|
|
|
a41c76 |
|
|
|
a41c76 |
Signed-off-by: Ján Tomko <jtomko@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
a41c76 |
Tested-by: Andrea Bolognani <abologna@redhat.com>
|
|
|
a41c76 |
(cherry picked from commit f0f986efa8a8e352fbdce7079ec440a4f3c8f522)
|
|
|
a41c76 |
Signed-off-by: Ján Tomko <jtomko@redhat.com>
|
|
|
a41c76 |
https://bugzilla.redhat.com/show_bug.cgi?id=1694166
|
|
|
a41c76 |
Message-Id: <78ba169fbe59c5307db462ad78b65b06776d64a6.1583322091.git.jtomko@redhat.com>
|
|
|
a41c76 |
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
a41c76 |
---
|
|
|
a41c76 |
po/POTFILES.in | 1 +
|
|
|
a41c76 |
src/qemu/Makefile.inc.am | 2 +
|
|
|
a41c76 |
src/qemu/qemu_domain.c | 5 +-
|
|
|
a41c76 |
src/qemu/qemu_domain.h | 2 +-
|
|
|
a41c76 |
src/qemu/qemu_extdevice.c | 20 ++-
|
|
|
a41c76 |
src/qemu/qemu_virtiofs.c | 301 ++++++++++++++++++++++++++++++++++++++
|
|
|
a41c76 |
src/qemu/qemu_virtiofs.h | 37 +++++
|
|
|
a41c76 |
tests/qemuxml2argvtest.c | 11 ++
|
|
|
a41c76 |
8 files changed, 376 insertions(+), 3 deletions(-)
|
|
|
a41c76 |
create mode 100644 src/qemu/qemu_virtiofs.c
|
|
|
a41c76 |
create mode 100644 src/qemu/qemu_virtiofs.h
|
|
|
a41c76 |
|
|
|
a41c76 |
diff --git a/po/POTFILES.in b/po/POTFILES.in
|
|
|
a41c76 |
index faf173584e..29984042f4 100644
|
|
|
a41c76 |
--- a/po/POTFILES.in
|
|
|
a41c76 |
+++ b/po/POTFILES.in
|
|
|
a41c76 |
@@ -169,6 +169,7 @@
|
|
|
a41c76 |
@SRCDIR@/src/qemu/qemu_tpm.c
|
|
|
a41c76 |
@SRCDIR@/src/qemu/qemu_vhost_user.c
|
|
|
a41c76 |
@SRCDIR@/src/qemu/qemu_vhost_user_gpu.c
|
|
|
a41c76 |
+@SRCDIR@/src/qemu/qemu_virtiofs.c
|
|
|
a41c76 |
@SRCDIR@/src/remote/remote_daemon.c
|
|
|
a41c76 |
@SRCDIR@/src/remote/remote_daemon_config.c
|
|
|
a41c76 |
@SRCDIR@/src/remote/remote_daemon_dispatch.c
|
|
|
a41c76 |
diff --git a/src/qemu/Makefile.inc.am b/src/qemu/Makefile.inc.am
|
|
|
a41c76 |
index 967f6e75a2..77786526ea 100644
|
|
|
a41c76 |
--- a/src/qemu/Makefile.inc.am
|
|
|
a41c76 |
+++ b/src/qemu/Makefile.inc.am
|
|
|
a41c76 |
@@ -67,6 +67,8 @@ QEMU_DRIVER_SOURCES = \
|
|
|
a41c76 |
qemu/qemu_vhost_user.h \
|
|
|
a41c76 |
qemu/qemu_vhost_user_gpu.c \
|
|
|
a41c76 |
qemu/qemu_vhost_user_gpu.h \
|
|
|
a41c76 |
+ qemu/qemu_virtiofs.c \
|
|
|
a41c76 |
+ qemu/qemu_virtiofs.h \
|
|
|
a41c76 |
qemu/qemu_checkpoint.c \
|
|
|
a41c76 |
qemu/qemu_checkpoint.h \
|
|
|
a41c76 |
qemu/qemu_backup.c \
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
|
|
|
a41c76 |
index 79d8de2e42..3cbe7ef6e1 100644
|
|
|
a41c76 |
--- a/src/qemu/qemu_domain.c
|
|
|
a41c76 |
+++ b/src/qemu/qemu_domain.c
|
|
|
a41c76 |
@@ -1440,8 +1440,11 @@ qemuDomainFSPrivateNew(void)
|
|
|
a41c76 |
|
|
|
a41c76 |
|
|
|
a41c76 |
static void
|
|
|
a41c76 |
-qemuDomainFSPrivateDispose(void *obj G_GNUC_UNUSED)
|
|
|
a41c76 |
+qemuDomainFSPrivateDispose(void *obj)
|
|
|
a41c76 |
{
|
|
|
a41c76 |
+ qemuDomainFSPrivatePtr priv = obj;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ g_free(priv->vhostuser_fs_sock);
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
static virClassPtr qemuDomainVideoPrivateClass;
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
|
|
|
a41c76 |
index c581b3a162..83150e4e6d 100644
|
|
|
a41c76 |
--- a/src/qemu/qemu_domain.h
|
|
|
a41c76 |
+++ b/src/qemu/qemu_domain.h
|
|
|
a41c76 |
@@ -568,7 +568,7 @@ typedef qemuDomainFSPrivate *qemuDomainFSPrivatePtr;
|
|
|
a41c76 |
struct _qemuDomainFSPrivate {
|
|
|
a41c76 |
virObject parent;
|
|
|
a41c76 |
|
|
|
a41c76 |
- int dummy;
|
|
|
a41c76 |
+ char *vhostuser_fs_sock;
|
|
|
a41c76 |
};
|
|
|
a41c76 |
|
|
|
a41c76 |
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
|
|
|
a41c76 |
index bb73787b8d..bfa770f45a 100644
|
|
|
a41c76 |
--- a/src/qemu/qemu_extdevice.c
|
|
|
a41c76 |
+++ b/src/qemu/qemu_extdevice.c
|
|
|
a41c76 |
@@ -20,11 +20,13 @@
|
|
|
a41c76 |
|
|
|
a41c76 |
#include <config.h>
|
|
|
a41c76 |
|
|
|
a41c76 |
+#include "qemu_command.h"
|
|
|
a41c76 |
#include "qemu_extdevice.h"
|
|
|
a41c76 |
#include "qemu_vhost_user_gpu.h"
|
|
|
a41c76 |
#include "qemu_domain.h"
|
|
|
a41c76 |
#include "qemu_tpm.h"
|
|
|
a41c76 |
#include "qemu_slirp.h"
|
|
|
a41c76 |
+#include "qemu_virtiofs.h"
|
|
|
a41c76 |
|
|
|
a41c76 |
#include "viralloc.h"
|
|
|
a41c76 |
#include "virlog.h"
|
|
|
a41c76 |
@@ -153,7 +155,7 @@ qemuExtDevicesCleanupHost(virQEMUDriverPtr driver,
|
|
|
a41c76 |
int
|
|
|
a41c76 |
qemuExtDevicesStart(virQEMUDriverPtr driver,
|
|
|
a41c76 |
virDomainObjPtr vm,
|
|
|
a41c76 |
- virLogManagerPtr logManager G_GNUC_UNUSED,
|
|
|
a41c76 |
+ virLogManagerPtr logManager,
|
|
|
a41c76 |
bool incomingMigration)
|
|
|
a41c76 |
{
|
|
|
a41c76 |
virDomainDefPtr def = vm->def;
|
|
|
a41c76 |
@@ -183,6 +185,15 @@ qemuExtDevicesStart(virQEMUDriverPtr driver,
|
|
|
a41c76 |
return -1;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
+ for (i = 0; i < def->nfss; i++) {
|
|
|
a41c76 |
+ virDomainFSDefPtr fs = def->fss[i];
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
|
|
|
a41c76 |
+ if (qemuVirtioFSStart(logManager, driver, vm, fs) < 0)
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
return 0;
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
@@ -214,6 +225,13 @@ qemuExtDevicesStop(virQEMUDriverPtr driver,
|
|
|
a41c76 |
if (slirp)
|
|
|
a41c76 |
qemuSlirpStop(slirp, vm, driver, net, false);
|
|
|
a41c76 |
}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ for (i = 0; i < def->nfss; i++) {
|
|
|
a41c76 |
+ virDomainFSDefPtr fs = def->fss[i];
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS)
|
|
|
a41c76 |
+ qemuVirtioFSStop(driver, vm, fs);
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c
|
|
|
a41c76 |
new file mode 100644
|
|
|
a41c76 |
index 0000000000..09ab2cef27
|
|
|
a41c76 |
--- /dev/null
|
|
|
a41c76 |
+++ b/src/qemu/qemu_virtiofs.c
|
|
|
a41c76 |
@@ -0,0 +1,301 @@
|
|
|
a41c76 |
+/*
|
|
|
a41c76 |
+ * qemu_virtiofs.c: virtiofs support
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * This library is free software; you can redistribute it and/or
|
|
|
a41c76 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
a41c76 |
+ * License as published by the Free Software Foundation; either
|
|
|
a41c76 |
+ * version 2.1 of the License, or (at your option) any later version.
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * This library is distributed in the hope that it will be useful,
|
|
|
a41c76 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
a41c76 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
a41c76 |
+ * Lesser General Public License for more details.
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
a41c76 |
+ * License along with this library. If not, see
|
|
|
a41c76 |
+ * <http://www.gnu.org/licenses/>.
|
|
|
a41c76 |
+ */
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+#include <config.h>
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+#include <sys/types.h>
|
|
|
a41c76 |
+#include <sys/stat.h>
|
|
|
a41c76 |
+#include <fcntl.h>
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+#include "logging/log_manager.h"
|
|
|
a41c76 |
+#include "virlog.h"
|
|
|
a41c76 |
+#include "qemu_command.h"
|
|
|
a41c76 |
+#include "qemu_conf.h"
|
|
|
a41c76 |
+#include "qemu_extdevice.h"
|
|
|
a41c76 |
+#include "qemu_security.h"
|
|
|
a41c76 |
+#include "qemu_virtiofs.h"
|
|
|
a41c76 |
+#include "virpidfile.h"
|
|
|
a41c76 |
+#include "virqemu.h"
|
|
|
a41c76 |
+#include "virutil.h"
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+#define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+char *
|
|
|
a41c76 |
+qemuVirtioFSCreatePidFilename(virDomainObjPtr vm,
|
|
|
a41c76 |
+ const char *alias)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ qemuDomainObjPrivatePtr priv = vm->privateData;
|
|
|
a41c76 |
+ g_autofree char *shortName = NULL;
|
|
|
a41c76 |
+ g_autofree char *name = NULL;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!(shortName = virDomainDefGetShortName(vm->def)))
|
|
|
a41c76 |
+ return NULL;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ name = g_strdup_printf("%s-%s-virtiofsd", shortName, alias);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return virPidFileBuildPath(priv->libDir, name);
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+char *
|
|
|
a41c76 |
+qemuVirtioFSCreateSocketFilename(virDomainObjPtr vm,
|
|
|
a41c76 |
+ const char *alias)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ qemuDomainObjPrivatePtr priv = vm->privateData;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return virFileBuildPath(priv->libDir, alias, "-virtiofsd.sock");
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+static char *
|
|
|
a41c76 |
+qemuVirtioFSCreateLogFilename(virQEMUDriverConfigPtr cfg,
|
|
|
a41c76 |
+ const virDomainDef *def,
|
|
|
a41c76 |
+ const char *alias)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ g_autofree char *name = NULL;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ name = g_strdup_printf("%s-%s", def->name, alias);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return virFileBuildPath(cfg->logDir, name, "-virtiofsd.log");
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+static int
|
|
|
a41c76 |
+qemuVirtioFSOpenChardev(virQEMUDriverPtr driver,
|
|
|
a41c76 |
+ virDomainObjPtr vm,
|
|
|
a41c76 |
+ const char *socket_path)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ virDomainChrSourceDefPtr chrdev = virDomainChrSourceDefNew(NULL);
|
|
|
a41c76 |
+ virDomainChrDef chr = { .source = chrdev };
|
|
|
a41c76 |
+ VIR_AUTOCLOSE fd = -1;
|
|
|
a41c76 |
+ int ret = -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ chrdev->type = VIR_DOMAIN_CHR_TYPE_UNIX;
|
|
|
a41c76 |
+ chrdev->data.nix.listen = true;
|
|
|
a41c76 |
+ chrdev->data.nix.path = g_strdup(socket_path);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (qemuSecuritySetDaemonSocketLabel(driver->securityManager, vm->def) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+ fd = qemuOpenChrChardevUNIXSocket(chrdev);
|
|
|
a41c76 |
+ if (fd < 0) {
|
|
|
a41c76 |
+ ignore_value(qemuSecurityClearSocketLabel(driver->securityManager, vm->def));
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+ if (qemuSecurityClearSocketLabel(driver->securityManager, vm->def) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (qemuSecuritySetChardevLabel(driver, vm, &chr) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ ret = fd;
|
|
|
a41c76 |
+ fd = -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ cleanup:
|
|
|
a41c76 |
+ virObjectUnref(chrdev);
|
|
|
a41c76 |
+ return ret;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+static virCommandPtr
|
|
|
a41c76 |
+qemuVirtioFSBuildCommandLine(virQEMUDriverConfigPtr cfg,
|
|
|
a41c76 |
+ virDomainFSDefPtr fs,
|
|
|
a41c76 |
+ int *fd)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ g_autoptr(virCommand) cmd = NULL;
|
|
|
a41c76 |
+ g_auto(virBuffer) opts = VIR_BUFFER_INITIALIZER;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!(cmd = virCommandNew(fs->binary)))
|
|
|
a41c76 |
+ return NULL;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ virCommandAddArgFormat(cmd, "--fd=%d", *fd);
|
|
|
a41c76 |
+ virCommandPassFD(cmd, *fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
|
|
|
a41c76 |
+ *fd = -1;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ virCommandAddArg(cmd, "-o");
|
|
|
a41c76 |
+ virBufferAddLit(&opts, "source=");
|
|
|
a41c76 |
+ virQEMUBuildBufferEscapeComma(&opts, fs->src->path);
|
|
|
a41c76 |
+ if (fs->cache)
|
|
|
a41c76 |
+ virBufferAsprintf(&opts, ",cache=%s", virDomainFSCacheModeTypeToString(fs->cache));
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (fs->xattr == VIR_TRISTATE_SWITCH_ON)
|
|
|
a41c76 |
+ virBufferAddLit(&opts, ",xattr");
|
|
|
a41c76 |
+ else if (fs->xattr == VIR_TRISTATE_SWITCH_OFF)
|
|
|
a41c76 |
+ virBufferAddLit(&opts, ",no_xattr");
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (fs->flock == VIR_TRISTATE_SWITCH_ON)
|
|
|
a41c76 |
+ virBufferAddLit(&opts, ",flock");
|
|
|
a41c76 |
+ else if (fs->flock == VIR_TRISTATE_SWITCH_OFF)
|
|
|
a41c76 |
+ virBufferAddLit(&opts, ",no_flock");
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (fs->posix_lock == VIR_TRISTATE_SWITCH_ON)
|
|
|
a41c76 |
+ virBufferAddLit(&opts, ",posix_lock");
|
|
|
a41c76 |
+ else if (fs->posix_lock == VIR_TRISTATE_SWITCH_OFF)
|
|
|
a41c76 |
+ virBufferAddLit(&opts, ",no_posix_lock");
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ virCommandAddArgBuffer(cmd, &opts);
|
|
|
a41c76 |
+ if (cfg->virtiofsdDebug)
|
|
|
a41c76 |
+ virCommandAddArg(cmd, "-d");
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ return g_steal_pointer(&cmd);
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+int
|
|
|
a41c76 |
+qemuVirtioFSStart(virLogManagerPtr logManager,
|
|
|
a41c76 |
+ virQEMUDriverPtr driver,
|
|
|
a41c76 |
+ virDomainObjPtr vm,
|
|
|
a41c76 |
+ virDomainFSDefPtr fs)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
|
|
a41c76 |
+ g_autoptr(virCommand) cmd = NULL;
|
|
|
a41c76 |
+ g_autofree char *socket_path = NULL;
|
|
|
a41c76 |
+ g_autofree char *pidfile = NULL;
|
|
|
a41c76 |
+ g_autofree char *logpath = NULL;
|
|
|
a41c76 |
+ pid_t pid = (pid_t) -1;
|
|
|
a41c76 |
+ VIR_AUTOCLOSE fd = -1;
|
|
|
a41c76 |
+ VIR_AUTOCLOSE logfd = -1;
|
|
|
a41c76 |
+ int ret = -1;
|
|
|
a41c76 |
+ int rc;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!virFileExists(fs->src->path)) {
|
|
|
a41c76 |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
a41c76 |
+ _("the virtiofs export directory '%s' does not exist"),
|
|
|
a41c76 |
+ fs->src->path);
|
|
|
a41c76 |
+ return -1;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!(pidfile = qemuVirtioFSCreatePidFilename(vm, fs->info.alias)))
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!(socket_path = qemuVirtioFSCreateSocketFilename(vm, fs->info.alias)))
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if ((fd = qemuVirtioFSOpenChardev(driver, vm, socket_path)) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ logpath = qemuVirtioFSCreateLogFilename(cfg, vm->def, fs->info.alias);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (cfg->stdioLogD) {
|
|
|
a41c76 |
+ if ((logfd = virLogManagerDomainOpenLogFile(logManager,
|
|
|
a41c76 |
+ "qemu",
|
|
|
a41c76 |
+ vm->def->uuid,
|
|
|
a41c76 |
+ vm->def->name,
|
|
|
a41c76 |
+ logpath,
|
|
|
a41c76 |
+ 0,
|
|
|
a41c76 |
+ NULL, NULL)) < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+ } else {
|
|
|
a41c76 |
+ if ((logfd = open(logpath, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR)) < 0) {
|
|
|
a41c76 |
+ virReportSystemError(errno, _("failed to create logfile %s"),
|
|
|
a41c76 |
+ logpath);
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+ if (virSetCloseExec(logfd) < 0) {
|
|
|
a41c76 |
+ virReportSystemError(errno, _("failed to set close-on-exec flag on %s"),
|
|
|
a41c76 |
+ logpath);
|
|
|
a41c76 |
+ goto error;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!(cmd = qemuVirtioFSBuildCommandLine(cfg, fs, &fd)))
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ /* so far only running as root is supported */
|
|
|
a41c76 |
+ virCommandSetUID(cmd, 0);
|
|
|
a41c76 |
+ virCommandSetGID(cmd, 0);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ virCommandSetPidFile(cmd, pidfile);
|
|
|
a41c76 |
+ virCommandSetOutputFD(cmd, &logfd);
|
|
|
a41c76 |
+ virCommandSetErrorFD(cmd, &logfd);
|
|
|
a41c76 |
+ virCommandNonblockingFDs(cmd);
|
|
|
a41c76 |
+ virCommandDaemonize(cmd);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (qemuExtDeviceLogCommand(driver, vm, cmd, "virtiofsd") < 0)
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ rc = virCommandRun(cmd, NULL);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (rc < 0) {
|
|
|
a41c76 |
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
a41c76 |
+ _("Could not start 'virtiofsd'"));
|
|
|
a41c76 |
+ goto error;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ rc = virPidFileReadPath(pidfile, &pid;;
|
|
|
a41c76 |
+ if (rc < 0) {
|
|
|
a41c76 |
+ virReportSystemError(-rc,
|
|
|
a41c76 |
+ _("Unable to read virtiofsd pidfile '%s'"),
|
|
|
a41c76 |
+ pidfile);
|
|
|
a41c76 |
+ goto error;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (virProcessKill(pid, 0) != 0) {
|
|
|
a41c76 |
+ virReportSystemError(errno, "%s",
|
|
|
a41c76 |
+ _("virtiofsd died unexpectedly"));
|
|
|
a41c76 |
+ goto error;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock = g_steal_pointer(&socket_path);
|
|
|
a41c76 |
+ ret = 0;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ cleanup:
|
|
|
a41c76 |
+ if (socket_path)
|
|
|
a41c76 |
+ unlink(socket_path);
|
|
|
a41c76 |
+ return ret;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ error:
|
|
|
a41c76 |
+ if (pid != -1)
|
|
|
a41c76 |
+ virProcessKillPainfully(pid, true);
|
|
|
a41c76 |
+ if (pidfile)
|
|
|
a41c76 |
+ unlink(pidfile);
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+void
|
|
|
a41c76 |
+qemuVirtioFSStop(virQEMUDriverPtr driver G_GNUC_UNUSED,
|
|
|
a41c76 |
+ virDomainObjPtr vm,
|
|
|
a41c76 |
+ virDomainFSDefPtr fs)
|
|
|
a41c76 |
+{
|
|
|
a41c76 |
+ g_autofree char *pidfile = NULL;
|
|
|
a41c76 |
+ virErrorPtr orig_err;
|
|
|
a41c76 |
+ pid_t pid = -1;
|
|
|
a41c76 |
+ int rc;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ virErrorPreserveLast(&orig_err);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (!(pidfile = qemuVirtioFSCreatePidFilename(vm, fs->info.alias)))
|
|
|
a41c76 |
+ goto cleanup;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ rc = virPidFileReadPathIfAlive(pidfile, &pid, NULL);
|
|
|
a41c76 |
+ if (rc >= 0 && pid != (pid_t) -1)
|
|
|
a41c76 |
+ virProcessKillPainfully(pid, true);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (unlink(pidfile) < 0 &&
|
|
|
a41c76 |
+ errno != ENOENT) {
|
|
|
a41c76 |
+ virReportSystemError(errno,
|
|
|
a41c76 |
+ _("Unable to remove stale pidfile %s"),
|
|
|
a41c76 |
+ pidfile);
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock)
|
|
|
a41c76 |
+ unlink(QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ cleanup:
|
|
|
a41c76 |
+ virErrorRestore(&orig_err);
|
|
|
a41c76 |
+}
|
|
|
a41c76 |
diff --git a/src/qemu/qemu_virtiofs.h b/src/qemu/qemu_virtiofs.h
|
|
|
a41c76 |
new file mode 100644
|
|
|
a41c76 |
index 0000000000..b2f0c57d0c
|
|
|
a41c76 |
--- /dev/null
|
|
|
a41c76 |
+++ b/src/qemu/qemu_virtiofs.h
|
|
|
a41c76 |
@@ -0,0 +1,37 @@
|
|
|
a41c76 |
+/*
|
|
|
a41c76 |
+ * qemu_virtiofs.h: virtiofs support
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * This library is free software; you can redistribute it and/or
|
|
|
a41c76 |
+ * modify it under the terms of the GNU Lesser General Public
|
|
|
a41c76 |
+ * License as published by the Free Software Foundation; either
|
|
|
a41c76 |
+ * version 2.1 of the License, or (at your option) any later version.
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * This library is distributed in the hope that it will be useful,
|
|
|
a41c76 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
a41c76 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
a41c76 |
+ * Lesser General Public License for more details.
|
|
|
a41c76 |
+ *
|
|
|
a41c76 |
+ * You should have received a copy of the GNU Lesser General Public
|
|
|
a41c76 |
+ * License along with this library. If not, see
|
|
|
a41c76 |
+ * <http://www.gnu.org/licenses/>.
|
|
|
a41c76 |
+ */
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+#pragma once
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+char *
|
|
|
a41c76 |
+qemuVirtioFSCreatePidFilename(virDomainObjPtr vm,
|
|
|
a41c76 |
+ const char *alias);
|
|
|
a41c76 |
+char *
|
|
|
a41c76 |
+qemuVirtioFSCreateSocketFilename(virDomainObjPtr vm,
|
|
|
a41c76 |
+ const char *alias);
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+int
|
|
|
a41c76 |
+qemuVirtioFSStart(virLogManagerPtr logManager,
|
|
|
a41c76 |
+ virQEMUDriverPtr driver,
|
|
|
a41c76 |
+ virDomainObjPtr vm,
|
|
|
a41c76 |
+ virDomainFSDefPtr fs);
|
|
|
a41c76 |
+void
|
|
|
a41c76 |
+qemuVirtioFSStop(virQEMUDriverPtr driver,
|
|
|
a41c76 |
+ virDomainObjPtr vm,
|
|
|
a41c76 |
+ virDomainFSDefPtr fs);
|
|
|
a41c76 |
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
|
|
|
a41c76 |
index 8215935bab..a391823090 100644
|
|
|
a41c76 |
--- a/tests/qemuxml2argvtest.c
|
|
|
a41c76 |
+++ b/tests/qemuxml2argvtest.c
|
|
|
a41c76 |
@@ -496,6 +496,17 @@ testCompareXMLToArgv(const void *data)
|
|
|
a41c76 |
}
|
|
|
a41c76 |
}
|
|
|
a41c76 |
|
|
|
a41c76 |
+ for (i = 0; i < vm->def->nfss; i++) {
|
|
|
a41c76 |
+ virDomainFSDefPtr fs = vm->def->fss[i];
|
|
|
a41c76 |
+ char *s;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ if (fs->fsdriver != VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS)
|
|
|
a41c76 |
+ continue;
|
|
|
a41c76 |
+
|
|
|
a41c76 |
+ s = g_strdup_printf("/tmp/lib/domain--1-guest/fs%zu.vhost-fs.sock", i);
|
|
|
a41c76 |
+ QEMU_DOMAIN_FS_PRIVATE(fs)->vhostuser_fs_sock = s;
|
|
|
a41c76 |
+ }
|
|
|
a41c76 |
+
|
|
|
a41c76 |
if (vm->def->vsock) {
|
|
|
a41c76 |
virDomainVsockDefPtr vsock = vm->def->vsock;
|
|
|
a41c76 |
qemuDomainVsockPrivatePtr vsockPriv =
|
|
|
a41c76 |
--
|
|
|
a41c76 |
2.25.1
|
|
|
a41c76 |
|