[PATCH 0/6] json helper cleanups

2021-12-22 Thread Peter Krempa
Peter Krempa (6):
  qemuBlockStorageSourceGetRBDProps: Simplify generation of auth modes
  Replace open coded virJSONValueArrayAppendString
  util: json: Don't copy string in virJSONValueNewString
  util: json: Open-code only call of virJSONValueNewStringLen
  util: json: Remove virJSONValueIsNull/virJSONValueObjectIsNull
  util: virjson.h: Reformat headers to conform with new style

 src/libvirt_private.syms |   3 -
 src/qemu/qemu_agent.c|   4 +-
 src/qemu/qemu_block.c|  10 +-
 src/util/virjson.c   |  57 +--
 src/util/virjson.h   | 315 +++
 src/util/virmacmap.c |   4 +-
 tests/virjsontest.c  |   4 +-
 7 files changed, 231 insertions(+), 166 deletions(-)

-- 
2.31.1



[PATCH 2/6] Replace open coded virJSONValueArrayAppendString

2021-12-22 Thread Peter Krempa
In two instances we've created a string virJSONValue just to append it
to the array. Replace it by use of the virJSONValueArrayAppendString
helper.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_agent.c | 4 +---
 src/util/virmacmap.c  | 4 +---
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index e2107e5cbf..cb3bf97415 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1168,9 +1168,7 @@ qemuAgentMakeStringsArray(const char **strings, unsigned 
int len)
 g_autoptr(virJSONValue) ret = virJSONValueNewArray();

 for (i = 0; i < len; i++) {
-g_autoptr(virJSONValue) str = virJSONValueNewString(strings[i]);
-
-if (virJSONValueArrayAppend(ret, &str) < 0)
+if (virJSONValueArrayAppendString(ret, strings[i]) < 0)
 return NULL;
 }

diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c
index 0b7b758c6d..cf554205a8 100644
--- a/src/util/virmacmap.c
+++ b/src/util/virmacmap.c
@@ -214,9 +214,7 @@ virMACMapHashDumper(void *payload,
 GSList *next;

 for (next = macs; next; next = next->next) {
-g_autoptr(virJSONValue) m = virJSONValueNewString((const char *) 
next->data);
-
-if (virJSONValueArrayAppend(arr, &m) < 0)
+if (virJSONValueArrayAppendString(arr, (const char *) next->data) < 0)
 return -1;
 }

-- 
2.31.1



[PATCH 4/6] util: json: Open-code only call of virJSONValueNewStringLen

2021-12-22 Thread Peter Krempa
Replace the function by a call to virJSONValueNewString, when we copy
the string using g_strndup. Remove the unused helper.

Signed-off-by: Peter Krempa 
---
 src/libvirt_private.syms |  1 -
 src/util/virjson.c   | 21 +
 src/util/virjson.h   |  1 -
 3 files changed, 1 insertion(+), 22 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b2c16c469d..bf5d0f54f3 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2536,7 +2536,6 @@ virJSONValueNewNumberUint;
 virJSONValueNewNumberUlong;
 virJSONValueNewObject;
 virJSONValueNewString;
-virJSONValueNewStringLen;
 virJSONValueObjectAdd;
 virJSONValueObjectAddVArgs;
 virJSONValueObjectAppend;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 37301bb87e..719f4de1bf 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -428,24 +428,6 @@ virJSONValueNewString(char *data)
 }


-virJSONValue *
-virJSONValueNewStringLen(const char *data,
- size_t length)
-{
-virJSONValue *val;
-
-if (!data)
-return virJSONValueNewNull();
-
-val = g_new0(virJSONValue, 1);
-
-val->type = VIR_JSON_TYPE_STRING;
-val->data.string = g_strndup(data, length);
-
-return val;
-}
-
-
 /**
  * virJSONValueNewNumber:
  * @data: string representing the number
@@ -1558,8 +1540,7 @@ virJSONParserHandleString(void *ctx,
   size_t stringLen)
 {
 virJSONParser *parser = ctx;
-g_autoptr(virJSONValue) value = virJSONValueNewStringLen((const char 
*)stringVal,
- stringLen);
+g_autoptr(virJSONValue) value = virJSONValueNewString(g_strndup((const 
char *)stringVal, stringLen));

 VIR_DEBUG("parser=%p str=%p", parser, (const char *)stringVal);

diff --git a/src/util/virjson.h b/src/util/virjson.h
index 71b88183fe..cb2315d13e 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -51,7 +51,6 @@ int virJSONValueObjectAddVArgs(virJSONValue **objptr, va_list 
args)


 virJSONValue *virJSONValueNewString(char *data);
-virJSONValue *virJSONValueNewStringLen(const char *data, size_t length);
 virJSONValue *virJSONValueNewNumberInt(int data);
 virJSONValue *virJSONValueNewNumberUint(unsigned int data);
 virJSONValue *virJSONValueNewNumberLong(long long data);
-- 
2.31.1



[PATCH 1/6] qemuBlockStorageSourceGetRBDProps: Simplify generation of auth modes

2021-12-22 Thread Peter Krempa
The auth mode array is static, parse it from a JSON string.

Signed-off-by: Peter Krempa 
---
 src/qemu/qemu_block.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 2e606e99b4..e5ff653a60 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -881,7 +881,6 @@ qemuBlockStorageSourceGetRBDProps(virStorageSource *src,
 const char *encformat;
 const char *username = NULL;
 g_autoptr(virJSONValue) authmodes = NULL;
-g_autoptr(virJSONValue) mode = NULL;
 const char *keysecret = NULL;

 if (src->nhosts > 0 &&
@@ -892,14 +891,7 @@ qemuBlockStorageSourceGetRBDProps(virStorageSource *src,
 username = srcPriv->secinfo->username;
 keysecret = srcPriv->secinfo->alias;
 /* the auth modes are modelled after our old command line generator */
-authmodes = virJSONValueNewArray();
-
-if (!(mode = virJSONValueNewString("cephx")) ||
-virJSONValueArrayAppend(authmodes, &mode) < 0)
-return NULL;
-
-if (!(mode = virJSONValueNewString("none")) ||
-virJSONValueArrayAppend(authmodes, &mode) < 0)
+if (!(authmodes = virJSONValueFromString("[\"cephx\",\"none\"]")))
 return NULL;
 }

-- 
2.31.1



[PATCH 3/6] util: json: Don't copy string in virJSONValueNewString

2021-12-22 Thread Peter Krempa
With 'g_strdup' not needing error handling we can ask callers to pass a
copy of the string which will be adopted by the JSON value.

Signed-off-by: Peter Krempa 
---
 src/util/virjson.c  | 17 +++--
 src/util/virjson.h  |  2 +-
 tests/virjsontest.c |  4 ++--
 3 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/util/virjson.c b/src/util/virjson.c
index dbc5b7840c..37301bb87e 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -412,7 +412,7 @@ virJSONValueHashFree(void *opaque)


 virJSONValue *
-virJSONValueNewString(const char *data)
+virJSONValueNewString(char *data)
 {
 virJSONValue *val;

@@ -422,7 +422,7 @@ virJSONValueNewString(const char *data)
 val = g_new0(virJSONValue, 1);

 val->type = VIR_JSON_TYPE_STRING;
-val->data.string = g_strdup(data);
+val->data.string = data;

 return val;
 }
@@ -608,12 +608,9 @@ virJSONValueObjectInsertString(virJSONValue *object,
const char *value,
bool prepend)
 {
-virJSONValue *jvalue = virJSONValueNewString(value);
-if (!jvalue)
-return -1;
-if (virJSONValueObjectInsert(object, key, &jvalue, prepend) < 0)
-return -1;
-return 0;
+g_autoptr(virJSONValue) jvalue = virJSONValueNewString(g_strdup(value));
+
+return virJSONValueObjectInsert(object, key, &jvalue, prepend);
 }


@@ -775,7 +772,7 @@ int
 virJSONValueArrayAppendString(virJSONValue *object,
   const char *value)
 {
-g_autoptr(virJSONValue) jvalue = virJSONValueNewString(value);
+g_autoptr(virJSONValue) jvalue = virJSONValueNewString(g_strdup(value));

 if (virJSONValueArrayAppend(object, &jvalue) < 0)
 return -1;
@@ -1438,7 +1435,7 @@ virJSONValueCopy(const virJSONValue *in)

 /* No need to error out in the following cases */
 case VIR_JSON_TYPE_STRING:
-out = virJSONValueNewString(in->data.string);
+out = virJSONValueNewString(g_strdup(in->data.string));
 break;
 case VIR_JSON_TYPE_NUMBER:
 out = virJSONValueNewNumber(g_strdup(in->data.number));
diff --git a/src/util/virjson.h b/src/util/virjson.h
index 361b0190e8..71b88183fe 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -50,7 +50,7 @@ int virJSONValueObjectAddVArgs(virJSONValue **objptr, va_list 
args)
 ATTRIBUTE_NONNULL(1);


-virJSONValue *virJSONValueNewString(const char *data);
+virJSONValue *virJSONValueNewString(char *data);
 virJSONValue *virJSONValueNewStringLen(const char *data, size_t length);
 virJSONValue *virJSONValueNewNumberInt(int data);
 virJSONValue *virJSONValueNewNumberUint(unsigned int data);
diff --git a/tests/virjsontest.c b/tests/virjsontest.c
index ddb93803b7..78283b632a 100644
--- a/tests/virjsontest.c
+++ b/tests/virjsontest.c
@@ -441,8 +441,8 @@ testJSONObjectFormatSteal(const void *opaque G_GNUC_UNUSED)
 g_autoptr(virJSONValue) t1 = NULL;
 g_autoptr(virJSONValue) t2 = NULL;

-if (!(a1 = virJSONValueNewString("test")) ||
-!(a2 = virJSONValueNewString("test"))) {
+if (!(a1 = virJSONValueNewString(g_strdup("test"))) ||
+!(a2 = virJSONValueNewString(g_strdup("test" {
 VIR_TEST_VERBOSE("Failed to create json object");
 }

-- 
2.31.1



[PATCH 5/6] util: json: Remove virJSONValueIsNull/virJSONValueObjectIsNull

2021-12-22 Thread Peter Krempa
If needed 'virJSONValueIsNull' can be easily replaced by
'virJSONValueGetType(obj) == VIR_JSON_TYPE_NULL'.

'virJSONValueObjectIsNull' has confusing name because it checks that a
virJSONValue of OBJECT type has a key which is NULL, not that the object
itself is NULL. This can be replaced according to the needs e.g. by
virJSONValueObjectHasKey or the above check.

Both are unused.

Signed-off-by: Peter Krempa 
---
 src/libvirt_private.syms |  2 --
 src/util/virjson.c   | 19 ---
 src/util/virjson.h   |  2 --
 3 files changed, 23 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index bf5d0f54f3..435ee8054c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2524,7 +2524,6 @@ virJSONValueGetString;
 virJSONValueGetType;
 virJSONValueHashFree;
 virJSONValueIsArray;
-virJSONValueIsNull;
 virJSONValueIsObject;
 virJSONValueNewArray;
 virJSONValueNewBoolean;
@@ -2565,7 +2564,6 @@ virJSONValueObjectGetString;
 virJSONValueObjectGetStringArray;
 virJSONValueObjectGetValue;
 virJSONValueObjectHasKey;
-virJSONValueObjectIsNull;
 virJSONValueObjectKeysNumber;
 virJSONValueObjectPrependString;
 virJSONValueObjectRemoveKey;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 719f4de1bf..1c6fef22da 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1136,13 +1136,6 @@ virJSONValueGetBoolean(virJSONValue *val,
 }


-bool
-virJSONValueIsNull(virJSONValue *val)
-{
-return val->type == VIR_JSON_TYPE_NULL;
-}
-
-
 const char *
 virJSONValueObjectGetString(virJSONValue *object,
 const char *key)
@@ -1296,18 +1289,6 @@ virJSONValueObjectStealObject(virJSONValue *object,
 }


-int
-virJSONValueObjectIsNull(virJSONValue *object,
- const char *key)
-{
-virJSONValue *val = virJSONValueObjectGet(object, key);
-
-if (!val)
-return -1;
-
-return virJSONValueIsNull(val);
-}
-
 char **
 virJSONValueObjectGetStringArray(virJSONValue *object, const char *key)
 {
diff --git a/src/util/virjson.h b/src/util/virjson.h
index cb2315d13e..24ac51f4f8 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -99,7 +99,6 @@ int virJSONValueGetNumberLong(virJSONValue *object, long long 
*value);
 int virJSONValueGetNumberUlong(virJSONValue *object, unsigned long long 
*value);
 int virJSONValueGetNumberDouble(virJSONValue *object, double *value);
 int virJSONValueGetBoolean(virJSONValue *object, bool *value);
-bool virJSONValueIsNull(virJSONValue *object);
 virJSONValue *virJSONValueObjectGetObject(virJSONValue *object,
 const char *key);
 virJSONValue *virJSONValueObjectGetArray(virJSONValue *object,
@@ -118,7 +117,6 @@ int virJSONValueObjectGetNumberLong(virJSONValue *object, 
const char *key, long
 int virJSONValueObjectGetNumberUlong(virJSONValue *object, const char *key, 
unsigned long long *value);
 int virJSONValueObjectGetNumberDouble(virJSONValue *object, const char *key, 
double *value);
 int virJSONValueObjectGetBoolean(virJSONValue *object, const char *key, bool 
*value);
-int virJSONValueObjectIsNull(virJSONValue *object, const char *key);

 int virJSONValueObjectAppendString(virJSONValue *object, const char *key, 
const char *value);
 int virJSONValueObjectAppendStringPrintf(virJSONValue *object, const char 
*key, const char *fmt, ...)
-- 
2.31.1



[PATCH 6/6] util: virjson.h: Reformat headers to conform with new style

2021-12-22 Thread Peter Krempa
Signed-off-by: Peter Krempa 
---
 src/util/virjson.h | 312 +++--
 1 file changed, 218 insertions(+), 94 deletions(-)

diff --git a/src/util/virjson.h b/src/util/virjson.h
index 24ac51f4f8..f0b8c419de 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -39,123 +39,247 @@ typedef enum {

 typedef struct _virJSONValue virJSONValue;

-void virJSONValueFree(virJSONValue *value);
-void virJSONValueHashFree(void *opaque);
+void
+virJSONValueFree(virJSONValue *value);
+void
+virJSONValueHashFree(void *opaque);

-virJSONType virJSONValueGetType(const virJSONValue *value);
+virJSONType
+virJSONValueGetType(const virJSONValue *value);

-int virJSONValueObjectAdd(virJSONValue **obj, ...)
+int
+virJSONValueObjectAdd(virJSONValue **obj, ...)
 ATTRIBUTE_NONNULL(1) G_GNUC_NULL_TERMINATED;
-int virJSONValueObjectAddVArgs(virJSONValue **objptr, va_list args)
+int
+virJSONValueObjectAddVArgs(virJSONValue **objptr,
+   va_list args)
 ATTRIBUTE_NONNULL(1);


-virJSONValue *virJSONValueNewString(char *data);
-virJSONValue *virJSONValueNewNumberInt(int data);
-virJSONValue *virJSONValueNewNumberUint(unsigned int data);
-virJSONValue *virJSONValueNewNumberLong(long long data);
-virJSONValue *virJSONValueNewNumberUlong(unsigned long long data);
-virJSONValue *virJSONValueNewNumberDouble(double data);
-virJSONValue *virJSONValueNewBoolean(int boolean);
-virJSONValue *virJSONValueNewNull(void);
-virJSONValue *virJSONValueNewArray(void);
-virJSONValue *virJSONValueNewObject(void);
+virJSONValue *
+virJSONValueNewString(char *data);
+virJSONValue *
+virJSONValueNewNumberInt(int data);
+virJSONValue *
+virJSONValueNewNumberUint(unsigned int data);
+virJSONValue *
+virJSONValueNewNumberLong(long long data);
+virJSONValue *
+virJSONValueNewNumberUlong(unsigned long long data);
+virJSONValue *
+virJSONValueNewNumberDouble(double data);
+virJSONValue *
+virJSONValueNewBoolean(int boolean);
+virJSONValue *
+virJSONValueNewNull(void);
+virJSONValue *
+virJSONValueNewArray(void);
+virJSONValue *
+virJSONValueNewObject(void);
+
+int
+virJSONValueObjectAppend(virJSONValue *object,
+ const char *key,
+ virJSONValue **value);
+int
+virJSONValueArrayAppend(virJSONValue *object,
+virJSONValue **value);
+int
+virJSONValueArrayConcat(virJSONValue *a,
+virJSONValue *c);
+
+int
+virJSONValueObjectHasKey(virJSONValue *object,
+ const char *key);
+virJSONValue *
+virJSONValueObjectGet(virJSONValue *object,
+  const char *key);
+virJSONValue *
+virJSONValueObjectGetByType(virJSONValue *object,
+const char *key,
+virJSONType type);
+
+bool
+virJSONValueIsObject(virJSONValue *object);
+
+bool
+virJSONValueIsArray(virJSONValue *array);
+size_t
+virJSONValueArraySize(const virJSONValue *array);
+virJSONValue *
+virJSONValueArrayGet(virJSONValue *object,
+ unsigned int element);
+virJSONValue *
+virJSONValueArraySteal(virJSONValue *object,
+   unsigned int element);

-int virJSONValueObjectAppend(virJSONValue *object,
- const char *key,
- virJSONValue **value);
-int virJSONValueArrayAppend(virJSONValue *object,
-virJSONValue **value);
-int virJSONValueArrayConcat(virJSONValue *a,
-virJSONValue *c);
-
-int virJSONValueObjectHasKey(virJSONValue *object, const char *key);
-virJSONValue *virJSONValueObjectGet(virJSONValue *object, const char *key);
-virJSONValue *virJSONValueObjectGetByType(virJSONValue *object,
-const char *key, virJSONType type);
-
-bool virJSONValueIsObject(virJSONValue *object);
-
-bool virJSONValueIsArray(virJSONValue *array);
-size_t virJSONValueArraySize(const virJSONValue *array);
-virJSONValue *virJSONValueArrayGet(virJSONValue *object, unsigned int element);
-virJSONValue *virJSONValueArraySteal(virJSONValue *object, unsigned int 
element);
 typedef int (*virJSONArrayIteratorFunc)(size_t pos,
 virJSONValue *item,
 void *opaque);
-int virJSONValueArrayForeachSteal(virJSONValue *array,
-  virJSONArrayIteratorFunc cb,
-  void *opaque);

-int virJSONValueObjectKeysNumber(virJSONValue *object);
-const char *virJSONValueObjectGetKey(virJSONValue *object, unsigned int n);
-virJSONValue *virJSONValueObjectGetValue(virJSONValue *object, unsigned int n);
-
-const char *virJSONValueGetString(virJSONValue *object);
-const char *virJSONValueGetNumberString(virJSONValue *number);
-int virJSONValueGetNumberInt(virJSONValue *object, int *value);
-int virJSONValueGetNumberUint(virJSONValue *object, unsigned int *value);
-int virJSONValueGetNumberLong

Re: [PATCH 0/2] gnutls: Be more clever about DH key size

2021-12-22 Thread Martin Kletzander

On Tue, Dec 21, 2021 at 03:22:57PM +0100, Michal Privoznik wrote:

See 2/2 for explanation.

Ideally, we wouldn't use gnutls_dh_params_generate2() at all, per [1].
But that would require bumping minimal required version to gnutls-3.6.0
and I'm not sure how available it is in OSes we support. Therefore, for


As far as I can tell from repology.org all the major distros have 3.6.x
in more than one version and definitely all those that we have in the
CI, so I'd say bump that.


now let's stick with patch 2/2.

1: https://www.gnutls.org/manual/html_node/Parameter-generation.html

Michal Prívozník (2):
 virnettlscontext: Drop gnutls_dh_set_prime_bits()
 virnettlscontext: Don't pass static key length to
   gnutls_dh_params_generate2()

src/rpc/virnettlscontext.c | 15 ++-
1 file changed, 10 insertions(+), 5 deletions(-)

--
2.32.0



signature.asc
Description: PGP signature


Re: [PATCH 0/6] json helper cleanups

2021-12-22 Thread Ján Tomko

On a Wednesday in 2021, Peter Krempa wrote:

Peter Krempa (6):
 qemuBlockStorageSourceGetRBDProps: Simplify generation of auth modes
 Replace open coded virJSONValueArrayAppendString
 util: json: Don't copy string in virJSONValueNewString
 util: json: Open-code only call of virJSONValueNewStringLen
 util: json: Remove virJSONValueIsNull/virJSONValueObjectIsNull
 util: virjson.h: Reformat headers to conform with new style

src/libvirt_private.syms |   3 -
src/qemu/qemu_agent.c|   4 +-
src/qemu/qemu_block.c|  10 +-
src/util/virjson.c   |  57 +--
src/util/virjson.h   | 315 +++
src/util/virmacmap.c |   4 +-
tests/virjsontest.c  |   4 +-
7 files changed, 231 insertions(+), 166 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH 1/2] virnettlscontext: Drop gnutls_dh_set_prime_bits()

2021-12-22 Thread Ján Tomko

On a Tuesday in 2021, Michal Privoznik wrote:

According to the gnutls_dh_set_prime_bits() manpage:

 The function has no effect in server side.



On top of that, it is deprecated as of 3.1.7 while our minimum version
is 3.2.


Therefore, don't call it when creating server side context.

Signed-off-by: Michal Privoznik 
---
src/rpc/virnettlscontext.c | 2 --
1 file changed, 2 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH 0/6] json helper cleanups

2021-12-22 Thread Tim Wiederhake
On Wed, 2021-12-22 at 13:02 +0100, Peter Krempa wrote:
> Peter Krempa (6):
>   qemuBlockStorageSourceGetRBDProps: Simplify generation of auth
> modes
>   Replace open coded virJSONValueArrayAppendString
>   util: json: Don't copy string in virJSONValueNewString
>   util: json: Open-code only call of virJSONValueNewStringLen
>   util: json: Remove virJSONValueIsNull/virJSONValueObjectIsNull
>   util: virjson.h: Reformat headers to conform with new style
> 
>  src/libvirt_private.syms |   3 -
>  src/qemu/qemu_agent.c    |   4 +-
>  src/qemu/qemu_block.c    |  10 +-
>  src/util/virjson.c   |  57 +--
>  src/util/virjson.h   | 315 +++--
> --
>  src/util/virmacmap.c |   4 +-
>  tests/virjsontest.c  |   4 +-
>  7 files changed, 231 insertions(+), 166 deletions(-)
> 
Reviewed-by: Tim Wiederhake 



Re: [libvirt PATCH v2] qemu: Fix typo in comment

2021-12-22 Thread Ján Tomko

On a Monday in 2021, Tim Wiederhake wrote:

Signed-off-by: Tim Wiederhake 
---
src/qemu/qemu_monitor_json.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH 0/2] gnutls: Be more clever about DH key size

2021-12-22 Thread Ján Tomko

On a Wednesday in 2021, Martin Kletzander wrote:

On Tue, Dec 21, 2021 at 03:22:57PM +0100, Michal Privoznik wrote:

See 2/2 for explanation.

Ideally, we wouldn't use gnutls_dh_params_generate2() at all, per [1].
But that would require bumping minimal required version to gnutls-3.6.0
and I'm not sure how available it is in OSes we support. Therefore, for


As far as I can tell from repology.org all the major distros have 3.6.x
in more than one version and definitely all those that we have in the
CI, so I'd say bump that.



There's Ubuntu 18.04 with 3.5.18.

But we could #ifndef the old code out and use the pre-generated
parameters on every other distro, as recommended.

Jano


signature.asc
Description: PGP signature


Re: [PATCH 2/2] virnettlscontext: Don't pass static key length to gnutls_dh_params_generate2()

2021-12-22 Thread Ján Tomko

On a Tuesday in 2021, Michal Privoznik wrote:

As encryption norms get more strict it's easy to fall on the
insecure side. For instance, so far we are generating 2048 bits
long prime for Diffie-Hellman keys. Some systems consider this
not long enough. While we may just keep increasing the value
passed to the corresponding gnutls_* function, that is not well
maintainable. Instead, we may do what's recommended in the


Is there a promise gnutls will increase those in the future?


gnutls_* manpage. From gnutls_dh_params_generate2(3):

 It is recommended not to set the number of bits directly, but
 use gnutls_sec_param_to_pk_bits() instead.

Looking into the gnutls_sec_param_to_pk_bits() then [1], 2048
bits corresponds to parameter MEDIUM. Therefore, we want to chose
the next size (HIGH) to be future proof.


IMO this patch should use MEDIUM and the bump should be separate.



1: https://www.gnutls.org/manual/gnutls.html#tab_003akey_002dsizes

Signed-off-by: Michal Privoznik 
---
src/rpc/virnettlscontext.c | 13 ++---
1 file changed, 10 insertions(+), 3 deletions(-)



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH v6 4/4] NEWS: mention removal of sysconfig

2021-12-22 Thread Olaf Hering
Tue, 21 Dec 2021 16:33:11 -0700 Jim Fehlig :

> What do you think of the below, slightly reworded variant?

As a native speaker you are in the perfect position to formulate a suitable 
paragraph for the NEWS file.
This new variant is certainly fine with me. If it is supposed to go into 
"Packaging changes" or "Improvements", no idea.

Olaf


pgpQXXiH4Uvlz.pgp
Description: Digitale Signatur von OpenPGP


[PATCH 0/5] tests: Tool for programatic modification of qemucapabilitiesdata/*.replies

2021-12-22 Thread Peter Krempa
I was asked multiple times how to automate modification of the qemu
capability dumps. I wrote a tool [1] that allowed doing that.
Unfortunately as it wasn't in the repo it was not avalilable.

Now I've finally set out to finish it. It masquerades as a test in
default mode checking the ordering and numbering of the caps dump files
as in the past there were few cases where manual edits broke it.

In update mode it allows modification of the replies and gives few
examples to do so. There's a lot of possible things users would want to
do so there's no way around actually writing some code but it should be
easier this way.

Since this now does also numbering, the AWK/shell script
'qemucapsfixreplies' can be removed.




[1]: Okay, okay. Copy&paste'd few bits from various places into one
messy C file and didn't bother with memory cleanup. But it worked.


Peter Krempa (5):
  util: json: Introduce virJSONValueObjectReplaceValue
  tests: qemumonitortestutils.h: Reformat header file
  qemumonitortestutils: Extract parser for the monitor conversation dump
file
  tests: Tool for programatic modification of
qemucapabilitiesdata/*.replies
  tests: Remove 'qemucapsfixreplies'

 src/libvirt_private.syms  |   1 +
 src/util/virjson.c|  20 +++
 src/util/virjson.h|   6 +
 tests/domaincapstest.c|   3 +-
 tests/meson.build |   1 +
 tests/qemucapabilitiesnumbering.c | 242 ++
 tests/qemucapabilitiestest.c  |   4 +-
 tests/qemucapsfixreplies  |  26 
 tests/qemumonitortestutils.c  | 123 ++-
 tests/qemumonitortestutils.h  | 149 +++---
 10 files changed, 453 insertions(+), 122 deletions(-)
 create mode 100644 tests/qemucapabilitiesnumbering.c
 delete mode 100755 tests/qemucapsfixreplies

-- 
2.31.1



[PATCH 1/5] util: json: Introduce virJSONValueObjectReplaceValue

2021-12-22 Thread Peter Krempa
The new helper replaces the 'value' part of the key-value tuple in an
object. The advantage of this new helper is that it preserves the
ordering of the key in the object when compared to a combination of
stealing the old key and adding a new value. This will be needed for a
new test/helper for validating and modifying qemu capabilities data.

Signed-off-by: Peter Krempa 
---
 src/libvirt_private.syms |  1 +
 src/util/virjson.c   | 20 
 src/util/virjson.h   |  6 ++
 3 files changed, 27 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 435ee8054c..431075899d 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2567,6 +2567,7 @@ virJSONValueObjectHasKey;
 virJSONValueObjectKeysNumber;
 virJSONValueObjectPrependString;
 virJSONValueObjectRemoveKey;
+virJSONValueObjectReplaceValue;
 virJSONValueObjectStealArray;
 virJSONValueObjectStealObject;
 virJSONValueToBuffer;
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 1c6fef22da..6e13e97e15 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -1149,6 +1149,26 @@ virJSONValueObjectGetString(virJSONValue *object,
 }


+void
+virJSONValueObjectReplaceValue(virJSONValue *object,
+   const char *key,
+   virJSONValue **newval)
+{
+size_t i;
+
+if (object->type != VIR_JSON_TYPE_OBJECT ||
+!*newval)
+return;
+
+for (i = 0; i < object->data.object.npairs; i++) {
+if (STREQ(object->data.object.pairs[i].key, key)) {
+virJSONValueFree(object->data.object.pairs[i].value);
+object->data.object.pairs[i].value = g_steal_pointer(newval);
+}
+}
+}
+
+
 /**
  * virJSONValueObjectGetStringOrNumber:
  * @object: JSON value object
diff --git a/src/util/virjson.h b/src/util/virjson.h
index f0b8c419de..aced48a538 100644
--- a/src/util/virjson.h
+++ b/src/util/virjson.h
@@ -248,6 +248,12 @@ virJSONValueObjectRemoveKey(virJSONValue *object,
 virJSONValue **value)
 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

+void
+virJSONValueObjectReplaceValue(virJSONValue *object,
+   const char *key,
+   virJSONValue **newval)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+
 int
 virJSONValueArrayAppendString(virJSONValue *object,
   const char *value);
-- 
2.31.1



[PATCH 3/5] qemumonitortestutils: Extract parser for the monitor conversation dump file

2021-12-22 Thread Peter Krempa
Make the parser reusable by extracting it and making it parse into
command,reply tuples.

Signed-off-by: Peter Krempa 
---
 tests/qemumonitortestutils.c | 123 ---
 tests/qemumonitortestutils.h |  13 
 2 files changed, 99 insertions(+), 37 deletions(-)

diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index 0d99b45909..f7a0a37685 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -1278,45 +1278,33 @@ qemuMonitorTestFullAddItem(qemuMonitorTest *test,


 /**
- * qemuMonitorTestNewFromFileFull:
- * @fileName: File name to load monitor replies from
- * @driver: qemu driver object
- * @vm: domain object (may be null if it's not needed by the test)
- * @qmpschema: QMP schema data hash table if QMP checking is required
+ * qemuMonitorTestProcessFileEntries:
+ * @inputstr: input file contents (modified)
+ * @fileName: File name of @inputstr (for error reporting)
+ * @items: filled with command, reply tuples
+ * @nitems: Count of elements in @items.
  *
- * Create a JSON test monitor simulator object and fill it with expected 
command
- * sequence and replies specified in @fileName.
+ * Process a monitor interaction file.
  *
  * The file contains a sequence of JSON commands and reply objects separated by
- * empty lines. A command is followed by a reply. The QMP greeting is added
- * automatically.
- *
- * Returns the monitor object on success; NULL on error.
+ * empty lines. A command is followed by a reply.
  */
-qemuMonitorTest *
-qemuMonitorTestNewFromFileFull(const char *fileName,
-   virQEMUDriver *driver,
-   virDomainObj *vm,
-   GHashTable *qmpschema)
+int
+qemuMonitorTestProcessFileEntries(char *inputstr,
+  const char *fileName,
+  struct qemuMonitorTestCommandReplyTuple 
**items,
+  size_t *nitems)
 {
-g_autoptr(qemuMonitorTest) ret = NULL;
-g_autofree char *jsonstr = NULL;
-char *tmp;
+size_t nalloc = 0;
+char *tmp = inputstr;
 size_t line = 0;
-
-char *command = NULL;
+char *command = inputstr;
 char *response = NULL;
 size_t commandln = 0;

-if (virTestLoadFile(fileName, &jsonstr) < 0)
-return NULL;
-
-if (!(ret = qemuMonitorTestNew(driver->xmlopt, vm, driver, NULL,
-   qmpschema)))
-return NULL;
+*items = NULL;
+*nitems = 0;

-tmp = jsonstr;
-command = tmp;
 while ((tmp = strchr(tmp, '\n'))) {
 line++;

@@ -1335,11 +1323,16 @@ qemuMonitorTestNewFromFileFull(const char *fileName,
 *(tmp + 1) = '\0';

 if (response) {
-if (qemuMonitorTestFullAddItem(ret, fileName, command,
-   response, commandln) < 0)
-return NULL;
-command = NULL;
-response = NULL;
+struct qemuMonitorTestCommandReplyTuple *item;
+
+VIR_RESIZE_N(*items, nalloc, *nitems, 1);
+
+item = *items + *nitems;
+
+item->command = g_steal_pointer(&command);
+item->reply = g_steal_pointer(&response);
+item->line = commandln;
+(*nitems)++;
 }

 /* Move the @tmp and @singleReply. */
@@ -1354,14 +1347,70 @@ qemuMonitorTestNewFromFileFull(const char *fileName,
 }

 if (command) {
+struct qemuMonitorTestCommandReplyTuple *item;
+
 if (!response) {
 virReportError(VIR_ERR_INTERNAL_ERROR, "missing response for 
command "
"on line '%zu' in '%s'", commandln, fileName);
-return NULL;
+return -1;
 }

-if (qemuMonitorTestFullAddItem(ret, fileName, command,
-   response, commandln) < 0)
+VIR_RESIZE_N(*items, nalloc, *nitems, 1);
+
+item = *items + *nitems;
+
+item->command = g_steal_pointer(&command);
+item->reply = g_steal_pointer(&response);
+item->line = commandln;
+(*nitems)++;
+}
+
+return 0;
+}
+
+/**
+ * qemuMonitorTestNewFromFileFull:
+ * @fileName: File name to load monitor replies from
+ * @driver: qemu driver object
+ * @vm: domain object (may be null if it's not needed by the test)
+ * @qmpschema: QMP schema data hash table if QMP checking is required
+ *
+ * Create a JSON test monitor simulator object and fill it with expected 
command
+ * sequence and replies specified in @fileName.
+ *
+ * The file contains a sequence of JSON commands and reply objects separated by
+ * empty lines. A command is followed by a reply. The QMP greeting is added
+ * automatically.
+ *
+ * Returns the monitor object on success; NULL on error.
+ */
+qemuMonitorTest *
+qemuMonitorTestNewFromFileFull(const char *fileName,
+   virQEMUDriver *driver,
+  

[PATCH 5/5] tests: Remove 'qemucapsfixreplies'

2021-12-22 Thread Peter Krempa
The 'qemucapabilitiesnumbering' tool now replaces the role of this
script and provides way to programmatically modify the replies file on
top.

Signed-off-by: Peter Krempa 
---
 tests/domaincapstest.c   |  3 ++-
 tests/qemucapabilitiestest.c |  4 +++-
 tests/qemucapsfixreplies | 26 --
 3 files changed, 5 insertions(+), 28 deletions(-)
 delete mode 100755 tests/qemucapsfixreplies

diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index 479bcb1c35..da5c629fd4 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -422,7 +422,8 @@ mymain(void)
  * to generate updated or new *.replies data files.
  *
  * If you manually edit replies files you can run
- * "tests/qemucapsfixreplies foo.replies" to fix the replies ids.
+ * VIR_TEST_REGENERATE_OUTPUT=1 tests/qemucapabilitiesnumbering
+ * to fix the replies ids.
  *
  * Once a replies file has been generated and tweaked if necessary,
  * you can drop it into tests/qemucapabilitiesdata/ (with a sensible
diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c
index 99534ab9a1..ae208f442c 100644
--- a/tests/qemucapabilitiestest.c
+++ b/tests/qemucapabilitiestest.c
@@ -212,7 +212,9 @@ mymain(void)
  * to generate updated or new *.replies data files.
  *
  * If you manually edit replies files you can run
- * "tests/qemucapsfixreplies foo.replies" to fix the replies ids.
+ * VIR_TEST_REGENERATE_OUTPUT=1 tests/qemucapabilitiesnumbering
+ * to fix the replies ids. The tool also allows for programatic 
modification
+ * of the replies file.
  *
  * Once a replies file has been generated and tweaked if necessary,
  * you can drop it into tests/qemucapabilitiesdata/ (with a sensible
diff --git a/tests/qemucapsfixreplies b/tests/qemucapsfixreplies
deleted file mode 100755
index 597f9ecd6e..00
--- a/tests/qemucapsfixreplies
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/sh
-
-if [ "$#" -ne 1 ] || [ "$1" = "--help" ] || [ ! -f "$1" ]; then
-echo "This script fixes replies ids in QEMU replies files."
-echo ""
-echo "  Usage: $0 path/to/qemu.replies"
-exit 0
-fi
-
-awk -i inplace \
-'BEGIN {last=0; pattern="libvirt-[0-9]+"}
-{
-if (match($0, "libvirt-1[^0-9]")) {
-count=1;
-}
-if (match($0, pattern)) {
-str="libvirt-" count;
-sub(pattern, str, $0);
-if (last != count) {
-last=count;
-} else {
-count++;
-}
-}
-print
-}' "$1"
-- 
2.31.1



[PATCH 2/5] tests: qemumonitortestutils.h: Reformat header file

2021-12-22 Thread Peter Krempa
Signed-off-by: Peter Krempa 
---
 tests/qemumonitortestutils.h | 140 ---
 1 file changed, 81 insertions(+), 59 deletions(-)

diff --git a/tests/qemumonitortestutils.h b/tests/qemumonitortestutils.h
index e572627e20..89c33c434b 100644
--- a/tests/qemumonitortestutils.h
+++ b/tests/qemumonitortestutils.h
@@ -31,76 +31,98 @@ typedef int 
(*qemuMonitorTestResponseCallback)(qemuMonitorTest *test,
qemuMonitorTestItem *item,
const char *message);

-int qemuMonitorTestAddHandler(qemuMonitorTest *test,
-  const char *identifier,
-  qemuMonitorTestResponseCallback cb,
-  void *opaque,
-  virFreeCallback freecb);
-
-int qemuMonitorTestAddResponse(qemuMonitorTest *test,
-   const char *response);
-
-int qemuMonitorTestAddInvalidCommandResponse(qemuMonitorTest *test,
- const char *expectedcommand,
- const char *actualcommand);
-
-void *qemuMonitorTestItemGetPrivateData(qemuMonitorTestItem *item);
-
-int qemuMonitorTestAddErrorResponse(qemuMonitorTest *test, const char *errmsg, 
...);
-
-void qemuMonitorTestAllowUnusedCommands(qemuMonitorTest *test);
-void qemuMonitorTestSkipDeprecatedValidation(qemuMonitorTest *test,
- bool allowRemoved);
-
-int qemuMonitorTestAddItem(qemuMonitorTest *test,
-   const char *command_name,
+int
+qemuMonitorTestAddHandler(qemuMonitorTest *test,
+  const char *identifier,
+  qemuMonitorTestResponseCallback cb,
+  void *opaque,
+  virFreeCallback freecb);
+
+int
+qemuMonitorTestAddResponse(qemuMonitorTest *test,
const char *response);

-int qemuMonitorTestAddItemVerbatim(qemuMonitorTest *test,
-   const char *command,
-   const char *cmderr,
-   const char *response);
+int
+qemuMonitorTestAddInvalidCommandResponse(qemuMonitorTest *test,
+ const char *expectedcommand,
+ const char *actualcommand);
+
+void *
+qemuMonitorTestItemGetPrivateData(qemuMonitorTestItem *item);
+
+int
+qemuMonitorTestAddErrorResponse(qemuMonitorTest *test,
+const char *errmsg,
+...);
+
+void
+qemuMonitorTestAllowUnusedCommands(qemuMonitorTest *test);
+void
+qemuMonitorTestSkipDeprecatedValidation(qemuMonitorTest *test,
+bool allowRemoved);
+
+int
+qemuMonitorTestAddItem(qemuMonitorTest *test,
+   const char *command_name,
+   const char *response);
+
+int
+qemuMonitorTestAddItemVerbatim(qemuMonitorTest *test,
+   const char *command,
+   const char *cmderr,
+   const char *response);

-int qemuMonitorTestAddAgentSyncResponse(qemuMonitorTest *test);
+int
+qemuMonitorTestAddAgentSyncResponse(qemuMonitorTest *test);

-int qemuMonitorTestAddItemParams(qemuMonitorTest *test,
- const char *cmdname,
- const char *response,
- ...)
+int
+qemuMonitorTestAddItemParams(qemuMonitorTest *test,
+ const char *cmdname,
+ const char *response,
+ ...)
 G_GNUC_NULL_TERMINATED;

-int qemuMonitorTestAddItemExpect(qemuMonitorTest *test,
- const char *cmdname,
- const char *cmdargs,
- bool apostrophe,
- const char *response);
+int
+qemuMonitorTestAddItemExpect(qemuMonitorTest *test,
+ const char *cmdname,
+ const char *cmdargs,
+ bool apostrophe,
+ const char *response);

 #define qemuMonitorTestNewSimple(xmlopt) \
 qemuMonitorTestNew(xmlopt, NULL, NULL, NULL, NULL)
 #define qemuMonitorTestNewSchema(xmlopt, schema) \
 qemuMonitorTestNew(xmlopt, NULL, NULL, NULL, schema)

-qemuMonitorTest *qemuMonitorTestNew(virDomainXMLOption *xmlopt,
-  virDomainObj *vm,
-  virQEMUDriver *driver,
-  const char *greeting,
-  GHashTable *schema);
-
-qemuMonitorTest *qemuMonitorTestNewFromFile(const char *fileName,
-  

[PATCH 4/5] tests: Tool for programatic modification of qemucapabilitiesdata/*.replies

2021-12-22 Thread Peter Krempa
The tool is assembled from individual bits used for tests and actual
capturing of the replies files. The tool ensures correct numbering and
formatting of entries.

In normal usage mode it masks as a test which validates formatting and
numbering of the tests/qemucapabilitiesdata/*.replies files. This tool
was actually used to produce commits 096ac87a1a46 and aa21615ccbc.

In case a manual modification of the replies file is needed the
'modify()' function provides a convenient way to do programatic
modification of the caps file.

As an example the modify() function has commented-out code which
provides a basic scaffold to do modifications along with a how-to.

Signed-off-by: Peter Krempa 
---
 tests/meson.build |   1 +
 tests/qemucapabilitiesnumbering.c | 242 ++
 2 files changed, 243 insertions(+)
 create mode 100644 tests/qemucapabilitiesnumbering.c

diff --git a/tests/meson.build b/tests/meson.build
index f75c248720..4792220b48 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -452,6 +452,7 @@ if conf.has('WITH_QEMU')
 { 'name': 'qemuagenttest', 'link_with': [ test_qemu_driver_lib, 
test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] },
 { 'name': 'qemublocktest', 'include': [ storage_file_inc_dir ], 
'link_with': [ test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 
'link_whole': [ test_utils_qemu_lib ] },
 { 'name': 'qemucapabilitiestest', 'link_with': [ test_qemu_driver_lib, 
test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] },
+{ 'name': 'qemucapabilitiesnumbering', 'link_with': [ 
test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole': [ 
test_utils_qemu_lib ] },
 { 'name': 'qemucaps2xmltest', 'link_with': [ test_qemu_driver_lib ], 
'link_whole': [ test_utils_qemu_lib ] },
 { 'name': 'qemucommandutiltest', 'link_with': [ test_qemu_driver_lib, 
test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] },
 { 'name': 'qemudomaincheckpointxml2xmltest', 'link_with': [ 
test_qemu_driver_lib ], 'link_whole': [ test_utils_qemu_lib ] },
diff --git a/tests/qemucapabilitiesnumbering.c 
b/tests/qemucapabilitiesnumbering.c
new file mode 100644
index 00..eff7dbe2a1
--- /dev/null
+++ b/tests/qemucapabilitiesnumbering.c
@@ -0,0 +1,242 @@
+/*
+ * qemucapabilitiesnumbering.c: swiss-army knife for qemu capability data 
manipulation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+#include 
+
+#include "testutils.h"
+#include "testutilsqemu.h"
+#include "qemumonitortestutils.h"
+
+struct qmpTuple {
+virJSONValue *command;
+virJSONValue *reply;
+};
+
+struct qmpCommandList {
+struct qmpTuple *items;
+size_t nitems;
+};
+
+typedef struct qmpCommandList qmpCommandList;
+
+
+static int
+modify(struct qmpCommandList *list G_GNUC_UNUSED)
+{
+/* in case you want to programmatically modify the replies file enable the
+ * following block and modify it to your needs. After compiling run this
+ * with:
+ *
+ * VIR_TEST_REGENERATE_OUTPUT=1 tests/qemucapabilitiesnumbering
+ *
+ * This applies the modification along with updating the files. Use git to
+ * your advantage to roll back mistakes.
+ */
+#if 0
+struct qmpTuple tmptuple = { NULL, NULL };
+size_t found = 0;
+size_t i;
+
+for (i = 0; i < list->nitems; i++) {
+struct qmpTuple *item = list->items + i;
+const char *cmdname = virJSONValueObjectGetString(item->command, 
"execute");
+
+if (STREQ_NULLABLE(cmdname, "qom-list-properties")) {
+found = i;
+// break; /* uncomment if you want to find the first occurence */
+}
+}
+
+if (found == 0) {
+fprintf(stderr, "entry not found!!!\n");
+return -1;
+}
+
+tmptuple.command = virJSONValueFromString("{\"execute\":\"dummy\"}");
+tmptuple.reply = virJSONValueFromString("{\"return\":{}}");
+// tmptuple.reply = virTestLoadFileJSON("path/", "to/", "file.json");
+
+ignore_value(VIR_INSERT_ELEMENT(list->items, found + 1, list->nitems, 
tmptuple));
+#endif
+
+return 0;
+}
+
+
+static void
+qmpCommandListFree(qmpCommandList* list)
+{
+size_t i;
+
+if (!list)
+return;
+
+for (i = 0; i < list->nitems; i++) {
+struct qmpTuple *item = list->items + i;
+
+virJSONValueFre

Re: [PATCH 0/2] gnutls: Be more clever about DH key size

2021-12-22 Thread Martin Kletzander

On Wed, Dec 22, 2021 at 02:14:59PM +0100, Ján Tomko wrote:

On a Wednesday in 2021, Martin Kletzander wrote:

On Tue, Dec 21, 2021 at 03:22:57PM +0100, Michal Privoznik wrote:

See 2/2 for explanation.

Ideally, we wouldn't use gnutls_dh_params_generate2() at all, per [1].
But that would require bumping minimal required version to gnutls-3.6.0
and I'm not sure how available it is in OSes we support. Therefore, for


As far as I can tell from repology.org all the major distros have 3.6.x
in more than one version and definitely all those that we have in the
CI, so I'd say bump that.



There's Ubuntu 18.04 with 3.5.18.



And we consider only LTS, so we can drop that in April when 20.04 is out
for 2 years.  I finally found the exact spelling in docs/platform.rst
(available online at https://libvirt.org/platforms.html as well) which I
always struggle to find.


But we could #ifndef the old code out and use the pre-generated
parameters on every other distro, as recommended.



Since counting the bits is so discouraged I would also prefer this
option with the hopes for us remembering to remove that.

Actually, can we have like a commit hook that would check current date
against some file in the repository and just let us know that there
might be something to remove? O:-)


Jano





signature.asc
Description: PGP signature


Re: [PATCH 2/2] virnettlscontext: Don't pass static key length to gnutls_dh_params_generate2()

2021-12-22 Thread Martin Kletzander

On Wed, Dec 22, 2021 at 02:12:37PM +0100, Ján Tomko wrote:

On a Tuesday in 2021, Michal Privoznik wrote:

As encryption norms get more strict it's easy to fall on the
insecure side. For instance, so far we are generating 2048 bits
long prime for Diffie-Hellman keys. Some systems consider this
not long enough. While we may just keep increasing the value
passed to the corresponding gnutls_* function, that is not well
maintainable. Instead, we may do what's recommended in the


Is there a promise gnutls will increase those in the future?



That is the whole point of the levels that they are not fixed and also
that distributions can select theirs.  And the fact that you can have
one option for the whole system.  Which makes me realise that we should
actually try that and not pick a level ourselves.  Having said that I
should also add that I do not know how to do that.  Maybe use "SYSTEM"
or "DEFAULT"?


gnutls_* manpage. From gnutls_dh_params_generate2(3):

 It is recommended not to set the number of bits directly, but
 use gnutls_sec_param_to_pk_bits() instead.

Looking into the gnutls_sec_param_to_pk_bits() then [1], 2048
bits corresponds to parameter MEDIUM. Therefore, we want to chose
the next size (HIGH) to be future proof.


IMO this patch should use MEDIUM and the bump should be separate.



1: https://www.gnutls.org/manual/gnutls.html#tab_003akey_002dsizes

Signed-off-by: Michal Privoznik 
---
src/rpc/virnettlscontext.c | 13 ++---
1 file changed, 10 insertions(+), 3 deletions(-)



Reviewed-by: Ján Tomko 

Jano





signature.asc
Description: PGP signature


[PATCH] ci: Refresh dockerfiles

2021-12-22 Thread Peter Krempa
Apart from some churn, the important is the removal of 'netcf-devel'
from the fedora rawhide container.

Update to state as of 174fe4999204afcae (libvirt-ci).

Signed-off-by: Peter Krempa 
---

Pushed as trivial. It makes CI green again.

 .../debian-10-cross-aarch64.Dockerfile | 18 +-
 .../debian-10-cross-armv6l.Dockerfile  | 18 +-
 .../debian-10-cross-armv7l.Dockerfile  | 18 +-
 ci/containers/debian-10-cross-i686.Dockerfile  | 18 +-
 ci/containers/debian-10-cross-mips.Dockerfile  | 18 +-
 .../debian-10-cross-mips64el.Dockerfile| 18 +-
 .../debian-10-cross-mipsel.Dockerfile  | 18 +-
 .../debian-10-cross-ppc64le.Dockerfile | 18 +-
 ci/containers/debian-10-cross-s390x.Dockerfile | 18 +-
 .../debian-11-cross-aarch64.Dockerfile | 12 ++--
 .../debian-11-cross-armv6l.Dockerfile  | 12 ++--
 .../debian-11-cross-armv7l.Dockerfile  | 12 ++--
 ci/containers/debian-11-cross-i686.Dockerfile  | 12 ++--
 .../debian-11-cross-mips64el.Dockerfile| 12 ++--
 .../debian-11-cross-mipsel.Dockerfile  | 12 ++--
 .../debian-11-cross-ppc64le.Dockerfile | 12 ++--
 ci/containers/debian-11-cross-s390x.Dockerfile | 12 ++--
 .../debian-sid-cross-aarch64.Dockerfile| 12 ++--
 .../debian-sid-cross-armv6l.Dockerfile | 12 ++--
 .../debian-sid-cross-armv7l.Dockerfile | 12 ++--
 ci/containers/debian-sid-cross-i686.Dockerfile | 12 ++--
 .../debian-sid-cross-mips64el.Dockerfile   | 12 ++--
 .../debian-sid-cross-mipsel.Dockerfile | 12 ++--
 .../debian-sid-cross-ppc64le.Dockerfile| 12 ++--
 .../debian-sid-cross-s390x.Dockerfile  | 12 ++--
 .../fedora-35-cross-mingw32.Dockerfile | 12 ++--
 .../fedora-35-cross-mingw64.Dockerfile | 12 ++--
 .../fedora-rawhide-cross-mingw32.Dockerfile| 12 ++--
 .../fedora-rawhide-cross-mingw64.Dockerfile| 12 ++--
 ci/containers/fedora-rawhide.Dockerfile|  1 -
 30 files changed, 201 insertions(+), 202 deletions(-)

diff --git a/ci/containers/debian-10-cross-aarch64.Dockerfile 
b/ci/containers/debian-10-cross-aarch64.Dockerfile
index 38013eb84b..cfbf5bb48f 100644
--- a/ci/containers/debian-10-cross-aarch64.Dockerfile
+++ b/ci/containers/debian-10-cross-aarch64.Dockerfile
@@ -56,6 +56,15 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
 sed -Ei 's,^# (en_US\.UTF-8 .*)$,\1,' /etc/locale.gen && \
 dpkg-reconfigure locales

+RUN pip3 install \
+ meson==0.56.0
+
+ENV LANG "en_US.UTF-8"
+ENV MAKE "/usr/bin/make"
+ENV NINJA "/usr/bin/ninja"
+ENV PYTHON "/usr/bin/python3"
+ENV CCACHE_WRAPPERSDIR "/usr/libexec/ccache-wrappers"
+
 RUN export DEBIAN_FRONTEND=noninteractive && \
 dpkg --add-architecture arm64 && \
 eatmydata apt-get update && \
@@ -117,14 +126,5 @@ endian = 'little'" > 
/usr/local/share/meson/cross/aarch64-linux-gnu && \
 ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/aarch64-linux-gnu-cc && 
\
 ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/aarch64-linux-gnu-gcc

-RUN pip3 install \
- meson==0.56.0
-
-ENV LANG "en_US.UTF-8"
-ENV MAKE "/usr/bin/make"
-ENV NINJA "/usr/bin/ninja"
-ENV PYTHON "/usr/bin/python3"
-ENV CCACHE_WRAPPERSDIR "/usr/libexec/ccache-wrappers"
-
 ENV ABI "aarch64-linux-gnu"
 ENV MESON_OPTS "--cross-file=aarch64-linux-gnu"
diff --git a/ci/containers/debian-10-cross-armv6l.Dockerfile 
b/ci/containers/debian-10-cross-armv6l.Dockerfile
index f9bfa031fa..3308ac2e10 100644
--- a/ci/containers/debian-10-cross-armv6l.Dockerfile
+++ b/ci/containers/debian-10-cross-armv6l.Dockerfile
@@ -56,6 +56,15 @@ RUN export DEBIAN_FRONTEND=noninteractive && \
 sed -Ei 's,^# (en_US\.UTF-8 .*)$,\1,' /etc/locale.gen && \
 dpkg-reconfigure locales

+RUN pip3 install \
+ meson==0.56.0
+
+ENV LANG "en_US.UTF-8"
+ENV MAKE "/usr/bin/make"
+ENV NINJA "/usr/bin/ninja"
+ENV PYTHON "/usr/bin/python3"
+ENV CCACHE_WRAPPERSDIR "/usr/libexec/ccache-wrappers"
+
 RUN export DEBIAN_FRONTEND=noninteractive && \
 dpkg --add-architecture armel && \
 eatmydata apt-get update && \
@@ -116,14 +125,5 @@ endian = 'little'" > 
/usr/local/share/meson/cross/arm-linux-gnueabi && \
 ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/arm-linux-gnueabi-cc && 
\
 ln -s /usr/bin/ccache /usr/libexec/ccache-wrappers/arm-linux-gnueabi-gcc

-RUN pip3 install \
- meson==0.56.0
-
-ENV LANG "en_US.UTF-8"
-ENV MAKE "/usr/bin/make"
-ENV NINJA "/usr/bin/ninja"
-ENV PYTHON "/usr/bin/python3"
-ENV CCACHE_WRAPPERSDIR "/usr/libexec/ccache-wrappers"
-
 ENV ABI "arm-linux-gnueabi"
 ENV MESON_OPTS "--cross-file=arm-linux-gnueabi"
diff --git a/ci/containers/debian-10-cross-armv7l.Dockerfile 
b/ci/containers/d

[libvirt PATCH v3 00/16] Add QEMU "-display dbus" support

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Hi,

This series implements supports for the uQEMU "-display dbus" support, that
landed earlier this week for 7.0.

By default, libvirt will start a private VM bus (sharing and reusing the
existing "vmstate" VM bus & code).

The feature set should cover the needs to replace Spice as local client of 
choice,
including 3daccel/dmabuf, audio, clipboard sharing, usb redirection, and 
arbitrary
chardev/channels (for serial etc).

The test Gtk4 client is also in progress, currently in development at
https://gitlab.com/marcandre.lureau/qemu-display/. A few dependencies, such as
zbus, require an upcoming release. virt-viewer & boxes will need a port to Gtk4
to make use of the shared widget.

Comments welcome, as we can still adjust the QEMU side etc.

thanks

v3: after QEMU 7.0 dev cycle opening and merge
 - rebased
 - add 7.0 x86-64 capabilities (instead of tweaking 6.2)
 - fix version annotations

Marc-André Lureau (16):
  qemu: add chardev-vdagent capability check
  qemu: add -display dbus capability check
  qemucapabilitiestest: Add x64 test data for the qemu-7.0 development
cycle
  conf: add 
  qemu: start the D-Bus daemon for the display
  qemu: add -display dbus support
  virsh: refactor/split cmdDomDisplay()
  virsh: report the D-Bus bus URI for domdisplay
  conf: add  support
  qemu: add audio type 'dbus'
  conf: add dbus 
  qemu: add dbus clipboard sharing
  conf: add 
  qemu: add -chardev dbus support
  qemu: add usbredir type 'dbus'
  docs: document  type dbus

 NEWS.rst  | 7 +-
 docs/formatdomain.rst |43 +-
 docs/schemas/basictypes.rng   | 7 +
 docs/schemas/domaincommon.rng |71 +
 src/bhyve/bhyve_command.c | 1 +
 src/conf/domain_conf.c|   141 +-
 src/conf/domain_conf.h|15 +
 src/conf/domain_validate.c|41 +-
 src/libxl/libxl_conf.c| 1 +
 src/qemu/qemu_capabilities.c  | 8 +
 src/qemu/qemu_capabilities.h  | 4 +
 src/qemu/qemu_command.c   |77 +-
 src/qemu/qemu_domain.c| 1 +
 src/qemu/qemu_driver.c|10 +-
 src/qemu/qemu_extdevice.c |13 +
 src/qemu/qemu_hotplug.c   | 1 +
 src/qemu/qemu_monitor_json.c  |10 +
 src/qemu/qemu_process.c   |41 +-
 src/qemu/qemu_validate.c  |33 +
 src/security/security_dac.c   | 2 +
 src/vmx/vmx.c | 1 +
 .../domaincapsdata/qemu_7.0.0-q35.x86_64.xml  |   231 +
 .../domaincapsdata/qemu_7.0.0-tcg.x86_64.xml  |   237 +
 tests/domaincapsdata/qemu_7.0.0.x86_64.xml|   231 +
 .../caps_6.1.0.x86_64.xml | 1 +
 .../caps_6.2.0.aarch64.xml| 1 +
 .../caps_6.2.0.x86_64.xml | 1 +
 .../caps_7.0.0.x86_64.replies | 37335 
 .../caps_7.0.0.x86_64.xml |  3720 ++
 .../graphics-dbus-address.args|30 +
 .../graphics-dbus-address.xml |35 +
 .../qemuxml2argvdata/graphics-dbus-audio.args |33 +
 .../qemuxml2argvdata/graphics-dbus-audio.xml  |45 +
 .../graphics-dbus-chardev.args|32 +
 .../graphics-dbus-chardev.xml |43 +
 .../graphics-dbus-clipboard.args  |31 +
 .../graphics-dbus-clipboard.xml   |35 +
 tests/qemuxml2argvdata/graphics-dbus-p2p.args |30 +
 tests/qemuxml2argvdata/graphics-dbus-p2p.xml  |33 +
 .../graphics-dbus-usbredir.args   |34 +
 .../graphics-dbus-usbredir.xml|30 +
 tests/qemuxml2argvdata/graphics-dbus.args |30 +
 tests/qemuxml2argvdata/graphics-dbus.xml  |33 +
 tests/qemuxml2argvtest.c  |22 +
 .../graphics-dbus-address.xml | 1 +
 .../graphics-dbus-audio.xml   | 1 +
 .../graphics-dbus-chardev.xml | 1 +
 .../graphics-dbus-clipboard.xml   | 1 +
 .../qemuxml2xmloutdata/graphics-dbus-p2p.xml  | 1 +
 tests/qemuxml2xmloutdata/graphics-dbus.xml| 1 +
 tests/qemuxml2xmltest.c   |20 +
 tools/virsh-domain.c  |   366 +-
 52 files changed, 42981 insertions(+), 192 deletions(-)
 create mode 100644 tests/domaincapsdata/qemu_7.0.0-q35.x86_64.xml
 create mode 100644 tests/domaincapsdata/qemu_7.0.0-tcg.x86_64.xml
 create mode 100644 tests/domaincapsdata/qemu_7.0.0.x86_64.xml
 create mode 100644 tests/qemucapabilitiesdata/caps_7.0.0.x86_64.replies
 create mode 100644 tests/qemucapabilitiesdata/caps_7.0.0.x86_64.xml
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-address.args
 create mode 100644 tests

[libvirt PATCH v3 01/16] qemu: add chardev-vdagent capability check

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 src/qemu/qemu_capabilities.c  | 2 ++
 src/qemu/qemu_capabilities.h  | 1 +
 tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml  | 1 +
 tests/qemucapabilitiesdata/caps_6.2.0.aarch64.xml | 1 +
 tests/qemucapabilitiesdata/caps_6.2.0.x86_64.xml  | 1 +
 5 files changed, 6 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 4f63322a9ea5..1cf56ace71b2 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -653,6 +653,7 @@ VIR_ENUM_IMPL(virQEMUCaps,
   "query-dirty-rate", /* QEMU_CAPS_QUERY_DIRTY_RATE */
   "rbd-encryption", /* QEMU_CAPS_RBD_ENCRYPTION */
   "sev-guest-kernel-hashes", /* QEMU_CAPS_SEV_GUEST_KERNEL_HASHES 
*/
+  "chardev-vdagent", /* QEMU_CAPS_CHARDEV_VDAGENT */
 );
 
 
@@ -1573,6 +1574,7 @@ static struct virQEMUCapsStringFlags 
virQEMUCapsQMPSchemaQueries[] = {
 { "screendump/arg-type/device", QEMU_CAPS_SCREENDUMP_DEVICE },
 { "set-numa-node/arg-type/+hmat-lb", QEMU_CAPS_NUMA_HMAT },
 { "object-add/arg-type/+sev-guest/kernel-hashes", 
QEMU_CAPS_SEV_GUEST_KERNEL_HASHES },
+{ "chardev-add/arg-type/backend/+qemu-vdagent", QEMU_CAPS_CHARDEV_VDAGENT 
},
 };
 
 typedef struct _virQEMUCapsObjectTypeProps virQEMUCapsObjectTypeProps;
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index aaac20a83496..dcbde052aedd 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -632,6 +632,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for 
syntax-check */
 QEMU_CAPS_QUERY_DIRTY_RATE, /* accepts query-dirty-rate */
 QEMU_CAPS_RBD_ENCRYPTION, /* Ceph RBD encryption support */
 QEMU_CAPS_SEV_GUEST_KERNEL_HASHES, /* sev-guest.kernel-hashes= */
+QEMU_CAPS_CHARDEV_VDAGENT, /* -chardev qemu-vdagent */
 
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
diff --git a/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml
index 1f4f49eb34ad..75cf496e7712 100644
--- a/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_6.1.0.x86_64.xml
@@ -239,6 +239,7 @@
   
   
   
+  
   6001000
   0
   43100243
diff --git a/tests/qemucapabilitiesdata/caps_6.2.0.aarch64.xml 
b/tests/qemucapabilitiesdata/caps_6.2.0.aarch64.xml
index 9662214cd882..032776706d7e 100644
--- a/tests/qemucapabilitiesdata/caps_6.2.0.aarch64.xml
+++ b/tests/qemucapabilitiesdata/caps_6.2.0.aarch64.xml
@@ -204,6 +204,7 @@
   
   
   
+  
   6001050
   0
   61700244
diff --git a/tests/qemucapabilitiesdata/caps_6.2.0.x86_64.xml 
b/tests/qemucapabilitiesdata/caps_6.2.0.x86_64.xml
index b7d6effa9419..0f8fbaecc542 100644
--- a/tests/qemucapabilitiesdata/caps_6.2.0.x86_64.xml
+++ b/tests/qemucapabilitiesdata/caps_6.2.0.x86_64.xml
@@ -241,6 +241,7 @@
   
   
   
+  
   6002000
   0
   43100244
-- 
2.34.1.8.g35151cf07204



[libvirt PATCH v3 02/16] qemu: add -display dbus capability check

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 src/qemu/qemu_capabilities.c | 4 
 src/qemu/qemu_capabilities.h | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 1cf56ace71b2..f6ba51229841 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -654,6 +654,9 @@ VIR_ENUM_IMPL(virQEMUCaps,
   "rbd-encryption", /* QEMU_CAPS_RBD_ENCRYPTION */
   "sev-guest-kernel-hashes", /* QEMU_CAPS_SEV_GUEST_KERNEL_HASHES 
*/
   "chardev-vdagent", /* QEMU_CAPS_CHARDEV_VDAGENT */
+
+  /* 420 */
+  "display-dbus", /* QEMU_CAPS_DISPLAY_DBUS */
 );
 
 
@@ -1575,6 +1578,7 @@ static struct virQEMUCapsStringFlags 
virQEMUCapsQMPSchemaQueries[] = {
 { "set-numa-node/arg-type/+hmat-lb", QEMU_CAPS_NUMA_HMAT },
 { "object-add/arg-type/+sev-guest/kernel-hashes", 
QEMU_CAPS_SEV_GUEST_KERNEL_HASHES },
 { "chardev-add/arg-type/backend/+qemu-vdagent", QEMU_CAPS_CHARDEV_VDAGENT 
},
+{ "query-display-options/ret-type/+dbus", QEMU_CAPS_DISPLAY_DBUS },
 };
 
 typedef struct _virQEMUCapsObjectTypeProps virQEMUCapsObjectTypeProps;
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index dcbde052aedd..d4d7a6c74daf 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -634,6 +634,9 @@ typedef enum { /* virQEMUCapsFlags grouping marker for 
syntax-check */
 QEMU_CAPS_SEV_GUEST_KERNEL_HASHES, /* sev-guest.kernel-hashes= */
 QEMU_CAPS_CHARDEV_VDAGENT, /* -chardev qemu-vdagent */
 
+/* 420 */
+QEMU_CAPS_DISPLAY_DBUS, /* -display dbus */
+
 QEMU_CAPS_LAST /* this must always be the last item */
 } virQEMUCapsFlags;
 
-- 
2.34.1.8.g35151cf07204



[libvirt PATCH v3 04/16] conf: add

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 docs/schemas/basictypes.rng   |  7 ++
 docs/schemas/domaincommon.rng | 33 
 src/conf/domain_conf.c| 78 ++-
 src/conf/domain_conf.h|  8 ++
 src/conf/domain_validate.c|  9 ++-
 src/libxl/libxl_conf.c|  1 +
 src/qemu/qemu_capabilities.c  |  2 +
 src/qemu/qemu_command.c   |  2 +
 src/qemu/qemu_domain.c|  1 +
 src/qemu/qemu_driver.c|  6 +-
 src/qemu/qemu_hotplug.c   |  1 +
 src/qemu/qemu_process.c   |  4 +
 src/qemu/qemu_validate.c  |  1 +
 src/vmx/vmx.c |  1 +
 .../domaincapsdata/qemu_7.0.0-q35.x86_64.xml  |  1 +
 .../domaincapsdata/qemu_7.0.0-tcg.x86_64.xml  |  1 +
 tests/domaincapsdata/qemu_7.0.0.x86_64.xml|  1 +
 .../graphics-dbus-address.xml | 35 +
 tests/qemuxml2argvdata/graphics-dbus-p2p.xml  | 33 
 tests/qemuxml2argvdata/graphics-dbus.xml  | 33 
 .../graphics-dbus-address.xml |  1 +
 .../qemuxml2xmloutdata/graphics-dbus-p2p.xml  |  1 +
 tests/qemuxml2xmloutdata/graphics-dbus.xml|  1 +
 tests/qemuxml2xmltest.c   | 10 +++
 24 files changed, 267 insertions(+), 4 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-address.xml
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-p2p.xml
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus.xml
 create mode 12 tests/qemuxml2xmloutdata/graphics-dbus-address.xml
 create mode 12 tests/qemuxml2xmloutdata/graphics-dbus-p2p.xml
 create mode 12 tests/qemuxml2xmloutdata/graphics-dbus.xml

diff --git a/docs/schemas/basictypes.rng b/docs/schemas/basictypes.rng
index a221ff6295c0..ae4d5682229c 100644
--- a/docs/schemas/basictypes.rng
+++ b/docs/schemas/basictypes.rng
@@ -220,6 +220,13 @@
   
   
 
+  
+  
+
+  .+
+
+  
+
   
   
 
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 7fa5c2b8b525..29a506cff86a 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4001,6 +4001,39 @@
 
   
 
+
+  
+dbus
+  
+  
+
+  
+
+  
+
+  
+  
+
+  
+
+  
+
+  
+  
+
+  
+
+  
+
+
+  
+
+  
+
+  
+
+  
+
 
   
 rdp
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 716c6d224007..1b44513d3415 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -920,6 +920,7 @@ VIR_ENUM_IMPL(virDomainGraphics,
   "desktop",
   "spice",
   "egl-headless",
+  "dbus",
 );
 
 VIR_ENUM_IMPL(virDomainGraphicsListen,
@@ -1900,6 +1901,11 @@ void virDomainGraphicsDefFree(virDomainGraphicsDef *def)
 g_free(def->data.egl_headless.rendernode);
 break;
 
+case VIR_DOMAIN_GRAPHICS_TYPE_DBUS:
+g_free(def->data.dbus.address);
+g_free(def->data.dbus.rendernode);
+break;
+
 case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
 break;
 }
@@ -12873,6 +12879,39 @@ 
virDomainGraphicsDefParseXMLEGLHeadless(virDomainGraphicsDef *def,
 }
 
 
+static int
+virDomainGraphicsDefParseXMLDBus(virDomainGraphicsDef *def,
+ xmlNodePtr node,
+ xmlXPathContextPtr ctxt)
+{
+VIR_XPATH_NODE_AUTORESTORE(ctxt)
+xmlNodePtr cur;
+virTristateBool p2p;
+
+if (virXMLPropTristateBool(node, "p2p", VIR_XML_PROP_NONE,
+   &p2p) < 0)
+return -1;
+def->data.dbus.p2p = p2p == VIR_TRISTATE_BOOL_YES;
+
+def->data.dbus.address = virXMLPropString(node, "address");
+def->data.dbus.fromConfig = def->data.dbus.address != NULL;
+
+ctxt->node = node;
+
+if ((cur = virXPathNode("./gl", ctxt))) {
+def->data.dbus.rendernode = virXMLPropString(cur,
+ "rendernode");
+
+if (virXMLPropTristateBool(cur, "enable",
+   VIR_XML_PROP_REQUIRED,
+   &def->data.dbus.gl) < 0)
+return -1;
+}
+
+return 0;
+}
+
+
 virDomainGraphicsDef *
 virDomainGraphicsDefNew(virDomainXMLOption *xmlopt)
 {
@@ -12947,6 +12986,10 @@ virDomainGraphicsDefParseXML(virDomainXMLOption 
*xmlopt,
 case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS:
 vi

[libvirt PATCH v3 05/16] qemu: start the D-Bus daemon for the display

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Start the daemon if necessary (it is already stopped in qemuProcessStop)

Signed-off-by: Marc-André Lureau 
---
 src/qemu/qemu_extdevice.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
index 537b13039488..8ada8324bed1 100644
--- a/src/qemu/qemu_extdevice.c
+++ b/src/qemu/qemu_extdevice.c
@@ -201,6 +201,19 @@ qemuExtDevicesStart(virQEMUDriver *driver,
 }
 }
 
+for (i = 0; i < def->ngraphics; i++) {
+virDomainGraphicsDef *graphics = def->graphics[i];
+
+if (graphics->type != VIR_DOMAIN_GRAPHICS_TYPE_DBUS)
+continue;
+
+if (graphics->data.dbus.p2p || graphics->data.dbus.fromConfig)
+continue;
+
+if (qemuDBusStart(driver, vm) < 0)
+return -1;
+}
+
 return 0;
 }
 
-- 
2.34.1.8.g35151cf07204



[libvirt PATCH v3 07/16] virsh: refactor/split cmdDomDisplay()

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

The function is large and quite complex. Move the inner loop for each
scheme in a separate function cmdDomDisplayScheme().

Signed-off-by: Marc-André Lureau 
---
 tools/virsh-domain.c | 341 +--
 1 file changed, 169 insertions(+), 172 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f086c2dd4b58..002cfc4be6af 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11507,209 +11507,213 @@ static const vshCmdOptDef opts_domdisplay[] = {
 };
 
 static bool
-cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
+cmdDomDisplayScheme(vshControl *ctl, const char *scheme,
+xmlXPathContext *ctxt, virBuffer *buf)
 {
-g_autoptr(xmlDoc) xml = NULL;
-g_autoptr(xmlXPathContext) ctxt = NULL;
-g_autoptr(virshDomain) dom = NULL;
-g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
-bool ret = false;
-char *xpath = NULL;
-char *listen_addr = NULL;
-int port, tls_port = 0;
-char *type_conn = NULL;
-char *sockpath = NULL;
-char *passwd = NULL;
-char *output = NULL;
-const char *scheme[] = { "vnc", "spice", "rdp", NULL };
-const char *type = NULL;
-int iter = 0;
-int tmp;
-int flags = 0;
-bool params = false;
-bool all = vshCommandOptBool(cmd, "all");
+g_autofree char *xpath = NULL;
+g_autofree char *listen_addr = NULL;
+g_autofree char *type_conn = NULL;
+g_autofree char *sockpath = NULL;
+g_autofree char *passwd = NULL;
 const char *xpath_fmt = "string(/domain/devices/graphics[@type='%s']/%s)";
 virSocketAddr addr;
+int port, tls_port = 0;
+bool params = false;
+int tmp;
 
-VSH_EXCLUSIVE_OPTIONS("all", "type");
+/* Create our XPATH lookup for the current display's port */
+xpath = g_strdup_printf(xpath_fmt, scheme, "@port");
 
-if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
-return false;
+/* Attempt to get the port number for the current graphics scheme */
+tmp = virXPathInt(xpath, ctxt, &port);
+VIR_FREE(xpath);
 
-if (!virDomainIsActive(dom)) {
-vshError(ctl, _("Domain is not running"));
-goto cleanup;
-}
+/* If there is no port number for this type, then jump to the next
+ * scheme */
+if (tmp)
+port = 0;
 
-if (vshCommandOptBool(cmd, "include-password"))
-flags |= VIR_DOMAIN_XML_SECURE;
+/* Create our XPATH lookup for TLS Port (automatically skipped
+ * for unsupported schemes */
+xpath = g_strdup_printf(xpath_fmt, scheme, "@tlsPort");
 
-if (vshCommandOptStringReq(ctl, cmd, "type", &type) < 0)
-goto cleanup;
+/* Attempt to get the TLS port number */
+tmp = virXPathInt(xpath, ctxt, &tls_port);
+VIR_FREE(xpath);
+if (tmp)
+tls_port = 0;
 
-if (virshDomainGetXMLFromDom(ctl, dom, flags, &xml, &ctxt) < 0)
-goto cleanup;
+/* Create our XPATH lookup for the current display's address */
+xpath = g_strdup_printf(xpath_fmt, scheme, "@listen");
 
-/* Attempt to grab our display info */
-for (iter = 0; scheme[iter] != NULL; iter++) {
-/* Particular scheme requested */
-if (!all && type && STRNEQ(type, scheme[iter]))
-continue;
+/* Attempt to get the listening addr if set for the current
+ * graphics scheme */
+listen_addr = virXPathString(xpath, ctxt);
+VIR_FREE(xpath);
 
-/* Create our XPATH lookup for the current display's port */
-VIR_FREE(xpath);
-xpath = g_strdup_printf(xpath_fmt, scheme[iter], "@port");
+/* Create our XPATH lookup for the current spice type. */
+xpath = g_strdup_printf(xpath_fmt, scheme, "listen/@type");
 
-/* Attempt to get the port number for the current graphics scheme */
-tmp = virXPathInt(xpath, ctxt, &port);
-VIR_FREE(xpath);
+/* Attempt to get the type of spice connection */
+type_conn = virXPathString(xpath, ctxt);
+VIR_FREE(xpath);
 
-/* If there is no port number for this type, then jump to the next
- * scheme */
-if (tmp)
-port = 0;
+if (STREQ_NULLABLE(type_conn, "socket")) {
+if (!sockpath) {
+xpath = g_strdup_printf(xpath_fmt, scheme, "listen/@socket");
 
-/* Create our XPATH lookup for TLS Port (automatically skipped
- * for unsupported schemes */
-xpath = g_strdup_printf(xpath_fmt, scheme[iter], "@tlsPort");
+sockpath = virXPathString(xpath, ctxt);
 
-/* Attempt to get the TLS port number */
-tmp = virXPathInt(xpath, ctxt, &tls_port);
-VIR_FREE(xpath);
-if (tmp)
-tls_port = 0;
+VIR_FREE(xpath);
+}
+}
 
-/* Create our XPATH lookup for the current display's address */
-xpath = g_strdup_printf(xpath_fmt, scheme[iter], "@listen");
+if (!port && !tls_port && !sockpath)
+return false;
+
+if (!listen_ad

[libvirt PATCH v3 08/16] virsh: report the D-Bus bus URI for domdisplay

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

This implementation reports only Unix bus address using the URI format
proposed in https://gitlab.freedesktop.org/dbus/dbus/-/issues/348.

We prefer a URI form over the D-Bus address form, since all other
display protocols use a URI, allowing to distinguish between protocols
and making client implementation simpler.

Other transports (for example TCP) are not yet handled.

The client is assumed to know what to lookup on the bus (the bus name,
path & interface of the VM, eventually matching its UUID)

P2P mode doesn't report any available URI.

Signed-off-by: Marc-André Lureau 
---
 tools/virsh-domain.c | 27 +--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 002cfc4be6af..00ed07a02cb4 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11497,7 +11497,7 @@ static const vshCmdOptDef opts_domdisplay[] = {
 {.name = "type",
  .type = VSH_OT_STRING,
  .help = N_("select particular graphical display "
-"(e.g. \"vnc\", \"spice\", \"rdp\")")
+"(e.g. \"vnc\", \"spice\", \"rdp\", \"dbus\")")
 },
 {.name = "all",
  .type = VSH_OT_BOOL,
@@ -11506,6 +11506,26 @@ static const vshCmdOptDef opts_domdisplay[] = {
 {.name = NULL}
 };
 
+static bool
+cmdDomDisplayDBus(vshControl *ctl, xmlXPathContext *ctxt, virBuffer *buf)
+{
+g_autofree char *addr = NULL;
+const char *xpath = 
"string(/domain/devices/graphics[@type='dbus']/@address)";
+
+addr = virXPathString(xpath, ctxt);
+if (!addr)
+return false;
+
+if (STRPREFIX(addr, "unix:path=")) {
+virBufferAsprintf(buf, "dbus+unix://%s", addr + 10);
+} else {
+vshError(ctl, _("'%s' D-Bus address is not handled"), addr);
+return false;
+}
+
+return true;
+}
+
 static bool
 cmdDomDisplayScheme(vshControl *ctl, const char *scheme,
 xmlXPathContext *ctxt, virBuffer *buf)
@@ -11521,6 +11541,9 @@ cmdDomDisplayScheme(vshControl *ctl, const char *scheme,
 bool params = false;
 int tmp;
 
+if (STREQ(scheme, "dbus"))
+return cmdDomDisplayDBus(ctl, ctxt, buf);
+
 /* Create our XPATH lookup for the current display's port */
 xpath = g_strdup_printf(xpath_fmt, scheme, "@port");
 
@@ -11681,7 +11704,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
 g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 g_autofree char *output = NULL;
 bool ret = false;
-const char *scheme[] = { "vnc", "spice", "rdp", NULL };
+const char *scheme[] = { "vnc", "spice", "rdp", "dbus", NULL };
 const char *type = NULL;
 int iter = 0;
 int flags = 0;
-- 
2.34.1.8.g35151cf07204



[libvirt PATCH v3 09/16] conf: add support

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 docs/schemas/domaincommon.rng | 29 
 src/bhyve/bhyve_command.c |  1 +
 src/conf/domain_conf.c| 34 +++---
 src/conf/domain_conf.h|  2 +
 src/qemu/qemu_command.c   |  7 +++
 src/qemu/qemu_validate.c  |  3 ++
 .../qemuxml2argvdata/graphics-dbus-audio.xml  | 45 +++
 .../graphics-dbus-audio.xml   |  1 +
 tests/qemuxml2xmltest.c   |  4 ++
 9 files changed, 121 insertions(+), 5 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-audio.xml
 create mode 12 tests/qemuxml2xmloutdata/graphics-dbus-audio.xml

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 29a506cff86a..5938f0d5acd3 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4032,6 +4032,13 @@
 
   
 
+
+  
+
+  
+
+  
+
   
 
 
@@ -4844,6 +4851,11 @@
 
   
 
+  
+
+
+  
+
   
 
   
@@ -4872,6 +4884,23 @@
 
   
 
+
+  
+dbus
+  
+  
+
+  
+
+  
+
+
+  
+
+  
+
+  
+
 
   
 alsa
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 3368d20a042c..95bba738fe5d 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -551,6 +551,7 @@ bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED,
 case VIR_DOMAIN_AUDIO_TYPE_SDL:
 case VIR_DOMAIN_AUDIO_TYPE_SPICE:
 case VIR_DOMAIN_AUDIO_TYPE_FILE:
+case VIR_DOMAIN_AUDIO_TYPE_DBUS:
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported audio backend '%s'"),
virDomainAudioTypeTypeToString(audio->type));
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1b44513d3415..791df66ff024 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -764,6 +764,7 @@ VIR_ENUM_IMPL(virDomainAudioType,
   "sdl",
   "spice",
   "file",
+  "dbus",
 );
 
 VIR_ENUM_IMPL(virDomainAudioSDLDriver,
@@ -3032,6 +3033,7 @@ virDomainAudioDefFree(virDomainAudioDef *def)
 g_free(def->backend.file.path);
 break;
 
+case VIR_DOMAIN_AUDIO_TYPE_DBUS:
 case VIR_DOMAIN_AUDIO_TYPE_LAST:
 break;
 }
@@ -12908,6 +12910,14 @@ virDomainGraphicsDefParseXMLDBus(virDomainGraphicsDef 
*def,
 return -1;
 }
 
+cur = virXPathNode("./audio", ctxt);
+if (cur) {
+if (virXMLPropUInt(cur, "id", 10,
+   VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO,
+   &def->data.dbus.audioId) < 0)
+return -1;
+}
+
 return 0;
 }
 
@@ -13398,6 +13408,9 @@ virDomainAudioDefParseXML(virDomainXMLOption *xmlopt 
G_GNUC_UNUSED,
 def->backend.file.path = virXMLPropString(node, "path");
 break;
 
+case VIR_DOMAIN_AUDIO_TYPE_DBUS:
+break;
+
 case VIR_DOMAIN_AUDIO_TYPE_LAST:
 default:
 virReportEnumRangeError(virDomainAudioType, def->type);
@@ -25816,6 +25829,9 @@ virDomainAudioDefFormat(virBuffer *buf,
 virBufferEscapeString(&attrBuf, " path='%s'", def->backend.file.path);
 break;
 
+case VIR_DOMAIN_AUDIO_TYPE_DBUS:
+break;
+
 case VIR_DOMAIN_AUDIO_TYPE_LAST:
 default:
 virReportEnumRangeError(virDomainAudioType, def->type);
@@ -26750,7 +26766,7 @@ virDomainGraphicsDefFormat(virBuffer *buf,
 virBufferAsprintf(buf, " address='%s'",
   def->data.dbus.address);
 
-if (!def->data.dbus.gl)
+if (!def->data.dbus.gl && def->data.dbus.audioId <= 0)
 break;
 
 if (!children) {
@@ -26759,10 +26775,17 @@ virDomainGraphicsDefFormat(virBuffer *buf,
 children = true;
 }
 
-virBufferAsprintf(buf, "data.dbus.gl));
-virBufferEscapeString(buf, " rendernode='%s'", 
def->data.dbus.rendernode);
-virBufferAddLit(buf, "/>\n");
+if (def->data.dbus.gl) {
+virBufferAsprintf(buf, "data.dbus.gl));
+virBufferEscapeString(buf, " rendernode='%s'", 
def->data.dbus.rendernode);
+virBufferAddLit(buf, "/>\n");
+}
+
+if (def->data.dbus.audioId > 0)
+virBufferAsprintf(buf, "\n",
+  def->data.dbus.audioId);
+
 break;
 case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
 break;
@@ -30112,6 +30135,7 @@ virDomainAudioBackendIsEqual(vir

[libvirt PATCH v3 10/16] qemu: add audio type 'dbus'

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 src/qemu/qemu_command.c   | 12 +--
 src/qemu/qemu_validate.c  | 30 -
 .../qemuxml2argvdata/graphics-dbus-audio.args | 33 +++
 tests/qemuxml2argvtest.c  |  2 ++
 4 files changed, 74 insertions(+), 3 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-audio.args

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2524abb1e971..8303a20bc8bd 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8586,7 +8586,8 @@ 
qemuBuildGraphicsEGLHeadlessCommandLine(virQEMUDriverConfig *cfg G_GNUC_UNUSED,
 
 
 static int
-qemuBuildGraphicsDBusCommandLine(virCommand *cmd,
+qemuBuildGraphicsDBusCommandLine(virDomainDef *def,
+ virCommand *cmd,
  virDomainGraphicsDef *graphics)
 {
 g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER;
@@ -8608,6 +8609,13 @@ qemuBuildGraphicsDBusCommandLine(virCommand *cmd,
   graphics->data.dbus.rendernode);
 }
 
+if (graphics->data.dbus.audioId > 0) {
+g_autofree char *audioid = qemuGetAudioIDString(def, 
graphics->data.dbus.audioId);
+if (!audioid)
+return -1;
+virBufferAsprintf(&opt, ",audiodev=%s", audioid);
+}
+
 virCommandAddArg(cmd, "-display");
 virCommandAddArgBuffer(cmd, &opt);
 
@@ -8652,7 +8660,7 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfig *cfg,
 
 break;
 case VIR_DOMAIN_GRAPHICS_TYPE_DBUS:
-if (qemuBuildGraphicsDBusCommandLine(cmd, graphics) < 0)
+if (qemuBuildGraphicsDBusCommandLine(def, cmd, graphics) < 0)
 return -1;
 
 break;
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 50253e9009b9..7ab121aed0dc 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -4128,6 +4128,24 @@ qemuValidateDomainDeviceDefVNCGraphics(const 
virDomainGraphicsDef *graphics,
 }
 
 
+static int
+qemuValidateDomainDeviceDefDBusGraphics(const virDomainGraphicsDef *graphics,
+const virDomainDef *def)
+{
+if (graphics->data.dbus.audioId > 0) {
+virDomainAudioDef *audio = virDomainDefFindAudioByID(def, 
graphics->data.dbus.audioId);
+
+if (audio && audio->type != VIR_DOMAIN_AUDIO_TYPE_DBUS) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("The associated audio is not of 'dbus' kind."));
+return -1;
+}
+}
+
+return 0;
+}
+
+
 static int
 qemuValidateDomainDeviceDefGraphics(const virDomainGraphicsDef *graphics,
 const virDomainDef *def,
@@ -4205,10 +4223,15 @@ qemuValidateDomainDeviceDefGraphics(const 
virDomainGraphicsDef *graphics,
 
 break;
 
+case VIR_DOMAIN_GRAPHICS_TYPE_DBUS:
+if (qemuValidateDomainDeviceDefDBusGraphics(graphics, def) < 0)
+return -1;
+
+break;
+
 case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
 case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
 case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
-case VIR_DOMAIN_GRAPHICS_TYPE_DBUS:
 case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
 break;
 }
@@ -4456,6 +4479,11 @@ qemuValidateDomainDeviceDefAudio(virDomainAudioDef 
*audio,
 break;
 
 case VIR_DOMAIN_AUDIO_TYPE_DBUS:
+if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DISPLAY_DBUS)) {
+virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+   _("D-Bus audio is not supported with this QEMU"));
+return -1;
+}
 break;
 
 case VIR_DOMAIN_AUDIO_TYPE_LAST:
diff --git a/tests/qemuxml2argvdata/graphics-dbus-audio.args 
b/tests/qemuxml2argvdata/graphics-dbus-audio.args
new file mode 100644
index ..ab23f6ac1cda
--- /dev/null
+++ b/tests/qemuxml2argvdata/graphics-dbus-audio.args
@@ -0,0 +1,33 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+/usr/bin/qemu-system-i386 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object 
secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes
 \
+-machine pc,usb=off,dump-guest-core=off \
+-accel tcg \
+-m 214 \
+-realtime mlock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-no-user-config \
+-nodefaults \
+-chardev 
socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server=on,wait=off
 \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-usb \
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
+-device ide-hd,bus=ide.0,uni

[libvirt PATCH v3 06/16] qemu: add -display dbus support

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

By default, libvirt will start a private bus and tell QEMU to connect to
it. Instead, a D-Bus "address" to connect to can be specified, or the
p2p mode enabled.

D-Bus display works best with GL & a rendernode, which can be specified
with  child element.

Signed-off-by: Marc-André Lureau 
---
 src/qemu/qemu_command.c   | 41 ++-
 src/qemu/qemu_driver.c|  4 ++
 src/qemu/qemu_process.c   | 36 +++-
 .../graphics-dbus-address.args| 30 ++
 tests/qemuxml2argvdata/graphics-dbus-p2p.args | 30 ++
 tests/qemuxml2argvdata/graphics-dbus.args | 30 ++
 tests/qemuxml2argvtest.c  |  7 
 7 files changed, 174 insertions(+), 4 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-address.args
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-p2p.args
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus.args

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8a32cb79f922..12197cfdb7b2 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8578,6 +8578,36 @@ 
qemuBuildGraphicsEGLHeadlessCommandLine(virQEMUDriverConfig *cfg G_GNUC_UNUSED,
 }
 
 
+static int
+qemuBuildGraphicsDBusCommandLine(virCommand *cmd,
+ virDomainGraphicsDef *graphics)
+{
+g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER;
+
+virBufferAddLit(&opt, "dbus");
+
+if (graphics->data.dbus.p2p) {
+virBufferAddLit(&opt, ",p2p=on");
+} else {
+virBufferAddLit(&opt, ",addr=");
+virQEMUBuildBufferEscapeComma(&opt, graphics->data.dbus.address);
+}
+if (graphics->data.dbus.gl != VIR_TRISTATE_BOOL_ABSENT)
+virBufferAsprintf(&opt, ",gl=%s",
+  
virTristateSwitchTypeToString(graphics->data.dbus.gl));
+if (graphics->data.dbus.rendernode) {
+virBufferAddLit(&opt, ",rendernode=");
+virQEMUBuildBufferEscapeComma(&opt,
+  graphics->data.dbus.rendernode);
+}
+
+virCommandAddArg(cmd, "-display");
+virCommandAddArgBuffer(cmd, &opt);
+
+return 0;
+}
+
+
 static int
 qemuBuildGraphicsCommandLine(virQEMUDriverConfig *cfg,
  virCommand *cmd,
@@ -8613,7 +8643,11 @@ qemuBuildGraphicsCommandLine(virQEMUDriverConfig *cfg,
 graphics) < 0)
 return -1;
 
+break;
 case VIR_DOMAIN_GRAPHICS_TYPE_DBUS:
+if (qemuBuildGraphicsDBusCommandLine(cmd, graphics) < 0)
+return -1;
+
 break;
 case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
 case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
@@ -10210,6 +10244,7 @@ qemuBuildCommandLineValidate(virQEMUDriver *driver,
 int vnc = 0;
 int spice = 0;
 int egl_headless = 0;
+int dbus = 0;
 
 if (!driver->privileged) {
 /* If we have no cgroups then we can have no tunings that
@@ -10255,6 +10290,8 @@ qemuBuildCommandLineValidate(virQEMUDriver *driver,
 ++egl_headless;
 break;
 case VIR_DOMAIN_GRAPHICS_TYPE_DBUS:
+++dbus;
+break;
 case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
 case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
 case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
@@ -10262,10 +10299,10 @@ qemuBuildCommandLineValidate(virQEMUDriver *driver,
 }
 }
 
-if (sdl > 1 || vnc > 1 || spice > 1 || egl_headless > 1) {
+if (sdl > 1 || vnc > 1 || spice > 1 || egl_headless > 1 || dbus > 1) {
 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("only 1 graphics device of each type "
- "(sdl, vnc, spice, headless) is supported"));
+ "(sdl, vnc, spice, headless, dbus) is supported"));
 return -1;
 }
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 1a73d4392c64..5f186a22beee 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15681,6 +15681,8 @@ qemuDomainOpenGraphics(virDomainPtr dom,
 protocol = "spice";
 break;
 case VIR_DOMAIN_GRAPHICS_TYPE_DBUS:
+protocol = "@dbus-display";
+break;
 case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
 case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
 case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
@@ -15750,6 +15752,8 @@ qemuDomainOpenGraphicsFD(virDomainPtr dom,
 protocol = "spice";
 break;
 case VIR_DOMAIN_GRAPHICS_TYPE_DBUS:
+protocol = "@dbus-display";
+break;
 case VIR_DOMAIN_GRAPHICS_TYPE_SDL:
 case VIR_DOMAIN_GRAPHICS_TYPE_RDP:
 case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP:
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index fd04849f025f..0bfb17e09790 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4874,6 +4874,22 @@ 
qemuProcessGraphicsSetup

[libvirt PATCH v3 11/16] conf: add dbus

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 docs/schemas/domaincommon.rng |  8 +
 src/conf/domain_conf.c| 13 ++-
 src/conf/domain_conf.h|  1 +
 .../graphics-dbus-clipboard.xml   | 35 +++
 .../graphics-dbus-clipboard.xml   |  1 +
 tests/qemuxml2xmltest.c   |  3 ++
 6 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-clipboard.xml
 create mode 12 tests/qemuxml2xmloutdata/graphics-dbus-clipboard.xml

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 5938f0d5acd3..213e1a07c0e8 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4039,6 +4039,14 @@
 
   
 
+
+  
+
+  
+
+
+  
+
   
 
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 791df66ff024..99cf63c1bc55 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12918,6 +12918,13 @@ virDomainGraphicsDefParseXMLDBus(virDomainGraphicsDef 
*def,
 return -1;
 }
 
+if ((cur = virXPathNode("./clipboard", ctxt))) {
+if (virXMLPropTristateBool(cur, "copypaste",
+   VIR_XML_PROP_REQUIRED,
+   &def->data.dbus.copypaste) < 0)
+return -1;
+}
+
 return 0;
 }
 
@@ -26766,7 +26773,7 @@ virDomainGraphicsDefFormat(virBuffer *buf,
 virBufferAsprintf(buf, " address='%s'",
   def->data.dbus.address);
 
-if (!def->data.dbus.gl && def->data.dbus.audioId <= 0)
+if (!def->data.dbus.gl && def->data.dbus.audioId <= 0 && 
!def->data.dbus.copypaste)
 break;
 
 if (!children) {
@@ -26786,6 +26793,10 @@ virDomainGraphicsDefFormat(virBuffer *buf,
 virBufferAsprintf(buf, "\n",
   def->data.dbus.audioId);
 
+if (def->data.dbus.copypaste)
+virBufferAsprintf(buf, "\n",
+  
virTristateBoolTypeToString(def->data.dbus.copypaste));
+
 break;
 case VIR_DOMAIN_GRAPHICS_TYPE_LAST:
 break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f15917c49500..a94a9f5d816e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1932,6 +1932,7 @@ struct _virDomainGraphicsDef {
 char *rendernode;
 virTristateBool gl;
 unsigned int audioId;
+virTristateBool copypaste;
 bool fromConfig;/* true if the @address is config file 
originated */
 } dbus;
 } data;
diff --git a/tests/qemuxml2argvdata/graphics-dbus-clipboard.xml 
b/tests/qemuxml2argvdata/graphics-dbus-clipboard.xml
new file mode 100644
index ..46ba6abb58bc
--- /dev/null
+++ b/tests/qemuxml2argvdata/graphics-dbus-clipboard.xml
@@ -0,0 +1,35 @@
+
+  QEMUGuest1
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219100
+  219100
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu-system-i386
+
+  
+
+
+  
+
+
+
+
+
+  
+
+
+  
+  
+
+
+  
+
diff --git a/tests/qemuxml2xmloutdata/graphics-dbus-clipboard.xml 
b/tests/qemuxml2xmloutdata/graphics-dbus-clipboard.xml
new file mode 12
index ..a4dc520711ad
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/graphics-dbus-clipboard.xml
@@ -0,0 +1 @@
+../qemuxml2argvdata/graphics-dbus-clipboard.xml
\ No newline at end of file
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 276cb8bcc274..4fcf5129c57e 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -387,6 +387,9 @@ mymain(void)
 QEMU_CAPS_DEVICE_CIRRUS_VGA,
 QEMU_CAPS_DISPLAY_DBUS,
 QEMU_CAPS_AUDIODEV);
+DO_TEST("graphics-dbus-clipboard",
+QEMU_CAPS_DEVICE_CIRRUS_VGA,
+QEMU_CAPS_DISPLAY_DBUS);
 
 DO_TEST_CAPS_ARCH_LATEST("default-video-type-aarch64", "aarch64");
 DO_TEST_CAPS_ARCH_LATEST("default-video-type-ppc64", "ppc64");
-- 
2.34.1.8.g35151cf07204



[libvirt PATCH v3 12/16] qemu: add dbus clipboard sharing

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

This feature requires to setup a "-chardev qemu-vdagent,clipboard=on".

"qemu-vdagent" is not a typical chardev that you can connect to another
end, so it doesn't map to a  or . Set it up along with
"-display dbus" code instead.

Signed-off-by: Marc-André Lureau 
---
 src/qemu/qemu_command.c   | 12 +++
 .../graphics-dbus-clipboard.args  | 31 +++
 tests/qemuxml2argvtest.c  |  4 +++
 3 files changed, 47 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-clipboard.args

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 8303a20bc8bd..bde3266f2148 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8590,6 +8590,7 @@ qemuBuildGraphicsDBusCommandLine(virDomainDef *def,
  virCommand *cmd,
  virDomainGraphicsDef *graphics)
 {
+g_autofree char *charAlias = NULL;
 g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER;
 
 virBufferAddLit(&opt, "dbus");
@@ -8619,6 +8620,17 @@ qemuBuildGraphicsDBusCommandLine(virDomainDef *def,
 virCommandAddArg(cmd, "-display");
 virCommandAddArgBuffer(cmd, &opt);
 
+
+if (graphics->data.dbus.copypaste == VIR_TRISTATE_BOOL_YES) {
+if (!(charAlias = qemuAliasChardevFromDevAlias("qemu-vdagent")))
+return -1;
+
+virBufferAsprintf(&opt, "qemu-vdagent,id=%s", charAlias);
+virBufferAddLit(&opt, ",clipboard=on");
+virCommandAddArg(cmd, "-chardev");
+virCommandAddArgBuffer(cmd, &opt);
+}
+
 return 0;
 }
 
diff --git a/tests/qemuxml2argvdata/graphics-dbus-clipboard.args 
b/tests/qemuxml2argvdata/graphics-dbus-clipboard.args
new file mode 100644
index ..fd0c3e7a253e
--- /dev/null
+++ b/tests/qemuxml2argvdata/graphics-dbus-clipboard.args
@@ -0,0 +1,31 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+/usr/bin/qemu-system-i386 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object 
secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes
 \
+-machine pc,usb=off,dump-guest-core=off \
+-accel tcg \
+-m 214 \
+-realtime mlock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-no-user-config \
+-nodefaults \
+-chardev 
socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server=on,wait=off
 \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-usb \
+-display 
dbus,addr=unix:path=/bad-test-used-env-xdg-runtime-dir/libvirt/qemu/run/dbus/-1-QEMUGuest1-dbus.sock
 \
+-chardev qemu-vdagent,id=charqemu-vdagent,clipboard=on \
+-device cirrus-vga,id=video0,bus=pci.0,addr=0x2 \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 37fc7120b6ed..3510bcce6cff 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1610,6 +1610,10 @@ mymain(void)
 QEMU_CAPS_DEVICE_CIRRUS_VGA, QEMU_CAPS_DISPLAY_DBUS);
 DO_TEST("graphics-dbus-audio",
 QEMU_CAPS_DEVICE_CIRRUS_VGA, QEMU_CAPS_DISPLAY_DBUS, 
QEMU_CAPS_AUDIODEV);
+DO_TEST("graphics-dbus-clipboard",
+QEMU_CAPS_DEVICE_CIRRUS_VGA,
+QEMU_CAPS_DISPLAY_DBUS,
+QEMU_CAPS_CHARDEV_VDAGENT);
 
 DO_TEST_NOCAPS("input-usbmouse");
 DO_TEST_NOCAPS("input-usbtablet");
-- 
2.34.1.8.g35151cf07204



[libvirt PATCH v3 13/16] conf: add

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Like a Spice port, a dbus serial must specify an associated channel name.

Signed-off-by: Marc-André Lureau 
---
 docs/schemas/domaincommon.rng |  1 +
 src/conf/domain_conf.c| 26 +++
 src/conf/domain_conf.h|  4 ++
 src/conf/domain_validate.c| 32 ++
 src/qemu/qemu_command.c   |  3 ++
 src/qemu/qemu_monitor_json.c  |  1 +
 src/qemu/qemu_process.c   |  1 +
 src/qemu/qemu_validate.c  |  1 +
 src/security/security_dac.c   |  2 +
 .../graphics-dbus-chardev.xml | 43 +++
 tests/qemuxml2argvtest.c  |  1 +
 .../graphics-dbus-chardev.xml |  1 +
 tests/qemuxml2xmltest.c   |  3 ++
 13 files changed, 110 insertions(+), 9 deletions(-)
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-chardev.xml
 create mode 12 tests/qemuxml2xmloutdata/graphics-dbus-chardev.xml

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 213e1a07c0e8..4d24ae6f878d 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4511,6 +4511,7 @@
   spicevmc
   spiceport
   nmdm
+  dbus
 
   
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 99cf63c1bc55..e62553eb039b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -710,6 +710,7 @@ VIR_ENUM_IMPL(virDomainChr,
   "spicevmc",
   "spiceport",
   "nmdm",
+  "dbus",
 );
 
 VIR_ENUM_IMPL(virDomainChrTcpProtocol,
@@ -2690,6 +2691,7 @@ virDomainChrSourceDefGetPath(virDomainChrSourceDef *chr)
 case VIR_DOMAIN_CHR_TYPE_STDIO:
 case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
 case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+case VIR_DOMAIN_CHR_TYPE_DBUS:
 case VIR_DOMAIN_CHR_TYPE_LAST:
 return NULL;
 }
@@ -2733,6 +2735,10 @@ virDomainChrSourceDefClear(virDomainChrSourceDef *def)
 case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
 VIR_FREE(def->data.spiceport.channel);
 break;
+
+case VIR_DOMAIN_CHR_TYPE_DBUS:
+VIR_FREE(def->data.dbus.channel);
+break;
 }
 
 VIR_FREE(def->logfile);
@@ -2787,7 +2793,14 @@ virDomainChrSourceDefCopy(virDomainChrSourceDef *dest,
 case VIR_DOMAIN_CHR_TYPE_NMDM:
 dest->data.nmdm.master = g_strdup(src->data.nmdm.master);
 dest->data.nmdm.slave = g_strdup(src->data.nmdm.slave);
+break;
+
+case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+dest->data.spiceport.channel = g_strdup(src->data.spiceport.channel);
+break;
 
+case VIR_DOMAIN_CHR_TYPE_DBUS:
+dest->data.dbus.channel = g_strdup(src->data.dbus.channel);
 break;
 }
 
@@ -2869,6 +2882,11 @@ virDomainChrSourceDefIsEqual(const virDomainChrSourceDef 
*src,
 case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
 return src->data.spicevmc == tgt->data.spicevmc;
 
+case VIR_DOMAIN_CHR_TYPE_DBUS:
+return STREQ_NULLABLE(src->data.dbus.channel,
+  tgt->data.dbus.channel);
+break;
+
 case VIR_DOMAIN_CHR_TYPE_NULL:
 case VIR_DOMAIN_CHR_TYPE_VC:
 case VIR_DOMAIN_CHR_TYPE_STDIO:
@@ -11381,6 +11399,10 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDef 
*def,
 def->data.spiceport.channel = virXMLPropString(sources[0], 
"channel");
 break;
 
+case VIR_DOMAIN_CHR_TYPE_DBUS:
+def->data.dbus.channel = virXMLPropString(sources[0], "channel");
+break;
+
 case VIR_DOMAIN_CHR_TYPE_NMDM:
 def->data.nmdm.master = virXMLPropString(sources[0], "master");
 def->data.nmdm.slave = virXMLPropString(sources[0], "slave");
@@ -25302,6 +25324,10 @@ virDomainChrSourceDefFormat(virBuffer *buf,
   def->data.spiceport.channel);
 break;
 
+case VIR_DOMAIN_CHR_TYPE_DBUS:
+virBufferEscapeString(buf, "\n",
+  def->data.dbus.channel);
+break;
 }
 
 if (def->logfile) {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a94a9f5d816e..3562ad74462a 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1217,6 +1217,7 @@ typedef enum {
 VIR_DOMAIN_CHR_TYPE_SPICEVMC,
 VIR_DOMAIN_CHR_TYPE_SPICEPORT,
 VIR_DOMAIN_CHR_TYPE_NMDM,
+VIR_DOMAIN_CHR_TYPE_DBUS,
 
 VIR_DOMAIN_CHR_TYPE_LAST
 } virDomainChrType;
@@ -1285,6 +1286,9 @@ struct _virDomainChrSourceDef {
 struct {
 char *channel;
 } spiceport;
+struct {
+char *channel;
+} dbus;
 } data;
 char *logfile;
 virTristateSwitch logappend;
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index c13472516fec..97b581ddb11d 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -832,6 +832,2

[libvirt PATCH v3 14/16] qemu: add -chardev dbus support

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 src/qemu/qemu_command.c   |  4 +++
 src/qemu/qemu_monitor_json.c  |  9 ++
 .../graphics-dbus-chardev.args| 32 +++
 tests/qemuxml2argvtest.c  |  4 +++
 4 files changed, 49 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-chardev.args

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2e2fa45ea576..bb60bc9d331e 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1439,6 +1439,10 @@ qemuBuildChardevStr(const virDomainChrSourceDef *dev,
 break;
 
 case VIR_DOMAIN_CHR_TYPE_DBUS:
+virBufferAsprintf(&buf, "dbus,id=%s,name=%s", charAlias,
+  dev->data.dbus.channel);
+break;
+
 case VIR_DOMAIN_CHR_TYPE_NMDM:
 case VIR_DOMAIN_CHR_TYPE_LAST:
 default:
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index b99381ecd2b1..5fb277339850 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6820,6 +6820,15 @@ qemuMonitorJSONAttachCharDevGetProps(const char *chrID,
 break;
 
 case VIR_DOMAIN_CHR_TYPE_DBUS:
+backendType = "dbus";
+
+if (virJSONValueObjectAdd(&backendData,
+  "s:name", chr->data.dbus.channel,
+  NULL) < 0)
+return NULL;
+
+break;
+
 case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
 case VIR_DOMAIN_CHR_TYPE_PIPE:
 case VIR_DOMAIN_CHR_TYPE_STDIO:
diff --git a/tests/qemuxml2argvdata/graphics-dbus-chardev.args 
b/tests/qemuxml2argvdata/graphics-dbus-chardev.args
new file mode 100644
index ..98debbbfa775
--- /dev/null
+++ b/tests/qemuxml2argvdata/graphics-dbus-chardev.args
@@ -0,0 +1,32 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+/usr/bin/qemu-system-i386 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object 
secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes
 \
+-machine pc,usb=off,dump-guest-core=off \
+-accel tcg \
+-m 214 \
+-realtime mlock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-no-user-config \
+-nodefaults \
+-chardev 
socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server=on,wait=off
 \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-usb \
+-chardev dbus,id=charserial0,name=org.qemu.console.serial.0 \
+-device isa-serial,chardev=charserial0,id=serial0 \
+-display dbus,p2p=on \
+-device cirrus-vga,id=video0,bus=pci.0,addr=0x2 \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 22b819588115..fb8248ddcb7b 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1615,6 +1615,10 @@ mymain(void)
 QEMU_CAPS_DEVICE_CIRRUS_VGA,
 QEMU_CAPS_DISPLAY_DBUS,
 QEMU_CAPS_CHARDEV_VDAGENT);
+DO_TEST("graphics-dbus-chardev",
+QEMU_CAPS_DEVICE_ISA_SERIAL,
+QEMU_CAPS_DEVICE_CIRRUS_VGA,
+QEMU_CAPS_DISPLAY_DBUS);
 
 DO_TEST_NOCAPS("input-usbmouse");
 DO_TEST_NOCAPS("input-usbtablet");
-- 
2.34.1.8.g35151cf07204



[libvirt PATCH v3 15/16] qemu: add usbredir type 'dbus'

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

The USB device redirection works in a similar way as Spice. The
underlying 'dbus' channel is set to "org.qemu.usbredir" by default for
the client to identify the channel purpose (as specified in -display
dbus documentation).

Signed-off-by: Marc-André Lureau 
---
 src/conf/domain_conf.c|  2 ++
 .../graphics-dbus-usbredir.args   | 34 +++
 .../graphics-dbus-usbredir.xml| 30 
 tests/qemuxml2argvtest.c  |  4 +++
 4 files changed, 70 insertions(+)
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-usbredir.args
 create mode 100644 tests/qemuxml2argvdata/graphics-dbus-usbredir.xml

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e62553eb039b..6ca434f854ff 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14537,6 +14537,8 @@ virDomainRedirdevDefParseXML(virDomainXMLOption *xmlopt,
 
 if (def->source->type == VIR_DOMAIN_CHR_TYPE_SPICEVMC)
 def->source->data.spicevmc = VIR_DOMAIN_CHR_SPICEVMC_USBREDIR;
+if (def->source->type == VIR_DOMAIN_CHR_TYPE_DBUS && 
!def->source->data.dbus.channel)
+def->source->data.dbus.channel = g_strdup("org.qemu.usbredir");
 
 if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info,
 flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT) < 
0)
diff --git a/tests/qemuxml2argvdata/graphics-dbus-usbredir.args 
b/tests/qemuxml2argvdata/graphics-dbus-usbredir.args
new file mode 100644
index ..f76693ac1e83
--- /dev/null
+++ b/tests/qemuxml2argvdata/graphics-dbus-usbredir.args
@@ -0,0 +1,34 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+/usr/bin/qemu-system-i386 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object 
secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes
 \
+-machine pc,usb=off,dump-guest-core=off \
+-accel tcg \
+-m 214 \
+-realtime mlock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-no-user-config \
+-nodefaults \
+-chardev 
socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server=on,wait=off
 \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-usb \
+-display dbus,p2p=on \
+-device cirrus-vga,id=video0,bus=pci.0,addr=0x2 \
+-chardev dbus,id=charredir0,name=org.qemu.usbredir \
+-device usb-redir,chardev=charredir0,id=redir0,bus=usb.0,port=1 \
+-chardev dbus,id=charredir1,name=org.qemu.usbredir \
+-device usb-redir,chardev=charredir1,id=redir1,bus=usb.0,port=2 \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/graphics-dbus-usbredir.xml 
b/tests/qemuxml2argvdata/graphics-dbus-usbredir.xml
new file mode 100644
index ..fad6cd8b5f98
--- /dev/null
+++ b/tests/qemuxml2argvdata/graphics-dbus-usbredir.xml
@@ -0,0 +1,30 @@
+
+  QEMUGuest1
+  c7a5fdbd-edaf-9455-926a-d65c16db1809
+  219100
+  219100
+  1
+  
+hvm
+
+  
+  
+  destroy
+  restart
+  destroy
+  
+/usr/bin/qemu-system-i386
+
+
+
+
+
+
+
+
+
+  
+
+
+  
+
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index fb8248ddcb7b..06f8a306b5ee 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -1619,6 +1619,10 @@ mymain(void)
 QEMU_CAPS_DEVICE_ISA_SERIAL,
 QEMU_CAPS_DEVICE_CIRRUS_VGA,
 QEMU_CAPS_DISPLAY_DBUS);
+DO_TEST("graphics-dbus-usbredir",
+QEMU_CAPS_DEVICE_CIRRUS_VGA,
+QEMU_CAPS_DISPLAY_DBUS,
+QEMU_CAPS_USB_REDIR);
 
 DO_TEST_NOCAPS("input-usbmouse");
 DO_TEST_NOCAPS("input-usbtablet");
-- 
2.34.1.8.g35151cf07204



[libvirt PATCH v3 16/16] docs: document type dbus

2021-12-22 Thread marcandre . lureau
From: Marc-André Lureau 

Signed-off-by: Marc-André Lureau 
---
 NEWS.rst  |  7 ++-
 docs/formatdomain.rst | 43 ++-
 2 files changed, 48 insertions(+), 2 deletions(-)

diff --git a/NEWS.rst b/NEWS.rst
index e7d53167219f..92042459653d 100644
--- a/NEWS.rst
+++ b/NEWS.rst
@@ -37,11 +37,16 @@ v8.0.0 (unreleased)
 as ``VIR_MIGRATE_NON_SHARED_SYNCHRONOUS_WRITES`` exposed via
 ``virsh migrate --copy-storage-synchronous-writes``.
 
-* Introduce TCG domain features
+  * Introduce TCG domain features
 
 Libvirt is now able to set the size of translation block cache size
 (tb-size) for TCG domains.
 
+  * qemu: D-Bus display
+
+Libvirt is now able to setup a D-Bus display export, either with a private
+bus or in p2p mode. This display is available in QEMU 7.0.0.
+
 * **Improvements**
 
 * **Bug fixes**
diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index d4f30bb8af57..a0d11e40c2fd 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -6094,6 +6094,39 @@ interaction with the admin.

  
 
+   ``dbus``:since:`Since 8.0.0`
+  Export the display over D-Bus. By default, it will use a private bus,
+  except when ``p2p`` or ``address`` are specified.
+
+  ::
+
+
+
+  ``p2p`` (accepts ``on`` or ``off``) enables peer-to-peer connections,
+  established through virDomainOpenGraphics() APIs.
+
+  ``address`` (accepts a `D-Bus address
+  `_),
+  will connect to the specified bus address.
+
+  This element accepts a  sub-element with an optional attribute
+  ``rendernode`` which can be used to specify an absolute path to a host's
+  DRI device to be used for OpenGL rendering.
+
+  Copy & Paste functionality (via Spice agent) is set by the ``clipboard``
+  element. It is disabled by default, and can be disabled by setting the
+  ``copypaste`` property to ``yes``.
+
+  D-Bus can export an audio backend using the  sub-element:
+
+  ::
+
+ 
+   
+ 
+
+  Where ``1`` is an id of the `audio device <#elementsAudio>`__.
+
 Graphics device uses a  to set up where the device should listen 
for
 clients. It has a mandatory attribute ``type`` which specifies the listen type.
 Only ``vnc``, ``spice`` and ``rdp`` supports  element. 
:since:`Since
@@ -7007,7 +7040,7 @@ to the guest sound device.
 ``type``
The required ``type`` attribute specifies audio backend type.
Currently, the supported values are 'none', 'alsa', 'coreaudio',
-   'jack', 'oss', 'pulseaudio', 'sdl', 'spice', 'file'.
+   'dbus', jack', 'oss', 'pulseaudio', 'sdl', 'spice', 'file'.
 
 ``id``
Integer id of the audio device. Must be greater than 0.
@@ -7134,6 +7167,14 @@ and  elements
 
 :since:`Since 7.2.0, qemu`
 
+D-Bus audio backend
+^^^
+
+The 'dbus' audio backend does not connect to any host audio framework. It
+exports a D-Bus interface when associated with a D-Bus display.
+
+:since:`Since 8.0.0, qemu`
+
 Jack audio backend
 ^^
 
-- 
2.34.1.8.g35151cf07204



Re: [PATCH 0/5] tests: Tool for programatic modification of qemucapabilitiesdata/*.replies

2021-12-22 Thread Ján Tomko

On a Wednesday in 2021, Peter Krempa wrote:

I was asked multiple times how to automate modification of the qemu
capability dumps. I wrote a tool [1] that allowed doing that.
Unfortunately as it wasn't in the repo it was not avalilable.

Now I've finally set out to finish it. It masquerades as a test in
default mode checking the ordering and numbering of the caps dump files
as in the past there were few cases where manual edits broke it.

In update mode it allows modification of the replies and gives few
examples to do so. There's a lot of possible things users would want to
do so there's no way around actually writing some code but it should be
easier this way.

Since this now does also numbering, the AWK/shell script
'qemucapsfixreplies' can be removed.




[1]: Okay, okay. Copy&paste'd few bits from various places into one
messy C file and didn't bother with memory cleanup. But it worked.


Peter Krempa (5):
 util: json: Introduce virJSONValueObjectReplaceValue
 tests: qemumonitortestutils.h: Reformat header file
 qemumonitortestutils: Extract parser for the monitor conversation dump
   file
 tests: Tool for programatic modification of
   qemucapabilitiesdata/*.replies
 tests: Remove 'qemucapsfixreplies'

src/libvirt_private.syms  |   1 +
src/util/virjson.c|  20 +++
src/util/virjson.h|   6 +
tests/domaincapstest.c|   3 +-
tests/meson.build |   1 +
tests/qemucapabilitiesnumbering.c | 242 ++
tests/qemucapabilitiestest.c  |   4 +-
tests/qemucapsfixreplies  |  26 
tests/qemumonitortestutils.c  | 123 ++-
tests/qemumonitortestutils.h  | 149 +++---
10 files changed, 453 insertions(+), 122 deletions(-)
create mode 100644 tests/qemucapabilitiesnumbering.c
delete mode 100755 tests/qemucapsfixreplies



Reviewed-by: Ján Tomko 

Jano


signature.asc
Description: PGP signature


Re: [PATCH v3 06/12] target/riscv: Support start kernel directly by KVM

2021-12-22 Thread Anup Patel
On Mon, Dec 20, 2021 at 6:39 PM Yifei Jiang  wrote:
>
> Get kernel and fdt start address in virt.c, and pass them to KVM
> when cpu reset. Add kvm_riscv.h to place riscv specific interface.
>
> In addition, PLIC is created without M-mode PLIC contexts when KVM
> is enabled.
>
> Signed-off-by: Yifei Jiang 
> Signed-off-by: Mingwang Li 
> Reviewed-by: Alistair Francis 
> ---
>  hw/intc/sifive_plic.c|  8 +++-
>  hw/riscv/boot.c  | 16 +++-
>  hw/riscv/virt.c  | 87 
>  include/hw/riscv/boot.h  |  1 +
>  target/riscv/cpu.c   |  8 
>  target/riscv/cpu.h   |  3 ++
>  target/riscv/kvm-stub.c  | 25 
>  target/riscv/kvm.c   | 14 +++
>  target/riscv/kvm_riscv.h | 24 +++
>  target/riscv/meson.build |  2 +-
>  10 files changed, 159 insertions(+), 29 deletions(-)
>  create mode 100644 target/riscv/kvm-stub.c
>  create mode 100644 target/riscv/kvm_riscv.h
>
> diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c
> index 877e76877c..1b2b4cc25e 100644
> --- a/hw/intc/sifive_plic.c
> +++ b/hw/intc/sifive_plic.c
> @@ -30,6 +30,7 @@
>  #include "target/riscv/cpu.h"
>  #include "migration/vmstate.h"
>  #include "hw/irq.h"
> +#include "sysemu/kvm.h"
>
>  #define RISCV_DEBUG_PLIC 0
>
> @@ -555,8 +556,11 @@ DeviceState *sifive_plic_create(hwaddr addr, char 
> *hart_config,
>
>  qdev_connect_gpio_out(dev, i,
>qdev_get_gpio_in(DEVICE(cpu), IRQ_S_EXT));
> -qdev_connect_gpio_out(dev, num_harts + i,
> -  qdev_get_gpio_in(DEVICE(cpu), IRQ_M_EXT));
> +
> +if (!kvm_enabled()) {
> +qdev_connect_gpio_out(dev, num_harts + i,
> +  qdev_get_gpio_in(DEVICE(cpu), IRQ_M_EXT));
> +}

We should have any KVM enabled check in interrupt controller emulators
instead I suggest to re-write the for-loop in sifive_plic_create() as follows:

SiFivePLICState *plic;

()

plic = SIFIVE_PLIC(dev);
for (i = 0; i < plic->num_addrs; i++) {
CPUState *cpu = qemu_get_cpu(plic->addr_config[i].hartid);

   if (plic->addr_mode[i] == PLICMode_S) {
   qdev_connect_gpio_out(dev, i,
qdev_get_gpio_in(DEVICE(cpu), IRQ_S_EXT));
   }
   if (plic->addr_mode[i] == PLICMode_M) {
qdev_connect_gpio_out(dev, num_harts + i,
qdev_get_gpio_in(DEVICE(cpu), IRQ_M_EXT));
}
}

>  }
>
>  return dev;
> diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
> index 519fa455a1..ccff662d89 100644
> --- a/hw/riscv/boot.c
> +++ b/hw/riscv/boot.c
> @@ -30,6 +30,7 @@
>  #include "elf.h"
>  #include "sysemu/device_tree.h"
>  #include "sysemu/qtest.h"
> +#include "sysemu/kvm.h"
>
>  #include 
>
> @@ -51,7 +52,9 @@ char *riscv_plic_hart_config_string(int hart_count)
>  CPUState *cs = qemu_get_cpu(i);
>  CPURISCVState *env = &RISCV_CPU(cs)->env;
>
> -if (riscv_has_ext(env, RVS)) {
> +if (kvm_enabled()) {
> +vals[i] = "S";
> +} else if (riscv_has_ext(env, RVS)) {
>  vals[i] = "MS";
>  } else {
>  vals[i] = "M";
> @@ -317,3 +320,14 @@ void riscv_setup_rom_reset_vec(MachineState *machine, 
> RISCVHartArrayState *harts
>
>  return;
>  }
> +
> +void riscv_setup_direct_kernel(hwaddr kernel_addr, hwaddr fdt_addr)
> +{
> +CPUState *cs;
> +
> +for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) {
> +RISCVCPU *riscv_cpu = RISCV_CPU(cs);
> +riscv_cpu->env.kernel_addr = kernel_addr;
> +riscv_cpu->env.fdt_addr = fdt_addr;
> +}
> +}
> diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> index 3af074148e..cc1a03f284 100644
> --- a/hw/riscv/virt.c
> +++ b/hw/riscv/virt.c
> @@ -38,6 +38,7 @@
>  #include "chardev/char.h"
>  #include "sysemu/device_tree.h"
>  #include "sysemu/sysemu.h"
> +#include "sysemu/kvm.h"
>  #include "hw/pci/pci.h"
>  #include "hw/pci-host/gpex.h"
>  #include "hw/display/ramfb.h"
> @@ -50,7 +51,11 @@ static const MemMapEntry virt_memmap[] = {
>  [VIRT_CLINT] =   {  0x200,   0x1 },
>  [VIRT_ACLINT_SSWI] = {  0x2F0,0x4000 },
>  [VIRT_PCIE_PIO] ={  0x300,   0x1 },
> +#if defined(CONFIG_KVM)
> +[VIRT_PLIC] ={  0xc00, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 1) },
> +#else
>  [VIRT_PLIC] ={  0xc00, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2) },
> +#endif

Please drop this change because the same QEMU binary should be
usable with and without KVM enabled.

>  [VIRT_UART0] =   { 0x1000, 0x100 },
>  [VIRT_VIRTIO] =  { 0x10001000,0x1000 },
>  [VIRT_FW_CFG] =  { 0x1010,  0x18 },
> @@ -372,13 +377,22 @@ static void create_fdt_socket_plic(RISCVVirtState *s,
>  "sifive,plic-1.0.0", "riscv,plic0"
>  };
>
> -plic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 4);
> +if (kvm_enabled()) {
> +plic_cells = g_new0(uint32_t, s->soc[socket].num_harts * 2);
> +} else

Re: [PATCH v3 06/12] target/riscv: Support start kernel directly by KVM

2021-12-22 Thread Anup Patel
On Thu, Dec 23, 2021 at 11:33 AM Anup Patel  wrote:
>
> On Mon, Dec 20, 2021 at 6:39 PM Yifei Jiang  wrote:
> >
> > Get kernel and fdt start address in virt.c, and pass them to KVM
> > when cpu reset. Add kvm_riscv.h to place riscv specific interface.
> >
> > In addition, PLIC is created without M-mode PLIC contexts when KVM
> > is enabled.
> >
> > Signed-off-by: Yifei Jiang 
> > Signed-off-by: Mingwang Li 
> > Reviewed-by: Alistair Francis 
> > ---
> >  hw/intc/sifive_plic.c|  8 +++-
> >  hw/riscv/boot.c  | 16 +++-
> >  hw/riscv/virt.c  | 87 
> >  include/hw/riscv/boot.h  |  1 +
> >  target/riscv/cpu.c   |  8 
> >  target/riscv/cpu.h   |  3 ++
> >  target/riscv/kvm-stub.c  | 25 
> >  target/riscv/kvm.c   | 14 +++
> >  target/riscv/kvm_riscv.h | 24 +++
> >  target/riscv/meson.build |  2 +-
> >  10 files changed, 159 insertions(+), 29 deletions(-)
> >  create mode 100644 target/riscv/kvm-stub.c
> >  create mode 100644 target/riscv/kvm_riscv.h
> >
> > diff --git a/hw/intc/sifive_plic.c b/hw/intc/sifive_plic.c
> > index 877e76877c..1b2b4cc25e 100644
> > --- a/hw/intc/sifive_plic.c
> > +++ b/hw/intc/sifive_plic.c
> > @@ -30,6 +30,7 @@
> >  #include "target/riscv/cpu.h"
> >  #include "migration/vmstate.h"
> >  #include "hw/irq.h"
> > +#include "sysemu/kvm.h"
> >
> >  #define RISCV_DEBUG_PLIC 0
> >
> > @@ -555,8 +556,11 @@ DeviceState *sifive_plic_create(hwaddr addr, char 
> > *hart_config,
> >
> >  qdev_connect_gpio_out(dev, i,
> >qdev_get_gpio_in(DEVICE(cpu), IRQ_S_EXT));
> > -qdev_connect_gpio_out(dev, num_harts + i,
> > -  qdev_get_gpio_in(DEVICE(cpu), IRQ_M_EXT));
> > +
> > +if (!kvm_enabled()) {
> > +qdev_connect_gpio_out(dev, num_harts + i,
> > +  qdev_get_gpio_in(DEVICE(cpu), 
> > IRQ_M_EXT));
> > +}
>
> We should have any KVM enabled check in interrupt controller emulators
> instead I suggest to re-write the for-loop in sifive_plic_create() as follows:

Typo correction:
*"We should not have any KVM enabled check in "

Regards,
Anup

>
> SiFivePLICState *plic;
>
> ()
>
> plic = SIFIVE_PLIC(dev);
> for (i = 0; i < plic->num_addrs; i++) {
> CPUState *cpu = qemu_get_cpu(plic->addr_config[i].hartid);
>
>if (plic->addr_mode[i] == PLICMode_S) {
>qdev_connect_gpio_out(dev, i,
> qdev_get_gpio_in(DEVICE(cpu), IRQ_S_EXT));
>}
>if (plic->addr_mode[i] == PLICMode_M) {
> qdev_connect_gpio_out(dev, num_harts + i,
> qdev_get_gpio_in(DEVICE(cpu), IRQ_M_EXT));
> }
> }
>
> >  }
> >
> >  return dev;
> > diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c
> > index 519fa455a1..ccff662d89 100644
> > --- a/hw/riscv/boot.c
> > +++ b/hw/riscv/boot.c
> > @@ -30,6 +30,7 @@
> >  #include "elf.h"
> >  #include "sysemu/device_tree.h"
> >  #include "sysemu/qtest.h"
> > +#include "sysemu/kvm.h"
> >
> >  #include 
> >
> > @@ -51,7 +52,9 @@ char *riscv_plic_hart_config_string(int hart_count)
> >  CPUState *cs = qemu_get_cpu(i);
> >  CPURISCVState *env = &RISCV_CPU(cs)->env;
> >
> > -if (riscv_has_ext(env, RVS)) {
> > +if (kvm_enabled()) {
> > +vals[i] = "S";
> > +} else if (riscv_has_ext(env, RVS)) {
> >  vals[i] = "MS";
> >  } else {
> >  vals[i] = "M";
> > @@ -317,3 +320,14 @@ void riscv_setup_rom_reset_vec(MachineState *machine, 
> > RISCVHartArrayState *harts
> >
> >  return;
> >  }
> > +
> > +void riscv_setup_direct_kernel(hwaddr kernel_addr, hwaddr fdt_addr)
> > +{
> > +CPUState *cs;
> > +
> > +for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) {
> > +RISCVCPU *riscv_cpu = RISCV_CPU(cs);
> > +riscv_cpu->env.kernel_addr = kernel_addr;
> > +riscv_cpu->env.fdt_addr = fdt_addr;
> > +}
> > +}
> > diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
> > index 3af074148e..cc1a03f284 100644
> > --- a/hw/riscv/virt.c
> > +++ b/hw/riscv/virt.c
> > @@ -38,6 +38,7 @@
> >  #include "chardev/char.h"
> >  #include "sysemu/device_tree.h"
> >  #include "sysemu/sysemu.h"
> > +#include "sysemu/kvm.h"
> >  #include "hw/pci/pci.h"
> >  #include "hw/pci-host/gpex.h"
> >  #include "hw/display/ramfb.h"
> > @@ -50,7 +51,11 @@ static const MemMapEntry virt_memmap[] = {
> >  [VIRT_CLINT] =   {  0x200,   0x1 },
> >  [VIRT_ACLINT_SSWI] = {  0x2F0,0x4000 },
> >  [VIRT_PCIE_PIO] ={  0x300,   0x1 },
> > +#if defined(CONFIG_KVM)
> > +[VIRT_PLIC] ={  0xc00, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 1) },
> > +#else
> >  [VIRT_PLIC] ={  0xc00, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2) },
> > +#endif
>
> Please drop this change because the same QEMU binary should be
> usable with and without KVM enabled.
>
> >  [VIRT_UART0] =   { 0x1000, 0x100 },
> >  [VIRT_VIR

Re: [PATCH v3 07/12] target/riscv: Support setting external interrupt by KVM

2021-12-22 Thread Anup Patel
On Mon, Dec 20, 2021 at 6:39 PM Yifei Jiang  wrote:
>
> When KVM is enabled, set the S-mode external interrupt through
> kvm_riscv_set_irq function.
>
> Signed-off-by: Yifei Jiang 
> Signed-off-by: Mingwang Li 
> Reviewed-by: Alistair Francis 

Looks good to me.

Reviewed-by: Anup Patel 

Regards,
Anup

> ---
>  target/riscv/cpu.c   |  6 +-
>  target/riscv/kvm-stub.c  |  5 +
>  target/riscv/kvm.c   | 17 +
>  target/riscv/kvm_riscv.h |  1 +
>  4 files changed, 28 insertions(+), 1 deletion(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 1c944872a3..3fc3a9c45b 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -603,7 +603,11 @@ static void riscv_cpu_set_irq(void *opaque, int irq, int 
> level)
>  case IRQ_S_EXT:
>  case IRQ_VS_EXT:
>  case IRQ_M_EXT:
> -riscv_cpu_update_mip(cpu, 1 << irq, BOOL_TO_MASK(level));
> +if (kvm_enabled()) {
> +kvm_riscv_set_irq(cpu, irq, level);
> +} else {
> +riscv_cpu_update_mip(cpu, 1 << irq, BOOL_TO_MASK(level));
> +}
>  break;
>  default:
>  g_assert_not_reached();
> diff --git a/target/riscv/kvm-stub.c b/target/riscv/kvm-stub.c
> index 39b96fe3f4..4e8fc31a21 100644
> --- a/target/riscv/kvm-stub.c
> +++ b/target/riscv/kvm-stub.c
> @@ -23,3 +23,8 @@ void kvm_riscv_reset_vcpu(RISCVCPU *cpu)
>  {
>  abort();
>  }
> +
> +void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level)
> +{
> +abort();
> +}
> diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
> index db6d8a5b6e..0027f11f45 100644
> --- a/target/riscv/kvm.c
> +++ b/target/riscv/kvm.c
> @@ -383,6 +383,23 @@ void kvm_riscv_reset_vcpu(RISCVCPU *cpu)
>  env->satp = 0;
>  }
>
> +void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level)
> +{
> +int ret;
> +unsigned virq = level ? KVM_INTERRUPT_SET : KVM_INTERRUPT_UNSET;
> +
> +if (irq != IRQ_S_EXT) {
> +perror("kvm riscv set irq != IRQ_S_EXT\n");
> +abort();
> +}
> +
> +ret = kvm_vcpu_ioctl(CPU(cpu), KVM_INTERRUPT, &virq);
> +if (ret < 0) {
> +perror("Set irq failed");
> +abort();
> +}
> +}
> +
>  bool kvm_arch_cpu_check_are_resettable(void)
>  {
>  return true;
> diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h
> index f38c82bf59..ed281bdce0 100644
> --- a/target/riscv/kvm_riscv.h
> +++ b/target/riscv/kvm_riscv.h
> @@ -20,5 +20,6 @@
>  #define QEMU_KVM_RISCV_H
>
>  void kvm_riscv_reset_vcpu(RISCVCPU *cpu);
> +void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level);
>
>  #endif
> --
> 2.19.1
>



Re: [PATCH v3 10/12] target/riscv: Add kvm_riscv_get/put_regs_timer

2021-12-22 Thread Anup Patel
On Mon, Dec 20, 2021 at 6:39 PM Yifei Jiang  wrote:
>
> Add kvm_riscv_get/put_regs_timer to synchronize virtual time context
> from KVM.
>
> To set register of RISCV_TIMER_REG(state) will occur a error from KVM
> on kvm_timer_state == 0. It's better to adapt in KVM, but it doesn't matter
> that adaping in QEMU.
>
> Signed-off-by: Yifei Jiang 
> Signed-off-by: Mingwang Li 

Looks good to me.

Reviewed-by: Anup Patel 

Regards,
Anup

> ---
>  target/riscv/cpu.h |  7 +
>  target/riscv/kvm.c | 72 ++
>  2 files changed, 79 insertions(+)
>
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index e7dba35acb..c892a2c8b7 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -259,6 +259,13 @@ struct CPURISCVState {
>
>  hwaddr kernel_addr;
>  hwaddr fdt_addr;
> +
> +/* kvm timer */
> +bool kvm_timer_dirty;
> +uint64_t kvm_timer_time;
> +uint64_t kvm_timer_compare;
> +uint64_t kvm_timer_state;
> +uint64_t kvm_timer_frequency;
>  };
>
>  OBJECT_DECLARE_TYPE(RISCVCPU, RISCVCPUClass,
> diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
> index 4d08669c81..3c20ec5ad3 100644
> --- a/target/riscv/kvm.c
> +++ b/target/riscv/kvm.c
> @@ -41,6 +41,7 @@
>  #include "sbi_ecall_interface.h"
>  #include "chardev/char-fe.h"
>  #include "semihosting/console.h"
> +#include "migration/migration.h"
>
>  static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, uint64_t 
> idx)
>  {
> @@ -65,6 +66,9 @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, 
> uint64_t type, uint64_t idx
>  #define RISCV_CSR_REG(env, name)  kvm_riscv_reg_id(env, KVM_REG_RISCV_CSR, \
>   KVM_REG_RISCV_CSR_REG(name))
>
> +#define RISCV_TIMER_REG(env, name)  kvm_riscv_reg_id(env, 
> KVM_REG_RISCV_TIMER, \
> + KVM_REG_RISCV_TIMER_REG(name))
> +
>  #define RISCV_FP_F_REG(env, idx)  kvm_riscv_reg_id(env, KVM_REG_RISCV_FP_F, 
> idx)
>
>  #define RISCV_FP_D_REG(env, idx)  kvm_riscv_reg_id(env, KVM_REG_RISCV_FP_D, 
> idx)
> @@ -85,6 +89,22 @@ static uint64_t kvm_riscv_reg_id(CPURISCVState *env, 
> uint64_t type, uint64_t idx
>  } \
>  } while(0)
>
> +#define KVM_RISCV_GET_TIMER(cs, env, name, reg) \
> +do { \
> +int ret = kvm_get_one_reg(cs, RISCV_TIMER_REG(env, name), ®); \
> +if (ret) { \
> +abort(); \
> +} \
> +} while(0)
> +
> +#define KVM_RISCV_SET_TIMER(cs, env, name, reg) \
> +do { \
> +int ret = kvm_set_one_reg(cs, RISCV_TIMER_REG(env, time), ®); \
> +if (ret) { \
> +abort(); \
> +} \
> +} while (0)
> +
>  static int kvm_riscv_get_regs_core(CPUState *cs)
>  {
>  int ret = 0;
> @@ -236,6 +256,58 @@ static int kvm_riscv_put_regs_fp(CPUState *cs)
>  return ret;
>  }
>
> +static void kvm_riscv_get_regs_timer(CPUState *cs)
> +{
> +CPURISCVState *env = &RISCV_CPU(cs)->env;
> +
> +if (env->kvm_timer_dirty) {
> +return;
> +}
> +
> +KVM_RISCV_GET_TIMER(cs, env, time, env->kvm_timer_time);
> +KVM_RISCV_GET_TIMER(cs, env, compare, env->kvm_timer_compare);
> +KVM_RISCV_GET_TIMER(cs, env, state, env->kvm_timer_state);
> +KVM_RISCV_GET_TIMER(cs, env, frequency, env->kvm_timer_frequency);
> +
> +env->kvm_timer_dirty = true;
> +}
> +
> +static void kvm_riscv_put_regs_timer(CPUState *cs)
> +{
> +uint64_t reg;
> +CPURISCVState *env = &RISCV_CPU(cs)->env;
> +
> +if (!env->kvm_timer_dirty) {
> +return;
> +}
> +
> +KVM_RISCV_SET_TIMER(cs, env, time, env->kvm_timer_time);
> +KVM_RISCV_SET_TIMER(cs, env, compare, env->kvm_timer_compare);
> +
> +/*
> + * To set register of RISCV_TIMER_REG(state) will occur a error from KVM
> + * on env->kvm_timer_state == 0, It's better to adapt in KVM, but it
> + * doesn't matter that adaping in QEMU now.
> + * TODO If KVM changes, adapt here.
> + */
> +if (env->kvm_timer_state) {
> +KVM_RISCV_SET_TIMER(cs, env, state, env->kvm_timer_state);
> +}
> +
> +/*
> + * For now, migration will not work between Hosts with different timer
> + * frequency. Therefore, we should check whether they are the same here
> + * during the migration.
> + */
> +if (migration_is_running(migrate_get_current()->state)) {
> +KVM_RISCV_GET_TIMER(cs, env, frequency, reg);
> +if (reg != env->kvm_timer_frequency) {
> +error_report("Dst Hosts timer frequency != Src Hosts");
> +}
> +}
> +
> +env->kvm_timer_dirty = false;
> +}
>
>  const KVMCapabilityInfo kvm_arch_required_capabilities[] = {
>  KVM_CAP_LAST_INFO
> --
> 2.19.1
>



[PATCH v2] Add VM info to improve error log message for qemu monitor

2021-12-22 Thread Rohit Kumar
This patch is to determine the VM which had IO or socket hangup error.
Accessing directly vm->def->name inside qemuMonitorIO() or qemuMonitorSend()
might leads to illegal access as we are out of 'vm' context and vm->def might
not exist. Adding a field "domainName" inside mon object to access vm name
and initialising it when creating mon object.

Signed-off-by: Rohit Kumar 
---
 diff to v1:
  - Adding a field domainName inside _qemuMonitor struct for accessing vm name
instead of directly accessing mon->vm->def->name.
  - Link to v1: 
https://listman.redhat.com/archives/libvir-list/2021-December/msg00217.html
  - Talked with peter on RFC and he suggested me to add a field inside 
monitor struct to get VM name.
 
 src/qemu/qemu_monitor.c | 47 +
 1 file changed, 29 insertions(+), 18 deletions(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index dda6ae9796..c3a0227795 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -80,6 +80,7 @@ struct _qemuMonitor {
 GSource *watch;
 
 virDomainObj *vm;
+char *domainName;
 
 qemuMonitorCallbacks *cb;
 void *callbackOpaque;
@@ -243,6 +244,7 @@ qemuMonitorDispose(void *obj)
 virCondDestroy(&mon->notify);
 g_free(mon->buffer);
 g_free(mon->balloonpath);
+g_free(mon->domainName);
 }
 
 
@@ -530,13 +532,18 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNUSED,
 qemuMonitor *mon = opaque;
 bool error = false;
 bool hangup = false;
+virDomainObj *vm = NULL;
+char *vmName = NULL;
 
 virObjectRef(mon);
 
+vm = mon->vm;
+vmName = mon->domainName;
+
 /* lock access to the monitor and protect fd */
 virObjectLock(mon);
 #if DEBUG_IO
-VIR_DEBUG("Monitor %p I/O on socket %p cond %d", mon, socket, cond);
+VIR_DEBUG("Monitor %p I/O on socket %p cond %d vm=%p name=%s", mon, 
socket, cond, vm, NULLSTR(vmName));
 #endif
 if (mon->fd == -1 || !mon->watch) {
 virObjectUnlock(mon);
@@ -583,8 +590,8 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNUSED,
 
 if (!error && !mon->goteof &&
 cond & G_IO_ERR) {
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Invalid file descriptor while waiting for 
monitor"));
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("%s: Invalid file descriptor while waiting for 
monitor"), NULLSTR(vmName));
 mon->goteof = true;
 }
 }
@@ -609,13 +616,14 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNUSED,
 virResetLastError();
 } else {
 if (virGetLastErrorCode() == VIR_ERR_OK && !mon->goteof)
-virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-   _("Error while processing monitor IO"));
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("%s: Error while processing monitor IO"), 
NULLSTR(vmName));
 virCopyLastError(&mon->lastError);
 virResetLastError();
 }
 
-VIR_DEBUG("Error on monitor %s", NULLSTR(mon->lastError.message));
+VIR_DEBUG("Error on monitor %s mon=%p vm=%p name=%s",
+  NULLSTR(mon->lastError.message), mon, vm, NULLSTR(vmName));
 /* If IO process resulted in an error & we have a message,
  * then wakeup that waiter */
 if (mon->msg && !mon->msg->finished) {
@@ -631,22 +639,22 @@ qemuMonitorIO(GSocket *socket G_GNUC_UNUSED,
  * will try to acquire the virDomainObj *mutex next */
 if (mon->goteof) {
 qemuMonitorEofNotifyCallback eofNotify = mon->cb->eofNotify;
-virDomainObj *vm = mon->vm;
 
 /* Make sure anyone waiting wakes up now */
 virCondSignal(&mon->notify);
 virObjectUnlock(mon);
-VIR_DEBUG("Triggering EOF callback");
+VIR_DEBUG("Triggering EOF callback mon=%p vm=%p name=%s",
+  mon, vm, NULLSTR(vmName));
 (eofNotify)(mon, vm, mon->callbackOpaque);
 virObjectUnref(mon);
 } else if (error) {
 qemuMonitorErrorNotifyCallback errorNotify = mon->cb->errorNotify;
-virDomainObj *vm = mon->vm;
 
 /* Make sure anyone waiting wakes up now */
 virCondSignal(&mon->notify);
 virObjectUnlock(mon);
-VIR_DEBUG("Triggering error callback");
+VIR_DEBUG("Triggering error callback mon=%p vm=%p name=%s",
+  mon, vm, NULLSTR(vmName));
 (errorNotify)(mon, vm, mon->callbackOpaque);
 virObjectUnref(mon);
 } else {
@@ -694,6 +702,7 @@ qemuMonitorOpenInternal(virDomainObj *vm,
 mon->fd = fd;
 mon->context = g_main_context_ref(context);
 mon->vm = virObjectRef(vm);
+mon->domainName = g_strdup(vm->def->name);
 mon->waitGreeting = true;
 mon->cb = cb;
 mon->callbackOpaque = opaque;
@@ -932,17 +941,19 @@ qemuMonitorSend(qemuMonitor *mon,
 qemuMonitorMessage *msg)
 {
 int ret = -1;