From patchwork Fri Nov 2 17:51:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 196743 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 D9BCC2C00C4 for ; Sat, 3 Nov 2012 05:51:45 +1100 (EST) Received: from localhost ([::1]:60635 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TULQ8-0004NC-Kl for incoming@patchwork.ozlabs.org; Fri, 02 Nov 2012 13:52:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38682) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TULPE-0002ZZ-Sp for qemu-devel@nongnu.org; Fri, 02 Nov 2012 13:51:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TULPD-0005W9-H1 for qemu-devel@nongnu.org; Fri, 02 Nov 2012 13:51:44 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:55021) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TULPD-0005PA-8i for qemu-devel@nongnu.org; Fri, 02 Nov 2012 13:51:43 -0400 Received: by mail-pb0-f45.google.com with SMTP id rp2so2539706pbb.4 for ; Fri, 02 Nov 2012 10:51:42 -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=Q+VC5qjDSNIwr0YdZGeOMRhUOCdsaM432c4C2UDSe2o=; b=Xj/1oxj3yF76XBlqsOrznadZpZDLAQWUfU3wcn7/dOFut2Yv2ACsmdDKYJP+46ojKj XnRa3d0Cg+D/9H2SzAC4JHoh4NZKrwRMDx8U60Kb+6H7or3/6urd5gjZX/255bc6nWpm g+tEnfmOTE+RAC/8C2kzZwiT82RFHKTH6lcrytaIT3evKuJ1gbxPHjGzttynRcwtLfrI tA8eaZ0Xw7phv8ubq+KyP15mHVMpWWws7ZTUKywk9amxyTXyZnga5jqFDIe3r1aDIcbu 7Nu01mZQ1PdcvkfGC7gbH+rgyRLDrvBs8PEM/fDfM111By6GP/7m67wnLjpGhOI5qj9v Y/og== Received: by 10.68.239.9 with SMTP id vo9mr1169605pbc.83.1351878702802; Fri, 02 Nov 2012 10:51:42 -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 a4sm6052116pax.12.2012.11.02.10.51.40 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 02 Nov 2012 10:51:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 2 Nov 2012 18:51:01 +0100 Message-Id: <1351878665-32413-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1351878665-32413-1-git-send-email-pbonzini@redhat.com> References: <1351878665-32413-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.160.45 Cc: aliguori@us.ibm.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. Reviewed-by: Orit Wasserman Signed-off-by: Paolo Bonzini --- 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 014c60f..2ce7770 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 a4cd83f..c678b23 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; } void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **errp) diff --git a/migration-tcp.c b/migration-tcp.c index 1a12f17..bb27ce8 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 5dc49cd..9b5521e 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; }