From nobody Thu Jul 10 04:25:22 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=1653391443; cv=none; d=zohomail.com; s=zohoarc; b=bs7/oYqkbhT2pg2efY64PbQx/iBSMj/EcTpnivSb4vBKBMDHiuFjpjM5k4oBQaT7dlSwmnMktk0Ca3ZZixS5r8o7EFYX2lPJ69IIDwHd8bRS6xY/c1Ckwek8Dty/1pnGIEiKryHPoBBCfpSmonoefPqzV07GbM3i0pJ9dcsXCVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1653391443; 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=7vOYCuiFOHwKEcxHDxUfpctKHL9UqUSBew1/Mv+uIlM=; b=IjolC0AdzzS28AOIyzAkl13uKuHAVl4JR9IAFz0rYW5Ow/oUDByM4E51XJ1cpGpaSs4rcyZrAOXno6P0RgKYbrfCjtsEYEfM7R1uj71wTQAKbHFwC03OB3Zp0r6NJc+VzbEc/Q4tSoRnebQD0Ja+BvIJQG9bnc4pXOkxpf1S+BQ= 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 1653391443590397.80309296872304; Tue, 24 May 2022 04:24:03 -0700 (PDT) Received: from localhost ([::1]:53268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntSdu-0003xy-En for importer2@patchew.org; Tue, 24 May 2022 07:24:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60734) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntSJR-0005lx-KS for qemu-devel@nongnu.org; Tue, 24 May 2022 07:02:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:55155) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntSJP-0003Nt-C8 for qemu-devel@nongnu.org; Tue, 24 May 2022 07:02:53 -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-192-JWh46h7tMeetnjnxg-q8pQ-1; Tue, 24 May 2022 07:02:49 -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 23B17101A54E; Tue, 24 May 2022 11:02:49 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.159]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5446112131B; Tue, 24 May 2022 11:02:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653390170; 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=7vOYCuiFOHwKEcxHDxUfpctKHL9UqUSBew1/Mv+uIlM=; b=RQDbpf6Dx7WpFitq6VfOtSEZ7LzvRJvOJ11ZKupoUd3EN1BvAQF+P0wehdY0wLkByxLgVT QLJJxqBwj1exiKSVpx+/8T393gMSEh8xTmWOwCvjih1x00Kf9SiAN7km4poaxZySG9HYNA VRo80Uqsdvy/fd/5cHkVtq4aPCoofok= X-MC-Unique: JWh46h7tMeetnjnxg-q8pQ-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 06/20] migration: rename qemu_ftell to qemu_file_total_transferred Date: Tue, 24 May 2022 12:02:21 +0100 Message-Id: <20220524110235.145079-7-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.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=ham 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: 1653391445197100001 The name 'ftell' gives the misleading impression that the QEMUFile objects are seekable. This is not the case, as in general we just have an opaque stream. The users of this method are only interested in the total bytes processed. This switches to a new name that reflects the intended usage. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Dr. David Alan Gilbert --- migration/block.c | 10 +++++----- migration/migration.c | 2 +- migration/qemu-file.c | 4 ++-- migration/qemu-file.h | 40 ++++++++++++++++++++++++++++++++++++++-- migration/savevm.c | 6 +++--- migration/vmstate.c | 4 ++-- 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/migration/block.c b/migration/block.c index 077a413325..823453c977 100644 --- a/migration/block.c +++ b/migration/block.c @@ -756,8 +756,8 @@ static int block_save_setup(QEMUFile *f, void *opaque) static int block_save_iterate(QEMUFile *f, void *opaque) { int ret; - int64_t last_ftell =3D qemu_ftell(f); - int64_t delta_ftell; + int64_t last_bytes =3D qemu_file_total_transferred(f); + int64_t delta_bytes; =20 trace_migration_block_save("iterate", block_mig_state.submitted, block_mig_state.transferred); @@ -809,10 +809,10 @@ static int block_save_iterate(QEMUFile *f, void *opaq= ue) } =20 qemu_put_be64(f, BLK_MIG_FLAG_EOS); - delta_ftell =3D qemu_ftell(f) - last_ftell; - if (delta_ftell > 0) { + delta_bytes =3D qemu_file_total_transferred(f) - last_bytes; + if (delta_bytes > 0) { return 1; - } else if (delta_ftell < 0) { + } else if (delta_bytes < 0) { return -1; } else { return 0; diff --git a/migration/migration.c b/migration/migration.c index 31739b2af9..ab1e9610ef 100644 --- a/migration/migration.c +++ b/migration/migration.c @@ -3544,7 +3544,7 @@ static MigThrError migration_detect_error(MigrationSt= ate *s) /* How many bytes have we transferred since the beginning of the migration= */ static uint64_t migration_total_bytes(MigrationState *s) { - return qemu_ftell(s->to_dst_file) + ram_counters.multifd_bytes; + return qemu_file_total_transferred(s->to_dst_file) + ram_counters.mult= ifd_bytes; } =20 static void migration_calculate_complete(MigrationState *s) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index b21da4c5bf..664ac77067 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -657,7 +657,7 @@ int qemu_get_byte(QEMUFile *f) return result; } =20 -int64_t qemu_ftell_fast(QEMUFile *f) +int64_t qemu_file_total_transferred_fast(QEMUFile *f) { int64_t ret =3D f->total_transferred; int i; @@ -669,7 +669,7 @@ int64_t qemu_ftell_fast(QEMUFile *f) return ret; } =20 -int64_t qemu_ftell(QEMUFile *f) +int64_t qemu_file_total_transferred(QEMUFile *f) { qemu_fflush(f); return f->total_transferred; diff --git a/migration/qemu-file.h b/migration/qemu-file.h index 3f36d4dc8c..febc961aa9 100644 --- a/migration/qemu-file.h +++ b/migration/qemu-file.h @@ -124,8 +124,44 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileO= ps *ops, bool has_ioc); void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks); int qemu_get_fd(QEMUFile *f); int qemu_fclose(QEMUFile *f); -int64_t qemu_ftell(QEMUFile *f); -int64_t qemu_ftell_fast(QEMUFile *f); + +/* + * qemu_file_total_transferred: + * + * Report the total number of bytes transferred with=20 + * this file. + * + * For writable files, any pending buffers will be + * flushed, so the reported value will be equal to + * the number of bytes transferred on the wire. + * + * For readable files, the reported value will be + * equal to the number of bytes transferred on the + * wire. + * + * Returns: the total bytes transferred + */ +int64_t qemu_file_total_transferred(QEMUFile *f); + +/* + * qemu_file_total_transferred_fast: + * + * Report the total number of bytes transferred with=20 + * this file. + * + * For writable files, no pending buffers will be + * flushed, but the reported value will include the + * size of any queued buffers, on top of the amount + * actually transferred. + * + * For readable files, the reported value will be + * equal to the number of bytes transferred on the + * wire. + * + * Returns: the total bytes transferred and queued + */ +int64_t qemu_file_total_transferred_fast(QEMUFile *f); + /* * put_buffer without copying the buffer. * The buffer should be available till it is sent asynchronously. diff --git a/migration/savevm.c b/migration/savevm.c index d9076897b8..75d05f1a84 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -916,9 +916,9 @@ static void vmstate_save_old_style(QEMUFile *f, SaveSta= teEntry *se, { int64_t old_offset, size; =20 - old_offset =3D qemu_ftell_fast(f); + old_offset =3D qemu_file_total_transferred_fast(f); se->ops->save_state(f, se->opaque); - size =3D qemu_ftell_fast(f) - old_offset; + size =3D qemu_file_total_transferred_fast(f) - old_offset; =20 if (vmdesc) { json_writer_int64(vmdesc, "size", size); @@ -2887,7 +2887,7 @@ bool save_snapshot(const char *name, bool overwrite, = const char *vmstate, goto the_end; } ret =3D qemu_savevm_state(f, errp); - vm_state_size =3D qemu_ftell(f); + vm_state_size =3D qemu_file_total_transferred(f); ret2 =3D qemu_fclose(f); if (ret < 0) { goto the_end; diff --git a/migration/vmstate.c b/migration/vmstate.c index 36ae8b9e19..b0551e82c6 100644 --- a/migration/vmstate.c +++ b/migration/vmstate.c @@ -360,7 +360,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *vmsd, void *curr_elem =3D first_elem + size * i; =20 vmsd_desc_field_start(vmsd, vmdesc_loop, field, i, n_elems= ); - old_offset =3D qemu_ftell_fast(f); + old_offset =3D qemu_file_total_transferred_fast(f); if (field->flags & VMS_ARRAY_OF_POINTER) { assert(curr_elem); curr_elem =3D *(void **)curr_elem; @@ -390,7 +390,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDesc= ription *vmsd, return ret; } =20 - written_bytes =3D qemu_ftell_fast(f) - old_offset; + written_bytes =3D qemu_file_total_transferred_fast(f) - ol= d_offset; vmsd_desc_field_end(vmsd, vmdesc_loop, field, written_byte= s, i); =20 /* Compressed arrays only care about the first element */ --=20 2.36.1