From nobody Mon Feb 9 19:53:55 2026 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