From nobody Sun Feb 8 17:21:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 163001482761511.241627800078732; Thu, 26 Aug 2021 14:53:47 -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-153-jS1kFwpjOYCh4tcfkmKW3Q-1; Thu, 26 Aug 2021 17:53:45 -0400 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 BF02F3E746; Thu, 26 Aug 2021 21:53:37 +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 9317B2855A; Thu, 26 Aug 2021 21:53:37 +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 5E0974A709; Thu, 26 Aug 2021 21:53:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17QLrK5l011809 for ; Thu, 26 Aug 2021 17:53:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id AC01814193D; Thu, 26 Aug 2021 21:53:20 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6B8414E78B for ; Thu, 26 Aug 2021 21:53:20 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8F22418A01A5 for ; Thu, 26 Aug 2021 21:53:20 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-472-PTAmQhKLPLaR5t7xK-MyOw-2; Thu, 26 Aug 2021 17:53:18 -0400 Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2021 14:52:02 -0700 Received: from wdouglas-dev.jf.intel.com (HELO desk.jf.intel.com) ([10.7.200.157]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Aug 2021 14:51:58 -0700 X-MC-Unique: jS1kFwpjOYCh4tcfkmKW3Q-1 X-MC-Unique: PTAmQhKLPLaR5t7xK-MyOw-2 X-IronPort-AV: E=McAfee;i="6200,9189,10088"; a="281568243" X-IronPort-AV: E=Sophos;i="5.84,354,1620716400"; d="scan'208";a="281568243" X-IronPort-AV: E=Sophos;i="5.84,354,1620716400"; d="scan'208";a="465266040" From: William Douglas To: libvir-list@redhat.com Subject: [PATCH 8/8] ch_driver: Add handler for console API Date: Thu, 26 Aug 2021 14:59:22 -0700 Message-Id: <20210826215922.703741-9-william.douglas@intel.com> In-Reply-To: <20210826215922.703741-1-william.douglas@intel.com> References: <20210826215922.703741-1-william.douglas@intel.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, William Douglas 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-ZM-MESSAGEID: 1630014828147100010 Content-Type: text/plain; charset="utf-8" Enable the handler function to find and open the console character device that will be used by the console API. Signed-off-by: William Douglas --- src/ch/ch_driver.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index ac958d73a8..a11357f83a 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -30,6 +30,7 @@ #include "viraccessapicheck.h" #include "viralloc.h" #include "virbuffer.h" +#include "virchrdev.h" #include "vircommand.h" #include "virerror.h" #include "virfile.h" @@ -816,6 +817,82 @@ static int chDomainGetInfo(virDomainPtr dom, return ret; } =20 +static int +chDomainOpenConsole(virDomainPtr dom, + const char *dev_name, + virStreamPtr st, + unsigned int flags) +{ + virDomainObj *vm =3D NULL; + int ret =3D -1; + size_t i; + virDomainChrDef *chr =3D NULL; + virCHDomainObjPrivate *priv; + + virCheckFlags(VIR_DOMAIN_CONSOLE_SAFE | VIR_DOMAIN_CONSOLE_FORCE, -1); + + if (!(vm =3D chDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainOpenConsoleEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + priv =3D vm->privateData; + + if (dev_name) { + for (i =3D 0; !chr && i < vm->def->nconsoles; i++) { + if (vm->def->consoles[i]->info.alias && + STREQ(dev_name, vm->def->consoles[i]->info.alias)) + chr =3D vm->def->consoles[i]; + } + for (i =3D 0; !chr && i < vm->def->nserials; i++) { + if (STREQ(dev_name, vm->def->serials[i]->info.alias)) + chr =3D vm->def->serials[i]; + } + for (i =3D 0; !chr && i < vm->def->nparallels; i++) { + if (STREQ(dev_name, vm->def->parallels[i]->info.alias)) + chr =3D vm->def->parallels[i]; + } + } else { + if (vm->def->nconsoles && + vm->def->consoles[0]->source->type =3D=3D VIR_DOMAIN_CHR_TYP= E_PTY) + chr =3D vm->def->consoles[0]; + else if (vm->def->nserials && + vm->def->serials[0]->source->type =3D=3D VIR_DOMAIN_CHR= _TYPE_PTY) + chr =3D vm->def->serials[0]; + } + + if (!chr) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("cannot find character = device %s"), + NULLSTR(dev_name)); + goto cleanup; + } + + if (chr->source->type !=3D VIR_DOMAIN_CHR_TYPE_PTY) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("character device %s is not using a PTY"), + dev_name ? dev_name : NULLSTR(chr->info.alias)); + goto cleanup; + } + + /* handle mutually exclusive access to console devices */ + ret =3D virChrdevOpen(priv->chrdevs, chr->source, st, + (flags & VIR_DOMAIN_CONSOLE_FORCE) !=3D 0); + + if (ret =3D=3D 1) { + virReportError(VIR_ERR_OPERATION_FAILED, "%s", + _("Active console session exists for this domain"= )); + ret =3D -1; + } + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static int chStateCleanup(void) { if (ch_driver =3D=3D NULL) @@ -913,6 +990,7 @@ static virHypervisorDriver chHypervisorDriver =3D { .domainGetXMLDesc =3D chDomainGetXMLDesc, /* 7.5.0 */ .domainGetInfo =3D chDomainGetInfo, /* 7.5.0 */ .domainIsActive =3D chDomainIsActive, /* 7.5.0 */ + .domainOpenConsole =3D chDomainOpenConsole, /* 7.6.0 */ .nodeGetInfo =3D chNodeGetInfo, /* 7.5.0 */ }; =20 --=20 2.31.1