Run the daemon with --print-capabilities first, to see what it supports.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/conf/domain_conf.h | 1 +
src/qemu/qemu_vhost_user.c | 58 ++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_vhost_user.h | 12 ++++++++
src/qemu/qemu_virtiofs.c | 9 ++++--
4 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 2818a9f1f5..b3a0d26cde 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -899,6 +899,7 @@ struct _virDomainFSDef {
virDomainIdMapDef idmap;
virDomainVirtioOptions *virtio;
virObject *privateData;
+ virBitmap *caps;
};
diff --git a/src/qemu/qemu_vhost_user.c b/src/qemu/qemu_vhost_user.c
index 0294daab80..b916412bc0 100644
--- a/src/qemu/qemu_vhost_user.c
+++ b/src/qemu/qemu_vhost_user.c
@@ -22,6 +22,7 @@
#include "qemu_vhost_user.h"
#include "qemu_interop_config.h"
+#include "virbitmap.h"
#include "virjson.h"
#include "virlog.h"
#include "viralloc.h"
@@ -90,6 +91,11 @@ VIR_ENUM_IMPL(qemuVhostUserGPUFeature,
"render-node",
);
+VIR_ENUM_IMPL(qemuVhostUserFSFeature,
+ QEMU_VHOST_USER_FS_FEATURE_LAST,
+ "options",
+);
+
typedef struct _qemuVhostUserGPU qemuVhostUserGPU;
struct _qemuVhostUserGPU {
size_t nfeatures;
@@ -414,6 +420,53 @@ qemuVhostUserFillDomainGPU(virQEMUDriver *driver,
return ret;
}
+int
+qemuVhostUserFillFSCapabilities(virBitmap **caps,
+ const char *binary,
+ bool reportError G_GNUC_UNUSED)
+{
+ g_autoptr(virJSONValue) doc = NULL;
+ g_autofree char *output = NULL;
+ g_autoptr(virCommand) cmd = NULL;
+ virJSONValue *featuresJSON;
+ size_t nfeatures;
+ size_t i;
+ g_autoptr(virBitmap) features = NULL;
+
+ cmd = virCommandNewArgList(binary, "--print-capabilities", NULL);
+ virCommandSetOutputBuffer(cmd, &output);
+ if (virCommandRun(cmd, NULL) < 0)
+ return -2;
+
+ if (!(doc = virJSONValueFromString(output))) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unable to parse json capabilities '%1$s'"),
+ binary);
+ return -2;
+ }
+
+
+ /* Older virtiofsd did not print any features */
+ if (!(featuresJSON = virJSONValueObjectGetArray(doc, "features")))
+ return 0;
+
+ nfeatures = virJSONValueArraySize(featuresJSON);
+
+ for (i = 0; i < nfeatures; i++) {
+ virJSONValue *item = virJSONValueArrayGet(featuresJSON, i);
+ const char *tmpStr = virJSONValueGetString(item);
+ int tmp;
+
+ if ((tmp = qemuVhostUserFSFeatureTypeFromString(tmpStr)) <= 0) {
+ VIR_DEBUG("ignoring unknown QEMU vhost-user feature '%s'",
tmpStr);
+ continue;
+ }
+ virBitmapSetBitExpand(features, tmp);
+ }
+
+ *caps = g_steal_pointer(&features);
+ return 0;
+}
int
qemuVhostUserFillDomainFS(virQEMUDriver *driver,
@@ -435,6 +488,11 @@ qemuVhostUserFillDomainFS(virQEMUDriver *driver,
continue;
fs->binary = g_strdup(vu->binary);
+ /* todo: error? */
+ if (qemuVhostUserFillFSCapabilities(&fs->caps,
+ vu->binary,
+ false) < 0)
+ continue;
break;
}
diff --git a/src/qemu/qemu_vhost_user.h b/src/qemu/qemu_vhost_user.h
index d1aa6ca189..683c945e34 100644
--- a/src/qemu/qemu_vhost_user.h
+++ b/src/qemu/qemu_vhost_user.h
@@ -46,3 +46,15 @@ qemuVhostUserFillDomainGPU(virQEMUDriver *driver,
int
qemuVhostUserFillDomainFS(virQEMUDriver *driver,
virDomainFSDef *fs);
+
+int
+qemuVhostUserFillFSCapabilities(virBitmap **caps,
+ const char *binary,
+ bool reportError);
+typedef enum {
+ QEMU_VHOST_USER_FS_FEATURE_OPTIONS = 0,
+
+ QEMU_VHOST_USER_FS_FEATURE_LAST
+} qemuVhostUserFSFeature;
+
+VIR_ENUM_DECL(qemuVhostUserFSFeature);
diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c
index 78897d8177..aba6a19562 100644
--- a/src/qemu/qemu_virtiofs.c
+++ b/src/qemu/qemu_virtiofs.c
@@ -446,8 +446,13 @@ qemuVirtioFSPrepareDomain(virQEMUDriver *driver,
if (fs->sock)
return 0;
- if (!fs->binary && qemuVhostUserFillDomainFS(driver, fs) < 0)
- return -1;
+ if (fs->binary) {
+ if (qemuVhostUserFillFSCapabilities(&fs->caps, fs->binary, true) <
0)
+ return -1;
+ } else {
+ if (qemuVhostUserFillDomainFS(driver, fs) < 0)
+ return -1;
+ }
if (!driver->privileged && !fs->idmap.uidmap) {
if (qemuVirtioFSPrepareIdMap(fs) < 0)
--
2.45.2