From patchwork Thu Oct 18 10:22:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 192279 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 532512C0089 for ; Thu, 18 Oct 2012 21:48:41 +1100 (EST) Received: from localhost ([::1]:43402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOnHF-00020K-1G for incoming@patchwork.ozlabs.org; Thu, 18 Oct 2012 06:24:33 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45508) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOnGQ-0000E7-Qq for qemu-devel@nongnu.org; Thu, 18 Oct 2012 06:23:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TOnGJ-0001kz-TB for qemu-devel@nongnu.org; Thu, 18 Oct 2012 06:23:42 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:62641) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TOnGJ-0001aH-NI for qemu-devel@nongnu.org; Thu, 18 Oct 2012 06:23:35 -0400 Received: by mail-pa0-f45.google.com with SMTP id fb10so8234740pad.4 for ; Thu, 18 Oct 2012 03:23:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=ylgu133xMVLb43vnJcOBjPx3DQ6u5iQFxQ38jlSWvYw=; b=ZvDnFIzsqhRej/HRDZICiif1tgcalmw4mljnR59dn5SZKOjDF8C+noFAxySI7uoDgO hmSh1f3l/AUWE23xSu5YCRWVMZjVgmX6vJ4i1kdHu/zXTt7Pj8bdZI8pNxXtuAWF2C9N IKMBDW2WTn2a0Ilc2pnjBwW1dcUYB1H0h20XMAAH55j82zioeQ+tTWzKcFWxsZQzzuaL 1b7LT6PTcvhkTL3SgqYF2td69uTCLUaC/HaHdau9zsgiq51BQ0d55UlkRiQpIY/LLEdK F3mm4j1d6o48+m6O+yKW1TrpsDaPWaHV8dIL5A9ogAnD8hjSO21IQbLBehdBiq0UogI4 OEPQ== Received: by 10.68.232.131 with SMTP id to3mr65171466pbc.58.1350555815413; Thu, 18 Oct 2012 03:23:35 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id hu5sm3581193pbc.72.2012.10.18.03.23.32 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 18 Oct 2012 03:23:34 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 18 Oct 2012 12:22:34 +0200 Message-Id: <1350555758-29988-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1350555758-29988-1-git-send-email-pbonzini@redhat.com> References: <1350555758-29988-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.220.45 Cc: quintela@redhat.com Subject: [Qemu-devel] [PATCH 08/12] migration: xxx_close will only be called once 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 No need to test s->fd again, it is tested in the caller. Signed-off-by: Paolo Bonzini Reviewed-by: Orit Wasserman Reviewed-by: Juan Quintela --- migration-exec.c | 14 ++++++-------- migration-fd.c | 33 +++++++++++++++------------------ migration-tcp.c | 7 ++----- migration-unix.c | 7 ++----- 4 file modificati, 25 inserzioni(+), 36 rimozioni(-) diff --git a/migration-exec.c b/migration-exec.c index 0964dbb..1c562ab 100644 --- a/migration-exec.c +++ b/migration-exec.c @@ -48,14 +48,12 @@ static int exec_close(MigrationState *s) { int ret = 0; DPRINTF("exec_close\n"); - if (s->opaque) { - ret = qemu_fclose(s->opaque); - s->opaque = NULL; - s->fd = -1; - if (ret >= 0 && !(WIFEXITED(ret) && WEXITSTATUS(ret) == 0)) { - /* close succeeded, but non-zero exit code: */ - ret = -EIO; /* fake errno value */ - } + ret = qemu_fclose(s->opaque); + s->opaque = NULL; + s->fd = -1; + if (ret >= 0 && !(WIFEXITED(ret) && WEXITSTATUS(ret) == 0)) { + /* close succeeded, but non-zero exit code: */ + ret = -EIO; /* fake errno value */ } return ret; } diff --git a/migration-fd.c b/migration-fd.c index bb91e0a..67ee3d1 100644 --- a/migration-fd.c +++ b/migration-fd.c @@ -48,29 +48,26 @@ static int fd_close(MigrationState *s) int ret; DPRINTF("fd_close\n"); - if (s->fd != -1) { - ret = fstat(s->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(s->fd); - if (ret != 0) { - ret = -errno; - perror("migration-fd: fsync"); - return ret; - } - } - ret = close(s->fd); - s->fd = -1; + ret = fstat(s->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(s->fd); if (ret != 0) { ret = -errno; - perror("migration-fd: close"); + perror("migration-fd: fsync"); return ret; } } - return 0; + ret = close(s->fd); + s->fd = -1; + if (ret != 0) { + ret = -errno; + perror("migration-fd: close"); + } + return ret; } int fd_start_outgoing_migration(MigrationState *s, const char *fdname) diff --git a/migration-tcp.c b/migration-tcp.c index e797d23..07715de 100644 --- a/migration-tcp.c +++ b/migration-tcp.c @@ -44,11 +44,8 @@ static int tcp_close(MigrationState *s) { int r = 0; DPRINTF("tcp_close\n"); - if (s->fd != -1) { - if (closesocket(s->fd) < 0) { - r = -errno; - } - s->fd = -1; + if (closesocket(s->fd) < 0) { + r = -socket_error(); } return r; } diff --git a/migration-unix.c b/migration-unix.c index a407af2..def1969 100644 --- a/migration-unix.c +++ b/migration-unix.c @@ -44,11 +44,8 @@ static int unix_close(MigrationState *s) { int r = 0; DPRINTF("unix_close\n"); - if (s->fd != -1) { - if (close(s->fd) < 0) { - r = -errno; - } - s->fd = -1; + if (close(s->fd) < 0) { + r = -errno; } return r; }