From nobody Mon Dec 15 01:40:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1503559653313208.29838097824972; Thu, 24 Aug 2017 00:27:33 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 938CC20276; Thu, 24 Aug 2017 07:27:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 74B4978AB9; Thu, 24 Aug 2017 07:27:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3FCD53FAD2; Thu, 24 Aug 2017 07:27:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v7O7RUKD008992 for ; Thu, 24 Aug 2017 03:27:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6EAFB78159; Thu, 24 Aug 2017 07:27:30 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A25C6D2A9 for ; Thu, 24 Aug 2017 07:27:26 +0000 (UTC) Received: from relay.sw.ru (mailhub.sw.ru [195.214.232.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30A1F8763A for ; Thu, 24 Aug 2017 07:27:25 +0000 (UTC) Received: from dim-vz7.qa.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v7O6vmwl024560 for ; Thu, 24 Aug 2017 09:57:50 +0300 (MSK) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 938CC20276 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 938CC20276 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 30A1F8763A Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=virtuozzo.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=nshirokovskiy@virtuozzo.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 30A1F8763A From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Thu, 24 Aug 2017 09:56:51 +0300 Message-Id: <1503557813-825347-15-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1503557813-825347-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1503557813-825347-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Delayed for 00:29:10 by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 24 Aug 2017 07:27:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 24 Aug 2017 07:27:25 +0000 (UTC) for IP:'195.214.232.25' DOMAIN:'mailhub.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 195.214.232.25 mailhub.sw.ru 195.214.232.25 mailhub.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 REBASE 14/16] qemu: migation: resolve race on getting job info and stopping block jobs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 24 Aug 2017 07:27:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" During stopping mirror block jobs vm lock is droped on awating block job events, thus next scenario is possible: 1. stop mirror block job is sent 2. migration routine awaits for block job event 3. mirror job stopped and event send 4. getting migration job info routine asks for block job info and as qemu block job stopped and disapperaed we get no block job info. As a result block job info for the disk will be missed in the result. To handle this case let's ask qemu for block job info and store it just before stopping mirror jobs. Next in getting migration job info routine we detect this race condition and take stored block job info instead. I guess info will be just slightly outdated and at least will not go backwards. --- src/qemu/qemu_migration.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index afe1804..906f8fe 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -1588,6 +1588,7 @@ qemuMigrationWaitForCompletion(virQEMUDriverPtr drive= r, ignore_value(qemuMigrationFetchMigrationStats(driver, vm, asyncJob, &jobInfo->stats, tru= e)); =20 + qemuMigrationFetchMirrorStats(driver, vm, asyncJob, NULL); qemuDomainJobInfoUpdateTime(jobInfo); qemuDomainJobInfoUpdateDowntime(jobInfo); VIR_FREE(priv->job.completed); @@ -5934,6 +5935,9 @@ qemuMigrationReset(virQEMUDriverPtr driver, } =20 =20 +/* Query qemu for block job stats. If @stats is not NULL then sum them up + * in @stats, otherwise store them in disks private area for each disk. + */ int qemuMigrationFetchMirrorStats(virQEMUDriverPtr driver, virDomainObjPtr vm, @@ -5968,14 +5972,33 @@ qemuMigrationFetchMirrorStats(virQEMUDriverPtr driv= er, virDomainDiskDefPtr disk =3D vm->def->disks[i]; qemuDomainDiskPrivatePtr diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(dis= k); qemuMonitorBlockJobInfoPtr data; + unsigned long long transferred; + unsigned long long total; =20 - if (!diskPriv->migrating || - !(data =3D virHashLookup(blockinfo, disk->info.alias))) + if (!diskPriv->migrating) continue; =20 - stats->disk_transferred +=3D data->cur; - stats->disk_total +=3D data->end; - stats->disk_remaining +=3D data->end - data->cur; + data =3D virHashLookup(blockinfo, disk->info.alias); + + if (stats) { + if (data) { + transferred =3D data->cur; + total =3D data->end; + } else { + /* Race condition. There is no blockjob for disk already + * but is has been migrating via nbd. Thanx we store job + * len value just before stopping mirror jobs which can be + * good approximation at this point. + */ + total =3D transferred =3D diskPriv->blockJobLength; + } + + stats->disk_transferred +=3D transferred; + stats->disk_total +=3D total; + stats->disk_remaining +=3D total - transferred; + } else if (data) { + diskPriv->blockJobLength =3D data->end; + } } =20 virHashFree(blockinfo); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list