From patchwork Fri Feb 15 17:47:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 220828 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 903C42C007B for ; Sat, 16 Feb 2013 06:21:43 +1100 (EST) Received: from localhost ([::1]:55596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6PPP-0007yq-35 for incoming@patchwork.ozlabs.org; Fri, 15 Feb 2013 12:49:15 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6POj-0006s4-9b for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U6POg-0004Rd-Iu for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:33 -0500 Received: from mail-ve0-f170.google.com ([209.85.128.170]:42749) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U6POg-0004RV-DY for qemu-devel@nongnu.org; Fri, 15 Feb 2013 12:48:30 -0500 Received: by mail-ve0-f170.google.com with SMTP id 14so3339083vea.29 for ; Fri, 15 Feb 2013 09:48:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=mUSeIMLknA8HrXWZl2qjS3RG1q6KO9pE6dPSIQLQtKI=; b=yyutO+6m1qgcP2uRic/xZZkiRuk55ODygF4Xcr4S6OqpiIuqiXAcPsU8aDfJfS1Dkk 9nYbWiVDhNTB56cLoyGT31W2w+UWowRbaw/HW1FyGjQY29kOCzjfEFuJgIuotimr6wh1 W0E/A/WuRYhfuVKoTYVkdYLqeo/XhohDDj4GDrF2bQxiNrPRYsAZtMJmaTK+2IYZ3a0b COYO8XgJ7Or7g3qcuTcR3T/pZ8VwNymeOILxYpRFcLUmPqsrCFlmh5U3eIvi1BER3y6F t4CFuv0XkWZrgRoO4Nif6P6VYZksHPF0uQ3sdtFzfjF96b96UrP6kkQRXcCK35CH1V2D 338Q== X-Received: by 10.52.97.7 with SMTP id dw7mr3859719vdb.38.1360950510007; Fri, 15 Feb 2013 09:48:30 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id yu12sm65402142vec.6.2013.02.15.09.48.28 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 15 Feb 2013 09:48:29 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 15 Feb 2013 18:47:02 +0100 Message-Id: <1360950433-17106-31-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1360950433-17106-1-git-send-email-pbonzini@redhat.com> References: <1360950433-17106-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.128.170 Cc: owasserm@redhat.com, chegu_vinod@hp.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 30/41] qemu-file: fsync a writable stdio QEMUFile 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 This is what fd_close does. Prepare for switching to a QEMUFile. Signed-off-by: Paolo Bonzini Reviewed-by: Orit Wasserman Reviewed-by: Juan Quintela --- savevm.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/savevm.c b/savevm.c index d7c2559..261d17a 100644 --- a/savevm.c +++ b/savevm.c @@ -256,6 +256,24 @@ static int stdio_fclose(void *opaque) { QEMUFileStdio *s = opaque; int ret = 0; + + if (s->file->ops->put_buffer) { + int fd = fileno(s->stdio_file); + struct stat st; + + ret = fstat(fd, &st); + if (ret == 0 && S_ISREG(st.st_mode)) { + /* + * If the file handle is a regular file make sure the + * data is flushed to disk before signaling success. + */ + ret = fsync(fd); + if (ret != 0) { + ret = -errno; + return ret; + } + } + } if (fclose(s->stdio_file) == EOF) { ret = -errno; }