We register QOM type "memory-backend-memfd" only when a test of
memfd_create() succeeds. Such conditional registration is unusual and
problematic:
1. Management applications use introspection interfaces to find out
what a certain QEMU can do. Conditional type registration makes QOM
introspection results depend on the condition, which generally makes
them valid only for the process that produced them. Undesirable.
2. For user-creatable objects like "memory-backend-memfd", it also
makes QAPI introspection unreliable: query-qmp-schema claims the type
exists (object-add argument @qom-type accepts "memory-backend-memfd")
even when it doesn't.
Conditional registration actually serves no purpose here, because we
still have to memfd_create() for real when we create the object, and
need and do handle errors then.
Register the type unconditionally.
To test, I hacked the qemu_memfd() call to fail. The error for
-object memory-backend-memfd,id=mem0,size=1m changes from
qemu-system-x86_64: invalid object type: memory-backend-memfd
to
qemu-system-x86_64: can't create 'memory-backend-memfd': failed to create
memfd with flags 0x3: Invalid argument
Signed-off-by: Markus Armbruster <[email protected]>
---
backends/hostmem-memfd.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/backends/hostmem-memfd.c b/backends/hostmem-memfd.c
index 11d456e3ebd..54f84ae331a 100644
--- a/backends/hostmem-memfd.c
+++ b/backends/hostmem-memfd.c
@@ -223,9 +223,7 @@ static const TypeInfo memfd_backend_info = {
static void register_types(void)
{
- if (qemu_memfd_check(MFD_ALLOW_SEALING)) {
- type_register_static(&memfd_backend_info);
- }
+ type_register_static(&memfd_backend_info);
}
type_init(register_types);
--
2.55.0