From nobody Sat Feb 7 22:53:44 2026 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1553390577175199.07834804658353; Sat, 23 Mar 2019 18:22:57 -0700 (PDT) Received: from localhost ([127.0.0.1]:50197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7rqX-0001Ej-A1 for importer@patchew.org; Sat, 23 Mar 2019 21:22:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h7pji-0007kP-QJ for qemu-devel@nongnu.org; Sat, 23 Mar 2019 19:07:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h7pcl-0006Kk-Dh for qemu-devel@nongnu.org; Sat, 23 Mar 2019 19:00:24 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:34134) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h7pci-0006Ga-Gs; Sat, 23 Mar 2019 19:00:20 -0400 Received: by mail-wm1-x344.google.com with SMTP id o10so6816942wmc.1; Sat, 23 Mar 2019 16:00:16 -0700 (PDT) Received: from lean.local (dsl217-132-181-48.bb.netvision.net.il. [217.132.181.48]) by smtp.gmail.com with ESMTPSA id y1sm25321732wrd.34.2019.03.23.16.00.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 23 Mar 2019 16:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=dXvN8k/Xxx239HSFIMFN+wJjWLgqgZydI+6NI4QDH1Y=; b=ZPJDMCH8cCfvEAuB/sNs3Ny7+traUfNiKOLsI0o4sxdLjmtwfxev/kI0XYtyJukrIx c63h2p5KdVIzUFzkU/KlOS5rTOp5Lv6Ph+OYGzHMCsdOYmPjB+spNdX/DXh+uzv7SanA XbAqCBONCciaTcm3Mz36zPik4BNjCBgZbyn4FVBU7HrmcoVqxipqHJlYNB+yWgUSoaKC glS/w/rYynhyTNJDDQnP1UgyPeQ/gARhQtFQ7ALfHKCi3NbcnFL5Rp/8euykSOUCpUKT cMY/aBOMDBT+VApr3Gj/Tdj1DLHpsdFBOfA883tLH7hJm6+jp67lKsl+L9DW+1vXONj6 YQwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=dXvN8k/Xxx239HSFIMFN+wJjWLgqgZydI+6NI4QDH1Y=; b=kUCfOWfTGTV/AS/s1geyTIxiMjdm7RipnDWuzSNmWU0iwShqJddPus652UU5n7Rm06 8dCLXSpfxwXF3oYGK3qK7bqJ+cll7eg7rqvG2QNYHKxwttTyP5ni1Hi+jC3l0cqf54LK UDSmqTFkiNhx+lOD4wWY4mmlpguFmLaf0UqNm9SoEjcSA9Is1Yf811QxLkYkKdGEwtJR IeLj3PSi+rNApsleUTbEYso/AH6HWLq+GeWQrwWx4CaHOrwbdiGMbMpvydEZoG5m6Ajw +O1l64IBzILUEnbWUmO5l0/Uqcakm+Y0tZQXJYrVlEdy2oV+21Jdln4Q5utviJJrrWXo OmAw== X-Gm-Message-State: APjAAAXSn4Tts/WSzjOaCC5RyTXjG23rLmzYepVJKrEKBZUkpcJ4RbKP SgxUoNfS+PLFUzvtPVslihQA3UXn X-Google-Smtp-Source: APXvYqxeASWRWf02E6z0iTPTlePVNHZjAB7dUubb2h32ctnpxe1vrM2ackr6oeJW7AlMizRan1ROMg== X-Received: by 2002:a1c:f204:: with SMTP id s4mr6100878wmc.51.1553382014302; Sat, 23 Mar 2019 16:00:14 -0700 (PDT) From: Nir Soffer To: qemu-block@nongnu.org Date: Sun, 24 Mar 2019 00:59:48 +0200 Message-Id: <20190323225948.19737-1-nirsof@gmail.com> X-Mailer: git-send-email 2.17.2 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 X-Mailman-Approved-At: Sat, 23 Mar 2019 21:21:48 -0400 Subject: [Qemu-devel] [PATCH] qemu-img: Enable BDRV_REQ_MAY_UNMAP in convert X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Nir Soffer , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" With Kevin's "block: Fix slow pre-zeroing in qemu-img convert"[1] we skip the pre zero step called like this: blk_make_zero(s->target, BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK) And we write zeroes later using: blk_co_pwrite_zeroes(s->target, sector_num << BDRV_SECTOR_BITS, n << BDRV_SECTOR_BITS, 0); Since we use flags=3D0, this is translated to NBD_CMD_WRITE_ZEROES with NBD_CMD_FLAG_NO_HOLE flag, which cause the NBD server to allocated space instead of punching a hole. Here is an example failure: $ dd if=3D/dev/urandom of=3Dsrc.img bs=3D1M count=3D5 $ truncate -s 50m src.img $ truncate -s 50m dst.img $ nbdkit -f -v -e '' -U nbd.sock file file=3Ddst.img $ ./qemu-img convert -n src.img nbd:unix:nbd.sock We can see in nbdkit log that it received the NBD_CMD_FLAG_NO_HOLE (may_trim=3D0): nbdkit: file[1]: debug: newstyle negotiation: flags: export 0x4d nbdkit: file[1]: debug: pwrite count=3D2097152 offset=3D0 nbdkit: file[1]: debug: pwrite count=3D2097152 offset=3D2097152 nbdkit: file[1]: debug: pwrite count=3D1048576 offset=3D4194304 nbdkit: file[1]: debug: zero count=3D33554432 offset=3D5242880 may_trim=3D0 nbdkit: file[1]: debug: zero count=3D13631488 offset=3D38797312 may_trim=3D0 nbdkit: file[1]: debug: flush And the image became fully allocated: $ qemu-img info dst.img virtual size: 50M (52428800 bytes) disk size: 50M With this change we see that nbdkit did not receive the NBD_CMD_FLAG_NO_HOLE (may_trim=3D1): nbdkit: file[1]: debug: newstyle negotiation: flags: export 0x4d nbdkit: file[1]: debug: pwrite count=3D2097152 offset=3D0 nbdkit: file[1]: debug: pwrite count=3D2097152 offset=3D2097152 nbdkit: file[1]: debug: pwrite count=3D1048576 offset=3D4194304 nbdkit: file[1]: debug: zero count=3D33554432 offset=3D5242880 may_trim=3D1 nbdkit: file[1]: debug: zero count=3D13631488 offset=3D38797312 may_trim=3D1 nbdkit: file[1]: debug: flush And the file is sparse as expected: $ qemu-img info dst.img virtual size: 50M (52428800 bytes) disk size: 5.0M Tested on top of Kevin patches: http://lists.nongnu.org/archive/html/qemu-block/2019-03/msg00755.html I'm not sure this change is correct for all cases, posting for discussion. [1] http://lists.nongnu.org/archive/html/qemu-block/2019-03/msg00761.html Signed-off-by: Nir Soffer Reviewed-by: Eric Blake --- qemu-img.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index 8ee63daeae..ca9deb3758 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1752,11 +1752,12 @@ static int coroutine_fn convert_co_write(ImgConvert= State *s, int64_t sector_num, assert(!s->target_has_backing); break; } ret =3D blk_co_pwrite_zeroes(s->target, sector_num << BDRV_SECTOR_BITS, - n << BDRV_SECTOR_BITS, 0); + n << BDRV_SECTOR_BITS, + BDRV_REQ_MAY_UNMAP); if (ret < 0) { return ret; } break; } --=20 2.17.2