From patchwork Fri Nov 2 17:50:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 196736 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 9709A2C00D2 for ; Sat, 3 Nov 2012 05:28:32 +1100 (EST) Received: from localhost ([::1]:59179 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TULPm-0003bt-Fy for incoming@patchwork.ozlabs.org; Fri, 02 Nov 2012 13:52:18 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38596) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TULP9-0002Ip-9F for qemu-devel@nongnu.org; Fri, 02 Nov 2012 13:51:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TULP7-0005Td-Kz for qemu-devel@nongnu.org; Fri, 02 Nov 2012 13:51:39 -0400 Received: from mail-pa0-f45.google.com ([209.85.220.45]:52142) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TULP7-0005Nu-Ep for qemu-devel@nongnu.org; Fri, 02 Nov 2012 13:51:37 -0400 Received: by mail-pa0-f45.google.com with SMTP id fb10so2536065pad.4 for ; Fri, 02 Nov 2012 10:51:37 -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=Hyni3p7/qYmpp5M0hRsj4trAUkF5hUyedrs1Qq7/bQk=; b=MjBH0YQwGWQRgDHJfW/RQxBI0V0ZIoYrUBeexiHvrRbu3Rcr9/gVPacWoNtB/+CG1q Awx8NxIJL1AzyVVvPnQbxaF4zLE/gVm/w/rfJbjGdcjTuKYgqVFHx4pP1SYOmt7PeqbB M4dmZCNtk0RhdRV9u2vZraW5WKHCLr+rWMvrGyyb1aPHHAKW4y+Lj7bE1n3AyC6LJ/Jw llkT300cH7tOpFmSvxuc6gf4E2UwF/VOkQq1LojHfXz+VZaRnnvdaZdMa47xzXKyXWs0 Ao/7tGqRX/W1cqEYngue9EcgOi8A2wReseuN1oCqQ9ZmnukbIc5K4NltKaTtVRPfBfPK EHRw== Received: by 10.68.189.102 with SMTP id gh6mr8446824pbc.37.1351878696949; Fri, 02 Nov 2012 10:51:36 -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.33 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 02 Nov 2012 10:51:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 2 Nov 2012 18:50:59 +0100 Message-Id: <1351878665-32413-7-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.220.45 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 06/12] migration: use migrate_fd_close in migrate_fd_cleanup 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 migrate_fd_cleanup will usually close the file descriptor via buffered_file_close's call to migrate_fd_close. However, in the case of s->file == NULL it is "inlining" migrate_fd_close (almost: there is a direct close() instead of using s->close(s)). To fix the inconsistency and clean up the code, allow multiple calls to migrate_fd_close and use the function in migrate_fd_cleanup. Signed-off-by: Paolo Bonzini --- migration.c | 19 ++++++++----------- 1 file modificato, 8 inserzioni(+), 11 rimozioni(-) diff --git a/migration.c b/migration.c index 300ab75..a63596f 100644 --- a/migration.c +++ b/migration.c @@ -243,21 +243,13 @@ static int migrate_fd_cleanup(MigrationState *s) { int ret = 0; - if (s->fd != -1) { - qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); - } - if (s->file) { DPRINTF("closing file\n"); ret = qemu_fclose(s->file); s->file = NULL; } - if (s->fd != -1) { - close(s->fd); - s->fd = -1; - } - + migrate_fd_close(s); return ret; } @@ -393,8 +385,13 @@ int migrate_fd_wait_for_unfreeze(MigrationState *s) int migrate_fd_close(MigrationState *s) { - qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); - return s->close(s); + int rc = 0; + if (s->fd != -1) { + qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL); + rc = s->close(s); + s->fd = -1; + } + return rc; } void add_migration_state_change_notifier(Notifier *notify)