From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52010) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UliD1-0002R7-DW for qemu-devel@nongnu.org; Sun, 09 Jun 2013 12:11:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UliCz-0001x7-MV for qemu-devel@nongnu.org; Sun, 09 Jun 2013 12:11:11 -0400 Received: from cantor2.suse.de ([195.135.220.15]:39896 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UliCz-0001wp-Cv for qemu-devel@nongnu.org; Sun, 09 Jun 2013 12:11:09 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Sun, 9 Jun 2013 18:10:45 +0200 Message-Id: <1370794247-28267-17-git-send-email-afaerber@suse.de> In-Reply-To: <1370794247-28267-1-git-send-email-afaerber@suse.de> References: <1370794247-28267-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH qom-cpu v4 16/18] dump: Abstract write_elf{64, 32}_notes() with qemu_for_each_cpu() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qiaonuohan@cn.fujitsu.com, =?UTF-8?q?Andreas=20F=C3=A4rber?= , lcapitulino@redhat.com Removes the last use of CPUArchState. Signed-off-by: Andreas F=C3=A4rber --- dump.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++------------= ------ 1 file changed, 97 insertions(+), 36 deletions(-) diff --git a/dump.c b/dump.c index 4e6b855..d3cb8e2 100644 --- a/dump.c +++ b/dump.c @@ -273,29 +273,62 @@ static inline int cpu_index(CPUState *cpu) return cpu->cpu_index + 1; } =20 -static int write_elf64_notes(DumpState *s) -{ - CPUArchState *env; - CPUState *cpu; +typedef struct WriteELFNoteData { + DumpState *state; int ret; +} WriteELFNoteData; + +static void write_one_elf64_note(CPUState *cpu, void *data) +{ + WriteELFNoteData *d =3D data; int id; + int ret; =20 - for (env =3D first_cpu; env !=3D NULL; env =3D env->next_cpu) { - cpu =3D ENV_GET_CPU(env); - id =3D cpu_index(cpu); - ret =3D cpu_write_elf64_note(fd_write_vmcore, cpu, id, s); - if (ret < 0) { - dump_error(s, "dump: failed to write elf notes.\n"); - return -1; - } + if (d->ret !=3D 0) { + return; } =20 - for (env =3D first_cpu; env !=3D NULL; env =3D env->next_cpu) { - ret =3D cpu_write_elf64_qemunote(fd_write_vmcore, cpu, s); - if (ret < 0) { - dump_error(s, "dump: failed to write CPU status.\n"); - return -1; - } + id =3D cpu_index(cpu); + ret =3D cpu_write_elf64_note(fd_write_vmcore, cpu, id, d->state); + if (ret < 0) { + dump_error(d->state, "dump: failed to write elf notes.\n"); + d->ret =3D -1; + return; + } +} + +static void write_one_elf64_qemunote(CPUState *cpu, void *data) +{ + WriteELFNoteData *d =3D data; + int ret; + + if (d->ret !=3D 0) { + return; + } + + ret =3D cpu_write_elf64_qemunote(fd_write_vmcore, cpu, d->state); + if (ret < 0) { + dump_error(d->state, "dump: failed to write CPU status.\n"); + d->ret =3D -1; + return; + } +} + +static int write_elf64_notes(DumpState *s) +{ + WriteELFNoteData data =3D { + .state =3D s, + .ret =3D 0, + }; + + qemu_for_each_cpu(write_one_elf64_note, &data); + if (data.ret !=3D 0) { + return data.ret; + } + + qemu_for_each_cpu(write_one_elf64_qemunote, &data); + if (data.ret !=3D 0) { + return data.ret; } =20 return 0; @@ -325,29 +358,57 @@ static int write_elf32_note(DumpState *s) return 0; } =20 -static int write_elf32_notes(DumpState *s) +static void write_one_elf32_note(CPUState *cpu, void *data) { - CPUArchState *env; - CPUState *cpu; - int ret; + WriteELFNoteData *d =3D data; int id; + int ret; =20 - for (env =3D first_cpu; env !=3D NULL; env =3D env->next_cpu) { - cpu =3D ENV_GET_CPU(env); - id =3D cpu_index(cpu); - ret =3D cpu_write_elf32_note(fd_write_vmcore, cpu, id, s); - if (ret < 0) { - dump_error(s, "dump: failed to write elf notes.\n"); - return -1; - } + if (d->ret !=3D 0) { + return; } =20 - for (env =3D first_cpu; env !=3D NULL; env =3D env->next_cpu) { - ret =3D cpu_write_elf32_qemunote(fd_write_vmcore, cpu, s); - if (ret < 0) { - dump_error(s, "dump: failed to write CPU status.\n"); - return -1; - } + id =3D cpu_index(cpu); + ret =3D cpu_write_elf32_note(fd_write_vmcore, cpu, id, d->state); + if (ret < 0) { + dump_error(d->state, "dump: failed to write elf notes.\n"); + d->ret =3D -1; + return; + } +} + +static void write_one_elf32_qemunote(CPUState *cpu, void *data) +{ + WriteELFNoteData *d =3D data; + int ret; + + if (d->ret !=3D 0) { + return; + } + + ret =3D cpu_write_elf32_qemunote(fd_write_vmcore, cpu, d->state); + if (ret < 0) { + dump_error(d->state, "dump: failed to write CPU status.\n"); + d->ret =3D -1; + return; + } +} + +static int write_elf32_notes(DumpState *s) +{ + WriteELFNoteData data =3D { + .state =3D s, + .ret =3D 0, + }; + + qemu_for_each_cpu(write_one_elf32_note, &data); + if (data.ret !=3D 0) { + return data.ret; + } + + qemu_for_each_cpu(write_one_elf32_qemunote, &data); + if (data.ret !=3D 0) { + return data.ret; } =20 return 0; --=20 1.8.1.4