From patchwork Fri Apr 9 12:04:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 12193989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC521C43461 for ; Fri, 9 Apr 2021 12:07:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 789A8610A4 for ; Fri, 9 Apr 2021 12:07:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 789A8610A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:35664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUpv5-0001Mp-I0 for qemu-devel@archiver.kernel.org; Fri, 09 Apr 2021 08:07:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43616) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUpsO-000811-F7 for qemu-devel@nongnu.org; Fri, 09 Apr 2021 08:04:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:56854) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUpsF-0008CF-Mj for qemu-devel@nongnu.org; Fri, 09 Apr 2021 08:04:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617969869; 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=FkZP2zq258xND6bWKPiyXr/bfL8VH+g2g0DWI6QgFA4=; b=fWmHzQhatw6vxrt3JPypHbZMkJytXFPe49V4KpWxOUNCvkU/9IeNjp26Z4/3AyvNgMs3gD RjQzbRO2jcjDgPwXc94KX41SSuvTWONvNOt1d0TwnYe979VtWWFvF8ZMLXiAqv7kCrmm4E zfwhBuA8mHbIqHV3kcHsAvHL3LLYmtw= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-459-tJd3-XtOPLeQwOR22hC_3Q-1; Fri, 09 Apr 2021 08:04:27 -0400 X-MC-Unique: tJd3-XtOPLeQwOR22hC_3Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF7C08030B5; Fri, 9 Apr 2021 12:04:26 +0000 (UTC) Received: from localhost (ovpn-114-67.ams2.redhat.com [10.36.114.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6A13719C71; Fri, 9 Apr 2021 12:04:26 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 1/4] mirror: Move open_backing_file to exit_common Date: Fri, 9 Apr 2021 14:04:18 +0200 Message-Id: <20210409120422.144040-2-mreitz@redhat.com> In-Reply-To: <20210409120422.144040-1-mreitz@redhat.com> References: <20210409120422.144040-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=mreitz@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_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" This is a graph change and therefore should be done in job-finalize (which is what invokes mirror_exit_common()). Signed-off-by: Max Reitz --- block/mirror.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index d7e54c0ff7..f1f936bf1a 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -689,6 +689,14 @@ static int mirror_exit_common(Job *job) ret = -EPERM; } } + } else if (!abort && s->backing_mode == MIRROR_OPEN_BACKING_CHAIN) { + assert(!bdrv_backing_chain_next(target_bs)); + ret = bdrv_open_backing_file(bdrv_skip_filters(target_bs), NULL, + "backing", &local_err); + if (ret < 0) { + error_report_err(local_err); + local_err = NULL; + } } if (s->to_replace) { @@ -1107,9 +1115,6 @@ immediate_exit: static void mirror_complete(Job *job, Error **errp) { MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job); - BlockDriverState *target; - - target = blk_bs(s->target); if (!s->synced) { error_setg(errp, "The active block job '%s' cannot be completed", @@ -1117,17 +1122,6 @@ static void mirror_complete(Job *job, Error **errp) return; } - if (s->backing_mode == MIRROR_OPEN_BACKING_CHAIN) { - int ret; - - assert(!bdrv_backing_chain_next(target)); - ret = bdrv_open_backing_file(bdrv_skip_filters(target), NULL, - "backing", errp); - if (ret < 0) { - return; - } - } - /* block all operations on to_replace bs */ if (s->replaces) { AioContext *replace_aio_context; From patchwork Fri Apr 9 12:04:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 12193995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8DD2C433B4 for ; Fri, 9 Apr 2021 12:12:06 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B2CA610A4 for ; Fri, 9 Apr 2021 12:12:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B2CA610A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:43634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUpzZ-0004oD-3T for qemu-devel@archiver.kernel.org; Fri, 09 Apr 2021 08:12:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43614) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUpsO-000810-F9 for qemu-devel@nongnu.org; Fri, 09 Apr 2021 08:04:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25630) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUpsH-0008DO-1O for qemu-devel@nongnu.org; Fri, 09 Apr 2021 08:04:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617969872; 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=LAc7L9+YJ0ealn7uzjhYK9sm6EPpUm39QMeBeWZZmLI=; b=UzoXO0rigOM9/X852USiEEfyBD2jIzOxviLnQ+eJoaWpQZ0Vo1iAw57uGie8U8pS7MZ3ew OGbpY4yrR55imoaRKSVcuayep1oeependyW0wOGFldej9ymCRdZdn49rwqpVCBx63w2SHR FsyQoCyjdt+FzoV3zZ+95VpZ4d/w+EE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-491-bZ4uwY5kMTK5NbaSkUPcvg-1; Fri, 09 Apr 2021 08:04:30 -0400 X-MC-Unique: bZ4uwY5kMTK5NbaSkUPcvg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4B368030B5; Fri, 9 Apr 2021 12:04:28 +0000 (UTC) Received: from localhost (ovpn-114-67.ams2.redhat.com [10.36.114.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 874992DAD0; Fri, 9 Apr 2021 12:04:28 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 2/4] mirror: Do not enter a paused job on completion Date: Fri, 9 Apr 2021 14:04:19 +0200 Message-Id: <20210409120422.144040-3-mreitz@redhat.com> In-Reply-To: <20210409120422.144040-1-mreitz@redhat.com> References: <20210409120422.144040-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=mreitz@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_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Currently, it is impossible to complete jobs on standby (i.e. paused ready jobs), but actually the only thing in mirror_complete() that does not work quite well with a paused job is the job_enter() at the end. If we make it conditional, this function works just fine even if the mirror job is paused. So technically this is a no-op, but obviously the intention is to accept block-job-complete even for jobs on standby, which we need this patch for first. Signed-off-by: Max Reitz --- block/mirror.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index f1f936bf1a..5a71bd8bbc 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1148,7 +1148,11 @@ static void mirror_complete(Job *job, Error **errp) } s->should_complete = true; - job_enter(job); + + /* If the job is paused, it will be re-entered when it is resumed */ + if (!job->paused) { + job_enter(job); + } } static void coroutine_fn mirror_pause(Job *job) From patchwork Fri Apr 9 12:04:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 12194001 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14FDEC433B4 for ; Fri, 9 Apr 2021 12:15:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F41C60241 for ; Fri, 9 Apr 2021 12:15:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F41C60241 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48504 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUq2b-0006rq-9o for qemu-devel@archiver.kernel.org; Fri, 09 Apr 2021 08:15:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUpsR-00084R-Qo for qemu-devel@nongnu.org; Fri, 09 Apr 2021 08:04:43 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37443) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUpsL-0008Ej-JR for qemu-devel@nongnu.org; Fri, 09 Apr 2021 08:04:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617969875; 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=dcJ4iKj56gsilCizTluXLSAk28HiI47nLspxmevo2Sw=; b=A+/Xw2LTOCa3JVsms4ghDyVthmQXPMpCC8I63iV5aoMVk0M+F4KbdZ+NwkqctIXD0bfpbW XBsYSL5UyaYsl091BVItO1MZhNNoiued2blI2w174r1LrJj08simmE8pPYAwGIGsYmndnu cPBrhIbpUQcXMraXfqfmrt3ULawZeWc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-450-wGaQICmGMLaTBNUxDF42Mw-1; Fri, 09 Apr 2021 08:04:32 -0400 X-MC-Unique: wGaQICmGMLaTBNUxDF42Mw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1AF7E8030A0; Fri, 9 Apr 2021 12:04:31 +0000 (UTC) Received: from localhost (ovpn-114-67.ams2.redhat.com [10.36.114.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B38E419C66; Fri, 9 Apr 2021 12:04:30 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 3/4] job: Allow complete for jobs on standby Date: Fri, 9 Apr 2021 14:04:20 +0200 Message-Id: <20210409120422.144040-4-mreitz@redhat.com> In-Reply-To: <20210409120422.144040-1-mreitz@redhat.com> References: <20210409120422.144040-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=mreitz@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_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" The only job that implements .complete is the mirror job, and it can handle completion requests just fine while the job is paused. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1945635 Signed-off-by: Max Reitz --- job.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/job.c b/job.c index 289edee143..4aff13d95a 100644 --- a/job.c +++ b/job.c @@ -56,7 +56,7 @@ bool JobVerbTable[JOB_VERB__MAX][JOB_STATUS__MAX] = { [JOB_VERB_PAUSE] = {0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}, [JOB_VERB_RESUME] = {0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}, [JOB_VERB_SET_SPEED] = {0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0}, - [JOB_VERB_COMPLETE] = {0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0}, + [JOB_VERB_COMPLETE] = {0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0}, [JOB_VERB_FINALIZE] = {0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0}, [JOB_VERB_DISMISS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, }; @@ -991,7 +991,7 @@ void job_complete(Job *job, Error **errp) if (job_apply_verb(job, JOB_VERB_COMPLETE, errp)) { return; } - if (job->pause_count || job_is_cancelled(job) || !job->driver->complete) { + if (job_is_cancelled(job) || !job->driver->complete) { error_setg(errp, "The active block job '%s' cannot be completed", job->id); return; From patchwork Fri Apr 9 12:04:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 12193993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56F46C433B4 for ; Fri, 9 Apr 2021 12:08:10 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C0336610A4 for ; Fri, 9 Apr 2021 12:08:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C0336610A4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUpvk-0001zm-4s for qemu-devel@archiver.kernel.org; Fri, 09 Apr 2021 08:08:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUpsQ-00083O-Tv for qemu-devel@nongnu.org; Fri, 09 Apr 2021 08:04:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24090) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUpsL-0008F3-N4 for qemu-devel@nongnu.org; Fri, 09 Apr 2021 08:04:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617969876; 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=1btMYzGXIGXUn8SpcmLoOJ91k5pXe5I8ELnO6r56N90=; b=GcTwmlROaSCRuvZC764K2dhOHOBxnIlHchFOujppnAw2D22fNqZEQ/QcFuAavIdXNqxD7Y 8n5vGfff1H1QXkLfyfS5nbs3I8gNhgHRPxbhsr4tYeY+PS3XwE6WrnaRZiXRRX+uFX2JY2 dRW415uYoLhfSo1x5ol4rzHi33I7Hzs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-471-YO3pFck4NXKUNyKmkoc6-g-1; Fri, 09 Apr 2021 08:04:34 -0400 X-MC-Unique: YO3pFck4NXKUNyKmkoc6-g-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 31BA28030A0; Fri, 9 Apr 2021 12:04:33 +0000 (UTC) Received: from localhost (ovpn-114-67.ams2.redhat.com [10.36.114.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C588260BE5; Fri, 9 Apr 2021 12:04:32 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 4/4] test-blockjob: Test job_wait_unpaused() Date: Fri, 9 Apr 2021 14:04:21 +0200 Message-Id: <20210409120422.144040-5-mreitz@redhat.com> In-Reply-To: <20210409120422.144040-1-mreitz@redhat.com> References: <20210409120422.144040-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=mreitz@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_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Create a job that remains on STANDBY after a drained section, and see that invoking job_wait_unpaused() will get it unstuck. Signed-off-by: Max Reitz --- tests/unit/test-blockjob.c | 121 +++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/tests/unit/test-blockjob.c b/tests/unit/test-blockjob.c index 7519847912..dcacfa6c7c 100644 --- a/tests/unit/test-blockjob.c +++ b/tests/unit/test-blockjob.c @@ -16,6 +16,7 @@ #include "block/blockjob_int.h" #include "sysemu/block-backend.h" #include "qapi/qmp/qdict.h" +#include "iothread.h" static const BlockJobDriver test_block_job_driver = { .job_driver = { @@ -375,6 +376,125 @@ static void test_cancel_concluded(void) cancel_common(s); } +/* (See test_yielding_driver for the job description) */ +typedef struct YieldingJob { + BlockJob common; + bool should_complete; +} YieldingJob; + +static void yielding_job_complete(Job *job, Error **errp) +{ + YieldingJob *s = container_of(job, YieldingJob, common.job); + s->should_complete = true; + job_enter(job); +} + +static int coroutine_fn yielding_job_run(Job *job, Error **errp) +{ + YieldingJob *s = container_of(job, YieldingJob, common.job); + + job_transition_to_ready(job); + + while (!s->should_complete) { + job_yield(job); + } + + return 0; +} + +/* + * This job transitions immediately to the READY state, and then + * yields until it is to complete. + */ +static const BlockJobDriver test_yielding_driver = { + .job_driver = { + .instance_size = sizeof(YieldingJob), + .free = block_job_free, + .user_resume = block_job_user_resume, + .run = yielding_job_run, + .complete = yielding_job_complete, + }, +}; + +/* + * Test that job_complete() works even on jobs that are in a paused + * state (i.e., STANDBY). + * + * To do this, run YieldingJob in an IO thread, get it into the READY + * state, then have a drained section. Before ending the section, + * acquire the context so the job will not be entered and will thus + * remain on STANDBY. + * + * job_complete() should still work without error. + * + * Note that on the QMP interface, it is impossible to lock an IO + * thread before a drained section ends. In practice, the + * bdrv_drain_all_end() and the aio_context_acquire() will be + * reversed. However, that makes for worse reproducibility here: + * Sometimes, the job would no longer be in STANDBY then but already + * be started. We cannot prevent that, because the IO thread runs + * concurrently. We can only prevent it by taking the lock before + * ending the drained section, so we do that. + * + * (You can reverse the order of operations and most of the time the + * test will pass, but sometimes the assert(status == STANDBY) will + * fail.) + */ +static void test_complete_in_standby(void) +{ + BlockBackend *blk; + IOThread *iothread; + AioContext *ctx; + Job *job; + BlockJob *bjob; + + /* Create a test drive, move it to an IO thread */ + blk = create_blk(NULL); + iothread = iothread_new(); + + ctx = iothread_get_aio_context(iothread); + blk_set_aio_context(blk, ctx, &error_abort); + + /* Create our test job */ + bjob = mk_job(blk, "job", &test_yielding_driver, true, + JOB_MANUAL_FINALIZE | JOB_MANUAL_DISMISS); + job = &bjob->job; + assert(job->status == JOB_STATUS_CREATED); + + /* Wait for the job to become READY */ + job_start(job); + aio_context_acquire(ctx); + AIO_WAIT_WHILE(ctx, job->status != JOB_STATUS_READY); + aio_context_release(ctx); + + /* Begin the drained section, pausing the job */ + bdrv_drain_all_begin(); + assert(job->status == JOB_STATUS_STANDBY); + /* Lock the IO thread to prevent the job from being run */ + aio_context_acquire(ctx); + /* This will schedule the job to resume it */ + bdrv_drain_all_end(); + + /* But the job cannot run, so it will remain on standby */ + assert(job->status == JOB_STATUS_STANDBY); + + /* Even though the job is on standby, this should work */ + job_complete(job, &error_abort); + + /* The test is done now, clean up. */ + job_finish_sync(job, NULL, &error_abort); + assert(job->status == JOB_STATUS_PENDING); + + job_finalize(job, &error_abort); + assert(job->status == JOB_STATUS_CONCLUDED); + + job_dismiss(&job, &error_abort); + + destroy_blk(blk); + aio_context_release(ctx); + iothread_join(iothread); +} + int main(int argc, char **argv) { qemu_init_main_loop(&error_abort); @@ -389,5 +509,6 @@ int main(int argc, char **argv) g_test_add_func("/blockjob/cancel/standby", test_cancel_standby); g_test_add_func("/blockjob/cancel/pending", test_cancel_pending); g_test_add_func("/blockjob/cancel/concluded", test_cancel_concluded); + g_test_add_func("/blockjob/complete_in_standby", test_complete_in_standby); return g_test_run(); } From patchwork Fri Apr 9 12:04:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 12193991 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9109C433ED for ; Fri, 9 Apr 2021 12:07:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 597B961042 for ; Fri, 9 Apr 2021 12:07:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 597B961042 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:36658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lUpvM-0001of-CT for qemu-devel@archiver.kernel.org; Fri, 09 Apr 2021 08:07:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUpsS-000873-OE for qemu-devel@nongnu.org; Fri, 09 Apr 2021 08:04:44 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29539) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lUpsO-0008H9-SM for qemu-devel@nongnu.org; Fri, 09 Apr 2021 08:04:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617969880; 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=1srMCU2bYhO+BsWlK/xCgdMlVZmHB88CcU9bByF1iPo=; b=e48pTYTrkMSwv75g1H8j9RuU3Nco7BBoJdBW46cU2p23v5dAGay0UPsIaEkKBG0C5cNbg8 mFZFM5HY2WgypkiAMveNdNFEt3YUxRtcRaaZYVgOmG+/qIv18MVFFwgt5P8gBEP6jkFYsk EukAaR8li6Otoa6mfW5/H+teAVtL0Bo= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-mzFZdOegNa6256xBo88UXA-1; Fri, 09 Apr 2021 08:04:36 -0400 X-MC-Unique: mzFZdOegNa6256xBo88UXA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6F82E107ACCA; Fri, 9 Apr 2021 12:04:35 +0000 (UTC) Received: from localhost (ovpn-114-67.ams2.redhat.com [10.36.114.67]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0C9C25C1A1; Fri, 9 Apr 2021 12:04:34 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 5/4] iotests: Test completion immediately after drain Date: Fri, 9 Apr 2021 14:04:22 +0200 Message-Id: <20210409120422.144040-6-mreitz@redhat.com> In-Reply-To: <20210409120422.144040-1-mreitz@redhat.com> References: <20210409120422.144040-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mreitz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=170.10.133.124; envelope-from=mreitz@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_H4=0.001, RCVD_IN_MSPIKE_WL=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Vladimir Sementsov-Ogievskiy , John Snow , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Test what happens when you have multiple busy block jobs, drain all (via an empty transaction), and immediately issue a block-job-complete on one of the jobs. Sometimes it will still be in STANDBY, in which case block-job-complete used to fail. It should not. Signed-off-by: Max Reitz --- .../tests/mirror-complete-after-drain | 89 +++++++++++++++++++ .../tests/mirror-complete-after-drain.out | 14 +++ 2 files changed, 103 insertions(+) create mode 100755 tests/qemu-iotests/tests/mirror-complete-after-drain create mode 100644 tests/qemu-iotests/tests/mirror-complete-after-drain.out diff --git a/tests/qemu-iotests/tests/mirror-complete-after-drain b/tests/qemu-iotests/tests/mirror-complete-after-drain new file mode 100755 index 0000000000..b096ffbcb4 --- /dev/null +++ b/tests/qemu-iotests/tests/mirror-complete-after-drain @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +# group: rw +# +# Tests for block-job-complete immediately after a drain +# +# Copyright (c) 2021 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +import iotests + +iotests.script_initialize(supported_fmts=['raw']) + +DISK_JOBS = 4 +NULL_JOBS = 1 + + +# We cannot auto-generate these in a loop because the files are +# deleted when their scope ends +src_imgs = iotests.file_path('src0', 'src1', 'src2', 'src3') +dst_imgs = iotests.file_path('dst0', 'dst1', 'dst2', 'dst3') + +assert len(src_imgs) == DISK_JOBS +assert len(dst_imgs) == DISK_JOBS + + +for i in range(DISK_JOBS): + ret = iotests.qemu_img('create', '-f', iotests.imgfmt, src_imgs[i], '128M') + assert ret == 0 + + ret = iotests.qemu_img('create', '-f', iotests.imgfmt, dst_imgs[i], '128M') + assert ret == 0 + +with iotests.VM() as vm: + vm.add_object('iothread,id=iothr0') + vm.add_device('virtio-scsi,iothread=iothr0') + + for i in range(DISK_JOBS): + vm.add_blockdev(f'file,node-name=source-disk-{i},' + f'filename={src_imgs[i]}') + + vm.add_blockdev(f'file,node-name=target-disk-{i},' + f'filename={dst_imgs[i]}') + + vm.add_device(f'scsi-hd,id=device-disk-{i},drive=source-disk-{i}') + + for i in range(NULL_JOBS): + vm.add_blockdev(f'null-co,node-name=source-null-{i},read-zeroes=on') + vm.add_blockdev(f'null-co,node-name=target-null-{i},read-zeroes=on') + vm.add_device(f'scsi-hd,id=device-null-{i},drive=source-null-{i}') + + vm.launch() + + for i in range(DISK_JOBS): + vm.qmp_log('blockdev-mirror', + job_id=f'mirror-disk-{i}', + device=f'source-disk-{i}', + target=f'target-disk-{i}', + sync='full', + granularity=1048576, + buf_size=(16 * 1048576)) + + for i in range(NULL_JOBS): + vm.qmp_log('blockdev-mirror', + job_id=f'mirror-null-{i}', + device=f'source-null-{i}', + target=f'target-null-{i}', + sync='full') + + for i in range(DISK_JOBS + NULL_JOBS): + vm.event_wait('BLOCK_JOB_READY') + + for i in range(DISK_JOBS): + vm.hmp(f'qemu-io -d device-disk-{i} "write 0 128M"') + + vm.qmp_log('transaction', actions=[]) + vm.qmp_log('block-job-complete', device='mirror-null-0') diff --git a/tests/qemu-iotests/tests/mirror-complete-after-drain.out b/tests/qemu-iotests/tests/mirror-complete-after-drain.out new file mode 100644 index 0000000000..4d9d0529fe --- /dev/null +++ b/tests/qemu-iotests/tests/mirror-complete-after-drain.out @@ -0,0 +1,14 @@ +{"execute": "blockdev-mirror", "arguments": {"buf-size": 16777216, "device": "source-disk-0", "granularity": 1048576, "job-id": "mirror-disk-0", "sync": "full", "target": "target-disk-0"}} +{"return": {}} +{"execute": "blockdev-mirror", "arguments": {"buf-size": 16777216, "device": "source-disk-1", "granularity": 1048576, "job-id": "mirror-disk-1", "sync": "full", "target": "target-disk-1"}} +{"return": {}} +{"execute": "blockdev-mirror", "arguments": {"buf-size": 16777216, "device": "source-disk-2", "granularity": 1048576, "job-id": "mirror-disk-2", "sync": "full", "target": "target-disk-2"}} +{"return": {}} +{"execute": "blockdev-mirror", "arguments": {"buf-size": 16777216, "device": "source-disk-3", "granularity": 1048576, "job-id": "mirror-disk-3", "sync": "full", "target": "target-disk-3"}} +{"return": {}} +{"execute": "blockdev-mirror", "arguments": {"device": "source-null-0", "job-id": "mirror-null-0", "sync": "full", "target": "target-null-0"}} +{"return": {}} +{"execute": "transaction", "arguments": {"actions": []}} +{"return": {}} +{"execute": "block-job-complete", "arguments": {"device": "mirror-null-0"}} +{"return": {}}