From nobody Mon Feb 9 02:51:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1570813482; cv=none; d=zoho.com; s=zohoarc; b=HqAjneaPAgQFInzHhzG4KAU9VV7SjziN/+BY4Rg3+rfm5NbD3gvWF1tAMEfJ+Gl2NYd6xf/3oWBjZYthu7Dq4J96ch1iGtLRCvVW88H0L845W2AfR+CPxVbPwTcYT7Gm/RvXICOOg0mNRUmvcF/3pS+JfSkierUaCvE3TQ1Iuxs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570813482; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DNUEp+Qg4GgmzVranKNDcMxt6d/hh+ckqaIhbsHHy5M=; b=Bh6/vmqTmo9SkIC3vutRRSFBu0GOFWWKTzuSgZHzCjThlXWaey42f4ERflluogW6UGvrZmUQcUjKKvGVZIHuz4xaeingOfTje1UloOY3SkB1sddqYfiuG1Aj82QyyCnavjaPAFWY0J9JuIKnblysRr5iBQiYm7v9Vw4ZkGWXcUI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1570813482489445.91266720690487; Fri, 11 Oct 2019 10:04:42 -0700 (PDT) Received: from localhost ([::1]:54326 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIyLJ-0008Vm-0T for importer@patchew.org; Fri, 11 Oct 2019 13:04:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36919) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iIxRA-0006fO-NF for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iIxR5-0004k6-Cd for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:40 -0400 Received: from relay.sw.ru ([185.231.240.75]:48388) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iIxR4-0004RB-Vf for qemu-devel@nongnu.org; Fri, 11 Oct 2019 12:06:35 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iIxQt-0003XG-Ho; Fri, 11 Oct 2019 19:06:23 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Subject: [RFC v5 081/126] qga: introduce ERRP_AUTO_PROPAGATE Date: Fri, 11 Oct 2019 19:05:07 +0300 Message-Id: <20191011160552.22907-82-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191011160552.22907-1-vsementsov@virtuozzo.com> References: <20191011160552.22907-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Michael Roth , vsementsov@virtuozzo.com, armbru@redhat.com, Greg Kurz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp =3D=3D &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases. If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are: 1. No need of explicit error_propagate call 2. No need of explicit local_err variable: use errp directly 3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit (together with its neighbors) was generated by for f in $(git grep -l errp \*.[ch]); do \ spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \ done; then fix a bit of compilation problems: coccinelle for some reason leaves several f() { ... goto out; ... out: } patterns, with "out:" at function end. then ./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)" (auto-msg was a file with this commit message) Still, for backporting it may be more comfortable to use only the first command and then do one huge commit. Reported-by: Kevin Wolf Reported-by: Greg Kurz Signed-off-by: Vladimir Sementsov-Ogievskiy --- qga/commands-posix.c | 220 +++++++++++++++++++------------------------ 1 file changed, 97 insertions(+), 123 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index 6dcd2d5db6..257eaaf0da 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -82,8 +82,8 @@ static void ga_wait_child(pid_t pid, int *status, Error *= *errp) =20 void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp) { + ERRP_AUTO_PROPAGATE(); const char *shutdown_flag; - Error *local_err =3D NULL; pid_t pid; int status; =20 @@ -116,9 +116,8 @@ void qmp_guest_shutdown(bool has_mode, const char *mode= , Error **errp) return; } =20 - ga_wait_child(pid, &status, &local_err); - if (local_err) { - error_propagate(errp, local_err); + ga_wait_child(pid, &status, errp); + if (*errp) { return; } =20 @@ -151,10 +150,10 @@ int64_t qmp_guest_get_time(Error **errp) =20 void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp) { + ERRP_AUTO_PROPAGATE(); int ret; int status; pid_t pid; - Error *local_err =3D NULL; struct timeval tv; =20 /* If user has passed a time, validate and set it. */ @@ -203,9 +202,8 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns,= Error **errp) return; } =20 - ga_wait_child(pid, &status, &local_err); - if (local_err) { - error_propagate(errp, local_err); + ga_wait_child(pid, &status, errp); + if (*errp) { return; } =20 @@ -328,11 +326,11 @@ find_open_flag(const char *mode_str, Error **errp) static FILE * safe_open_or_create(const char *path, const char *mode, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); int oflag; =20 - oflag =3D find_open_flag(mode, &local_err); - if (local_err =3D=3D NULL) { + oflag =3D find_open_flag(mode, errp); + if (*errp =3D=3D NULL) { int fd; =20 /* If the caller wants / allows creation of a new file, we impleme= nt it @@ -364,13 +362,13 @@ safe_open_or_create(const char *path, const char *mod= e, Error **errp) } =20 if (fd =3D=3D -1) { - error_setg_errno(&local_err, errno, "failed to open file '%s' " + error_setg_errno(errp, errno, "failed to open file '%s' " "(mode: '%s')", path, mode); } else { qemu_set_cloexec(fd); =20 if ((oflag & O_CREAT) && fchmod(fd, DEFAULT_NEW_FILE_MODE) =3D= =3D -1) { - error_setg_errno(&local_err, errno, "failed to set permiss= ion " + error_setg_errno(errp, errno, "failed to set permission " "0%03o on new file '%s' (mode: '%s')", (unsigned)DEFAULT_NEW_FILE_MODE, path, mo= de); } else { @@ -378,7 +376,7 @@ safe_open_or_create(const char *path, const char *mode,= Error **errp) =20 f =3D fdopen(fd, mode); if (f =3D=3D NULL) { - error_setg_errno(&local_err, errno, "failed to associa= te " + error_setg_errno(errp, errno, "failed to associate " "stdio stream with file descriptor %d= , " "file '%s' (mode: '%s')", fd, path, m= ode); } else { @@ -393,24 +391,22 @@ safe_open_or_create(const char *path, const char *mod= e, Error **errp) } } =20 - error_propagate(errp, local_err); return NULL; } =20 int64_t qmp_guest_file_open(const char *path, bool has_mode, const char *m= ode, Error **errp) { + ERRP_AUTO_PROPAGATE(); FILE *fh; - Error *local_err =3D NULL; int64_t handle; =20 if (!has_mode) { mode =3D "r"; } slog("guest-file-open called, filepath: %s, mode: %s", path, mode); - fh =3D safe_open_or_create(path, mode, &local_err); - if (local_err !=3D NULL) { - error_propagate(errp, local_err); + fh =3D safe_open_or_create(path, mode, errp); + if (*errp) { return -1; } =20 @@ -563,21 +559,20 @@ struct GuestFileSeek *qmp_guest_file_seek(int64_t han= dle, int64_t offset, GuestFileWhence *whence_code, Error **errp) { + ERRP_AUTO_PROPAGATE(); GuestFileHandle *gfh =3D guest_file_handle_find(handle, errp); GuestFileSeek *seek_data =3D NULL; FILE *fh; int ret; int whence; - Error *err =3D NULL; =20 if (!gfh) { return NULL; } =20 /* We stupidly exposed 'whence':'int' in our qapi */ - whence =3D ga_parse_whence(whence_code, &err); - if (err) { - error_propagate(errp, err); + whence =3D ga_parse_whence(whence_code, errp); + if (*errp) { return NULL; } =20 @@ -1150,15 +1145,14 @@ static GuestFilesystemInfo *build_guest_fsinfo(stru= ct FsMount *mount, =20 GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp) { + ERRP_AUTO_PROPAGATE(); FsMountList mounts; struct FsMount *mount; GuestFilesystemInfoList *new, *ret =3D NULL; - Error *local_err =3D NULL; =20 QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { - error_propagate(errp, local_err); + build_fs_mount_list(&mounts, errp); + if (*errp) { return NULL; } =20 @@ -1166,11 +1160,10 @@ GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error= **errp) g_debug("Building guest fsinfo for '%s'", mount->dirname); =20 new =3D g_malloc0(sizeof(*ret)); - new->value =3D build_guest_fsinfo(mount, &local_err); + new->value =3D build_guest_fsinfo(mount, errp); new->next =3D ret; ret =3D new; - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { qapi_free_GuestFilesystemInfoList(ret); ret =3D NULL; break; @@ -1194,11 +1187,11 @@ static const char *fsfreeze_hook_arg_string[] =3D { =20 static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **errp) { + ERRP_AUTO_PROPAGATE(); int status; pid_t pid; const char *hook; const char *arg_str =3D fsfreeze_hook_arg_string[arg]; - Error *local_err =3D NULL; =20 hook =3D ga_fsfreeze_hook(ga_state); if (!hook) { @@ -1224,9 +1217,8 @@ static void execute_fsfreeze_hook(FsfreezeHookArg arg= , Error **errp) return; } =20 - ga_wait_child(pid, &status, &local_err); - if (local_err) { - error_propagate(errp, local_err); + ga_wait_child(pid, &status, errp); + if (*errp) { return; } =20 @@ -1267,25 +1259,23 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mou= ntpoints, strList *mountpoints, Error **errp) { + ERRP_AUTO_PROPAGATE(); int ret =3D 0, i =3D 0; strList *list; FsMountList mounts; struct FsMount *mount; - Error *local_err =3D NULL; int fd; =20 slog("guest-fsfreeze called"); =20 - execute_fsfreeze_hook(FSFREEZE_HOOK_FREEZE, &local_err); - if (local_err) { - error_propagate(errp, local_err); + execute_fsfreeze_hook(FSFREEZE_HOOK_FREEZE, errp); + if (*errp) { return -1; } =20 QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { - error_propagate(errp, local_err); + build_fs_mount_list(&mounts, errp); + if (*errp) { return -1; } =20 @@ -1358,16 +1348,15 @@ error: */ int64_t qmp_guest_fsfreeze_thaw(Error **errp) { + ERRP_AUTO_PROPAGATE(); int ret; FsMountList mounts; FsMount *mount; int fd, i =3D 0, logged; - Error *local_err =3D NULL; =20 QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { - error_propagate(errp, local_err); + build_fs_mount_list(&mounts, errp); + if (*errp) { return 0; } =20 @@ -1433,6 +1422,7 @@ static void guest_fsfreeze_cleanup(void) GuestFilesystemTrimResponse * qmp_guest_fstrim(bool has_minimum, int64_t minimum, Error **errp) { + ERRP_AUTO_PROPAGATE(); GuestFilesystemTrimResponse *response; GuestFilesystemTrimResultList *list; GuestFilesystemTrimResult *result; @@ -1440,15 +1430,13 @@ qmp_guest_fstrim(bool has_minimum, int64_t minimum,= Error **errp) FsMountList mounts; struct FsMount *mount; int fd; - Error *local_err =3D NULL; struct fstrim_range r; =20 slog("guest-fstrim called"); =20 QTAILQ_INIT(&mounts); - build_fs_mount_list(&mounts, &local_err); - if (local_err) { - error_propagate(errp, local_err); + build_fs_mount_list(&mounts, errp); + if (*errp) { return NULL; } =20 @@ -1554,13 +1542,13 @@ static int run_process_child(const char *command[],= Error **errp) =20 static bool systemd_supports_mode(SuspendMode mode, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); const char *systemctl_args[3] =3D {"systemd-hibernate", "systemd-suspe= nd", "systemd-hybrid-sleep"}; const char *cmd[4] =3D {"systemctl", "status", systemctl_args[mode], N= ULL}; int status; =20 - status =3D run_process_child(cmd, &local_err); + status =3D run_process_child(cmd, errp); =20 /* * systemctl status uses LSB return codes so we can expect @@ -1574,31 +1562,29 @@ static bool systemd_supports_mode(SuspendMode mode,= Error **errp) return true; } =20 - error_propagate(errp, local_err); return false; } =20 static void systemd_suspend(SuspendMode mode, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); const char *systemctl_args[3] =3D {"hibernate", "suspend", "hybrid-sle= ep"}; const char *cmd[3] =3D {"systemctl", systemctl_args[mode], NULL}; int status; =20 - status =3D run_process_child(cmd, &local_err); + status =3D run_process_child(cmd, errp); =20 if (status =3D=3D 0) { return; } =20 - if ((status =3D=3D -1) && !local_err) { + if ((status =3D=3D -1) && !*errp) { error_setg(errp, "the helper program 'systemctl %s' was not found", systemctl_args[mode]); return; } =20 - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { } else { error_setg(errp, "the helper program 'systemctl %s' returned an " "unexpected exit status code (%d)", @@ -1608,24 +1594,23 @@ static void systemd_suspend(SuspendMode mode, Error= **errp) =20 static bool pmutils_supports_mode(SuspendMode mode, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); const char *pmutils_args[3] =3D {"--hibernate", "--suspend", "--suspend-hybrid"}; const char *cmd[3] =3D {"pm-is-supported", pmutils_args[mode], NULL}; int status; =20 - status =3D run_process_child(cmd, &local_err); + status =3D run_process_child(cmd, errp); =20 if (status =3D=3D SUSPEND_SUPPORTED) { return true; } =20 - if ((status =3D=3D -1) && !local_err) { + if ((status =3D=3D -1) && !*errp) { return false; } =20 - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { } else { error_setg(errp, "the helper program '%s' returned an unexpected exit" @@ -1637,26 +1622,25 @@ static bool pmutils_supports_mode(SuspendMode mode,= Error **errp) =20 static void pmutils_suspend(SuspendMode mode, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); const char *pmutils_binaries[3] =3D {"pm-hibernate", "pm-suspend", "pm-suspend-hybrid"}; const char *cmd[2] =3D {pmutils_binaries[mode], NULL}; int status; =20 - status =3D run_process_child(cmd, &local_err); + status =3D run_process_child(cmd, errp); =20 if (status =3D=3D 0) { return; } =20 - if ((status =3D=3D -1) && !local_err) { + if ((status =3D=3D -1) && !*errp) { error_setg(errp, "the helper program '%s' was not found", pmutils_binaries[mode]); return; } =20 - if (local_err) { - error_propagate(errp, local_err); + if (*errp) { } else { error_setg(errp, "the helper program '%s' returned an unexpected exit" @@ -1697,7 +1681,7 @@ static bool linux_sys_state_supports_mode(SuspendMode= mode, Error **errp) =20 static void linux_sys_state_suspend(SuspendMode mode, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); const char *sysfile_strs[3] =3D {"disk", "mem", NULL}; const char *sysfile_str =3D sysfile_strs[mode]; pid_t pid; @@ -1733,9 +1717,8 @@ static void linux_sys_state_suspend(SuspendMode mode,= Error **errp) return; } =20 - ga_wait_child(pid, &status, &local_err); - if (local_err) { - error_propagate(errp, local_err); + ga_wait_child(pid, &status, errp); + if (*errp) { return; } =20 @@ -1747,41 +1730,40 @@ static void linux_sys_state_suspend(SuspendMode mod= e, Error **errp) =20 static void guest_suspend(SuspendMode mode, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); bool mode_supported =3D false; =20 - if (systemd_supports_mode(mode, &local_err)) { + if (systemd_supports_mode(mode, errp)) { mode_supported =3D true; - systemd_suspend(mode, &local_err); + systemd_suspend(mode, errp); } =20 - if (!local_err) { + if (!*errp) { return; } =20 - error_free(local_err); + error_free_errp(errp); =20 - if (pmutils_supports_mode(mode, &local_err)) { + if (pmutils_supports_mode(mode, errp)) { mode_supported =3D true; - pmutils_suspend(mode, &local_err); + pmutils_suspend(mode, errp); } =20 - if (!local_err) { + if (!*errp) { return; } =20 - error_free(local_err); + error_free_errp(errp); =20 - if (linux_sys_state_supports_mode(mode, &local_err)) { + if (linux_sys_state_supports_mode(mode, errp)) { mode_supported =3D true; - linux_sys_state_suspend(mode, &local_err); + linux_sys_state_suspend(mode, errp); } =20 if (!mode_supported) { error_setg(errp, "the requested suspend mode is not supported by the gue= st"); } else { - error_propagate(errp, local_err); } } =20 @@ -2120,17 +2102,17 @@ static void transfer_vcpu(GuestLogicalProcessor *vc= pu, bool sys2vcpu, =20 GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp) { + ERRP_AUTO_PROPAGATE(); int64_t current; GuestLogicalProcessorList *head, **link; long sc_max; - Error *local_err =3D NULL; =20 current =3D 0; head =3D NULL; link =3D &head; - sc_max =3D SYSCONF_EXACT(_SC_NPROCESSORS_CONF, &local_err); + sc_max =3D SYSCONF_EXACT(_SC_NPROCESSORS_CONF, errp); =20 - while (local_err =3D=3D NULL && current < sc_max) { + while (*errp =3D=3D NULL && current < sc_max) { GuestLogicalProcessor *vcpu; GuestLogicalProcessorList *entry; int64_t id =3D current++; @@ -2141,7 +2123,7 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error = **errp) vcpu =3D g_malloc0(sizeof *vcpu); vcpu->logical_id =3D id; vcpu->has_can_offline =3D true; /* lolspeak ftw */ - transfer_vcpu(vcpu, true, path, &local_err); + transfer_vcpu(vcpu, true, path, errp); entry =3D g_malloc0(sizeof *entry); entry->value =3D vcpu; *link =3D entry; @@ -2150,41 +2132,39 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Erro= r **errp) g_free(path); } =20 - if (local_err =3D=3D NULL) { + if (*errp =3D=3D NULL) { /* there's no guest with zero VCPUs */ g_assert(head !=3D NULL); return head; } =20 qapi_free_GuestLogicalProcessorList(head); - error_propagate(errp, local_err); return NULL; } =20 int64_t qmp_guest_set_vcpus(GuestLogicalProcessorList *vcpus, Error **errp) { + ERRP_AUTO_PROPAGATE(); int64_t processed; - Error *local_err =3D NULL; =20 processed =3D 0; while (vcpus !=3D NULL) { char *path =3D g_strdup_printf("/sys/devices/system/cpu/cpu%" PRId= 64 "/", vcpus->value->logical_id); =20 - transfer_vcpu(vcpus->value, false, path, &local_err); + transfer_vcpu(vcpus->value, false, path, errp); g_free(path); - if (local_err !=3D NULL) { + if (*errp) { break; } ++processed; vcpus =3D vcpus->next; } =20 - if (local_err !=3D NULL) { + if (*errp) { if (processed =3D=3D 0) { - error_propagate(errp, local_err); } else { - error_free(local_err); + error_free_errp(errp); } } =20 @@ -2196,7 +2176,7 @@ void qmp_guest_set_user_password(const char *username, bool crypted, Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); char *passwd_path =3D NULL; pid_t pid; int status; @@ -2268,9 +2248,8 @@ void qmp_guest_set_user_password(const char *username, close(datafd[1]); datafd[1] =3D -1; =20 - ga_wait_child(pid, &status, &local_err); - if (local_err) { - error_propagate(errp, local_err); + ga_wait_child(pid, &status, errp); + if (*errp) { goto out; } =20 @@ -2356,10 +2335,10 @@ static void transfer_memory_block(GuestMemoryBlock = *mem_blk, bool sys2memblk, GuestMemoryBlockResponse *result, Error **errp) { + ERRP_AUTO_PROPAGATE(); char *dirpath; int dirfd; char *status; - Error *local_err =3D NULL; =20 if (!sys2memblk) { DIR *dp; @@ -2404,11 +2383,11 @@ static void transfer_memory_block(GuestMemoryBlock = *mem_blk, bool sys2memblk, g_free(dirpath); =20 status =3D g_malloc0(10); - ga_read_sysfs_file(dirfd, "state", status, 10, &local_err); - if (local_err) { + ga_read_sysfs_file(dirfd, "state", status, 10, errp); + if (*errp) { /* treat with sysfs file that not exist in old kernel */ if (errno =3D=3D ENOENT) { - error_free(local_err); + error_free_errp(errp); if (sys2memblk) { mem_blk->online =3D true; mem_blk->can_offline =3D false; @@ -2418,7 +2397,6 @@ static void transfer_memory_block(GuestMemoryBlock *m= em_blk, bool sys2memblk, } } else { if (sys2memblk) { - error_propagate(errp, local_err); } else { result->response =3D GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED; @@ -2432,14 +2410,13 @@ static void transfer_memory_block(GuestMemoryBlock = *mem_blk, bool sys2memblk, =20 mem_blk->online =3D (strncmp(status, "online", 6) =3D=3D 0); =20 - ga_read_sysfs_file(dirfd, "removable", &removable, 1, &local_err); - if (local_err) { + ga_read_sysfs_file(dirfd, "removable", &removable, 1, errp); + if (*errp) { /* if no 'removable' file, it doesn't support offline mem blk = */ if (errno =3D=3D ENOENT) { - error_free(local_err); + error_free_errp(errp); mem_blk->can_offline =3D false; } else { - error_propagate(errp, local_err); } } else { mem_blk->can_offline =3D (removable !=3D '0'); @@ -2449,9 +2426,9 @@ static void transfer_memory_block(GuestMemoryBlock *m= em_blk, bool sys2memblk, const char *new_state =3D mem_blk->online ? "online" : "offlin= e"; =20 ga_write_sysfs_file(dirfd, "state", new_state, strlen(new_stat= e), - &local_err); - if (local_err) { - error_free(local_err); + errp); + if (*errp) { + error_free_errp(errp); result->response =3D GUEST_MEMORY_BLOCK_RESPONSE_TYPE_OPERATION_FAILED; goto out2; @@ -2477,8 +2454,8 @@ out1: =20 GuestMemoryBlockList *qmp_guest_get_memory_blocks(Error **errp) { + ERRP_AUTO_PROPAGATE(); GuestMemoryBlockList *head, **link; - Error *local_err =3D NULL; struct dirent *de; DIR *dp; =20 @@ -2516,7 +2493,7 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Err= or **errp) /* The d_name is "memoryXXX", phys_index is block id, same as XXX= */ mem_blk->phys_index =3D strtoul(&de->d_name[6], NULL, 10); mem_blk->has_can_offline =3D true; /* lolspeak ftw */ - transfer_memory_block(mem_blk, true, NULL, &local_err); + transfer_memory_block(mem_blk, true, NULL, errp); =20 entry =3D g_malloc0(sizeof *entry); entry->value =3D mem_blk; @@ -2526,7 +2503,7 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(Err= or **errp) } =20 closedir(dp); - if (local_err =3D=3D NULL) { + if (*errp =3D=3D NULL) { /* there's no guest with zero memory blocks */ if (head =3D=3D NULL) { error_setg(errp, "guest reported zero memory blocks!"); @@ -2535,15 +2512,14 @@ GuestMemoryBlockList *qmp_guest_get_memory_blocks(E= rror **errp) } =20 qapi_free_GuestMemoryBlockList(head); - error_propagate(errp, local_err); return NULL; } =20 GuestMemoryBlockResponseList * qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem_blks, Error **errp) { + ERRP_AUTO_PROPAGATE(); GuestMemoryBlockResponseList *head, **link; - Error *local_err =3D NULL; =20 head =3D NULL; link =3D &head; @@ -2555,8 +2531,8 @@ qmp_guest_set_memory_blocks(GuestMemoryBlockList *mem= _blks, Error **errp) =20 result =3D g_malloc0(sizeof(*result)); result->phys_index =3D current_mem_blk->phys_index; - transfer_memory_block(current_mem_blk, false, result, &local_err); - if (local_err) { /* should never happen */ + transfer_memory_block(current_mem_blk, false, result, errp); + if (*errp) { /* should never happen */ goto err; } entry =3D g_malloc0(sizeof *entry); @@ -2570,13 +2546,12 @@ qmp_guest_set_memory_blocks(GuestMemoryBlockList *m= em_blks, Error **errp) return head; err: qapi_free_GuestMemoryBlockResponseList(head); - error_propagate(errp, local_err); return NULL; } =20 GuestMemoryBlockInfo *qmp_guest_get_memory_block_info(Error **errp) { - Error *local_err =3D NULL; + ERRP_AUTO_PROPAGATE(); char *dirpath; int dirfd; char *buf; @@ -2592,11 +2567,10 @@ GuestMemoryBlockInfo *qmp_guest_get_memory_block_in= fo(Error **errp) g_free(dirpath); =20 buf =3D g_malloc0(20); - ga_read_sysfs_file(dirfd, "block_size_bytes", buf, 20, &local_err); + ga_read_sysfs_file(dirfd, "block_size_bytes", buf, 20, errp); close(dirfd); - if (local_err) { + if (*errp) { g_free(buf); - error_propagate(errp, local_err); return NULL; } =20 --=20 2.21.0