From nobody Sun May 19 16:58:42 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=1671110509; cv=none; d=zohomail.com; s=zohoarc; b=mjOJt69HqFpbGIubH220MY7rIccM/GOAFbvW4GGEzIZNrXrlqCpvZph58XR8P5iy1AfL9DPsalIuaxdLkm5dmUn7h8gVBBIgdSeU1+6LxyNz1OVZEWhVZ8XPZdbf1MFniSUUmFu/b8fums6g9vWS0MF8ICsSeBMY8o2Kvpw+LvY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1671110509; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=/u63xcwR4pBPzuAJYrFKyPl/P6dbO0ye1WgVvdyqS0U=; b=KAtdxw0d7HxkkqLyVGz0yQei/XxnalhswbFZlWB3Ul/AEBQpNSkWK0eTl6yAO4edzmgtvsjslqJOJm+crcGsURvqO2CHwx2YJh5Wl+T1t8uUKsD0SN4eH9WLp3YjvuB9W+EMEJhVcwD4h7nrJp9Ude/UTfKXzBmFzCrCa4Y1cjA= 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 1671110509134628.4194471487596; Thu, 15 Dec 2022 05:21:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5nsx-0001rk-ET; Thu, 15 Dec 2022 08:02:51 -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 1p5nsi-0001pG-MC for qemu-devel@nongnu.org; Thu, 15 Dec 2022 08:02:41 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5nsg-0000bs-0N for qemu-devel@nongnu.org; Thu, 15 Dec 2022 08:02:36 -0500 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-444-ldaMSRBVMTa8W6r8nkCDSQ-1; Thu, 15 Dec 2022 08:02:30 -0500 Received: by mail-wr1-f69.google.com with SMTP id e19-20020adfa453000000b0024209415034so612066wra.18 for ; Thu, 15 Dec 2022 05:02:30 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id 8-20020a05600c020800b003d237d60318sm6283745wmi.2.2022.12.15.05.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 05:02:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671109352; 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; bh=/u63xcwR4pBPzuAJYrFKyPl/P6dbO0ye1WgVvdyqS0U=; b=g4JpIpQM5xApREzabBX34WAR6s+w5eZxZorMcX2uBeqz5GooerjbZl3whn8M+nVkD/VCAd 5dm9XKpftRi9ZRpqDubVJwzOnEU6uWEUcR5uKQDJOKKvZKOz5Wy6FL2HLMp2o0yZC8d2Q5 Ai9YEiS2cQWtR7RZax6rAh33RpJ0oz4= X-MC-Unique: ldaMSRBVMTa8W6r8nkCDSQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/u63xcwR4pBPzuAJYrFKyPl/P6dbO0ye1WgVvdyqS0U=; b=zP4pLsvuPC6x0lp4rPN9RE0HI6lXPR5YwDx1dI9R3bNrPjInruQYvmIzU6xtx8gf+8 kGpj+/gaXGGQrq7W3xKHNYJAIL88204iM/WKyfr2eiI7zQGigqiG37PULOCqaYDHE/4b ntQX64qsqX/4pa/upVMkBIb7gP+lPsola0Qpf08fKaNNBw97lV/GZqPtyLlCn3fcGgg2 oH38+1jPQDOlhuGc/RKAwtbBQLtT+QtUe/f5X0kK5f3pfq0AlmuOg714DPC4lppo26oc tFXbdm4tPsV6WyrVD1jGuAqZWYGIPmuCyDtWMBK9II01L2HY245jHjS+36re0tTZIdpu HaSA== X-Gm-Message-State: ANoB5pnmdtNgiy/vgqsOKb85NhEY+21opgLlL8YOsYrYDK9j0rPJorR0 PwsllJRzkd3i2yermsn4wVReHoNRa3GT+KKcd/YTQcigoWPVgM56uUAnd8HE6uFknvUbuDs6RYH ougbz/lEW8wireB00mnjztF+kPCzqFzWbSCFMbf/BlJi92ywSoIMa/WKz8rclf2ThY+Y= X-Received: by 2002:a05:600c:4fd0:b0:3cf:d367:274d with SMTP id o16-20020a05600c4fd000b003cfd367274dmr21897973wmq.31.1671109349320; Thu, 15 Dec 2022 05:02:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf6O+nVQXY72JVRi97Dz/t/gGjoqcMztMv5gqyAxMyNiSw8i9MWKVLhsxm+CjqGBO3bTwOEpDg== X-Received: by 2002:a05:600c:4fd0:b0:3cf:d367:274d with SMTP id o16-20020a05600c4fd000b003cfd367274dmr21897938wmq.31.1671109348942; Thu, 15 Dec 2022 05:02:28 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, kwolf@redhat.com Subject: [PATCH] qemu-io: do not reinvent the blk_pwrite_zeroes wheel Date: Thu, 15 Dec 2022 14:02:23 +0100 Message-Id: <20221215130225.476477-1-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, 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: 1671110509981100001 Content-Type: text/plain; charset="utf-8" qemu-io's do_co_pwrite_zeroes is reinventing the coroutine wrapper blk_pwrite_zeroes. Just use the real thing directly. Signed-off-by: Paolo Bonzini --- qemu-io-cmds.c | 55 +++++++++----------------------------------------- 1 file changed, 9 insertions(+), 46 deletions(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 952dc940f1df..7a412d6512fb 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -572,54 +572,17 @@ static int do_pwrite(BlockBackend *blk, char *buf, in= t64_t offset, return 1; } =20 -typedef struct { - BlockBackend *blk; - int64_t offset; - int64_t bytes; - int64_t *total; - int flags; - int ret; - bool done; -} CoWriteZeroes; - -static void coroutine_fn co_pwrite_zeroes_entry(void *opaque) -{ - CoWriteZeroes *data =3D opaque; - - data->ret =3D blk_co_pwrite_zeroes(data->blk, data->offset, data->byte= s, - data->flags); - data->done =3D true; - if (data->ret < 0) { - *data->total =3D data->ret; - return; - } - - *data->total =3D data->bytes; -} - -static int do_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, +static int do_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t bytes, int flags, int64_t *total) { - Coroutine *co; - CoWriteZeroes data =3D { - .blk =3D blk, - .offset =3D offset, - .bytes =3D bytes, - .total =3D total, - .flags =3D flags, - .done =3D false, - }; + int ret =3D blk_pwrite_zeroes(blk, offset, bytes, + flags | BDRV_REQ_ZERO_WRITE); =20 - co =3D qemu_coroutine_create(co_pwrite_zeroes_entry, &data); - bdrv_coroutine_enter(blk_bs(blk), co); - while (!data.done) { - aio_poll(blk_get_aio_context(blk), true); - } - if (data.ret < 0) { - return data.ret; - } else { - return 1; + if (ret < 0) { + return ret; } + *total =3D bytes; + return 1; } =20 static int do_write_compressed(BlockBackend *blk, char *buf, int64_t offse= t, @@ -1042,7 +1005,7 @@ static void write_help(void) " -C, -- report statistics in a machine parsable format\n" " -q, -- quiet mode, do not show I/O statistics\n" " -u, -- with -z, allow unmapping\n" -" -z, -- write zeroes using blk_co_pwrite_zeroes\n" +" -z, -- write zeroes using blk_pwrite_zeroes\n" "\n"); } =20 @@ -1199,7 +1162,7 @@ static int write_f(BlockBackend *blk, int argc, char = **argv) if (bflag) { ret =3D do_save_vmstate(blk, buf, offset, count, &total); } else if (zflag) { - ret =3D do_co_pwrite_zeroes(blk, offset, count, flags, &total); + ret =3D do_pwrite_zeroes(blk, offset, count, flags, &total); } else if (cflag) { ret =3D do_write_compressed(blk, buf, offset, count, &total); } else { --=20 2.38.1