Make the function reusable by other vhost-user based devices.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
src/qemu/qemu_validate.c | 99 +++++++++++++++++++++-------------------
1 file changed, 51 insertions(+), 48 deletions(-)
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 88f4344df0..96fc7d4118 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1380,6 +1380,54 @@ qemuValidateDomainVirtioOptions(const virDomainVirtioOptions *virtio,
}
+static int
+qemuValidateDomainDefVhostUserRequireSharedMemory(const virDomainDef *def,
+ const char *name,
+ virQEMUCapsPtr qemuCaps)
+{
+ const char *defaultRAMId = virQEMUCapsGetMachineDefaultRAMid(qemuCaps,
+ def->virtType,
+ def->os.machine);
+ size_t numa_nodes = virDomainNumaGetNodeCount(def->numa);
+ size_t i;
+
+ if (numa_nodes == 0 &&
+ !(defaultRAMId && def->mem.access == VIR_DOMAIN_MEMORY_ACCESS_SHARED)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("'%s' requires shared memory"), name);
+ return -1;
+ }
+
+ for (i = 0; i < numa_nodes; i++) {
+ virDomainMemoryAccess node_access =
+ virDomainNumaGetNodeMemoryAccessMode(def->numa, i);
+
+ switch (node_access) {
+ case VIR_DOMAIN_MEMORY_ACCESS_DEFAULT:
+ if (def->mem.access != VIR_DOMAIN_MEMORY_ACCESS_SHARED) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("'%s' requires shared memory"), name);
+ return -1;
+ }
+ break;
+ case VIR_DOMAIN_MEMORY_ACCESS_SHARED:
+ break;
+ case VIR_DOMAIN_MEMORY_ACCESS_PRIVATE:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("'%s' requires shared memory"), name);
+ return -1;
+
+ case VIR_DOMAIN_MEMORY_ACCESS_LAST:
+ default:
+ virReportEnumRangeError(virDomainMemoryAccess, node_access);
+ return -1;
+
+ }
+ }
+ return 0;
+}
+
+
static int
qemuValidateDomainDeviceDefNetwork(const virDomainNetDef *net,
virQEMUCapsPtr qemuCaps)
@@ -3947,53 +3995,6 @@ qemuValidateDomainDeviceDefGraphics(const virDomainGraphicsDef *graphics,
}
-static int
-qemuValidateDomainDefVirtioFSSharedMemory(const virDomainDef *def,
- virQEMUCapsPtr qemuCaps)
-{
- const char *defaultRAMId = virQEMUCapsGetMachineDefaultRAMid(qemuCaps,
- def->virtType,
- def->os.machine);
- size_t numa_nodes = virDomainNumaGetNodeCount(def->numa);
- size_t i;
-
- if (numa_nodes == 0 &&
- !(defaultRAMId && def->mem.access == VIR_DOMAIN_MEMORY_ACCESS_SHARED)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("virtiofs requires shared memory"));
- return -1;
- }
-
- for (i = 0; i < numa_nodes; i++) {
- virDomainMemoryAccess node_access =
- virDomainNumaGetNodeMemoryAccessMode(def->numa, i);
-
- switch (node_access) {
- case VIR_DOMAIN_MEMORY_ACCESS_DEFAULT:
- if (def->mem.access != VIR_DOMAIN_MEMORY_ACCESS_SHARED) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("virtiofs requires shared memory"));
- return -1;
- }
- break;
- case VIR_DOMAIN_MEMORY_ACCESS_SHARED:
- break;
- case VIR_DOMAIN_MEMORY_ACCESS_PRIVATE:
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("virtiofs requires shared memory"));
- return -1;
-
- case VIR_DOMAIN_MEMORY_ACCESS_LAST:
- default:
- virReportEnumRangeError(virDomainMemoryAccess, node_access);
- return -1;
-
- }
- }
- return 0;
-}
-
-
static int
qemuValidateDomainDeviceDefFS(virDomainFSDefPtr fs,
const virDomainDef *def,
@@ -4091,8 +4092,10 @@ qemuValidateDomainDeviceDefFS(virDomainFSDefPtr fs,
_("virtiofs does not support fmode and dmode"));
return -1;
}
- if (qemuValidateDomainDefVirtioFSSharedMemory(def, qemuCaps) < 0)
+ if (qemuValidateDomainDefVhostUserRequireSharedMemory(def, "virtiofs",
+ qemuCaps) < 0) {
return -1;
+ }
if (fs->info.bootIndex &&
!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VHOST_USER_FS_BOOTINDEX)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
--
2.29.2
On Tue, Feb 02, 2021 at 16:04:08 +0100, Pavel Hrdina wrote:
> Make the function reusable by other vhost-user based devices.
Since reusability is the goal ...
>
> Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> ---
> src/qemu/qemu_validate.c | 99 +++++++++++++++++++++-------------------
> 1 file changed, 51 insertions(+), 48 deletions(-)
>
> diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
> index 88f4344df0..96fc7d4118 100644
> --- a/src/qemu/qemu_validate.c
> +++ b/src/qemu/qemu_validate.c
> @@ -1380,6 +1380,54 @@ qemuValidateDomainVirtioOptions(const virDomainVirtioOptions *virtio,
> }
>
>
> +static int
> +qemuValidateDomainDefVhostUserRequireSharedMemory(const virDomainDef *def,
> + const char *name,
> + virQEMUCapsPtr qemuCaps)
... please document the semantics of the function.
> +{
> + const char *defaultRAMId = virQEMUCapsGetMachineDefaultRAMid(qemuCaps,
> + def->virtType,
On Wed, Feb 03, 2021 at 08:45:52AM +0100, Peter Krempa wrote: > On Tue, Feb 02, 2021 at 16:04:08 +0100, Pavel Hrdina wrote: > > Make the function reusable by other vhost-user based devices. > > Since reusability is the goal ... > > > > > Signed-off-by: Pavel Hrdina <phrdina@redhat.com> > > --- > > src/qemu/qemu_validate.c | 99 +++++++++++++++++++++------------------- > > 1 file changed, 51 insertions(+), 48 deletions(-) > > > > diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c > > index 88f4344df0..96fc7d4118 100644 > > --- a/src/qemu/qemu_validate.c > > +++ b/src/qemu/qemu_validate.c > > @@ -1380,6 +1380,54 @@ qemuValidateDomainVirtioOptions(const virDomainVirtioOptions *virtio, > > } > > > > > > +static int > > +qemuValidateDomainDefVhostUserRequireSharedMemory(const virDomainDef *def, > > + const char *name, > > + virQEMUCapsPtr qemuCaps) > > ... please document the semantics of the function. Is this reasonable documentation: +/** + * qemuValidateDomainDefVhostUserRequireSharedMemory: + * @def: VM definition + * @name: name of the attribute/element + * @qemuCaps: capabilities of QEMU binary + * + * Check if the VM definition contains any form of shared memory + * which is required by vhost-user devices to operate properly. + * + * On success returns 0, on error returns -1 and reports proper error + * message. + */ Pavel
On Wed, Feb 03, 2021 at 10:10:11 +0100, Pavel Hrdina wrote: > On Wed, Feb 03, 2021 at 08:45:52AM +0100, Peter Krempa wrote: > > On Tue, Feb 02, 2021 at 16:04:08 +0100, Pavel Hrdina wrote: > > > Make the function reusable by other vhost-user based devices. > > > > Since reusability is the goal ... > > > > > > > > Signed-off-by: Pavel Hrdina <phrdina@redhat.com> > > > --- > > > src/qemu/qemu_validate.c | 99 +++++++++++++++++++++------------------- > > > 1 file changed, 51 insertions(+), 48 deletions(-) > > > [...] > Is this reasonable documentation: > > +/** > + * qemuValidateDomainDefVhostUserRequireSharedMemory: > + * @def: VM definition > + * @name: name of the attribute/element > + * @qemuCaps: capabilities of QEMU binary > + * > + * Check if the VM definition contains any form of shared memory > + * which is required by vhost-user devices to operate properly. > + * > + * On success returns 0, on error returns -1 and reports proper error > + * message. Yes, that sounds good.
© 2016 - 2026 Red Hat, Inc.