From nobody Sat Apr 20 02:49:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1578573981; cv=none; d=zohomail.com; s=zohoarc; b=mQ6gzRskQL077mUBwB0p93oekjBoBNnWdw63ruOB8B19dLNefQNExkWUIFU+T3jXJXlnUamIdA3sZBVi1OuS8/WRQaBMQtPkEHY5k8yaONrHZv9YATx3BmCwDS9r5YrzhuYT1IGa7du45ZdWoFbt+CGbvGlACNrzy9DQWRaF/w4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578573981; 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=1J/1tqO83VSKJboBqu683cEuBljy30hvbeJTimzjLJA=; b=Rn//PFLuhhVZRONZJhAZVNBeohw65EDUoSQC0tqKRylmO1UB/cx5pkecwH4Uj1IK2thw+qmw8kUju5/Zut1DOZIHlvKq2Bip9LpkYVcSAUyv5pum9HyYVs+tPSeg3LQk2ErfwAufvkxWg7cuwH82FdpkcYKQtWE+2/8WLpIE4ws= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 157857398177983.22403958310656; Thu, 9 Jan 2020 04:46:21 -0800 (PST) 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-84-0A4LX1HpMGKLuCUgHk7KXA-1; Thu, 09 Jan 2020 07:46:19 -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 5A3AD800D5B; Thu, 9 Jan 2020 12:46:13 +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 AC3FC5DA32; Thu, 9 Jan 2020 12:46:12 +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 894F4503C1; Thu, 9 Jan 2020 12:46:09 +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 009Ck82t030815 for ; Thu, 9 Jan 2020 07:46:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4D87086CA0; Thu, 9 Jan 2020 12:46:08 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A27F986C5C; Thu, 9 Jan 2020 12:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578573980; 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=1J/1tqO83VSKJboBqu683cEuBljy30hvbeJTimzjLJA=; b=BD1Z+rNwRGvUCuVPLvlSbRrRzT3dqQtUeO1FOAgqt6fz2Jl0SPmOOscCLM7aPseVFcW7Ya HovtC1+BppvYN283mCyY3NLuUC5J3O3FJduWHPgO2ZMv/owbwoaJKheUMzrdgWkHscVnYw X6Y2FNhLRHBY7S4aF7QouxszLvNv1Bc= From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 9 Jan 2020 13:45:56 +0100 Message-Id: <867cf6e203c39406dfd0b8dc159f68e9de39c1ce.1578573671.git.mprivozn@redhat.com> 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 Cc: jcfaracco@gmail.com Subject: [libvirt] [PATCH v4 1/5] virerror: Make it easier to add new error number 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 X-MC-Unique: 0A4LX1HpMGKLuCUgHk7KXA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In v5.0.0-rc1~94 we switched from one huge switch() to an array for translating error numbers into error messages. However, the array is declared to have VIR_ERR_NUMBER_LAST items which makes it impossible to spot this place by compile checking when adding new error number. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- scripts/apibuild.py | 6 ++++++ src/util/virerror.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/apibuild.py b/scripts/apibuild.py index 2f7314b379..595c004a4c 100755 --- a/scripts/apibuild.py +++ b/scripts/apibuild.py @@ -1657,6 +1657,12 @@ class CParser: token =3D ("name", "virloginit") return token =20 + elif token[0] =3D=3D "name" and token[1] =3D=3D "G_STATIC_ASSERT": + # skip whole line + while token is not None and token[0] !=3D "sep" or token[1] != =3D ";": + token =3D self.token() + return self.token() + elif token[0] =3D=3D "name": if self.type =3D=3D "": self.type =3D token[1] diff --git a/src/util/virerror.c b/src/util/virerror.c index fd2f77329f..aac6ee3597 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -910,7 +910,7 @@ typedef struct { } virErrorMsgTuple; =20 =20 -const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NUMBER_LAST] =3D { +static const virErrorMsgTuple virErrorMsgStrings[] =3D { [VIR_ERR_OK] =3D { NULL, NULL }, [VIR_ERR_INTERNAL_ERROR] =3D { N_("internal error"), @@ -1235,6 +1235,8 @@ const virErrorMsgTuple virErrorMsgStrings[VIR_ERR_NUM= BER_LAST] =3D { N_("network port not found: %s") }, }; =20 +G_STATIC_ASSERT(G_N_ELEMENTS(virErrorMsgStrings) =3D=3D VIR_ERR_NUMBER_LAS= T); + =20 /** * virErrorMsg: --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 02:49:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1578573983; cv=none; d=zohomail.com; s=zohoarc; b=PSysXHeosWDWb8I0//o0P5cBHxGEh9vvWyzp1Lksv7uuRPErwXd2qYjZWT+D7DaCvY2xHLcYAIWF+eoFUgORdpXV4wBGS+reeIFFLwvT1VyuybJmGMPz7pcJvjP/iAzesKtLngJndyRd3xGnBSFGcE4lSNJ/feWe4MRwchPK6tk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578573983; 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=laF13MMafw1ahsDNPLl5DKc9FlhQP7b/UZBHBpCeFGY=; b=L3+8+b9uPdk5s7dnFNBoPipRKoL+jYwJuQO4+irXJsWwJvqa3M97mb7AaJTG6BVL9G7xQv2hWkoV9rZ/pqK5QWQTbk0b9bmR6orqfqAUh7sKhflmMOQ3vX8PGPtuTdB6Vo2JSRAv99uP/P8AOQPjKsJZegy68HD7Vu0Ycaq3f+Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1578573983424448.2811223551106; Thu, 9 Jan 2020 04:46:23 -0800 (PST) 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-66-zpwlI-XdNSSAtaPW_5QShw-1; Thu, 09 Jan 2020 07:46:19 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D1F81005513; Thu, 9 Jan 2020 12:46:13 +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 9EE6C7FB5C; Thu, 9 Jan 2020 12:46:12 +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 DD815503BE; Thu, 9 Jan 2020 12:46:11 +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 009Ck9us030823 for ; Thu, 9 Jan 2020 07:46:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4357786C5C; Thu, 9 Jan 2020 12:46:09 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99DCD86CBA; Thu, 9 Jan 2020 12:46:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578573980; 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=laF13MMafw1ahsDNPLl5DKc9FlhQP7b/UZBHBpCeFGY=; b=DRRN3ah8oFCL5CoAITnhUGOc41isk1LcX2HKYUIlQurGk5Qznjwwlog4nuENxM5PBxn4M+ fzT+/iSCAD7+tNRwme1qXtkCxF0WUbJrCATSsDgqa+UNPIBljg4UgnnQ/p8TdSZGJZ6q57 VqhZJZSUILDhyYdI/wWMmko+NCkDGVg= From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 9 Jan 2020 13:45:57 +0100 Message-Id: <41c0cfde24da010b1b563affc3442c830a31909d.1578573671.git.mprivozn@redhat.com> 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 Cc: jcfaracco@gmail.com Subject: [libvirt] [PATCH v4 2/5] Introduce source flags to virDomainGetHostname() 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.11 X-MC-Unique: zpwlI-XdNSSAtaPW_5QShw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Julio Faracco There is a lots of possibilities to retrieve hostname information from domain. Libvirt could use lease information from dnsmasq to get current hostname too. QEMU supports QEMU-agent but it can use lease source. Signed-off-by: Michal Privoznik Signed-off-by: Julio Faracco Reviewed-by: Erik Skultety --- include/libvirt/libvirt-domain.h | 6 ++++++ include/libvirt/virterror.h | 1 + src/libvirt-domain.c | 9 +++++---- src/remote/remote_daemon.c | 1 + src/util/virerror.c | 3 +++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index c1b9a9d1d0..44f6b62913 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1567,6 +1567,12 @@ int virDomainSetMemoryStatsPerio= d (virDomainPtr domain, int virDomainGetMaxVcpus (virDomainPtr domain); int virDomainGetSecurityLabel (virDomainPtr domain, virSecurityLabelPtr sec= label); + +typedef enum { + VIR_DOMAIN_GET_HOSTNAME_LEASE =3D (1 << 0), /* Parse DHCP lease file */ + VIR_DOMAIN_GET_HOSTNAME_AGENT =3D (1 << 1), /* Query qemu guest agent = */ +} virDomainGetHostnameFlags; + char * virDomainGetHostname (virDomainPtr domain, unsigned int flags); int virDomainGetSecurityLabelList (virDomainPtr domain, diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 54f4f8190d..b7aa2a0ec3 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -332,6 +332,7 @@ typedef enum { VIR_ERR_INVALID_NETWORK_PORT =3D 105, /* invalid network port object */ VIR_ERR_NETWORK_PORT_EXIST =3D 106, /* the network port already exis= t */ VIR_ERR_NO_NETWORK_PORT =3D 107, /* network port not found */ + VIR_ERR_NO_HOSTNAME =3D 108, /* no domain's hostname found */ =20 # ifdef VIR_ENUM_SENTINELS VIR_ERR_NUMBER_LAST diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index eb66999f07..d0304e174f 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11025,12 +11025,13 @@ virDomainGetDiskErrors(virDomainPtr dom, /** * virDomainGetHostname: * @domain: a domain object - * @flags: extra flags; not used yet, so callers should always pass 0 + * @flags: bitwise-OR of virDomainGetHostnameFlags * - * Get the hostname for that domain. + * Get the hostname for that domain. If no hostname is found, + * then an error is raised with VIR_ERR_NO_HOSTNAME code. * - * Dependent on hypervisor used, this may require a guest agent to be - * available. + * Dependent on hypervisor and @flags used, this may require a + * guest agent to be available. * * Returns the hostname which must be freed by the caller, or * NULL if there was an error. diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index cd55b2c39e..1c224f8050 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -296,6 +296,7 @@ static int daemonErrorLogFilter(virErrorPtr err, int pr= iority) case VIR_ERR_NO_DOMAIN_METADATA: case VIR_ERR_NO_SERVER: case VIR_ERR_NO_CLIENT: + case VIR_ERR_NO_HOSTNAME: return VIR_LOG_DEBUG; } =20 diff --git a/src/util/virerror.c b/src/util/virerror.c index aac6ee3597..0f3ee1faaa 100644 --- a/src/util/virerror.c +++ b/src/util/virerror.c @@ -1233,6 +1233,9 @@ static const virErrorMsgTuple virErrorMsgStrings[] = =3D { [VIR_ERR_NO_NETWORK_PORT] =3D { N_("network port not found"), N_("network port not found: %s") }, + [VIR_ERR_NO_HOSTNAME] =3D { + N_("no hostname found"), + N_("no hostname found: %s") }, }; =20 G_STATIC_ASSERT(G_N_ELEMENTS(virErrorMsgStrings) =3D=3D VIR_ERR_NUMBER_LAS= T); --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 02:49:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1578573991; cv=none; d=zohomail.com; s=zohoarc; b=Zws7tTQmudlHh+90Ji2ipwBhWEGpERd39ZUqxbYHfh1psryDobzBlp8T42HobZb9xyU/ylePco4yJwuu3etQ1DDc0vkR88Yk+VvehwaKIMyBuAjK1eyBhJAPlGUFw0dMEZkqyd07HNxuDARHl4ixXpTBIZEMgui8TkONOA5e1Ik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578573991; 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=vitvpb4ZYsedoeqj0xRdX+GlCHdTSnh0tORFvEtEDHc=; b=nNjP7yfIfRqsnVtsRCl2ndm4DxsEepUklN4oGzyIkt8ilHl7rpCKCwsBOrzu0M7fxVl6bdYsRuxANrjNzjhwAquI52OU6AdN6le/Alrj6sOSMj/XgUQQPPywapslKPW9nWLNtHDoXc5YxCTui2g+iaZj33w76aZSM/5yUsN9Dds= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 157857399144164.72691120697414; Thu, 9 Jan 2020 04:46:31 -0800 (PST) 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-34-l8IS5IOtNW-Vhy_HMpckdA-1; Thu, 09 Jan 2020 07:46:28 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EBBC6801E6C; Thu, 9 Jan 2020 12:46:22 +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 C448C80618; Thu, 9 Jan 2020 12:46:22 +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 741BA18089CF; Thu, 9 Jan 2020 12:46:22 +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 009CkAnm030837 for ; Thu, 9 Jan 2020 07:46:10 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3BAED86CA4; Thu, 9 Jan 2020 12:46:10 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90DE986C5C; Thu, 9 Jan 2020 12:46:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578573990; 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=vitvpb4ZYsedoeqj0xRdX+GlCHdTSnh0tORFvEtEDHc=; b=Zxra3oo/1SHjKtogaaihHTvPU3pvlEWVEnsZPr7M8uKEoCcpcUDNMUBDwKD1R9+dz4Bnj8 Kpd+46sWFuhZ25YWZI8Ri4ets9ZmR3+2fBvzVBEtgSOkIHSKGoNou6ZAzKGX+P7U1Rbzhf kSRX4/e4bzHbSV4Kz9TwpeEOObENsWM= From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 9 Jan 2020 13:45:58 +0100 Message-Id: <8c08f92ce126ad866b965d766e8555ed293b07f9.1578573671.git.mprivozn@redhat.com> 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 Cc: jcfaracco@gmail.com Subject: [libvirt] [PATCH v4 3/5] qemu: Implement virDomainGetHostnameFlags 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.11 X-MC-Unique: l8IS5IOtNW-Vhy_HMpckdA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Julio Faracco We have to keep the default - querying the agent if no flag is set. Signed-off-by: Michal Privoznik Signed-off-by: Julio Faracco Reviewed-by: Erik Skultety --- src/qemu/qemu_driver.c | 125 +++++++++++++++++++++++++++++++++++------ 1 file changed, 109 insertions(+), 16 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1fc662b3c8..6b33342be8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20257,25 +20257,16 @@ qemuConnectGetCPUModelNames(virConnectPtr conn, } =20 =20 -static char * -qemuDomainGetHostname(virDomainPtr dom, - unsigned int flags) +static int +qemuDomainGetHostnameAgent(virQEMUDriverPtr driver, + virDomainObjPtr vm, + char **hostname) { - virQEMUDriverPtr driver =3D dom->conn->privateData; - virDomainObjPtr vm =3D NULL; qemuAgentPtr agent; - char *hostname =3D NULL; - - virCheckFlags(0, NULL); - - if (!(vm =3D qemuDomainObjFromDomain(dom))) - return NULL; - - if (virDomainGetHostnameEnsureACL(dom->conn, vm->def) < 0) - goto cleanup; + int ret =3D -1; =20 if (qemuDomainObjBeginAgentJob(driver, vm, QEMU_AGENT_JOB_QUERY) < 0) - goto cleanup; + return -1; =20 if (virDomainObjCheckActive(vm) < 0) goto endjob; @@ -20284,11 +20275,113 @@ qemuDomainGetHostname(virDomainPtr dom, goto endjob; =20 agent =3D qemuDomainObjEnterAgent(vm); - ignore_value(qemuAgentGetHostname(agent, &hostname)); + ignore_value(qemuAgentGetHostname(agent, hostname)); qemuDomainObjExitAgent(vm, agent); =20 + ret =3D 0; endjob: qemuDomainObjEndAgentJob(vm); + return ret; +} + + +static int +qemuDomainGetHostnameLease(virQEMUDriverPtr driver, + virDomainObjPtr vm, + char **hostname) +{ + char macaddr[VIR_MAC_STRING_BUFLEN]; + g_autoptr(virConnect) conn =3D NULL; + virNetworkDHCPLeasePtr *leases =3D NULL; + int n_leases; + size_t i, j; + int ret =3D -1; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0) + return -1; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (!(conn =3D virGetConnectNetwork())) + goto endjob; + + for (i =3D 0; i < vm->def->nnets; i++) { + g_autoptr(virNetwork) network =3D NULL; + virDomainNetDefPtr net =3D vm->def->nets[i]; + + if (net->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) + continue; + + virMacAddrFormat(&net->mac, macaddr); + network =3D virNetworkLookupByName(conn, net->data.network.name); + + if (!network) + goto endjob; + + if ((n_leases =3D virNetworkGetDHCPLeases(network, macaddr, + &leases, 0)) < 0) + goto endjob; + + for (j =3D 0; j < n_leases; j++) { + virNetworkDHCPLeasePtr lease =3D leases[j]; + if (lease->hostname && !*hostname) + *hostname =3D g_strdup(lease->hostname); + + virNetworkDHCPLeaseFree(lease); + } + + VIR_FREE(leases); + + if (*hostname) + goto endjob; + } + + ret =3D 0; + endjob: + qemuDomainObjEndJob(driver, vm); + return ret; +} + + +static char * +qemuDomainGetHostname(virDomainPtr dom, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D dom->conn->privateData; + virDomainObjPtr vm =3D NULL; + char *hostname =3D NULL; + + virCheckFlags(VIR_DOMAIN_GET_HOSTNAME_LEASE | + VIR_DOMAIN_GET_HOSTNAME_AGENT, NULL); + + VIR_EXCLUSIVE_FLAGS_RET(VIR_DOMAIN_GET_HOSTNAME_LEASE, + VIR_DOMAIN_GET_HOSTNAME_AGENT, + NULL); + + if (!(flags & VIR_DOMAIN_GET_HOSTNAME_LEASE)) + flags |=3D VIR_DOMAIN_GET_HOSTNAME_AGENT; + + if (!(vm =3D qemuDomainObjFromDomain(dom))) + return NULL; + + if (virDomainGetHostnameEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (flags & VIR_DOMAIN_GET_HOSTNAME_AGENT) { + if (qemuDomainGetHostnameAgent(driver, vm, &hostname) < 0) + goto cleanup; + } else if (flags & VIR_DOMAIN_GET_HOSTNAME_LEASE) { + if (qemuDomainGetHostnameLease(driver, vm, &hostname) < 0) + goto cleanup; + } + + if (!hostname) { + virReportError(VIR_ERR_NO_HOSTNAME, + _("no hostname found for domain %s"), + vm->def->name); + goto cleanup; + } =20 cleanup: virDomainObjEndAPI(&vm); --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 02:49:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1578573998; cv=none; d=zohomail.com; s=zohoarc; b=DiT51zGUCP82WnjECQ3gJxFpqcVbLIsRe8D8BSQZxu11gh1XjFiFH8na63RC9zOyzakn4zoltMDaKj0tuaPn1PNhooPChaRByCZxD3h3fn0l7UorBxVduEQ89mZve07YvMlMkYjy2lUyft2r9RfVS3I27dy8zKHFPnFdDrR/Haw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578573998; 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=ANMf2UVEsgvkI2hmUEqYQtJzjmhpzYgG48xE7JgZInY=; b=TFQDEmnGRF79twlYuDtQlDfrpKcSmL3ORDpNkZrSlGUSyOiEKbXVDzMfuNCl8XxsYaxR39kfBvRTF8FTQBi07SObiuVzjV9s2Z3K78cwyfhqX08TMjNn34cHySIxeKw/0/X+nb8N6yA7v1L5UiLizNHAGG+r4j5lyHe6wIKRdBE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1578573998981978.8758518062461; Thu, 9 Jan 2020 04:46:38 -0800 (PST) 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-420-zMQPNNwzOfmROaVHfZsHMA-1; Thu, 09 Jan 2020 07:46:35 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6BED5800D54; Thu, 9 Jan 2020 12:46:30 +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 43EC28061C; Thu, 9 Jan 2020 12:46:30 +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 021AD18089D0; Thu, 9 Jan 2020 12:46:30 +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 009CkBOD030842 for ; Thu, 9 Jan 2020 07:46:11 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3492486CB5; Thu, 9 Jan 2020 12:46:11 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A51486CB4; Thu, 9 Jan 2020 12:46:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578573997; 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=ANMf2UVEsgvkI2hmUEqYQtJzjmhpzYgG48xE7JgZInY=; b=YKn7IPV1Fq3TtJF6YqOIkIHkPqsaqnwoFBNGg4Jn4idOcmf8WrEeHDY5a0Hjfe7jnod7P2 XOFh9VNYjKTLPiaKB7Ivwfv4cskYLCZ83fYHdtCa4FlNlbGyVhKrBfcbJzwjdfVch8OTXM gbsvGaZAYt0sQTj8B9ya/BrWqdWHcAo= From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 9 Jan 2020 13:45:59 +0100 Message-Id: <073b70f6d49d9303c4671b43d9b68c538d118444.1578573671.git.mprivozn@redhat.com> 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 Cc: jcfaracco@gmail.com Subject: [libvirt] [PATCH v4 4/5] lxc: Implement virDomainGetHostnameFlags 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.11 X-MC-Unique: zMQPNNwzOfmROaVHfZsHMA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Julio Faracco Since there is no guest agent in LXC world (yet), we can implement _LEASE flag only. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/lxc/lxc_driver.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 780c6ed4a2..bf1f8f8190 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5291,6 +5291,84 @@ lxcDomainGetCPUStats(virDomainPtr dom, } =20 =20 +static char * +lxcDomainGetHostname(virDomainPtr dom, + unsigned int flags) +{ + virLXCDriverPtr driver =3D dom->conn->privateData; + virDomainObjPtr vm =3D NULL; + char macaddr[VIR_MAC_STRING_BUFLEN]; + g_autoptr(virConnect) conn =3D NULL; + virNetworkDHCPLeasePtr *leases =3D NULL; + int n_leases; + size_t i, j; + char *hostname =3D NULL; + + virCheckFlags(VIR_DOMAIN_GET_HOSTNAME_LEASE, NULL); + + if (!(vm =3D lxcDomObjFromDomain(dom))) + return NULL; + + if (virDomainGetHostnameEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_QUERY) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (!(conn =3D virGetConnectNetwork())) + goto endjob; + + for (i =3D 0; i < vm->def->nnets; i++) { + g_autoptr(virNetwork) network =3D NULL; + virDomainNetDefPtr net =3D vm->def->nets[i]; + + if (net->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) + continue; + + virMacAddrFormat(&net->mac, macaddr); + network =3D virNetworkLookupByName(conn, net->data.network.name); + + if (!network) + goto endjob; + + if ((n_leases =3D virNetworkGetDHCPLeases(network, macaddr, + &leases, 0)) < 0) + goto endjob; + + for (j =3D 0; j < n_leases; j++) { + virNetworkDHCPLeasePtr lease =3D leases[j]; + + if (lease->hostname && !hostname) + hostname =3D g_strdup(lease->hostname); + + virNetworkDHCPLeaseFree(lease); + } + + VIR_FREE(leases); + + if (hostname) + goto endjob; + } + + if (!hostname) { + virReportError(VIR_ERR_NO_HOSTNAME, + _("no hostname found for domain %s"), + vm->def->name); + goto endjob; + } + + endjob: + virLXCDomainObjEndJob(driver, vm); + + cleanup: + virDomainObjEndAPI(&vm); + return hostname; +} + + static int lxcNodeGetFreePages(virConnectPtr conn, unsigned int npages, @@ -5436,6 +5514,7 @@ static virHypervisorDriver lxcHypervisorDriver =3D { .domainSetMetadata =3D lxcDomainSetMetadata, /* 1.1.3 */ .domainGetMetadata =3D lxcDomainGetMetadata, /* 1.1.3 */ .domainGetCPUStats =3D lxcDomainGetCPUStats, /* 1.2.2 */ + .domainGetHostname =3D lxcDomainGetHostname, /* 6.0.0 */ .nodeGetMemoryParameters =3D lxcNodeGetMemoryParameters, /* 0.10.2 */ .nodeSetMemoryParameters =3D lxcNodeSetMemoryParameters, /* 0.10.2 */ .domainSendProcessSignal =3D lxcDomainSendProcessSignal, /* 1.0.1 */ --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 20 02:49:19 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1578573991; cv=none; d=zohomail.com; s=zohoarc; b=bwEFYbN8MWYC8YtCnne/Teb/XAFOtumaFW7knd+w8621HwWjFM+1HCHjbwX/OTZcgNL+/BA5MCU4QSsNd/aNkze0Q5YpnpwCZ3k+RyNXi/BKXLqiyQ/dKRh9CkuspYjTJjwY3joS24ihszcj3n4qOB5bSMOTVTfQ16RAWGwVUXc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1578573991; 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=yD5Rqld9IvU6MGJwJiCTjQqMLHKKEm5+XlsBTXuC/m8=; b=cCFvu3aBsjuoCSZSXPplb+TwYkO4oMb2kpswoI7mJXXJ9h8jcJv34zGrIU0CKTykAcml78YcPI6nUEGa1jDHrQMIcpJmv+AbR0Ae6w7YIZo+KHmAnbs6v7DGL1kaNqDoKspg1HiZZEzD030yYDDFSGg+DbA43/V61dThTmLbIdQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1578573991054770.263103068392; Thu, 9 Jan 2020 04:46:31 -0800 (PST) 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-351-xPmMreWaOi-A0uNM9Hp1ig-1; Thu, 09 Jan 2020 07:46:28 -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 E420618C35A2; Thu, 9 Jan 2020 12:46:22 +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 BBA045DA32; Thu, 9 Jan 2020 12:46:22 +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 708D218089CE; Thu, 9 Jan 2020 12:46:22 +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 009CkCRI030855 for ; Thu, 9 Jan 2020 07:46:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 85B4786CB5; Thu, 9 Jan 2020 12:46:12 +0000 (UTC) Received: from moe.redhat.com (unknown [10.43.2.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB49B86CB4; Thu, 9 Jan 2020 12:46:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578573989; 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=yD5Rqld9IvU6MGJwJiCTjQqMLHKKEm5+XlsBTXuC/m8=; b=Wczg1IUShAFiYcXNdIClU+if8uoc29Hf926oTohB9mJS0354OvfY/xJ5fWhamX1RWXGfxT 538VabQEWi8zreWozuIz4SGCffyicw/UcQ+kxTtmtQzj+QhqK2wiLrUzKUG3Nmy1FiAEgl vf+hz/YwVnhMszcVvEpoSwwL1sHgZHY= From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 9 Jan 2020 13:46:00 +0100 Message-Id: <7e86189c29d6047af8b4e9317adb89bbf2048c15.1578573671.git.mprivozn@redhat.com> 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 Cc: jcfaracco@gmail.com Subject: [libvirt] [PATCH v4 5/5] virsh: Expose virDomainGetHostnameFlags 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 X-MC-Unique: xPmMreWaOi-A0uNM9Hp1ig-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Julio Faracco Our virsh already has 'domhostname' command. Add '--source' argument to it so that users can chose between 'lease' and 'agent' sources. Also, implement completer for the argument. Signed-off-by: Julio Faracco Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- docs/manpages/virsh.rst | 7 ++++++- tools/virsh-completer-domain.c | 19 +++++++++++++++++ tools/virsh-completer-domain.h | 4 ++++ tools/virsh-domain.c | 37 +++++++++++++++++++++++++++++++++- tools/virsh-domain.h | 8 ++++++++ 5 files changed, 73 insertions(+), 2 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 4522259657..95a20aef9c 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1797,10 +1797,15 @@ domhostname =20 .. code-block:: =20 - domhostname domain + domhostname domain [--source lease|agent] =20 Returns the hostname of a domain, if the hypervisor makes it available. =20 +The *--source* argument specifies what data source to use for the +hostnames, currently 'lease' to read DHCP leases or 'agent' to query +the guest OS via an agent. If unspecified, driver returns the default +method available (some drivers support only one type of source). + =20 domid ----- diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c index 6da603048e..4472ee08f2 100644 --- a/tools/virsh-completer-domain.c +++ b/tools/virsh-completer-domain.c @@ -316,3 +316,22 @@ virshDomainInterfaceAddrSourceCompleter(vshControl *ct= l G_GNUC_UNUSED, =20 return ret; } + + +char ** +virshDomainHostnameSourceCompleter(vshControl *ctl G_GNUC_UNUSED, + const vshCmd *cmd G_GNUC_UNUSED, + unsigned int flags) +{ + char **ret =3D NULL; + size_t i; + + virCheckFlags(0, NULL); + + ret =3D g_new0(typeof(*ret), VIRSH_DOMAIN_HOSTNAME_SOURCE_LAST + 1); + + for (i =3D 0; i < VIRSH_DOMAIN_HOSTNAME_SOURCE_LAST; i++) + ret[i] =3D g_strdup(virshDomainHostnameSourceTypeToString(i)); + + return ret; +} diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h index 79beec2cfe..b00b05e3bd 100644 --- a/tools/virsh-completer-domain.h +++ b/tools/virsh-completer-domain.h @@ -58,3 +58,7 @@ char ** virshDomainInterfaceAddrSourceCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); + +char ** virshDomainHostnameSourceCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 9315755990..0b6a9f2fbd 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11741,20 +11741,55 @@ static const vshCmdInfo info_domhostname[] =3D { =20 static const vshCmdOptDef opts_domhostname[] =3D { VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), + {.name =3D "source", + .type =3D VSH_OT_STRING, + .flags =3D VSH_OFLAG_NONE, + .completer =3D virshDomainHostnameSourceCompleter, + .help =3D N_("address source: 'lease' or 'agent'")}, {.name =3D NULL} }; =20 +VIR_ENUM_IMPL(virshDomainHostnameSource, + VIRSH_DOMAIN_HOSTNAME_SOURCE_LAST, + "agent", + "lease"); + static bool cmdDomHostname(vshControl *ctl, const vshCmd *cmd) { char *hostname; virDomainPtr dom; bool ret =3D false; + const char *sourcestr =3D NULL; + int flags =3D 0; /* Use default value. Drivers can have its own defaul= t. */ =20 if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) return false; =20 - hostname =3D virDomainGetHostname(dom, 0); + if (vshCommandOptStringReq(ctl, cmd, "source", &sourcestr) < 0) + goto error; + + if (sourcestr) { + int source =3D virshDomainHostnameSourceTypeFromString(sourcestr); + + if (source < 0) { + vshError(ctl, _("Unknown data source '%s'"), sourcestr); + goto error; + } + + switch ((virshDomainHostnameSource) source) { + case VIRSH_DOMAIN_HOSTNAME_SOURCE_AGENT: + flags |=3D VIR_DOMAIN_GET_HOSTNAME_AGENT; + break; + case VIRSH_DOMAIN_HOSTNAME_SOURCE_LEASE: + flags |=3D VIR_DOMAIN_GET_HOSTNAME_LEASE; + break; + case VIRSH_DOMAIN_HOSTNAME_SOURCE_LAST: + break; + } + } + + hostname =3D virDomainGetHostname(dom, flags); if (hostname =3D=3D NULL) { vshError(ctl, "%s", _("failed to get hostname")); goto error; diff --git a/tools/virsh-domain.h b/tools/virsh-domain.h index 02996d51b1..0d59c579d4 100644 --- a/tools/virsh-domain.h +++ b/tools/virsh-domain.h @@ -30,4 +30,12 @@ typedef struct virshDomainEventCallback virshDomainEvent= Callback; =20 extern virshDomainEventCallback virshDomainEventCallbacks[]; =20 +typedef enum { + VIRSH_DOMAIN_HOSTNAME_SOURCE_AGENT, + VIRSH_DOMAIN_HOSTNAME_SOURCE_LEASE, + VIRSH_DOMAIN_HOSTNAME_SOURCE_LAST +} virshDomainHostnameSource; + +VIR_ENUM_DECL(virshDomainHostnameSource); + extern const vshCmdDef domManagementCmds[]; --=20 2.24.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list