From patchwork Mon Mar 3 17:11:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 325916 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6DBAD2C00D5 for ; Tue, 4 Mar 2014 04:30:24 +1100 (EST) Received: from localhost ([::1]:40820 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKWaz-0006Wu-NX for incoming@patchwork.ozlabs.org; Mon, 03 Mar 2014 12:24:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43843) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKWYU-00029J-3M for qemu-devel@nongnu.org; Mon, 03 Mar 2014 12:21:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WKWYN-0003Gj-7T for qemu-devel@nongnu.org; Mon, 03 Mar 2014 12:21:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:9376) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKWYM-0003Ga-Vi for qemu-devel@nongnu.org; Mon, 03 Mar 2014 12:21:23 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s23HLJP1015952 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 3 Mar 2014 12:21:19 -0500 Received: from localhost (ovpn-113-127.phx2.redhat.com [10.3.113.127]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s23HLI5i011712; Mon, 3 Mar 2014 12:21:18 -0500 From: Luiz Capitulino To: peter.maydell@linaro.org Date: Mon, 3 Mar 2014 12:11:58 -0500 Message-Id: <1393866743-17385-8-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1393866743-17385-1-git-send-email-lcapitulino@redhat.com> References: <1393866743-17385-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws Subject: [Qemu-devel] [PULL 07/32] dump: add API to write elf notes to buffer X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: qiaonuohan the function can be used by write_elf32_notes/write_elf64_notes to write notes to a buffer. If fd_write_vmcore is used, write_elf32_notes/write_elf64_notes will write elf notes to vmcore directly. Instead, if buf_write_note is used, elf notes will be written to opaque->note_buf at first. Signed-off-by: Qiao Nuohan Reviewed-by: Laszlo Ersek Signed-off-by: Luiz Capitulino --- dump.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dump.c b/dump.c index 238ffa5..2b940bd 100644 --- a/dump.c +++ b/dump.c @@ -76,6 +76,9 @@ typedef struct DumpState { int64_t begin; int64_t length; Error **errp; + + uint8_t *note_buf; /* buffer for notes */ + size_t note_buf_offset; /* the writing place in note_buf */ } DumpState; static int dump_cleanup(DumpState *s) @@ -749,6 +752,22 @@ static int write_buffer(int fd, off_t offset, const void *buf, size_t size) return 0; } +static int buf_write_note(const void *buf, size_t size, void *opaque) +{ + DumpState *s = opaque; + + /* note_buf is not enough */ + if (s->note_buf_offset + size > s->note_size) { + return -1; + } + + memcpy(s->note_buf + s->note_buf_offset, buf, size); + + s->note_buf_offset += size; + + return 0; +} + static ram_addr_t get_start_block(DumpState *s) { GuestPhysBlock *block;