From nobody Thu Jul 10 07:09:04 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1653393320; cv=none; d=zohomail.com; s=zohoarc; b=C3ZdgW98ss/1WsIC0BdvVtGpKSCfOhdAcA1J21fiuxDlo81moqnQ2hjc75TPxsIeIRrHwN8LK5dMq2w4Rv2klPD7ay//PIhaM3pjwwSk/+thEQP5U0CBixIFfh6OdGfqi2eClffxnY75pY6Tfw02DAimNDWj0j8CfG6dmwD8gXQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653393320; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jdx67keC66P+vSbuOgYtmolesP7R4jEOHd8z2UsDAfQ=; b=mFWwXW/vWdVQqmJd3LkvsR5rJ3Xm7D3JD9NMNoWzAxB5DFE0JU23JjfTD0ndVg1KAyhCHUXKaaQTJgpCfVmqqhFs/jzVgF4wwD8S46mOiBlHaYvu5dZlnyjYDlbeL/HTvkPtUqn9MJ1T9E+czzWwyYudhATTxvY79aV8jaAIQ2Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1653393320814967.7902793119272; Tue, 24 May 2022 04:55:20 -0700 (PDT) Received: from localhost ([::1]:55698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntT8B-0001iD-QC for importer2@patchew.org; Tue, 24 May 2022 07:55:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntSJc-0005tb-FI for qemu-devel@nongnu.org; Tue, 24 May 2022 07:03:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42391) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntSJZ-0003QK-6e for qemu-devel@nongnu.org; Tue, 24 May 2022 07:03:04 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-111-BVCf9McIOCWdZ_vHsIJDhQ-1; Tue, 24 May 2022 07:02:57 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E36C1811E81; Tue, 24 May 2022 11:02:56 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD3971121315; Tue, 24 May 2022 11:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653390180; 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=jdx67keC66P+vSbuOgYtmolesP7R4jEOHd8z2UsDAfQ=; b=ZUoErybOwqq5LyLeX65h7qaYcWjtwhc0ErQ2XxzEu1vw2Uemk8Xf/1Ydy+ONwI9+bttqcO 4pS+T/TIHeAYvdqtjuxTuvWHBA7531JuMZPabgZTCav2krD/G0cH5QMaHpvPt0a8wx8UTC 1hbtfGEqaPNco9sJ7HzWtRW6uFTtByA= X-MC-Unique: BVCf9McIOCWdZ_vHsIJDhQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , "Dr. David Alan Gilbert" , qemu-block@nongnu.org, Stefan Hajnoczi , Hailiang Zhang , Juan Quintela , Fam Zheng Subject: [PATCH 11/20] migration: hardcode assumption that QEMUFile is backed with QIOChannel Date: Tue, 24 May 2022 12:02:26 +0100 Message-Id: <20220524110235.145079-12-berrange@redhat.com> In-Reply-To: <20220524110235.145079-1-berrange@redhat.com> References: <20220524110235.145079-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.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+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1653393321919100001 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. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert --- 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 =3D { 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); } =20 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 6badc8b0ec..ea1e8da0cb 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; =20 /* * 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; }; =20 /* @@ -81,7 +79,7 @@ int qemu_file_shutdown(QEMUFile *f) if (!f->ops->shut_down) { return -ENOSYS; } - ret =3D f->ops->shut_down(f->opaque, true, true, NULL); + ret =3D f->ops->shut_down(f->ioc, true, true, NULL); =20 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); } =20 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; } =20 -QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_io= c) +QEMUFile *qemu_fopen_ops(QIOChannel *ioc, const QEMUFileOps *ops) { QEMUFile *f; =20 f =3D g_new0(QEMUFile, 1); =20 - f->opaque =3D opaque; + f->ioc =3D ioc; f->ops =3D ops; - f->has_ioc =3D has_ioc; + return f; } =20 @@ -242,7 +240,7 @@ void qemu_fflush(QEMUFile *f) } if (f->iovcnt > 0) { expect =3D iov_size(f->iov, f->iovcnt); - ret =3D f->ops->writev_buffer(f->opaque, f->iov, f->iovcnt, f->tot= al_transferred, + ret =3D f->ops->writev_buffer(f->ioc, f->iov, f->iovcnt, f->total_= transferred, &local_error); =20 qemu_iovec_release_ram(f); @@ -358,7 +356,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) return 0; } =20 - len =3D f->ops->get_buffer(f->opaque, f->buf + pending, f->total_trans= ferred, + len =3D f->ops->get_buffer(f->ioc, f->buf + pending, f->total_transfer= red, IO_BUF_SIZE - pending, &local_error); if (len > 0) { f->buf_size +=3D len; @@ -394,7 +392,7 @@ int qemu_fclose(QEMUFile *f) ret =3D qemu_file_get_error(f); =20 if (f->ops->close) { - int ret2 =3D f->ops->close(f->opaque, NULL); + int ret2 =3D f->ops->close(f->ioc, NULL); if (ret >=3D 0) { ret =3D 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); } } =20 /* - * 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_b= drv() - * 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_destro= y() - * 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 6310071f90..0458b1d3b6 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -118,7 +118,7 @@ typedef struct QEMUFileHooks { QEMURamSaveFunc *save_page; } QEMUFileHooks; =20 -QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_io= c); +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); --=20 2.36.1