From nobody Mon Apr 29 00:24:00 2024 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; dkim=fail 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 1498408311824920.1392392065176; Sun, 25 Jun 2017 09:31:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CF94181227; Sun, 25 Jun 2017 16:31:47 +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 79AEB8CE21; Sun, 25 Jun 2017 16:31:46 +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 9682E1853DD3; Sun, 25 Jun 2017 16:31:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v5PGVeGm011212 for ; Sun, 25 Jun 2017 12:31:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6228E5D967; Sun, 25 Jun 2017 16:31:40 +0000 (UTC) Received: from mx1.redhat.com (ext-mx03.extmail.prod.ext.phx2.redhat.com [10.5.110.27]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B5385D9C3 for ; Sun, 25 Jun 2017 16:31:38 +0000 (UTC) Received: from mail-lf0-f48.google.com (mail-lf0-f48.google.com [209.85.215.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8BD3383F42 for ; Sun, 25 Jun 2017 16:31:36 +0000 (UTC) Received: by mail-lf0-f48.google.com with SMTP id l13so50287358lfl.1 for ; Sun, 25 Jun 2017 09:31:36 -0700 (PDT) Received: from kloomba.mnv.mirantis.net ([31.29.239.95]) by smtp.gmail.com with ESMTPSA id r82sm3006149lfr.57.2017.06.25.09.31.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Jun 2017 09:31:33 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CF94181227 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx01.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 CF94181227 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cHGBP/1t" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8BD3383F42 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=bogorodskiy@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8BD3383F42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=pHOrZuV7fpZghLjTpZ2nC6CtnsdO6ecI1WJiYNUn+Ag=; b=cHGBP/1td1HJY5rS14FcGfK/+uYPOjEgQixRsC2kEAL8wyIfJV/1VplsgCe+826TLB +YQ2fBayfX97J7WJ+rWpLPImdfEfGD29HNGbYfot+Do28QrbcgVLfU+l4R9WO8nLWNus w6IiTUV+7nyJHms0/ibmpeI2AZQXucgh+4ATpv8q1qBzuVg4T9UkbmJ53cnXTAYbdyjM PDmUIcWuWpVnAeXIqIn/pbnQ6x/jryYyJHUTfKFqVx0NEwVeRAC34B0O4GwE523V0KuM NWtFZQNb51ZeDr6OBnQXFkOtn/1YgqGR0qKva7vjc1ncSCtBhSCAfvCvVpK0a7s5DHKg uwKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pHOrZuV7fpZghLjTpZ2nC6CtnsdO6ecI1WJiYNUn+Ag=; b=TRnBBxLpta3+ZFMTwm/+46IBgFGSJgjT5iNI5u72mLdAQMIhQ/9Xa3+Zes+cGyZmcs L+37NoZvLEBvZwLM9Zyma0tZzN5mUyQ1Jku/xYtt9sK83rPLhfbrY4Od6AbYcN21GzLJ MO1K/+PynW0LPXosrSaRQbQZStUGFUSSP3bmyKUTnxVyvH17WHwKNXNXqCE8rO7RCWng nANC07qH6S8z7D4M2ePWp0bo/bhHo5Rju7cTe0ClF9ujwqqhvcBrYiKZ55jj5W2PUVMo nIPl69RueuLP3oXIDm1ziPOQaGS9O6JvUCLKd243gY8AOMfCwKiG/uqzLeC/VRnBRJHk WsvA== X-Gm-Message-State: AKS2vOz1zHv68RnvSfmwPqDuSkgtTLL0brhNFTPa4fVSdZK5CM2KRw/7 kMHeIF+hpeCJLshM X-Received: by 10.25.44.72 with SMTP id s69mr5580621lfs.156.1498408294538; Sun, 25 Jun 2017 09:31:34 -0700 (PDT) From: Roman Bogorodskiy To: libvir-list@redhat.com Date: Sun, 25 Jun 2017 20:31:24 +0400 Message-Id: <20170625163124.44725-1-bogorodskiy@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sun, 25 Jun 2017 16:31:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sun, 25 Jun 2017 16:31:37 +0000 (UTC) for IP:'209.85.215.48' DOMAIN:'mail-lf0-f48.google.com' HELO:'mail-lf0-f48.google.com' FROM:'bogorodskiy@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.77 (BAYES_50, DCC_REPUT_00_12, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.215.48 mail-lf0-f48.google.com 209.85.215.48 mail-lf0-f48.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.27 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Alexander Nusov Subject: [libvirt] [PATCH v2] bhyve: Add support for VNC autoport 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sun, 25 Jun 2017 16:31:49 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Alexander Nusov This patch adds support for automatic VNC port assignment for bhyve guests. --- Changes from v1: * Call virPortAllocatorRelease() in virBhyveProcessStop() to release VNC port; that's done unconditionally of using autoport * Call virPortAllocatorSetUsed(.., true) in virBhyveProcessReconnect() to reserve already used VNC ports after daemon restart * Call virPortAllocatorSetUsed(.., true) in bhyveBuildGraphicsArgStr() for domains that don't use autoport so allocator didn't try to use ports allocated by these domains * In dryRun mode (i.e. for domxml-to-native) don't allocate any ports * Add a couple of unit tests Note 1: while adding tests I noticed that port allocator will actually skip already bound ports, so I'm wondering if it makes any sense to use virPortAllocatorSetUsed(.., true)? Right now I cannot come up with any case to trigger this except probably some races when spawning guests simultaneously, but that's hard to reproduce. Note 2: there are still some cases where resources allocated during command preparation are not properly cleaned up; that's not only VNC ports, but also TAP devices. I plan to add proper cleanup routines separately. src/bhyve/bhyve_command.c | 25 +++++++++++-- src/bhyve/bhyve_driver.c | 5 +++ src/bhyve/bhyve_process.c | 20 +++++++++++ src/bhyve/bhyve_utils.h | 3 ++ .../bhyvexml2argv-vnc-autoport.args | 12 +++++++ .../bhyvexml2argv-vnc-autoport.ldargs | 1 + .../bhyvexml2argv-vnc-autoport.xml | 26 ++++++++++++++ tests/bhyvexml2argvtest.c | 7 ++++ .../bhyvexml2xmlout-vnc-autoport.xml | 41 ++++++++++++++++++= ++++ tests/bhyvexml2xmltest.c | 1 + 10 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.args create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.ldar= gs create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.xml create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-autoport.= xml diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index eae5cb3ca..e62b5df66 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -330,15 +330,19 @@ bhyveBuildLPCArgStr(const virDomainDef *def ATTRIBUTE= _UNUSED, } =20 static int -bhyveBuildGraphicsArgStr(const virDomainDef *def ATTRIBUTE_UNUSED, +bhyveBuildGraphicsArgStr(const virDomainDef *def, virDomainGraphicsDefPtr graphics, virDomainVideoDefPtr video, virConnectPtr conn, - virCommandPtr cmd) + virCommandPtr cmd, + bool dryRun) { virBuffer opt =3D VIR_BUFFER_INITIALIZER; virDomainGraphicsListenDefPtr glisten =3D NULL; bool escapeAddr; + unsigned short port; + + bhyveConnPtr driver =3D conn->privateData; =20 if (!(bhyveDriverGetCaps(conn) & BHYVE_CAP_LPC_BOOTROM) || def->os.bootloader || @@ -401,6 +405,20 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def ATTRI= BUTE_UNUSED, virBufferAdd(&opt, glisten->address, -1); } =20 + if (!dryRun) { + if (graphics->data.vnc.autoport) { + if (virPortAllocatorAcquire(driver->remotePorts, &port) < = 0) + return -1; + graphics->data.vnc.port =3D port; + } else { + if (virPortAllocatorSetUsed(driver->remotePorts, + graphics->data.vnc.port, + true) < 0) + VIR_WARN("Failed to mark VNC port '%d' as used by '%s'= ", + graphics->data.vnc.port, def->name); + } + } + virBufferAsprintf(&opt, ":%d", graphics->data.vnc.port); break; default: @@ -553,7 +571,8 @@ virBhyveProcessBuildBhyveCmd(virConnectPtr conn, =20 if (def->ngraphics && def->nvideos) { if (def->ngraphics =3D=3D 1 && def->nvideos =3D=3D 1) { - if (bhyveBuildGraphicsArgStr(def, def->graphics[0], def->video= s[0], conn, cmd) < 0) + if (bhyveBuildGraphicsArgStr(def, def->graphics[0], def->video= s[0], + conn, cmd, dryRun) < 0) goto error; add_lpc =3D true; } else { diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index ed2221a35..bffeea7d9 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -52,6 +52,7 @@ #include "viraccessapicheck.h" #include "virhostcpu.h" #include "virhostmem.h" +#include "virportallocator.h" #include "conf/domain_capabilities.h" =20 #include "bhyve_conf.h" @@ -1219,6 +1220,7 @@ bhyveStateCleanup(void) virObjectUnref(bhyve_driver->closeCallbacks); virObjectUnref(bhyve_driver->domainEventState); virObjectUnref(bhyve_driver->config); + virObjectUnref(bhyve_driver->remotePorts); =20 virMutexDestroy(&bhyve_driver->lock); VIR_FREE(bhyve_driver); @@ -1265,6 +1267,9 @@ bhyveStateInitialize(bool privileged, if (!(bhyve_driver->domainEventState =3D virObjectEventStateNew())) goto cleanup; =20 + if (!(bhyve_driver->remotePorts =3D virPortAllocatorNew(_("display"), = 5900, 65535, 0))) + goto cleanup; + bhyve_driver->hostsysinfo =3D virSysinfoRead(); =20 if (!(bhyve_driver->config =3D virBhyveDriverConfigNew())) diff --git a/src/bhyve/bhyve_process.c b/src/bhyve/bhyve_process.c index a97e300ff..7211156ca 100644 --- a/src/bhyve/bhyve_process.c +++ b/src/bhyve/bhyve_process.c @@ -293,6 +293,16 @@ virBhyveProcessStop(bhyveConnPtr driver, /* Cleanup network interfaces */ bhyveNetCleanup(vm); =20 + /* VNC autoport cleanup */ + if ((vm->def->ngraphics =3D=3D 1) && + vm->def->graphics[0]->type =3D=3D VIR_DOMAIN_GRAPHICS_TYPE_VNC) { + if (virPortAllocatorRelease(driver->remotePorts, + vm->def->graphics[0]->data.vnc.port) <= 0) { + VIR_WARN("Failed to release VNC port for '%s'", + vm->def->name); + } + } + ret =3D 0; =20 virCloseCallbacksUnset(driver->closeCallbacks, vm, @@ -412,6 +422,16 @@ virBhyveProcessReconnect(virDomainObjPtr vm, if (STREQ(expected_proctitle, proc_argv[0])) { ret =3D 0; priv->mon =3D bhyveMonitorOpen(vm, data->driver); + if (vm->def->ngraphics =3D=3D 1 && + vm->def->graphics[0]->type =3D=3D VIR_DOMAIN_GRAPHICS_TYP= E_VNC) { + int vnc_port =3D vm->def->graphics[0]->data.vnc.port; + if (virPortAllocatorSetUsed(data->driver->remotePorts, + vnc_port, + true) < 0) { + VIR_WARN("Failed to mark VNC port '%d' as used by '%s= '", + vnc_port, vm->def->name); + } + } } } =20 diff --git a/src/bhyve/bhyve_utils.h b/src/bhyve/bhyve_utils.h index db50e012a..8ad2698d4 100644 --- a/src/bhyve/bhyve_utils.h +++ b/src/bhyve/bhyve_utils.h @@ -28,6 +28,7 @@ # include "virdomainobjlist.h" # include "virthread.h" # include "virclosecallbacks.h" +# include "virportallocator.h" =20 # define BHYVE_AUTOSTART_DIR SYSCONFDIR "/libvirt/bhyve/autostart" # define BHYVE_CONFIG_DIR SYSCONFDIR "/libvirt/bhyve" @@ -58,6 +59,8 @@ struct _bhyveConn { =20 virCloseCallbacksPtr closeCallbacks; =20 + virPortAllocatorPtr remotePorts; + unsigned bhyvecaps; unsigned grubcaps; }; diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.args b/test= s/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.args new file mode 100644 index 000000000..039526ff3 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.args @@ -0,0 +1,12 @@ +/usr/sbin/bhyve \ +-c 1 \ +-m 214 \ +-u \ +-H \ +-P \ +-s 0:0,hostbridge \ +-l bootrom,/path/to/test.fd \ +-s 2:0,ahci,hd:/tmp/freebsd.img \ +-s 3:0,virtio-net,faketapdev,mac=3D52:54:00:00:00:00 \ +-s 4:0,fbuf,tcp=3D127.0.0.1:5900 \ +-s 1,lpc bhyve diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.ldargs b/te= sts/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.ldargs new file mode 100644 index 000000000..421376db9 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.ldargs @@ -0,0 +1 @@ +dummy diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.xml b/tests= /bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.xml new file mode 100644 index 000000000..afb73f040 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-vnc-autoport.xml @@ -0,0 +1,26 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + /path/to/test.fd + + + + + + +
+ + + + +
+ + + + + + diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index c8f8c685a..95fada0bd 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -145,6 +145,11 @@ mymain(void) if ((driver.xmlopt =3D virBhyveDriverCreateXMLConf(&driver)) =3D=3D NU= LL) return EXIT_FAILURE; =20 + if (!(driver.remotePorts =3D virPortAllocatorNew("display", 5900, 6553= 5, + VIR_PORT_ALLOCATOR_SKIP= _BIND_CHECK))) + return EXIT_FAILURE; + + # define DO_TEST_FULL(name, flags) \ do { \ static struct testInfo info =3D { \ @@ -193,6 +198,7 @@ mymain(void) DO_TEST("net-e1000"); DO_TEST("uefi"); DO_TEST("vnc"); + DO_TEST("vnc-autoport"); =20 /* Address allocation tests */ DO_TEST("addr-single-sata-disk"); @@ -231,6 +237,7 @@ mymain(void) =20 virObjectUnref(driver.caps); virObjectUnref(driver.xmlopt); + virObjectUnref(driver.remotePorts); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-autoport.xml b/t= ests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-autoport.xml new file mode 100644 index 000000000..d6cfe76b7 --- /dev/null +++ b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-vnc-autoport.xml @@ -0,0 +1,41 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 219136 + 1 + + hvm + /path/to/test.fd + + + + destroy + restart + destroy + + + + + +
+ + + +
+ + + + + +
+ + + + +