QGA VSS Logging
v3 cover QGA VSS Logging
Print all VSS error and trace to debugger and stderr.
v3 -> v2:
Reformat few log lines
Move G_GNUC_PRINTF attribute to the declaration
v2: https://patchew.org/QEMU/[email protected]/
v2 -> v1:
Rename debug macro
Move log code to function
v1: https://patchew.org/QEMU/[email protected]/
Konstantin Kostiuk (4):
QGA VSS: Add wrapper to send log to debugger and stderr QGA VSS: Replace 'fprintf(stderr' with PRINT_DEBUG QGA VSS: Print error in err_set
QGA VSS: Add log in functions begin/end
qga/vss-win32/install.cpp | 45 +++++++++++++++++++++++++++----- qga/vss-win32/meson.build | 2 +- qga/vss-win32/provider.cpp | 3 +++ qga/vss-win32/requester.cpp | 51 ++++++++++++++++++++++++++++++++----- qga/vss-win32/vss-debug.cpp | 31 ++++++++++++++++++++++ qga/vss-win32/vss-debug.h | 25 ++++++++++++++++++ 6 files changed, 143 insertions(+), 14 deletions(-) create mode 100644 qga/vss-win32/vss-debug.cpp create mode 100644 qga/vss-win32/vss-debug.h
--
2.34.1
PATCH v3 1/4 QGA VSS: Add wrapper to send log to debugger and stderr
--- qga/vss-win32/meson.build | 2 +- qga/vss-win32/vss-debug.cpp | 31 +++++++++++++++++++++++++++++++ qga/vss-win32/vss-debug.h | 25 +++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 qga/vss-win32/vss-debug.cpp create mode 100644 qga/vss-win32/vss-debug.h
qga/vss-win32/meson.build +1 -1
@@ -7,7 +7,7 @@ link_args = cc.get_supported_link_arguments([ qga_vss = shared_module( 'qga-vss', - ['requester.cpp', 'provider.cpp', 'install.cpp', genh], + ['requester.cpp', 'provider.cpp', 'install.cpp', 'vss-debug.cpp', genh], name_prefix: '', cpp_args: ['-Wno-unknown-pragmas', '-Wno-delete-non-virtual-dtor', '-Wno-non-virtual-dtor'], link_args: link_args,
qga/vss-win32/vss-debug.cpp new file +31 -0
@@ -0,0 +1,31 @@ +/* + * QEMU Guest Agent VSS debug declarations + * + * Copyright (C) 2023 Red Hat Inc + * + * Authors: + * Konstantin Kostiuk <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "vss-debug.h" +#include "vss-common.h" + +void qga_debug_internal(const char *funcname, const char *fmt, ...) { + char user_sting[512] = {0}; + char full_string[640] = {0}; + + va_list args; + va_start(args, fmt); + vsnprintf(user_sting, 512, fmt, args); + va_end(args); + + snprintf(full_string, 640, QGA_PROVIDER_NAME "[%lu]: %s %s\n", + GetCurrentThreadId(), funcname, user_sting); + + OutputDebugString(full_string); + fprintf(stderr, "%s", full_string); +}
qga/vss-win32/vss-debug.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* QEMU Guest Agent VSS debug declarations +* +* Copyright (C) 2023 Red Hat Inc +* +* Authors: +* Konstantin Kostiuk <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include <vss-handles.h> + +#ifndef VSS_DEBUG_H +#define VSS_DEBUG_H + +void qga_debug_internal(const char *funcname, const char *fmt, ...) G_GNUC_PRINTF(2, 3); + +#define qga_debug (fmt, ...) qga_debug_internal(__func__, fmt, ## __VA_ARGS__) +#define qga_debug_begin qga_debug("begin") +#define qga_debug_end qga_debug("end") + +#endif
Signature · 1 line
2.34.1
Re: [PATCH v3 1/4] QGA VSS: Add wrapper to send log to debugger and stderr
Quoted 24 lines · Konstantin Kostiuk
Signed-off-by Konstantin Kostiuk <[email protected]>--- qga/vss-win32/meson.build | 2 +- qga/vss-win32/vss-debug.cpp | 31 +++++++++++++++++++++++++++++++ qga/vss-win32/vss-debug.h | 25 +++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-)create mode 100644 qga/vss-win32/vss-debug.cpp
create mode 100644qga/vss-win32/vss-debug.hqga/vss-win32/vss-debug.cpp new file +8
-0@@ -0,0 +1,31 @@ +/* + * QEMU Guest Agent VSS debug declarations + * + * Copyright (C) 2023 Red Hat Inc + * + * Authors: + * Konstantin Kostiuk <[email protected]> + *
qga/vss-win32/vss-debug.cpp line 18
Quoted 10 lines
qga/vss-win32/vss-debug.cpp new file +10
-0+ * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "vss-debug.h" +#include "vss-common.h" + +void qga_debug_internal(const char *funcname, const char *fmt, ...) { + char user_sting[512] = {0};
"user_string"
qga/vss-win32/vss-debug.cpp line 23
Quoted 5 lines
qga/vss-win32/vss-debug.cpp new file +5
-0+ char full_string[640] = {0}; + + va_list args; + va_start(args, fmt); + vsnprintf(user_sting, 512, fmt, args);
ARRAY_SIZE(user_string)
qga/vss-win32/vss-debug.cpp line 27
Quoted 4 lines
qga/vss-win32/vss-debug.cpp new file +4
-0+ va_end(args); + + snprintf(full_string, 640, QGA_PROVIDER_NAME "[%lu]: %s %s\n", + GetCurrentThreadId(), funcname, user_sting);
if (snprintf() <= 0) { return; }
qga/vss-win32/vss-debug.cpp line 30
Quoted 3 lines
qga/vss-win32/vss-debug.cpp new file +3
-0+ + OutputDebugString(full_string); + fprintf(stderr, "%s", full_string);
Format unused:
fputs(full_string, stderr);
qga/vss-win32/vss-debug.cpp line 31
Quoted 1 line
qga/vss-win32/vss-debug.cpp new file +1
-0+}
With the changes:
Re: [PATCH v3 1/4] QGA VSS: Add wrapper to send log to debugger and stderr
Quoted 39 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Konstantin Kostiuk
Signed-off-by Konstantin Kostiuk <[email protected]>--- qga/vss-win32/meson.build | 2 +- qga/vss-win32/vss-debug.cpp | 31 +++++++++++++++++++++++++++++++ qga/vss-win32/vss-debug.h | 25 +++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-)create mode 100644 qga/vss-win32/vss-debug.cpp
create mode 100644qga/vss-win32/vss-debug.hqga/vss-win32/vss-debug.cpp new file +0
-0qga/vss-win32/vss-debug.cpp line 9
Quoted 9 lines
qga/vss-win32/vss-debug.cpp new file +9
-0@@ -0,0 +1,31 @@ +/* + * QEMU Guest Agent VSS debug declarations + * + * Copyright (C) 2023 Red Hat Inc + * + * Authors: + * Konstantin Kostiuk <[email protected]> + * + * This work is licensed under the terms of the GNU GPL, version 2 orlater.
qga/vss-win32/vss-debug.cpp line 18
Quoted 9 lines
qga/vss-win32/vss-debug.cpp new file +9
-0+ * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "vss-debug.h" +#include "vss-common.h" + +void qga_debug_internal(const char *funcname, const char *fmt, ...) { + char user_sting[512] = {0};"
user_string"
Quoted 8 lines
qga/vss-win32/vss-debug.cpp line 23
Quoted 5 lines
qga/vss-win32/vss-debug.cpp new file +5
-0+ char full_string[640] = {0}; + + va_list args; + va_start(args, fmt); + vsnprintf(user_sting, 512, fmt, args);
ARRAY_SIZE(user_string)
I have a problem with ARRAY_SIZE define.
../qga/vss-win32/vss-debug.cpp: In function 'void qga_debug_internal(const char*, const char*, ...)':
/src/include/qemu/compiler.h:70:12: error: types may not be defined in 'sizeof' expressions
70 | struct { \
| ^
/src/include/qemu/compiler.h:78:43: note: in expansion of macro 'QEMU_BUILD_BUG_ON_STRUCT'
78 | #define QEMU_BUILD_BUG_ON_ZERO(x)
(sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - \
| ^~~~~~~~~~~~~~~~~~~~~~~~
/src/include/qemu/osdep.h:474:24: note: in expansion of macro
'QEMU_BUILD_BUG_ON_ZERO'
474 | QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x)))
| ^~~~~~~~~~~~~~~~~~~~~~
../qga/vss-win32/vss-debug.cpp:23:32: note: in expansion of macro
'ARRAY_SIZE'
23 | if (vsnprintf(user_string, ARRAY_SIZE(user_string), fmt, args)
<= 0) {
| ^~~~~~~~~~/src/include/qemu/osdep.h:470:57: error: expected primary-expression before 'typeof'
470 | #define QEMU_IS_ARRAY(x) (!__builtin_types_compatible_p(typeof(x), \
| ^~~~~~
/src/include/qemu/compiler.h:71:14: note: in definition of macro 'QEMU_BUILD_BUG_ON_STRUCT'
71 | int:(x) ? -1 : 1; \
| ^
/src/include/qemu/osdep.h:474:24: note: in expansion of macro 'QEMU_BUILD_BUG_ON_ZERO'
474 | QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x)))
| ^~~~~~~~~~~~~~~~~~~~~~/src/include/qemu/osdep.h:474:48: note: in expansion of macro 'QEMU_IS_ARRAY'
474 | QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x)))
Can you help with this?
Quoted 21 lines
qga/vss-win32/vss-debug.cpp line 27
Quoted 4 lines
qga/vss-win32/vss-debug.cpp new file +4
-0+ va_end(args); + + snprintf(full_string, 640, QGA_PROVIDER_NAME "[%lu]: %s %s\n", + GetCurrentThreadId(), funcname, user_sting);if (
snprintf()<= 0) { return; }qga/vss-win32/vss-debug.cpp line 30
Quoted 3 lines
qga/vss-win32/vss-debug.cpp new file +3
-0+ + OutputDebugString(full_string); + fprintf(stderr, "%s", full_string);Format unused:
fputs(full_string, stderr);qga/vss-win32/vss-debug.cpp line 31
Quoted 1 line
qga/vss-win32/vss-debug.cpp new file +1
-0+}With the changes:
Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Re: [PATCH v3 1/4] QGA VSS: Add wrapper to send log to debugger and stderr
Quoted 86 lines · Konstantin Kostiuk
On Fri, Jul 7, 2023 at 1:33 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 7/7/23 11:22, Konstantin Kostiuk wrote: > Signed-off-by: Konstantin Kostiuk <[email protected] <mailto:[email protected]>> > --- > qga/vss-win32/meson.build | 2 +- > qga/vss-win32/vss-debug.cpp | 31 +++++++++++++++++++++++++++++++ > qga/vss-win32/vss-debug.h | 25 +++++++++++++++++++++++++ > 3 files changed, 57 insertions(+), 1 deletion(-) > create mode 100644 qga/vss-win32/vss-debug.cpp > create mode 100644 qga/vss-win32/vss-debug.h > diff --git a/qga/vss-win32/vss-debug.cpp b/qga/vss-win32/vss-debug.cpp > new file mode 100644 > index 0000000000..5d6f37944b > --- /dev/null > +++ b/qga/vss-win32/vss-debug.cpp > @@ -0,0 +1,31 @@ > +/* > + * QEMU Guest Agent VSS debug declarations > + * > + * Copyright (C) 2023 Red Hat Inc > + * > + * Authors: > + * Konstantin Kostiuk <[email protected] <mailto:[email protected]>> > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > + * See the COPYING file in the top-level directory. > + */ > + > +#include "qemu/osdep.h" > +#include "vss-debug.h" > +#include "vss-common.h" > + > +void qga_debug_internal(const char *funcname, const char *fmt, ...) { > + char user_sting[512] = {0}; "user_string" > + char full_string[640] = {0}; > + > + va_list args; > + va_start(args, fmt); > + vsnprintf(user_sting, 512, fmt, args); ARRAY_SIZE(user_string)I have a problem with
ARRAY_SIZEdefine.../qga/vss-win32/vss-debug.cpp: In function 'void
qga_debug_internal(const char*, const char*, ...)':
/src/include/qemu/compiler.h:70:12: error: types may not be defined in 'sizeof' expressions
70 | struct { \
| ^
/src/include/qemu/compiler.h:78:43: note: in expansion of macro 'QEMU_BUILD_BUG_ON_STRUCT'
78 | #defineQEMU_BUILD_BUG_ON_ZERO(x)
(sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - \
| ^~~~~~~~~~~~~~~~~~~~~~~~
/src/include/qemu/osdep.h:474:24: note: in expansion of macro 'QEMU_BUILD_BUG_ON_ZERO'
474 | QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x)))
| ^~~~~~~~~~~~~~~~~~~~~~
../qga/vss-win32/vss-debug.cpp:23:32: note: in expansion of macro 'ARRAY_SIZE'
23 | if (vsnprintf(user_string,ARRAY_SIZE(user_string), fmt,
args) <= 0) {
| ^~~~~~~~~~
/src/include/qemu/osdep.h:470:57: error: expected primary-expression before 'typeof'
470 | #defineQEMU_IS_ARRAY(x)
(!__builtin_types_compatible_p(typeof(x), \
| ^~~~~~
/src/include/qemu/compiler.h:71:14: note: in definition of macro 'QEMU_BUILD_BUG_ON_STRUCT'
71 | int:(x) ? -1 : 1; \
| ^
/src/include/qemu/osdep.h:474:24: note: in expansion of macro 'QEMU_BUILD_BUG_ON_ZERO'
474 | QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x)))
| ^~~~~~~~~~~~~~~~~~~~~~
/src/include/qemu/osdep.h:474:48: note: in expansion of macro 'QEMU_IS_ARRAY'
474 | QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x)))
Quoted 1 line
Can you help with this?
Eh no clue, maybe not C++ compliant?
Fall back to sizeof() ¯\_(ツ)_/¯
Quoted 23 lines
> + va_end(args);
> +
> + snprintf(full_string, 640, QGA_PROVIDER_NAME "[%lu]: %s %s\n",
> + GetCurrentThreadId(), funcname, user_sting);
if (snprintf() <= 0) { return; }
> +
> + OutputDebugString(full_string);
> + fprintf(stderr, "%s", full_string);
Format unused:
fputs(full_string, stderr);
> +}
With the changes:
Reviewed-by: Philippe Mathieu-Daudé <[email protected]
<mailto:[email protected]>>Re: [PATCH v3 1/4] QGA VSS: Add wrapper to send log to debugger and stderr
Quoted 99 lines · Philippe Mathieu-Daudé
Quoted 63 lines · Konstantin Kostiuk
On Fri, Jul 7, 2023 at 1:33 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 7/7/23 11:22, Konstantin Kostiuk wrote: > Signed-off-by: Konstantin Kostiuk <[email protected] <mailto:[email protected]>> > --- > qga/vss-win32/meson.build | 2 +- > qga/vss-win32/vss-debug.cpp | 31 +++++++++++++++++++++++++++++++ > qga/vss-win32/vss-debug.h | 25 +++++++++++++++++++++++++ > 3 files changed, 57 insertions(+), 1 deletion(-) > create mode 100644 qga/vss-win32/vss-debug.cpp > create mode 100644 qga/vss-win32/vss-debug.h > diff --git a/qga/vss-win32/vss-debug.cpp b/qga/vss-win32/vss-debug.cpp > new file mode 100644 > index 0000000000..5d6f37944b > --- /dev/null > +++ b/qga/vss-win32/vss-debug.cpp > @@ -0,0 +1,31 @@ > +/* > + * QEMU Guest Agent VSS debug declarations > + * > + * Copyright (C) 2023 Red Hat Inc > + * > + * Authors: > + * Konstantin Kostiuk <[email protected] <mailto:[email protected]>> > + * > + * This work is licensed under the terms of the GNU GPL, version 2 or later. > + * See the COPYING file in the top-level directory. > + */ > + > +#include "qemu/osdep.h" > +#include "vss-debug.h" > +#include "vss-common.h" > + > +void qga_debug_internal(const char *funcname, const char *fmt, ...) { > + char user_sting[512] = {0}; "user_string" > + char full_string[640] = {0}; > + > + va_list args; > + va_start(args, fmt); > + vsnprintf(user_sting, 512, fmt, args); ARRAY_SIZE(user_string)I have a problem with
ARRAY_SIZEdefine.../qga/vss-win32/vss-debug.cpp: In function 'void
qga_debug_internal(const char*, const char*, ...)':
/src/include/qemu/compiler.h:70:12: error: types may not be defined in 'sizeof' expressionsQuoted 7 lines
70 | struct { \ | ^ /src/include/qemu/compiler.h:78:43: note: in expansion of macro 'QEMU_BUILD_BUG_ON_STRUCT' 78 | #define QEMU_BUILD_BUG_ON_ZERO(x) (sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - \ |^~~~~~~~~~~~~~~~~~~~~~~~
Quoted 3 lines
/src/include/qemu/osdep.h:474:24: note: in expansion of macro '
QEMU_BUILD_BUG_ON_ZERO'
474 |QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x)))
Quoted 13 lines
| ^~~~~~~~~~~~~~~~~~~~~~ ../qga/vss-win32/vss-debug.cpp:23:32: note: in expansion of macro 'ARRAY_SIZE' 23 | if (vsnprintf(user_string, ARRAY_SIZE(user_string), fmt, args) <= 0) { | ^~~~~~~~~~/src/include/qemu/osdep.h:470:57: error: expected primary-expression before 'typeof'
470 | #defineQEMU_IS_ARRAY(x)
(!__builtin_types_compatible_p(typeof(x), \
| ^~~~~~
/src/include/qemu/compiler.h:71:14: note: in definition of macro 'QEMU_BUILD_BUG_ON_STRUCT'Quoted 5 lines
71 | int:(x) ? -1 : 1; \ | ^/src/include/qemu/osdep.h:474:24: note: in expansion of macro '
QEMU_BUILD_BUG_ON_ZERO'
474 |QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x)))
Quoted 4 lines
| ^~~~~~~~~~~~~~~~~~~~~~/src/include/qemu/osdep.h:474:48: note: in expansion of macro '
QEMU_IS_ARRAY'
474 |
Quoted 9 lines
QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x)))
Quoted 2 lines
Can you help with this?
Eh no clue, maybe not C++ compliant?
Fall back to
sizeof()¯\_(ツ)_/¯
You are right, When I rename the file to vss-debug.c the error disappears. What is the better solution:
1) use vss-debug.c and extern "C" { #include "vss-debug.h" } in CPP files
2) just use sizeof() in CPP
Quoted 26 lines
Quoted 5 lines
> + va_end(args); > + > + snprintf(full_string, 640, QGA_PROVIDER_NAME "[%lu]: %s%s\n",
Quoted 18 lines
> + GetCurrentThreadId(), funcname, user_sting); if (snprintf() <= 0) { return; } > + > + OutputDebugString(full_string); > + fprintf(stderr, "%s", full_string); Format unused: fputs(full_string, stderr); > +} With the changes: Reviewed-by: Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>>
Re: [PATCH v3 1/4] QGA VSS: Add wrapper to send log to debugger and stderr
Quoted 115 lines · Konstantin Kostiuk
On Fri, Jul 7, 2023 at 6:36 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:
On 7/7/23 16:24, Konstantin Kostiuk wrote: > > > On Fri, Jul 7, 2023 at 1:33 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]> > <mailto:[email protected] <mailto:[email protected]>>> wrote: > > On 7/7/23 11:22, Konstantin Kostiuk wrote: > > Signed-off-by: Konstantin Kostiuk <[email protected] <mailto:[email protected]> > <mailto:[email protected] <mailto:[email protected]>>> > > --- > > qga/vss-win32/meson.build | 2 +- > > qga/vss-win32/vss-debug.cpp | 31 +++++++++++++++++++++++++++++++ > > qga/vss-win32/vss-debug.h | 25 +++++++++++++++++++++++++ > > 3 files changed, 57 insertions(+), 1 deletion(-) > > create mode 100644 qga/vss-win32/vss-debug.cpp > > create mode 100644 qga/vss-win32/vss-debug.h > > > > diff --git a/qga/vss-win32/vss-debug.cpp > b/qga/vss-win32/vss-debug.cpp > > new file mode 100644 > > index 0000000000..5d6f37944b > > --- /dev/null > > +++ b/qga/vss-win32/vss-debug.cpp > > @@ -0,0 +1,31 @@ > > +/* > > + * QEMU Guest Agent VSS debug declarations > > + * > > + * Copyright (C) 2023 Red Hat Inc > > + * > > + * Authors: > > + * Konstantin Kostiuk <[email protected] <mailto:[email protected]> > <mailto:[email protected] <mailto:[email protected]>>> > > + * > > + * This work is licensed under the terms of the GNU GPL, version > 2 or later. > > + * See the COPYING file in the top-level directory. > > + */ > > + > > +#include "qemu/osdep.h" > > +#include "vss-debug.h" > > +#include "vss-common.h" > > + > > +void qga_debug_internal(const char *funcname, const char *fmt, > ...) { > > + char user_sting[512] = {0}; > > "user_string" > > > + char full_string[640] = {0}; > > + > > + va_list args; > > + va_start(args, fmt); > > + vsnprintf(user_sting, 512, fmt, args); > > ARRAY_SIZE(user_string) > > > I have a problem with ARRAY_SIZE define. > > ../qga/vss-win32/vss-debug.cpp: In function 'void > qga_debug_internal(const char*, const char*, ...)': > /src/include/qemu/compiler.h:70:12: error: types may not be defined in > 'sizeof' expressions > 70 | struct { \ > | ^ > /src/include/qemu/compiler.h:78:43: note: in expansion of macro > 'QEMU_BUILD_BUG_ON_STRUCT' > 78 | #define QEMU_BUILD_BUG_ON_ZERO(x) > (sizeof(QEMU_BUILD_BUG_ON_STRUCT(x)) - \ > | ^~~~~~~~~~~~~~~~~~~~~~~~ > /src/include/qemu/osdep.h:474:24: note: in expansion of macro > 'QEMU_BUILD_BUG_ON_ZERO' > 474 | QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x))) > | ^~~~~~~~~~~~~~~~~~~~~~ > ../qga/vss-win32/vss-debug.cpp:23:32: note: in expansion of macro > 'ARRAY_SIZE' > 23 | if (vsnprintf(user_string, ARRAY_SIZE(user_string), fmt, > args) <= 0) { > | ^~~~~~~~~~ > /src/include/qemu/osdep.h:470:57: error: expected primary-expression > before 'typeof' > 470 | #define QEMU_IS_ARRAY(x) > (!__builtin_types_compatible_p(typeof(x), \ > | ^~~~~~ > /src/include/qemu/compiler.h:71:14: note: in definition of macro > 'QEMU_BUILD_BUG_ON_STRUCT' > 71 | int:(x) ? -1 : 1; \ > | ^ > /src/include/qemu/osdep.h:474:24: note: in expansion of macro > 'QEMU_BUILD_BUG_ON_ZERO' > 474 | QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x))) > | ^~~~~~~~~~~~~~~~~~~~~~ > /src/include/qemu/osdep.h:474:48: note: in expansion of macro > 'QEMU_IS_ARRAY' > 474 | QEMU_BUILD_BUG_ON_ZERO(!QEMU_IS_ARRAY(x))) > > Can you help with this? Eh no clue, maybe not C++ compliant? Fall back to sizeof() ¯\_(ツ)_/¯
Quoted 4 lines
You are right, When I rename the file to
vss-debug.cthe error disappears. What is the better solution:
1) usevss-debug.cand extern "C" { #include "vss-debug.h" } in CPP files
2) just usesizeof()in CPP
I recently sent a patch to drop the logic for linking C code with C++ code:
https://lists.gnu.org/archive/html/qemu-devel/2023-07/msg01553.html
So please go with option 2 ;-)
Thomas
PATCH v3 2/4 QGA VSS: Replace 'fprintf(stderr' with PRINT_DEBUG
In reply to Konstantin Kostiuk--- qga/vss-win32/install.cpp | 12 ++++++------ qga/vss-win32/requester.cpp | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-)
qga/vss-win32/install.cpp +6 -6
@@ -13,6 +13,7 @@ #include "qemu/osdep.h" #include "vss-common.h" +#include "vss-debug.h" #ifdef HAVE_VSS_SDK #include <vscoordint.h> #else
@@ -54,7 +55,7 @@ void errmsg(DWORD err, const char *text) FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char *)&msg, 0, NULL); - fprintf(stderr, "%.*s. (Error: %lx) %s\n", len, text, err, msg); + qga_debug("%.*s. (Error: %lx) %s\n", len, text, err, msg); LocalFree(msg); }
@@ -219,7 +220,7 @@ static HRESULT QGAProviderRemove(ICatalogCollection *coll, int i, void *arg) { HRESULT hr; - fprintf(stderr, "Removing COM+ Application: %s\n", QGA_PROVIDER_NAME); + qga_debug("Removing COM+ Application: %s", QGA_PROVIDER_NAME); chk(coll->Remove(i)); out: return hr;
@@ -304,9 +305,8 @@ STDAPI COMRegister(void) } strcpy(tlbPath, dllPath); strcpy(tlbPath+n-3, "tlb"); - fprintf(stderr, "Registering " QGA_PROVIDER_NAME ":\n"); - fprintf(stderr, " %s\n", dllPath); - fprintf(stderr, " %s\n", tlbPath); + qga_debug("Registering " QGA_PROVIDER_NAME ": %s %s", + dllPath, tlbPath); if (!PathFileExists(tlbPath)) { hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); errmsg(hr, "Failed to lookup tlb");
@@ -517,7 +517,7 @@ namespace _com_util } if (mbstowcs(bstr, ascii, len) == (size_t)-1) { - fprintf(stderr, "Failed to convert string '%s' into BSTR", ascii); + qga_debug("Failed to convert string '%s' into BSTR", ascii); bstr[0] = 0; } return bstr;
qga/vss-win32/requester.cpp +5 -4
@@ -12,6 +12,7 @@ #include "qemu/osdep.h" #include "vss-common.h" +#include "vss-debug.h" #include "requester.h" #include "install.h" #include <vswriter.h>
@@ -59,13 +60,13 @@ STDAPI requester_init(void) NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, NULL); if (FAILED(hr)) { - fprintf(stderr, "failed to CoInitializeSecurity (error %lx)\n", hr); + qga_debug("failed to CoInitializeSecurity (error %lx)", hr); return hr; } hLib = LoadLibraryA("VSSAPI.DLL"); if (!hLib) { - fprintf(stderr, "failed to load VSSAPI.DLL\n"); + qga_debug("failed to load VSSAPI.DLL"); return HRESULT_FROM_WIN32(GetLastError()); }
@@ -78,14 +79,14 @@ STDAPI requester_init(void) #endif ); if (!pCreateVssBackupComponents) { - fprintf(stderr, "failed to get proc address from VSSAPI.DLL\n"); + qga_debug("failed to get proc address from VSSAPI.DLL"); return HRESULT_FROM_WIN32(GetLastError()); } pVssFreeSnapshotProperties = (t_VssFreeSnapshotProperties) GetProcAddress(hLib, "VssFreeSnapshotProperties"); if (!pVssFreeSnapshotProperties) { - fprintf(stderr, "failed to get proc address from VSSAPI.DLL\n"); + qga_debug("failed to get proc address from VSSAPI.DLL"); return HRESULT_FROM_WIN32(GetLastError()); }
Signature · 1 line
2.34.1
Re: [PATCH v3 2/4] QGA VSS: Replace 'fprintf(stderr' with PRINT_DEBUG
Quoted 8 lines · Konstantin Kostiuk
Signed-off-by Konstantin Kostiuk <[email protected]>--- qga/vss-win32/install.cpp | 12 ++++++------ qga/vss-win32/requester.cpp | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-)
qga/vss-win32/install.cpp STDAPI COMRegister(void) · line 309
Quoted 8 lines
qga/vss-win32/install.cpp +2
-3@@ -304,9 +305,8 @@ STDAPI COMRegister(void) } strcpy(tlbPath, dllPath); strcpy(tlbPath+n-3, "tlb"); - fprintf(stderr, "Registering " QGA_PROVIDER_NAME ":\n"); - fprintf(stderr, " %s\n", dllPath); - fprintf(stderr, " %s\n", tlbPath); + qga_debug("Registering " QGA_PROVIDER_NAME ": %s %s", + dllPath, tlbPath);
Previous has 3 "\n", not necessary? Otherwise:
Quoted 3 lines
qga/vss-win32/install.cpp +0
-0if (!PathFileExists(tlbPath)) { hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); errmsg(hr, "Failed to lookup tlb");
Re: [PATCH v3 2/4] QGA VSS: Replace 'fprintf(stderr' with PRINT_DEBUG
Quoted 8 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Konstantin Kostiuk
Signed-off-by Konstantin Kostiuk <[email protected]>--- qga/vss-win32/install.cpp | 12 ++++++------ qga/vss-win32/requester.cpp | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-)
Quoted 12 lines
qga/vss-win32/install.cpp STDAPI COMRegister(void) · line 309
Quoted 9 lines
qga/vss-win32/install.cpp +2
-3@@ -304,9 +305,8 @@ STDAPI COMRegister(void) } strcpy(tlbPath, dllPath); strcpy(tlbPath+n-3, "tlb"); - fprintf(stderr, "Registering " QGA_PROVIDER_NAME ":\n"); - fprintf(stderr, " %s\n", dllPath); - fprintf(stderr, " %s\n", tlbPath); + qga_debug("Registering " QGA_PROVIDER_NAME ": %s %s", + dllPath, tlbPath);Previous has 3 "\n", not necessary? Otherwise:
I think 3 "\n" is not necessary. The line is still human-readable.
Quoted 9 lines
Reviewed-by Philippe Mathieu-Daudé <[email protected]>Quoted 3 lines
qga/vss-win32/install.cpp +0
-0if (!PathFileExists(tlbPath)) { hr = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); errmsg(hr, "Failed to lookup tlb");
PATCH v3 3/4 QGA VSS: Print error in err_set
In reply to Konstantin Kostiuk--- qga/vss-win32/requester.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
qga/vss-win32/requester.cpp +5 -3
@@ -26,9 +26,11 @@ #define DEFAULT_VSS_BACKUP_TYPE VSS_BT_FULL -#define err_set(e, err, fmt, ...) \ - ((e)->error_setg_win32_wrapper((e)->errp, __FILE__, __LINE__, __func__, \ - err, fmt, ## __VA_ARGS__)) +#define err_set(e, err, fmt, ...) { \ + (e)->error_setg_win32_wrapper((e)->errp, __FILE__, __LINE__, __func__, \ + err, fmt, ## __VA_ARGS__); \ + qga_debug(fmt, ## __VA_ARGS__); \ +} /* Bad idea, works only when (e)->errp != NULL: */ #define err_is_set(e) ((e)->errp && *(e)->errp) /* To lift this restriction, error_propagate(), like we do in QEMU code */
Signature · 1 line
2.34.1
PATCH v3 4/4 QGA VSS: Add log in functions begin/end
In reply to Konstantin Kostiuk--- qga/vss-win32/install.cpp | 33 +++++++++++++++++++++++++++++++++ qga/vss-win32/provider.cpp | 3 +++ qga/vss-win32/requester.cpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+)
qga/vss-win32/install.cpp +33 -0
@@ -100,6 +100,8 @@ HRESULT put_Value(ICatalogObject *pObj, LPCWSTR name, T val) /* Lookup Administrators group name from winmgmt */ static HRESULT GetAdminName(_bstr_t *name) { + qga_debug_begin; + HRESULT hr; COMPointer<IWbemLocator> pLoc; COMPointer<IWbemServices> pSvc;
@@ -142,6 +144,7 @@ static HRESULT GetAdminName(_bstr_t *name) } out: + qga_debug_end; return hr; }
@@ -149,6 +152,8 @@ out: static HRESULT getNameByStringSID( const wchar_t *sid, LPWSTR buffer, LPDWORD bufferLen) { + qga_debug_begin; + HRESULT hr = S_OK; PSID psid = NULL; SID_NAME_USE groupType;
@@ -168,6 +173,7 @@ static HRESULT getNameByStringSID( LocalFree(psid); out: + qga_debug_end; return hr; }
@@ -175,6 +181,8 @@ out: static HRESULT QGAProviderFind( HRESULT (*found)(ICatalogCollection *, int, void *), void *arg) { + qga_debug_begin; + HRESULT hr; COMInitializer initializer; COMPointer<IUnknown> pUnknown;
@@ -205,12 +213,15 @@ static HRESULT QGAProviderFind( chk(pColl->SaveChanges(&n)); out: + qga_debug_end; return hr; } /* Count QGA VSS provider in COM+ Application Catalog */ static HRESULT QGAProviderCount(ICatalogCollection *coll, int i, void *arg) { + qga_debug_begin; + (*(int *)arg)++; return S_OK; }
@@ -218,28 +229,35 @@ static HRESULT QGAProviderCount(ICatalogCollection *coll, int i, void *arg) /* Remove QGA VSS provider from COM+ Application Catalog Collection */ static HRESULT QGAProviderRemove(ICatalogCollection *coll, int i, void *arg) { + qga_debug_begin; HRESULT hr; qga_debug("Removing COM+ Application: %s", QGA_PROVIDER_NAME); chk(coll->Remove(i)); out: + qga_debug_end; return hr; } /* Unregister this module from COM+ Applications Catalog */ STDAPI COMUnregister(void) { + qga_debug_begin; + HRESULT hr; DllUnregisterServer(); chk(QGAProviderFind(QGAProviderRemove, NULL)); out: + qga_debug_end; return hr; } /* Register this module to COM+ Applications Catalog */ STDAPI COMRegister(void) { + qga_debug_begin; + HRESULT hr; COMInitializer initializer; COMPointer<IUnknown> pUnknown;
@@ -259,12 +277,14 @@ STDAPI COMRegister(void) if (!g_hinstDll) { errmsg(E_FAIL, "Failed to initialize DLL"); + qga_debug_end; return E_FAIL; } chk(QGAProviderFind(QGAProviderCount, (void *)&count)); if (count) { errmsg(E_ABORT, "QGA VSS Provider is already installed"); + qga_debug_end; return E_ABORT; }
@@ -354,6 +374,7 @@ out: COMUnregister(); } + qga_debug_end; return hr; }
@@ -369,6 +390,8 @@ STDAPI_(void) CALLBACK DLLCOMUnregister(HWND, HINSTANCE, LPSTR, int) static BOOL CreateRegistryKey(LPCTSTR key, LPCTSTR value, LPCTSTR data) { + qga_debug_begin; + HKEY hKey; LONG ret; DWORD size;
@@ -389,6 +412,7 @@ static BOOL CreateRegistryKey(LPCTSTR key, LPCTSTR value, LPCTSTR data) RegCloseKey(hKey); out: + qga_debug_end; if (ret != ERROR_SUCCESS) { /* As we cannot printf within DllRegisterServer(), show a dialog. */ errmsg_dialog(ret, "Cannot add registry", key);
@@ -400,6 +424,8 @@ out: /* Register this dll as a VSS provider */ STDAPI DllRegisterServer(void) { + qga_debug_begin; + COMInitializer initializer; COMPointer<IVssAdmin> pVssAdmin; HRESULT hr = E_FAIL;
@@ -478,12 +504,15 @@ out: DllUnregisterServer(); } + qga_debug_end; return hr; } /* Unregister this VSS hardware provider from the system */ STDAPI DllUnregisterServer(void) { + qga_debug_begin; + TCHAR key[256]; COMInitializer initializer; COMPointer<IVssAdmin> pVssAdmin;
@@ -501,6 +530,7 @@ STDAPI DllUnregisterServer(void) SHDeleteKey(HKEY_CLASSES_ROOT, key); SHDeleteKey(HKEY_CLASSES_ROOT, g_szProgid); + qga_debug_end; return S_OK; /* Uninstall should never fail */ }
@@ -527,6 +557,8 @@ namespace _com_util /* Stop QGA VSS provider service using Winsvc API */ STDAPI StopService(void) { + qga_debug_begin; + HRESULT hr = S_OK; SC_HANDLE manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); SC_HANDLE service = NULL;
@@ -551,5 +583,6 @@ STDAPI StopService(void) out: CloseServiceHandle(service); CloseServiceHandle(manager); + qga_debug_end; return hr; }
qga/vss-win32/provider.cpp +3 -0
@@ -12,6 +12,7 @@ #include "qemu/osdep.h" #include "vss-common.h" +#include "vss-debug.h" #ifdef HAVE_VSS_SDK #include <vscoordint.h> #else
@@ -529,9 +530,11 @@ STDAPI DllCanUnloadNow() EXTERN_C BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD dwReason, LPVOID lpReserved) { + qga_debug("begin, reason = %lu", dwReason); if (dwReason == DLL_PROCESS_ATTACH) { g_hinstDll = hinstDll; DisableThreadLibraryCalls(hinstDll); } + qga_debug_end; return TRUE; }
qga/vss-win32/requester.cpp +34 -0
@@ -57,6 +57,8 @@ static struct QGAVSSContext { STDAPI requester_init(void) { + qga_debug_begin; + COMInitializer initializer; /* to call CoInitializeSecurity */ HRESULT hr = CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
@@ -92,11 +94,14 @@ STDAPI requester_init(void) return HRESULT_FROM_WIN32(GetLastError()); } + qga_debug_end; return S_OK; } static void requester_cleanup(void) { + qga_debug_begin; + if (vss_ctx.hEventFrozen) { CloseHandle(vss_ctx.hEventFrozen); vss_ctx.hEventFrozen = NULL;
@@ -118,10 +123,13 @@ static void requester_cleanup(void) vss_ctx.pVssbc = NULL; } vss_ctx.cFrozenVols = 0; + qga_debug_end; } STDAPI requester_deinit(void) { + qga_debug_begin; + requester_cleanup(); pCreateVssBackupComponents = NULL;
@@ -131,11 +139,14 @@ STDAPI requester_deinit(void) hLib = NULL; } + qga_debug_end; return S_OK; } static HRESULT WaitForAsync(IVssAsync *pAsync) { + qga_debug_begin; + HRESULT ret, hr; do {
@@ -151,11 +162,14 @@ static HRESULT WaitForAsync(IVssAsync *pAsync) } } while (ret == VSS_S_ASYNC_PENDING); + qga_debug_end; return ret; } static void AddComponents(ErrorSet *errset) { + qga_debug_begin; + unsigned int cWriters, i; VSS_ID id, idInstance, idWriter; BSTR bstrWriterName = NULL;
@@ -237,17 +251,21 @@ out: if (pComponent && info) { pComponent->FreeComponentInfo(info); } + qga_debug_end; } DWORD get_reg_dword_value(HKEY baseKey, LPCSTR subKey, LPCSTR valueName, DWORD defaultData) { + qga_debug_begin; + DWORD regGetValueError; DWORD dwordData; DWORD dataSize = sizeof(DWORD); regGetValueError = RegGetValue(baseKey, subKey, valueName, RRF_RT_DWORD, NULL, &dwordData, &dataSize); + qga_debug_end; if (regGetValueError != ERROR_SUCCESS) { return defaultData; }
@@ -262,6 +280,8 @@ bool is_valid_vss_backup_type(VSS_BACKUP_TYPE vssBT) VSS_BACKUP_TYPE get_vss_backup_type( VSS_BACKUP_TYPE defaultVssBT = DEFAULT_VSS_BACKUP_TYPE) { + qga_debug_begin; + VSS_BACKUP_TYPE vssBackupType; vssBackupType = static_cast<VSS_BACKUP_TYPE>(
@@ -269,6 +289,7 @@ VSS_BACKUP_TYPE get_vss_backup_type( QGA_PROVIDER_REGISTRY_ADDRESS, "VssOption", defaultVssBT)); + qga_debug_end; if (!is_valid_vss_backup_type(vssBackupType)) { return defaultVssBT; }
@@ -277,6 +298,8 @@ VSS_BACKUP_TYPE get_vss_backup_type( void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset) { + qga_debug_begin; + COMPointer<IVssAsync> pAsync; HANDLE volume; HRESULT hr;
@@ -292,6 +315,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset) if (vss_ctx.pVssbc) { /* already frozen */ *num_vols = 0; + qga_debug("finished, already frozen"); return; }
@@ -449,6 +473,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset) } } + qga_debug("preparing for backup"); hr = vss_ctx.pVssbc->PrepareForBackup(pAsync.replace()); if (SUCCEEDED(hr)) { hr = WaitForAsync(pAsync);
@@ -472,6 +497,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset) * CQGAVssProvider::CommitSnapshots will kick vss_ctx.hEventFrozen * after the applications and filesystems are frozen. */ + qga_debug("do snapshot set"); hr = vss_ctx.pVssbc->DoSnapshotSet(&vss_ctx.pAsyncSnapshot); if (FAILED(hr)) { err_set(errset, hr, "failed to do snapshot set");
@@ -518,6 +544,7 @@ void requester_freeze(int *num_vols, void *mountpoints, ErrorSet *errset) *num_vols = vss_ctx.cFrozenVols = num_fixed_drives; } + qga_debug("end successful"); return; out:
@@ -528,11 +555,14 @@ out: out1: requester_cleanup(); CoUninitialize(); + + qga_debug_end; } void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset) { + qga_debug_begin; COMPointer<IVssAsync> pAsync; if (!vss_ctx.hEventThaw) {
@@ -541,6 +571,8 @@ void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset) * and no volumes must be frozen. We return without an error. */ *num_vols = 0; + qga_debug("finished, no volumes were frozen"); + return; }
@@ -597,4 +629,6 @@ void requester_thaw(int *num_vols, void *mountpints, ErrorSet *errset) CoUninitialize(); StopService(); + + qga_debug_end; }
Signature · 1 line
2.34.1