aboutsummaryrefslogtreecommitdiff
path: root/dump.c
AgeCommit message (Collapse)AuthorFilesLines
2019-02-06dump: Set correct vaddr for ELF dumpJon Doron1-2/+3
vaddr needs to be equal to the paddr since the dump file represents the physical memory image. Without setting vaddr correctly, GDB would load all the different memory regions on top of each other to vaddr 0, thus making GDB showing the wrong memory data for a given address. Signed-off-by: Jon Doron <arilou@gmail.com> Message-Id: <20190109082203.27142-1-arilou@gmail.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Tested-by: Marc-André Lureau <marcandre.lureau@redhat.com> Acked-by: Laszlo Ersek <lersek@redhat.com>
2019-01-11qemu/queue.h: simplify reverse access to QTAILQPaolo Bonzini1-1/+1
The new definition of QTAILQ does not require passing the headname, remove it. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-08-28qapi: Drop qapi_event_send_FOO()'s Error ** argumentPeter Xu1-2/+1
The generated qapi_event_send_FOO() take an Error ** argument. They can't actually fail, because all they do with the argument is passing it to functions that can't fail: the QObject output visitor, and the @qmp_emit callback, which is either monitor_qapi_event_queue() or event_test_emit(). Drop the argument, and pass &error_abort to the QObject output visitor and @qmp_emit instead. Suggested-by: Eric Blake <eblake@redhat.com> Suggested-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <20180815133747.25032-4-peterx@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Commit message rewritten, update to qapi-code-gen.txt corrected] Signed-off-by: Markus Armbruster <armbru@redhat.com>
2018-08-23fw_cfg: import & use linux/qemu_fw_cfg.hMarc-André Lureau1-1/+1
Use kernel common header for fw_cfg. (unfortunately, optionrom.h must have its own define, since it's actually an assembler header) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20180817155910.5722-2-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-06-29dump: add Windows dump format to dump-guest-memoryViktor Prutyanov1-1/+23
This patch adds Windows crashdumping feature. Now QEMU can produce ELF-dump containing Windows crashdump header, which can help to convert to a valid WinDbg-understandable crashdump file, or immediately create such file. The crashdump will be obtained by joining physical memory dump and 8K header exposed through vmcoreinfo/fw_cfg device by guest driver at BSOD time. Option '-w' was added to dump-guest-memory command. At the moment, only x64 configuration is supported. Suitable driver can be found at https://github.com/virtio-win/kvm-guest-drivers-windows/tree/master/fwcfg64 Signed-off-by: Viktor Prutyanov <viktor.prutyanov@virtuozzo.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20180517162342.4330-2-viktor.prutyanov@virtuozzo.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-04-09dump: Fix build with newer gccEric Blake1-2/+2
gcc 8 on rawhide is picky enough to complain: /home/dummy/qemu/dump.c: In function 'create_header32': /home/dummy/qemu/dump.c:817:5: error: 'strncpy' output truncated before terminating nul copying 8 bytes from a string of the same length [-Werror=stringop-truncation] strncpy(dh->signature, KDUMP_SIGNATURE, strlen(KDUMP_SIGNATURE)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ But we already have SIG_LEN defined as the right length without needing to do a strlen(), and memcpy() is better than strncpy() when we know we do not want a trailing NUL byte. Signed-off-by: Eric Blake <eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2018-03-21dump.c: allow fd_write_vmcore to return errno on failureYasmin Beatriz1-9/+14
fd_write_vmcore can fail to execute for a lot of reasons that can be retrieved by errno, but it only returns -1. This makes difficult for the caller to know what happened and only a generic error message is propagated back to the user. This is an example using dump-guest-memory: (qemu) dump-guest-memory /home/yasmin/mnt/test.dump dump: failed to save memory All callers of fd_write_vmcore of dump.c does error handling via error_setg(), so at first it seems feasible to add the Error pointer as an argument of fd_write_vmcore. This proved to be more complex than it first looked. fd_write_vmcore is used by write_elf64_notes and write_elf32_notes as a WriteCoreDumpFunction prototype. WriteCoreDumpFunction is declared in include/qom/cpu.h and is used all around the code. This leaves us with few alternatives: - change the WriteCoreDumpFunction prototype to include an error pointer. This would require to change all functions that implements this prototype to also receive an Error pointer; - change both write_elf64_notes and write_elf32_notes to no use the WriteCoreDumpFunction. These functions use not only fd_write_vmcore but also buf_write_note, so this would require to change buf_write_note to handle an Error pointer. Considerable easier than the alternative above, but it's still a lot of code just for the benefit of the callers of fd_write_vmcore. This patch presents an easier solution that benefits all fd_write_vmcore callers: - instead of returning -1 on error, return -errno. All existing callers already checks for ret < 0 so there is no need to change the caller's logic too much. This also allows the retrieval of the errno. - all callers were updated to use error_setg_errno instead of just errno_setg. Now that fd_write_vmcore can return an errno, let's update all callers so they can benefit from a more detailed error message. This is the same dump-guest-memory example with this patch applied: (qemu) dump-guest-memory /home/yasmin/mnt/test.dump dump: failed to save memory: No space left on device (qemu) This example illustrates an error of fd_write_vmcore when called from write_data. All other callers will benefit from better error messages as well. Reported-by: yilzhang@redhat.com Cc: Jose Ricardo Ziviani <joserz@linux.vnet.ibm.com> Signed-off-by: Yasmin Beatriz <yasmins@linux.vnet.ibm.com> Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com> Message-Id: <20180212142506.28445-2-danielhb@linux.vnet.ibm.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2018-03-19dump: Update correct kdump phys_base field for AArch64Wei Huang1-3/+11
For guest kernel that supports KASLR, the load address can change every time when guest VM runs. To find the physical base address correctly, current QEMU dump searches VMCOREINFO for the string "NUMBER(phys_base)=". However this string pattern is only available on x86_64. AArch64 uses a different field, called "NUMBER(PHYS_OFFSET)=". This patch makes sure QEMU dump uses the correct string on AArch64. Signed-off-by: Wei Huang <wei@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-id: 1520615003-20869-1-git-send-email-wei@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2018-03-02qapi: Empty out qapi-schema.jsonMarkus Armbruster1-2/+2
The previous commit improved compile time by including less of the generated QAPI headers. This is impossible for stuff defined directly in qapi-schema.json, because that ends up in headers that that pull in everything. Move everything but include directives from qapi-schema.json to new sub-module qapi/misc.json, then include just the "misc" shard where possible. It's possible everywhere, except: * monitor.c needs qmp-command.h to get qmp_init_marshal() * monitor.c, ui/vnc.c and the generated qapi-event-FOO.c need qapi-event.h to get enum QAPIEvent Perhaps we'll get rid of those some other day. Adding a type to qapi/migration.json now recompiles some 120 instead of 2300 out of 5100 objects. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20180211093607.27351-25-armbru@redhat.com> [eblake: rebase to master] Signed-off-by: Eric Blake <eblake@redhat.com>
2018-02-09Include qapi/error.h exactly where neededMarkus Armbruster1-0/+1
This cleanup makes the number of objects depending on qapi/error.h drop from 1910 (out of 4743) to 1612 in my "build everything" tree. While there, separate #include from file comment with a blank line, and drop a useless comment on why qemu/osdep.h is included first. Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20180201111846.21846-5-armbru@redhat.com> [Semantic conflict with commit 34e304e975 resolved, OSX breakage fixed]
2018-01-02dump: fix note_name_equal()Marc-André Lureau1-6/+1
Use the function argument "name" instead of hardcoded "VMCOREINFO". All callers use "VMCOREINFO" as argument, so this isn't an exposed bug, thankfully. Simplify a little bit the code while touching this. Suggested-by: Andrew Jones <drjones@redhat.com> Reported-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2017-10-15kdump: set vmcoreinfo locationMarc-André Lureau1-0/+24
kdump header provides offset and size of the vmcoreinfo content, append it if available (skip the ELF note header). crash-7.1.9 was the first version that started looking in the vmcoreinfo data for phys_base instead of in the kdump_sub_header. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2017-10-15dump: update phys_base header field based on VMCOREINFO contentMarc-André Lureau1-2/+54
If the guest note is VMCOREINFO, try to get phys_base from it. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2017-10-15dump: add guest ELF noteMarc-André Lureau1-0/+107
Read the guest ELF PT_NOTE from guest memory when fw_cfg etc/vmcoreinfo entry provides the location, and write it as an additional note in the dump. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2017-09-19exec,dump,i386,ppc,s390x: don't include exec/cpu-all.h explicitlyDavid Hildenbrand1-1/+0
All but a handful of files include exec/cpu-all.h via cpu.h only. As these files already include cpu.h, let's just drop the additional include. Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: David Hildenbrand <david@redhat.com> Message-Id: <20170913132417.24384-2-david@redhat.com> Signed-off-by: Cornelia Huck <cohuck@redhat.com>
2017-09-14dump: do not dump non-existent guest memoryCornelia Huck1-0/+6
It does not really make sense to dump memory that is not there. Moreover, that fixes a segmentation fault when calling dump-guest-memory with no filter for a machine with no memory defined. New behaviour is: (qemu) dump-guest-memory /dev/null dump: no guest memory to dump (qemu) dump-guest-memory /dev/null 0 4096 dump: no guest memory to dump Signed-off-by: Cornelia Huck <cohuck@redhat.com> Tested-by: Laurent Vivier <lvivier@redhat.com> Reviewed-by: Laurent Vivier <lvivier@redhat.com> Reviewed-by: Greg Kurz <groug@kaod.org> Reviewed-by: Peter Xu <peterx@redhat.com> Message-Id: <20170913142036.2469-4-lvivier@redhat.com> Signed-off-by: Laurent Vivier <lvivier@redhat.com> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
2017-08-30misc: Remove unused Error variablesAlberto Garcia1-3/+1
There's a few cases which we're passing an Error pointer to a function only to discard it immediately afterwards without checking it. In these cases we can simply remove the variable and pass NULL instead. Signed-off-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 20170829120836.16091-1-berto@igalia.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2017-05-05dump: Acquire BQL around vm_start() in dump threadFam Zheng1-0/+7
This fixes an assertion failure in the following backtrace: __GI___assert_fail memory_region_transaction_commit memory_region_add_eventfd virtio_pci_ioeventfd_assign virtio_bus_set_host_notifier virtio_blk_data_plane_start virtio_bus_start_ioeventfd virtio_vmstate_change vm_state_notify vm_prepare_start vm_start dump_cleanup dump_process dump_thread start_thread clone vm_start need BQL, acquire it if doing cleaning up from main thread. Signed-off-by: Fam Zheng <famz@redhat.com> Message-Id: <20170503072819.14462-1-famz@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-06-20error: Remove NULL checks on error_propagate() callsEduardo Habkost1-3/+1
error_propagate() already ignores local_err==NULL, so there's no need to check it before calling. Coccinelle patch used to perform the changes added to scripts/coccinelle/error_propagate_null.cocci. Reviewed-by: Eric Blake <eblake@redhat.com> Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Message-Id: <1465855078-19435-2-git-send-email-ehabkost@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-03-22util: move declarations out of qemu-common.hVeronia Bahaa1-1/+1
Move declarations out of qemu-common.h for functions declared in utils/ files: e.g. include/qemu/path.h for utils/path.c. Move inline functions out of qemu-common.h and into new files (e.g. include/qemu/bcd.h) Signed-off-by: Veronia Bahaa <veroniabahaa@gmail.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-22dump-guest-memory: add qmp event DUMP_COMPLETEDPeter Xu1-6/+12
One new QMP event DUMP_COMPLETED is added. When a dump finishes, one DUMP_COMPLETED event will occur to notify the user. Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-Id: <1455772616-8668-12-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-22Dump: add qmp command "query-dump"Peter Xu1-4/+19
When dump-guest-memory is requested with detach flag, after its return, user could query its status using "query-dump" command (with no argument). The result contains: - status: current dump status - completed: bytes written in the latest dump - total: bytes to write in the latest dump From completed and total, we could know how much work finished by calculating: 100.0 * completed / total (%) Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <1455772616-8668-10-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-22DumpState: adding total_size and written_size fieldsPeter Xu1-0/+32
Here, total_size is the size in bytes to be dumped (raw data, which means before compression), while written_size are bytes handled (raw size too). Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <1455772616-8668-9-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-22dump-guest-memory: add "detach" supportPeter Xu1-1/+26
If "detach" is provided, one thread is created to do the dump work, while main thread will return immediately. For each GuestPhysBlock, adding one more field "mr" to points to MemoryRegion that it belongs, also ref the mr before use. Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-Id: <1455772616-8668-8-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-22dump-guest-memory: disable dump when in INMIGRATE statePeter Xu1-0/+5
Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-Id: <1455772616-8668-7-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-22dump-guest-memory: introduce dump_process() helper function.Peter Xu1-10/+21
No functional change. Cleanup only. Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-Id: <1455772616-8668-6-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-22dump-guest-memory: add dump_in_progress() helper functionPeter Xu1-0/+13
For now, it has no effect. It will be used in dump detach support. Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-Id: <1455772616-8668-5-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-22dump-guest-memory: using static DumpState, add DumpStatusPeter Xu1-5/+16
Instead of malloc/free each time for DumpState, make it static. Added DumpStatus to show status for dump. This is to be used for detached dump. Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-Id: <1455772616-8668-4-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-22dump-guest-memory: add "detach" flag for QMP/HMP interfaces.Peter Xu1-2/+3
This patch only adds the interfaces, but does not implement them. "detach" parameter is made optional, to make sure that all the old dump-guest-memory requests will still be able to work. Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-Id: <1455772616-8668-3-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-22dump-guest-memory: cleanup: removing dump_{error|cleanup}().Peter Xu1-46/+32
It might be a little bit confusing and error prone to do dump_cleanup() in these two functions. A better way is to do dump_cleanup() before dump finish, no matter whether dump has succeeded or not. Signed-off-by: Peter Xu <peterx@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Message-Id: <1455772616-8668-2-git-send-email-peterx@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-02-04all: Clean up includesPeter Maydell1-1/+1
Clean up includes so that osdep.h is included first and headers which it implies are not included manually. This commit was created with scripts/clean-includes. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 1454089805-5470-16-git-send-email-peter.maydell@linaro.org
2016-01-15dump: allow target to set the physical baseAndrew Jones1-2/+2
crash assumes the physical base in the kdump subheader of makedumpfile formatted dumps is correct. Zero is not correct for all architectures, so allow it to be changed. (No functional change.) Signed-off-by: Andrew Jones <drjones@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 1452542185-10914-5-git-send-email-drjones@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2016-01-15dump: allow target to set the page sizeAndrew Jones1-49/+78
This is necessary for targets that don't have TARGET_PAGE_SIZE == real-target-page-size. The target should set the page size to the correct one, if known, or, if not known, to the maximum page size it supports. (No functional change.) Signed-off-by: Andrew Jones <drjones@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Message-id: 1452542185-10914-4-git-send-email-drjones@redhat.com Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2015-06-22Include qapi/qmp/qerror.h exactly where neededMarkus Armbruster1-0/+1
In particular, don't include it into headers. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-06-22qerror: Clean up QERR_ macros to expand into a single stringMarkus Armbruster1-6/+6
These macros expand into error class enumeration constant, comma, string. Unclean. Has been that way since commit 13f59ae. The error class is always ERROR_CLASS_GENERIC_ERROR since the previous commit. Clean up as follows: * Prepend every use of a QERR_ macro by ERROR_CLASS_GENERIC_ERROR, and delete it from the QERR_ macro. No change after preprocessing. * Rewrite error_set(ERROR_CLASS_GENERIC_ERROR, ...) into error_setg(...). Again, no change after preprocessing. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-11-02dump: Fix dump-guest-memory termination and use-after-closeGonglei1-7/+4
dump_iterate() dumps blocks in a loop. Eventually, get_next_block() returns "no more". We then call dump_completed(). But we neglect to break the loop! Broken in commit 4c7e251a. Because of that, we dump the last block again. This attempts to write to s->fd, which fails if we're lucky. The error makes dump_iterate() return failure. It's the only way it can ever return. Theoretical: if we're not so lucky, something else has opened something for writing and got the same fd. dump_iterate() then keeps looping, messing up the something else's output, until a write fails, or the process mercifully terminates. The obvious fix is to restore the return lost in commit 4c7e251a. But the root cause of the bug is needlessly opaque loop control. Replace it by a clean do ... while loop. This makes the badly chosen return values of get_next_block() more visible. Cleaning that up is outside the scope of this bug fix. Signed-off-by: Gonglei <arei.gonglei@huawei.com> Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2014-10-23dump: Turn some functions to void to make code cleanerzhanghailiang1-170/+142
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>
2014-10-23dump: Propagate errors into qmp_dump_guest_memory()zhanghailiang1-83/+82
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>
2014-08-18dump.c: Fix memory leak issue in cleanup processing for dump_init()Chen Gang1-13/+5
In dump_init(), when failure occurs, need notice about 'fd' and memory mapping. So call dump_cleanup() for it (need let all initializations at front). Also simplify dump_cleanup(): remove redundant 'ret' and redundant 'fd' checking. Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-06-16dump: Make DumpState and endian conversion routines available for ↵Bharata B Rao1-141/+90
arch-specific dump code Make DumpState and endian conversion routines available for arch-specific dump code by moving into dump.h. DumpState will be needed by arch-specific dump code to access target endian information from DumpState->ArchDumpInfo. Also break the dependency of dump.h from stubs/dump.c by creating a separate dump-arch.h. This patch doesn't change any functionality. Signed-off-by: Bharata B Rao <bharata@linux.ibm.com> [ rebased on top of current master branch, renamed endian helpers to cpu_to_dump{16,32,64}, pass a DumpState * argument to endian helpers, Greg Kurz <gkurz@linux.vnet.ibm.com> ] Signed-off-by: Greg Kurz <gkurz@linux.vnet.ibm.com> [agraf: fix to apply] Signed-off-by: Alexander Graf <agraf@suse.de>
2014-06-11dump: simplify get_len_buf_out()Laszlo Ersek1-30/+16
We can (and should) rely on the fact that s->flag_compress is exactly one of DUMP_DH_COMPRESSED_ZLIB, DUMP_DH_COMPRESSED_LZO, and DUMP_DH_COMPRESSED_SNAPPY. This is ensured by the QMP schema and dump_init() in combination. Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-06-11dump: hoist lzo_init() from get_len_buf_out() to dump_init()Laszlo Ersek1-7/+6
qmp_dump_guest_memory() dump_init() lzo_init() <---------+ create_kdump_vmcore() | write_dump_pages() | get_len_buf_out() | lzo_init() ------+ This patch doesn't change the fact that lzo_init() is called for every LZO-compressed dump, but it makes get_len_buf_out() more focused (single responsibility). Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-06-11dump: select header bitness based on ELF class, not ELF architectureLaszlo Ersek1-1/+1
The specific ELF architecture (d_machine) carries Too Much Information (TM) for deciding between create_header32() and create_header64(), use "d_class" instead (ELFCLASS32 vs. ELFCLASS64). This change adapts write_dump_header() to write_elf_loads(), dump_begin() etc. that also rely on the ELF class of the target for bitness selection. Considering the current targets that support dumping, cpu_get_dump_info() works as follows: - target-s390x/arch_dump.c: (EM_S390, ELFCLASS64) only - target-ppc/arch_dump.c (EM_PPC64, ELFCLASS64) only - target-i386/arch_dump.c: sets (EM_X86_64, ELFCLASS64) vs. (EM_386, ELFCLASS32) keying off the same Long Mode Active flag. Hence no observable change. Approximately-suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-06-11dump: eliminate DumpState.page_size ("guest's page size")Laszlo Ersek1-26/+25
Use TARGET_PAGE_SIZE and ~TARGET_PAGE_MASK instead. "DumpState.page_size" has type "size_t", whereas TARGET_PAGE_SIZE has type "int". TARGET_PAGE_MASK is of type "int" and has negative value. The patch affects the implicit type conversions as follows: - create_header32() and create_header64(): assigned to "block_size", which has type "uint32_t". No change. - get_next_page(): "block->target_start", "block->target_end" and "addr" have type "hwaddr" (uint64_t). Before the patch, - if "size_t" was "uint64_t", then no additional conversion was done as part of the usual arithmetic conversions, - If "size_t" was "uint32_t", then it was widened to uint64_t as part of the usual arithmetic conversions, for the remainder and addition operators. After the patch, - "~TARGET_PAGE_MASK" expands to ~~((1 << TARGET_PAGE_BITS) - 1). It has type "int" and positive value (only least significant bits set). That's converted (widened) to "uint64_t" for the bit-ands. No visible change. - The same holds for the (addr + TARGET_PAGE_SIZE) addition. - write_dump_pages(): - TARGET_PAGE_SIZE passed as argument to a bunch of functions that all have prototypes. No change. - When incrementing "offset_data" (of type "off_t"): given that we never build for ILP32_OFF32 (see "-D_FILE_OFFSET_BITS=64" in configure), "off_t" is always "int64_t", and we only need to consider: - ILP32_OFFBIG: "size_t" is "uint32_t". - before: int64_t += uint32_t. Page size converted to int64_t for the addition. - after: int64_t += int32_t. No change. - LP64_OFF64: "size_t" is "uint64_t". - before: int64_t += uint64_t. Offset converted to uint64_t for the addition, then the uint64_t result is converted to int64_t for storage. - after: int64_t += int32_t. Same as the ILP32_OFFBIG/after case. No visible change. - (size_out < s->page_size) comparisons, and (size_out = s->page_size) assignment: - before: "size_out" is of type "size_t", no implicit conversion for either operator. - after: TARGET_PAGE_SIZE (of type "int" and positive value) is converted to "size_t" (for the relop because the latter is one of "uint32_t" and "uint64_t"). No visible change. - dump_init(): - DIV_ROUND_UP(DIV_ROUND_UP(s->max_mapnr, CHAR_BIT), s->page_size): The innermost "DumpState.max_mapnr" field has type uint64_t, which propagates through all implicit conversions at hand: #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d)) regardless of the page size macro argument's type. In the outer macro replacement, the page size is converted from uint32_t and int32_t alike to uint64_t. - (tmp * s->page_size) multiplication: "tmp" has size "uint64_t"; the RHS is converted to that type from uint32_t and int32_t just the same if it's not uint64_t to begin with. Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-06-11dump: eliminate DumpState.page_shift ("guest's page shift")Laszlo Ersek1-6/+4
Just use TARGET_PAGE_BITS. "DumpState.page_shift" used to have type "uint32_t", while the replacement TARGET_PAGE_BITS has type "int". Since "DumpState.page_shift" was only used as bit shift counts in the paddr_to_pfn() and pfn_to_paddr() macros, this is safe. Suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-06-11dump: simplify write_start_flat_header()Laszlo Ersek1-11/+9
Currently, the function - defines and populates an auto variable of type MakedumpfileHeader - allocates and zeroes a buffer of size MAX_SIZE_MDF_HEADER (4096) - copies the former into the latter (covering an initial portion of the latter) Fill in the MakedumpfileHeader structure in its final place (the alignment is OK because the structure lives at the address returned by g_malloc0()). Approximately-suggested-by: Luiz Capitulino <lcapitulino@redhat.com> Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-06-11dump: fill in the flat header signature more pleasingly to the eyeLaszlo Ersek1-2/+2
The "mh.signature" array field has size 16, and is zeroed by the preceding memset(). MAKEDUMPFILE_SIGNATURE expands to a string literal with string length 12 (size 13). There's no need to measure the length of MAKEDUMPFILE_SIGNATURE at runtime, nor for the extra zero-filling of "mh.signature" with strncpy(). Use memcpy() with MIN(sizeof, sizeof) for robustness (which is an integer constant expression, evaluable at compile time.) Approximately-suggested-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-05-09dump: Drop pointless error_is_set(), DumpState member errpMarkus Armbruster1-4/+2
In 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. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-02-28dump: add 'query-dump-guest-memory-capability' commandqiaonuohan1-0/+33
'query-dump-guest-memory-capability' is used to query the available formats for 'dump-guest-memory'. The output of the command will be like: -> { "execute": "query-dump-guest-memory-capability" } <- { "return": { "formats": ["elf", "kdump-zlib", "kdump-lzo", "kdump-snappy"] } Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
2014-02-28Define the architecture for compressed dump formatqiaonuohan1-2/+5
Signed-off-by: Ekaterina Tumanova <tumanova@linux.vnet.ibm.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>