From nobody Sat Nov 15 19:33:08 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1748108244; cv=none; d=zohomail.com; s=zohoarc; b=NmyHJ2pQZG2sEjuQQR5340T9CWrtiZOOiX7TXknM7AP6h/tEjdsGmdtNErE8UmgqqKugcaAJSKpgQI7gOtgwI7UDNCUpYhqx/KDFlQTeHDYmjJsUUnxEV58bYQNEbRyQTbjhCmTmtgZV1/27NhQt6A9PBMgB2eHnMDLKmKw6Uj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748108244; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XUfnDwYRc5/qq1OUomuApWVfWvzcXVHwfvl96q7zTjo=; b=eRJJGWQjfaOQuHZnnWNIyYiwt1yM/mQJapysUgA6IE7cRx20dnDlwcje5w/hCoMVvfo3Du0VVHho6f6bbl0FeLFZK5s9fROfh1N8jIfeuGw8cS0WwxXpcYMblNX718zAvACZnJo2qKGDRbD/wSCpCx234YGpR48bIDrquMBHlyQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1748108243911338.81239185873767; Sat, 24 May 2025 10:37:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uIsmv-00005C-M8; Sat, 24 May 2025 13:36:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uIsmn-0008Eq-6r for qemu-devel@nongnu.org; Sat, 24 May 2025 13:35:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uIsml-0000jY-Ky for qemu-devel@nongnu.org; Sat, 24 May 2025 13:35:52 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-7-BnLn_uNxOP5rYZRr7h5Q-1; Sat, 24 May 2025 13:35:48 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2B86519560AA for ; Sat, 24 May 2025 17:35:48 +0000 (UTC) Received: from localhost (unknown [10.45.242.4]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7DB0819560AF; Sat, 24 May 2025 17:35:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748108151; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XUfnDwYRc5/qq1OUomuApWVfWvzcXVHwfvl96q7zTjo=; b=BHgd1IdvfkL9jNJNTjLO20ICU/rF6jiuU4kQbr+P7bM3TEy7SPXhGc3ZSBMAkNXj0rqpzM hcGDJeBud+UyACDYKbGFpahgmCBdpJHTRbqoM6i8JIld2UvqlzjYr1bdvHU9ppBiBHo3xN l2/Whd1x5WZtdE7NoTh1pJs6Ip7Y9Eg= X-MC-Unique: 7-BnLn_uNxOP5rYZRr7h5Q-1 X-Mimecast-MFC-AGG-ID: 7-BnLn_uNxOP5rYZRr7h5Q_1748108148 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , stefanha@redhat.com Subject: [PULL 09/19] ui/vdagent: add migration support Date: Sat, 24 May 2025 19:35:02 +0200 Message-ID: <20250524173514.317886-10-marcandre.lureau@redhat.com> In-Reply-To: <20250524173514.317886-1-marcandre.lureau@redhat.com> References: <20250524173514.317886-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.298, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1748108251061116600 From: Marc-Andr=C3=A9 Lureau Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- ui/vdagent.c | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) diff --git a/ui/vdagent.c b/ui/vdagent.c index fcbd7b167b..adc8755bd9 100644 --- a/ui/vdagent.c +++ b/ui/vdagent.c @@ -10,6 +10,7 @@ #include "ui/clipboard.h" #include "ui/console.h" #include "ui/input.h" +#include "migration/vmstate.h" #include "trace.h" =20 #include "qapi/qapi-types-char.h" @@ -930,6 +931,146 @@ static void vdagent_chr_class_init(ObjectClass *oc, c= onst void *data) cc->chr_accept_input =3D vdagent_chr_accept_input; } =20 +static int post_load(void *opaque, int version_id) +{ + VDAgentChardev *vd =3D QEMU_VDAGENT_CHARDEV(opaque); + + if (have_mouse(vd) && vd->mouse_hs) { + qemu_input_handler_activate(vd->mouse_hs); + } + + if (have_clipboard(vd)) { + vdagent_clipboard_peer_register(vd); + } + + return 0; +} + +static const VMStateDescription vmstate_chunk =3D { + .name =3D "vdagent/chunk", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32(port, VDIChunkHeader), + VMSTATE_UINT32(size, VDIChunkHeader), + VMSTATE_END_OF_LIST() + } +}; + +static const VMStateDescription vmstate_vdba =3D { + .name =3D "vdagent/bytearray", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32(len, GByteArray), + VMSTATE_VBUFFER_ALLOC_UINT32(data, GByteArray, 0, 0, len), + VMSTATE_END_OF_LIST() + } +}; + +struct CBInfoArray { + uint32_t n; + QemuClipboardInfo cbinfo[QEMU_CLIPBOARD_SELECTION__COUNT]; +}; + +static const VMStateDescription vmstate_cbinfo_array =3D { + .name =3D "cbinfoarray", + .fields =3D (const VMStateField[]) { + VMSTATE_UINT32(n, struct CBInfoArray), + VMSTATE_STRUCT_VARRAY_UINT32(cbinfo, struct CBInfoArray, n, + 0, vmstate_cbinfo, QemuClipboardInfo), + VMSTATE_END_OF_LIST() + } +}; + +static int put_cbinfo(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, JSONWriter *vmdesc) +{ + VDAgentChardev *vd =3D QEMU_VDAGENT_CHARDEV(pv); + struct CBInfoArray cbinfo =3D {}; + int i; + + if (!have_clipboard(vd)) { + return 0; + } + + for (i =3D 0; i < QEMU_CLIPBOARD_SELECTION__COUNT; i++) { + if (qemu_clipboard_peer_owns(&vd->cbpeer, i)) { + cbinfo.cbinfo[cbinfo.n++] =3D *qemu_clipboard_info(i); + } + } + + return vmstate_save_state(f, &vmstate_cbinfo_array, &cbinfo, vmdesc); +} + +static int get_cbinfo(QEMUFile *f, void *pv, size_t size, + const VMStateField *field) +{ + VDAgentChardev *vd =3D QEMU_VDAGENT_CHARDEV(pv); + struct CBInfoArray cbinfo =3D {}; + int i, ret; + + if (!have_clipboard(vd)) { + return 0; + } + + vdagent_clipboard_peer_register(vd); + + ret =3D vmstate_load_state(f, &vmstate_cbinfo_array, &cbinfo, 0); + if (ret) { + return ret; + } + + for (i =3D 0; i < cbinfo.n; i++) { + g_autoptr(QemuClipboardInfo) info =3D + qemu_clipboard_info_new(&vd->cbpeer, cbinfo.cbinfo[i].selectio= n); + /* this will steal clipboard data pointer from cbinfo.types */ + memcpy(info->types, cbinfo.cbinfo[i].types, sizeof(cbinfo.cbinfo[i= ].types)); + qemu_clipboard_update(info); + } + + return 0; +} + +static const VMStateInfo vmstate_cbinfos =3D { + .name =3D "vdagent/cbinfos", + .get =3D get_cbinfo, + .put =3D put_cbinfo, +}; + +static const VMStateDescription vmstate_vdagent =3D { + .name =3D "vdagent", + .version_id =3D 0, + .minimum_version_id =3D 0, + .post_load =3D post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_BOOL(connected, VDAgentChardev), + VMSTATE_UINT32(caps, VDAgentChardev), + VMSTATE_STRUCT(chunk, VDAgentChardev, 0, vmstate_chunk, VDIChunkHe= ader), + VMSTATE_UINT32(chunksize, VDAgentChardev), + VMSTATE_UINT32(msgsize, VDAgentChardev), + VMSTATE_VBUFFER_ALLOC_UINT32(msgbuf, VDAgentChardev, 0, 0, msgsize= ), + VMSTATE_UINT32(xsize, VDAgentChardev), + VMSTATE_UINT32(xoff, VDAgentChardev), + VMSTATE_VBUFFER_ALLOC_UINT32(xbuf, VDAgentChardev, 0, 0, xsize), + VMSTATE_STRUCT_POINTER(outbuf, VDAgentChardev, vmstate_vdba, GByte= Array), + VMSTATE_UINT32(mouse_x, VDAgentChardev), + VMSTATE_UINT32(mouse_y, VDAgentChardev), + VMSTATE_UINT32(mouse_btn, VDAgentChardev), + VMSTATE_UINT32(mouse_display, VDAgentChardev), + VMSTATE_UINT32_ARRAY(last_serial, VDAgentChardev, + QEMU_CLIPBOARD_SELECTION__COUNT), + VMSTATE_UINT32_ARRAY(cbpending, VDAgentChardev, + QEMU_CLIPBOARD_SELECTION__COUNT), + { + .name =3D "cbinfos", + .info =3D &vmstate_cbinfos, + .flags =3D VMS_SINGLE, + }, + VMSTATE_END_OF_LIST() + } +}; + static void vdagent_chr_init(Object *obj) { VDAgentChardev *vd =3D QEMU_VDAGENT_CHARDEV(obj); @@ -937,6 +1078,7 @@ static void vdagent_chr_init(Object *obj) vd->outbuf =3D g_byte_array_new(); error_setg(&vd->migration_blocker, "The vdagent chardev doesn't yet support migration"); + vmstate_register_any(NULL, &vmstate_vdagent, vd); } =20 static void vdagent_chr_fini(Object *obj) --=20 2.49.0