qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/7] QMP queue
@ 2014-10-23 15:19 Luiz Capitulino
  2014-10-23 15:19 ` [Qemu-devel] [PULL 1/7] virtio-balloon: Tweak recent fix for integer overflow Luiz Capitulino
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Luiz Capitulino @ 2014-10-23 15:19 UTC (permalink / raw)
  To: peter.maydell; +Cc: qemu-devel

The following changes since commit e40830afa1cff3ffdc37bdfdd40d80860074636c:

  Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2014-10-22-tag' into staging (2014-10-22 21:42:33 +0100)

are available in the git repository at:


  git://repo.or.cz/qemu/qmp-unstable.git tags/for-upstream

for you to fetch changes up to e799157c766d96506214059d8b75712a3e615431:

  monitor: delete device_del_bus_completion (2014-10-23 09:04:05 -0400)

----------------------------------------------------------------
QMP patches

----------------------------------------------------------------
Luiz Capitulino (1):
      MAINTAINERS: add entry for qobject files

Markus Armbruster (1):
      virtio-balloon: Tweak recent fix for integer overflow

Zhu Guihua (3):
      qdev: add qdev_build_hotpluggable_device_list helper
      monitor: add del completion for peripheral device
      monitor: delete device_del_bus_completion

zhanghailiang (2):
      dump: Propagate errors into qmp_dump_guest_memory()
      dump: Turn some functions to void to make code cleaner

 MAINTAINERS                |   6 +
 dump.c                     | 383 +++++++++++++++++++++------------------------
 hw/core/qdev.c             |  13 ++
 hw/virtio/virtio-balloon.c |   2 +-
 include/hw/qdev-core.h     |   2 +
 monitor.c                  |  28 ++--
 6 files changed, 216 insertions(+), 218 deletions(-)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PULL 1/7] virtio-balloon: Tweak recent fix for integer overflow
  2014-10-23 15:19 [Qemu-devel] [PULL 0/7] QMP queue Luiz Capitulino
@ 2014-10-23 15:19 ` Luiz Capitulino
  2014-10-23 15:19 ` [Qemu-devel] [PULL 2/7] dump: Propagate errors into qmp_dump_guest_memory() Luiz Capitulino
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2014-10-23 15:19 UTC (permalink / raw)
  To: peter.maydell; +Cc: qemu-devel

From: Markus Armbruster <armbru@redhat.com>

Commit 1f9296b avoids "other kinds of overflow" by limiting the
polling interval to UINT_MAX.  The computations to protect are done in
64 bits.  This is indeed safe when unsigned is 32 bits, as it commonly
is.  It isn't when unsigned is 64 bits.  Purely theoretical; I'm not
aware of such a system.  Limit it to UINT32_MAX instead.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hw/virtio/virtio-balloon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
index b5cf7ca..7bfbb75 100644
--- a/hw/virtio/virtio-balloon.c
+++ b/hw/virtio/virtio-balloon.c
@@ -170,7 +170,7 @@ static void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v,
         return;
     }
 
-    if (value > UINT_MAX) {
+    if (value > UINT32_MAX) {
         error_setg(errp, "timer value is too big");
         return;
     }
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PULL 2/7] dump: Propagate errors into qmp_dump_guest_memory()
  2014-10-23 15:19 [Qemu-devel] [PULL 0/7] QMP queue Luiz Capitulino
  2014-10-23 15:19 ` [Qemu-devel] [PULL 1/7] virtio-balloon: Tweak recent fix for integer overflow Luiz Capitulino
@ 2014-10-23 15:19 ` Luiz Capitulino
  2014-10-23 15:19 ` [Qemu-devel] [PULL 3/7] dump: Turn some functions to void to make code cleaner Luiz Capitulino
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2014-10-23 15:19 UTC (permalink / raw)
  To: peter.maydell; +Cc: qemu-devel

From: zhanghailiang <zhang.zhanghailiang@huawei.com>

The code calls dump_error() on error, and even passes it a suitable
message.  However, the message is thrown away, and its callers pass
up only success/failure.  All qmp_dump_guest_memory() can do is set
a generic error.

Propagate the errors properly, so qmp_dump_guest_memory() can return
a more useful error.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 dump.c | 165 ++++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 82 insertions(+), 83 deletions(-)

diff --git a/dump.c b/dump.c
index 71d3e94..07d2300 100644
--- a/dump.c
+++ b/dump.c
@@ -81,9 +81,10 @@ static int dump_cleanup(DumpState *s)
     return 0;
 }
 
-static void dump_error(DumpState *s, const char *reason)
+static void dump_error(DumpState *s, const char *reason, Error **errp)
 {
     dump_cleanup(s);
+    error_setg(errp, "%s", reason);
 }
 
 static int fd_write_vmcore(const void *buf, size_t size, void *opaque)
@@ -99,7 +100,7 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque)
     return 0;
 }
 
-static int write_elf64_header(DumpState *s)
+static int write_elf64_header(DumpState *s, Error **errp)
 {
     Elf64_Ehdr elf_header;
     int ret;
@@ -126,14 +127,14 @@ static int write_elf64_header(DumpState *s)
 
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
     if (ret < 0) {
-        dump_error(s, "dump: failed to write elf header.\n");
+        dump_error(s, "dump: failed to write elf header", errp);
         return -1;
     }
 
     return 0;
 }
 
-static int write_elf32_header(DumpState *s)
+static int write_elf32_header(DumpState *s, Error **errp)
 {
     Elf32_Ehdr elf_header;
     int ret;
@@ -160,7 +161,7 @@ static int write_elf32_header(DumpState *s)
 
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
     if (ret < 0) {
-        dump_error(s, "dump: failed to write elf header.\n");
+        dump_error(s, "dump: failed to write elf header", errp);
         return -1;
     }
 
@@ -169,7 +170,7 @@ static int write_elf32_header(DumpState *s)
 
 static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
                             int phdr_index, hwaddr offset,
-                            hwaddr filesz)
+                            hwaddr filesz, Error **errp)
 {
     Elf64_Phdr phdr;
     int ret;
@@ -186,7 +187,7 @@ static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
 
     ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
     if (ret < 0) {
-        dump_error(s, "dump: failed to write program header table.\n");
+        dump_error(s, "dump: failed to write program header table", errp);
         return -1;
     }
 
@@ -195,7 +196,7 @@ static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
 
 static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
                             int phdr_index, hwaddr offset,
-                            hwaddr filesz)
+                            hwaddr filesz, Error **errp)
 {
     Elf32_Phdr phdr;
     int ret;
@@ -212,14 +213,14 @@ static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
 
     ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
     if (ret < 0) {
-        dump_error(s, "dump: failed to write program header table.\n");
+        dump_error(s, "dump: failed to write program header table", errp);
         return -1;
     }
 
     return 0;
 }
 
-static int write_elf64_note(DumpState *s)
+static int write_elf64_note(DumpState *s, Error **errp)
 {
     Elf64_Phdr phdr;
     hwaddr begin = s->memory_offset - s->note_size;
@@ -235,7 +236,7 @@ static int write_elf64_note(DumpState *s)
 
     ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
     if (ret < 0) {
-        dump_error(s, "dump: failed to write program header table.\n");
+        dump_error(s, "dump: failed to write program header table", errp);
         return -1;
     }
 
@@ -247,7 +248,8 @@ static inline int cpu_index(CPUState *cpu)
     return cpu->cpu_index + 1;
 }
 
-static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s)
+static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
+                             Error **errp)
 {
     CPUState *cpu;
     int ret;
@@ -257,7 +259,7 @@ static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s)
         id = cpu_index(cpu);
         ret = cpu_write_elf64_note(f, cpu, id, s);
         if (ret < 0) {
-            dump_error(s, "dump: failed to write elf notes.\n");
+            dump_error(s, "dump: failed to write elf notes", errp);
             return -1;
         }
     }
@@ -265,7 +267,7 @@ static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s)
     CPU_FOREACH(cpu) {
         ret = cpu_write_elf64_qemunote(f, cpu, s);
         if (ret < 0) {
-            dump_error(s, "dump: failed to write CPU status.\n");
+            dump_error(s, "dump: failed to write CPU status", errp);
             return -1;
         }
     }
@@ -273,7 +275,7 @@ static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s)
     return 0;
 }
 
-static int write_elf32_note(DumpState *s)
+static int write_elf32_note(DumpState *s, Error **errp)
 {
     hwaddr begin = s->memory_offset - s->note_size;
     Elf32_Phdr phdr;
@@ -289,14 +291,15 @@ static int write_elf32_note(DumpState *s)
 
     ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
     if (ret < 0) {
-        dump_error(s, "dump: failed to write program header table.\n");
+        dump_error(s, "dump: failed to write program header table", errp);
         return -1;
     }
 
     return 0;
 }
 
-static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s)
+static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
+                             Error **errp)
 {
     CPUState *cpu;
     int ret;
@@ -306,7 +309,7 @@ static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s)
         id = cpu_index(cpu);
         ret = cpu_write_elf32_note(f, cpu, id, s);
         if (ret < 0) {
-            dump_error(s, "dump: failed to write elf notes.\n");
+            dump_error(s, "dump: failed to write elf notes", errp);
             return -1;
         }
     }
@@ -314,7 +317,7 @@ static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s)
     CPU_FOREACH(cpu) {
         ret = cpu_write_elf32_qemunote(f, cpu, s);
         if (ret < 0) {
-            dump_error(s, "dump: failed to write CPU status.\n");
+            dump_error(s, "dump: failed to write CPU status", errp);
             return -1;
         }
     }
@@ -322,7 +325,7 @@ static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s)
     return 0;
 }
 
-static int write_elf_section(DumpState *s, int type)
+static int write_elf_section(DumpState *s, int type, Error **errp)
 {
     Elf32_Shdr shdr32;
     Elf64_Shdr shdr64;
@@ -344,20 +347,20 @@ static int write_elf_section(DumpState *s, int type)
 
     ret = fd_write_vmcore(&shdr, shdr_size, s);
     if (ret < 0) {
-        dump_error(s, "dump: failed to write section header table.\n");
+        dump_error(s, "dump: failed to write section header table", errp);
         return -1;
     }
 
     return 0;
 }
 
-static int write_data(DumpState *s, void *buf, int length)
+static int write_data(DumpState *s, void *buf, int length, Error **errp)
 {
     int ret;
 
     ret = fd_write_vmcore(buf, length, s);
     if (ret < 0) {
-        dump_error(s, "dump: failed to save memory.\n");
+        dump_error(s, "dump: failed to save memory", errp);
         return -1;
     }
 
@@ -366,14 +369,14 @@ static int write_data(DumpState *s, void *buf, int length)
 
 /* write the memroy to vmcore. 1 page per I/O. */
 static int write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
-                        int64_t size)
+                        int64_t size, Error **errp)
 {
     int64_t i;
     int ret;
 
     for (i = 0; i < size / TARGET_PAGE_SIZE; i++) {
         ret = write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
-                         TARGET_PAGE_SIZE);
+                         TARGET_PAGE_SIZE, errp);
         if (ret < 0) {
             return ret;
         }
@@ -381,7 +384,7 @@ static int write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
 
     if ((size % TARGET_PAGE_SIZE) != 0) {
         ret = write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
-                         size % TARGET_PAGE_SIZE);
+                         size % TARGET_PAGE_SIZE, errp);
         if (ret < 0) {
             return ret;
         }
@@ -452,7 +455,7 @@ static void get_offset_range(hwaddr phys_addr,
     }
 }
 
-static int write_elf_loads(DumpState *s)
+static int write_elf_loads(DumpState *s, Error **errp)
 {
     hwaddr offset, filesz;
     MemoryMapping *memory_mapping;
@@ -472,10 +475,10 @@ static int write_elf_loads(DumpState *s)
                          s, &offset, &filesz);
         if (s->dump_info.d_class == ELFCLASS64) {
             ret = write_elf64_load(s, memory_mapping, phdr_index++, offset,
-                                   filesz);
+                                   filesz, errp);
         } else {
             ret = write_elf32_load(s, memory_mapping, phdr_index++, offset,
-                                   filesz);
+                                   filesz, errp);
         }
 
         if (ret < 0) {
@@ -491,7 +494,7 @@ static int write_elf_loads(DumpState *s)
 }
 
 /* write elf header, PT_NOTE and elf note to vmcore. */
-static int dump_begin(DumpState *s)
+static int dump_begin(DumpState *s, Error **errp)
 {
     int ret;
 
@@ -521,9 +524,9 @@ static int dump_begin(DumpState *s)
 
     /* write elf header to vmcore */
     if (s->dump_info.d_class == ELFCLASS64) {
-        ret = write_elf64_header(s);
+        ret = write_elf64_header(s, errp);
     } else {
-        ret = write_elf32_header(s);
+        ret = write_elf32_header(s, errp);
     }
     if (ret < 0) {
         return -1;
@@ -531,47 +534,47 @@ static int dump_begin(DumpState *s)
 
     if (s->dump_info.d_class == ELFCLASS64) {
         /* write PT_NOTE to vmcore */
-        if (write_elf64_note(s) < 0) {
+        if (write_elf64_note(s, errp) < 0) {
             return -1;
         }
 
         /* write all PT_LOAD to vmcore */
-        if (write_elf_loads(s) < 0) {
+        if (write_elf_loads(s, errp) < 0) {
             return -1;
         }
 
         /* write section to vmcore */
         if (s->have_section) {
-            if (write_elf_section(s, 1) < 0) {
+            if (write_elf_section(s, 1, errp) < 0) {
                 return -1;
             }
         }
 
         /* write notes to vmcore */
-        if (write_elf64_notes(fd_write_vmcore, s) < 0) {
+        if (write_elf64_notes(fd_write_vmcore, s, errp) < 0) {
             return -1;
         }
 
     } else {
         /* write PT_NOTE to vmcore */
-        if (write_elf32_note(s) < 0) {
+        if (write_elf32_note(s, errp) < 0) {
             return -1;
         }
 
         /* write all PT_LOAD to vmcore */
-        if (write_elf_loads(s) < 0) {
+        if (write_elf_loads(s, errp) < 0) {
             return -1;
         }
 
         /* write section to vmcore */
         if (s->have_section) {
-            if (write_elf_section(s, 0) < 0) {
+            if (write_elf_section(s, 0, errp) < 0) {
                 return -1;
             }
         }
 
         /* write notes to vmcore */
-        if (write_elf32_notes(fd_write_vmcore, s) < 0) {
+        if (write_elf32_notes(fd_write_vmcore, s, errp) < 0) {
             return -1;
         }
     }
@@ -614,7 +617,7 @@ static int get_next_block(DumpState *s, GuestPhysBlock *block)
 }
 
 /* write all memory to vmcore */
-static int dump_iterate(DumpState *s)
+static int dump_iterate(DumpState *s, Error **errp)
 {
     GuestPhysBlock *block;
     int64_t size;
@@ -630,7 +633,7 @@ static int dump_iterate(DumpState *s)
                 size -= block->target_end - (s->begin + s->length);
             }
         }
-        ret = write_memory(s, block, s->start, size);
+        ret = write_memory(s, block, s->start, size, errp);
         if (ret == -1) {
             return ret;
         }
@@ -643,16 +646,16 @@ static int dump_iterate(DumpState *s)
     }
 }
 
-static int create_vmcore(DumpState *s)
+static int create_vmcore(DumpState *s, Error **errp)
 {
     int ret;
 
-    ret = dump_begin(s);
+    ret = dump_begin(s, errp);
     if (ret < 0) {
         return -1;
     }
 
-    ret = dump_iterate(s);
+    ret = dump_iterate(s, errp);
     if (ret < 0) {
         return -1;
     }
@@ -738,7 +741,7 @@ static int buf_write_note(const void *buf, size_t size, void *opaque)
 }
 
 /* write common header, sub header and elf note to vmcore */
-static int create_header32(DumpState *s)
+static int create_header32(DumpState *s, Error **errp)
 {
     int ret = 0;
     DiskDumpHeader32 *dh = NULL;
@@ -784,7 +787,7 @@ static int create_header32(DumpState *s)
     dh->status = cpu_to_dump32(s, status);
 
     if (write_buffer(s->fd, 0, dh, size) < 0) {
-        dump_error(s, "dump: failed to write disk dump header.\n");
+        dump_error(s, "dump: failed to write disk dump header", errp);
         ret = -1;
         goto out;
     }
@@ -804,7 +807,7 @@ static int create_header32(DumpState *s)
 
     if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *
                      block_size, kh, size) < 0) {
-        dump_error(s, "dump: failed to write kdump sub header.\n");
+        dump_error(s, "dump: failed to write kdump sub header", errp);
         ret = -1;
         goto out;
     }
@@ -814,14 +817,14 @@ static int create_header32(DumpState *s)
     s->note_buf_offset = 0;
 
     /* use s->note_buf to store notes temporarily */
-    if (write_elf32_notes(buf_write_note, s) < 0) {
+    if (write_elf32_notes(buf_write_note, s, errp) < 0) {
         ret = -1;
         goto out;
     }
 
     if (write_buffer(s->fd, offset_note, s->note_buf,
                      s->note_size) < 0) {
-        dump_error(s, "dump: failed to write notes");
+        dump_error(s, "dump: failed to write notes", errp);
         ret = -1;
         goto out;
     }
@@ -843,7 +846,7 @@ out:
 }
 
 /* write common header, sub header and elf note to vmcore */
-static int create_header64(DumpState *s)
+static int create_header64(DumpState *s, Error **errp)
 {
     int ret = 0;
     DiskDumpHeader64 *dh = NULL;
@@ -889,7 +892,7 @@ static int create_header64(DumpState *s)
     dh->status = cpu_to_dump32(s, status);
 
     if (write_buffer(s->fd, 0, dh, size) < 0) {
-        dump_error(s, "dump: failed to write disk dump header.\n");
+        dump_error(s, "dump: failed to write disk dump header", errp);
         ret = -1;
         goto out;
     }
@@ -909,7 +912,7 @@ static int create_header64(DumpState *s)
 
     if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *
                      block_size, kh, size) < 0) {
-        dump_error(s, "dump: failed to write kdump sub header.\n");
+        dump_error(s, "dump: failed to write kdump sub header", errp);
         ret = -1;
         goto out;
     }
@@ -919,14 +922,14 @@ static int create_header64(DumpState *s)
     s->note_buf_offset = 0;
 
     /* use s->note_buf to store notes temporarily */
-    if (write_elf64_notes(buf_write_note, s) < 0) {
+    if (write_elf64_notes(buf_write_note, s, errp) < 0) {
         ret = -1;
         goto out;
     }
 
     if (write_buffer(s->fd, offset_note, s->note_buf,
                      s->note_size) < 0) {
-        dump_error(s, "dump: failed to write notes");
+        dump_error(s, "dump: failed to write notes", errp);
         ret = -1;
         goto out;
     }
@@ -947,12 +950,12 @@ out:
     return ret;
 }
 
-static int write_dump_header(DumpState *s)
+static int write_dump_header(DumpState *s, Error **errp)
 {
     if (s->dump_info.d_class == ELFCLASS32) {
-        return create_header32(s);
+        return create_header32(s, errp);
     } else {
-        return create_header64(s);
+        return create_header64(s, errp);
     }
 }
 
@@ -1066,7 +1069,7 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
     return true;
 }
 
-static int write_dump_bitmap(DumpState *s)
+static int write_dump_bitmap(DumpState *s, Error **errp)
 {
     int ret = 0;
     uint64_t last_pfn, pfn;
@@ -1087,7 +1090,7 @@ static int write_dump_bitmap(DumpState *s)
     while (get_next_page(&block_iter, &pfn, NULL, s)) {
         ret = set_dump_bitmap(last_pfn, pfn, true, dump_bitmap_buf, s);
         if (ret < 0) {
-            dump_error(s, "dump: failed to set dump_bitmap.\n");
+            dump_error(s, "dump: failed to set dump_bitmap", errp);
             ret = -1;
             goto out;
         }
@@ -1105,7 +1108,7 @@ static int write_dump_bitmap(DumpState *s)
         ret = set_dump_bitmap(last_pfn, last_pfn + PFN_BUFBITMAP, false,
                               dump_bitmap_buf, s);
         if (ret < 0) {
-            dump_error(s, "dump: failed to sync dump_bitmap.\n");
+            dump_error(s, "dump: failed to sync dump_bitmap", errp);
             ret = -1;
             goto out;
         }
@@ -1197,7 +1200,7 @@ static inline bool is_zero_page(const uint8_t *buf, size_t page_size)
     return buffer_is_zero(buf, page_size);
 }
 
-static int write_dump_pages(DumpState *s)
+static int write_dump_pages(DumpState *s, Error **errp)
 {
     int ret = 0;
     DataCache page_desc, page_data;
@@ -1241,7 +1244,7 @@ static int write_dump_pages(DumpState *s)
     ret = write_cache(&page_data, buf, TARGET_PAGE_SIZE, false);
     g_free(buf);
     if (ret < 0) {
-        dump_error(s, "dump: failed to write page data(zero page).\n");
+        dump_error(s, "dump: failed to write page data (zero page)", errp);
         goto out;
     }
 
@@ -1257,7 +1260,7 @@ static int write_dump_pages(DumpState *s)
             ret = write_cache(&page_desc, &pd_zero, sizeof(PageDescriptor),
                               false);
             if (ret < 0) {
-                dump_error(s, "dump: failed to write page desc.\n");
+                dump_error(s, "dump: failed to write page desc", errp);
                 goto out;
             }
         } else {
@@ -1282,7 +1285,7 @@ static int write_dump_pages(DumpState *s)
 
                 ret = write_cache(&page_data, buf_out, size_out, false);
                 if (ret < 0) {
-                    dump_error(s, "dump: failed to write page data.\n");
+                    dump_error(s, "dump: failed to write page data", errp);
                     goto out;
                 }
 #ifdef CONFIG_LZO
@@ -1295,7 +1298,7 @@ static int write_dump_pages(DumpState *s)
 
                 ret = write_cache(&page_data, buf_out, size_out, false);
                 if (ret < 0) {
-                    dump_error(s, "dump: failed to write page data.\n");
+                    dump_error(s, "dump: failed to write page data", errp);
                     goto out;
                 }
 #endif
@@ -1309,7 +1312,7 @@ static int write_dump_pages(DumpState *s)
 
                 ret = write_cache(&page_data, buf_out, size_out, false);
                 if (ret < 0) {
-                    dump_error(s, "dump: failed to write page data.\n");
+                    dump_error(s, "dump: failed to write page data", errp);
                     goto out;
                 }
 #endif
@@ -1324,7 +1327,7 @@ static int write_dump_pages(DumpState *s)
 
                 ret = write_cache(&page_data, buf, TARGET_PAGE_SIZE, false);
                 if (ret < 0) {
-                    dump_error(s, "dump: failed to write page data.\n");
+                    dump_error(s, "dump: failed to write page data", errp);
                     goto out;
                 }
             }
@@ -1336,7 +1339,7 @@ static int write_dump_pages(DumpState *s)
 
             ret = write_cache(&page_desc, &pd, sizeof(PageDescriptor), false);
             if (ret < 0) {
-                dump_error(s, "dump: failed to write page desc.\n");
+                dump_error(s, "dump: failed to write page desc", errp);
                 goto out;
             }
         }
@@ -1344,12 +1347,12 @@ static int write_dump_pages(DumpState *s)
 
     ret = write_cache(&page_desc, NULL, 0, true);
     if (ret < 0) {
-        dump_error(s, "dump: failed to sync cache for page_desc.\n");
+        dump_error(s, "dump: failed to sync cache for page_desc", errp);
         goto out;
     }
     ret = write_cache(&page_data, NULL, 0, true);
     if (ret < 0) {
-        dump_error(s, "dump: failed to sync cache for page_data.\n");
+        dump_error(s, "dump: failed to sync cache for page_data", errp);
         goto out;
     }
 
@@ -1366,7 +1369,7 @@ out:
     return ret;
 }
 
-static int create_kdump_vmcore(DumpState *s)
+static int create_kdump_vmcore(DumpState *s, Error **errp)
 {
     int ret;
 
@@ -1394,28 +1397,28 @@ static int create_kdump_vmcore(DumpState *s)
 
     ret = write_start_flat_header(s->fd);
     if (ret < 0) {
-        dump_error(s, "dump: failed to write start flat header.\n");
+        dump_error(s, "dump: failed to write start flat header", errp);
         return -1;
     }
 
-    ret = write_dump_header(s);
+    ret = write_dump_header(s, errp);
     if (ret < 0) {
         return -1;
     }
 
-    ret = write_dump_bitmap(s);
+    ret = write_dump_bitmap(s, errp);
     if (ret < 0) {
         return -1;
     }
 
-    ret = write_dump_pages(s);
+    ret = write_dump_pages(s, errp);
     if (ret < 0) {
         return -1;
     }
 
     ret = write_end_flat_header(s->fd);
     if (ret < 0) {
-        dump_error(s, "dump: failed to write end flat header.\n");
+        dump_error(s, "dump: failed to write end flat header", errp);
         return -1;
     }
 
@@ -1699,13 +1702,9 @@ 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_set(errp, QERR_IO_ERROR);
-        }
+        create_kdump_vmcore(s, errp);
     } else {
-        if (create_vmcore(s) < 0) {
-            error_set(errp, QERR_IO_ERROR);
-        }
+        create_vmcore(s, errp);
     }
 
     g_free(s);
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PULL 3/7] dump: Turn some functions to void to make code cleaner
  2014-10-23 15:19 [Qemu-devel] [PULL 0/7] QMP queue Luiz Capitulino
  2014-10-23 15:19 ` [Qemu-devel] [PULL 1/7] virtio-balloon: Tweak recent fix for integer overflow Luiz Capitulino
  2014-10-23 15:19 ` [Qemu-devel] [PULL 2/7] dump: Propagate errors into qmp_dump_guest_memory() Luiz Capitulino
@ 2014-10-23 15:19 ` Luiz Capitulino
  2014-10-23 15:19 ` [Qemu-devel] [PULL 4/7] MAINTAINERS: add entry for qobject files Luiz Capitulino
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2014-10-23 15:19 UTC (permalink / raw)
  To: peter.maydell; +Cc: qemu-devel

From: zhanghailiang <zhang.zhanghailiang@huawei.com>

Functions shouldn't return an error code and an Error object at the same time.
Turn all these functions that returning Error object to void.
We also judge if a function success or fail by reference to the local_err.

Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 dump.c | 312 ++++++++++++++++++++++++++++++-----------------------------------
 1 file changed, 142 insertions(+), 170 deletions(-)

diff --git a/dump.c b/dump.c
index 07d2300..06a4915 100644
--- a/dump.c
+++ b/dump.c
@@ -100,7 +100,7 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque)
     return 0;
 }
 
-static int write_elf64_header(DumpState *s, Error **errp)
+static void write_elf64_header(DumpState *s, Error **errp)
 {
     Elf64_Ehdr elf_header;
     int ret;
@@ -128,13 +128,10 @@ static int write_elf64_header(DumpState *s, Error **errp)
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
     if (ret < 0) {
         dump_error(s, "dump: failed to write elf header", errp);
-        return -1;
     }
-
-    return 0;
 }
 
-static int write_elf32_header(DumpState *s, Error **errp)
+static void write_elf32_header(DumpState *s, Error **errp)
 {
     Elf32_Ehdr elf_header;
     int ret;
@@ -162,15 +159,12 @@ static int write_elf32_header(DumpState *s, Error **errp)
     ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
     if (ret < 0) {
         dump_error(s, "dump: failed to write elf header", errp);
-        return -1;
     }
-
-    return 0;
 }
 
-static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
-                            int phdr_index, hwaddr offset,
-                            hwaddr filesz, Error **errp)
+static void write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
+                             int phdr_index, hwaddr offset,
+                             hwaddr filesz, Error **errp)
 {
     Elf64_Phdr phdr;
     int ret;
@@ -188,15 +182,12 @@ static int write_elf64_load(DumpState *s, MemoryMapping *memory_mapping,
     ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
     if (ret < 0) {
         dump_error(s, "dump: failed to write program header table", errp);
-        return -1;
     }
-
-    return 0;
 }
 
-static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
-                            int phdr_index, hwaddr offset,
-                            hwaddr filesz, Error **errp)
+static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
+                             int phdr_index, hwaddr offset,
+                             hwaddr filesz, Error **errp)
 {
     Elf32_Phdr phdr;
     int ret;
@@ -214,13 +205,10 @@ static int write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
     ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
     if (ret < 0) {
         dump_error(s, "dump: failed to write program header table", errp);
-        return -1;
     }
-
-    return 0;
 }
 
-static int write_elf64_note(DumpState *s, Error **errp)
+static void write_elf64_note(DumpState *s, Error **errp)
 {
     Elf64_Phdr phdr;
     hwaddr begin = s->memory_offset - s->note_size;
@@ -237,10 +225,7 @@ static int write_elf64_note(DumpState *s, Error **errp)
     ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
     if (ret < 0) {
         dump_error(s, "dump: failed to write program header table", errp);
-        return -1;
     }
-
-    return 0;
 }
 
 static inline int cpu_index(CPUState *cpu)
@@ -248,8 +233,8 @@ static inline int cpu_index(CPUState *cpu)
     return cpu->cpu_index + 1;
 }
 
-static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
-                             Error **errp)
+static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
+                              Error **errp)
 {
     CPUState *cpu;
     int ret;
@@ -260,7 +245,7 @@ static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
         ret = cpu_write_elf64_note(f, cpu, id, s);
         if (ret < 0) {
             dump_error(s, "dump: failed to write elf notes", errp);
-            return -1;
+            return;
         }
     }
 
@@ -268,14 +253,12 @@ static int write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
         ret = cpu_write_elf64_qemunote(f, cpu, s);
         if (ret < 0) {
             dump_error(s, "dump: failed to write CPU status", errp);
-            return -1;
+            return;
         }
     }
-
-    return 0;
 }
 
-static int write_elf32_note(DumpState *s, Error **errp)
+static void write_elf32_note(DumpState *s, Error **errp)
 {
     hwaddr begin = s->memory_offset - s->note_size;
     Elf32_Phdr phdr;
@@ -292,14 +275,11 @@ static int write_elf32_note(DumpState *s, Error **errp)
     ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
     if (ret < 0) {
         dump_error(s, "dump: failed to write program header table", errp);
-        return -1;
     }
-
-    return 0;
 }
 
-static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
-                             Error **errp)
+static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
+                              Error **errp)
 {
     CPUState *cpu;
     int ret;
@@ -310,7 +290,7 @@ static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
         ret = cpu_write_elf32_note(f, cpu, id, s);
         if (ret < 0) {
             dump_error(s, "dump: failed to write elf notes", errp);
-            return -1;
+            return;
         }
     }
 
@@ -318,14 +298,12 @@ static int write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
         ret = cpu_write_elf32_qemunote(f, cpu, s);
         if (ret < 0) {
             dump_error(s, "dump: failed to write CPU status", errp);
-            return -1;
+            return;
         }
     }
-
-    return 0;
 }
 
-static int write_elf_section(DumpState *s, int type, Error **errp)
+static void write_elf_section(DumpState *s, int type, Error **errp)
 {
     Elf32_Shdr shdr32;
     Elf64_Shdr shdr64;
@@ -348,49 +326,43 @@ static int write_elf_section(DumpState *s, int type, Error **errp)
     ret = fd_write_vmcore(&shdr, shdr_size, s);
     if (ret < 0) {
         dump_error(s, "dump: failed to write section header table", errp);
-        return -1;
     }
-
-    return 0;
 }
 
-static int write_data(DumpState *s, void *buf, int length, Error **errp)
+static void write_data(DumpState *s, void *buf, int length, Error **errp)
 {
     int ret;
 
     ret = fd_write_vmcore(buf, length, s);
     if (ret < 0) {
         dump_error(s, "dump: failed to save memory", errp);
-        return -1;
     }
-
-    return 0;
 }
 
-/* write the memroy to vmcore. 1 page per I/O. */
-static int write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
-                        int64_t size, Error **errp)
+/* write the memory to vmcore. 1 page per I/O. */
+static void write_memory(DumpState *s, GuestPhysBlock *block, ram_addr_t start,
+                         int64_t size, Error **errp)
 {
     int64_t i;
-    int ret;
+    Error *local_err = NULL;
 
     for (i = 0; i < size / TARGET_PAGE_SIZE; i++) {
-        ret = write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
-                         TARGET_PAGE_SIZE, errp);
-        if (ret < 0) {
-            return ret;
+        write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
+                   TARGET_PAGE_SIZE, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
     }
 
     if ((size % TARGET_PAGE_SIZE) != 0) {
-        ret = write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
-                         size % TARGET_PAGE_SIZE, errp);
-        if (ret < 0) {
-            return ret;
+        write_data(s, block->host_addr + start + i * TARGET_PAGE_SIZE,
+                   size % TARGET_PAGE_SIZE, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
     }
-
-    return 0;
 }
 
 /* get the memory's offset and size in the vmcore */
@@ -455,13 +427,13 @@ static void get_offset_range(hwaddr phys_addr,
     }
 }
 
-static int write_elf_loads(DumpState *s, Error **errp)
+static void write_elf_loads(DumpState *s, Error **errp)
 {
     hwaddr offset, filesz;
     MemoryMapping *memory_mapping;
     uint32_t phdr_index = 1;
-    int ret;
     uint32_t max_index;
+    Error *local_err = NULL;
 
     if (s->have_section) {
         max_index = s->sh_info;
@@ -474,29 +446,28 @@ static int write_elf_loads(DumpState *s, Error **errp)
                          memory_mapping->length,
                          s, &offset, &filesz);
         if (s->dump_info.d_class == ELFCLASS64) {
-            ret = write_elf64_load(s, memory_mapping, phdr_index++, offset,
-                                   filesz, errp);
+            write_elf64_load(s, memory_mapping, phdr_index++, offset,
+                             filesz, &local_err);
         } else {
-            ret = write_elf32_load(s, memory_mapping, phdr_index++, offset,
-                                   filesz, errp);
+            write_elf32_load(s, memory_mapping, phdr_index++, offset,
+                             filesz, &local_err);
         }
 
-        if (ret < 0) {
-            return -1;
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
 
         if (phdr_index >= max_index) {
             break;
         }
     }
-
-    return 0;
 }
 
 /* write elf header, PT_NOTE and elf note to vmcore. */
-static int dump_begin(DumpState *s, Error **errp)
+static void dump_begin(DumpState *s, Error **errp)
 {
-    int ret;
+    Error *local_err = NULL;
 
     /*
      * the vmcore's format is:
@@ -524,69 +495,81 @@ static int dump_begin(DumpState *s, Error **errp)
 
     /* write elf header to vmcore */
     if (s->dump_info.d_class == ELFCLASS64) {
-        ret = write_elf64_header(s, errp);
+        write_elf64_header(s, &local_err);
     } else {
-        ret = write_elf32_header(s, errp);
+        write_elf32_header(s, &local_err);
     }
-    if (ret < 0) {
-        return -1;
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
     }
 
     if (s->dump_info.d_class == ELFCLASS64) {
         /* write PT_NOTE to vmcore */
-        if (write_elf64_note(s, errp) < 0) {
-            return -1;
+        write_elf64_note(s, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
 
         /* write all PT_LOAD to vmcore */
-        if (write_elf_loads(s, errp) < 0) {
-            return -1;
+        write_elf_loads(s, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
 
         /* write section to vmcore */
         if (s->have_section) {
-            if (write_elf_section(s, 1, errp) < 0) {
-                return -1;
+            write_elf_section(s, 1, &local_err);
+            if (local_err) {
+                error_propagate(errp, local_err);
+                return;
             }
         }
 
         /* write notes to vmcore */
-        if (write_elf64_notes(fd_write_vmcore, s, errp) < 0) {
-            return -1;
+        write_elf64_notes(fd_write_vmcore, s, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
-
     } else {
         /* write PT_NOTE to vmcore */
-        if (write_elf32_note(s, errp) < 0) {
-            return -1;
+        write_elf32_note(s, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
 
         /* write all PT_LOAD to vmcore */
-        if (write_elf_loads(s, errp) < 0) {
-            return -1;
+        write_elf_loads(s, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
 
         /* write section to vmcore */
         if (s->have_section) {
-            if (write_elf_section(s, 0, errp) < 0) {
-                return -1;
+            write_elf_section(s, 0, &local_err);
+            if (local_err) {
+                error_propagate(errp, local_err);
+                return;
             }
         }
 
         /* write notes to vmcore */
-        if (write_elf32_notes(fd_write_vmcore, s, errp) < 0) {
-            return -1;
+        write_elf32_notes(fd_write_vmcore, s, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
     }
-
-    return 0;
 }
 
-/* write PT_LOAD to vmcore */
-static int dump_completed(DumpState *s)
+static void dump_completed(DumpState *s)
 {
     dump_cleanup(s);
-    return 0;
 }
 
 static int get_next_block(DumpState *s, GuestPhysBlock *block)
@@ -617,11 +600,12 @@ static int get_next_block(DumpState *s, GuestPhysBlock *block)
 }
 
 /* write all memory to vmcore */
-static int dump_iterate(DumpState *s, Error **errp)
+static void dump_iterate(DumpState *s, Error **errp)
 {
     GuestPhysBlock *block;
     int64_t size;
     int ret;
+    Error *local_err = NULL;
 
     while (1) {
         block = s->next_block;
@@ -633,34 +617,30 @@ static int dump_iterate(DumpState *s, Error **errp)
                 size -= block->target_end - (s->begin + s->length);
             }
         }
-        ret = write_memory(s, block, s->start, size, errp);
-        if (ret == -1) {
-            return ret;
+        write_memory(s, block, s->start, size, &local_err);
+        if (local_err) {
+            error_propagate(errp, local_err);
+            return;
         }
 
         ret = get_next_block(s, block);
         if (ret == 1) {
             dump_completed(s);
-            return 0;
         }
     }
 }
 
-static int create_vmcore(DumpState *s, Error **errp)
+static void create_vmcore(DumpState *s, Error **errp)
 {
-    int ret;
+    Error *local_err = NULL;
 
-    ret = dump_begin(s, errp);
-    if (ret < 0) {
-        return -1;
-    }
-
-    ret = dump_iterate(s, errp);
-    if (ret < 0) {
-        return -1;
+    dump_begin(s, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
     }
 
-    return 0;
+    dump_iterate(s, errp);
 }
 
 static int write_start_flat_header(int fd)
@@ -741,9 +721,8 @@ static int buf_write_note(const void *buf, size_t size, void *opaque)
 }
 
 /* write common header, sub header and elf note to vmcore */
-static int create_header32(DumpState *s, Error **errp)
+static void create_header32(DumpState *s, Error **errp)
 {
-    int ret = 0;
     DiskDumpHeader32 *dh = NULL;
     KdumpSubHeader32 *kh = NULL;
     size_t size;
@@ -752,6 +731,7 @@ static int create_header32(DumpState *s, Error **errp)
     uint32_t bitmap_blocks;
     uint32_t status = 0;
     uint64_t offset_note;
+    Error *local_err = NULL;
 
     /* write common header, the version of kdump-compressed format is 6th */
     size = sizeof(DiskDumpHeader32);
@@ -788,7 +768,6 @@ static int create_header32(DumpState *s, Error **errp)
 
     if (write_buffer(s->fd, 0, dh, size) < 0) {
         dump_error(s, "dump: failed to write disk dump header", errp);
-        ret = -1;
         goto out;
     }
 
@@ -808,7 +787,6 @@ static int create_header32(DumpState *s, Error **errp)
     if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *
                      block_size, kh, size) < 0) {
         dump_error(s, "dump: failed to write kdump sub header", errp);
-        ret = -1;
         goto out;
     }
 
@@ -817,15 +795,14 @@ static int create_header32(DumpState *s, Error **errp)
     s->note_buf_offset = 0;
 
     /* use s->note_buf to store notes temporarily */
-    if (write_elf32_notes(buf_write_note, s, errp) < 0) {
-        ret = -1;
+    write_elf32_notes(buf_write_note, s, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
         goto out;
     }
-
     if (write_buffer(s->fd, offset_note, s->note_buf,
                      s->note_size) < 0) {
         dump_error(s, "dump: failed to write notes", errp);
-        ret = -1;
         goto out;
     }
 
@@ -841,14 +818,11 @@ out:
     g_free(dh);
     g_free(kh);
     g_free(s->note_buf);
-
-    return ret;
 }
 
 /* write common header, sub header and elf note to vmcore */
-static int create_header64(DumpState *s, Error **errp)
+static void create_header64(DumpState *s, Error **errp)
 {
-    int ret = 0;
     DiskDumpHeader64 *dh = NULL;
     KdumpSubHeader64 *kh = NULL;
     size_t size;
@@ -857,6 +831,7 @@ static int create_header64(DumpState *s, Error **errp)
     uint32_t bitmap_blocks;
     uint32_t status = 0;
     uint64_t offset_note;
+    Error *local_err = NULL;
 
     /* write common header, the version of kdump-compressed format is 6th */
     size = sizeof(DiskDumpHeader64);
@@ -893,7 +868,6 @@ static int create_header64(DumpState *s, Error **errp)
 
     if (write_buffer(s->fd, 0, dh, size) < 0) {
         dump_error(s, "dump: failed to write disk dump header", errp);
-        ret = -1;
         goto out;
     }
 
@@ -913,7 +887,6 @@ static int create_header64(DumpState *s, Error **errp)
     if (write_buffer(s->fd, DISKDUMP_HEADER_BLOCKS *
                      block_size, kh, size) < 0) {
         dump_error(s, "dump: failed to write kdump sub header", errp);
-        ret = -1;
         goto out;
     }
 
@@ -922,15 +895,15 @@ static int create_header64(DumpState *s, Error **errp)
     s->note_buf_offset = 0;
 
     /* use s->note_buf to store notes temporarily */
-    if (write_elf64_notes(buf_write_note, s, errp) < 0) {
-        ret = -1;
+    write_elf64_notes(buf_write_note, s, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
         goto out;
     }
 
     if (write_buffer(s->fd, offset_note, s->note_buf,
                      s->note_size) < 0) {
         dump_error(s, "dump: failed to write notes", errp);
-        ret = -1;
         goto out;
     }
 
@@ -946,16 +919,19 @@ out:
     g_free(dh);
     g_free(kh);
     g_free(s->note_buf);
-
-    return ret;
 }
 
-static int write_dump_header(DumpState *s, Error **errp)
+static void write_dump_header(DumpState *s, Error **errp)
 {
+     Error *local_err = NULL;
+
     if (s->dump_info.d_class == ELFCLASS32) {
-        return create_header32(s, errp);
+        create_header32(s, &local_err);
     } else {
-        return create_header64(s, errp);
+        create_header64(s, &local_err);
+    }
+    if (local_err) {
+        error_propagate(errp, local_err);
     }
 }
 
@@ -1069,7 +1045,7 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
     return true;
 }
 
-static int write_dump_bitmap(DumpState *s, Error **errp)
+static void write_dump_bitmap(DumpState *s, Error **errp)
 {
     int ret = 0;
     uint64_t last_pfn, pfn;
@@ -1091,7 +1067,6 @@ static int write_dump_bitmap(DumpState *s, Error **errp)
         ret = set_dump_bitmap(last_pfn, pfn, true, dump_bitmap_buf, s);
         if (ret < 0) {
             dump_error(s, "dump: failed to set dump_bitmap", errp);
-            ret = -1;
             goto out;
         }
 
@@ -1109,7 +1084,6 @@ static int write_dump_bitmap(DumpState *s, Error **errp)
                               dump_bitmap_buf, s);
         if (ret < 0) {
             dump_error(s, "dump: failed to sync dump_bitmap", errp);
-            ret = -1;
             goto out;
         }
     }
@@ -1119,8 +1093,6 @@ static int write_dump_bitmap(DumpState *s, Error **errp)
 
 out:
     g_free(dump_bitmap_buf);
-
-    return ret;
 }
 
 static void prepare_data_cache(DataCache *data_cache, DumpState *s,
@@ -1200,7 +1172,7 @@ static inline bool is_zero_page(const uint8_t *buf, size_t page_size)
     return buffer_is_zero(buf, page_size);
 }
 
-static int write_dump_pages(DumpState *s, Error **errp)
+static void write_dump_pages(DumpState *s, Error **errp)
 {
     int ret = 0;
     DataCache page_desc, page_data;
@@ -1365,13 +1337,12 @@ out:
 #endif
 
     g_free(buf_out);
-
-    return ret;
 }
 
-static int create_kdump_vmcore(DumpState *s, Error **errp)
+static void create_kdump_vmcore(DumpState *s, Error **errp)
 {
     int ret;
+    Error *local_err = NULL;
 
     /*
      * the kdump-compressed format is:
@@ -1398,33 +1369,34 @@ static int create_kdump_vmcore(DumpState *s, Error **errp)
     ret = write_start_flat_header(s->fd);
     if (ret < 0) {
         dump_error(s, "dump: failed to write start flat header", errp);
-        return -1;
+        return;
     }
 
-    ret = write_dump_header(s, errp);
-    if (ret < 0) {
-        return -1;
+    write_dump_header(s, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
     }
 
-    ret = write_dump_bitmap(s, errp);
-    if (ret < 0) {
-        return -1;
+    write_dump_bitmap(s, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
     }
 
-    ret = write_dump_pages(s, errp);
-    if (ret < 0) {
-        return -1;
+    write_dump_pages(s, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
     }
 
     ret = write_end_flat_header(s->fd);
     if (ret < 0) {
         dump_error(s, "dump: failed to write end flat header", errp);
-        return -1;
+        return;
     }
 
     dump_completed(s);
-
-    return 0;
 }
 
 static ram_addr_t get_start_block(DumpState *s)
@@ -1463,9 +1435,9 @@ static void get_max_mapnr(DumpState *s)
     s->max_mapnr = paddr_to_pfn(last_block->target_end);
 }
 
-static int dump_init(DumpState *s, int fd, bool has_format,
-                     DumpGuestMemoryFormat format, bool paging, bool has_filter,
-                     int64_t begin, int64_t length, Error **errp)
+static void dump_init(DumpState *s, int fd, bool has_format,
+                      DumpGuestMemoryFormat format, bool paging, bool has_filter,
+                      int64_t begin, int64_t length, Error **errp)
 {
     CPUState *cpu;
     int nr_cpus;
@@ -1570,7 +1542,7 @@ static int dump_init(DumpState *s, int fd, bool has_format,
             s->flag_compress = 0;
         }
 
-        return 0;
+        return;
     }
 
     if (s->has_filter) {
@@ -1619,11 +1591,10 @@ static int dump_init(DumpState *s, int fd, bool has_format,
         }
     }
 
-    return 0;
+    return;
 
 cleanup:
     dump_cleanup(s);
-    return -1;
 }
 
 void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
@@ -1634,7 +1605,7 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
     const char *p;
     int fd = -1;
     DumpState *s;
-    int ret;
+    Error *local_err = NULL;
 
     /*
      * kdump-compressed format need the whole memory dumped, so paging or
@@ -1694,10 +1665,11 @@ void qmp_dump_guest_memory(bool paging, const char *file, bool has_begin,
 
     s = g_malloc0(sizeof(DumpState));
 
-    ret = dump_init(s, fd, has_format, format, paging, has_begin,
-                    begin, length, errp);
-    if (ret < 0) {
+    dump_init(s, fd, has_format, format, paging, has_begin,
+              begin, length, &local_err);
+    if (local_err) {
         g_free(s);
+        error_propagate(errp, local_err);
         return;
     }
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PULL 4/7] MAINTAINERS: add entry for qobject files
  2014-10-23 15:19 [Qemu-devel] [PULL 0/7] QMP queue Luiz Capitulino
                   ` (2 preceding siblings ...)
  2014-10-23 15:19 ` [Qemu-devel] [PULL 3/7] dump: Turn some functions to void to make code cleaner Luiz Capitulino
@ 2014-10-23 15:19 ` Luiz Capitulino
  2014-10-23 15:19 ` [Qemu-devel] [PULL 5/7] qdev: add qdev_build_hotpluggable_device_list helper Luiz Capitulino
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2014-10-23 15:19 UTC (permalink / raw)
  To: peter.maydell; +Cc: qemu-devel

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 8eed800..b4fac85 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -829,6 +829,12 @@ S: Supported
 F: qapi-schema.json
 T: git git://repo.or.cz/qemu/qmp-unstable.git queue/qmp
 
+QObject
+M: Luiz Capitulino <lcapitulino@redhat.com>
+S: Maintained
+F: qobject/
+T: git git://repo.or.cz/qemu/qmp-unstable.git queue/qmp
+
 QOM
 M: Anthony Liguori <aliguori@amazon.com>
 M: Andreas Färber <afaerber@suse.de>
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PULL 5/7] qdev: add qdev_build_hotpluggable_device_list helper
  2014-10-23 15:19 [Qemu-devel] [PULL 0/7] QMP queue Luiz Capitulino
                   ` (3 preceding siblings ...)
  2014-10-23 15:19 ` [Qemu-devel] [PULL 4/7] MAINTAINERS: add entry for qobject files Luiz Capitulino
@ 2014-10-23 15:19 ` Luiz Capitulino
  2014-10-23 15:19 ` [Qemu-devel] [PULL 6/7] monitor: add del completion for peripheral device Luiz Capitulino
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2014-10-23 15:19 UTC (permalink / raw)
  To: peter.maydell; +Cc: qemu-devel

From: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>

For peripheral device del completion, add a function to build a list for
hotpluggable devices.

Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hw/core/qdev.c         | 13 +++++++++++++
 include/hw/qdev-core.h |  2 ++
 2 files changed, 15 insertions(+)

diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index a1e9247..9357aba 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -866,6 +866,19 @@ void qdev_alias_all_properties(DeviceState *target, Object *source)
     } while (class != object_class_by_name(TYPE_DEVICE));
 }
 
+int qdev_build_hotpluggable_device_list(Object *obj, void *opaque)
+{
+    GSList **list = opaque;
+    DeviceState *dev = DEVICE(obj);
+
+    if (dev->realized && object_property_get_bool(obj, "hotpluggable", NULL)) {
+        *list = g_slist_append(*list, dev);
+    }
+
+    object_child_foreach(obj, qdev_build_hotpluggable_device_list, opaque);
+    return 0;
+}
+
 static bool device_get_realized(Object *obj, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 1fca75c..22820fe 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -360,6 +360,8 @@ extern int qdev_hotplug;
 
 char *qdev_get_dev_path(DeviceState *dev);
 
+int qdev_build_hotpluggable_device_list(Object *obj, void *opaque);
+
 void qbus_set_hotplug_handler(BusState *bus, DeviceState *handler,
                               Error **errp);
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PULL 6/7] monitor: add del completion for peripheral device
  2014-10-23 15:19 [Qemu-devel] [PULL 0/7] QMP queue Luiz Capitulino
                   ` (4 preceding siblings ...)
  2014-10-23 15:19 ` [Qemu-devel] [PULL 5/7] qdev: add qdev_build_hotpluggable_device_list helper Luiz Capitulino
@ 2014-10-23 15:19 ` Luiz Capitulino
  2014-10-23 15:19 ` [Qemu-devel] [PULL 7/7] monitor: delete device_del_bus_completion Luiz Capitulino
  2014-10-23 18:19 ` [Qemu-devel] [PULL 0/7] QMP queue Peter Maydell
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2014-10-23 15:19 UTC (permalink / raw)
  To: peter.maydell; +Cc: qemu-devel

From: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>

Add peripheral_device_del_completion() to let peripheral device del completion
be possible.

Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/monitor.c b/monitor.c
index fba4ce2..e3799f9 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4341,6 +4341,31 @@ static void device_del_bus_completion(ReadLineState *rs,  BusState *bus,
     }
 }
 
+static void peripheral_device_del_completion(ReadLineState *rs,
+                                             const char *str, size_t len)
+{
+    Object *peripheral;
+    GSList *list = NULL, *item;
+
+    peripheral = object_resolve_path("/machine/peripheral/", NULL);
+    if (peripheral == NULL) {
+        return;
+    }
+
+    object_child_foreach(peripheral, qdev_build_hotpluggable_device_list,
+                         &list);
+
+    for (item = list; item; item = g_slist_next(item)) {
+        DeviceState *dev = item->data;
+
+        if (dev->id && !strncmp(str, dev->id, len)) {
+            readline_add_completion(rs, dev->id);
+        }
+    }
+
+    g_slist_free(list);
+}
+
 void chardev_remove_completion(ReadLineState *rs, int nb_args, const char *str)
 {
     size_t len;
@@ -4414,6 +4439,7 @@ void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
     len = strlen(str);
     readline_set_completion_index(rs, len);
     device_del_bus_completion(rs, sysbus_get_default(), str, len);
+    peripheral_device_del_completion(rs, str, len);
 }
 
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str)
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PULL 7/7] monitor: delete device_del_bus_completion
  2014-10-23 15:19 [Qemu-devel] [PULL 0/7] QMP queue Luiz Capitulino
                   ` (5 preceding siblings ...)
  2014-10-23 15:19 ` [Qemu-devel] [PULL 6/7] monitor: add del completion for peripheral device Luiz Capitulino
@ 2014-10-23 15:19 ` Luiz Capitulino
  2014-10-23 18:19 ` [Qemu-devel] [PULL 0/7] QMP queue Peter Maydell
  7 siblings, 0 replies; 9+ messages in thread
From: Luiz Capitulino @ 2014-10-23 15:19 UTC (permalink / raw)
  To: peter.maydell; +Cc: qemu-devel

From: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>

device_del_bus_completion() that gathers devices from buses is unused; delete
it.

Signed-off-by: Zhu Guihua <zhugh.fnst@cn.fujitsu.com>
Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 monitor.c | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/monitor.c b/monitor.c
index e3799f9..07fb36e 100644
--- a/monitor.c
+++ b/monitor.c
@@ -4322,25 +4322,6 @@ void object_add_completion(ReadLineState *rs, int nb_args, const char *str)
     g_slist_free(list);
 }
 
-static void device_del_bus_completion(ReadLineState *rs,  BusState *bus,
-                                      const char *str, size_t len)
-{
-    BusChild *kid;
-
-    QTAILQ_FOREACH(kid, &bus->children, sibling) {
-        DeviceState *dev = kid->child;
-        BusState *dev_child;
-
-        if (dev->id && !strncmp(str, dev->id, len)) {
-            readline_add_completion(rs, dev->id);
-        }
-
-        QLIST_FOREACH(dev_child, &dev->child_bus, sibling) {
-            device_del_bus_completion(rs, dev_child, str, len);
-        }
-    }
-}
-
 static void peripheral_device_del_completion(ReadLineState *rs,
                                              const char *str, size_t len)
 {
@@ -4438,7 +4419,6 @@ void device_del_completion(ReadLineState *rs, int nb_args, const char *str)
 
     len = strlen(str);
     readline_set_completion_index(rs, len);
-    device_del_bus_completion(rs, sysbus_get_default(), str, len);
     peripheral_device_del_completion(rs, str, len);
 }
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Qemu-devel] [PULL 0/7] QMP queue
  2014-10-23 15:19 [Qemu-devel] [PULL 0/7] QMP queue Luiz Capitulino
                   ` (6 preceding siblings ...)
  2014-10-23 15:19 ` [Qemu-devel] [PULL 7/7] monitor: delete device_del_bus_completion Luiz Capitulino
@ 2014-10-23 18:19 ` Peter Maydell
  7 siblings, 0 replies; 9+ messages in thread
From: Peter Maydell @ 2014-10-23 18:19 UTC (permalink / raw)
  To: Luiz Capitulino; +Cc: QEMU Developers

On 23 October 2014 16:19, Luiz Capitulino <lcapitulino@redhat.com> wrote:
> The following changes since commit e40830afa1cff3ffdc37bdfdd40d80860074636c:
>
>   Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2014-10-22-tag' into staging (2014-10-22 21:42:33 +0100)
>
> are available in the git repository at:
>
>
>   git://repo.or.cz/qemu/qmp-unstable.git tags/for-upstream
>
> for you to fetch changes up to e799157c766d96506214059d8b75712a3e615431:
>
>   monitor: delete device_del_bus_completion (2014-10-23 09:04:05 -0400)
>
> ----------------------------------------------------------------
> QMP patches
>
> ----------------------------------------------------------------

Applied, thanks.

-- PMM

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-10-23 18:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-23 15:19 [Qemu-devel] [PULL 0/7] QMP queue Luiz Capitulino
2014-10-23 15:19 ` [Qemu-devel] [PULL 1/7] virtio-balloon: Tweak recent fix for integer overflow Luiz Capitulino
2014-10-23 15:19 ` [Qemu-devel] [PULL 2/7] dump: Propagate errors into qmp_dump_guest_memory() Luiz Capitulino
2014-10-23 15:19 ` [Qemu-devel] [PULL 3/7] dump: Turn some functions to void to make code cleaner Luiz Capitulino
2014-10-23 15:19 ` [Qemu-devel] [PULL 4/7] MAINTAINERS: add entry for qobject files Luiz Capitulino
2014-10-23 15:19 ` [Qemu-devel] [PULL 5/7] qdev: add qdev_build_hotpluggable_device_list helper Luiz Capitulino
2014-10-23 15:19 ` [Qemu-devel] [PULL 6/7] monitor: add del completion for peripheral device Luiz Capitulino
2014-10-23 15:19 ` [Qemu-devel] [PULL 7/7] monitor: delete device_del_bus_completion Luiz Capitulino
2014-10-23 18:19 ` [Qemu-devel] [PULL 0/7] QMP queue Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).