qmp qga: Purge error_is_set()
v3 cover qmp qga: Purge error_is_set()
I got a private branch getting rid of it entirely. This is the fifth part, covering QMP and the guest agent up to the point where I start messing with the QAPI code generators. That's left for the final part.
Luiz agreed to take this through his tree.
This series conflicts with Lluís's "qapi: Allow modularization of QAPI schema files", but only in docs/writing-qmp-commands.txt, and resolution is trivial.
v3:
- PATCH 02/15 peformed two unwanted renames, 03/15 reverted them; drop all that. Since this effectively squashes 03 into 02, I took the liberty to retain Eric's R-by.
v2:
- Rebased, straightforward conflict in PATCH 01/15 resolved
- Commit message for PATCH 06/15 clarified [Eric]
Markus Armbruster (14):
qmp hmp: Consistently name Error * objects err, and not errp
qga: Consistently name Error ** objects errp, and not err
qmp: Consistently name Error ** objects errp, and not err
error: Consistently name Error ** objects errp, and not err
qga: Use return values instead of error_is_set(errp)
hmp: Guard against misuse of hmp_handle_error()
qapi: Drop redundant, unclean error_is_set() tests/qapi-schema: Drop superfluous error_is_set()
qapi: Clean up fragile use of error_is_set()
qga: Clean up fragile use of error_is_set()
qga: Drop superfluous error_is_set()
qemu-option: Clean up fragile use of error_is_set()
dump: Drop pointless error_is_set(), DumpState member errp
qmp: Don't use error_is_set() to suppress additional errors
docs/writing-qmp-commands.txt | 28 ++--- dump.c | 6 +- hmp.c | 141 ++++++++++++------------ include/qapi/error.h | 27 +++-- include/qapi/qmp/dispatch.h | 2 +- qapi/qmp-dispatch.c | 24 ++--- qga/commands-posix.c | 213 ++++++++++++++++++++----------------- qga/commands-win32.c | 123 ++++++++++----------- qga/commands.c | 4 +- qga/main.c | 1 + qga/vss-win32.c | 4 +- qga/vss-win32.h | 2 +- qmp.c | 42 +++----- tests/test-qmp-input-strict.c | 72 ++++++------- tests/test-qmp-input-visitor.c | 89 ++++++++-------- tests/test-qmp-output-visitor.c | 74 ++++++------- tests/test-string-input-visitor.c | 50 ++++----- tests/test-string-output-visitor.c | 46 ++++---- util/error.c | 8 +- util/qemu-option.c | 2 +- 20 files changed, 484 insertions(+), 474 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v3 1/14 qmp hmp: Consistently name Error * objects err, and not errp
--- docs/writing-qmp-commands.txt | 28 ++++---- hmp.c | 138 ++++++++++++++++++------------------- include/qapi/qmp/dispatch.h | 2 +- qapi/qmp-dispatch.c | 6 +- tests/test-qmp-input-strict.c | 72 +++++++++---------- tests/test-qmp-input-visitor.c | 64 ++++++++--------- tests/test-qmp-output-visitor.c | 74 ++++++++++---------- tests/test-string-input-visitor.c | 50 +++++++------- tests/test-string-output-visitor.c | 46 ++++++------- 9 files changed, 240 insertions(+), 240 deletions(-)
docs/writing-qmp-commands.txt +14 -14
@@ -308,12 +308,12 @@ Here's the implementation of the "hello-world" HMP command: void hmp_hello_world(Monitor *mon, const QDict *qdict) { const char *message = qdict_get_try_str(qdict, "message"); - Error *errp = NULL; + Error *err = NULL; - qmp_hello_world(!!message, message, &errp); - if (errp) { - monitor_printf(mon, "%s\n", error_get_pretty(errp)); - error_free(errp); + qmp_hello_world(!!message, message, &err); + if (err) { + monitor_printf(mon, "%s\n", error_get_pretty(err)); + error_free(err); return; } }
@@ -328,7 +328,7 @@ There are three important points to be noticed: 2. hmp_hello_world() performs error checking. In this example we just print the error description to the user, but we could do more, like taking different actions depending on the error qmp_hello_world() returns -3. The "errp" variable must be initialized to NULL before performing the +3. The "err" variable must be initialized to NULL before performing the QMP call There's one last step to actually make the command available to monitor users,
@@ -480,12 +480,12 @@ Here's the HMP counterpart of the query-alarm-clock command: void hmp_info_alarm_clock(Monitor *mon) { QemuAlarmClock *clock; - Error *errp = NULL; + Error *err = NULL; - clock = qmp_query_alarm_clock(&errp); - if (errp) { + clock = qmp_query_alarm_clock(&err); + if (err) { monitor_printf(mon, "Could not query alarm clock information\n"); - error_free(errp); + error_free(err); return; }
@@ -631,12 +631,12 @@ has to traverse the list, it's shown below for reference: void hmp_info_alarm_methods(Monitor *mon) { TimerAlarmMethodList *method_list, *method; - Error *errp = NULL; + Error *err = NULL; - method_list = qmp_query_alarm_methods(&errp); - if (errp) { + method_list = qmp_query_alarm_methods(&err); + if (err) { monitor_printf(mon, "Could not query alarm methods\n"); - error_free(errp); + error_free(err); return; }
hmp.c +69 -69
311 lines not on this page · raw message
include/qapi/qmp/dispatch.h +1 -1
@@ -50,7 +50,7 @@ void qmp_enable_command(const char *name);bool qmp_command_is_enabled (const QmpCommand *cmd);const char *qmp_command_name (const QmpCommand *cmd);bool qmp_has_success_response (const QmpCommand *cmd); -QObject *qmp_build_error_object (Error *errp); +QObject *qmp_build_error_object (Error *err);typedef void (*qmp_cmd_callback_fn )(QmpCommand *cmd,void *opaque);void qmp_for_each_command (qmp_cmd_callback_fn fn,void *opaque);
qapi/qmp-dispatch.c +3 -3
@@ -110,11 +110,11 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp)return ret; } -QObject *qmp_build_error_object (Error *errp) +QObject *qmp_build_error_object (Error *err) {return qobject_from_jsonf ("{ 'class': %s, 'desc': %s }" , - ErrorClass_lookup[error_get_class (errp)], -error_get_pretty (errp)); + ErrorClass_lookup[error_get_class (err)], +error_get_pretty (err)); }QObject *qmp_dispatch (QObject *request)
tests/test-qmp-input-strict.c +36 -36
191 lines not on this page · raw message
tests/test-qmp-input-visitor.c +32 -32
171 lines not on this page · raw message
tests/test-qmp-output-visitor.c +37 -37
178 lines not on this page · raw message
tests/test-string-input-visitor.c +25 -25
128 lines not on this page · raw message
tests/test-string-output-visitor.c +23 -23
106 lines not on this page · raw message
Signature · 1 line
1.8.1.4
PATCH v3 2/14 qga: Consistently name Error ** objects errp, and not err
In reply to Markus Armbruster--- qga/commands-posix.c | 199 ++++++++++++++++++++++++++------------------------- qga/commands-win32.c | 105 ++++++++++++++------------- qga/commands.c | 4 +- qga/vss-win32.c | 4 +- qga/vss-win32.h | 2 +- 5 files changed, 160 insertions(+), 154 deletions(-)
qga/commands-posix.c +101 -98
@@ -53,7 +53,7 @@ extern char **environ;#endif #endif -static void ga_wait_child (pid_t pid,int *status,Error **err) +static void ga_wait_child (pid_t pid,int *status,Error **errp) {pid_t rpid;
@@ -64,14 +64,15 @@ static void ga_wait_child(pid_t pid, int *status, Error **err) }while (rpid ==-1 && errno ==EINTR );if (rpid ==-1 ) { -error_setg_errno (err, errno,"failed to wait for child (pid: %d)" , pid); +error_setg_errno (errp, errno,"failed to wait for child (pid: %d)" , + pid);return ; }g_assert (rpid == pid); } -void qmp_guest_shutdown (bool has_mode,const char *mode,Error **err) +void qmp_guest_shutdown (bool has_mode,const char *mode,Error **errp) {const char *shutdown_flag;Error *local_err =NULL ;
@@ -86,7 +87,7 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) }else if (strcmp (mode,"reboot" ) ==0 ) { shutdown_flag ="-r" ; }else { -error_setg (err, +error_setg (errp,"mode is invalid (valid values are: halt|powerdown|reboot" );return ; }
@@ -103,23 +104,23 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **err) "hypervisor initiated shutdown", (char*)NULL, environ);_exit (EXIT_FAILURE ); }else if (pid <0 ) { -error_setg_errno (err, errno,"failed to create child process" ); +error_setg_errno (errp, errno,"failed to create child process" );return ; }ga_wait_child (pid, &status, &local_err);if (local_err) { -error_propagate (err, local_err); +error_propagate (errp, local_err);return ; }if (!WIFEXITED (status)) { -error_setg (err,"child process has terminated abnormally" ); +error_setg (errp,"child process has terminated abnormally" );return ; }if (WEXITSTATUS (status)) { -error_setg (err,"child process has failed to shutdown" ); +error_setg (errp,"child process has failed to shutdown" );return ; }
@@ -234,7 +235,7 @@ static int64_t guest_file_handle_add(FILE *fh, Error **errp)return handle; } -static GuestFileHandle *guest_file_handle_find (int64_t id,Error **err) +static GuestFileHandle *guest_file_handle_find (int64_t id,Error **errp) {GuestFileHandle *gfh;
@@ -245,7 +246,7 @@ static GuestFileHandle *guest_file_handle_find(int64_t id, Error **err) } } -error_setg (err,"handle '%" PRId64"' has not been found" , id); +error_setg (errp,"handle '%" PRId64"' has not been found" , id);return NULL ; }
@@ -275,7 +276,7 @@ static const struct { };static int -find_open_flag (const char *mode_str,Error **err) +find_open_flag (const char *mode_str,Error **errp) {unsigned mode;
@@ -292,7 +293,7 @@ find_open_flag(const char *mode_str, Error **err) }if (mode ==ARRAY_SIZE (guest_file_open_modes)) { -error_setg (err,"invalid file open mode '%s'" , mode_str); +error_setg (errp,"invalid file open mode '%s'" , mode_str);return -1 ; }return guest_file_open_modes[mode].oflag_base |O_NOCTTY |O_NONBLOCK ;
@@ -303,7 +304,7 @@ find_open_flag(const char *mode_str, Error **err) S_IROTH | S_IWOTH)static FILE * -safe_open_or_create (const char *path,const char *mode,Error **err) +safe_open_or_create (const char *path,const char *mode,Error **errp) {Error *local_err =NULL ;int oflag;
@@ -370,11 +371,12 @@ safe_open_or_create(const char *path, const char *mode, Error **err) } } -error_propagate (err, local_err); +error_propagate (errp, local_err);return NULL ; } -int64_t qmp_guest_file_open (const char *path,bool has_mode,const char *mode,Error **err) +int64_t qmp_guest_file_open (const char *path,bool has_mode,const char *mode, +Error **errp) {FILE *fh;Error *local_err =NULL ;
@@ -387,7 +389,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Eslog ("guest-file-open called, filepath: %s, mode: %s" , path, mode); fh =safe_open_or_create (path, mode, &local_err);if (local_err !=NULL ) { -error_propagate (err, local_err); +error_propagate (errp, local_err);return -1 ; }
@@ -398,14 +400,14 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, E ret =fcntl (fd,F_GETFL ); ret =fcntl (fd,F_SETFL , ret |O_NONBLOCK );if (ret ==-1 ) { -error_setg_errno (err, errno,"failed to make file '%s' non-blocking" , +error_setg_errno (errp, errno,"failed to make file '%s' non-blocking" , path);fclose (fh);return -1 ; } - handle =guest_file_handle_add (fh, err); -if (error_is_set (err)) { + handle =guest_file_handle_add (fh, errp); +if (error_is_set (errp)) {fclose (fh);return -1 ; }
@@ -414,9 +416,9 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, Ereturn handle; } -void qmp_guest_file_close (int64_t handle,Error **err) +void qmp_guest_file_close (int64_t handle,Error **errp) { -GuestFileHandle *gfh =guest_file_handle_find (handle, err); +GuestFileHandle *gfh =guest_file_handle_find (handle, errp);int ret;slog ("guest-file-close called, handle: %" PRId64, handle);
@@ -426,7 +428,7 @@ void qmp_guest_file_close(int64_t handle, Error **err) ret =fclose (gfh->fh);if (ret ==EOF ) { -error_setg_errno (err, errno,"failed to close handle" ); +error_setg_errno (errp, errno,"failed to close handle" );return ; }
@@ -435,9 +437,9 @@ void qmp_guest_file_close(int64_t handle, Error **err) }struct GuestFileRead *qmp_guest_file_read (int64_t handle,bool has_count, -int64_t count,Error **err) +int64_t count,Error **errp) { -GuestFileHandle *gfh =guest_file_handle_find (handle, err); +GuestFileHandle *gfh =guest_file_handle_find (handle, errp);GuestFileRead *read_data =NULL ;guchar *buf;FILE *fh;
@@ -450,7 +452,7 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,if (!has_count) { count =QGA_READ_COUNT_DEFAULT ; }else if (count <0 ) { -error_setg (err,"value '%" PRId64"' is invalid for argument count" , +error_setg (errp,"value '%" PRId64"' is invalid for argument count" , count);return NULL ; }
@@ -459,7 +461,7 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count, buf =g_malloc0 (count+1 ); read_count =fread (buf,1 , count, fh);if (ferror (fh)) { -error_setg_errno (err, errno,"failed to read file" ); +error_setg_errno (errp, errno,"failed to read file" );slog ("guest-file-read failed, handle: %" PRId64, handle); }else { buf[read_count] =0 ;
@@ -477,13 +479,14 @@ struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count, }GuestFileWrite *qmp_guest_file_write (int64_t handle,const char *buf_b64, -bool has_count,int64_t count,Error **err) +bool has_count,int64_t count, +Error **errp) {GuestFileWrite *write_data =NULL ;guchar *buf;gsize buf_len;int write_count; -GuestFileHandle *gfh =guest_file_handle_find (handle, err); +GuestFileHandle *gfh =guest_file_handle_find (handle, errp);FILE *fh;if (!gfh) {
@@ -496,7 +499,7 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64,if (!has_count) { count = buf_len; }else if (count <0 || count > buf_len) { -error_setg (err,"value '%" PRId64"' is invalid for argument count" , +error_setg (errp,"value '%" PRId64"' is invalid for argument count" , count);g_free (buf);return NULL ;
@@ -504,7 +507,7 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64, write_count =fwrite (buf,1 , count, fh);if (ferror (fh)) { -error_setg_errno (err, errno,"failed to write to file" ); +error_setg_errno (errp, errno,"failed to write to file" );slog ("guest-file-write failed, handle: %" PRId64, handle); }else { write_data =g_malloc0 (sizeof (GuestFileWrite));
@@ -518,9 +521,9 @@ GuestFileWrite *qmp_guest_file_write(int64_t handle, const char *buf_b64, }struct GuestFileSeek *qmp_guest_file_seek (int64_t handle,int64_t offset, -int64_t whence,Error **err) +int64_t whence,Error **errp) { -GuestFileHandle *gfh =guest_file_handle_find (handle, err); +GuestFileHandle *gfh =guest_file_handle_find (handle, errp);GuestFileSeek *seek_data =NULL ;FILE *fh;int ret;
@@ -532,7 +535,7 @@ struct GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset, fh = gfh->fh; ret =fseek (fh, offset, whence);if (ret ==-1 ) { -error_setg_errno (err, errno,"failed to seek file" ); +error_setg_errno (errp, errno,"failed to seek file" ); }else { seek_data =g_new0 (GuestFileSeek,1 ); seek_data->position =ftell (fh);
@@ -543,9 +546,9 @@ struct GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,return seek_data; } -void qmp_guest_file_flush (int64_t handle,Error **err) +void qmp_guest_file_flush (int64_t handle,Error **errp) { -GuestFileHandle *gfh =guest_file_handle_find (handle, err); +GuestFileHandle *gfh =guest_file_handle_find (handle, errp);FILE *fh;int ret;
@@ -556,7 +559,7 @@ void qmp_guest_file_flush(int64_t handle, Error **err) fh = gfh->fh; ret =fflush (fh);if (ret ==EOF ) { -error_setg_errno (err, errno,"failed to flush file" ); +error_setg_errno (errp, errno,"failed to flush file" ); } }
@@ -596,7 +599,7 @@ static void free_fs_mount_list(FsMountList *mounts)/* * Walk the mount table and build a list of local file systems */ -static void build_fs_mount_list (FsMountList *mounts,Error **err) +static void build_fs_mount_list (FsMountList *mounts,Error **errp) {struct mntent *ment;FsMount *mount;
@@ -605,7 +608,7 @@ static void build_fs_mount_list(FsMountList *mounts, Error **err) fp =setmntent (mtab,"r" );if (!fp) { -error_setg (err,"failed to open mtab file: '%s'" , mtab); +error_setg (errp,"failed to open mtab file: '%s'" , mtab);return ; }
@@ -645,7 +648,7 @@ const char *fsfreeze_hook_arg_string[] = { "freeze", }; -static void execute_fsfreeze_hook (FsfreezeHookArg arg,Error **err) +static void execute_fsfreeze_hook (FsfreezeHookArg arg,Error **errp) {int status;pid_t pid;
@@ -658,7 +661,7 @@ static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **err)return ; }if (access (hook,X_OK ) !=0 ) { -error_setg_errno (err, errno,"can't access fsfreeze hook '%s'" , hook); +error_setg_errno (errp, errno,"can't access fsfreeze hook '%s'" , hook);return ; }
@@ -673,24 +676,24 @@ static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **err)execle (hook, hook, arg_str,NULL , environ);_exit (EXIT_FAILURE ); }else if (pid <0 ) { -error_setg_errno (err, errno,"failed to create child process" ); +error_setg_errno (errp, errno,"failed to create child process" );return ; }ga_wait_child (pid, &status, &local_err);if (local_err) { -error_propagate (err, local_err); +error_propagate (errp, local_err);return ; }if (!WIFEXITED (status)) { -error_setg (err,"fsfreeze hook has terminated abnormally" ); +error_setg (errp,"fsfreeze hook has terminated abnormally" );return ; } status =WEXITSTATUS (status);if (status) { -error_setg (err,"fsfreeze hook has failed with status %d" , status); +error_setg (errp,"fsfreeze hook has failed with status %d" , status);return ; } }
@@ -698,7 +701,7 @@ static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **err)/* * Return status of freeze/thaw */ -GuestFsfreezeStatus qmp_guest_fsfreeze_status (Error **err) +GuestFsfreezeStatus qmp_guest_fsfreeze_status (Error **errp) {if (ga_is_frozen (ga_state)) {return GUEST_FSFREEZE_STATUS_FROZEN ;
@@ -711,7 +714,7 @@ GuestFsfreezeStatus qmp_guest_fsfreeze_status(Error **err)* Walk list of mounted file systems in the guest, and freeze the ones which * are real local file systems. */ -int64_t qmp_guest_fsfreeze_freeze (Error **err) +int64_t qmp_guest_fsfreeze_freeze (Error **errp) {int ret =0 , i =0 ;FsMountList mounts;
@@ -723,14 +726,14 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err)execute_fsfreeze_hook (FSFREEZE_HOOK_FREEZE , &local_err);if (local_err) { -error_propagate (err, local_err); +error_propagate (errp, local_err);return -1 ; }QTAILQ_INIT (&mounts);build_fs_mount_list (&mounts, &local_err);if (local_err) { -error_propagate (err, local_err); +error_propagate (errp, local_err);return -1 ; }
@@ -740,7 +743,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err) QTAILQ_FOREACH_REVERSE(mount, &mounts, FsMountList, next) { fd =qemu_open (mount->dirname,O_RDONLY );if (fd ==-1 ) { -error_setg_errno (err, errno,"failed to open %s" , mount->dirname); +error_setg_errno (errp, errno,"failed to open %s" , mount->dirname); goto error; }
@@ -756,7 +759,7 @@ int64_t qmp_guest_fsfreeze_freeze(Error **err) ret =ioctl (fd,FIFREEZE );if (ret ==-1 ) {if (errno !=EOPNOTSUPP ) { -error_setg_errno (err, errno,"failed to freeze %s" , +error_setg_errno (errp, errno,"failed to freeze %s" , mount->dirname);close (fd); goto error;
@@ -779,7 +782,7 @@ error:/* * Walk list of frozen file systems in the guest, and thaw them. */ -int64_t qmp_guest_fsfreeze_thaw (Error **err) +int64_t qmp_guest_fsfreeze_thaw (Error **errp) {int ret;FsMountList mounts;
@@ -790,7 +793,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)QTAILQ_INIT (&mounts);build_fs_mount_list (&mounts, &local_err);if (local_err) { -error_propagate (err, local_err); +error_propagate (errp, local_err);return 0 ; }
@@ -829,7 +832,7 @@ int64_t qmp_guest_fsfreeze_thaw(Error **err)ga_unset_frozen (ga_state);free_fs_mount_list (&mounts); -execute_fsfreeze_hook (FSFREEZE_HOOK_THAW , err); +execute_fsfreeze_hook (FSFREEZE_HOOK_THAW , errp);return i; }
@@ -853,7 +856,7 @@ static void guest_fsfreeze_cleanup(void)/* * Walk list of mounted file systems in the guest, and trim them. */ -void qmp_guest_fstrim (bool has_minimum,int64_t minimum,Error **err) +void qmp_guest_fstrim (bool has_minimum,int64_t minimum,Error **errp) {int ret =0 ;FsMountList mounts;
@@ -871,14 +874,14 @@ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err)QTAILQ_INIT (&mounts);build_fs_mount_list (&mounts, &local_err);if (local_err) { -error_propagate (err, local_err); +error_propagate (errp, local_err);return ; } QTAILQ_FOREACH(mount, &mounts, next) { fd =qemu_open (mount->dirname,O_RDONLY );if (fd ==-1 ) { -error_setg_errno (err, errno,"failed to open %s" , mount->dirname); +error_setg_errno (errp, errno,"failed to open %s" , mount->dirname); goto error; }
@@ -891,7 +894,7 @@ void qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **err) ret =ioctl (fd,FITRIM , &r);if (ret ==-1 ) {if (errno !=ENOTTY && errno !=EOPNOTSUPP ) { -error_setg_errno (err, errno,"failed to trim %s" , +error_setg_errno (errp, errno,"failed to trim %s" , mount->dirname);close (fd); goto error;
@@ -911,7 +914,7 @@ error:#define SUSPEND_NOT_SUPPORTED 1static void bios_supports_mode (const char *pmutils_bin,const char *pmutils_arg, -const char *sysfile_str,Error **err) +const char *sysfile_str,Error **errp) {Error *local_err =NULL ;char *pmutils_path;
@@ -961,18 +964,18 @@ static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg,_exit (SUSPEND_NOT_SUPPORTED ); }else if (pid <0 ) { -error_setg_errno (err, errno,"failed to create child process" ); +error_setg_errno (errp, errno,"failed to create child process" ); goto out; }ga_wait_child (pid, &status, &local_err);if (local_err) { -error_propagate (err, local_err); +error_propagate (errp, local_err); goto out; }if (!WIFEXITED (status)) { -error_setg (err,"child process has terminated abnormally" ); +error_setg (errp,"child process has terminated abnormally" ); goto out; }
@@ -980,11 +983,11 @@ static void bios_supports_mode(const char *pmutils_bin, const char *pmutils_arg,case SUSPEND_SUPPORTED : goto out;case SUSPEND_NOT_SUPPORTED : -error_setg (err, +error_setg (errp,"the requested suspend mode is not supported by the guest" ); goto out;default : -error_setg (err, +error_setg (errp,"the helper program '%s' returned an unexpected exit status" " code (%d)" , pmutils_path,WEXITSTATUS (status)); goto out;
@@ -995,7 +998,7 @@ out: }static void guest_suspend (const char *pmutils_bin,const char *sysfile_str, -Error **err) +Error **errp) {Error *local_err =NULL ;char *pmutils_path;
@@ -1038,23 +1041,23 @@ static void guest_suspend(const char *pmutils_bin, const char *sysfile_str,_exit (EXIT_SUCCESS ); }else if (pid <0 ) { -error_setg_errno (err, errno,"failed to create child process" ); +error_setg_errno (errp, errno,"failed to create child process" ); goto out; }ga_wait_child (pid, &status, &local_err);if (local_err) { -error_propagate (err, local_err); +error_propagate (errp, local_err); goto out; }if (!WIFEXITED (status)) { -error_setg (err,"child process has terminated abnormally" ); +error_setg (errp,"child process has terminated abnormally" ); goto out; }if (WEXITSTATUS (status)) { -error_setg (err,"child process has failed to suspend" ); +error_setg (errp,"child process has failed to suspend" ); goto out; }
@@ -1062,34 +1065,34 @@ out:g_free (pmutils_path); } -void qmp_guest_suspend_disk (Error **err) +void qmp_guest_suspend_disk (Error **errp) { -bios_supports_mode ("pm-is-supported" ,"--hibernate" ,"disk" , err); -if (error_is_set (err)) { +bios_supports_mode ("pm-is-supported" ,"--hibernate" ,"disk" , errp); +if (error_is_set (errp)) {return ; } -guest_suspend ("pm-hibernate" ,"disk" , err); +guest_suspend ("pm-hibernate" ,"disk" , errp); } -void qmp_guest_suspend_ram (Error **err) +void qmp_guest_suspend_ram (Error **errp) { -bios_supports_mode ("pm-is-supported" ,"--suspend" ,"mem" , err); -if (error_is_set (err)) { +bios_supports_mode ("pm-is-supported" ,"--suspend" ,"mem" , errp); +if (error_is_set (errp)) {return ; } -guest_suspend ("pm-suspend" ,"mem" , err); +guest_suspend ("pm-suspend" ,"mem" , errp); } -void qmp_guest_suspend_hybrid (Error **err) +void qmp_guest_suspend_hybrid (Error **errp) { -bios_supports_mode ("pm-is-supported" ,"--suspend-hybrid" ,NULL , err); -if (error_is_set (err)) { +bios_supports_mode ("pm-is-supported" ,"--suspend-hybrid" ,NULL , errp); +if (error_is_set (errp)) {return ; } -guest_suspend ("pm-suspend-hybrid" ,NULL , err); +guest_suspend ("pm-suspend-hybrid" ,NULL , errp); } static GuestNetworkInterfaceList *
@@ -1252,9 +1255,9 @@ error:return NULL ; } -#define SYSCONF_EXACT (name, err) sysconf_exact((name), #name, (err)) +#define SYSCONF_EXACT (name, errp) sysconf_exact((name), #name, (errp)) -static long sysconf_exact (int name,const char *name_str,Error **err) +static long sysconf_exact (int name,const char *name_str,Error **errp) {long ret;
@@ -1262,9 +1265,9 @@ static long sysconf_exact(int name, const char *name_str, Error **err) ret =sysconf (name);if (ret ==-1 ) {if (errno ==0 ) { -error_setg (err,"sysconf(%s): value indefinite" , name_str); +error_setg (errp,"sysconf(%s): value indefinite" , name_str); }else { -error_setg_errno (err, errno,"sysconf(%s)" , name_str); +error_setg_errno (errp, errno,"sysconf(%s)" , name_str); } }return ret;
@@ -1410,19 +1413,19 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)#else /* defined(__linux__) */ -void qmp_guest_suspend_disk (Error **err) +void qmp_guest_suspend_disk (Error **errp) { -error_set (err,QERR_UNSUPPORTED ); +error_set (errp,QERR_UNSUPPORTED ); } -void qmp_guest_suspend_ram (Error **err) +void qmp_guest_suspend_ram (Error **errp) { -error_set (err,QERR_UNSUPPORTED ); +error_set (errp,QERR_UNSUPPORTED ); } -void qmp_guest_suspend_hybrid (Error **err) +void qmp_guest_suspend_hybrid (Error **errp) { -error_set (err,QERR_UNSUPPORTED ); +error_set (errp,QERR_UNSUPPORTED ); }GuestNetworkInterfaceList *qmp_guest_network_get_interfaces (Error **errp)
@@ -1447,32 +1450,32 @@ int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp)#if !defined(CONFIG_FSFREEZE ) -GuestFsfreezeStatus qmp_guest_fsfreeze_status (Error **err) +GuestFsfreezeStatus qmp_guest_fsfreeze_status (Error **errp) { -error_set (err,QERR_UNSUPPORTED ); +error_set (errp,QERR_UNSUPPORTED );return 0 ; } -int64_t qmp_guest_fsfreeze_freeze (Error **err) +int64_t qmp_guest_fsfreeze_freeze (Error **errp) { -error_set (err,QERR_UNSUPPORTED ); +error_set (errp,QERR_UNSUPPORTED );return 0 ; } -int64_t qmp_guest_fsfreeze_thaw (Error **err) +int64_t qmp_guest_fsfreeze_thaw (Error **errp) { -error_set (err,QERR_UNSUPPORTED ); +error_set (errp,QERR_UNSUPPORTED );return 0 ; }#endif /* CONFIG_FSFREEZE */ #if !defined(CONFIG_FSTRIM ) -void qmp_guest_fstrim (bool has_minimum,int64_t minimum,Error **err) +void qmp_guest_fstrim (bool has_minimum,int64_t minimum,Error **errp) { -error_set (err,QERR_UNSUPPORTED ); +error_set (errp,QERR_UNSUPPORTED ); }#endif
qga/commands-win32.c +54 -51
268 lines not on this page · raw message
qga/commands.c +2 -2
@@ -40,7 +40,7 @@ int64_t qmp_guest_sync(int64_t id, Error **errp)return id; } -void qmp_guest_ping (Error **err) +void qmp_guest_ping (Error **errp) {slog ("guest-ping called" ); }
@@ -62,7 +62,7 @@ static void qmp_command_info(QmpCommand *cmd, void *opaque) info->supported_commands = cmd_info_list; } -struct GuestAgentInfo *qmp_guest_info (Error **err) +struct GuestAgentInfo *qmp_guest_info (Error **errp) {GuestAgentInfo *info =g_malloc0 (sizeof (GuestAgentInfo));
qga/vss-win32.c +2 -2
@@ -145,13 +145,13 @@ void ga_uninstall_vss_provider(void) }/* Call VSS requester and freeze/thaw filesystems and applications */ -void qga_vss_fsfreeze (int *nr_volume,Error **err,bool freeze) +void qga_vss_fsfreeze (int *nr_volume,Error **errp,bool freeze) {const char *func_name = freeze ?"requester_freeze" :"requester_thaw" ;QGAVSSRequesterFunc func;ErrorSet errset = { .error_set = (ErrorSetFunc )error_set_win32, - .errp = (void **)err, + .errp = (void **)errp, .err_class =ERROR_CLASS_GENERIC_ERROR };
qga/vss-win32.h +1 -1
@@ -22,6 +22,6 @@ bool vss_initialized(void);int ga_install_vss_provider (void );void ga_uninstall_vss_provider (void ); -void qga_vss_fsfreeze (int *nr_volume,Error **err,bool freeze); +void qga_vss_fsfreeze (int *nr_volume,Error **errp,bool freeze);#endif
Signature · 1 line
1.8.1.4
PATCH v3 3/14 qmp: Consistently name Error ** objects errp, and not err
In reply to Markus Armbruster--- qmp.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
qmp.c +8 -8
@@ -41,7 +41,7 @@ NameInfo *qmp_query_name(Error **errp)return info; } -VersionInfo *qmp_query_version (Error **err) +VersionInfo *qmp_query_version (Error **errp) {VersionInfo *info =g_malloc0 (sizeof (*info));const char *version =QEMU_VERSION ;
@@ -82,7 +82,7 @@ UuidInfo *qmp_query_uuid(Error **errp)return info; } -void qmp_quit (Error **err) +void qmp_quit (Error **errp) { no_shutdown =0 ;qemu_system_shutdown_request ();
@@ -153,10 +153,10 @@ static void iostatus_bdrv_it(void *opaque, BlockDriverState *bs)static void encrypted_bdrv_it (void *opaque,BlockDriverState *bs) { -Error **err = opaque; +Error **errp = opaque; -if (!error_is_set (err) &&bdrv_key_required (bs)) { -error_set (err,QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), +if (!error_is_set (errp) &&bdrv_key_required (bs)) { +error_set (errp,QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs),bdrv_get_encrypted_filename (bs)); } }
@@ -401,12 +401,12 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,#endif /* !CONFIG_VNC */ void qmp_change (const char *device,const char *target, -bool has_arg,const char *arg,Error **err) +bool has_arg,const char *arg,Error **errp) {if (strcmp (device,"vnc" ) ==0 ) { -qmp_change_vnc (target, has_arg, arg, err); +qmp_change_vnc (target, has_arg, arg, errp); }else { -qmp_change_blockdev (device, target, arg, err); +qmp_change_blockdev (device, target, arg, errp); } }
Signature · 1 line
1.8.1.4
PATCH v3 4/14 error: Consistently name Error ** objects errp, and not err
In reply to Markus Armbruster--- include/qapi/error.h | 27 ++++++++++++++++----------- util/error.c | 8 ++++---- 2 files changed, 20 insertions(+), 15 deletions(-)
include/qapi/error.h +16 -11
@@ -27,14 +27,16 @@ typedef struct Error Error;* printf-style human message. This function is not meant to be used outside * of QEMU. */ -void error_set(Error **err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(3, 4); +void error_set(Error **errp, ErrorClass err_class, const char *fmt, ...) + GCC_FMT_ATTR(3, 4);/** * Set an indirect pointer to an error given a ErrorClass value and a * printf-style human message, followed by a strerror() string if * @os_error is not zero. */ -void error_set_errno(Error **err, int os_error, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(4, 5); +void error_set_errno(Error **errp, int os_error, ErrorClass err_class, + const char *fmt, ...) GCC_FMT_ATTR(4, 5);#ifdef _WIN32/**
@@ -42,19 +44,22 @@ void error_set_errno(Error **err, int os_error, ErrorClass err_class, const char* printf-style human message, followed by a g_win32_error_message() string if * @win32_err is not zero. */ -void error_set_win32(Error **err, int win32_err, ErrorClass err_class, const char *fmt, ...) GCC_FMT_ATTR(4, 5); +void error_set_win32(Error **errp, int win32_err, ErrorClass err_class, + const char *fmt, ...) GCC_FMT_ATTR(4, 5);#endif /** * Same as error_set(), but sets a generic error */ -#define error_setg (err, fmt, ...) \ - error_set(err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__) -#define error_setg_errno (err, os_error, fmt, ...) \ - error_set_errno(err, os_error, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__) +#define error_setg (errp, fmt, ...) \ + error_set(errp, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__) +#define error_setg_errno (errp, os_error, fmt, ...) \ + error_set_errno(errp, os_error, ERROR_CLASS_GENERIC_ERROR, \ + fmt, ## __VA_ARGS__)#ifdef _WIN32 -#define error_setg_win32 (err, win32_err, fmt, ...) \ - error_set_win32(err, win32_err, ERROR_CLASS_GENERIC_ERROR, fmt, ## __VA_ARGS__) +#define error_setg_win32 (errp, win32_err, fmt, ...) \ + error_set_win32(errp, win32_err, ERROR_CLASS_GENERIC_ERROR, \ + fmt, ## __VA_ARGS__)#endif /**
@@ -66,7 +71,7 @@ void error_setg_file_open(Error **errp, int os_errno, const char *filename);* Returns true if an indirect pointer to an error is pointing to a valid * error object. */ -bool error_is_set (Error **err); +bool error_is_set (Error **errp);/* * Get the error class of an error object.
@@ -88,7 +93,7 @@ const char *error_get_pretty(Error *err);* always transfer ownership of the error reference and handles the case where * dst_err is NULL correctly. Errors after the first are discarded. */ -void error_propagate (Error **dst_err,Error *local_err); +void error_propagate (Error **dst_errp,Error *local_err);/** * Free an error object.
util/error.c +4 -4
@@ -165,13 +165,13 @@ void error_free(Error *err) } } -void error_propagate (Error **dst_err,Error *local_err) +void error_propagate (Error **dst_errp,Error *local_err) { -if (local_err && dst_err == &error_abort) { +if (local_err && dst_errp == &error_abort) {error_report ("%s" ,error_get_pretty (local_err));abort (); - }else if (dst_err && !*dst_err) { - *dst_err = local_err; + }else if (dst_errp && !*dst_errp) { + *dst_errp = local_err; }else if (local_err) {error_free (local_err); }
Signature · 1 line
1.8.1.4
PATCH v3 5/14 qga: Use return values instead of error_is_set(errp)
In reply to Markus ArmbrusterUsing error_is_set(errp) to check whether a function call failed is
fragile: it breaks when errp is null. ga_get_fd_handle() and guest_file_handle_add() don't return a useful value when they fail, but that's just stupid. Fix that, and check them instead. As far as I can tell, errp can't be null there, but this is more robust and more obviously correct.
--- qga/commands-posix.c | 6 +++--- qga/main.c | 1 + 2 files changed, 4 insertions(+), 3 deletions(-)
qga/commands-posix.c +3 -3
@@ -223,8 +223,8 @@ static int64_t guest_file_handle_add(FILE *fh, Error **errp)int64_t handle; handle =ga_get_fd_handle (ga_state, errp); -if (error_is_set (errp)) { -return 0 ; +if (handle <0 ) { +return -1 ; } gfh =g_malloc0 (sizeof (GuestFileHandle));
@@ -407,7 +407,7 @@ int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *mode, } handle =guest_file_handle_add (fh, errp); -if (error_is_set (errp)) { +if (handle <0 ) {fclose (fh);return -1 ; }
qga/main.c +1 -0
@@ -910,6 +910,7 @@ int64_t ga_get_fd_handle(GAState *s, Error **errp)if (!write_persistent_state (&s->pstate, s->pstate_filepath)) {error_setg (errp,"failed to commit persistent state to disk" ); +return -1 ; }return handle;
Signature · 1 line
1.8.1.4
PATCH v3 6/14 hmp: Guard against misuse of hmp_handle_error()
In reply to Markus ArmbrusterNull errp argument makes no sense. Assert it's not null, to make this explicit, and guard against misuse. All current callers pass non-null errp.
--- hmp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hmp.c +2 -1
@@ -28,7 +28,8 @@static void hmp_handle_error (Monitor *mon,Error **errp) { -if (error_is_set (errp)) { +assert (errp); +if (*errp) {monitor_printf (mon,"%s\n" ,error_get_pretty (*errp));error_free (*errp); }
Signature · 1 line
1.8.1.4
PATCH v3 7/14 qapi: Drop redundant, unclean error_is_set()
In reply to Markus Armbrusterdo_qmp_dispatch()'s test for qmp_dispatch_check_obj() failure examines both the return value and the error object. The latter part is unclean; it works only when do_qmp_dispatch()'s caller passes a non-null errp argument. That's the case, but it's not locally obvious. Unclean.
Cleanup would be easy enough, but since the unclean code is also redundant, let's just drop it.
--- qapi/qmp-dispatch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
qapi/qmp-dispatch.c +1 -2
@@ -67,9 +67,8 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp)QmpCommand *cmd;QObject *ret =NULL ; - dict =qmp_dispatch_check_obj (request, errp); -if (!dict ||error_is_set (errp)) { +if (!dict) {return NULL ; }
Signature · 1 line
1.8.1.4
PATCH v3 8/14 tests/qapi-schema: Drop superfluous error_is_set()
In reply to Markus Armbrustervisit_type_TestStruct() does nothing when called with an error set. Callers shouldn't do that, and no caller does. Drop the superfluous test.
--- tests/test-qmp-input-visitor.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
tests/test-qmp-input-visitor.c +12 -13
@@ -196,21 +196,20 @@ static void visit_type_TestStruct(Visitor *v, TestStruct **obj, const char *name, Error **errp) { Error *err = NULL; -if (!error_is_set (errp)) { -visit_start_struct (v, (void **)obj,"TestStruct" , name,sizeof (TestStruct), - &err); -if (!err) { -visit_type_int (v, &(*obj)->integer,"integer" , &err); -visit_type_bool (v, &(*obj)->boolean,"boolean" , &err); -visit_type_str (v, &(*obj)->string,"string" , &err); - -/* Always call end_struct if start_struct succeeded. */ -error_propagate (errp, err); - err =NULL ; -visit_end_struct (v, &err); - } + +visit_start_struct (v, (void **)obj,"TestStruct" , name,sizeof (TestStruct), + &err); +if (!err) { +visit_type_int (v, &(*obj)->integer,"integer" , &err); +visit_type_bool (v, &(*obj)->boolean,"boolean" , &err); +visit_type_str (v, &(*obj)->string,"string" , &err); + +/* Always call end_struct if start_struct succeeded. */ error_propagate (errp, err); + err =NULL ; +visit_end_struct (v, &err); } +error_propagate (errp, err); } static void test_visitor_in_struct(TestInputVisitorData *data,
Signature · 1 line
1.8.1.4
PATCH v3 9/14 qapi: Clean up fragile use of error_is_set()
In reply to Markus ArmbrusterUsing error_is_set(ERRP) to find out whether a function failed is either wrong, fragile, or unnecessarily opaque. It's wrong when ERRP may be null, because errors go undetected when it is. It's fragile when proving ERRP non-null involves a non-local argument. Else, it's unnecessarily opaque (see commit 84d18f0).
The error_is_set(errp) in do_qmp_dispatch() is merely fragile, because the caller never passes a null errp argument.
Make the code more robust and more obviously correct: receive the error in a local variable, then propagate it through the parameter.
--- qapi/qmp-dispatch.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
qapi/qmp-dispatch.c +8 -7
@@ -62,6 +62,7 @@ static QDict *qmp_dispatch_check_obj(const QObject *request, Error **errp)static QObject *do_qmp_dispatch (QObject *request,Error **errp) { +Error *local_err =NULL ;const char *command;QDict *args, *dict;QmpCommand *cmd;
@@ -93,13 +94,13 @@ static QObject *do_qmp_dispatch(QObject *request, Error **errp)switch (cmd->type) {case QCT_NORMAL : - cmd->fn (args, &ret, errp); -if (!error_is_set (errp)) { -if (cmd->options &QCO_NO_SUCCESS_RESP ) { -g_assert (!ret); - }else if (!ret) { - ret =QOBJECT (qdict_new ()); - } + cmd->fn (args, &ret, &local_err); +if (local_err) { +error_propagate (errp, local_err); + }else if (cmd->options &QCO_NO_SUCCESS_RESP ) { +g_assert (!ret); + }else if (!ret) { + ret =QOBJECT (qdict_new ()); }break ; }
Signature · 1 line
1.8.1.4
PATCH v3 10/14 qga: Clean up fragile use of error_is_set()
In reply to Markus ArmbrusterUsing error_is_set(ERRP) to find out whether a function failed is either wrong, fragile, or unnecessarily opaque. It's wrong when ERRP may be null, because errors go undetected when it is. It's fragile when proving ERRP non-null involves a non-local argument. Else, it's unnecessarily opaque (see commit 84d18f0).
The error_is_set(errp) in the guest agent command handler functions are merely fragile, because all chall chains (do_qmp_dispatch() via the generated marshalling functions) pass a non-null errp argument.
Make the code more robust and more obviously correct: receive the error in a local variable, then propagate it through the parameter.
--- qga/commands-posix.c | 22 ++++++++++++++++------ qga/commands-win32.c | 38 ++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 20 deletions(-)
qga/commands-posix.c +16 -6
@@ -1067,8 +1067,11 @@ out:void qmp_guest_suspend_disk (Error **errp) { -bios_supports_mode ("pm-is-supported" ,"--hibernate" ,"disk" , errp); -if (error_is_set (errp)) { +Error *local_err =NULL ; + +bios_supports_mode ("pm-is-supported" ,"--hibernate" ,"disk" , &local_err); +if (local_err) { +error_propagate (errp, local_err);return ; }
@@ -1077,8 +1080,11 @@ void qmp_guest_suspend_disk(Error **errp)void qmp_guest_suspend_ram (Error **errp) { -bios_supports_mode ("pm-is-supported" ,"--suspend" ,"mem" , errp); -if (error_is_set (errp)) { +Error *local_err =NULL ; + +bios_supports_mode ("pm-is-supported" ,"--suspend" ,"mem" , &local_err); +if (local_err) { +error_propagate (errp, local_err);return ; }
@@ -1087,8 +1093,12 @@ void qmp_guest_suspend_ram(Error **errp)void qmp_guest_suspend_hybrid (Error **errp) { -bios_supports_mode ("pm-is-supported" ,"--suspend-hybrid" ,NULL , errp); -if (error_is_set (errp)) { +Error *local_err =NULL ; + +bios_supports_mode ("pm-is-supported" ,"--suspend-hybrid" ,NULL , + &local_err); +if (local_err) { +error_propagate (errp, local_err);return ; }
qga/commands-win32.c +24 -14
@@ -87,6 +87,7 @@ static void execute_async(DWORD WINAPI (*func)(LPVOID), LPVOID opaque,void qmp_guest_shutdown (bool has_mode,const char *mode,Error **errp) { +Error *local_err =NULL ;UINT shutdown_flag =EWX_FORCE ;slog ("guest-shutdown called, mode: %s" , mode);
@@ -105,8 +106,9 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)/* Request a shutdown privilege, but try to shut down the system anyway. */ -acquire_privilege (SE_SHUTDOWN_NAME , errp); -if (error_is_set (errp)) { +acquire_privilege (SE_SHUTDOWN_NAME , &local_err); +if (local_err) { +error_propagate (errp, local_err);return ; }
@@ -191,14 +193,16 @@ int64_t qmp_guest_fsfreeze_freeze(Error **errp)/* cannot risk guest agent blocking itself on a write in this state */ ga_set_frozen (ga_state); -qga_vss_fsfreeze (&i, errp, true); -if (error_is_set (errp)) { +qga_vss_fsfreeze (&i, &local_err, true); +if (local_err) { +error_propagate (errp, local_err); goto error; }return i; error: + local_err =NULL ;qmp_guest_fsfreeze_thaw (&local_err);if (local_err) {g_debug ("cleanup thaw: %s" ,error_get_pretty (local_err));
@@ -313,28 +317,32 @@ static DWORD WINAPI do_suspend(LPVOID opaque)void qmp_guest_suspend_disk (Error **errp) { +Error *local_err =NULL ;GuestSuspendMode *mode =g_malloc (sizeof (GuestSuspendMode)); *mode =GUEST_SUSPEND_MODE_DISK ; -check_suspend_mode (*mode, errp); -acquire_privilege (SE_SHUTDOWN_NAME , errp); -execute_async (do_suspend, mode, errp); +check_suspend_mode (*mode, &local_err); +acquire_privilege (SE_SHUTDOWN_NAME , &local_err); +execute_async (do_suspend, mode, &local_err); -if (error_is_set (errp)) { +if (local_err) { +error_propagate (errp, local_err);g_free (mode); } }void qmp_guest_suspend_ram (Error **errp) { +Error *local_err =NULL ;GuestSuspendMode *mode =g_malloc (sizeof (GuestSuspendMode)); *mode =GUEST_SUSPEND_MODE_RAM ; -check_suspend_mode (*mode, errp); -acquire_privilege (SE_SHUTDOWN_NAME , errp); -execute_async (do_suspend, mode, errp); +check_suspend_mode (*mode, &local_err); +acquire_privilege (SE_SHUTDOWN_NAME , &local_err); +execute_async (do_suspend, mode, &local_err); -if (error_is_set (errp)) { +if (local_err) { +error_propagate (errp, local_err);g_free (mode); } }
@@ -375,6 +383,7 @@ int64_t qmp_guest_get_time(Error **errp)void qmp_guest_set_time (bool has_time,int64_t time_ns,Error **errp) { +Error *local_err =NULL ;SYSTEMTIME ts;FILETIME tf;LONGLONG time;
@@ -406,8 +415,9 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) } } -acquire_privilege (SE_SYSTEMTIME_NAME , errp); -if (error_is_set (errp)) { +acquire_privilege (SE_SYSTEMTIME_NAME , &local_err); +if (local_err) { +error_propagate (errp, local_err);return ; }
Signature · 1 line
1.8.1.4
PATCH v3 11/14 qga: Drop superfluous error_is_set()
In reply to Markus Armbrusteracquire_privilege(), execute_async() and check_suspend_mode() do nothing when called with an error set. Callers shouldn't do that, and no caller does. Drop the superfluous tests.
--- qga/commands-win32.c | 10 ---------- 1 file changed, 10 deletions(-)
qga/commands-win32.c +0 -10
@@ -35,10 +35,6 @@ static void acquire_privilege(const char *name, Error **errp)TOKEN_PRIVILEGES priv;Error *local_err =NULL ; -if (error_is_set (errp)) { -return ; - } -if (OpenProcessToken (GetCurrentProcess (),TOKEN_ADJUST_PRIVILEGES |TOKEN_QUERY , &token)) {
@@ -74,9 +70,6 @@ static void execute_async(DWORD WINAPI (*func)(LPVOID), LPVOID opaque, {Error *local_err =NULL ; -if (error_is_set (errp)) { -return ; - }HANDLE thread =CreateThread (NULL ,0 , func, opaque,0 ,NULL );if (!thread) { error_set(&local_err, QERR_QGA_COMMAND_FAILED,
@@ -268,9 +261,6 @@ static void check_suspend_mode(GuestSuspendMode mode, Error **errp)SYSTEM_POWER_CAPABILITIES sys_pwr_caps;Error *local_err =NULL ; -if (error_is_set (errp)) { -return ; - }ZeroMemory (&sys_pwr_caps,sizeof (sys_pwr_caps));if (!GetPwrCapabilities (&sys_pwr_caps)) { error_set(&local_err, QERR_QGA_COMMAND_FAILED,
Signature · 1 line
1.8.1.4
PATCH v3 12/14 qemu-option: Clean up fragile use of error_is_set()
In reply to Markus ArmbrusterUsing error_is_set(ERRP) to find out whether to bail out due to previous error is either wrong, fragile, or unnecessarily opaque. It's wrong when ERRP may be null, because errors go undetected when it is. It's fragile when proving ERRP non-null involves a non-local argument. Else, it's unnecessarily opaque (see commit 84d18f0).
The error_is_set(state->errp) in qemu_opts_from_qdict_1() is merely fragile, because the callers never pass state argument with null state->errp.
Make the code more robust and more obviously correct: test *state->errp directly.
--- util/qemu-option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/qemu-option.c +1 -1
@@ -1036,7 +1036,7 @@ static void qemu_opts_from_qdict_1(const char *key, QObject *obj, void *opaque)const char *value;int n; -if (!strcmp (key,"id" ) ||error_is_set (state->errp)) { +if (!strcmp (key,"id" ) || *state->errp) {return ; }
Signature · 1 line
1.8.1.4
PATCH v3 13/14 dump: Drop pointless error_is_set(), DumpState member errp
In reply to Markus ArmbrusterIn qmp_dump_guest_memory(), the error must be clear on entry, and we always bail out after setting it, directly or via dump_init(). Therefore, both error_is_set() are always false. Drop them.
DumpState member errp is now write-only. Drop it, too.
--- dump.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
dump.c +2 -4
@@ -86,7 +86,6 @@ typedef struct DumpState {bool has_filter;int64_t begin;int64_t length; -Error **errp;uint8_t *note_buf;/* buffer for notes */ size_t note_buf_offset;/* the writing place in note_buf */
@@ -1570,7 +1569,6 @@ static int dump_init(DumpState *s, int fd, bool has_format, nr_cpus++; } - s->errp = errp; s->fd = fd; s->has_filter = has_filter; s->begin = begin;
@@ -1780,11 +1778,11 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin, }if (has_format && format !=DUMP_GUEST_MEMORY_FORMAT_ELF ) { -if (create_kdump_vmcore (s) <0 && !error_is_set (s->errp)) { +if (create_kdump_vmcore (s) <0 ) {error_set (errp,QERR_IO_ERROR ); } }else { -if (create_vmcore (s) <0 && !error_is_set (s->errp)) { +if (create_vmcore (s) <0 ) {error_set (errp,QERR_IO_ERROR ); } }
Signature · 1 line
1.8.1.4
PATCH v3 14/14 qmp: Don't use error_is_set() to suppress additional errors
In reply to Markus ArmbrusterUsing error_is_set(errp) that way can sweep programming errors under the carpet when we get called incorrectly with an error set.
encrypted_bdrv_it() does it, because there's no way to make bdrv_iterate() break its loop. Actually safe, because qmp_cont() clears the error before the loop. Clean it up anyway: replace bdrv_iterate() by bdrv_next(), break the loop on error.
Replace both occurences, for consistency.
--- qmp.c | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-)
qmp.c +11 -21
@@ -146,24 +146,9 @@ SpiceInfo *qmp_query_spice(Error **errp) };#endif -static void iostatus_bdrv_it (void *opaque,BlockDriverState *bs) -{ -bdrv_iostatus_reset (bs); -} - -static void encrypted_bdrv_it (void *opaque,BlockDriverState *bs) -{ -Error **errp = opaque; - -if (!error_is_set (errp) &&bdrv_key_required (bs)) { -error_set (errp,QERR_DEVICE_ENCRYPTED ,bdrv_get_device_name (bs), -bdrv_get_encrypted_filename (bs)); - } -} -void qmp_cont (Error **errp) { -Error *local_err =NULL ; +BlockDriverState *bs;if (runstate_needs_reset ()) {error_setg (errp,"Resetting the Virtual Machine is required" );
@@ -172,11 +157,16 @@ void qmp_cont(Error **errp)return ; } -bdrv_iterate (iostatus_bdrv_it,NULL ); -bdrv_iterate (encrypted_bdrv_it, &local_err); -if (local_err) { -error_propagate (errp, local_err); -return ; +for (bs =bdrv_next (NULL ); bs; bs =bdrv_next (bs)) { +bdrv_iostatus_reset (bs); + } +for (bs =bdrv_next (NULL ); bs; bs =bdrv_next (bs)) { +if (bdrv_key_required (bs)) { +error_set (errp,QERR_DEVICE_ENCRYPTED , +bdrv_get_device_name (bs), +bdrv_get_encrypted_filename (bs)); +return ; + } }if (runstate_check (RUN_STATE_INMIGRATE )) {
Signature · 1 line
1.8.1.4
Re: [Qemu-devel] [PATCH v3 14/14] qmp: Don't use error_is_set() to suppress additional errors
Quoted 9 lines · Markus Armbruster
Using
error_is_set(errp)that way can sweep programming errors under the carpet when we get called incorrectly with an error set.
encrypted_bdrv_it()does it, because there's no way to makebdrv_iterate()break its loop. Actually safe, becauseqmp_cont()clears the error before the loop. Clean it up anyway: replacebdrv_iterate()bybdrv_next(), break the loop on error.Replace both occurences, for consistency.
s/occurences/occurrences/
Quoted 3 lines
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>
Fixing up the commit message typo is trivial and doesn't alter the positive review.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v3 14/14] qmp: Don't use error_is_set() to suppress additional errors
Quoted 11 lines · Eric Blake
Quoted 9 lines · Markus Armbruster
Using
error_is_set(errp)that way can sweep programming errors under the carpet when we get called incorrectly with an error set.
encrypted_bdrv_it()does it, because there's no way to makebdrv_iterate()break its loop. Actually safe, becauseqmp_cont()clears the error before the loop. Clean it up anyway: replacebdrv_iterate()bybdrv_next(), break the loop on error.Replace both occurences, for consistency.
Quoted 8 lines
s/occurences/occurrences/
Quoted 3 lines
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>Fixing up the commit message typo is trivial and doesn't alter the positive review.
Luiz, could you fix it up on commit, when you add Eric's R-by?
Re: [Qemu-devel] [PATCH v3 14/14] qmp: Don't use error_is_set() to suppress additional errors
Quoted 16 lines · On Wed, 07 May 2014 08:08:30 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 14 lines · Eric Blake
Quoted 9 lines · Markus Armbruster
Using
error_is_set(errp)that way can sweep programming errors under the carpet when we get called incorrectly with an error set.
encrypted_bdrv_it()does it, because there's no way to makebdrv_iterate()break its loop. Actually safe, becauseqmp_cont()clears the error before the loop. Clean it up anyway: replacebdrv_iterate()bybdrv_next(), break the loop on error.Replace both occurences, for consistency.
s/occurences/occurrences/
Quoted 1 line
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>Fixing up the commit message typo is trivial and doesn't alter the positive review.
Luiz, could you fix it up on commit, when you add Eric's R-by?
Fixed. But I didn't have to add his R-bys, you did it already.
Re: [Qemu-devel] [PATCH v3 14/14] qmp: Don't use error_is_set() to suppress additional errors
Quoted 22 lines · Luiz Capitulino
Quoted 19 lines · On Wed, 07 May 2014 08:08:30 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 17 lines · Eric Blake
Quoted 9 lines · Markus Armbruster
Using
error_is_set(errp)that way can sweep programming errors under the carpet when we get called incorrectly with an error set.
encrypted_bdrv_it()does it, because there's no way to makebdrv_iterate()break its loop. Actually safe, becauseqmp_cont()clears the error before the loop. Clean it up anyway: replacebdrv_iterate()bybdrv_next(), break the loop on error.Replace both occurences, for consistency.
s/occurences/occurrences/
Quoted 3 lines
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eric Blake <[email protected]>
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Fixing up the commit message typo is trivial and doesn't alter the positive review.
Luiz, could you fix it up on commit, when you add Eric's R-by?
Fixed. But I didn't have to add his R-bys, you did it already.
-EFRIEDBRAIN. Thanks!
Quoted 7 lines · Markus Armbruster
I got a private branch getting rid of it entirely. This is the fifth part, covering QMP and the guest agent up to the point where I start messing with the QAPI code generators. That's left for the final part.
Luiz agreed to take this through his tree.
Quoted 8 lines
This series conflicts with Lluís's "qapi: Allow modularization of QAPI schema files", but only in
docs/writing-qmp-commands.txt, and resolution is trivial.v3:
- PATCH 02/15 peformed two unwanted renames, 03/15 reverted them; drop all that. Since this effectively squashes 03 into 02, I took the liberty to retain Eric's R-by.
I double checked just to make sure; still looks good so I'm fine keeping R-by.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Luiz Capitulino
AppliedQuoted 10 lines · On Fri, 2 May 2014 13:26:28 +0200 Markus Armbruster <[email protected]> wrote:
I got a private branch getting rid of it entirely. This is the fifth part, covering QMP and the guest agent up to the point where I start messing with the QAPI code generators. That's left for the final part.
Luiz agreed to take this through his tree.
This series conflicts with Lluís's "qapi: Allow modularization of QAPI schema files", but only in
docs/writing-qmp-commands.txt, and resolution is trivial.
I didn't get any conflicts.
Have you looked at Laszlo series to make sure it follows your guidelines?
http://lists.nongnu.org/archive/html/qemu-devel/2014-04/msg01506.html
I've already applied his series to my tree, btw. Yours is on top.
Applied to the qmp branch, thanks.
Quoted 8 lines · Luiz Capitulino
Quoted 5 lines · On Fri, 2 May 2014 13:26:28 +0200 Markus Armbruster <[email protected]> wrote:
I got a private branch getting rid of it entirely. This is the fifth part, covering QMP and the guest agent up to the point where I start messing with the QAPI code generators. That's left for the final part.
Quoted 7 lines
Quoted 5 lines
Luiz agreed to take this through his tree.
This series conflicts with Lluís's "qapi: Allow modularization of QAPI schema files", but only in
docs/writing-qmp-commands.txt, and resolution is trivial.I didn't get any conflicts.
Even better :)
Quoted 3 lines
Have you looked at Laszlo series to make sure it follows your guidelines?
http://lists.nongnu.org/archive/html/qemu-devel/2014-04/msg01506.html
Looks fine to me at a glance: no new error_is_set(), all Error * and Error ** variables are nicely named.
Quoted 3 lines
I've already applied his series to my tree, btw. Yours is on top.
Applied to the qmp branch, thanks.
Thanks!