Re: Module/Tool/SO to convert from KVM-xml => QEMU-native?

2021-10-09 Thread Ajay Garg
For converting kvm-xml to qemu-native, qemu needs to be
installed/updated in entirety.

Doing a complete "sudo make install" for qemu, will take care of the
conversion (without touching virt-manager / kvm /libvirt).
"sudo make install" (for qemu) safely updates the older qemu-files (if
any), provided the (qeemu) build has been configured via "./configure
--prefix=/usr".

Marking this thread as closed-solved.



[PATCH v2 4/5] qapi: Implement deprecated-input={reject, crash} for enum values

2021-10-09 Thread Markus Armbruster
This copies the code implementing the policy from qapi/qmp-dispatch.c
to qapi/qobject-input-visitor.c.  Tolerable, but if we acquire more
copes, we should look into factoring them out.

Signed-off-by: Markus Armbruster 
---
 docs/devel/qapi-code-gen.rst |  6 --
 qapi/compat.json |  3 ++-
 include/qapi/util.h  |  6 +-
 qapi/qapi-visit-core.c   | 18 +++---
 scripts/qapi/types.py| 17 -
 5 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
index 00334e9fb8..006a6f4a9a 100644
--- a/docs/devel/qapi-code-gen.rst
+++ b/docs/devel/qapi-code-gen.rst
@@ -708,8 +708,10 @@ QEMU shows a certain behaviour.
 Special features
 
 
-Feature "deprecated" marks a command, event, or struct member as
-deprecated.  It is not supported elsewhere so far.
+Feature "deprecated" marks a command, event, struct or enum member as
+deprecated.  It is not supported elsewhere so far.  Interfaces so
+marked may be withdrawn in future releases in accordance with QEMU's
+deprecation policy.
 
 
 Naming rules and reserved names
diff --git a/qapi/compat.json b/qapi/compat.json
index 1d2b76f00c..74a8493d3d 100644
--- a/qapi/compat.json
+++ b/qapi/compat.json
@@ -42,7 +42,8 @@
 # with feature 'deprecated'.  We may want to extend it to cover
 # semantic aspects, CLI, and experimental features.
 #
-# Limitation: not implemented for deprecated enumeration values.
+# Limitation: deprecated-output policy @hide is not implemented for
+# enumeration values.  They behave the same as with policy @accept.
 #
 # @deprecated-input: how to handle deprecated input (default 'accept')
 # @deprecated-output: how to handle deprecated output (default 'accept')
diff --git a/include/qapi/util.h b/include/qapi/util.h
index d7bfb30e25..257c600f99 100644
--- a/include/qapi/util.h
+++ b/include/qapi/util.h
@@ -11,9 +11,13 @@
 #ifndef QAPI_UTIL_H
 #define QAPI_UTIL_H
 
+/* QEnumLookup flags */
+#define QAPI_ENUM_DEPRECATED 1
+
 typedef struct QEnumLookup {
 const char *const *array;
-int size;
+const unsigned char *const flags;
+const int size;
 } QEnumLookup;
 
 const char *qapi_enum_lookup(const QEnumLookup *lookup, int val);
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index 066f77a26d..49136ae88e 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -393,7 +393,7 @@ static bool input_type_enum(Visitor *v, const char *name, 
int *obj,
 const QEnumLookup *lookup, Error **errp)
 {
 int64_t value;
-char *enum_str;
+g_autofree char *enum_str = NULL;
 
 if (!visit_type_str(v, name, &enum_str, errp)) {
 return false;
@@ -402,11 +402,23 @@ static bool input_type_enum(Visitor *v, const char *name, 
int *obj,
 value = qapi_enum_parse(lookup, enum_str, -1, NULL);
 if (value < 0) {
 error_setg(errp, QERR_INVALID_PARAMETER, enum_str);
-g_free(enum_str);
 return false;
 }
 
-g_free(enum_str);
+if (lookup->flags && (lookup->flags[value] & QAPI_ENUM_DEPRECATED)) {
+switch (v->compat_policy.deprecated_input) {
+case COMPAT_POLICY_INPUT_ACCEPT:
+break;
+case COMPAT_POLICY_INPUT_REJECT:
+error_setg(errp, "Deprecated value '%s' disabled by policy",
+   enum_str);
+return false;
+case COMPAT_POLICY_INPUT_CRASH:
+default:
+abort();
+}
+}
+
 *obj = value;
 return true;
 }
diff --git a/scripts/qapi/types.py b/scripts/qapi/types.py
index 831294fe42..ab2441adc9 100644
--- a/scripts/qapi/types.py
+++ b/scripts/qapi/types.py
@@ -38,6 +38,8 @@
 def gen_enum_lookup(name: str,
 members: List[QAPISchemaEnumMember],
 prefix: Optional[str] = None) -> str:
+max_index = c_enum_const(name, '_MAX', prefix)
+flags = ''
 ret = mcgen('''
 
 const QEnumLookup %(c_name)s_lookup = {
@@ -52,13 +54,26 @@ def gen_enum_lookup(name: str,
 ''',
  index=index, name=memb.name)
 ret += memb.ifcond.gen_endif()
+if 'deprecated' in (f.name for f in memb.features):
+flags += mcgen('''
+[%(index)s] = QAPI_ENUM_DEPRECATED,
+''',
+   index=index)
+
+if flags:
+ret += mcgen('''
+},
+.flags = (const unsigned char[%(max_index)s]) {
+''',
+ max_index=max_index)
+ret += flags
 
 ret += mcgen('''
 },
 .size = %(max_index)s
 };
 ''',
- max_index=c_enum_const(name, '_MAX', prefix))
+ max_index=max_index)
 return ret
 
 
-- 
2.31.1



[PATCH RFC v2 5/5] block: Deprecate transaction type drive-backup

2021-10-09 Thread Markus Armbruster
Several moons ago, Vladimir posted

Subject: [PATCH v2 3/3] qapi: deprecate drive-backup
Date: Wed,  5 May 2021 16:58:03 +0300
Message-Id: <20210505135803.67896-4-vsement...@virtuozzo.com>
https://lists.gnu.org/archive/html/qemu-devel/2021-05/msg01394.html

with this

TODO: We also need to deprecate drive-backup transaction action..
But union members in QAPI doesn't support 'deprecated' feature. I tried
to dig a bit, but failed :/ Markus, could you please help with it? At
least by advice?

This is one way to resolve it.  Sorry it took so long.

John explored another way, namely adding feature flags to union
branches.  Could also be useful, say to add different features to
branches in multiple unions sharing the same tag enum.

Signed-off-by: Markus Armbruster 
---
 qapi/transaction.json | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/qapi/transaction.json b/qapi/transaction.json
index d175b5f863..0564a893b3 100644
--- a/qapi/transaction.json
+++ b/qapi/transaction.json
@@ -54,6 +54,9 @@
 # @blockdev-snapshot-sync: since 1.1
 # @drive-backup: Since 1.6
 #
+# Features:
+# @deprecated: Member @drive-backup is deprecated.  Use FIXME instead.
+#
 # Since: 1.1
 ##
 { 'enum': 'TransactionActionKind',
@@ -62,7 +65,7 @@
 'block-dirty-bitmap-disable', 'block-dirty-bitmap-merge',
 'blockdev-backup', 'blockdev-snapshot',
 'blockdev-snapshot-internal-sync', 'blockdev-snapshot-sync',
-'drive-backup' ] }
+{ 'name': 'drive-backup', 'features': [ 'deprecated' ] } ] }
 
 ##
 # @AbortWrapper:
-- 
2.31.1



[PATCH v2 2/5] qapi: Add feature flags to enum members

2021-10-09 Thread Markus Armbruster
This is quite similar to commit 84ab008687 "qapi: Add feature flags to
struct members", only for enums instead of structs.

Special feature flag 'deprecated' is silently ignored there.  This is
okay only because it will be implemented shortly.

Signed-off-by: Markus Armbruster 
Reviewed-by: Eric Blake 
---
 docs/devel/qapi-code-gen.rst  |  4 +++-
 qapi/compat.json  |  2 ++
 qapi/introspect.json  |  5 -
 scripts/qapi/expr.py  |  3 ++-
 scripts/qapi/introspect.py|  5 +++--
 scripts/qapi/schema.py| 22 +--
 tests/qapi-schema/doc-good.json   |  5 -
 tests/qapi-schema/doc-good.out|  3 +++
 tests/qapi-schema/doc-good.txt|  3 +++
 .../qapi-schema/enum-dict-member-unknown.err  |  2 +-
 tests/qapi-schema/qapi-schema-test.json   |  3 ++-
 tests/qapi-schema/qapi-schema-test.out|  1 +
 tests/qapi-schema/test-qapi.py|  1 +
 13 files changed, 49 insertions(+), 10 deletions(-)

diff --git a/docs/devel/qapi-code-gen.rst b/docs/devel/qapi-code-gen.rst
index b2569de486..00334e9fb8 100644
--- a/docs/devel/qapi-code-gen.rst
+++ b/docs/devel/qapi-code-gen.rst
@@ -200,7 +200,9 @@ Syntax::
  '*if': COND,
  '*features': FEATURES }
 ENUM-VALUE = STRING
-   | { 'name': STRING, '*if': COND }
+   | { 'name': STRING,
+   '*if': COND,
+   '*features': FEATURES }
 
 Member 'enum' names the enum type.
 
diff --git a/qapi/compat.json b/qapi/compat.json
index ae3afc22df..1d2b76f00c 100644
--- a/qapi/compat.json
+++ b/qapi/compat.json
@@ -42,6 +42,8 @@
 # with feature 'deprecated'.  We may want to extend it to cover
 # semantic aspects, CLI, and experimental features.
 #
+# Limitation: not implemented for deprecated enumeration values.
+#
 # @deprecated-input: how to handle deprecated input (default 'accept')
 # @deprecated-output: how to handle deprecated output (default 'accept')
 #
diff --git a/qapi/introspect.json b/qapi/introspect.json
index f806bd7281..4a3b76464e 100644
--- a/qapi/introspect.json
+++ b/qapi/introspect.json
@@ -163,10 +163,13 @@
 #
 # @name: the member's name, as defined in the QAPI schema.
 #
+# @features: names of features associated with the member, in no
+#particular order.
+#
 # Since: 6.2
 ##
 { 'struct': 'SchemaInfoEnumMember',
-  'data': { 'name': 'str' } }
+  'data': { 'name': 'str', '*features': [ 'str' ] } }
 
 ##
 # @SchemaInfoArray:
diff --git a/scripts/qapi/expr.py b/scripts/qapi/expr.py
index 819ea6ad97..3cb389e875 100644
--- a/scripts/qapi/expr.py
+++ b/scripts/qapi/expr.py
@@ -472,7 +472,7 @@ def check_enum(expr: _JSONObject, info: QAPISourceInfo) -> 
None:
   for m in members]
 for member in members:
 source = "'data' member"
-check_keys(member, info, source, ['name'], ['if'])
+check_keys(member, info, source, ['name'], ['if', 'features'])
 member_name = member['name']
 check_name_is_str(member_name, info, source)
 source = "%s '%s'" % (source, member_name)
@@ -483,6 +483,7 @@ def check_enum(expr: _JSONObject, info: QAPISourceInfo) -> 
None:
  permit_upper=permissive,
  permit_underscore=permissive)
 check_if(member, info, source)
+check_features(member.get('features'), info)
 
 
 def check_struct(expr: _JSONObject, info: QAPISourceInfo) -> None:
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index 6334546363..67c7d89aae 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -275,12 +275,13 @@ def _gen_tree(self, name: str, mtype: str, obj: Dict[str, 
object],
 obj['features'] = self._gen_features(features)
 self._trees.append(Annotated(obj, ifcond, comment))
 
-@staticmethod
-def _gen_enum_member(member: QAPISchemaEnumMember
+def _gen_enum_member(self, member: QAPISchemaEnumMember
  ) -> Annotated[SchemaInfoEnumMember]:
 obj: SchemaInfoEnumMember = {
 'name': member.name,
 }
+if member.features:
+obj['features'] = self._gen_features(member.features)
 return Annotated(obj, member.ifcond)
 
 def _gen_object_member(self, member: QAPISchemaObjectTypeMember
diff --git a/scripts/qapi/schema.py b/scripts/qapi/schema.py
index 004d7095ff..6d5f46509a 100644
--- a/scripts/qapi/schema.py
+++ b/scripts/qapi/schema.py
@@ -708,6 +708,19 @@ def describe(self, info):
 class QAPISchemaEnumMember(QAPISchemaMember):
 role = 'value'
 
+def __init__(self, name, info, ifcond=None, features=None):
+super().__init__(name, info, ifcond)
+for f in features or []:
+assert isinstance(f, QAPISchemaFeature)
+f.set_defined_in(name)
+self.features = features or []
+
+

[PATCH v2 0/5] qapi: Add feature flags to enum members

2021-10-09 Thread Markus Armbruster
PATCH 1+2 add feature flags to enum members.  Awkward due to an
introspection design mistake; see PATCH 1 for details.

PATCH 3+4 implement policy deprecated-input={reject,crash} for enum
values.

Policy deprecated-output=hide is not implemented, because we can't
hide a value without hiding the entire member, which is almost
certainly more than the requester of this policy bargained for.
Perhaps we want a new policy deprecated-output=hide-or-else-crash to
help us catch unwanted use of deprecated enum values.  Perhaps we want
deprecated-output=hide to behave that way together with
deprecated-input=crash.  Or even always.  Thoughts?

PATCH 5 puts the new feature flags to use.  It's RFC because it makes
sense only on top of Vladimir's deprecation of drive-backup.  See its
commit message for a reference.

I prefer to commit new features together with a use outside tests/.
PATCH 5 adds such a use, but it's RFC, because it depends on
Vladimir's work.  Perhaps another use pops up.  I can delay this work
in the hope of a use becoming ready, but the feature flags work I have
in the pipeline will eventually force my hand.

v2:
* Rebased with straightforward conflicts.
* PATCH 1-4: No longer RFC.
* PATCH 1: "Since" information fixed [Eric].  Commit message updated
  to reflect feedback.
* PATCH 2: Commit message amended to point out special feature flag
 'deprecated' is ignored at this stage.
* PATCH 4: Documentation updated.  Commit message tweaked.

Markus Armbruster (5):
  qapi: Enable enum member introspection to show more than name
  qapi: Add feature flags to enum members
  qapi: Move compat policy from QObject to generic visitor
  qapi: Implement deprecated-input={reject,crash} for enum values
  block: Deprecate transaction type drive-backup

 docs/devel/qapi-code-gen.rst  | 10 ---
 qapi/compat.json  |  3 +++
 qapi/introspect.json  | 24 +++--
 qapi/transaction.json |  5 +++-
 include/qapi/qobject-input-visitor.h  |  4 ---
 include/qapi/qobject-output-visitor.h |  4 ---
 include/qapi/util.h   |  6 -
 include/qapi/visitor-impl.h   |  3 +++
 include/qapi/visitor.h|  9 +++
 qapi/qapi-visit-core.c| 27 ---
 qapi/qmp-dispatch.c   |  4 +--
 qapi/qobject-input-visitor.c  | 14 +-
 qapi/qobject-output-visitor.c | 14 +-
 scripts/qapi/expr.py  |  3 ++-
 scripts/qapi/introspect.py| 19 ++---
 scripts/qapi/schema.py| 22 +--
 scripts/qapi/types.py | 17 +++-
 tests/qapi-schema/doc-good.json   |  5 +++-
 tests/qapi-schema/doc-good.out|  3 +++
 tests/qapi-schema/doc-good.txt|  3 +++
 .../qapi-schema/enum-dict-member-unknown.err  |  2 +-
 tests/qapi-schema/qapi-schema-test.json   |  3 ++-
 tests/qapi-schema/qapi-schema-test.out|  1 +
 tests/qapi-schema/test-qapi.py|  1 +
 24 files changed, 149 insertions(+), 57 deletions(-)

-- 
2.31.1



[PATCH v2 3/5] qapi: Move compat policy from QObject to generic visitor

2021-10-09 Thread Markus Armbruster
The next commit needs to access compat policy from the generic visitor
core.  Move it there from qobject input and output visitor.

Signed-off-by: Markus Armbruster 
Reviewed-by: Eric Blake 
---
 include/qapi/qobject-input-visitor.h  |  4 
 include/qapi/qobject-output-visitor.h |  4 
 include/qapi/visitor-impl.h   |  3 +++
 include/qapi/visitor.h|  9 +
 qapi/qapi-visit-core.c|  9 +
 qapi/qmp-dispatch.c   |  4 ++--
 qapi/qobject-input-visitor.c  | 14 +-
 qapi/qobject-output-visitor.c | 14 +-
 8 files changed, 25 insertions(+), 36 deletions(-)

diff --git a/include/qapi/qobject-input-visitor.h 
b/include/qapi/qobject-input-visitor.h
index 8d69388810..95985e25e5 100644
--- a/include/qapi/qobject-input-visitor.h
+++ b/include/qapi/qobject-input-visitor.h
@@ -15,7 +15,6 @@
 #ifndef QOBJECT_INPUT_VISITOR_H
 #define QOBJECT_INPUT_VISITOR_H
 
-#include "qapi/qapi-types-compat.h"
 #include "qapi/visitor.h"
 
 typedef struct QObjectInputVisitor QObjectInputVisitor;
@@ -59,9 +58,6 @@ typedef struct QObjectInputVisitor QObjectInputVisitor;
  */
 Visitor *qobject_input_visitor_new(QObject *obj);
 
-void qobject_input_visitor_set_policy(Visitor *v,
-  CompatPolicyInput deprecated);
-
 /*
  * Create a QObject input visitor for @obj for use with keyval_parse()
  *
diff --git a/include/qapi/qobject-output-visitor.h 
b/include/qapi/qobject-output-visitor.h
index f2a2f92a00..2b1726baf5 100644
--- a/include/qapi/qobject-output-visitor.h
+++ b/include/qapi/qobject-output-visitor.h
@@ -15,7 +15,6 @@
 #define QOBJECT_OUTPUT_VISITOR_H
 
 #include "qapi/visitor.h"
-#include "qapi/qapi-types-compat.h"
 
 typedef struct QObjectOutputVisitor QObjectOutputVisitor;
 
@@ -54,7 +53,4 @@ typedef struct QObjectOutputVisitor QObjectOutputVisitor;
  */
 Visitor *qobject_output_visitor_new(QObject **result);
 
-void qobject_output_visitor_set_policy(Visitor *v,
-   CompatPolicyOutput deprecated);
-
 #endif
diff --git a/include/qapi/visitor-impl.h b/include/qapi/visitor-impl.h
index 3b950f6e3d..72b6537bef 100644
--- a/include/qapi/visitor-impl.h
+++ b/include/qapi/visitor-impl.h
@@ -122,6 +122,9 @@ struct Visitor
 /* Must be set */
 VisitorType type;
 
+/* Optional */
+struct CompatPolicy compat_policy;
+
 /* Must be set for output visitors, optional otherwise. */
 void (*complete)(Visitor *v, void *opaque);
 
diff --git a/include/qapi/visitor.h b/include/qapi/visitor.h
index b3c9ef7a81..dcb96018a9 100644
--- a/include/qapi/visitor.h
+++ b/include/qapi/visitor.h
@@ -16,6 +16,7 @@
 #define QAPI_VISITOR_H
 
 #include "qapi/qapi-builtin-types.h"
+#include "qapi/qapi-types-compat.h"
 
 /*
  * The QAPI schema defines both a set of C data types, and a QMP wire
@@ -477,6 +478,14 @@ bool visit_deprecated_accept(Visitor *v, const char *name, 
Error **errp);
  */
 bool visit_deprecated(Visitor *v, const char *name);
 
+/*
+ * Set policy for handling deprecated management interfaces.
+ *
+ * Intended use: call visit_set_policy(v, &compat_policy) when
+ * visiting management interface input or output.
+ */
+void visit_set_policy(Visitor *v, CompatPolicy *policy);
+
 /*
  * Visit an enum value.
  *
diff --git a/qapi/qapi-visit-core.c b/qapi/qapi-visit-core.c
index a641adec51..066f77a26d 100644
--- a/qapi/qapi-visit-core.c
+++ b/qapi/qapi-visit-core.c
@@ -19,6 +19,10 @@
 #include "qapi/visitor-impl.h"
 #include "trace.h"
 
+/* Zero-initialization must result in default policy */
+QEMU_BUILD_BUG_ON(COMPAT_POLICY_INPUT_ACCEPT || COMPAT_POLICY_OUTPUT_ACCEPT);
+
+
 void visit_complete(Visitor *v, void *opaque)
 {
 assert(v->type != VISITOR_OUTPUT || v->complete);
@@ -153,6 +157,11 @@ bool visit_deprecated(Visitor *v, const char *name)
 return true;
 }
 
+void visit_set_policy(Visitor *v, CompatPolicy *policy)
+{
+v->compat_policy = *policy;
+}
+
 bool visit_is_input(Visitor *v)
 {
 return v->type == VISITOR_INPUT;
diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c
index 59600210ce..7e943a0af5 100644
--- a/qapi/qmp-dispatch.c
+++ b/qapi/qmp-dispatch.c
@@ -32,7 +32,7 @@ Visitor *qobject_input_visitor_new_qmp(QObject *obj)
 {
 Visitor *v = qobject_input_visitor_new(obj);
 
-qobject_input_visitor_set_policy(v, compat_policy.deprecated_input);
+visit_set_policy(v, &compat_policy);
 return v;
 }
 
@@ -40,7 +40,7 @@ Visitor *qobject_output_visitor_new_qmp(QObject **result)
 {
 Visitor *v = qobject_output_visitor_new(result);
 
-qobject_output_visitor_set_policy(v, compat_policy.deprecated_output);
+visit_set_policy(v, &compat_policy);
 return v;
 }
 
diff --git a/qapi/qobject-input-visitor.c b/qapi/qobject-input-visitor.c
index 04b790412e..71b24a4429 100644
--- a/qapi/qobject-input-visitor.c
+++ b/qapi/qobject-input-visitor.c
@@ -14,7 +14,6 @@
 
 #include "qemu/osdep.h"
 #include 
-#include "qapi/compat-p

[PATCH v2 1/5] qapi: Enable enum member introspection to show more than name

2021-10-09 Thread Markus Armbruster
The next commit will add feature flags to enum members.  There's a
problem, though: query-qmp-schema shows an enum type's members as an
array of member names (SchemaInfoEnum member @values).  If it showed
an array of objects with a name member, we could simply add more
members to these objects.  Since it's just strings, we can't.

I can see three ways to correct this design mistake:

1. Do it the way we should have done it, plus compatibility goo.

   We want a ['SchemaInfoEnumMember'] member in SchemaInfoEnum.  Since
   changing @values would be a compatibility break, add a new member
   @members instead.

   @values is now redundant.  In my testing, output of
   qemu-system-x86_64's query-qmp-schema grows by 11% (18.5KiB).

   We can deprecate @values now and drop it later.  This will break
   outmoded clients.  Well-behaved clients such as libvirt are
   expected to break cleanly.

2. Like 1, but omit "boring" elements of @member, and empty @member.

   @values does not become redundant.  @members augments it.  Somewhat
   cumbersome, but output of query-qmp-schema grows only as we make
   enum members non-boring.

   There is nothing to deprecate here.

3. Versioned query-qmp-schema.

   query-qmp-schema provides either @values or @members.  The QMP
   client can select which version it wants.  There is no redundant
   output.

   We can deprecate old versions and eventually drop them.  This will
   break outmoded clients.  Breaking cleanly is easier than for 1.

   While 1 and 2 operate within the common rules for compatible
   evolution apply (section "Compatibility considerations" in
   docs/devel/qapi-code-gen.rst), 3 bypasses them.  Attractive when
   operating within the rules is just too awkward.  Not the case here.

This commit implements 1.  Libvirt developers prefer it.

Signed-off-by: Markus Armbruster 
---
 qapi/introspect.json   | 21 +++--
 scripts/qapi/introspect.py | 18 ++
 2 files changed, 33 insertions(+), 6 deletions(-)

diff --git a/qapi/introspect.json b/qapi/introspect.json
index 39bd303778..f806bd7281 100644
--- a/qapi/introspect.json
+++ b/qapi/introspect.json
@@ -142,14 +142,31 @@
 #
 # Additional SchemaInfo members for meta-type 'enum'.
 #
-# @values: the enumeration type's values, in no particular order.
+# @members: the enum type's members, in no particular order
+#   (since 6.2).
+#
+# @values: the enumeration type's member names, in no particular order.
+#  Redundant with @members.  Just for backward compatibility.
 #
 # Values of this type are JSON string on the wire.
 #
 # Since: 2.5
 ##
 { 'struct': 'SchemaInfoEnum',
-  'data': { 'values': ['str'] } }
+  'data': { 'members': [ 'SchemaInfoEnumMember' ],
+'values': ['str'] } }
+
+##
+# @SchemaInfoEnumMember:
+#
+# An object member.
+#
+# @name: the member's name, as defined in the QAPI schema.
+#
+# Since: 6.2
+##
+{ 'struct': 'SchemaInfoEnumMember',
+  'data': { 'name': 'str' } }
 
 ##
 # @SchemaInfoArray:
diff --git a/scripts/qapi/introspect.py b/scripts/qapi/introspect.py
index 4c079ee627..6334546363 100644
--- a/scripts/qapi/introspect.py
+++ b/scripts/qapi/introspect.py
@@ -68,6 +68,7 @@
 # TypedDict constructs, so they are broadly typed here as simple
 # Python Dicts.
 SchemaInfo = Dict[str, object]
+SchemaInfoEnumMember = Dict[str, object]
 SchemaInfoObject = Dict[str, object]
 SchemaInfoObjectVariant = Dict[str, object]
 SchemaInfoObjectMember = Dict[str, object]
@@ -274,8 +275,16 @@ def _gen_tree(self, name: str, mtype: str, obj: Dict[str, 
object],
 obj['features'] = self._gen_features(features)
 self._trees.append(Annotated(obj, ifcond, comment))
 
-def _gen_member(self, member: QAPISchemaObjectTypeMember
-) -> Annotated[SchemaInfoObjectMember]:
+@staticmethod
+def _gen_enum_member(member: QAPISchemaEnumMember
+ ) -> Annotated[SchemaInfoEnumMember]:
+obj: SchemaInfoEnumMember = {
+'name': member.name,
+}
+return Annotated(obj, member.ifcond)
+
+def _gen_object_member(self, member: QAPISchemaObjectTypeMember
+   ) -> Annotated[SchemaInfoObjectMember]:
 obj: SchemaInfoObjectMember = {
 'name': member.name,
 'type': self._use_type(member.type)
@@ -305,7 +314,8 @@ def visit_enum_type(self, name: str, info: 
Optional[QAPISourceInfo],
 prefix: Optional[str]) -> None:
 self._gen_tree(
 name, 'enum',
-{'values': [Annotated(m.name, m.ifcond) for m in members]},
+{'members': [self._gen_enum_member(m) for m in members],
+ 'values': [Annotated(m.name, m.ifcond) for m in members]},
 ifcond, features
 )
 
@@ -322,7 +332,7 @@ def visit_object_type_flat(self, name: str, info: 
Optional[QAPISourceInfo],
members: List[QAPISchemaObjectTypeMember],
  

Re: [PATCH 3/3] qemu: Add support for virtio device option paeg-per-vq

2021-10-09 Thread Han Han
On Thu, Sep 9, 2021 at 7:43 PM Michal Prívozník  wrote:

> On 9/6/21 4:06 PM, Han Han wrote:
> > Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1925363
> >
> > Signed-off-by: Han Han 
> > ---
> >  src/qemu/qemu_command.c   |  4 ++
> >  src/qemu/qemu_hotplug.c   |  3 +-
> >  src/qemu/qemu_validate.c  |  8 
> >  .../virtio-options-controller-page_per_vq.err |  1 +
> >  ...-controller-page_per_vq.x86_64-latest.args | 37 ++
> >  .../virtio-options-controller-page_per_vq.xml | 38 ++
> >  .../virtio-options-disk-page_per_vq.err   |  1 +
> >  ...ptions-disk-page_per_vq.x86_64-latest.args | 39 +++
> >  .../virtio-options-disk-page_per_vq.xml   | 34 
> >  .../virtio-options-fs-page_per_vq.err |  1 +
> >  ...-options-fs-page_per_vq.x86_64-latest.args | 37 ++
> >  .../virtio-options-fs-page_per_vq.xml | 34 
> >  .../virtio-options-input-page_per_vq.err  |  1 +
> >  ...tions-input-page_per_vq.x86_64-latest.args | 35 +
> >  .../virtio-options-input-page_per_vq.xml  | 30 ++
> >  .../virtio-options-memballoon-page_per_vq.err |  1 +
> >  ...-memballoon-page_per_vq.x86_64-latest.args | 33 
> >  .../virtio-options-memballoon-page_per_vq.xml | 23 +++
> >  .../virtio-options-net-page_per_vq.err|  1 +
> >  ...options-net-page_per_vq.x86_64-latest.args | 37 ++
> >  .../virtio-options-net-page_per_vq.xml| 34 
> >  .../virtio-options-rng-page_per_vq.err|  1 +
> >  ...options-rng-page_per_vq.x86_64-latest.args | 37 ++
> >  .../virtio-options-rng-page_per_vq.xml| 32 +++
> >  .../virtio-options-video-page_per_vq.err  |  1 +
> >  ...tions-video-page_per_vq.x86_64-latest.args | 37 ++
> >  .../virtio-options-video-page_per_vq.xml  | 36 +
> >  .../virtio-options.x86_64-latest.args | 26 ++---
> >  tests/qemuxml2argvdata/virtio-options.xml | 26 ++---
> >  tests/qemuxml2argvtest.c  | 22 +++
> >  30 files changed, 623 insertions(+), 27 deletions(-)
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.err
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.x86_64-latest.args
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.xml
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-disk-page_per_vq.err
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-disk-page_per_vq.x86_64-latest.args
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-disk-page_per_vq.xml
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-fs-page_per_vq.err
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-fs-page_per_vq.x86_64-latest.args
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-fs-page_per_vq.xml
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-input-page_per_vq.err
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-input-page_per_vq.x86_64-latest.args
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-input-page_per_vq.xml
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-memballoon-page_per_vq.err
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-memballoon-page_per_vq.x86_64-latest.args
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-memballoon-page_per_vq.xml
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-net-page_per_vq.err
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-net-page_per_vq.x86_64-latest.args
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-net-page_per_vq.xml
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-rng-page_per_vq.err
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-rng-page_per_vq.x86_64-latest.args
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-rng-page_per_vq.xml
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-video-page_per_vq.err
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-video-page_per_vq.x86_64-latest.args
> >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-video-page_per_vq.xml
>
> Wow, that's a lot of test cases. Do we need all of them?
>
> >
> > diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> > index b230314f7f..549f11dbe8 100644
> > --- a/src/qemu/qemu_command.c
> > +++ b/src/qemu/qemu_command.c
> > @@ -645,6 +645,10 @@ qemuBuildVirtioOptionsStr(virBuffer *buf,
> >  virBufferAsprintf(buf, ",packed=%s",
> >
> virTristateSwitchTypeToString(virtio->packed));
> >  }
> > +if (virtio->page_per_vq != VIR_TRISTATE_SWITCH_ABSENT) {
> > +virBufferAsprintf(buf

Re: [PATCH 3/3] qemu: Add support for virtio device option paeg-per-vq

2021-10-09 Thread Han Han
On Wed, Oct 6, 2021 at 3:27 AM Jonathon Jongsma  wrote:

> On Fri, Sep 17, 2021 at 3:17 PM Jonathon Jongsma 
> wrote:
> >
> > On Thu, Sep 9, 2021 at 6:51 AM Michal Prívozník 
> wrote:
> > >
> > > On 9/6/21 4:06 PM, Han Han wrote:
> > > > Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1925363
> > > >
> > > > Signed-off-by: Han Han 
> > > > ---
> > > >  src/qemu/qemu_command.c   |  4 ++
> > > >  src/qemu/qemu_hotplug.c   |  3 +-
> > > >  src/qemu/qemu_validate.c  |  8 
> > > >  .../virtio-options-controller-page_per_vq.err |  1 +
> > > >  ...-controller-page_per_vq.x86_64-latest.args | 37
> ++
> > > >  .../virtio-options-controller-page_per_vq.xml | 38
> ++
> > > >  .../virtio-options-disk-page_per_vq.err   |  1 +
> > > >  ...ptions-disk-page_per_vq.x86_64-latest.args | 39
> +++
> > > >  .../virtio-options-disk-page_per_vq.xml   | 34 
> > > >  .../virtio-options-fs-page_per_vq.err |  1 +
> > > >  ...-options-fs-page_per_vq.x86_64-latest.args | 37
> ++
> > > >  .../virtio-options-fs-page_per_vq.xml | 34 
> > > >  .../virtio-options-input-page_per_vq.err  |  1 +
> > > >  ...tions-input-page_per_vq.x86_64-latest.args | 35 +
> > > >  .../virtio-options-input-page_per_vq.xml  | 30 ++
> > > >  .../virtio-options-memballoon-page_per_vq.err |  1 +
> > > >  ...-memballoon-page_per_vq.x86_64-latest.args | 33 
> > > >  .../virtio-options-memballoon-page_per_vq.xml | 23 +++
> > > >  .../virtio-options-net-page_per_vq.err|  1 +
> > > >  ...options-net-page_per_vq.x86_64-latest.args | 37
> ++
> > > >  .../virtio-options-net-page_per_vq.xml| 34 
> > > >  .../virtio-options-rng-page_per_vq.err|  1 +
> > > >  ...options-rng-page_per_vq.x86_64-latest.args | 37
> ++
> > > >  .../virtio-options-rng-page_per_vq.xml| 32 +++
> > > >  .../virtio-options-video-page_per_vq.err  |  1 +
> > > >  ...tions-video-page_per_vq.x86_64-latest.args | 37
> ++
> > > >  .../virtio-options-video-page_per_vq.xml  | 36 +
> > > >  .../virtio-options.x86_64-latest.args | 26 ++---
> > > >  tests/qemuxml2argvdata/virtio-options.xml | 26 ++---
> > > >  tests/qemuxml2argvtest.c  | 22 +++
> > > >  30 files changed, 623 insertions(+), 27 deletions(-)
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.err
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.x86_64-latest.args
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.xml
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-disk-page_per_vq.err
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-disk-page_per_vq.x86_64-latest.args
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-disk-page_per_vq.xml
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-fs-page_per_vq.err
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-fs-page_per_vq.x86_64-latest.args
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-fs-page_per_vq.xml
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-input-page_per_vq.err
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-input-page_per_vq.x86_64-latest.args
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-input-page_per_vq.xml
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-memballoon-page_per_vq.err
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-memballoon-page_per_vq.x86_64-latest.args
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-memballoon-page_per_vq.xml
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-net-page_per_vq.err
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-net-page_per_vq.x86_64-latest.args
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-net-page_per_vq.xml
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-rng-page_per_vq.err
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-rng-page_per_vq.x86_64-latest.args
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-rng-page_per_vq.xml
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-video-page_per_vq.err
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-video-page_per_vq.x86_64-latest.args
> > > >  create mode 100644
> tests/qemuxml2argvdata/virtio-options-video-page_per_vq.xml
> > >
> > > Wow, that's a lot of test cases. Do we need all of them?
> > >
> > > >
> > > > diff --git a/src/qemu/qemu_command.c b/src/qem

[PATCH v2 3/3] qemu: Add support for virtio device option page-per-vq

2021-10-09 Thread Han Han
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1925363

Signed-off-by: Han Han 
---
 src/qemu/qemu_command.c   |  4 ++
 src/qemu/qemu_hotplug.c   |  3 +-
 src/qemu/qemu_validate.c  |  7 
 .../virtio-options-controller-page_per_vq.err |  1 +
 .../virtio-options-controller-page_per_vq.xml | 38 +++
 .../virtio-options-disk-page_per_vq.err   |  1 +
 .../virtio-options-disk-page_per_vq.xml   | 34 +
 .../virtio-options-fs-page_per_vq.err |  1 +
 .../virtio-options-fs-page_per_vq.xml | 34 +
 .../virtio-options-input-page_per_vq.err  |  1 +
 .../virtio-options-input-page_per_vq.xml  | 30 +++
 .../virtio-options-memballoon-page_per_vq.err |  1 +
 .../virtio-options-memballoon-page_per_vq.xml | 23 +++
 .../virtio-options-net-page_per_vq.err|  1 +
 .../virtio-options-net-page_per_vq.xml| 34 +
 .../virtio-options-rng-page_per_vq.err|  1 +
 .../virtio-options-rng-page_per_vq.xml| 32 
 .../virtio-options-video-page_per_vq.err  |  1 +
 .../virtio-options-video-page_per_vq.xml  | 36 ++
 .../virtio-options.x86_64-latest.args | 26 ++---
 tests/qemuxml2argvdata/virtio-options.xml | 26 ++---
 tests/qemuxml2argvtest.c  | 14 +++
 22 files changed, 322 insertions(+), 27 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.err
 create mode 100644 
tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.xml
 create mode 100644 tests/qemuxml2argvdata/virtio-options-disk-page_per_vq.err
 create mode 100644 tests/qemuxml2argvdata/virtio-options-disk-page_per_vq.xml
 create mode 100644 tests/qemuxml2argvdata/virtio-options-fs-page_per_vq.err
 create mode 100644 tests/qemuxml2argvdata/virtio-options-fs-page_per_vq.xml
 create mode 100644 tests/qemuxml2argvdata/virtio-options-input-page_per_vq.err
 create mode 100644 tests/qemuxml2argvdata/virtio-options-input-page_per_vq.xml
 create mode 100644 
tests/qemuxml2argvdata/virtio-options-memballoon-page_per_vq.err
 create mode 100644 
tests/qemuxml2argvdata/virtio-options-memballoon-page_per_vq.xml
 create mode 100644 tests/qemuxml2argvdata/virtio-options-net-page_per_vq.err
 create mode 100644 tests/qemuxml2argvdata/virtio-options-net-page_per_vq.xml
 create mode 100644 tests/qemuxml2argvdata/virtio-options-rng-page_per_vq.err
 create mode 100644 tests/qemuxml2argvdata/virtio-options-rng-page_per_vq.xml
 create mode 100644 tests/qemuxml2argvdata/virtio-options-video-page_per_vq.err
 create mode 100644 tests/qemuxml2argvdata/virtio-options-video-page_per_vq.xml

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 28bca1519c..36159971fa 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -636,6 +636,10 @@ qemuBuildVirtioOptionsStr(virBuffer *buf,
 virBufferAsprintf(buf, ",packed=%s",
   virTristateSwitchTypeToString(virtio->packed));
 }
+if (virtio->page_per_vq != VIR_TRISTATE_SWITCH_ABSENT) {
+virBufferAsprintf(buf, ",page-per-vq=%s",
+  virTristateSwitchTypeToString(virtio->page_per_vq));
+}
 }
 
 static int
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 22239b2689..9bbbab47e3 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3675,7 +3675,8 @@ qemuDomainChangeNet(virQEMUDriver *driver,
 (olddev->virtio && newdev->virtio &&
  (olddev->virtio->iommu != newdev->virtio->iommu ||
   olddev->virtio->ats != newdev->virtio->ats ||
-  olddev->virtio->packed != newdev->virtio->packed))) {
+  olddev->virtio->packed != newdev->virtio->packed ||
+  olddev->virtio->page_per_vq != newdev->virtio->page_per_vq))) {
 virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("cannot modify virtio network device driver 
options"));
goto cleanup;
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index c84508cb64..233544e944 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1430,6 +1430,13 @@ qemuValidateDomainVirtioOptions(const 
virDomainVirtioOptions *virtio,
  "QEMU binary"));
 return -1;
 }
+
+if (virtio->page_per_vq != VIR_TRISTATE_SWITCH_ABSENT &&
+!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_PAGE_PER_VQ)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("the page_per_vq setting is not supported with 
this QEMU binary"));
+return -1;
+}
 return 0;
 }
 
diff --git a/tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.err 
b/tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.err
new file mode 100644
index 00..475aa8be43
--- /dev/

[PATCH v2 2/3] conf: Add page_per_vq for driver element

2021-10-09 Thread Han Han
Signed-off-by: Han Han 
---
 docs/formatdomain.rst |  9 +
 docs/schemas/domaincommon.rng |  5 +
 src/conf/domain_conf.c| 16 
 src/conf/domain_conf.h|  1 +
 src/conf/domain_validate.c|  6 ++
 5 files changed, 37 insertions(+)

diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index a02802a954..289e7bf5f1 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -3548,6 +3548,15 @@ virtqueues are actually used depends on the feature 
negotiation between QEMU,
 vhost backends and guest drivers. Possible values are ``on`` or ``off``.
 :since:`Since 6.3.0 (QEMU and KVM only)`
 
+This optional attribute ``page_per_vq`` controls the layout of the notification
+capabilities exposed to the guest. When enabled, each virtio queue will have a
+dedicated page on the device BAR exposed to the guest. It is recommended to be
+used when vDPA is enabled on the hypervisor, as it enables mapping the
+notification area to the physical device, which is only supported in page
+granularity. The default is determined by QEMU. :since:`Since 7.8.0`
+Note: In general you should leave this option alone, unless you are very 
certain
+you know what you are doing.
+
 :anchor:``
 
 Virtio transitional devices
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index ec5bd91740..f71e375a33 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -6810,6 +6810,11 @@
 
   
 
+
+  
+
+  
+
   
 
   
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b8370f6950..04bdd110b6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1630,6 +1630,10 @@ virDomainVirtioOptionsParseXML(xmlNodePtr driver,
  &(*virtio)->packed) < 0)
 return -1;
 
+if (virXMLPropTristateSwitch(driver, "page_per_vq", VIR_XML_PROP_NONE,
+ &(*virtio)->page_per_vq) < 0)
+return -1;
+
 return 0;
 }
 
@@ -6314,6 +6318,10 @@ virDomainVirtioOptionsFormat(virBuffer *buf,
 virBufferAsprintf(buf, " packed='%s'",
   virTristateSwitchTypeToString(virtio->packed));
 }
+if (virtio->page_per_vq != VIR_TRISTATE_SWITCH_ABSENT) {
+virBufferAsprintf(buf, " page_per_vq='%s'",
+  virTristateSwitchTypeToString(virtio->page_per_vq));
+}
 }
 
 
@@ -20784,6 +20792,14 @@ 
virDomainVirtioOptionsCheckABIStability(virDomainVirtioOptions *src,
virTristateSwitchTypeToString(src->packed));
 return false;
 }
+if (src->page_per_vq != dst->page_per_vq) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+   _("Target device page_per_vq option '%s' does not "
+ "match source '%s'"),
+   virTristateSwitchTypeToString(dst->page_per_vq),
+   virTristateSwitchTypeToString(src->page_per_vq));
+return false;
+}
 return true;
 }
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c23c233184..d6bc3dd0d2 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2733,6 +2733,7 @@ struct _virDomainVirtioOptions {
 virTristateSwitch iommu;
 virTristateSwitch ats;
 virTristateSwitch packed;
+virTristateSwitch page_per_vq;
 };
 
 
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index f023d22f23..80401cf8c7 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -135,6 +135,12 @@ 
virDomainCheckVirtioOptionsAreAbsent(virDomainVirtioOptions *virtio)
  "for virtio devices"));
 return -1;
 }
+
+if (virtio->page_per_vq != VIR_TRISTATE_SWITCH_ABSENT) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("page_per_vq option is only supported for virtio 
devices"));
+return -1;
+}
 return 0;
 }
 
-- 
2.31.1



[PATCH v2 1/3] qemu_capabilities: Add flag QEMU_CAPS_VIRTIO_PAGE_PER_VQ

2021-10-09 Thread Han Han
The qemu capability will be used for the page_per_vq option of virtio
devices.

Signed-off-by: Han Han 
---
 src/qemu/qemu_capabilities.c   | 6 ++
 src/qemu/qemu_capabilities.h   | 1 +
 tests/qemucapabilitiesdata/caps_2.11.0.s390x.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.11.0.x86_64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.aarch64.xml | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.ppc64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.s390x.xml   | 1 +
 tests/qemucapabilitiesdata/caps_2.12.0.x86_64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_3.0.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_3.1.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_3.1.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_4.1.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_4.2.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.riscv64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_5.1.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_5.2.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_5.2.0.ppc64.xml| 1 +
 tests/qemucapabilitiesdata/caps_5.2.0.riscv64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_5.2.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_5.2.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_6.0.0.aarch64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_6.0.0.s390x.xml| 1 +
 tests/qemucapabilitiesdata/caps_6.0.0.x86_64.xml   | 1 +
 tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml   | 1 +
 38 files changed, 43 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 82687dbf39..95caea9b41 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -644,6 +644,7 @@ VIR_ENUM_IMPL(virQEMUCaps,
   "virtio-mem-pci", /* QEMU_CAPS_DEVICE_VIRTIO_MEM_PCI */
   "memory-backend-file.reserve", /* 
QEMU_CAPS_MEMORY_BACKEND_RESERVE */
   "piix4.acpi-root-pci-hotplug", /* 
QEMU_CAPS_PIIX4_ACPI_ROOT_PCI_HOTPLUG */
+  "virtio.page-per-vq", /* QEMU_CAPS_VIRTIO_PAGE_PER_VQ */
 );
 
 
@@ -1377,6 +1378,7 @@ static struct virQEMUCapsDevicePropsFlags 
virQEMUCapsDevicePropsVirtioBalloon[]
 { "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES, NULL },
 { "free-page-reporting", QEMU_CAPS_VIRTIO_BALLOON_FREE_PAGE_REPORTING, 
NULL },
 { "acpi-index", QEMU_CAPS_ACPI_INDEX, NULL },
+{ "page-per-vq", QEMU_CAPS_VIRTIO_PAGE_PER_VQ, NULL },
 };
 
 
@@ -1411,6 +1413,7 @@ static struct virQEMUCapsDevicePropsFlags 
virQEMUCapsDevicePropsVirtioBlk[] = {
 { "werror", QEMU_CAPS_STORAGE_WERROR, NULL },
 { "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES, NULL },
 { "acpi-index", QEMU_CAPS_ACPI_INDEX, NULL },
+{ "page-per-vq", QEMU_CAPS_VIRTIO_PAGE_PER_VQ, NULL },
 };
 
 static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVirtioNet[] = {
@@ -1425,6 +1428,7 @@ static struct virQEMUCapsDevicePropsFlags 
virQEMUCapsDevicePropsVirtioNet[] = {
 { "failover", QEMU_CAPS_VIRTIO_NET_FAILOVER, NULL },
 { "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES, NULL },
 { "acpi-index", QEMU_CAPS_ACPI_INDEX, NULL },
+{ "page-per-vq", QEMU_CAPS_VIRTIO_PAGE_PER_VQ, NULL },
 };
 
 static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsPCIeRootPort[] 
= {
@@ -1446,6 +1450,7 @@ static struct virQEMUCapsDevicePropsFlags 
virQEMUCapsDevicePropsVirtioSCSI[] = {
 { "ats", QEMU_CAPS_VIRTIO_PCI_ATS, NULL },
 { "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES, NULL },
 { "acpi-index", QEMU_CAPS_ACPI_INDEX, NULL },
+{ "page-per-vq", QEMU_CAPS_VIRTIO_PAGE_PER_VQ, NULL },
 };
 
 static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsVfioPCI[] = {
@@ -1519,6 +1524,7 @@ static struct virQEMUCapsDevicePropsFlags 
virQEMUCapsDevicePropsVirtioGpu[] = {
 { "ats", QEMU_CAPS_VIRTIO_PCI_ATS, NULL },
 { "packed", QEMU_CAPS_VIRTIO_PACKED_QUEUES, NULL },
 { "acpi-index", QEMU_CAPS_ACPI_INDEX, NULL },
+{ "page-per-vq", QEMU_CAPS_VIRTIO_PAGE_PER_VQ, NULL },
 };
 
 static struct virQEMUCapsDevicePropsFlags virQEMUCapsDevicePropsICH9[] = {
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 2bbfc15dc

[PATCH v2 0/3] Implement paeg-per-vq to virtio devices

2021-10-09 Thread Han Han
Diff from v1:
- Remove some duplicated test cases
- Merge some err msgs of 2 lines into one line
- Rebase to latest upstream

v1: https://listman.redhat.com/archives/libvir-list/2021-September/msg00087.html

Han Han (3):
  qemu_capabilities: Add flag QEMU_CAPS_VIRTIO_PAGE_PER_VQ
  conf: Add page_per_vq for driver element
  qemu: Add support for virtio device option page-per-vq

 docs/formatdomain.rst |  9 +
 docs/schemas/domaincommon.rng |  5 +++
 src/conf/domain_conf.c| 16 
 src/conf/domain_conf.h|  1 +
 src/conf/domain_validate.c|  6 +++
 src/qemu/qemu_capabilities.c  |  6 +++
 src/qemu/qemu_capabilities.h  |  1 +
 src/qemu/qemu_command.c   |  4 ++
 src/qemu/qemu_hotplug.c   |  3 +-
 src/qemu/qemu_validate.c  |  7 
 .../caps_2.11.0.s390x.xml |  1 +
 .../caps_2.11.0.x86_64.xml|  1 +
 .../caps_2.12.0.aarch64.xml   |  1 +
 .../caps_2.12.0.ppc64.xml |  1 +
 .../caps_2.12.0.s390x.xml |  1 +
 .../caps_2.12.0.x86_64.xml|  1 +
 .../qemucapabilitiesdata/caps_3.0.0.ppc64.xml |  1 +
 .../qemucapabilitiesdata/caps_3.0.0.s390x.xml |  1 +
 .../caps_3.0.0.x86_64.xml |  1 +
 .../qemucapabilitiesdata/caps_3.1.0.ppc64.xml |  1 +
 .../caps_3.1.0.x86_64.xml |  1 +
 .../caps_4.0.0.aarch64.xml|  1 +
 .../qemucapabilitiesdata/caps_4.0.0.ppc64.xml |  1 +
 .../caps_4.0.0.riscv32.xml|  1 +
 .../caps_4.0.0.riscv64.xml|  1 +
 .../qemucapabilitiesdata/caps_4.0.0.s390x.xml |  1 +
 .../caps_4.0.0.x86_64.xml |  1 +
 .../caps_4.1.0.x86_64.xml |  1 +
 .../caps_4.2.0.aarch64.xml|  1 +
 .../qemucapabilitiesdata/caps_4.2.0.ppc64.xml |  1 +
 .../qemucapabilitiesdata/caps_4.2.0.s390x.xml |  1 +
 .../caps_4.2.0.x86_64.xml |  1 +
 .../caps_5.0.0.aarch64.xml|  1 +
 .../qemucapabilitiesdata/caps_5.0.0.ppc64.xml |  1 +
 .../caps_5.0.0.riscv64.xml|  1 +
 .../caps_5.0.0.x86_64.xml |  1 +
 .../caps_5.1.0.x86_64.xml |  1 +
 .../caps_5.2.0.aarch64.xml|  1 +
 .../qemucapabilitiesdata/caps_5.2.0.ppc64.xml |  1 +
 .../caps_5.2.0.riscv64.xml|  1 +
 .../qemucapabilitiesdata/caps_5.2.0.s390x.xml |  1 +
 .../caps_5.2.0.x86_64.xml |  1 +
 .../caps_6.0.0.aarch64.xml|  1 +
 .../qemucapabilitiesdata/caps_6.0.0.s390x.xml |  1 +
 .../caps_6.0.0.x86_64.xml |  1 +
 .../caps_6.1.0.x86_64.xml |  1 +
 .../virtio-options-controller-page_per_vq.err |  1 +
 .../virtio-options-controller-page_per_vq.xml | 38 +++
 .../virtio-options-disk-page_per_vq.err   |  1 +
 .../virtio-options-disk-page_per_vq.xml   | 34 +
 .../virtio-options-fs-page_per_vq.err |  1 +
 .../virtio-options-fs-page_per_vq.xml | 34 +
 .../virtio-options-input-page_per_vq.err  |  1 +
 .../virtio-options-input-page_per_vq.xml  | 30 +++
 .../virtio-options-memballoon-page_per_vq.err |  1 +
 .../virtio-options-memballoon-page_per_vq.xml | 23 +++
 .../virtio-options-net-page_per_vq.err|  1 +
 .../virtio-options-net-page_per_vq.xml| 34 +
 .../virtio-options-rng-page_per_vq.err|  1 +
 .../virtio-options-rng-page_per_vq.xml| 32 
 .../virtio-options-video-page_per_vq.err  |  1 +
 .../virtio-options-video-page_per_vq.xml  | 36 ++
 .../virtio-options.x86_64-latest.args | 26 ++---
 tests/qemuxml2argvdata/virtio-options.xml | 26 ++---
 tests/qemuxml2argvtest.c  | 14 +++
 65 files changed, 402 insertions(+), 27 deletions(-)
 create mode 100644 
tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.err
 create mode 100644 
tests/qemuxml2argvdata/virtio-options-controller-page_per_vq.xml
 create mode 100644 tests/qemuxml2argvdata/virtio-options-disk-page_per_vq.err
 create mode 100644 tests/qemuxml2argvdata/virtio-options-disk-page_per_vq.xml
 create mode 100644 tests/qemuxml2argvdata/virtio-options-fs-page_per_vq.err
 create mode 100644 tests/qemuxml2argvdata/virtio-options-fs-page_per_vq.xml
 create mode 100644 tests/qemuxml2argvdata/virtio-options-input-page_per_vq.err
 create mode 100644 tests/qemuxml2argvdata/virtio-options-input-page_per_vq.xml
 create mode 100644 
tests/qemuxml2argvdata/virtio-options-memballoon-page_per_vq.err
 create mode 100644 
tests/qemuxml2argvdata/virtio-options-memballoon-page_per_vq.xml
 create mode 100644 tests/qemuxml2argvdata/virtio-options-net-pa

Re: [PATCH RFC 1/5] qapi: Enable enum member introspection to show more than name

2021-10-09 Thread Markus Armbruster
Peter Krempa  writes:

> On Mon, Sep 20, 2021 at 11:08:59 +0200, Markus Armbruster wrote:
>> Peter Krempa  writes:
>> 
>> > On Wed, Sep 15, 2021 at 21:24:21 +0200, Markus Armbruster wrote:
>> >> The next commit will add feature flags to enum members.  There's a
>> >> problem, though: query-qmp-schema shows an enum type's members as an
>> >> array of member names (SchemaInfoEnum member @values).  If it showed
>> >> an array of objects with a name member, we could simply add more
>> >> members to these objects.  Since it's just strings, we can't.
>> >> 
>> >> I can see three ways to correct this design mistake:
>> >> 
>> >> 1. Do it the way we should have done it, plus compatibility goo.
>> >> 
>> >>We want a ['SchemaInfoEnumMember'] member in SchemaInfoEnum.  Since
>> >>changing @values would be a compatibility break, add a new member
>> >>@members instead.
>> >> 
>> >>@values is now redundant.  We should be able to get rid of it
>> >>eventually.
>> >> 
>> >>In my testing, output of qemu-system-x86_64's query-qmp-schema
>> >>grows by 11% (18.5KiB).
>> >
>> > I prefer this one. While the schema output grows, nobody is really
>> > reading it manually.
>> 
>> True, but growing schema output can only slow down client startup.
>> Negligible for libvirt, I presume?
>
> Libvirt employs caching, so unless it's the first VM started after a
> qemu/libvirt upgrade, the results are already processed and cached.

Good!

> In fact we don't even keep the full schema around, we just extract
> information and store them as capability bits. For now we didn't run
> into the need to have the full schema around when starting a VM.
>
> [...]
>
>> >> 3. Versioned query-qmp-schema.
>> >> 
>> >>query-qmp-schema provides either @values or @members.  The QMP
>> >>client can select which version it wants.
>> >
>> > At least for libvirt this poses a chicken & egg problem. We'd have to
>> > query the schema to see that it has the switch to do the selection and
>> > then probe with the modern one.
>> 
>> The simplest solution is to try the versions the management application
>> can understand in order of preference (newest to oldest) until one
>> succeeds.  I'd expect the first try to work most of the time.  Only when
>> you combine new libvirt with old QEMU, the fallback has to kick in.
>> 
>> Other parts of the management application should remain oblivous of the
>> differences.
>
> That would certainly work and be reasonably straightforward for libvirt
> to implement, but:
>  1) libvirt's code for using the QMP schema would be exactly the same as
> with approach 1), as we need to handle old clients too and the new
> way is simply a superset of what we have

Yes, libvirt would need the same code for processing old and new.  The
only difference would be how it decides which method to use.  With 1,
it's "if @members is present, use it, else @values".  With 2, it's "if
the version we use is new enough, use @members, else @values".

>  2) qemu's deprecation approach itself wouldn't be any easier in either
> of those scenarios
>
> Basically the only thing this would gain us is that if the deprecation
> period is over old clients which were not fixed could fail silently:
>
> Assuming that 'query-qmp-schema' gains a boolean option such as
> 'fancier-enums' and setting that to true returns the new format of
> schema, after the deprecation is over you could simply return an error
> if a caller omits 'fancier-enums' or sets it to false, which creates a
> clean cut for the removal.

Yes.

> With approach 1) itself, clients which were not adapted would start
> lacking information based on enum values.
>
> Now for those it depends on how they actually handled it until now. E.g.
> old libvirt would report that the QMP schema is broken if 'values' would
> be missing.

Which I consider the sensible thing to do.

> Whether that's a worthwhile thing to do? I'm not really persuaded. (And
> I'm biased since libvirt handles it correctly).

I think 3 has the following advantages over 1:

* As you noted, it ensures outmoded clients fail cleanly.  Not much of
  an advantage for clients that handle missing @values sensibly.
  Perhaps it could enable better error messages.

* It avoids duplicated contents in old an new format.  Not much of an
  advantage for clients that cache their schema interrogation.

* It can enable more radical introspection changes.  Without versioning,
  the common rules for compatible evolution apply (section
  "Compatibility considerations" in qapi-code-gen.rst).  With
  versioning, they don't.

I agree this is not really compelling just for the problem at hand.  We
can reconsider when we run into more problems.

>> We could of course try to reduce the number of roundtrips, say by
>> putting sufficient information into the QMP greeting (one roundtrip), or
>> the output of query-qmp-schema (try oldest to find the best one, then
>> try the best one unless it's the oldest).  I doubt that's 

[PATCH] libvirt qemu add rbd mirror dest in qemuDomainBlockCopyCommon

2021-10-09 Thread dingli...@cmss.chinamobile.com
From: dinglimin 

The BlockCopy command is designed to copy a chain of disk backup images to dest.
For RBD external destination, before the modification, only the '--XML' 
parameter is supported by 'blockdev-mirror'.
After the modification, the '--dest' parameter(--dest 
'rbd:xxx/xxx:auth_supported=none:mon_host=xxx.xxx.xxx.xxx')can be used.

Signed-off-by: dinglimin 
---
 src/qemu/qemu_driver.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 760d30a..db15898 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14963,12 +14963,27 @@ qemuDomainBlockCopyCommon(virDomainObj *vm,
 virStorageSource *mirrorBacking = NULL;
 g_autoptr(GHashTable) blockNamedNodeData = NULL;
 int rc = 0;
+const char *p = NULL;
 
 /* Preliminaries: find the disk we are editing, sanity checks */
 virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW |
   VIR_DOMAIN_BLOCK_COPY_REUSE_EXT |
   VIR_DOMAIN_BLOCK_COPY_TRANSIENT_JOB, -1);
 
+/* if mirror->path contains 'rbd:' prefix, set rbd attributes */
+if (STRPREFIX(mirror->path, "rbd:")) {
+mirror->format = VIR_STORAGE_FILE_RAW;
+mirror->protocol = VIR_STORAGE_NET_PROTOCOL_RBD;
+mirror->type = VIR_STORAGE_TYPE_NETWORK;
+
+p = g_strdup(mirror->path);
+if (virStorageSourceParseRBDColonString(p, mirror) < 0) {
+  virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("RBD path conversion failed"));
+  return -1;
+}
+}
+  
 if (virStorageSourceIsRelative(mirror)) {
 virReportError(VIR_ERR_INVALID_ARG, "%s",
_("absolute path must be used as block copy target"));
-- 
1.8.3.1