From nobody Sun Feb 8 22:57:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149030342575753.37325695242646; Thu, 23 Mar 2017 14:10:25 -0700 (PDT) Received: from localhost ([::1]:58656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1crA00-0003zS-9z for importer@patchew.org; Thu, 23 Mar 2017 17:10:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cr9d5-0008Hi-JM for qemu-devel@nongnu.org; Thu, 23 Mar 2017 16:46:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cr9d3-0000al-Dz for qemu-devel@nongnu.org; Thu, 23 Mar 2017 16:46:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40226) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cr9d3-0000ZI-5Q for qemu-devel@nongnu.org; Thu, 23 Mar 2017 16:46:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 29A2F437F7C for ; Thu, 23 Mar 2017 20:46:41 +0000 (UTC) Received: from secure.mitica (ovpn-116-230.ams2.redhat.com [10.36.116.230]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30FD553; Thu, 23 Mar 2017 20:46:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 29A2F437F7C Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=quintela@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 29A2F437F7C From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 23 Mar 2017 21:45:29 +0100 Message-Id: <20170323204544.12015-37-quintela@redhat.com> In-Reply-To: <20170323204544.12015-1-quintela@redhat.com> References: <20170323204544.12015-1-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 23 Mar 2017 20:46:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 36/51] ram: Move QEMUFile into RAMState X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We receive the file from save_live operations and we don't use it until 3 or 4 levels of calls down. Signed-off-by: Juan Quintela Reviewed-by: Dr. David Alan Gilbert --- migration/ram.c | 84 +++++++++++++++++++++++++----------------------------= ---- 1 file changed, 37 insertions(+), 47 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 7667e73..6a39704 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -756,21 +756,20 @@ static void migration_bitmap_sync(RAMState *rs) * Returns the number of pages written. * * @rs: current RAM state - * @f: QEMUFile where to send the data * @block: block that contains the page we want to send * @offset: offset inside the block for the page * @p: pointer to the page */ -static int save_zero_page(RAMState *rs, QEMUFile *f, RAMBlock *block, - ram_addr_t offset, uint8_t *p) +static int save_zero_page(RAMState *rs, RAMBlock *block, ram_addr_t offset, + uint8_t *p) { int pages =3D -1; =20 if (is_zero_range(p, TARGET_PAGE_SIZE)) { rs->zero_pages++; rs->bytes_transferred +=3D - save_page_header(f, block, offset | RAM_SAVE_FLAG_COMPRESS); - qemu_put_byte(f, 0); + save_page_header(rs->f, block, offset | RAM_SAVE_FLAG_COMPRESS= ); + qemu_put_byte(rs->f, 0); rs->bytes_transferred +=3D 1; pages =3D 1; } @@ -798,12 +797,11 @@ static void ram_release_pages(MigrationState *ms, con= st char *rbname, * * @rs: current RAM state * @ms: current migration state - * @f: QEMUFile where to send the data * @block: block that contains the page we want to send * @offset: offset inside the block for the page * @last_stage: if we are at the completion stage */ -static int ram_save_page(RAMState *rs, MigrationState *ms, QEMUFile *f, +static int ram_save_page(RAMState *rs, MigrationState *ms, PageSearchStatus *pss, bool last_stage) { int pages =3D -1; @@ -819,7 +817,7 @@ static int ram_save_page(RAMState *rs, MigrationState *= ms, QEMUFile *f, =20 /* In doubt sent page as normal */ bytes_xmit =3D 0; - ret =3D ram_control_save_page(f, block->offset, + ret =3D ram_control_save_page(rs->f, block->offset, offset, TARGET_PAGE_SIZE, &bytes_xmit); if (bytes_xmit) { rs->bytes_transferred +=3D bytes_xmit; @@ -842,7 +840,7 @@ static int ram_save_page(RAMState *rs, MigrationState *= ms, QEMUFile *f, } } } else { - pages =3D save_zero_page(rs, f, block, offset, p); + pages =3D save_zero_page(rs, block, offset, p); if (pages > 0) { /* Must let xbzrle know, otherwise a previous (now 0'd) cached * page would be stale @@ -864,14 +862,14 @@ static int ram_save_page(RAMState *rs, MigrationState= *ms, QEMUFile *f, =20 /* XBZRLE overflow or normal page */ if (pages =3D=3D -1) { - rs->bytes_transferred +=3D save_page_header(f, block, + rs->bytes_transferred +=3D save_page_header(rs->f, block, offset | RAM_SAVE_FLAG_PAGE= ); if (send_async) { - qemu_put_buffer_async(f, p, TARGET_PAGE_SIZE, + qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE, migrate_release_ram() & migration_in_postcopy(ms)); } else { - qemu_put_buffer(f, p, TARGET_PAGE_SIZE); + qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE); } rs->bytes_transferred +=3D TARGET_PAGE_SIZE; pages =3D 1; @@ -906,7 +904,7 @@ static int do_compress_ram_page(QEMUFile *f, RAMBlock *= block, return bytes_sent; } =20 -static void flush_compressed_data(RAMState *rs, QEMUFile *f) +static void flush_compressed_data(RAMState *rs) { int idx, len, thread_count; =20 @@ -926,7 +924,7 @@ static void flush_compressed_data(RAMState *rs, QEMUFil= e *f) for (idx =3D 0; idx < thread_count; idx++) { qemu_mutex_lock(&comp_param[idx].mutex); if (!comp_param[idx].quit) { - len =3D qemu_put_qemu_file(f, comp_param[idx].file); + len =3D qemu_put_qemu_file(rs->f, comp_param[idx].file); rs->bytes_transferred +=3D len; } qemu_mutex_unlock(&comp_param[idx].mutex); @@ -940,8 +938,8 @@ static inline void set_compress_params(CompressParam *p= aram, RAMBlock *block, param->offset =3D offset; } =20 -static int compress_page_with_multi_thread(RAMState *rs, QEMUFile *f, - RAMBlock *block, ram_addr_t off= set) +static int compress_page_with_multi_thread(RAMState *rs, RAMBlock *block, + ram_addr_t offset) { int idx, thread_count, bytes_xmit =3D -1, pages =3D -1; =20 @@ -951,7 +949,7 @@ static int compress_page_with_multi_thread(RAMState *rs= , QEMUFile *f, for (idx =3D 0; idx < thread_count; idx++) { if (comp_param[idx].done) { comp_param[idx].done =3D false; - bytes_xmit =3D qemu_put_qemu_file(f, comp_param[idx].file); + bytes_xmit =3D qemu_put_qemu_file(rs->f, comp_param[idx].f= ile); qemu_mutex_lock(&comp_param[idx].mutex); set_compress_params(&comp_param[idx], block, offset); qemu_cond_signal(&comp_param[idx].cond); @@ -980,13 +978,11 @@ static int compress_page_with_multi_thread(RAMState *= rs, QEMUFile *f, * * @rs: current RAM state * @ms: current migration state - * @f: QEMUFile where to send the data * @block: block that contains the page we want to send * @offset: offset inside the block for the page * @last_stage: if we are at the completion stage */ static int ram_save_compressed_page(RAMState *rs, MigrationState *ms, - QEMUFile *f, PageSearchStatus *pss, bool last_stage) { int pages =3D -1; @@ -998,7 +994,7 @@ static int ram_save_compressed_page(RAMState *rs, Migra= tionState *ms, =20 p =3D block->host + offset; =20 - ret =3D ram_control_save_page(f, block->offset, + ret =3D ram_control_save_page(rs->f, block->offset, offset, TARGET_PAGE_SIZE, &bytes_xmit); if (bytes_xmit) { rs->bytes_transferred +=3D bytes_xmit; @@ -1020,20 +1016,20 @@ static int ram_save_compressed_page(RAMState *rs, M= igrationState *ms, * is used to avoid resending the block name. */ if (block !=3D rs->last_sent_block) { - flush_compressed_data(rs, f); - pages =3D save_zero_page(rs, f, block, offset, p); + flush_compressed_data(rs); + pages =3D save_zero_page(rs, block, offset, p); if (pages =3D=3D -1) { /* Make sure the first page is sent out before other pages= */ - bytes_xmit =3D save_page_header(f, block, offset | + bytes_xmit =3D save_page_header(rs->f, block, offset | RAM_SAVE_FLAG_COMPRESS_PAGE); - blen =3D qemu_put_compression_data(f, p, TARGET_PAGE_SIZE, + blen =3D qemu_put_compression_data(rs->f, p, TARGET_PAGE_S= IZE, migrate_compress_level()); if (blen > 0) { rs->bytes_transferred +=3D bytes_xmit + blen; rs->norm_pages++; pages =3D 1; } else { - qemu_file_set_error(f, blen); + qemu_file_set_error(rs->f, blen); error_report("compressed data failed!"); } } @@ -1042,9 +1038,9 @@ static int ram_save_compressed_page(RAMState *rs, Mig= rationState *ms, } } else { offset |=3D RAM_SAVE_FLAG_CONTINUE; - pages =3D save_zero_page(rs, f, block, offset, p); + pages =3D save_zero_page(rs, block, offset, p); if (pages =3D=3D -1) { - pages =3D compress_page_with_multi_thread(rs, f, block, of= fset); + pages =3D compress_page_with_multi_thread(rs, block, offse= t); } else { ram_release_pages(ms, block->idstr, pss->offset, pages); } @@ -1061,13 +1057,12 @@ static int ram_save_compressed_page(RAMState *rs, M= igrationState *ms, * Returns if a page is found * * @rs: current RAM state - * @f: QEMUFile where to send the data * @pss: data about the state of the current dirty page scan * @again: set to false if the search has scanned the whole of RAM * @ram_addr_abs: pointer into which to store the address of the dirty page * within the global ram_addr space */ -static bool find_dirty_block(RAMState *rs, QEMUFile *f, PageSearchStatus *= pss, +static bool find_dirty_block(RAMState *rs, PageSearchStatus *pss, bool *again, ram_addr_t *ram_addr_abs) { pss->offset =3D migration_bitmap_find_dirty(rs, pss->block, pss->offse= t, @@ -1095,7 +1090,7 @@ static bool find_dirty_block(RAMState *rs, QEMUFile *= f, PageSearchStatus *pss, /* If xbzrle is on, stop using the data compression at this * point. In theory, xbzrle can do better than compression. */ - flush_compressed_data(rs, f); + flush_compressed_data(rs); compression_switch =3D false; } } @@ -1314,12 +1309,11 @@ err: * * @rs: current RAM state * @ms: current migration state - * @f: QEMUFile where to send the data * @pss: data about the page we want to send * @last_stage: if we are at the completion stage * @dirty_ram_abs: address of the start of the dirty page in ram_addr_t sp= ace */ -static int ram_save_target_page(RAMState *rs, MigrationState *ms, QEMUFile= *f, +static int ram_save_target_page(RAMState *rs, MigrationState *ms, PageSearchStatus *pss, bool last_stage, ram_addr_t dirty_ram_abs) @@ -1330,9 +1324,9 @@ static int ram_save_target_page(RAMState *rs, Migrati= onState *ms, QEMUFile *f, if (migration_bitmap_clear_dirty(rs, dirty_ram_abs)) { unsigned long *unsentmap; if (compression_switch && migrate_use_compression()) { - res =3D ram_save_compressed_page(rs, ms, f, pss, last_stage); + res =3D ram_save_compressed_page(rs, ms, pss, last_stage); } else { - res =3D ram_save_page(rs, ms, f, pss, last_stage); + res =3D ram_save_page(rs, ms, pss, last_stage); } =20 if (res < 0) { @@ -1367,12 +1361,11 @@ static int ram_save_target_page(RAMState *rs, Migra= tionState *ms, QEMUFile *f, * * @rs: current RAM state * @ms: current migration state - * @f: QEMUFile where to send the data * @pss: data about the page we want to send * @last_stage: if we are at the completion stage * @dirty_ram_abs: Address of the start of the dirty page in ram_addr_t sp= ace */ -static int ram_save_host_page(RAMState *rs, MigrationState *ms, QEMUFile *= f, +static int ram_save_host_page(RAMState *rs, MigrationState *ms, PageSearchStatus *pss, bool last_stage, ram_addr_t dirty_ram_abs) @@ -1381,8 +1374,7 @@ static int ram_save_host_page(RAMState *rs, Migration= State *ms, QEMUFile *f, size_t pagesize =3D qemu_ram_pagesize(pss->block); =20 do { - tmppages =3D ram_save_target_page(rs, ms, f, pss, last_stage, - dirty_ram_abs); + tmppages =3D ram_save_target_page(rs, ms, pss, last_stage, dirty_r= am_abs); if (tmppages < 0) { return tmppages; } @@ -1405,14 +1397,13 @@ static int ram_save_host_page(RAMState *rs, Migrati= onState *ms, QEMUFile *f, * Returns the number of pages written where zero means no dirty pages * * @rs: current RAM state - * @f: QEMUFile where to send the data * @last_stage: if we are at the completion stage * * On systems where host-page-size > target-page-size it will send all the * pages in a host page that are dirty. */ =20 -static int ram_find_and_save_block(RAMState *rs, QEMUFile *f, bool last_st= age) +static int ram_find_and_save_block(RAMState *rs, bool last_stage) { PageSearchStatus pss; MigrationState *ms =3D migrate_get_current(); @@ -1440,12 +1431,11 @@ static int ram_find_and_save_block(RAMState *rs, QE= MUFile *f, bool last_stage) =20 if (!found) { /* priority queue empty, so just search for something dirty */ - found =3D find_dirty_block(rs, f, &pss, &again, &dirty_ram_abs= ); + found =3D find_dirty_block(rs, &pss, &again, &dirty_ram_abs); } =20 if (found) { - pages =3D ram_save_host_page(rs, ms, f, &pss, last_stage, - dirty_ram_abs); + pages =3D ram_save_host_page(rs, ms, &pss, last_stage, dirty_r= am_abs); } } while (!pages && again); =20 @@ -2145,7 +2135,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) while ((ret =3D qemu_file_rate_limit(f)) =3D=3D 0) { int pages; =20 - pages =3D ram_find_and_save_block(rs, f, false); + pages =3D ram_find_and_save_block(rs, false); /* no more pages to sent */ if (pages =3D=3D 0) { done =3D 1; @@ -2167,7 +2157,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque) } i++; } - flush_compressed_data(rs, f); + flush_compressed_data(rs); rcu_read_unlock(); =20 /* @@ -2215,14 +2205,14 @@ static int ram_save_complete(QEMUFile *f, void *opa= que) while (true) { int pages; =20 - pages =3D ram_find_and_save_block(rs, f, !migration_in_colo_state(= )); + pages =3D ram_find_and_save_block(rs, !migration_in_colo_state()); /* no more blocks to sent */ if (pages =3D=3D 0) { break; } } =20 - flush_compressed_data(rs, f); + flush_compressed_data(rs); ram_control_after_iterate(f, RAM_CONTROL_FINISH); =20 rcu_read_unlock(); --=20 2.9.3