From nobody Mon Feb 9 08:32:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; 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 207.211.31.81 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=1593772360; cv=none; d=zohomail.com; s=zohoarc; b=lRifhnGNVmEsiyAlq5626sbqUAGv8Gfx2Uca/mAv4fbzMNCiqV9LCYuxe/CcwK8A1fhH9AqzBUeUjt5yTv+D0DOzIMK/sEmbZEpb943j8BHRQ/QEzgF1fv9KZzG028MJj8PnW/XxfutmjDfhzfFpR/kB8AoLKibUu2MG3Kfxq+E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593772360; 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=b/s+6JJfbRWrWI/8bnMRQxdvp3jbxuIhouSNMgyGIvWFrxx8zKU2sFjzlQGTKDN/axxTEamsk511bTfVDeON62tWwHhSQaBFhCdv3JeXn6QIAGJUwhfBC/ljTlvskQPdC67vRNmy1pUfMNp/MvrB8DWN/AO/IAnMonPQqLCx8qA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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 [207.211.31.81]) by mx.zohomail.com with SMTPS id 1593772360900925.3215955553986; Fri, 3 Jul 2020 03:32:40 -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-163-kEkOSQw7O7CtpEgTPyFt7Q-1; Fri, 03 Jul 2020 06:32:37 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0019F800406; Fri, 3 Jul 2020 10:32:32 +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 D26161053B1B; Fri, 3 Jul 2020 10:32:31 +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 A0028180043A; Fri, 3 Jul 2020 10:32:31 +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 063AT6PE016997 for ; Fri, 3 Jul 2020 06:29:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id E13D77BD56; Fri, 3 Jul 2020 10:29:06 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60DEE79242 for ; Fri, 3 Jul 2020 10:29:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593772359; 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=KQnIk60R/keux/oL7K8tRzIrBCsBOowjv1gLxbSDDD+EEe8x81BqqDNvIhbXHqOR2JQE08 +/NapDp78qfnAWjrkljdmjGdRB1Dj+ZFAR6DURz6Sjes8lAB0Kl4mfYw4fDXzpmTA25xu3 ad5zDzrutpf6DI0enk0y07WbZbUaLy0= X-MC-Unique: kEkOSQw7O7CtpEgTPyFt7Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 6/9] virshStreamSkip: Emulate skip for block devices Date: Fri, 3 Jul 2020 12:28:47 +0200 Message-Id: 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.84 on 10.5.11.22 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 --- 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