From nobody Sat May 11 08:37:17 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=fail(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1695915705; cv=none; d=zohomail.com; s=zohoarc; b=CdCdPtUUDpRqCafbIHndXUpp4Ita9cfYCJ4+HLrVllxgcN6PHHDILQOClXpk0GFDWC4PrxfDmpQlw3builzEbDZF8JBOUH1iOK+AhTnPrxlCCmKPF4Fem/sJb3g/Ica8WCi7mQ/SIyX/WDn69h+/0cDyEfXIt1J8qZSFQxDYy7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695915705; h=Content-Type:Content-Transfer-Encoding:Cc: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=Aun/URs/nh7pSCUseegZjHv99ty+tFGSah7SqofMqFY=; b=CxSVrt3alW1O36NdJMhxmy4BFlL5X8eei9+jOLjZWso7i5cKjtgxEBjage6BThOF1gaXRUUg58lw9DccX65kC1hGLK1LGn/xaa9LClu29cZRfM8dszEcrAptrHyhJoDbB4I9rJOiTteNcJjdiEb22gDLGtwNh2Zlv+2MGu/iRq8= 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=fail header.from= (p=reject 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 1695915705927803.9184983393393; Thu, 28 Sep 2023 08:41:45 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-156-KV3PqK6CPxaBJ2s9eXlG6w-1; Thu, 28 Sep 2023 11:41:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 8AEFF280BC4D; Thu, 28 Sep 2023 15:41:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96C022156702; Thu, 28 Sep 2023 15:41:35 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 391421946588; Thu, 28 Sep 2023 15:41:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9AC8B1946587 for ; Thu, 28 Sep 2023 15:37:34 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 8BC76215670B; Thu, 28 Sep 2023 15:37:34 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast09.extmail.prod.ext.rdu2.redhat.com [10.11.55.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 83DD02156702 for ; Thu, 28 Sep 2023 15:37:34 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.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 615B6280BC9A for ; Thu, 28 Sep 2023 15:37:34 +0000 (UTC) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-333--aPRCmpJODa-BDAWT3cjWQ-1; Thu, 28 Sep 2023 11:37:32 -0400 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38SFIkaE008259; Thu, 28 Sep 2023 15:37:31 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tdbk29c76-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 15:37:31 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 38SElPrG030454; Thu, 28 Sep 2023 15:37:30 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3tad2250qg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 15:37:30 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 38SFbS8p28115556 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Sep 2023 15:37:28 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A6F9E2004D; Thu, 28 Sep 2023 15:37:28 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4818020043; Thu, 28 Sep 2023 15:37:28 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.ibm.com.com (unknown [9.171.83.163]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 28 Sep 2023 15:37:28 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695915704; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Aun/URs/nh7pSCUseegZjHv99ty+tFGSah7SqofMqFY=; b=gEAp5o0EIo5/4MXFPfC0mbzvuKmWdgRQVSZynETK37dhMZ+dwnoXNY2wzxatV2nYhJgzAK xDVlqror80naBPbJ8DMTm5u73dT0rNtPjdTs2P85hYsg1V2mijd6hTBedmjvzj9pHyGjpj MjLr63WnRUGiFw3NUwF9Wmzq6bPP/YY= X-MC-Unique: KV3PqK6CPxaBJ2s9eXlG6w-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: -aPRCmpJODa-BDAWT3cjWQ-1 From: Marc Hartmayer To: Subject: [PATCH libvirt v1 1/3] virsh: add `console --resume` support Date: Thu, 28 Sep 2023 17:37:08 +0200 Message-ID: <20230928153710.14340-2-mhartmay@linux.ibm.com> In-Reply-To: <20230928153710.14340-1-mhartmay@linux.ibm.com> References: <20230928153710.14340-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Pe17xx5IYTm-VuQHyKHt46XDIRb8KHHw X-Proofpoint-ORIG-GUID: Pe17xx5IYTm-VuQHyKHt46XDIRb8KHHw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-28_14,2023-09-28_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 phishscore=0 clxscore=1015 mlxscore=0 spamscore=0 bulkscore=0 mlxlogscore=761 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309280130 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 3.1 on 10.11.54.6 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , Boris Fiuczynski Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: linux.ibm.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695915708230100001 Content-Type: text/plain; charset="utf-8"; x-default="true" This patch adds the command line flag `--resume` to the `virsh console` command. This resumes a paused guest after connecting to the console. This might be handy since it's a "common" pattern to start a guest paused, connect to the console, and then resume it so as not to miss any console messages. Reviewed-by: Boris Fiuczynski Signed-off-by: Marc Hartmayer Reviewed-by: Michal Privoznik Reviewed-by: Thomas Huth --- tools/virsh-console.c | 8 ++++++++ tools/virsh-console.h | 1 + tools/virsh-domain.c | 14 ++++++++++---- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/virsh-console.c b/tools/virsh-console.c index 6bfb44a190ec..e44a070e7045 100644 --- a/tools/virsh-console.c +++ b/tools/virsh-console.c @@ -401,6 +401,7 @@ int virshRunConsole(vshControl *ctl, virDomainPtr dom, const char *dev_name, + const bool resume_domain, unsigned int flags) { virConsole *con =3D NULL; @@ -476,6 +477,13 @@ virshRunConsole(vshControl *ctl, goto cleanup; } =20 + if (resume_domain) { + if (virDomainResume(dom) !=3D 0) { + vshError(ctl, _("Failed to resume domain '%1$s'"), virDomainGe= tName(dom)); + goto cleanup; + } + } + while (!con->quit) { if (virCondWait(&con->cond, &con->parent.lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", diff --git a/tools/virsh-console.h b/tools/virsh-console.h index e89484d24bf4..2d00ed90cf4a 100644 --- a/tools/virsh-console.h +++ b/tools/virsh-console.h @@ -27,6 +27,7 @@ int virshRunConsole(vshControl *ctl, virDomainPtr dom, const char *dev_name, + const bool resume_domain, unsigned int flags); =20 #endif /* !WIN32 */ diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7abafe2ba30c..5c3c6d18aebf 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3012,6 +3012,10 @@ static const vshCmdOptDef opts_console[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("force console connection (disconnect already connected= sessions)") }, + {.name =3D "resume", + .type =3D VSH_OT_BOOL, + .help =3D N_("resume a paused guest after connecting to console") + }, {.name =3D "safe", .type =3D VSH_OT_BOOL, .help =3D N_("only connect if safe console handling is supported") @@ -3022,6 +3026,7 @@ static const vshCmdOptDef opts_console[] =3D { static bool cmdRunConsole(vshControl *ctl, virDomainPtr dom, const char *name, + const bool resume_domain, unsigned int flags) { int state; @@ -3048,7 +3053,7 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom, vshPrintExtra(ctl, " (Ctrl + %c)", priv->escapeChar[1]); vshPrintExtra(ctl, "\n"); fflush(stdout); - if (virshRunConsole(ctl, dom, name, flags) =3D=3D 0) + if (virshRunConsole(ctl, dom, name, resume_domain, flags) =3D=3D 0) return true; =20 return false; @@ -3059,6 +3064,7 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; bool force =3D vshCommandOptBool(cmd, "force"); + bool resume =3D vshCommandOptBool(cmd, "resume"); bool safe =3D vshCommandOptBool(cmd, "safe"); unsigned int flags =3D 0; const char *name =3D NULL; @@ -3074,7 +3080,7 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd) if (safe) flags |=3D VIR_DOMAIN_CONSOLE_SAFE; =20 - return cmdRunConsole(ctl, dom, name, flags); + return cmdRunConsole(ctl, dom, name, resume, flags); } #endif /* WIN32 */ =20 @@ -4136,7 +4142,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Domain '%1$s' started\n"), virDomainGetName(dom)); #ifndef WIN32 - if (console && !cmdRunConsole(ctl, dom, NULL, 0)) + if (console && !cmdRunConsole(ctl, dom, NULL, false, 0)) return false; #endif =20 @@ -8232,7 +8238,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) virDomainGetName(dom), from); #ifndef WIN32 if (console) - cmdRunConsole(ctl, dom, NULL, 0); + cmdRunConsole(ctl, dom, NULL, false, 0); #endif return true; } --=20 2.34.1 From nobody Sat May 11 08:37:17 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=fail(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1695917171; cv=none; d=zohomail.com; s=zohoarc; b=mEtsHGenLTWAX2DCYZb7zq+DmmZ24P4B6bt9bxPymZnE+VVDcJSN7JiUpyYy+thBWo7KUUz2++OyM+sZTV0VmvADCYzveeLLEM9n0K3QOUhq8mcufZRgOeYwD74R53PhfDax8crjP3LgBwBA1z+KCMuibvNBxXmUneiZbhN3APk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695917171; h=Content-Type:Content-Transfer-Encoding:Cc: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=UR381ZLEbM3B/6QW18x6HRWiX4iSP1dUZBQnKLB2JZ0=; b=Y7E4Eqf4ZgVhJmgEdfu5EPVK6hVrbsjFD0ZOuuU6rF9kxy0zvObjfF/74cvSKv5dJ2I22t9Ncmf2RwdMgKKqYUBRWrDGEICWkw6DQ6X2snDJrpA6+Cg10mLfxNguRHxLs4gZO+2JvRJWHO7+3pQMLIeUs+0d2TWvlD31fj6jI9M= 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=fail header.from= (p=reject 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 1695917171324508.3571604827722; Thu, 28 Sep 2023 09:06:11 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-675-tzZ0H_oSNQasLCXM5nfxww-1; Thu, 28 Sep 2023 12:06:02 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 1F4448060F9; Thu, 28 Sep 2023 16:05:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06DDA492C37; Thu, 28 Sep 2023 16:05:58 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 1253719466E9; Thu, 28 Sep 2023 16:05:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CD6741946587 for ; Thu, 28 Sep 2023 15:37:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id AFAB610EE402; Thu, 28 Sep 2023 15:37:35 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A725410EE6C9 for ; Thu, 28 Sep 2023 15:37:35 +0000 (UTC) Received: from us-smtp-inbound-delivery-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 89BA0801779 for ; Thu, 28 Sep 2023 15:37:35 +0000 (UTC) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-280-F1WOaBzCPCKUo-PMNO72hg-1; Thu, 28 Sep 2023 11:37:33 -0400 Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38SFQIqb021954; Thu, 28 Sep 2023 15:37:32 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tdc4ngauq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 15:37:31 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 38SDg68l011010; Thu, 28 Sep 2023 15:37:31 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3tabukwaua-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 15:37:31 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 38SFbTks21758624 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Sep 2023 15:37:29 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2CE5220040; Thu, 28 Sep 2023 15:37:29 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C320220043; Thu, 28 Sep 2023 15:37:28 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.ibm.com.com (unknown [9.171.83.163]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 28 Sep 2023 15:37:28 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695917170; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=UR381ZLEbM3B/6QW18x6HRWiX4iSP1dUZBQnKLB2JZ0=; b=AFA6KXdSI5I+jIBPyChfi96UMq2hXz7tAXKFBhP241OpASnw5Y4HBvxJyDnX8mDd61kQPH V2/JpJs966XPogd/tHKffRrZexlQBxiSC94zLR0vaivw8FSW+1pR7xkonoV5o5crJU+FmO sqjbFcK1mFhkwmjkRkyfgxRl478oHrA= X-MC-Unique: tzZ0H_oSNQasLCXM5nfxww-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: F1WOaBzCPCKUo-PMNO72hg-1 From: Marc Hartmayer To: Subject: [PATCH libvirt v1 2/3] Improve `virsh start --console` behavior Date: Thu, 28 Sep 2023 17:37:09 +0200 Message-ID: <20230928153710.14340-3-mhartmay@linux.ibm.com> In-Reply-To: <20230928153710.14340-1-mhartmay@linux.ibm.com> References: <20230928153710.14340-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Po7zZ2cSw41rjMmm5KXwFJNK-YyhQR9t X-Proofpoint-ORIG-GUID: Po7zZ2cSw41rjMmm5KXwFJNK-YyhQR9t X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-28_14,2023-09-28_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 phishscore=0 impostorscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 suspectscore=0 mlxscore=0 mlxlogscore=482 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309280130 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 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , Boris Fiuczynski Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: linux.ibm.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695917173495100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When starting a guest via libvirt (`virsh start --console`), early console output was missed because the guest was started first and then the console was attached. This patch changes this to the following sequence: 1. create a paused guest 2. attach the console 3. resume the guest Reviewed-by: Boris Fiuczynski Signed-off-by: Marc Hartmayer Reviewed-by: Michal Privoznik Reviewed-by: Thomas Huth --- tools/virsh-domain.c | 50 +++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 5c3c6d18aebf..36670039444c 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4059,12 +4059,27 @@ static const vshCmdOptDef opts_start[] =3D { {.name =3D NULL} }; =20 +static int +virDomainCreateHelper(virDomainPtr dom, unsigned int nfds, int *fds, + unsigned int flags) +{ + /* Prefer older API unless we have to pass a flag. */ + if (nfds > 0) { + return virDomainCreateWithFiles(dom, nfds, fds, flags); + } else if (flags !=3D 0) { + return virDomainCreateWithFlags(dom, flags); + } else { + return virDomainCreate(dom); + } +} + static bool cmdStart(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshDomain) dom =3D NULL; #ifndef WIN32 bool console =3D vshCommandOptBool(cmd, "console"); + bool resume_domain =3D false; #endif unsigned int flags =3D VIR_DOMAIN_NONE; int rc; @@ -4083,8 +4098,14 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) if (virshFetchPassFdsList(ctl, cmd, &nfds, &fds) < 0) return false; =20 - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(cmd, "paused")) { flags |=3D VIR_DOMAIN_START_PAUSED; +#ifndef WIN32 + } else if (console) { + flags |=3D VIR_DOMAIN_START_PAUSED; + resume_domain =3D true; +#endif + } if (vshCommandOptBool(cmd, "autodestroy")) flags |=3D VIR_DOMAIN_START_AUTODESTROY; if (vshCommandOptBool(cmd, "bypass-cache")) @@ -4096,12 +4117,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) =20 /* We can emulate force boot, even for older servers that reject it. = */ if (flags & VIR_DOMAIN_START_FORCE_BOOT) { - if (nfds > 0) { - rc =3D virDomainCreateWithFiles(dom, nfds, fds, flags); - } else { - rc =3D virDomainCreateWithFlags(dom, flags); - } - + rc =3D virDomainCreateHelper(dom, nfds, fds, flags); if (rc =3D=3D 0) goto started; =20 @@ -4124,14 +4140,18 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) flags &=3D ~VIR_DOMAIN_START_FORCE_BOOT; } =20 - /* Prefer older API unless we have to pass a flag. */ - if (nfds > 0) { - rc =3D virDomainCreateWithFiles(dom, nfds, fds, flags); - } else if (flags !=3D 0) { - rc =3D virDomainCreateWithFlags(dom, flags); - } else { - rc =3D virDomainCreate(dom); + rc =3D virDomainCreateHelper(dom, nfds, fds, flags); +#ifndef WIN32 + /* If the driver does not support the paused flag, let's fallback to t= he old + * behavior without the flag. */ + if (rc < 0 && resume_domain && last_error && last_error->code =3D=3D V= IR_ERR_INVALID_ARG) { + vshResetLibvirtError(); + + flags &=3D ~VIR_DOMAIN_START_PAUSED; + resume_domain =3D false; + rc =3D virDomainCreateHelper(dom, nfds, fds, flags); } +#endif =20 if (rc < 0) { vshError(ctl, _("Failed to start domain '%1$s'"), virDomainGetName= (dom)); @@ -4142,7 +4162,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Domain '%1$s' started\n"), virDomainGetName(dom)); #ifndef WIN32 - if (console && !cmdRunConsole(ctl, dom, NULL, false, 0)) + if (console && !cmdRunConsole(ctl, dom, NULL, resume_domain, 0)) return false; #endif =20 --=20 2.34.1 From nobody Sat May 11 08:37:17 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=fail(p=reject dis=none) header.from=linux.ibm.com ARC-Seal: i=1; a=rsa-sha256; t=1695917648; cv=none; d=zohomail.com; s=zohoarc; b=VSAgjS5ccLwVf3zfvaW8LEzNbPlLgG0Y7DDmeDzQbA6ImT61YtKECIMcXME6gCd1ksv4vDtV0JL+/LNgDwNxeDVP/vVpiTML17HXU+RZhUv7wAUXmXeV0DSy/GG1e2rXlfqynAh0TkKMLWukNiPD6pSjUWuWGRFjkDSVLQb1hEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695917648; h=Content-Type:Content-Transfer-Encoding:Cc: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=nr4faqBu7BYXdMJ1RAquN0GKNZXNsBeIAmN9AgBSTCk=; b=ky4H7KARj2XtO/eFjdXHjea6/jvXTbJJw9eVgVQt7f9bpdl3I0dKynOtGx1Ruq2sitrD+2gWueJwunc9V5KUijGOOE9JzKnzhl98t4sbeF0xL+B0AvjTlwmRo+tON4rbG+ZW2CA+Sar7pO9SDiKOYnNQ2pb73KrR+67QZsS2xJk= 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=fail header.from= (p=reject 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 1695917648554767.8073446048385; Thu, 28 Sep 2023 09:14:08 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-204--3dzTob9MByr_ajUeMVMBA-1; Thu, 28 Sep 2023 12:14:03 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 DCCB2101A550; Thu, 28 Sep 2023 16:14:00 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3BEE740C2009; Thu, 28 Sep 2023 16:14:00 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DFC361946589; Thu, 28 Sep 2023 16:13:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CC0C51946587 for ; Thu, 28 Sep 2023 15:37:40 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A98C0176E4; Thu, 28 Sep 2023 15:37:35 +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 A124D28FE for ; Thu, 28 Sep 2023 15:37:35 +0000 (UTC) Received: from us-smtp-inbound-delivery-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 825571875052 for ; Thu, 28 Sep 2023 15:37:35 +0000 (UTC) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-348-vUqbvtJ3M3qgSD2nYyNpOg-1; Thu, 28 Sep 2023 11:37:33 -0400 Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38SFIvtV008306; Thu, 28 Sep 2023 15:37:32 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tdbk29c81-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 15:37:32 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 38SDt2l9010995; Thu, 28 Sep 2023 15:37:31 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3tabukwaue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Sep 2023 15:37:31 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 38SFbTdf21758628 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 28 Sep 2023 15:37:29 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A779D20040; Thu, 28 Sep 2023 15:37:29 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4910220043; Thu, 28 Sep 2023 15:37:29 +0000 (GMT) Received: from li-1de7cd4c-3205-11b2-a85c-d27f97db1fe1.ibm.com.com (unknown [9.171.83.163]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 28 Sep 2023 15:37:29 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695917647; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=nr4faqBu7BYXdMJ1RAquN0GKNZXNsBeIAmN9AgBSTCk=; b=hj5m75vKGicWmH7jx+N3LxIRbifumDlR1kv1CXPQOULmoUuvKtSzAsStHOncnCy9ur5LoO EAliLZJDIIMWjKFqOebIRW8gDzT8R/xolGYpH8SREuWFx+VLVoKSzkQKQzv5Tvpaboanbh bB3qDFABXrPz1Fq1g898aFxNAksmmys= X-MC-Unique: -3dzTob9MByr_ajUeMVMBA-1 X-Original-To: libvir-list@listman.corp.redhat.com X-MC-Unique: vUqbvtJ3M3qgSD2nYyNpOg-1 From: Marc Hartmayer To: Subject: [PATCH libvirt v1 3/3] Improve `virsh create --console` behavior Date: Thu, 28 Sep 2023 17:37:10 +0200 Message-ID: <20230928153710.14340-4-mhartmay@linux.ibm.com> In-Reply-To: <20230928153710.14340-1-mhartmay@linux.ibm.com> References: <20230928153710.14340-1-mhartmay@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: x7JQS5iiMvuEOGLXeImjLz2nCMELp5tU X-Proofpoint-ORIG-GUID: x7JQS5iiMvuEOGLXeImjLz2nCMELp5tU X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-28_14,2023-09-28_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 malwarescore=0 phishscore=0 clxscore=1015 mlxscore=0 spamscore=0 bulkscore=0 mlxlogscore=603 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309280130 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 3.1 on 10.11.54.5 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , Boris Fiuczynski Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: linux.ibm.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1695917649907100001 Content-Type: text/plain; charset="utf-8"; x-default="true" When starting a guest via libvirt (`virsh create --console`), early console output was missed because the guest was started first and then the console was attached. This patch changes this to the following sequence: 1. create a paused transient guest 2. attach the console 3. resume the guest Reviewed-by: Boris Fiuczynski Signed-off-by: Marc Hartmayer Reviewed-by: Michal Privoznik Reviewed-by: Thomas Huth --- tools/virsh-domain.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 36670039444c..2f055df0d97d 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8212,6 +8212,13 @@ static const vshCmdOptDef opts_create[] =3D { {.name =3D NULL} }; =20 + +static virshDomain *virDomainCreateXMLHelper(virConnectPtr conn, const cha= r *xmlDesc, unsigned int nfds, int *fds, unsigned int flags) { + if (nfds) + return virDomainCreateXMLWithFiles(conn, xmlDesc, nfds, fds, flags); + return virDomainCreateXML(conn, xmlDesc, flags); +} + static bool cmdCreate(vshControl *ctl, const vshCmd *cmd) { @@ -8220,6 +8227,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) g_autofree char *buffer =3D NULL; #ifndef WIN32 bool console =3D vshCommandOptBool(cmd, "console"); + bool resume_domain =3D false; #endif unsigned int flags =3D 0; size_t nfds =3D 0; @@ -8235,8 +8243,14 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (virshFetchPassFdsList(ctl, cmd, &nfds, &fds) < 0) return false; =20 - if (vshCommandOptBool(cmd, "paused")) + if (vshCommandOptBool(cmd, "paused")) { flags |=3D VIR_DOMAIN_START_PAUSED; +#ifndef WIN32 + } else if (console) { + flags |=3D VIR_DOMAIN_START_PAUSED; + resume_domain =3D true; +#endif + } if (vshCommandOptBool(cmd, "autodestroy")) flags |=3D VIR_DOMAIN_START_AUTODESTROY; if (vshCommandOptBool(cmd, "validate")) @@ -8244,10 +8258,18 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptBool(cmd, "reset-nvram")) flags |=3D VIR_DOMAIN_START_RESET_NVRAM; =20 - if (nfds) - dom =3D virDomainCreateXMLWithFiles(priv->conn, buffer, nfds, fds,= flags); - else - dom =3D virDomainCreateXML(priv->conn, buffer, flags); + dom =3D virDomainCreateXMLHelper(priv->conn, buffer, nfds, fds, flags); +#ifndef WIN32 + /* If the driver does not support the paused flag, let's fallback to t= he old + * behavior without the flag. */ + if (!dom && resume_domain && last_error && last_error->code =3D=3D VIR= _ERR_INVALID_ARG) { + vshResetLibvirtError(); + + flags &=3D ~VIR_DOMAIN_START_PAUSED; + resume_domain =3D false; + dom =3D virDomainCreateXMLHelper(priv->conn, buffer, nfds, fds, flag= s); + } +#endif =20 if (!dom) { vshError(ctl, _("Failed to create domain from %1$s"), from); @@ -8258,7 +8280,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) virDomainGetName(dom), from); #ifndef WIN32 if (console) - cmdRunConsole(ctl, dom, NULL, false, 0); + cmdRunConsole(ctl, dom, NULL, resume_domain, 0); #endif return true; } --=20 2.34.1