From nobody Wed May 15 19:16:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 162575021623964.80554937298007; Thu, 8 Jul 2021 06:16:56 -0700 (PDT) Received: from localhost ([::1]:50676 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1Ttf-0001RY-19 for importer@patchew.org; Thu, 08 Jul 2021 09:16:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Tp0-00021K-Tk for qemu-devel@nongnu.org; Thu, 08 Jul 2021 09:12:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56189) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Tol-0000dN-Kl for qemu-devel@nongnu.org; Thu, 08 Jul 2021 09:12:06 -0400 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-30-e2PgXzMQOAC1-plSKKY-Fw-1; Thu, 08 Jul 2021 09:11:49 -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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9064210A4045; Thu, 8 Jul 2021 13:11:48 +0000 (UTC) Received: from localhost (ovpn-114-141.ams2.redhat.com [10.36.114.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D4B360C13; Thu, 8 Jul 2021 13:11:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625749911; 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=NlkeZiVV5Ck2GGazhM0bewAevv3vNsVOoidIImrFQmY=; b=Sv5iLD90Uug5enbWR1lM8nW64jQRbuFzxuWfmtUye+/AEyoKwh3ElB+ilXrdyvvR5Ow2LJ +Y6+0x9f0y/+qjrr/fjaKwoWDPZzb/XXj+oV52eBY4URb1O8jOn1QcAgjacg3MA5GHRRQo LYKjYw5m4+QLdUps2rk8ReUH2hf+Z4A= X-MC-Unique: e2PgXzMQOAC1-plSKKY-Fw-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 1/5] util/async: add a human-readable name to BHs for debugging Date: Thu, 8 Jul 2021 14:11:39 +0100 Message-Id: <20210708131143.240647-2-stefanha@redhat.com> In-Reply-To: <20210708131143.240647-1-stefanha@redhat.com> References: <20210708131143.240647-1-stefanha@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=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.45, 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: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625750217629100003 Content-Type: text/plain; charset="utf-8" It can be difficult to debug issues with BHs in production environments. Although BHs can usually be identified by looking up their ->cb() function pointer, this requires debug information for the program. It is also not possible to print human-readable diagnostics about BHs because they have no identifier. This patch adds a name to each BH. The name is not unique per instance but differentiates between cb() functions, which is usually enough. It's done by changing aio_bh_new() and friends to macros that stringify cb. The next patch will use the name field when reporting leaked BHs. Signed-off-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20210414200247.917496-2-stefanha@redhat.com> --- include/block/aio.h | 31 ++++++++++++++++++++++++++++--- include/qemu/main-loop.h | 4 +++- tests/unit/ptimer-test-stubs.c | 2 +- util/async.c | 9 +++++++-- util/main-loop.c | 4 ++-- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index 10fcae1515..807edce9b5 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -291,20 +291,45 @@ void aio_context_acquire(AioContext *ctx); /* Relinquish ownership of the AioContext. */ void aio_context_release(AioContext *ctx); =20 +/** + * aio_bh_schedule_oneshot_full: Allocate a new bottom half structure that= will + * run only once and as soon as possible. + * + * @name: A human-readable identifier for debugging purposes. + */ +void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, void *o= paque, + const char *name); + /** * aio_bh_schedule_oneshot: Allocate a new bottom half structure that will= run * only once and as soon as possible. + * + * A convenience wrapper for aio_bh_schedule_oneshot_full() that uses cb a= s the + * name string. */ -void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque= ); +#define aio_bh_schedule_oneshot(ctx, cb, opaque) \ + aio_bh_schedule_oneshot_full((ctx), (cb), (opaque), (stringify(cb))) =20 /** - * aio_bh_new: Allocate a new bottom half structure. + * aio_bh_new_full: Allocate a new bottom half structure. * * Bottom halves are lightweight callbacks whose invocation is guaranteed * to be wait-free, thread-safe and signal-safe. The #QEMUBH structure * is opaque and must be allocated prior to its use. + * + * @name: A human-readable identifier for debugging purposes. */ -QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque); +QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, + const char *name); + +/** + * aio_bh_new: Allocate a new bottom half structure + * + * A convenience wrapper for aio_bh_new_full() that uses the cb as the name + * string. + */ +#define aio_bh_new(ctx, cb, opaque) \ + aio_bh_new_full((ctx), (cb), (opaque), (stringify(cb))) =20 /** * aio_notify: Force processing of pending events. diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h index 98aef5647c..8dbc6fcb89 100644 --- a/include/qemu/main-loop.h +++ b/include/qemu/main-loop.h @@ -294,7 +294,9 @@ void qemu_cond_timedwait_iothread(QemuCond *cond, int m= s); =20 void qemu_fd_register(int fd); =20 -QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque); +#define qemu_bh_new(cb, opaque) \ + qemu_bh_new_full((cb), (opaque), (stringify(cb))) +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name); void qemu_bh_schedule_idle(QEMUBH *bh); =20 enum { diff --git a/tests/unit/ptimer-test-stubs.c b/tests/unit/ptimer-test-stubs.c index 7f801a4d09..2a3ef58799 100644 --- a/tests/unit/ptimer-test-stubs.c +++ b/tests/unit/ptimer-test-stubs.c @@ -108,7 +108,7 @@ int64_t qemu_clock_deadline_ns_all(QEMUClockType type, = int attr_mask) return deadline; } =20 -QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name) { QEMUBH *bh =3D g_new(QEMUBH, 1); =20 diff --git a/util/async.c b/util/async.c index 5d9b7cc1eb..9a668996b8 100644 --- a/util/async.c +++ b/util/async.c @@ -57,6 +57,7 @@ enum { =20 struct QEMUBH { AioContext *ctx; + const char *name; QEMUBHFunc *cb; void *opaque; QSLIST_ENTRY(QEMUBH) next; @@ -107,7 +108,8 @@ static QEMUBH *aio_bh_dequeue(BHList *head, unsigned *f= lags) return bh; } =20 -void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHFunc *cb, void *opaque) +void aio_bh_schedule_oneshot_full(AioContext *ctx, QEMUBHFunc *cb, + void *opaque, const char *name) { QEMUBH *bh; bh =3D g_new(QEMUBH, 1); @@ -115,11 +117,13 @@ void aio_bh_schedule_oneshot(AioContext *ctx, QEMUBHF= unc *cb, void *opaque) .ctx =3D ctx, .cb =3D cb, .opaque =3D opaque, + .name =3D name, }; aio_bh_enqueue(bh, BH_SCHEDULED | BH_ONESHOT); } =20 -QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, void *opaque) +QEMUBH *aio_bh_new_full(AioContext *ctx, QEMUBHFunc *cb, void *opaque, + const char *name) { QEMUBH *bh; bh =3D g_new(QEMUBH, 1); @@ -127,6 +131,7 @@ QEMUBH *aio_bh_new(AioContext *ctx, QEMUBHFunc *cb, voi= d *opaque) .ctx =3D ctx, .cb =3D cb, .opaque =3D opaque, + .name =3D name, }; return bh; } diff --git a/util/main-loop.c b/util/main-loop.c index 4ae5b23e99..06b18b195c 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -544,9 +544,9 @@ void main_loop_wait(int nonblocking) =20 /* Functions to operate on the main QEMU AioContext. */ =20 -QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque) +QEMUBH *qemu_bh_new_full(QEMUBHFunc *cb, void *opaque, const char *name) { - return aio_bh_new(qemu_aio_context, cb, opaque); + return aio_bh_new_full(qemu_aio_context, cb, opaque, name); } =20 /* --=20 2.31.1 From nobody Wed May 15 19:16:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625750588516335.5077664168176; Thu, 8 Jul 2021 06:23:08 -0700 (PDT) Received: from localhost ([::1]:38352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1Tzf-0003g5-6b for importer@patchew.org; Thu, 08 Jul 2021 09:23:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47550) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Tp0-00021D-TU for qemu-devel@nongnu.org; Thu, 08 Jul 2021 09:12:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:44484) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Top-0000eF-5A for qemu-devel@nongnu.org; Thu, 08 Jul 2021 09:12:02 -0400 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-203-Gz-ByVt5NwS-9TGxoS95Tg-1; Thu, 08 Jul 2021 09:11:51 -0400 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 EB9D9804148; Thu, 8 Jul 2021 13:11:49 +0000 (UTC) Received: from localhost (ovpn-114-141.ams2.redhat.com [10.36.114.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 904FA5C1C2; Thu, 8 Jul 2021 13:11:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625749912; 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=AGunXnsX5X5a10cUZ0ZbGtgp64NwMRmKUHHSFbi3aEM=; b=fIvp2urPSwaEJKs1YbByRveSChoSFOHY0yuD61sVLfeUfg/GORiiZq0tdxOAxb90klFoNy WzZvFL+CYCSBzi1kA7+HRj/mqjZI8ZJve2JSGeuE9PAof7G6kO6i5iU3W9DUgYnQk7JjD3 RuuDqUtjTRBI8SGiDHRa+On8QEU8g+k= X-MC-Unique: Gz-ByVt5NwS-9TGxoS95Tg-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 2/5] util/async: print leaked BH name when AioContext finalizes Date: Thu, 8 Jul 2021 14:11:40 +0100 Message-Id: <20210708131143.240647-3-stefanha@redhat.com> In-Reply-To: <20210708131143.240647-1-stefanha@redhat.com> References: <20210708131143.240647-1-stefanha@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=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.45, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, 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: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini , Eric Ernst , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625750590167100001 Content-Type: text/plain; charset="utf-8" BHs must be deleted before the AioContext is finalized. If not, it's a bug and probably indicates that some part of the program still expects the BH to run in the future. That can lead to memory leaks, inconsistent state, or just hangs. Unfortunately the assert(flags & BH_DELETED) call in aio_ctx_finalize() is difficult to debug because the assertion failure contains no information about the BH! Use the QEMUBH name field added in the previous patch to show a useful error when a leaked BH is detected. Suggested-by: Eric Ernst Signed-off-by: Stefan Hajnoczi Message-Id: <20210414200247.917496-3-stefanha@redhat.com> --- util/async.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/util/async.c b/util/async.c index 9a668996b8..9a41591319 100644 --- a/util/async.c +++ b/util/async.c @@ -344,8 +344,20 @@ aio_ctx_finalize(GSource *source) assert(QSIMPLEQ_EMPTY(&ctx->bh_slice_list)); =20 while ((bh =3D aio_bh_dequeue(&ctx->bh_list, &flags))) { - /* qemu_bh_delete() must have been called on BHs in this AioContex= t */ - assert(flags & BH_DELETED); + /* + * qemu_bh_delete() must have been called on BHs in this AioContex= t. In + * many cases memory leaks, hangs, or inconsistent state occur whe= n a + * BH is leaked because something still expects it to run. + * + * If you hit this, fix the lifecycle of the BH so that + * qemu_bh_delete() and any associated cleanup is called before the + * AioContext is finalized. + */ + if (unlikely(!(flags & BH_DELETED))) { + fprintf(stderr, "%s: BH '%s' leaked, aborting...\n", + __func__, bh->name); + abort(); + } =20 g_free(bh); } --=20 2.31.1 From nobody Wed May 15 19:16:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625750483630197.86177734047556; Thu, 8 Jul 2021 06:21:23 -0700 (PDT) Received: from localhost ([::1]:60924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1Txy-0008NX-Do for importer@patchew.org; Thu, 08 Jul 2021 09:21:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47674) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1TpB-0002BA-6C for qemu-devel@nongnu.org; Thu, 08 Jul 2021 09:12:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41899) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Tp0-0000fe-Kx for qemu-devel@nongnu.org; Thu, 08 Jul 2021 09:12:16 -0400 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-428-DRgt8TjaOfmm8mF2OJTQ1Q-1; Thu, 08 Jul 2021 09:11:56 -0400 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 181EF10A4043; Thu, 8 Jul 2021 13:11:55 +0000 (UTC) Received: from localhost (ovpn-114-141.ams2.redhat.com [10.36.114.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 343E819C66; Thu, 8 Jul 2021 13:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625749925; 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=KrYVBHC3vnFNE5ZaL5/G6mEcyR9PcvRAlapWZn6AUoY=; b=HYpFUI6aN02XbjLTIIiZNq8gLZf3VsYOPuMdgurp0D3ozSBhGzpRf4EIkgWAGreDUk928U lSd43dLlLTXuG3be96aXj2hcQdezyAMt9YR3zsO3UW23QMEcV1xWqEYvjoXH2qBBZGZgPn 8bGnZrc1yImdP+INblitoRRpEBM5S+0= X-MC-Unique: DRgt8TjaOfmm8mF2OJTQ1Q-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 3/5] block/file-posix: Optimize for macOS Date: Thu, 8 Jul 2021 14:11:41 +0100 Message-Id: <20210708131143.240647-4-stefanha@redhat.com> In-Reply-To: <20210708131143.240647-1-stefanha@redhat.com> References: <20210708131143.240647-1-stefanha@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=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.45, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, 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: Fam Zheng , Kevin Wolf , Akihiko Odaki , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625750485493100001 Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki This commit introduces "punch hole" operation and optimizes transfer block size for macOS. Thanks to Konstantin Nazarov for detailed analysis of a flaw in an old version of this change: https://gist.github.com/akihikodaki/87df4149e7ca87f18dc56807ec5a1bc5#gistco= mment-3654667 Signed-off-by: Akihiko Odaki Message-id: 20210705130458.97642-1-akihiko.odaki@gmail.com Signed-off-by: Stefan Hajnoczi --- block/file-posix.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index a26eab0ac3..cb9bffe047 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -46,6 +46,7 @@ #if defined(HAVE_HOST_BLOCK_DEVICE) #include #include +#include #include #include #include @@ -1254,6 +1255,15 @@ static void raw_refresh_limits(BlockDriverState *bs,= Error **errp) return; } =20 +#if defined(__APPLE__) && (__MACH__) + struct statfs buf; + + if (!fstatfs(s->fd, &buf)) { + bs->bl.opt_transfer =3D buf.f_iosize; + bs->bl.pdiscard_alignment =3D buf.f_bsize; + } +#endif + if (bs->sg || S_ISBLK(st.st_mode)) { int ret =3D hdev_get_max_hw_transfer(s->fd, &st); =20 @@ -1591,6 +1601,7 @@ out: } } =20 +#if defined(CONFIG_FALLOCATE) || defined(BLKZEROOUT) || defined(BLKDISCARD) static int translate_err(int err) { if (err =3D=3D -ENODEV || err =3D=3D -ENOSYS || err =3D=3D -EOPNOTSUPP= || @@ -1599,6 +1610,7 @@ static int translate_err(int err) } return err; } +#endif =20 #ifdef CONFIG_FALLOCATE static int do_fallocate(int fd, int mode, off_t offset, off_t len) @@ -1811,16 +1823,27 @@ static int handle_aiocb_discard(void *opaque) } } while (errno =3D=3D EINTR); =20 - ret =3D -errno; + ret =3D translate_err(-errno); #endif } else { #ifdef CONFIG_FALLOCATE_PUNCH_HOLE ret =3D do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_= SIZE, aiocb->aio_offset, aiocb->aio_nbytes); + ret =3D translate_err(-errno); +#elif defined(__APPLE__) && (__MACH__) + fpunchhole_t fpunchhole; + fpunchhole.fp_flags =3D 0; + fpunchhole.reserved =3D 0; + fpunchhole.fp_offset =3D aiocb->aio_offset; + fpunchhole.fp_length =3D aiocb->aio_nbytes; + if (fcntl(s->fd, F_PUNCHHOLE, &fpunchhole) =3D=3D -1) { + ret =3D errno =3D=3D ENODEV ? -ENOTSUP : -errno; + } else { + ret =3D 0; + } #endif } =20 - ret =3D translate_err(ret); if (ret =3D=3D -ENOTSUP) { s->has_discard =3D false; } --=20 2.31.1 From nobody Wed May 15 19:16:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625750096456926.5687711155125; Thu, 8 Jul 2021 06:14:56 -0700 (PDT) Received: from localhost ([::1]:45946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1Trj-0006W6-BN for importer@patchew.org; Thu, 08 Jul 2021 09:14:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1TpA-0002A7-PQ for qemu-devel@nongnu.org; Thu, 08 Jul 2021 09:12:16 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:60458) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Tp0-0000ew-MK for qemu-devel@nongnu.org; Thu, 08 Jul 2021 09:12:16 -0400 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-280-QSS9pzt6ONSKCU2HeKaifQ-1; Thu, 08 Jul 2021 09:11:58 -0400 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 E5CE31098482; Thu, 8 Jul 2021 13:11:56 +0000 (UTC) Received: from localhost (ovpn-114-141.ams2.redhat.com [10.36.114.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 608435C1C2; Thu, 8 Jul 2021 13:11:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625749919; 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=4s7MghzgqrKMPDRKf8MAQPA2CmurX7SMUV6DY1AtBBw=; b=EcKh5d1qFulFPMRh855b6skpXO3NPWRMXCdBf/oSI+E1zpRI+4o+cDrVTS7vYoDKXoXDgI s2FNCTfbh0J67NrpFziynzafEYVRYh9/gfZHQp1utX9UYBYb3uz38G7R+GM2565zzx0+bg /wH1hQKcqMxsuORGGZH7ujEpbx/BhsU= X-MC-Unique: QSS9pzt6ONSKCU2HeKaifQ-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 4/5] block: Add backend_defaults property Date: Thu, 8 Jul 2021 14:11:42 +0100 Message-Id: <20210708131143.240647-5-stefanha@redhat.com> In-Reply-To: <20210708131143.240647-1-stefanha@redhat.com> References: <20210708131143.240647-1-stefanha@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=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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.133.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.45, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, 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: Fam Zheng , Kevin Wolf , Akihiko Odaki , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625750096963100001 Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki backend_defaults property allow users to control if default block properties should be decided with backend information. If it is off, any backend information will be discarded, which is suitable if you plan to perform live migration to a different disk backend. If it is on, a block device may utilize backend information more aggressively. By default, it is auto, which uses backend information for block sizes and ignores the others, which is consistent with the older versions. Signed-off-by: Akihiko Odaki Message-id: 20210705130458.97642-2-akihiko.odaki@gmail.com Signed-off-by: Stefan Hajnoczi --- include/hw/block/block.h | 3 +++ hw/block/block.c | 42 ++++++++++++++++++++++++++++++++++---- tests/qemu-iotests/172.out | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/include/hw/block/block.h b/include/hw/block/block.h index c172cbe65f..5902c0440a 100644 --- a/include/hw/block/block.h +++ b/include/hw/block/block.h @@ -19,6 +19,7 @@ =20 typedef struct BlockConf { BlockBackend *blk; + OnOffAuto backend_defaults; uint32_t physical_block_size; uint32_t logical_block_size; uint32_t min_io_size; @@ -48,6 +49,8 @@ static inline unsigned int get_physical_block_exp(BlockCo= nf *conf) } =20 #define DEFINE_BLOCK_PROPERTIES_BASE(_state, _conf) \ + DEFINE_PROP_ON_OFF_AUTO("backend_defaults", _state, \ + _conf.backend_defaults, ON_OFF_AUTO_AUTO), \ DEFINE_PROP_BLOCKSIZE("logical_block_size", _state, \ _conf.logical_block_size), \ DEFINE_PROP_BLOCKSIZE("physical_block_size", _state, \ diff --git a/hw/block/block.c b/hw/block/block.c index 1e34573da7..d47ebf005a 100644 --- a/hw/block/block.c +++ b/hw/block/block.c @@ -65,24 +65,58 @@ bool blkconf_blocksizes(BlockConf *conf, Error **errp) { BlockBackend *blk =3D conf->blk; BlockSizes blocksizes; - int backend_ret; + BlockDriverState *bs; + bool use_blocksizes; + bool use_bs; + + switch (conf->backend_defaults) { + case ON_OFF_AUTO_AUTO: + use_blocksizes =3D !blk_probe_blocksizes(blk, &blocksizes); + use_bs =3D false; + break; + + case ON_OFF_AUTO_ON: + use_blocksizes =3D !blk_probe_blocksizes(blk, &blocksizes); + bs =3D blk_bs(blk); + use_bs =3D bs; + break; + + case ON_OFF_AUTO_OFF: + use_blocksizes =3D false; + use_bs =3D false; + break; + + default: + abort(); + } =20 - backend_ret =3D blk_probe_blocksizes(blk, &blocksizes); /* fill in detected values if they are not defined via qemu command li= ne */ if (!conf->physical_block_size) { - if (!backend_ret) { + if (use_blocksizes) { conf->physical_block_size =3D blocksizes.phys; } else { conf->physical_block_size =3D BDRV_SECTOR_SIZE; } } if (!conf->logical_block_size) { - if (!backend_ret) { + if (use_blocksizes) { conf->logical_block_size =3D blocksizes.log; } else { conf->logical_block_size =3D BDRV_SECTOR_SIZE; } } + if (use_bs) { + if (!conf->opt_io_size) { + conf->opt_io_size =3D bs->bl.opt_transfer; + } + if (conf->discard_granularity =3D=3D -1) { + if (bs->bl.pdiscard_alignment) { + conf->discard_granularity =3D bs->bl.pdiscard_alignment; + } else if (bs->bl.request_alignment !=3D 1) { + conf->discard_granularity =3D bs->bl.request_alignment; + } + } + } =20 if (conf->logical_block_size > conf->physical_block_size) { error_setg(errp, diff --git a/tests/qemu-iotests/172.out b/tests/qemu-iotests/172.out index d53f61d0de..4cf4d536b4 100644 --- a/tests/qemu-iotests/172.out +++ b/tests/qemu-iotests/172.out @@ -21,6 +21,7 @@ Testing: dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -48,6 +49,7 @@ Testing: -fda TEST_DIR/t.qcow2 dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -85,6 +87,7 @@ Testing: -fdb TEST_DIR/t.qcow2 dev: floppy, id "" unit =3D 1 (0x1) drive =3D "floppy1" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -96,6 +99,7 @@ Testing: -fdb TEST_DIR/t.qcow2 dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -137,6 +141,7 @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 dev: floppy, id "" unit =3D 1 (0x1) drive =3D "floppy1" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -148,6 +153,7 @@ Testing: -fda TEST_DIR/t.qcow2 -fdb TEST_DIR/t.qcow2.2 dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -190,6 +196,7 @@ Testing: -fdb dev: floppy, id "" unit =3D 1 (0x1) drive =3D "floppy1" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -201,6 +208,7 @@ Testing: -fdb dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -228,6 +236,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -265,6 +274,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2,ind= ex=3D1 dev: floppy, id "" unit =3D 1 (0x1) drive =3D "floppy1" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -276,6 +286,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2,ind= ex=3D1 dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -317,6 +328,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dfloppy,file=3DTEST_DIR/t dev: floppy, id "" unit =3D 1 (0x1) drive =3D "floppy1" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -328,6 +340,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dfloppy,file=3DTEST_DIR/t dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -373,6 +386,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -devi= ce floppy,drive=3Dnone0 dev: floppy, id "" unit =3D 0 (0x0) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -410,6 +424,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -devi= ce floppy,drive=3Dnone0,unit=3D1 dev: floppy, id "" unit =3D 1 (0x1) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -447,6 +462,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco dev: floppy, id "" unit =3D 1 (0x1) drive =3D "none1" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -458,6 +474,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -driv= e if=3Dnone,file=3DTEST_DIR/t.qco dev: floppy, id "" unit =3D 0 (0x0) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -509,6 +526,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit =3D 1 (0x1) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -520,6 +538,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -562,6 +581,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit =3D 1 (0x1) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -573,6 +593,7 @@ Testing: -fda TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -615,6 +636,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit =3D 0 (0x0) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -626,6 +648,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit =3D 1 (0x1) drive =3D "floppy1" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -668,6 +691,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit =3D 0 (0x0) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -679,6 +703,7 @@ Testing: -fdb TEST_DIR/t.qcow2 -drive if=3Dnone,file=3D= TEST_DIR/t.qcow2.2 -device fl dev: floppy, id "" unit =3D 1 (0x1) drive =3D "floppy1" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -730,6 +755,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dnone,file=3DTEST_DIR/t.q dev: floppy, id "" unit =3D 1 (0x1) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -741,6 +767,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dnone,file=3DTEST_DIR/t.q dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -783,6 +810,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dnone,file=3DTEST_DIR/t.q dev: floppy, id "" unit =3D 1 (0x1) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -794,6 +822,7 @@ Testing: -drive if=3Dfloppy,file=3DTEST_DIR/t.qcow2 -dr= ive if=3Dnone,file=3DTEST_DIR/t.q dev: floppy, id "" unit =3D 0 (0x0) drive =3D "floppy0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -842,6 +871,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -glob= al floppy.drive=3Dnone0 -device dev: floppy, id "" unit =3D 0 (0x0) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -909,6 +939,7 @@ Testing: -device floppy dev: floppy, id "" unit =3D 0 (0x0) drive =3D "" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -933,6 +964,7 @@ Testing: -device floppy,drive-type=3D120 dev: floppy, id "" unit =3D 0 (0x0) drive =3D "" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -957,6 +989,7 @@ Testing: -device floppy,drive-type=3D144 dev: floppy, id "" unit =3D 0 (0x0) drive =3D "" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -981,6 +1014,7 @@ Testing: -device floppy,drive-type=3D288 dev: floppy, id "" unit =3D 0 (0x0) drive =3D "" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -1008,6 +1042,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -de= vice floppy,drive=3Dnone0,drive-t dev: floppy, id "" unit =3D 0 (0x0) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -1045,6 +1080,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -de= vice floppy,drive=3Dnone0,drive-t dev: floppy, id "" unit =3D 0 (0x0) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -1085,6 +1121,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -de= vice floppy,drive=3Dnone0,logical dev: floppy, id "" unit =3D 0 (0x0) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) @@ -1122,6 +1159,7 @@ Testing: -drive if=3Dnone,file=3DTEST_DIR/t.qcow2 -de= vice floppy,drive=3Dnone0,physica dev: floppy, id "" unit =3D 0 (0x0) drive =3D "none0" + backend_defaults =3D "auto" logical_block_size =3D 512 (512 B) physical_block_size =3D 512 (512 B) min_io_size =3D 0 (0 B) --=20 2.31.1 From nobody Wed May 15 19:16:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1625750351602930.7715183811644; Thu, 8 Jul 2021 06:19:11 -0700 (PDT) Received: from localhost ([::1]:55530 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m1Tvq-0004j0-Kp for importer@patchew.org; Thu, 08 Jul 2021 09:19:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Tp4-000241-H2 for qemu-devel@nongnu.org; Thu, 08 Jul 2021 09:12:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:22010) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m1Tp0-0000fF-Kg for qemu-devel@nongnu.org; Thu, 08 Jul 2021 09:12:10 -0400 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-523-5LoQgkkiP9OEVe2jLEZOqA-1; Thu, 08 Jul 2021 09:11:59 -0400 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 639911934100; Thu, 8 Jul 2021 13:11:58 +0000 (UTC) Received: from localhost (ovpn-114-141.ams2.redhat.com [10.36.114.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06D2F19C66; Thu, 8 Jul 2021 13:11:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1625749921; 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=03x1xG7Q6lW/zbtBfeHefd7Fjg4pA2oZfps0DxQm0QQ=; b=Q4Qkc9FbUC86SiacLlpAgnqHjS04jlXnEMjcSEzu93H/LCH1mKQeurnVzDT1vpBhaxaGbX TyZXG2MalpxOzfWjFHpYapA4tcCnQj616d4XLcG4w5eW4GTClnOv4Rn09JSb9LpS/OZd+M dAiFpHfAhUNehMsofmluRQJFLRPB52M= X-MC-Unique: 5LoQgkkiP9OEVe2jLEZOqA-1 From: Stefan Hajnoczi To: qemu-devel@nongnu.org, Peter Maydell Subject: [PULL 5/5] block/io: Merge discard request alignments Date: Thu, 8 Jul 2021 14:11:43 +0100 Message-Id: <20210708131143.240647-6-stefanha@redhat.com> In-Reply-To: <20210708131143.240647-1-stefanha@redhat.com> References: <20210708131143.240647-1-stefanha@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=stefanha@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=stefanha@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.45, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, 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: Fam Zheng , Kevin Wolf , Akihiko Odaki , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , Paolo Bonzini , John Snow Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1625750352833100001 Content-Type: text/plain; charset="utf-8" From: Akihiko Odaki Signed-off-by: Akihiko Odaki Message-id: 20210705130458.97642-3-akihiko.odaki@gmail.com Signed-off-by: Stefan Hajnoczi --- block/io.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/io.c b/block/io.c index cf177a9d2d..e0a689c584 100644 --- a/block/io.c +++ b/block/io.c @@ -125,6 +125,8 @@ void bdrv_parent_drained_begin_single(BdrvChild *c, boo= l poll) =20 static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) { + dst->pdiscard_alignment =3D MAX(dst->pdiscard_alignment, + src->pdiscard_alignment); dst->opt_transfer =3D MAX(dst->opt_transfer, src->opt_transfer); dst->max_transfer =3D MIN_NON_ZERO(dst->max_transfer, src->max_transfe= r); dst->max_hw_transfer =3D MIN_NON_ZERO(dst->max_hw_transfer, --=20 2.31.1