From patchwork Mon Jun 20 11:01:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 12887389 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB975C43334 for ; Mon, 20 Jun 2022 11:18:57 +0000 (UTC) Received: from localhost ([::1]:46104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o3FQl-00012R-Pr for qemu-devel@archiver.kernel.org; Mon, 20 Jun 2022 07:18:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3FB2-0003D2-03 for qemu-devel@nongnu.org; Mon, 20 Jun 2022 07:02:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37673) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o3FAx-0007aI-8T for qemu-devel@nongnu.org; Mon, 20 Jun 2022 07:02:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655722953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=61fhm0GaMZVyHDlPdf9W0SZF2CrvDtdMMbZHwDSJcOw=; b=AKvXCyC+BZzI8+U/booK6uMu4ShwmNNBQlkmo0i8pvc5avVMrzIwZjzHcQibBRyghCSQAk qjjDx4fPmAGXWxshwPOfvh+8DMJAu7isDYSlaX9QsokIogDNTDfPWJesHEo6kQhxnjQJwM THN5ixd4byc0r05F9RGfk3G4Oh+oLng= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-408-4BVD1PS1MI6JjDB29B-82Q-1; Mon, 20 Jun 2022 07:02:30 -0400 X-MC-Unique: 4BVD1PS1MI6JjDB29B-82Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D292B384F804; Mon, 20 Jun 2022 11:02:29 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.144]) by smtp.corp.redhat.com (Postfix) with ESMTP id 357A3C08087; Mon, 20 Jun 2022 11:02:28 +0000 (UTC) From: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , Juan Quintela , "Dr. David Alan Gilbert" , Stefan Hajnoczi , Hailiang Zhang , Fam Zheng , Hailiang Zhang Subject: [PATCH v2 12/21] migration: hardcode assumption that QEMUFile is backed with QIOChannel Date: Mon, 20 Jun 2022 12:01:56 +0100 Message-Id: <20220620110205.1357829-13-berrange@redhat.com> In-Reply-To: <20220620110205.1357829-1-berrange@redhat.com> References: <20220620110205.1357829-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Received-SPF: pass client-ip=170.10.133.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The only callers of qemu_fopen_ops pass 'true' for the 'has_ioc' parameter, so hardcode this assumption in QEMUFile, by passing in the QIOChannel object as a non-opaque parameter. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Daniel P. Berrangé Reviewed-by: Juan Quintela --- migration/qemu-file-channel.c | 4 ++-- migration/qemu-file.c | 35 +++++++++++++++++------------------ migration/qemu-file.h | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/migration/qemu-file-channel.c b/migration/qemu-file-channel.c index bb5a5752df..ce8eced417 100644 --- a/migration/qemu-file-channel.c +++ b/migration/qemu-file-channel.c @@ -184,11 +184,11 @@ static const QEMUFileOps channel_output_ops = { QEMUFile *qemu_fopen_channel_input(QIOChannel *ioc) { object_ref(OBJECT(ioc)); - return qemu_fopen_ops(ioc, &channel_input_ops, true); + return qemu_fopen_ops(ioc, &channel_input_ops); } QEMUFile *qemu_fopen_channel_output(QIOChannel *ioc) { object_ref(OBJECT(ioc)); - return qemu_fopen_ops(ioc, &channel_output_ops, true); + return qemu_fopen_ops(ioc, &channel_output_ops); } diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 006880abd3..ce48d7a5d8 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -37,7 +37,7 @@ struct QEMUFile { const QEMUFileOps *ops; const QEMUFileHooks *hooks; - void *opaque; + QIOChannel *ioc; /* * Maximum amount of data in bytes to transfer during one @@ -65,8 +65,6 @@ struct QEMUFile { Error *last_error_obj; /* has the file has been shutdown */ bool shutdown; - /* Whether opaque points to a QIOChannel */ - bool has_ioc; }; /* @@ -81,7 +79,7 @@ int qemu_file_shutdown(QEMUFile *f) if (!f->ops->shut_down) { return -ENOSYS; } - ret = f->ops->shut_down(f->opaque, true, true, NULL); + ret = f->ops->shut_down(f->ioc, true, true, NULL); if (!f->last_error) { qemu_file_set_error(f, -EIO); @@ -98,7 +96,7 @@ QEMUFile *qemu_file_get_return_path(QEMUFile *f) if (!f->ops->get_return_path) { return NULL; } - return f->ops->get_return_path(f->opaque); + return f->ops->get_return_path(f->ioc); } bool qemu_file_mode_is_not_valid(const char *mode) @@ -113,15 +111,15 @@ bool qemu_file_mode_is_not_valid(const char *mode) return false; } -QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc) +QEMUFile *qemu_fopen_ops(QIOChannel *ioc, const QEMUFileOps *ops) { QEMUFile *f; f = g_new0(QEMUFile, 1); - f->opaque = opaque; + f->ioc = ioc; f->ops = ops; - f->has_ioc = has_ioc; + return f; } @@ -242,7 +240,7 @@ void qemu_fflush(QEMUFile *f) } if (f->iovcnt > 0) { expect = iov_size(f->iov, f->iovcnt); - ret = f->ops->writev_buffer(f->opaque, f->iov, f->iovcnt, f->total_transferred, + ret = f->ops->writev_buffer(f->ioc, f->iov, f->iovcnt, f->total_transferred, &local_error); qemu_iovec_release_ram(f); @@ -358,7 +356,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) return 0; } - len = f->ops->get_buffer(f->opaque, f->buf + pending, f->total_transferred, + len = f->ops->get_buffer(f->ioc, f->buf + pending, f->total_transferred, IO_BUF_SIZE - pending, &local_error); if (len > 0) { f->buf_size += len; @@ -394,7 +392,7 @@ int qemu_fclose(QEMUFile *f) ret = qemu_file_get_error(f); if (f->ops->close) { - int ret2 = f->ops->close(f->opaque, NULL); + int ret2 = f->ops->close(f->ioc, NULL); if (ret >= 0) { ret = ret2; } @@ -861,18 +859,19 @@ void qemu_put_counted_string(QEMUFile *f, const char *str) void qemu_file_set_blocking(QEMUFile *f, bool block) { if (f->ops->set_blocking) { - f->ops->set_blocking(f->opaque, block, NULL); + f->ops->set_blocking(f->ioc, block, NULL); } } /* - * Return the ioc object if it's a migration channel. Note: it can return NULL - * for callers passing in a non-migration qemufile. E.g. see qemu_fopen_bdrv() - * and its usage in e.g. load_snapshot(). So we need to check against NULL - * before using it. If without the check, migration_incoming_state_destroy() - * could fail for load_snapshot(). + * qemu_file_get_ioc: + * + * Get the ioc object for the file, without incrementing + * the reference count. + * + * Returns: the ioc object */ QIOChannel *qemu_file_get_ioc(QEMUFile *file) { - return file->has_ioc ? QIO_CHANNEL(file->opaque) : NULL; + return file->ioc; } diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 277f1d5a62..3a1ecc0e34 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -118,7 +118,7 @@ typedef struct QEMUFileHooks { QEMURamSaveFunc *save_page; } QEMUFileHooks; -QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc); +QEMUFile *qemu_fopen_ops(QIOChannel *ioc, const QEMUFileOps *ops); void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f);