From nobody Mon Feb 9 03:14:39 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1494945187329439.04687660900515; Tue, 16 May 2017 07:33:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9982D7F4B3; Tue, 16 May 2017 14:33:01 +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 4E9697ED99; Tue, 16 May 2017 14:33:01 +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 D238B180BAFD; Tue, 16 May 2017 14:33:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4GE4mMO027982 for ; Tue, 16 May 2017 10:04:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 12782860EE; Tue, 16 May 2017 14:04:48 +0000 (UTC) Received: from moe.brq.redhat.com (dhcp129-131.brq.redhat.com [10.34.129.131]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E6D5860E4 for ; Tue, 16 May 2017 14:04:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9982D7F4B3 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9982D7F4B3 From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 16 May 2017 16:04:06 +0200 Message-Id: <78d56a6a920269c3669c9985a6ff36b2f79176cb.1494943031.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 26/31] daemonStreamHandleRead: Wire up seekable stream 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 16 May 2017 14:33:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Whenever client is able to receive some data from stream daemonStreamHandleRead is called. But now the behaviour of this function needs to be changed a bit. Previously it just read data from underlying file (of chardev or whatever) and sent those through the stream to client. This model will not work any longer because it does not differentiate whether underlying file is in data or hole section. Therefore, at the beginning of this function add code that checks this situation and acts accordingly. So after the this, when wanting to send some data we always check whether we are not in a hole and if so, skip it an inform client about its size. Signed-off-by: Michal Privoznik Reviewed-by: John Ferlan --- daemon/stream.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 59 insertions(+) diff --git a/daemon/stream.c b/daemon/stream.c index 57ddfe830..284499912 100644 --- a/daemon/stream.c +++ b/daemon/stream.c @@ -29,6 +29,7 @@ #include "virlog.h" #include "virnetserverclient.h" #include "virerror.h" +#include "libvirt_internal.h" =20 #define VIR_FROM_THIS VIR_FROM_STREAMS =20 @@ -53,6 +54,7 @@ struct daemonClientStream { bool tx; =20 bool allowSkip; + size_t dataLen; /* How much data is there remaining until we see a hol= e */ =20 daemonClientStreamPtr next; }; @@ -796,6 +798,8 @@ daemonStreamHandleRead(virNetServerClientPtr client, size_t bufferLen =3D VIR_NET_MESSAGE_LEGACY_PAYLOAD_MAX; int ret =3D -1; int rv; + int inData =3D 0; + long long length =3D 0; =20 VIR_DEBUG("client=3D%p, stream=3D%p tx=3D%d closed=3D%d", client, stream, stream->tx, stream->closed); @@ -820,6 +824,58 @@ daemonStreamHandleRead(virNetServerClientPtr client, if (!(msg =3D virNetMessageNew(false))) goto cleanup; =20 + if (stream->allowSkip && !stream->dataLen) { + /* Handle skip. We want to send some data to the client. But we mi= ght + * be in a hole. Seek to next data. But if we are in data already,= just + * carry on. */ + + rv =3D virStreamInData(stream->st, &inData, &length); + VIR_DEBUG("rv=3D%d inData=3D%d length=3D%lld", rv, inData, length); + + if (rv < 0) { + if (virNetServerProgramSendStreamError(remoteProgram, + client, + msg, + &rerr, + stream->procedure, + stream->serial) < 0) + goto cleanup; + msg =3D NULL; + + /* We're done with this call */ + goto done; + } else { + if (!inData && length) { + stream->tx =3D false; + msg->cb =3D daemonStreamMessageFinished; + msg->opaque =3D stream; + stream->refs++; + if (virNetServerProgramSendStreamHole(remoteProgram, + client, + msg, + stream->procedure, + stream->serial, + length, + 0) < 0) + goto cleanup; + + msg =3D NULL; + + /* We have successfully sent stream skip to the other sid= e. + * To keep streams in sync seek locally too. */ + virStreamSendHole(stream->st, length, 0); + /* We're done with this call */ + goto done; + } + } + + stream->dataLen =3D length; + } + + if (stream->allowSkip && + bufferLen > stream->dataLen) + bufferLen =3D stream->dataLen; + rv =3D virStreamRecv(stream->st, buffer, bufferLen); if (rv =3D=3D -2) { /* Should never get this, since we're only called when we know @@ -834,6 +890,8 @@ daemonStreamHandleRead(virNetServerClientPtr client, goto cleanup; msg =3D NULL; } else { + stream->dataLen -=3D rv; + stream->tx =3D false; if (rv =3D=3D 0) stream->recvEOF =3D true; @@ -851,6 +909,7 @@ daemonStreamHandleRead(virNetServerClientPtr client, msg =3D NULL; } =20 + done: ret =3D 0; cleanup: VIR_FREE(buffer); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list