From nobody Mon Feb 9 01:49:08 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594151415; cv=none; d=zohomail.com; s=zohoarc; b=d10bGOvjfsJwsVt4GHQNXhUnx8qjluJfZ0ALChdifViPS11kTVJVpWIyIlEOjymMXQfdmUXNrCV+axMOejJVjfU5d9JdueNSCYWld84uSe1sOwdFfuecM4GwjTudVIdMIBeKRlaaWUz64XrRRx2GBK7A8UPT8t/JYzLnS8VwHWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594151415; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=4iaslwF3zmWy+jtD7l+8UjwLEm5V9FlaqxEw3Ms2V0M=; b=G74Qu92vWUB1GHMOe7D8jPmPK25UBljlcvJXUgVVbBY3ChcCCAjOXfh34WK/kh1KoYc0TaJCoHwjQvLibh6oS3Tl9Noc0AMf/V9Qcl0SGRvU4BavCeE+68HEXf5oI3OopQpOO6MncHA/F5EAw+MFVWC/0l2TYBgkCm1XPobU3Gc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1594151415909964.1169247953866; Tue, 7 Jul 2020 12:50:15 -0700 (PDT) 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-344-Ro3einxEPp2fTuTFNxROhA-1; Tue, 07 Jul 2020 15:47:21 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 53A2E100CCC7; Tue, 7 Jul 2020 19:47:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 35269797F9; Tue, 7 Jul 2020 19:47:15 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 04EDD180530E; Tue, 7 Jul 2020 19:47:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 067JkoTY031535 for ; Tue, 7 Jul 2020 15:46:50 -0400 Received: by smtp.corp.redhat.com (Postfix) id C88C3797F1; Tue, 7 Jul 2020 19:46:50 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 475DE797F0 for ; Tue, 7 Jul 2020 19:46:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594151414; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=4iaslwF3zmWy+jtD7l+8UjwLEm5V9FlaqxEw3Ms2V0M=; b=cFCkYTqUds2TZwlA0Wt8PqTlt/Gag4GEqeTUxe88ghiqZ38EdMuStqnJ17xV4x356cmc8O FoKIyIEBPdK0oM6YaP/gcNGRGum+2xK71NTLaDGj+7Cc3Yfy95wTZMo3ip9ShftwAkg20h ppz6v57kF5pi7HokrDKo+546SU5liDs= X-MC-Unique: Ro3einxEPp2fTuTFNxROhA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 12/17] virshStreamSkip: Emulate skip for block devices Date: Tue, 7 Jul 2020 21:46:30 +0200 Message-Id: <5ca67478806396ea0335f5adc296cab8141d15c1.1594150891.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This callback is called when the server sends us STREAM_HOLE meaning there is no real data, only zeroes. For regular files we would just seek() beyond EOF and ftruncate() to create the hole. But for block devices this won't work. Not only we can't seek() beyond EOF, and ftruncate() will fail, this approach won't fill the device with zeroes. We have to do it manually. Partially resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1852528 Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- tools/virsh-util.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 89f15efd08..884261eb49 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -189,11 +189,33 @@ virshStreamSkip(virStreamPtr st G_GNUC_UNUSED, virshStreamCallbackDataPtr cbData =3D opaque; off_t cur; =20 - if ((cur =3D lseek(cbData->fd, offset, SEEK_CUR)) =3D=3D (off_t) -1) - return -1; + if (cbData->isBlock) { + g_autofree char * buf =3D NULL; + const size_t buflen =3D 1 * 1024 * 1024; /* 1MiB */ =20 - if (ftruncate(cbData->fd, cur) < 0) - return -1; + /* While for files it's enough to lseek() and ftruncate() to create + * a hole which would emulate zeroes on read(), for block devices + * we have to write zeroes to read() zeroes. And we have to write + * @got bytes of zeroes. Do that in smaller chunks though.*/ + + buf =3D g_new0(char, buflen); + + while (offset) { + size_t count =3D MIN(offset, buflen); + ssize_t r; + + if ((r =3D safewrite(cbData->fd, buf, count)) < 0) + return -1; + + offset -=3D r; + } + } else { + if ((cur =3D lseek(cbData->fd, offset, SEEK_CUR)) =3D=3D (off_t) -= 1) + return -1; + + if (ftruncate(cbData->fd, cur) < 0) + return -1; + } =20 return 0; } --=20 2.26.2