From nobody Sun Apr 28 21:24:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 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=1638891367; cv=none; d=zohomail.com; s=zohoarc; b=DoqKClDju8o8uebvmbzQFiV0pklY1QpFt7RE8IrMH1D9KqONRxYHPyzqkWcNRnk9fIslxeDYcuGIbmAW6egkHE34adtO7Hou9vu34JMQr60QpWBRBs3nte7IqzYtyhAWeFveCTU+Et9hn0wwBWIZEh1NJUNi7GChxqtAyKPNcso= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638891367; 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=ihbVP+9IfGRooGhoZdbjb0BtWiFa5Sl517i0gcS4JWU=; b=kri9imHYVbYiqD+GjQfyX4KjCUcHPCO9a5RpXGew2HCisgzzch5HOLpLvG1uIDG62b7hgaFuu49rnQ4lmec3dXDWLvovc8tyNR4DPEDlA06lq3m9Zf2/IR1Fig3HHctBpiG86/IFOb72NJYVUvj9bTjbQ4fMgSBLoLDZgenYkIs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 163889136796081.16180372372776; Tue, 7 Dec 2021 07:36:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-559-4IkeMrb-OzCBcjgiX8zXTw-1; Tue, 07 Dec 2021 10:36:04 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C9D4D100C618; Tue, 7 Dec 2021 15:35:55 +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 AD1A35DF2B; Tue, 7 Dec 2021 15:35:55 +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 15D011809CB8; Tue, 7 Dec 2021 15:35:55 +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 1B7FZrGN023984 for ; Tue, 7 Dec 2021 10:35:53 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9152B694D8; Tue, 7 Dec 2021 15:35:53 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AB86694D7 for ; Tue, 7 Dec 2021 15:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638891367; 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=ihbVP+9IfGRooGhoZdbjb0BtWiFa5Sl517i0gcS4JWU=; b=SIcX8zDf7VdKHK2cdQ4g+IFPfJq4jCBqRoJp2RmF5Y/CLQNPs9+LLkKm7OZf9iN4ab/0Tu Yy5Wspizc3RpqniT9swokpAjb3QrCZdXTOE/m1dWyQ1uCpJaiLQxIYsLlytZXQInTxdWrW PIkzm2hH5iRg3kCjsOi6QioAqNUeOcY= X-MC-Unique: 4IkeMrb-OzCBcjgiX8zXTw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/3] virStreamInData: Allow callback to not rewind the stream Date: Tue, 7 Dec 2021 16:34:40 +0100 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.14 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) X-ZM-MESSAGEID: 1638891368276100001 Content-Type: text/plain; charset="utf-8" So far, virStreamInData() is effectively a wrapper over virFDStreamInData() which means it deals with files which can be rewind (lseek()-ed) to whatever position we need. And in fact, that's what virFDStreamInData() does - it makes sure that the FD is left unchanged in terms of position in the file. Skipping the hole happens soon after - in daemonStreamHandleRead() when virStreamSendHole() is called. But this is about to change. Soon we will have another implementation where we won't be dealing with FDs but virNetMessage queue and it will be handy to pop message at the beginning of the queue. Implement and document this new behavior. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/libvirt-stream.c | 9 ++++++++- src/remote/remote_daemon_stream.c | 8 +++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/libvirt-stream.c b/src/libvirt-stream.c index 873d7b1d4e..bacbbfd325 100644 --- a/src/libvirt-stream.c +++ b/src/libvirt-stream.c @@ -505,7 +505,14 @@ virStreamRecvHole(virStreamPtr stream, * hole: @data =3D false, @length > 0 * EOF: @data =3D false, @length =3D 0 * - * Returns 0 on success, + * The position in the underlying stream should not be changed + * upon return from this function, e.g. position in the + * underlying file is kept the same. For streams where this + * condition is impossible to meet, the function can return 1 to + * signal this to a caller. + * + * Returns 0 on success (stream position unchanged), + * 1 on success (stream position changed), * -1 otherwise */ int diff --git a/src/remote/remote_daemon_stream.c b/src/remote/remote_daemon_s= tream.c index 007ad73e27..eb7ed5edf3 100644 --- a/src/remote/remote_daemon_stream.c +++ b/src/remote/remote_daemon_stream.c @@ -894,9 +894,11 @@ daemonStreamHandleRead(virNetServerClient *client, =20 msg =3D NULL; =20 - /* We have successfully sent stream skip to the other side. - * To keep streams in sync seek locally too. */ - virStreamSendHole(stream->st, length, 0); + /* We have successfully sent stream skip to the other side= . To + * keep streams in sync seek locally too (rv =3D=3D 0), un= less it's + * already done (rv =3D=3D 1). */ + if (rv =3D=3D 0) + virStreamSendHole(stream->st, length, 0); /* We're done with this call */ goto done; } --=20 2.32.0 From nobody Sun Apr 28 21:24:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1638891370; cv=none; d=zohomail.com; s=zohoarc; b=CQTiza0H1C+yZXOJGDmjhJTVUAHNEFFshgw3vTuEHs0dpcD8wax/BlPnvaEF8N41zqNemleLkccetYrBQIF/7katSQuGFvlxD7JGwNEq5QOO7xI8WGk36ucHt8NAVsq9X+wIB4x7z8I3R0cfUntodYFBsMJmLdZuLXtihluSnRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638891370; 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=R/9a0eVi06yjUyn+RW4dLjC1fNSnpVIik0+U9J09PhU=; b=lyrcwf8h30tkhAqb0NlHyUuf0QApFkU3DToK1h1+LDOkQXXZ/TAFfs8pH6BWtd+AWSqkFGuAH2/UUUP+87k8WOiFYCrLWNLhITzMbUVmwWWsqsKAZQIvMKjsTwaUYRtobiKxQXXNoEez3ietKuQB/pEYk25oknHOSmec3k3snVw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638891370071910.2048221005891; Tue, 7 Dec 2021 07:36:10 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-348-uhL_ish4PG-jVksUwZBWEQ-1; Tue, 07 Dec 2021 10:36:04 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 69B8681EE74; Tue, 7 Dec 2021 15:35:57 +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 4B47419D9D; Tue, 7 Dec 2021 15:35:57 +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 162824CA9B; Tue, 7 Dec 2021 15:35:57 +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 1B7FZsDA023989 for ; Tue, 7 Dec 2021 10:35:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 61214694D8; Tue, 7 Dec 2021 15:35:54 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id DDF85694D7 for ; Tue, 7 Dec 2021 15:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638891369; 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=R/9a0eVi06yjUyn+RW4dLjC1fNSnpVIik0+U9J09PhU=; b=h7WANUcd4a4YcpbMYe184Xi0aUI8R5koF3TmydTCdcrDZ8AXdMrFVZGszrCkGQwGvIl2UJ J2Noac+h4wtBK5Al5OflKVg0zwlH+yF82tB6JVO7GLAUgTOLOcH35qRQ+kod14CREJsEFg CEZJgZotZsQmti3krhzkWdcfT2xgafs= X-MC-Unique: uhL_ish4PG-jVksUwZBWEQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/3] rpc: Introduce virNetClientStreamInData() Date: Tue, 7 Dec 2021 16:34:41 +0100 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.23 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) X-ZM-MESSAGEID: 1638891370927100001 Content-Type: text/plain; charset="utf-8" The aim of this function is to look at a virNetClientStream and tell whether the incoming packet (if there's one) contains data (type VIR_NET_STREAM) or a hole (type VIR_NET_STREAM_HOLE) and how big the section is. This function will be called from the remote driver in one of future commits. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/libvirt_remote.syms | 1 + src/rpc/virnetclientstream.c | 61 ++++++++++++++++++++++++++++++++++++ src/rpc/virnetclientstream.h | 4 +++ 3 files changed, 66 insertions(+) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 942e1013a6..07d22e368b 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -66,6 +66,7 @@ virNetClientStreamEOF; virNetClientStreamEventAddCallback; virNetClientStreamEventRemoveCallback; virNetClientStreamEventUpdateCallback; +virNetClientStreamInData; virNetClientStreamMatches; virNetClientStreamNew; virNetClientStreamQueuePacket; diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c index 1ba6167a1d..ffc702cdc3 100644 --- a/src/rpc/virnetclientstream.c +++ b/src/rpc/virnetclientstream.c @@ -801,3 +801,64 @@ bool virNetClientStreamEOF(virNetClientStream *st) { return st->incomingEOF; } + + +int virNetClientStreamInData(virNetClientStream *st, + int *inData, + long long *length) +{ + int ret =3D 0; + virNetMessage *msg =3D NULL; + + if (!st->allowSkip) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("Holes are not supported with this stream")); + return -1; + } + + virObjectLock(st); + + if (virNetClientStreamCheckState(st) < 0) + goto cleanup; + + msg =3D st->rx; + + if (!msg) { + /* No incoming message. This means that the stream is at its end. = In + * this case, virStreamInData() should set both inData and length = to + * zero and return success. */ + *inData =3D 0; + *length =3D 0; + } else if (msg->header.type =3D=3D VIR_NET_STREAM) { + *inData =3D 1; + *length =3D msg->bufferLength - msg->bufferOffset; + } else if (msg->header.type =3D=3D VIR_NET_STREAM_HOLE) { + *inData =3D 0; + + if (st->holeLength =3D=3D 0 && + virNetClientStreamHandleHole(NULL, st) < 0) + goto cleanup; + + *length =3D st->holeLength; + st->holeLength =3D 0; + + /* virNetClientStreamHandleHole() called above did pop the message= from + * the queue (and freed it). Instead of trying to push it back let= 's + * just signal to the caller what we did. */ + ret =3D 1; + goto cleanup; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid message prog=3D%d type=3D%d serial=3D%u = proc=3D%d"), + msg->header.prog, + msg->header.type, + msg->header.serial, + msg->header.proc); + goto cleanup; + } + + ret =3D 0; + cleanup: + virObjectUnlock(st); + return ret; +} diff --git a/src/rpc/virnetclientstream.h b/src/rpc/virnetclientstream.h index e16d6e4a9a..7428843f9b 100644 --- a/src/rpc/virnetclientstream.h +++ b/src/rpc/virnetclientstream.h @@ -90,3 +90,7 @@ int virNetClientStreamEventRemoveCallback(virNetClientStr= eam *st); =20 bool virNetClientStreamEOF(virNetClientStream *st) ATTRIBUTE_NONNULL(1); + +int virNetClientStreamInData(virNetClientStream *st, + int *inData, + long long *length); --=20 2.32.0 From nobody Sun Apr 28 21:24:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 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=1639039493; cv=none; d=zohomail.com; s=zohoarc; b=ZdIHb8WNiCMuNrlNT4DpPSwHGn0/JyT8c0myNKWlDlvcJKSOj8XmO9f5512uztaTVDxkiola0adMja6TC4ERxsU0LNMY4jU1TZjvizgPLvnpsBiMFJUs0dtbdYJA60+Xh8oBx1+oKi+5hOalWX6MryaufQpv0TmCqYPChDW28x4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1639039493; 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=z9RxdzOinqBiLOoY4R/P2UFMBfC9SF92YJmVSv+gV8w=; b=mJIjIACQTLY0KstEsFUL89K5hncP+vHMLigFXCBFpPmpOI82ohEc9IeVCl7tGmCPI7wLTPYah/s9VQjel9cT5cfCr5rAN/bTe7yA1t6hvZwj3ZaPc8zIZg+0JY/mq2FRPZkXwF++Kn3q6U5rHkQZ2HUWdNTFamcq9XYxE348k4w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1639039493249388.6639802032022; Thu, 9 Dec 2021 00:44:53 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-441-huiu5cRAMVSt1_VQiteaVQ-1; Thu, 09 Dec 2021 03:44:51 -0500 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 8B766801AFC; Thu, 9 Dec 2021 08:44:45 +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 6B30C60C82; Thu, 9 Dec 2021 08:44:45 +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 0FE8B1809CB9; Thu, 9 Dec 2021 08:44:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B98ihJh024319 for ; Thu, 9 Dec 2021 03:44:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6EEDB19729; Thu, 9 Dec 2021 08:44:43 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB0C419D9D for ; Thu, 9 Dec 2021 08:44:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1639039492; 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=z9RxdzOinqBiLOoY4R/P2UFMBfC9SF92YJmVSv+gV8w=; b=aVN4pv9dTJzNoSCj4zeZEZlBKcSCTUUIb6AXuUd1Qd6q4iww/+Cp+zqK4b1Cp7b+89bLUE LnHSzspT9EOsM52bee/uqM93FAVZS526uVMvyzjbgua2EylKRz0qdkz1GaW3PgPuAqQx7J LRwC7T6tDp+/c81cKGyZXpirk9huyvQ= X-MC-Unique: huiu5cRAMVSt1_VQiteaVQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 2/3] rpc: Introduce virNetClientStreamInData() Date: Thu, 9 Dec 2021 09:44:22 +0100 Message-Id: <62a73f1bb93288649291eeaf2c0704a2519713f6.1639038520.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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) X-ZM-MESSAGEID: 1639039495101100001 Content-Type: text/plain; charset="utf-8" The aim of this function is to look at a virNetClientStream and tell whether the incoming packet (if there's one) contains data (type VIR_NET_STREAM) or a hole (type VIR_NET_STREAM_HOLE) and how big the section is. This function will be called from the remote driver in one of future commits. Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- diff to v1: - initialize ret to -1 - lock stream even for checking allowSkip - return 1 only if message was really popped from the queue - If there's no incoming message, return the size of yet unprocessed hole. This size should always be zero though, because at EOF there's a hole of size 0. I have not met this case and I probably never will, but I figured it's better to be safe than sorry. src/libvirt_remote.syms | 1 + src/rpc/virnetclientstream.c | 64 ++++++++++++++++++++++++++++++++++++ src/rpc/virnetclientstream.h | 4 +++ 3 files changed, 69 insertions(+) diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms index 942e1013a6..07d22e368b 100644 --- a/src/libvirt_remote.syms +++ b/src/libvirt_remote.syms @@ -66,6 +66,7 @@ virNetClientStreamEOF; virNetClientStreamEventAddCallback; virNetClientStreamEventRemoveCallback; virNetClientStreamEventUpdateCallback; +virNetClientStreamInData; virNetClientStreamMatches; virNetClientStreamNew; virNetClientStreamQueuePacket; diff --git a/src/rpc/virnetclientstream.c b/src/rpc/virnetclientstream.c index 1ba6167a1d..eb4dc6854d 100644 --- a/src/rpc/virnetclientstream.c +++ b/src/rpc/virnetclientstream.c @@ -801,3 +801,67 @@ bool virNetClientStreamEOF(virNetClientStream *st) { return st->incomingEOF; } + + +int virNetClientStreamInData(virNetClientStream *st, + int *inData, + long long *length) +{ + int ret =3D -1; + bool msgPopped =3D false; + virNetMessage *msg =3D NULL; + + virObjectLock(st); + + if (!st->allowSkip) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("Holes are not supported with this stream")); + goto cleanup; + } + + if (virNetClientStreamCheckState(st) < 0) + goto cleanup; + + msg =3D st->rx; + + if (!msg) { + /* No incoming message. This means that the stream is at its end. = In + * this case, virStreamInData() should set both inData and length = to + * zero and return success. If there is a trailing hole though (th= ere + * shouldn't be), signal that to the caller. */ + *inData =3D 0; + *length =3D st->holeLength; + st->holeLength =3D 0; + } else if (msg->header.type =3D=3D VIR_NET_STREAM) { + *inData =3D 1; + *length =3D msg->bufferLength - msg->bufferOffset; + } else if (msg->header.type =3D=3D VIR_NET_STREAM_HOLE) { + *inData =3D 0; + + if (st->holeLength =3D=3D 0) { + if (virNetClientStreamHandleHole(NULL, st) < 0) + goto cleanup; + + /* virNetClientStreamHandleHole() called above did pop the mes= sage from + * the queue (and freed it). Instead of trying to push it back= let's + * just signal to the caller what we did. */ + msgPopped =3D true; + } + + *length =3D st->holeLength; + st->holeLength =3D 0; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid message prog=3D%d type=3D%d serial=3D%u = proc=3D%d"), + msg->header.prog, + msg->header.type, + msg->header.serial, + msg->header.proc); + goto cleanup; + } + + ret =3D msgPopped ? 1 : 0; + cleanup: + virObjectUnlock(st); + return ret; +} diff --git a/src/rpc/virnetclientstream.h b/src/rpc/virnetclientstream.h index e16d6e4a9a..7428843f9b 100644 --- a/src/rpc/virnetclientstream.h +++ b/src/rpc/virnetclientstream.h @@ -90,3 +90,7 @@ int virNetClientStreamEventRemoveCallback(virNetClientStr= eam *st); =20 bool virNetClientStreamEOF(virNetClientStream *st) ATTRIBUTE_NONNULL(1); + +int virNetClientStreamInData(virNetClientStream *st, + int *inData, + long long *length); --=20 2.32.0 From nobody Sun Apr 28 21:24:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1638891392; cv=none; d=zohomail.com; s=zohoarc; b=JvU3wsqrkw+mZ395jjVGVgRz/NPXJR/R7avWcOk5XUIgLWkM2nulBaF8/FmCDavmkzrUHnONkdWTJOYi30UidqUzomRBdlK7lZt1XeLWpF9pvwRHwPsDoVI/bhtN38drwd7WDljPO/z2eyL0e+06DIrQcnqCYlDX184UfC85uiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638891392; 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=10X1nTCVYp+mbpjBQqJGYYVnlFxOkEupxpVKE5ImSUY=; b=bns+LpJTCG5VxNQ3LSVm/PIh6WekLzH/KpC5YGcZQxJ7znZH62dr9IB6hG4LJYiIzONg8r+0RNmaN1S81FD+IIx3FUGIf0WRdb1sZQ4KN4L009/ZrN/Hyh3xNe7XIJAyZE/Xe3FsVY1G7rsxYkwttLJGdz5BR851gzwQNMq8TI8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1638891392485974.7487348124865; Tue, 7 Dec 2021 07:36:32 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-526-E1iO4QfRMxyvkkZluFEAcg-1; Tue, 07 Dec 2021 10:36:29 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9C556801AC5; Tue, 7 Dec 2021 15:36:19 +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 7D6E317D61; Tue, 7 Dec 2021 15:36:19 +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 20C0A4A7C8; Tue, 7 Dec 2021 15:36:19 +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 1B7FaIYZ024084 for ; Tue, 7 Dec 2021 10:36:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 221CD4ABA6; Tue, 7 Dec 2021 15:36:18 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FFEE13A58 for ; Tue, 7 Dec 2021 15:35:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638891391; 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=10X1nTCVYp+mbpjBQqJGYYVnlFxOkEupxpVKE5ImSUY=; b=SJ4C1IDvCynhxFfW9k1O7ngfz4dYW4aQBDCHm1v0teaYtxUC19yLnNZPstHo3XpE2Ks71w 2sQyatljJWhPBELLcehdoXIY6KGj0/Pc1JarA4VTVr3LuO6lJrc/wV1cyGkqRiBfXrtrwR 7Smn3z7sXkAHiUGhf94Bu5ryc8aRTog= X-MC-Unique: E1iO4QfRMxyvkkZluFEAcg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/3] remote_driver: Implement virStreamInData() callback Date: Tue, 7 Dec 2021 16:34:42 +0100 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.14 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) X-ZM-MESSAGEID: 1638891393767100001 Content-Type: text/plain; charset="utf-8" When using the monolithic daemon the driver for virStream is always virFDStreamDrv and thus calling virStreamInData() results in calling virFDStreamInData(). But things are different with split daemon, especially when a client connects to one of hypervisor daemons (e.g. virtqemud) and then lets the daemon connect to the storage daemon for vol-upload/vol-download. Here, the hypervisor daemon acts like both client and server. This is reflected by stream->driver pointing to remoteStreamDrv, which doesn't have streamInData callback implemented and thus vol-upload/vol-download with sparse flag fails. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2026537 Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/remote/remote_driver.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 235c406a5a..5b179a927d 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -5599,6 +5599,31 @@ remoteStreamRecvHole(virStreamPtr st, } =20 =20 +static int +remoteStreamInData(virStreamPtr st, + int *data, + long long *length) +{ + struct private_data *priv =3D st->conn->privateData; + virNetClientStream *privst =3D st->privateData; + int rv; + + VIR_DEBUG("st=3D%p data=3D%p length=3D%p", + st, data, length); + + remoteDriverLock(priv); + priv->localUses++; + remoteDriverUnlock(priv); + + rv =3D virNetClientStreamInData(privst, data, length); + + remoteDriverLock(priv); + priv->localUses--; + remoteDriverUnlock(priv); + return rv; +} + + struct remoteStreamCallbackData { virStreamPtr st; virStreamEventCallback cb; @@ -5745,6 +5770,7 @@ static virStreamDriver remoteStreamDrv =3D { .streamSend =3D remoteStreamSend, .streamSendHole =3D remoteStreamSendHole, .streamRecvHole =3D remoteStreamRecvHole, + .streamInData =3D remoteStreamInData, .streamFinish =3D remoteStreamFinish, .streamAbort =3D remoteStreamAbort, .streamEventAddCallback =3D remoteStreamEventAddCallback, --=20 2.32.0