From patchwork Thu Dec 17 17:46:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 558499 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 763A41401B5 for ; Fri, 18 Dec 2015 04:51:53 +1100 (AEDT) Received: from localhost ([::1]:55486 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9ciV-0000ow-BK for incoming@patchwork.ozlabs.org; Thu, 17 Dec 2015 12:51:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9ceE-0001LC-Q5 for qemu-devel@nongnu.org; Thu, 17 Dec 2015 12:47:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9ceD-0006tt-NR for qemu-devel@nongnu.org; Thu, 17 Dec 2015 12:47:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:57131) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9ceD-0006tl-Il for qemu-devel@nongnu.org; Thu, 17 Dec 2015 12:47:25 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 2E8D61136FD; Thu, 17 Dec 2015 17:47:25 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-23.ams2.redhat.com [10.36.112.23]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBHHkfcM014618; Thu, 17 Dec 2015 12:47:23 -0500 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 17 Dec 2015 18:46:16 +0100 Message-Id: <1450374401-31352-21-git-send-email-pbonzini@redhat.com> In-Reply-To: <1450374401-31352-1-git-send-email-pbonzini@redhat.com> References: <1450374401-31352-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Olga Krishtal , Markus Armbruster , "Denis V. Lunev" Subject: [Qemu-devel] [PULL 20/45] qemu-char: append opt to stop truncation of serial file 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: Olga Krishtal Our QA team wants to preserve serial output of the guest in between QEMU runs to perform post-analysis. By default this behavior is off (file is truncated each time QEMU is started or device is plugged). Signed-off-by: Olga Krishtal Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Markus Armbruster CC: Paolo Bonzini Message-Id: <1449211324-17856-1-git-send-email-den@openvz.org> Signed-off-by: Paolo Bonzini --- qapi-schema.json | 5 ++++- qemu-char.c | 14 +++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index f014a80..516b145 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3102,11 +3102,14 @@ # # @in: #optional The name of the input file # @out: The name of the output file +# @append: #optional Open the file in append mode (default false to +# truncate) (Since 2.6) # # Since: 1.4 ## { 'struct': 'ChardevFile', 'data': { '*in' : 'str', - 'out' : 'str' } } + 'out' : 'str', + '*append': 'bool' } } ## # @ChardevHostdev: diff --git a/qemu-char.c b/qemu-char.c index 2969c44..66703e3 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3484,6 +3484,9 @@ static void qemu_chr_parse_file_out(QemuOpts *opts, ChardevBackend *backend, } backend->u.file = g_new0(ChardevFile, 1); backend->u.file->out = g_strdup(path); + + backend->u.file->has_append = true; + backend->u.file->append = qemu_opt_get_bool(opts, "append", false); } static void qemu_chr_parse_stdio(QemuOpts *opts, ChardevBackend *backend, @@ -4041,6 +4044,9 @@ QemuOptsList qemu_chardev_opts = { },{ .name = "chardev", .type = QEMU_OPT_STRING, + },{ + .name = "append", + .type = QEMU_OPT_BOOL, }, { /* end of list */ } }, @@ -4101,7 +4107,13 @@ static CharDriverState *qmp_chardev_open_file(const char *id, ChardevFile *file = backend->u.file; int flags, in = -1, out; - flags = O_WRONLY | O_TRUNC | O_CREAT | O_BINARY; + flags = O_WRONLY | O_CREAT | O_BINARY; + if (file->has_append && file->append) { + flags |= O_APPEND; + } else { + flags |= O_TRUNC; + } + out = qmp_chardev_open_file_source(file->out, flags, errp); if (out < 0) { return NULL;