From nobody Thu May 16 17:36:17 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668012952; cv=none; d=zohomail.com; s=zohoarc; b=k06LKSAO872kpL5DQXfYbdFha5mmjJPCud/sD3Cx9n6EHIVWRLuWjJtBd7cSDScSSjKZY4+Y16+RrpcwFaR1B09jhEWaVdLi+ZgohfeOiKCj5SYr19hoNr+cc/9doLExNlVh4FCY+caiAFxKVnhisUsnDiuSGf2abdk+Wu0MKUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668012952; 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=J+SaDJyh8u65L6WmNX4P9dHWfAjiiCMvWED/Ot9+1Jk=; b=WngKOyhx1VqqTtOOGnfVIc5Ou5CIfKjzVW0+ioxlIrZ++rGNjWG/P3T1u2UUsvEYYIxOMfwrwebmkim251Coe1DCjGFChcFQSy5LEivC7ukxOHOwyiTC9CXD33kajjRZtkSsA3+F5MvGtB0gtBymIQSUtsVnHVArUAL1/HlCjGQ= 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+importer=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 1668012952265590.8991228274308; Wed, 9 Nov 2022 08:55:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osoMB-0005pU-Is; Wed, 09 Nov 2022 11:55:23 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osoM9-0005mQ-JA for qemu-devel@nongnu.org; Wed, 09 Nov 2022 11:55:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osoM7-0007D0-6x for qemu-devel@nongnu.org; Wed, 09 Nov 2022 11:55:17 -0500 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-637-9ZoWYkqiPry_qJYMsOKuhw-1; Wed, 09 Nov 2022 11:55:12 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 049422823825; Wed, 9 Nov 2022 16:54:56 +0000 (UTC) Received: from localhost (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B20932024CC6; Wed, 9 Nov 2022 16:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668012914; 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=J+SaDJyh8u65L6WmNX4P9dHWfAjiiCMvWED/Ot9+1Jk=; b=czgkuOHcGVEiVMduiLEmtURduAiP5BLeDKgzl5FgufQwE+sHlxILlR+I85oc3O1lVTIzAL vZ+2+c0FkZN7Oc5SZd/782mIprmP3gmf3MslUXZarU7GiVMYg/jiB/pz+Ab7IXE2R8crNw B5WA9rJMr14+ywelIlObfJhuk5REljc= X-MC-Unique: 9ZoWYkqiPry_qJYMsOKuhw-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , John Snow , Vladimir Sementsov-Ogievskiy Subject: [PATCH for-7.2 1/5] block/mirror: Do not wait for active writes Date: Wed, 9 Nov 2022 17:54:48 +0100 Message-Id: <20221109165452.67927-2-hreitz@redhat.com> In-Reply-To: <20221109165452.67927-1-hreitz@redhat.com> References: <20221109165452.67927-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668012954488100007 Content-Type: text/plain; charset="utf-8" Waiting for all active writes to settle before daring to create a background copying operation means that we will never do background operations while the guest does anything (in write-blocking mode), and therefore cannot converge. Yes, we also will not diverge, but actually converging would be even nicer. It is unclear why we did decide to wait for all active writes to settle before creating a background operation, but it just does not seem necessary. Active writes will put themselves into the in_flight bitmap and thus properly block actually conflicting background requests. It is important for active requests to wait on overlapping background requests, which we do in active_write_prepare(). However, so far it was not documented why it is important. Add such documentation now, and also to the other call of mirror_wait_on_conflicts(), so that it becomes more clear why and when requests need to actively wait for other requests to settle. Another thing to note is that of course we need to ensure that there are no active requests when the job completes, but that is done by virtue of the BDS being drained anyway, so there cannot be any active requests at that point. With this change, we will need to explicitly keep track of how many bytes are in flight in active requests so that job_progress_set_remaining() in mirror_run() can set the correct number of remaining bytes. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D2123297 Signed-off-by: Hanna Reitz Reviewed-by: Kevin Wolf --- block/mirror.c | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 1a75a47cc3..e5467b0053 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -82,6 +82,7 @@ typedef struct MirrorBlockJob { int max_iov; bool initial_zeroing_ongoing; int in_active_write_counter; + int64_t active_write_bytes_in_flight; bool prepared; bool in_drain; } MirrorBlockJob; @@ -494,6 +495,13 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBl= ockJob *s) } bdrv_dirty_bitmap_unlock(s->dirty_bitmap); =20 + /* + * Wait for concurrent requests to @offset. The next loop will limit = the + * copied area based on in_flight_bitmap so we only copy an area that = does + * not overlap with concurrent in-flight requests. Still, we would li= ke to + * copy something, so wait until there are at least no more requests t= o the + * very beginning of the area. + */ mirror_wait_on_conflicts(NULL, s, offset, 1); =20 job_pause_point(&s->common.job); @@ -988,12 +996,6 @@ static int coroutine_fn mirror_run(Job *job, Error **e= rrp) int64_t cnt, delta; bool should_complete; =20 - /* Do not start passive operations while there are active - * writes in progress */ - while (s->in_active_write_counter) { - mirror_wait_for_any_operation(s, true); - } - if (s->ret < 0) { ret =3D s->ret; goto immediate_exit; @@ -1010,7 +1012,9 @@ static int coroutine_fn mirror_run(Job *job, Error **= errp) /* cnt is the number of dirty bytes remaining and s->bytes_in_flig= ht is * the number of bytes currently being processed; together those a= re * the current remaining operation length */ - job_progress_set_remaining(&s->common.job, s->bytes_in_flight + cn= t); + job_progress_set_remaining(&s->common.job, + s->bytes_in_flight + cnt + + s->active_write_bytes_in_flight); =20 /* Note that even when no rate limit is applied we need to yield * periodically with no pending I/O so that bdrv_drain_all() retur= ns. @@ -1071,6 +1075,10 @@ static int coroutine_fn mirror_run(Job *job, Error *= *errp) =20 s->in_drain =3D true; bdrv_drained_begin(bs); + + /* Must be zero because we are drained */ + assert(s->in_active_write_counter =3D=3D 0); + cnt =3D bdrv_get_dirty_count(s->dirty_bitmap); if (cnt > 0 || mirror_flush(s) < 0) { bdrv_drained_end(bs); @@ -1306,6 +1314,7 @@ do_sync_target_write(MirrorBlockJob *job, MirrorMetho= d method, } =20 job_progress_increase_remaining(&job->common.job, bytes); + job->active_write_bytes_in_flight +=3D bytes; =20 switch (method) { case MIRROR_METHOD_COPY: @@ -1327,6 +1336,7 @@ do_sync_target_write(MirrorBlockJob *job, MirrorMetho= d method, abort(); } =20 + job->active_write_bytes_in_flight -=3D bytes; if (ret >=3D 0) { job_progress_update(&job->common.job, bytes); } else { @@ -1375,6 +1385,19 @@ static MirrorOp *coroutine_fn active_write_prepare(M= irrorBlockJob *s, =20 s->in_active_write_counter++; =20 + /* + * Wait for concurrent requests affecting the area. If there are alre= ady + * running requests that are copying off now-to-be stale data in the a= rea, + * we must wait for them to finish before we begin writing fresh data = to the + * target so that the write operations appear in the correct order. + * Note that background requests (see mirror_iteration()) in contrast = only + * wait for conflicting requests at the start of the dirty area, and t= hen + * (based on the in_flight_bitmap) truncate the area to copy so it wil= l not + * conflict with any requests beyond that. For active writes, however= , we + * cannot truncate that area. The request from our parent must be blo= cked + * until the area is copied in full. Therefore, we must wait for the = whole + * area to become free of concurrent requests. + */ mirror_wait_on_conflicts(op, s, offset, bytes); =20 bitmap_set(s->in_flight_bitmap, start_chunk, end_chunk - start_chunk); --=20 2.36.1 From nobody Thu May 16 17:36:17 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668012951; cv=none; d=zohomail.com; s=zohoarc; b=ZjEhmWL+6grd3xWPuyIwPryjIOgaztEOhF+me6wQztHocSHLjbDL0tJ2g5D6Ir/0Wy31Npzkz1g2REDJrN5AtLuo9UuQebMEgv1J84Jn4pKnJJyQ4Te1koEGEYu2JHFfBdhlKsqiqbjVRLZnCqtHzsOtygjz1vtlgPupMXHp4Jc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668012951; 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=GoPyUzlp4ewB5aVuOklPFzlcWGFhkDh3wdADGNvjG3w=; b=XyvQTqiItAu8bkVc0fAPT/CTk4A3IQLY578CseMq+aXxy19wUpA98pAnHf4ipmNN54J4tyv9exdUaHxa/zttT7h6+wO+xuVceTF13B5KEBvJN6YBOyeRLvuVYH4mwgej9xTZJfyVRw124GRZenglDo1uT2y0Q4iGafXTCSHWFpY= 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+importer=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 1668012951473932.0618534576112; Wed, 9 Nov 2022 08:55:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osoM9-0005m9-JG; Wed, 09 Nov 2022 11:55:17 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osoM7-0005iQ-Q9 for qemu-devel@nongnu.org; Wed, 09 Nov 2022 11:55:15 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osoM6-0007Cg-EA for qemu-devel@nongnu.org; Wed, 09 Nov 2022 11:55:15 -0500 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-335-SbZwEd_YMaqppxSOD049cQ-1; Wed, 09 Nov 2022 11:55:10 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FC512833B0B; Wed, 9 Nov 2022 16:54:57 +0000 (UTC) Received: from localhost (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A7D02166B30; Wed, 9 Nov 2022 16:54:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668012913; 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=GoPyUzlp4ewB5aVuOklPFzlcWGFhkDh3wdADGNvjG3w=; b=gYCmKqrzwUR6DIYYG2rSzJLm021EpzXgG1IWJD+5h1Y8E5QhbHGfc5G1TOJnouMzhY9N6d 1nyZxnkcaPgCbOH0O6iaD9PSP8p3QwZ8TVG+p9esjf5N3vLATQjycG3vRqa0/dEK4YUXij 9nMzfjh7+b/ziRH7Jf4RGsXygvKMiGo= X-MC-Unique: SbZwEd_YMaqppxSOD049cQ-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , John Snow , Vladimir Sementsov-Ogievskiy Subject: [PATCH for-7.2 2/5] block/mirror: Drop mirror_wait_for_any_operation() Date: Wed, 9 Nov 2022 17:54:49 +0100 Message-Id: <20221109165452.67927-3-hreitz@redhat.com> In-Reply-To: <20221109165452.67927-1-hreitz@redhat.com> References: <20221109165452.67927-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668012952561100003 Content-Type: text/plain; charset="utf-8" mirror_wait_for_free_in_flight_slot() is the only remaining user of mirror_wait_for_any_operation(), so inline the latter into the former. Signed-off-by: Hanna Reitz Reviewed-by: Kevin Wolf --- block/mirror.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index e5467b0053..5b6f42392c 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -305,19 +305,21 @@ static int mirror_cow_align(MirrorBlockJob *s, int64_= t *offset, } =20 static inline void coroutine_fn -mirror_wait_for_any_operation(MirrorBlockJob *s, bool active) +mirror_wait_for_free_in_flight_slot(MirrorBlockJob *s) { MirrorOp *op; =20 QTAILQ_FOREACH(op, &s->ops_in_flight, next) { - /* Do not wait on pseudo ops, because it may in turn wait on + /* + * Do not wait on pseudo ops, because it may in turn wait on * some other operation to start, which may in fact be the * caller of this function. Since there is only one pseudo op * at any given time, we will always find some real operation - * to wait on. */ - if (!op->is_pseudo_op && op->is_in_flight && - op->is_active_write =3D=3D active) - { + * to wait on. + * Also, do not wait on active operations, because they do not + * use up in-flight slots. + */ + if (!op->is_pseudo_op && op->is_in_flight && !op->is_active_write)= { qemu_co_queue_wait(&op->waiting_requests, NULL); return; } @@ -325,13 +327,6 @@ mirror_wait_for_any_operation(MirrorBlockJob *s, bool = active) abort(); } =20 -static inline void coroutine_fn -mirror_wait_for_free_in_flight_slot(MirrorBlockJob *s) -{ - /* Only non-active operations use up in-flight slots */ - mirror_wait_for_any_operation(s, false); -} - /* Perform a mirror copy operation. * * *op->bytes_handled is set to the number of bytes copied after and --=20 2.36.1 From nobody Thu May 16 17:36:17 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668013012; cv=none; d=zohomail.com; s=zohoarc; b=ed82egKlm8S1In3Nf/bgAhQdLmyDo5Q6VNrEc3QNjRS9IbLXFOyEq8ZV4EsrZdVjepvMDAzGFhGDyzYMSOutyFr7YmL4kgLtno4oIlNN4Yw35wYwY0OelOZQByd/1Df7a6nwEcHTZDMA1OoW7CelhRaARDL2GKhpNJ+vejfmuxU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668013012; 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=IiaJTOHZCCD8Eo7QY8zmxfdJeeuL3NHpRNHYnl3Eh7k=; b=O56tF2Eny7hUFsCPqtTQHNiD4rn2CAS4tlwMa/afaRcayXUw4EiHkPJmF3pMoj+a2HnZH7TL1keg83Bf4ShMDc5KKHz3g7UKaGJXZSpuNumV5qUSgAYrJqDHcOFDCqaUayDHzatn3e3Db6lL6X8eDVVgClvHvnujuar6jShk6Dk= 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+importer=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 1668013012831274.3463085192142; Wed, 9 Nov 2022 08:56:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osoMr-00066s-Ex; Wed, 09 Nov 2022 11:56:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osoMU-00062i-3H for qemu-devel@nongnu.org; Wed, 09 Nov 2022 11:55:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osoMJ-0007Kg-Hr for qemu-devel@nongnu.org; Wed, 09 Nov 2022 11:55:37 -0500 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-131-gOGBI3gsNTGAMX6jMH3D2w-1; Wed, 09 Nov 2022 11:55:12 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 218A41C08979; Wed, 9 Nov 2022 16:54:59 +0000 (UTC) Received: from localhost (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D2A3320290A6; Wed, 9 Nov 2022 16:54:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668012924; 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=IiaJTOHZCCD8Eo7QY8zmxfdJeeuL3NHpRNHYnl3Eh7k=; b=U0wMuYJboW7Q1QZ0hHOaTwZf4rkryrcc90TZMGjY5RUFAc7JERAxU1LB7pLyDgZ4ry0Vzz J4jseswciLea1m8i+qt7KCUuAs6BUe0PcT4F3ZgP2Cd8NoZUChwBK9SSOdQ8/YQN949vhI DTA7MrJm2meQCDZtRs2oTKXZkHAoYWw= X-MC-Unique: gOGBI3gsNTGAMX6jMH3D2w-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , John Snow , Vladimir Sementsov-Ogievskiy Subject: [PATCH for-7.2 3/5] block/mirror: Fix NULL s->job in active writes Date: Wed, 9 Nov 2022 17:54:50 +0100 Message-Id: <20221109165452.67927-4-hreitz@redhat.com> In-Reply-To: <20221109165452.67927-1-hreitz@redhat.com> References: <20221109165452.67927-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668013015056100003 Content-Type: text/plain; charset="utf-8" There is a small gap in mirror_start_job() before putting the mirror filter node into the block graph (bdrv_append() call) and the actual job being created. Before the job is created, MirrorBDSOpaque.job is NULL. It is possible that requests come in when bdrv_drained_end() is called, and those requests would see MirrorBDSOpaque.job =3D=3D NULL. Have our filter node handle that case gracefully. Signed-off-by: Hanna Reitz Reviewed-by: Kevin Wolf --- block/mirror.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 5b6f42392c..251adc5ae0 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1438,11 +1438,13 @@ static int coroutine_fn bdrv_mirror_top_do_write(Bl= ockDriverState *bs, MirrorOp *op =3D NULL; MirrorBDSOpaque *s =3D bs->opaque; int ret =3D 0; - bool copy_to_target; + bool copy_to_target =3D false; =20 - copy_to_target =3D s->job->ret >=3D 0 && - !job_is_cancelled(&s->job->common.job) && - s->job->copy_mode =3D=3D MIRROR_COPY_MODE_WRITE_BLOCK= ING; + if (s->job) { + copy_to_target =3D s->job->ret >=3D 0 && + !job_is_cancelled(&s->job->common.job) && + s->job->copy_mode =3D=3D MIRROR_COPY_MODE_WRITE_B= LOCKING; + } =20 if (copy_to_target) { op =3D active_write_prepare(s->job, offset, bytes); @@ -1487,11 +1489,13 @@ static int coroutine_fn bdrv_mirror_top_pwritev(Blo= ckDriverState *bs, QEMUIOVector bounce_qiov; void *bounce_buf; int ret =3D 0; - bool copy_to_target; + bool copy_to_target =3D false; =20 - copy_to_target =3D s->job->ret >=3D 0 && - !job_is_cancelled(&s->job->common.job) && - s->job->copy_mode =3D=3D MIRROR_COPY_MODE_WRITE_BLOCK= ING; + if (s->job) { + copy_to_target =3D s->job->ret >=3D 0 && + !job_is_cancelled(&s->job->common.job) && + s->job->copy_mode =3D=3D MIRROR_COPY_MODE_WRITE_B= LOCKING; + } =20 if (copy_to_target) { /* The guest might concurrently modify the data to write; but --=20 2.36.1 From nobody Thu May 16 17:36:17 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668013043; cv=none; d=zohomail.com; s=zohoarc; b=CU1iYWW5/A7YeMhNzqVGGNU+17AV7ntg2lJk0ft6m4JCPtaBmsI0hywHqO1PnsGJmE/w1ANGUBYVderv6M7FYHeqMbFIxLbxcjg9ILOMq2u/pdFK9Oon7NHSyQAqAaXkHe2oA2Oiths7WlZV+bz3MNS6YecAde98HfmPHWTBCwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668013043; 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=Yr2WYAovp6EyKYty2HAlgQtGC2F574eMQsRRtaYymH8=; b=EdNwV7fWhHMCTqfE4stIr96bA4AJ8mlWk+UUwUf+SNXcEdiqZ6Uyv+A3FMyMbJbrUFRsWSffw6TUAvWMzfK/FYw8uR7Sou98win+qu49gdd9CuibutvRiPsTAOikEqVYBVlYC1adKPZW31SUQPdoyilQzUcWg9KmK4MCc+szWoQ= 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+importer=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 1668013043131529.5517106579937; Wed, 9 Nov 2022 08:57:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osoMI-0005sq-2e; Wed, 09 Nov 2022 11:55:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osoM9-0005me-NQ for qemu-devel@nongnu.org; Wed, 09 Nov 2022 11:55:17 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osoM6-0007Cn-Mt for qemu-devel@nongnu.org; Wed, 09 Nov 2022 11:55:17 -0500 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-183-IVcvoe-zOVy62wr2nGmclw-1; Wed, 09 Nov 2022 11:55:12 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EFBF11C09B8A; Wed, 9 Nov 2022 16:55:00 +0000 (UTC) Received: from localhost (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8CBFB2166B29; Wed, 9 Nov 2022 16:55:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668012914; 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=Yr2WYAovp6EyKYty2HAlgQtGC2F574eMQsRRtaYymH8=; b=JI1rKU0zgEh+IKyNbbcp88BSKl+1OHCbnXMfqnOv6P7csrD5k2EOn2c69JWvSvA4NedJqI v+7fqjgx7HGnn9Foo+d7+bSlOanvN+kxMnOImOAi5yrd5W7aHYFZq+JWSqzAUwE9vDgiTP A2vO7xkVveeTQfSB1hVCT35FClke4DU= X-MC-Unique: IVcvoe-zOVy62wr2nGmclw-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , John Snow , Vladimir Sementsov-Ogievskiy Subject: [PATCH for-7.2 4/5] iotests/151: Test that active mirror progresses Date: Wed, 9 Nov 2022 17:54:51 +0100 Message-Id: <20221109165452.67927-5-hreitz@redhat.com> In-Reply-To: <20221109165452.67927-1-hreitz@redhat.com> References: <20221109165452.67927-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668013045142100007 Content-Type: text/plain; charset="utf-8" Before this series, a mirror job in write-blocking mode would pause issuing background requests while active requests are in flight. Thus, if the source is constantly in use by active requests, no actual progress can be made. This series should have fixed that, making the mirror job issue background requests even while active requests are in flight. Have a new test case in 151 verify this. Signed-off-by: Hanna Reitz Reviewed-by: Kevin Wolf --- tests/qemu-iotests/151 | 180 ++++++++++++++++++++++++++++++++++++- tests/qemu-iotests/151.out | 4 +- 2 files changed, 181 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/151 b/tests/qemu-iotests/151 index 93d14193d0..0a052e5050 100755 --- a/tests/qemu-iotests/151 +++ b/tests/qemu-iotests/151 @@ -19,7 +19,10 @@ # along with this program. If not, see . # =20 +import math import os +import subprocess +from typing import List import iotests from iotests import qemu_img =20 @@ -50,7 +53,7 @@ class TestActiveMirror(iotests.QMPTestCase): self.vm =3D iotests.VM() self.vm.add_drive_raw(self.vm.qmp_to_opts(blk_source)) self.vm.add_blockdev(self.vm.qmp_to_opts(blk_target)) - self.vm.add_device('virtio-blk,drive=3Dsource') + self.vm.add_device('virtio-blk,id=3Dvblk,drive=3Dsource') self.vm.launch() =20 def tearDown(self): @@ -192,6 +195,181 @@ class TestActiveMirror(iotests.QMPTestCase): self.potential_writes_in_flight =3D False =20 =20 +class TestThrottledWithNbdExport(iotests.QMPTestCase): + image_len =3D 128 * 1024 * 1024 # MB + iops =3D 16 + background_processes: List['subprocess.Popen[str]'] =3D [] + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, source_img, '128M') + qemu_img('create', '-f', iotests.imgfmt, target_img, '128M') + + self.vm =3D iotests.VM() + self.vm.launch() + + result =3D self.vm.qmp('object-add', **{ + 'qom-type': 'throttle-group', + 'id': 'thrgr', + 'limits': { + 'iops-total': self.iops, + 'iops-total-max': self.iops + } + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'source-node', + 'driver': 'throttle', + 'throttle-group': 'thrgr', + 'file': { + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': source_img + } + } + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('blockdev-add', **{ + 'node-name': 'target-node', + 'driver': iotests.imgfmt, + 'file': { + 'driver': 'file', + 'filename': target_img + } + }) + self.assert_qmp(result, 'return', {}) + + self.nbd_sock =3D iotests.file_path('nbd.sock', + base_dir=3Diotests.sock_dir) + self.nbd_url =3D f'nbd+unix:///source-node?socket=3D{self.nbd_sock= }' + + result =3D self.vm.qmp('nbd-server-start', addr=3D{ + 'type': 'unix', + 'data': { + 'path': self.nbd_sock + } + }) + self.assert_qmp(result, 'return', {}) + + result =3D self.vm.qmp('block-export-add', id=3D'exp0', type=3D'nb= d', + node_name=3D'source-node', writable=3DTrue) + self.assert_qmp(result, 'return', {}) + + def tearDown(self): + # Wait for background requests to settle + try: + while True: + p =3D self.background_processes.pop() + while True: + try: + p.wait(timeout=3D0.0) + break + except subprocess.TimeoutExpired: + self.vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000= }') + except IndexError: + pass + + # Cancel ongoing block jobs + for job in self.vm.qmp('query-jobs')['return']: + self.vm.qmp('block-job-cancel', device=3Djob['id'], force=3DTr= ue) + + while True: + self.vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000}') + if len(self.vm.qmp('query-jobs')['return']) =3D=3D 0: + break + + self.vm.shutdown() + os.remove(source_img) + os.remove(target_img) + + def testUnderLoad(self): + ''' + Throttle the source node, then issue a whole bunch of external req= uests + while the mirror job (in write-blocking mode) is running. We want= to + see background requests being issued even while the source is under + full load by active writes, so that progress can be made towards R= EADY. + ''' + + # Fill the first half of the source image; do not fill the second = half, + # that is where we will have active requests occur. This ensures = that + # active mirroring itself will not directly contribute to the job's + # progress (because when the job was started, those areas were not + # intended to be copied, so active mirroring will only lead to not + # losing progress, but also not making any). + self.vm.hmp_qemu_io('source-node', + f'aio_write -P 1 0 {self.image_len // 2}') + self.vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000}') + + # Launch the mirror job + mirror_buf_size =3D 65536 + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + filter_node_name=3D'mirror-node', + device=3D'source-node', + target=3D'target-node', + sync=3D'full', + copy_mode=3D'write-blocking', + buf_size=3Dmirror_buf_size) + self.assert_qmp(result, 'return', {}) + + # We create the external requests via qemu-io processes on the NBD + # server. Have their offset start in the middle of the image so t= hey + # do not overlap with the background requests (which start from the + # beginning). + active_request_offset =3D self.image_len // 2 + active_request_len =3D 4096 + + # Create enough requests to saturate the node for 5 seconds + for _ in range(0, 5 * self.iops): + req =3D f'write -P 42 {active_request_offset} {active_request_= len}' + active_request_offset +=3D active_request_len + p =3D iotests.qemu_io_popen('-f', 'nbd', self.nbd_url, '-c', r= eq) + self.background_processes +=3D [p] + + # Now advance the clock one I/O operation at a time by the 4 secon= ds + # (i.e. one less than 5). We expect the mirror job to issue backg= round + # operations here, even though active requests are still in flight. + # The active requests will take precedence, however, because they = have + # been issued earlier than mirror's background requests. + # Once the active requests we have started above are done (i.e. af= ter 5 + # virtual seconds), we expect those background requests to be work= ed + # on. We only advance 4 seconds here to avoid race conditions. + for _ in range(0, 4 * self.iops): + step =3D math.ceil(1 * 1000 * 1000 * 1000 / self.iops) + self.vm.qtest(f'clock_step {step}') + + # Note how much remains to be done until the mirror job is finished + job_status =3D self.vm.qmp('query-jobs')['return'][0] + start_remaining =3D job_status['total-progress'] - \ + job_status['current-progress'] + + # Create a whole bunch of more active requests + for _ in range(0, 10 * self.iops): + req =3D f'write -P 42 {active_request_offset} {active_request_= len}' + active_request_offset +=3D active_request_len + p =3D iotests.qemu_io_popen('-f', 'nbd', self.nbd_url, '-c', r= eq) + self.background_processes +=3D [p] + + # Let the clock advance more. After 1 second, as noted above, we + # expect the background requests to be worked on. Give them a cou= ple + # of seconds (specifically 4) to see their impact. + for _ in range(0, 5 * self.iops): + step =3D math.ceil(1 * 1000 * 1000 * 1000 / self.iops) + self.vm.qtest(f'clock_step {step}') + + # Note how much remains to be done now. We expect this number to = be + # reduced thanks to those background requests. + job_status =3D self.vm.qmp('query-jobs')['return'][0] + end_remaining =3D job_status['total-progress'] - \ + job_status['current-progress'] + + # See that indeed progress was being made on the job, even while t= he + # node was saturated with active requests + self.assertGreater(start_remaining - end_remaining, 0) + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'raw'], supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/151.out b/tests/qemu-iotests/151.out index 89968f35d7..914e3737bd 100644 --- a/tests/qemu-iotests/151.out +++ b/tests/qemu-iotests/151.out @@ -1,5 +1,5 @@ -.... +..... ---------------------------------------------------------------------- -Ran 4 tests +Ran 5 tests =20 OK --=20 2.36.1 From nobody Thu May 16 17:36:17 2024 Delivered-To: importer@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+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668013040; cv=none; d=zohomail.com; s=zohoarc; b=DzrMgLyfrrsCJLRVjbrhM5qNXqwhA+32+5YzCv9ianQ5ewoTqzG8Hp88+HluOk59qSXmQO+SM/+T25/qZhBvlSwmFMMeTIGqbujxHVy/29uZWCHtkaq2x8tTovw2sPCYFJR1bTeBQuVLx3BaLeWiaUYtYRvYyOenKbYTDRGMP3Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668013040; 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=VPRM/Gm2AeRZAzAyn9NJklCrfWnXpb8KMjpS5jJN8P0=; b=ikOmULOPmDG3J5hMnbuG9ds8EQbkCECLczf9RomgYQ9xan72cpa6ALgBJsFlbeK0U0rcx9cj7PUCxOwL6s67UENilyt87x8LpsyylYOYhuLE/fy3KTb39F7pxdTeoUAknmUHpgWCpMg0zjPK1DfxpYVzKnEC0mKhAr1aKTjuf2c= 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+importer=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 1668013040907847.4605313312355; Wed, 9 Nov 2022 08:57:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osoMI-0005rU-2G; Wed, 09 Nov 2022 11:55:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osoMA-0005o7-KP for qemu-devel@nongnu.org; Wed, 09 Nov 2022 11:55:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1osoM8-0007Dd-Qf for qemu-devel@nongnu.org; Wed, 09 Nov 2022 11:55:18 -0500 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-249-GkzAZV7SMRyh133run84EA-1; Wed, 09 Nov 2022 11:55:14 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 935D51C0050A; Wed, 9 Nov 2022 16:55:02 +0000 (UTC) Received: from localhost (unknown [10.39.195.15]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F35F7AE5; Wed, 9 Nov 2022 16:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668012916; 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=VPRM/Gm2AeRZAzAyn9NJklCrfWnXpb8KMjpS5jJN8P0=; b=duwh3hij54cD92oZxYSXboR8acM/rBO6EFKWm2cQTrNwumHOMBOQJyZObOrl9XwuuqSQ9t fqli3GPXy6r21YmZiV6Y6vRZZUfnmvtErH1p2e9hKG/nwPjLgskp29M1bDeJgaWZI3y/ol Rlf712zYcXfWBzOL/yakLEtJB6LueEY= X-MC-Unique: GkzAZV7SMRyh133run84EA-1 From: Hanna Reitz To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, Hanna Reitz , Kevin Wolf , John Snow , Vladimir Sementsov-Ogievskiy Subject: [PATCH for-7.2 5/5] iotests/151: Test active requests on mirror start Date: Wed, 9 Nov 2022 17:54:52 +0100 Message-Id: <20221109165452.67927-6-hreitz@redhat.com> In-Reply-To: <20221109165452.67927-1-hreitz@redhat.com> References: <20221109165452.67927-1-hreitz@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=hreitz@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1668013043014100003 Content-Type: text/plain; charset="utf-8" Have write requests happen to the source node right when we start a mirror job. The mirror filter node may encounter MirrorBDSOpaque.job being NULL, but this should not cause a segfault. Signed-off-by: Hanna Reitz Reviewed-by: Kevin Wolf --- tests/qemu-iotests/151 | 53 +++++++++++++++++++++++++++++++++++--- tests/qemu-iotests/151.out | 4 +-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/tests/qemu-iotests/151 b/tests/qemu-iotests/151 index 0a052e5050..b4d1bc2553 100755 --- a/tests/qemu-iotests/151 +++ b/tests/qemu-iotests/151 @@ -22,7 +22,8 @@ import math import os import subprocess -from typing import List +import time +from typing import List, Optional import iotests from iotests import qemu_img =20 @@ -195,12 +196,15 @@ class TestActiveMirror(iotests.QMPTestCase): self.potential_writes_in_flight =3D False =20 =20 -class TestThrottledWithNbdExport(iotests.QMPTestCase): +class TestThrottledWithNbdExportBase(iotests.QMPTestCase): image_len =3D 128 * 1024 * 1024 # MB - iops =3D 16 + iops: Optional[int] =3D None background_processes: List['subprocess.Popen[str]'] =3D [] =20 def setUp(self): + # Must be set by subclasses + self.assertIsNotNone(self.iops) + qemu_img('create', '-f', iotests.imgfmt, source_img, '128M') qemu_img('create', '-f', iotests.imgfmt, target_img, '128M') =20 @@ -284,6 +288,10 @@ class TestThrottledWithNbdExport(iotests.QMPTestCase): os.remove(source_img) os.remove(target_img) =20 + +class TestLowThrottledWithNbdExport(TestThrottledWithNbdExportBase): + iops =3D 16 + def testUnderLoad(self): ''' Throttle the source node, then issue a whole bunch of external req= uests @@ -370,6 +378,45 @@ class TestThrottledWithNbdExport(iotests.QMPTestCase): self.assertGreater(start_remaining - end_remaining, 0) =20 =20 +class TestHighThrottledWithNbdExport(TestThrottledWithNbdExportBase): + iops =3D 1024 + + def testActiveOnCreation(self): + ''' + Issue requests on the mirror source node right as the mirror is + instated. It's possible that requests occur before the actual job= is + created, but after the node has been put into the graph. Write + requests across the node must in that case be forwarded to the sou= rce + node without attempting to mirror them (there is no job object yet= , so + attempting to access it would cause a segfault). + We do this with a lightly throttled node (i.e. quite high IOPS lim= it). + Using throttling seems to increase reproductivity, but if the limi= t is + too low, all requests allowed per second will be submitted before + mirror_start_job() gets to the problematic point. + ''' + + # Let qemu-img bench create write requests (enough for two seconds= on + # the virtual clock) + bench_args =3D ['bench', '-w', '-d', '1024', '-f', 'nbd', + '-c', str(self.iops * 2), self.nbd_url] + p =3D iotests.qemu_tool_popen(iotests.qemu_img_args + bench_args) + self.background_processes +=3D [p] + + # Give qemu-img bench time to start up and issue requests + time.sleep(1.0) + # Flush the request queue, so new requests can come in right as we + # start blockdev-mirror + self.vm.qtest(f'clock_step {1 * 1000 * 1000 * 1000}') + + result =3D self.vm.qmp('blockdev-mirror', + job_id=3D'mirror', + device=3D'source-node', + target=3D'target-node', + sync=3D'full', + copy_mode=3D'write-blocking') + self.assert_qmp(result, 'return', {}) + + if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2', 'raw'], supported_protocols=3D['file']) diff --git a/tests/qemu-iotests/151.out b/tests/qemu-iotests/151.out index 914e3737bd..3f8a935a08 100644 --- a/tests/qemu-iotests/151.out +++ b/tests/qemu-iotests/151.out @@ -1,5 +1,5 @@ -..... +...... ---------------------------------------------------------------------- -Ran 5 tests +Ran 6 tests =20 OK --=20 2.36.1