From nobody Mon Feb 9 04:15:24 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1594151287; cv=none; d=zohomail.com; s=zohoarc; b=Xp+dsv+2+ZpEOibyFRd/0GZiy1PNR0DQ8F9kr5Wf+LyS3WotXnr0VfTIfOnkFRehlQQVRfdMQCKEPEAajaPobYwSgvP+D2dz3fLAR9NkSVGQBgtZEx18ecUNd/XkkAEt1wv3y+qSq5KdBcj8bYgE7frI2Eb98rlVA8nIXsqWgCo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594151287; 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=4nVPpdd7RlJ6yyh/U8t5CFVvbZKVX89jUDZO5sXsDfA=; b=jS3IS1yCvZBOeleDYa0i4BEXBEWex10UF/iRA4arZPkD6U9Kna6PyuZJeTz1jG5NfjyEVtI6AB3zkZ5Us0LWAG+dSw2WZ+6n/uuWfrJkuOLoI6gKMyoTMnoatQFxP/JXehxImT690EhBEq+PnbxQBNpSzuZqbigFnNW1JTrID5o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1594151287507858.0502618857378; Tue, 7 Jul 2020 12:48:07 -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-448-P64K_xGFOCmkvL8EsJnwEg-1; Tue, 07 Jul 2020 15:47:13 -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 3CBA78015FB; Tue, 7 Jul 2020 19:47:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 172F560CC0; Tue, 7 Jul 2020 19:47:07 +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 D9BA572F75; Tue, 7 Jul 2020 19:47:06 +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 067Jkp2O031547 for ; Tue, 7 Jul 2020 15:46:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id A9BC9797F1; Tue, 7 Jul 2020 19:46:51 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27BB6797F0 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=1594151286; 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=4nVPpdd7RlJ6yyh/U8t5CFVvbZKVX89jUDZO5sXsDfA=; b=jGEF09OO/3OrXlUxfLR8Ndrh4cn+jZRP+LcKDNm9j+bM/t6YWZudSe8TtLzASv4jJFMFo3 Iu5AZcHWElxLZ0gGR+s/DYnnD2zBtkGEZ5FkJNm27SLzgW7jFBwpk9RQyOolAPGBoeDsdY wb7g3Q8GtLtUvtN3GKdYvdSlFTeqLOk= X-MC-Unique: P64K_xGFOCmkvL8EsJnwEg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 13/17] virfdstream: Allow sparse stream vol-download Date: Tue, 7 Jul 2020 21:46:31 +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.79 on 10.5.11.12 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" When handling sparse stream, a thread is executed. This thread runs a read() or write() loop (depending what API is called; in this case it's virStorageVolDownload() and this the thread run read() loop). The read() is handled in virFDStreamThreadDoRead() which is then data/hole section aware, meaning it uses virFileInData() to detect data and hole sections and sends TYPE_DATA or TYPE_HOLE virStream messages accordingly. However, virFileInData() does not work with block devices. Simply because block devices don't have data and hole sections. But we can use new virFileInDataDetectZeroes() which is block device friendly for that. Partially resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1852528 Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/util/virfdstream.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/util/virfdstream.c b/src/util/virfdstream.c index 50209a8bd4..44b4855549 100644 --- a/src/util/virfdstream.c +++ b/src/util/virfdstream.c @@ -398,6 +398,7 @@ struct _virFDStreamThreadData { size_t length; bool doRead; bool sparse; + bool isBlock; int fdin; char *fdinname; int fdout; @@ -421,6 +422,7 @@ virFDStreamThreadDataFree(virFDStreamThreadDataPtr data) static ssize_t virFDStreamThreadDoRead(virFDStreamDataPtr fdst, bool sparse, + bool isBlock, const int fdin, const int fdout, const char *fdinname, @@ -437,8 +439,13 @@ virFDStreamThreadDoRead(virFDStreamDataPtr fdst, ssize_t got; =20 if (sparse && *dataLen =3D=3D 0) { - if (virFileInData(fdin, &inData, §ionLen) < 0) - return -1; + if (isBlock) { + if (virFileInDataDetectZeroes(fdin, &inData, §ionLen) < 0) + return -1; + } else { + if (virFileInData(fdin, &inData, §ionLen) < 0) + return -1; + } =20 if (length && sectionLen > length - total) @@ -568,6 +575,7 @@ virFDStreamThread(void *opaque) virStreamPtr st =3D data->st; size_t length =3D data->length; bool sparse =3D data->sparse; + bool isBlock =3D data->isBlock; VIR_AUTOCLOSE fdin =3D data->fdin; char *fdinname =3D data->fdinname; VIR_AUTOCLOSE fdout =3D data->fdout; @@ -604,7 +612,7 @@ virFDStreamThread(void *opaque) } =20 if (doRead) - got =3D virFDStreamThreadDoRead(fdst, sparse, + got =3D virFDStreamThreadDoRead(fdst, sparse, isBlock, fdin, fdout, fdinname, fdoutname, length, total, @@ -1271,6 +1279,7 @@ virFDStreamOpenFileInternal(virStreamPtr st, threadData->st =3D virObjectRef(st); threadData->length =3D length; threadData->sparse =3D sparse; + threadData->isBlock =3D !!S_ISBLK(sb.st_mode); =20 if ((oflags & O_ACCMODE) =3D=3D O_RDONLY) { threadData->fdin =3D fd; --=20 2.26.2