From nobody Fri Apr 26 01:13:48 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=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1574626882; cv=none; d=zohomail.com; s=zohoarc; b=Qg1yWf0/nSljirvqb1/MlTjukYjBBPZ23gNI1fit5Y2lsoIQwTmfYm/fUXVSe0cEfyVUnathe/fzOAvc43bCJQRCdMrMFfIZEo4FfwXKa28ToxkimDpqF36U+yFYnzj9OFxHDq6OHskHM2qiOzFp/jLL5QKj3xz/sVzxszGwbvM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574626882; 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=hzqY4NbPIhzBLvFwy8aUMzkqza+bi0amdzaObs3J7LM=; b=EOU6kwzX66LA37YHDBNvbWMi9ONxbIp0LwDj5wvE8lB5l1f6iXTArKGjVjFQeSuF4TPXdad4uxzwo1+q+H7QjEEW31MrK3fI08arD4fdRwfr/VVnuP1cV0FvtwnwEL6oV1laO3F4lyK4720xn860MH/e11aHsFzBm9+NabZ5xD4= 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=fail 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 1574626882902836.6320140272223; Sun, 24 Nov 2019 12:21:22 -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-203-ljLhUlQ2Mum0FFHhbYL_Ew-1; Sun, 24 Nov 2019 15:21:15 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3A758800EBA; Sun, 24 Nov 2019 20:21:10 +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 DB6C85C1C3; Sun, 24 Nov 2019 20:21:09 +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 78B2F4E562; Sun, 24 Nov 2019 20:21:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAOKL84S021491 for ; Sun, 24 Nov 2019 15:21:08 -0500 Received: by smtp.corp.redhat.com (Postfix) id 678F210100CD; Sun, 24 Nov 2019 20:21:08 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EB191013EFA for ; Sun, 24 Nov 2019 20:21:06 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3A2F49018F0 for ; Sun, 24 Nov 2019 20:21:06 +0000 (UTC) Received: from mail-qv1-f67.google.com (mail-qv1-f67.google.com [209.85.219.67]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-421-auK2xcZANDy3hrZZvKG3Ng-1; Sun, 24 Nov 2019 15:21:04 -0500 Received: by mail-qv1-f67.google.com with SMTP id s18so4897464qvr.4 for ; Sun, 24 Nov 2019 12:21:04 -0800 (PST) Received: from localhost.localdomain (201-27-172-196.dsl.telesp.net.br. [201.27.172.196]) by smtp.gmail.com with ESMTPSA id s21sm2705423qtc.12.2019.11.24.12.21.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Nov 2019 12:21:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574626881; 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=hzqY4NbPIhzBLvFwy8aUMzkqza+bi0amdzaObs3J7LM=; b=YGraLb6EM2AVGzfQQBvFbR7MMlrptGWUrvvknFSIHJpYjyAGQPFRPYnvoY1z8HweJ/ZSuo Gqo6wEt+sCo53M2khau2A/tgRzjv1x1p/qsTWk9GPIKFZ+AoEiTZPu5GvSCle9HZ6p7VHK 1sVq7OnZbbFpuUDOEVw+Rx54hmQMnkc= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=bmPXHC5mPUiTKGtkBjH5qfrW7zr6ZgzRLoDWphEpb+Y=; b=MVl+xCPIlfr+4yoh9twA0j/7/gpfz6FXsA1HWtideDoUtdOyrSW4KRthiijUTRK8/R ve8RDRTCKTLhGR7phKaHhW0yiqjpNEZtBKchSHmn9HH1Go1JTugSx7jKB6AzcA6deTNy vQtLHa8H6wZ8iYhyIb7M1lijFEy2DSWD7Eb5e/od20zcWVWFFqssqtLVFzMguxQoofrg vZdnrt9siJOnWHzpE30bp5Vq7fbAEXbhRh81IXM3rMK1NIn9t3ZkR0lmLSPjVzrwjiUC qnw64d5Iwv2PBsFP8uWLdQDjy7DGPxFETLneuRBt8+VBUwLtEP58j1/Rsl0uCVCfs4gr fPPw== X-Gm-Message-State: APjAAAWB7xbxvaStTYY1NaCtgV3F4Iu/j+//Rk/Lm5x77whlfGsRbEn+ Px4mDXm5w8XwwwiL1HbdZyu+cqCz X-Google-Smtp-Source: APXvYqxy+dcOf4QhoyEtqdmkf2FMLsKmepdQxCswmr/EoBOczyrOYl4MluguuPw3FBs79qlRwS6shg== X-Received: by 2002:a0c:ed2e:: with SMTP id u14mr24459947qvq.119.1574626863122; Sun, 24 Nov 2019 12:21:03 -0800 (PST) From: jcfaracco@gmail.com To: libvir-list@redhat.com Date: Sun, 24 Nov 2019 17:19:49 -0300 Message-Id: <20191124201949.6816-3-jcfaracco@gmail.com> In-Reply-To: <20191124201949.6816-1-jcfaracco@gmail.com> References: <20191124201949.6816-1-jcfaracco@gmail.com> MIME-Version: 1.0 X-MC-Unique: auK2xcZANDy3hrZZvKG3Ng-1 X-MC-Unique: ljLhUlQ2Mum0FFHhbYL_Ew-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xAOKL84S021491 X-loop: libvir-list@redhat.com Cc: Julio Faracco Subject: [libvirt] [PATCH 2/2] lxc: Introduce lxcDomainGetHostname 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.16 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 Using lease information from dnsmasq, libvirt can retrieve hostname information. LXC documentation says that hostname can be 'lxc.uts.name', but if an user runs 'hostnamectl' and change hostname during container execution, it will reflect the command output. This option could fix this. Signed-off-by: Julio Faracco --- src/lxc/lxc_driver.c | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index ea86451b09..999e74fcc8 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5317,6 +5317,76 @@ lxcDomainGetCPUStats(virDomainPtr dom, return ret; } =20 +static char * +lxcDomainGetHostname(virDomainPtr dom, + unsigned int source, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + char macaddr[VIR_MAC_STRING_BUFLEN]; + g_autoptr(virNetwork) network =3D NULL; + virNetworkDHCPLeasePtr *leases =3D NULL; + int n_leases; + size_t i, j; + char *hostname =3D NULL; + + virCheckFlags(0, NULL); + + if (!(vm =3D lxcDomObjFromDomain(dom))) + return NULL; + + if (virDomainGetHostnameEnsureACL(dom->conn, vm->def) < 0) + goto cleanup; + + switch (source) { + default: + case VIR_DOMAIN_HOSTNAME_SRC_LEASE: + for (i =3D 0; i < vm->def->nnets; i++) { + if (vm->def->nets[i]->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) + continue; + + virMacAddrFormat(&(vm->def->nets[i]->mac), macaddr); + virObjectUnref(network); + network =3D virNetworkLookupByName(dom->conn, + vm->def->nets[i]->data.networ= k.name); + + if ((n_leases =3D virNetworkGetDHCPLeases(network, macaddr, + &leases, 0)) < 0) + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("There is no available hostname %d"), + source); + + for (j =3D 0; j < n_leases; j++) { + virNetworkDHCPLeasePtr lease =3D leases[j]; + if (lease->hostname) { + hostname =3D g_strdup(lease->hostname); + + for (j =3D 0; j < n_leases; j++) + virNetworkDHCPLeaseFree(leases[j]); + + VIR_FREE(leases); + + goto cleanup; + } + } + + for (j =3D 0; j < n_leases; j++) + virNetworkDHCPLeaseFree(leases[j]); + + VIR_FREE(leases); + } + break; + case VIR_DOMAIN_HOSTNAME_SRC_AGENT: + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, + _("Unknown hostname data source %d"), + source); + break; + } + + cleanup: + virDomainObjEndAPI(&vm); + return hostname; +} =20 static int lxcNodeGetFreePages(virConnectPtr conn, @@ -5463,6 +5533,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, /* 5.9.0 */ .nodeGetMemoryParameters =3D lxcNodeGetMemoryParameters, /* 0.10.2 */ .nodeSetMemoryParameters =3D lxcNodeSetMemoryParameters, /* 0.10.2 */ .domainSendProcessSignal =3D lxcDomainSendProcessSignal, /* 1.0.1 */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list