From nobody Wed Apr 24 12:21:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; 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 207.211.31.81 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=1574626877; cv=none; d=zohomail.com; s=zohoarc; b=eRsRUWxuBicuqLQk68V9J9951m/Hty1JpZ7vSzu3VtCTaYXIrnXl/+8TC930miCPl4DZtzbjZT/4TEw3ZMY/clLDsEcRSAALSB0y2KFzPUE5z+ZfE4uxiCs6gE1x3qEMBYpAnN5Q9VOYxwf9/5phFEM3lOeqxYkw9frgutWilh4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1574626877; 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=5ByvD5P7p137EekOJ0p/pVPAU26IujNmCM8AgyeIt6s=; b=H+StCuWZ+dgJaa158K1AFX5ekd8rH8U0f6Z/I59D7E1ArZKKScY3L7OHFbvvhC3X+PJo3Ip78/IX+qQ/XawP6Ri4j3fLT2irT2KkJokskCwYKWgvNKBsLQyDmv4op/jMnvlxZ6AjQnHgIgo705P9vpCJHSXmluudNstoC+qf25k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 157462687771658.22732301186227; Sun, 24 Nov 2019 12:21:17 -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-169-tiHbgAmKPDm5DpoDJToaDA-1; Sun, 24 Nov 2019 15:21:14 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 963132F2A; Sun, 24 Nov 2019 20:21:08 +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 4904E60C63; Sun, 24 Nov 2019 20:21:08 +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 7B87118089CD; Sun, 24 Nov 2019 20:21:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAOKL5I8021473 for ; Sun, 24 Nov 2019 15:21:05 -0500 Received: by smtp.corp.redhat.com (Postfix) id E8228F4995; Sun, 24 Nov 2019 20:21:04 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast04.extmail.prod.ext.rdu2.redhat.com [10.11.55.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E39CCF498C for ; Sun, 24 Nov 2019 20:21:04 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) (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 BE78E1015630 for ; Sun, 24 Nov 2019 20:21:04 +0000 (UTC) Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397-SsjDpwX8OvquR1Lf9jOEaA-1; Sun, 24 Nov 2019 15:21:02 -0500 Received: by mail-qt1-f193.google.com with SMTP id y39so14813914qty.0 for ; Sun, 24 Nov 2019 12:21:02 -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.20.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Nov 2019 12:21:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574626876; 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=5ByvD5P7p137EekOJ0p/pVPAU26IujNmCM8AgyeIt6s=; b=VT63YgoatsmkMCn9IxrLFaPyENBmo/Ia0Z38+skgsiSmWj1A2gdfUNEux5jtRmklstbdCJ jbFHcB7nmaJ7Lkb0f+Y4Gsu2o7ncjGj2czrr7sKOc41eVexidD/VlWL3ImMH5egGRd0wkr o3V5efogtbT6Nn85aXRldbXB+06LY6o= 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=wsf+FbIJ1sGjiKtBdJRHjVvBxu6g1fubzeSqpcs/hVQ=; b=sOmdjGeSYqECuXBOwJeQwo+RPmCMs8QhAJuiJQ0tm558DVc4Odbe7GBgCB6pgu1LIz uCxg2FqVtu59QfygMndkyfQ2Lsh7weFAxdwO5rD9XiPlIP58GYiX5Y1btjNThUUGAYQL xPUoWOLrPWgj7LfxLm/a9z1N9/QcycckXFhX+YT7k2wOZnIh1/Jjwg/pzLk9wLWeAZ1a JpExBUkwpvBY6Pat2whalnzl/1GrUFaNJyOhXE/5pCSPzX0Qe2MYJDkuKDdGhCz3QNj/ Wfx7b7VvGkH0zmytkHIAwoiFqU97yoeQQZnRGfHIJ3PnoKXigwWYisLkF2SQ6y6V6lGn B09w== X-Gm-Message-State: APjAAAWaIBLCCh0RRDsTfMEnCIXPaXz5XViwZxJSPkhqXfuW2Vn8JLTC BES3yfQoPkf7YDag6HnK/WJaxJkg X-Google-Smtp-Source: APXvYqz9Nfk6N+HGHTDCuAvWODOS42feWPxui0IwsManWro88xh1t1p/sdxMm4lkrAvu2Oi4DX8edg== X-Received: by 2002:ac8:60d9:: with SMTP id i25mr8814672qtm.26.1574626861199; Sun, 24 Nov 2019 12:21:01 -0800 (PST) From: jcfaracco@gmail.com To: libvir-list@redhat.com Date: Sun, 24 Nov 2019 17:19:48 -0300 Message-Id: <20191124201949.6816-2-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: SsjDpwX8OvquR1Lf9jOEaA-1 X-MC-Unique: tiHbgAmKPDm5DpoDJToaDA-1 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xAOKL5I8021473 X-loop: libvir-list@redhat.com Cc: Julio Faracco Subject: [libvirt] [PATCH 1/2] driver: Include source parameter 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.12 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. See 'domifaddr' as an example. This commit still adds lease options for QEMU. It will get the first hostname available from domain networks. Signed-off-by: Julio Faracco --- include/libvirt/libvirt-domain.h | 10 +++++ src/driver-hypervisor.h | 1 + src/libvirt-domain.c | 7 +++- src/openvz/openvz_driver.c | 30 +++++++++----- src/qemu/qemu_driver.c | 67 +++++++++++++++++++++++++++----- src/remote/remote_protocol.x | 1 + src/remote_protocol-structs | 1 + src/test/test_driver.c | 1 + tools/virsh-domain.c | 25 +++++++++++- 9 files changed, 120 insertions(+), 23 deletions(-) diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index a2f007568c..cc3d6ed0ca 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1554,6 +1554,7 @@ int virDomainGetMaxVcpus (virD= omainPtr domain); int virDomainGetSecurityLabel (virDomainPtr domain, virSecurityLabelPtr sec= label); char * virDomainGetHostname (virDomainPtr domain, + unsigned int source, unsigned int flags); int virDomainGetSecurityLabelList (virDomainPtr domain, virSecurityLabelPtr= * seclabels); @@ -4790,6 +4791,15 @@ typedef struct _virTypedParameter virMemoryParameter; */ typedef virMemoryParameter *virMemoryParameterPtr; =20 +typedef enum { + VIR_DOMAIN_HOSTNAME_SRC_LEASE =3D 0, /* Parse DHCP lease file */ + VIR_DOMAIN_HOSTNAME_SRC_AGENT =3D 1, /* Query qemu guest agent */ + +# ifdef VIR_ENUM_SENTINELS + VIR_DOMAIN_HOSTNAME_SRC_LAST +# endif +} virDomainHostnameSource; + typedef enum { VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE =3D 0, /* Parse DHCP lease fi= le */ VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT =3D 1, /* Query qemu guest ag= ent */ diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 4afd8f6ec5..6338a3ab73 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -156,6 +156,7 @@ typedef char * =20 typedef char * (*virDrvDomainGetHostname)(virDomainPtr domain, + unsigned int source, unsigned int flags); =20 typedef unsigned long long diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 51fb79cddd..6aa093d8af 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -11017,6 +11017,7 @@ virDomainGetDiskErrors(virDomainPtr dom, /** * virDomainGetHostname: * @domain: a domain object + * @source: one of the virDomainHostnameSource constants * @flags: extra flags; not used yet, so callers should always pass 0 * * Get the hostname for that domain. @@ -11028,7 +11029,9 @@ virDomainGetDiskErrors(virDomainPtr dom, * NULL if there was an error. */ char * -virDomainGetHostname(virDomainPtr domain, unsigned int flags) +virDomainGetHostname(virDomainPtr domain, + unsigned int source, + unsigned int flags) { virConnectPtr conn; =20 @@ -11043,7 +11046,7 @@ virDomainGetHostname(virDomainPtr domain, unsigned = int flags) =20 if (conn->driver->domainGetHostname) { char *ret; - ret =3D conn->driver->domainGetHostname(domain, flags); + ret =3D conn->driver->domainGetHostname(domain, source, flags); if (!ret) goto error; return ret; diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index e07b3b302d..363eb5522a 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -295,7 +295,9 @@ openvzSetDiskQuota(virDomainDefPtr vmdef, =20 =20 static char * -openvzDomainGetHostname(virDomainPtr dom, unsigned int flags) +openvzDomainGetHostname(virDomainPtr dom, + unsigned int source, + unsigned int flags) { char *hostname =3D NULL; struct openvz_driver *driver =3D dom->conn->privateData; @@ -305,15 +307,25 @@ openvzDomainGetHostname(virDomainPtr dom, unsigned in= t flags) if (!(vm =3D openvzDomObjFromDomain(driver, dom->uuid))) return NULL; =20 - hostname =3D openvzVEGetStringParam(dom, "hostname"); - if (hostname =3D=3D NULL) - goto cleanup; + switch (source) { + default: + hostname =3D openvzVEGetStringParam(dom, "hostname"); + if (hostname =3D=3D NULL) + goto cleanup; =20 - /* vzlist prints an unset hostname as '-' */ - if (STREQ(hostname, "-")) { - virReportError(VIR_ERR_OPERATION_FAILED, - _("Hostname of '%s' is unset"), vm->def->name); - VIR_FREE(hostname); + /* vzlist prints an unset hostname as '-' */ + if (STREQ(hostname, "-")) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("Hostname of '%s' is unset"), vm->def->name); + VIR_FREE(hostname); + } + break; + case VIR_DOMAIN_HOSTNAME_SRC_AGENT: + case VIR_DOMAIN_HOSTNAME_SRC_LEASE: + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, + _("Unknown hostname data source %d"), + source); + break; } =20 cleanup: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 669c12d6ca..afcd5e8571 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20085,11 +20085,17 @@ qemuConnectGetCPUModelNames(virConnectPtr conn, =20 static char * qemuDomainGetHostname(virDomainPtr dom, + unsigned int source, unsigned int flags) { virQEMUDriverPtr driver =3D dom->conn->privateData; virDomainObjPtr vm =3D NULL; qemuAgentPtr agent; + 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; =20 virCheckFlags(0, NULL); @@ -20100,21 +20106,62 @@ qemuDomainGetHostname(virDomainPtr dom, if (virDomainGetHostnameEnsureACL(dom->conn, vm->def) < 0) goto cleanup; =20 - if (qemuDomainObjBeginAgentJob(driver, vm, QEMU_AGENT_JOB_QUERY) < 0) - goto cleanup; - if (virDomainObjCheckActive(vm) < 0) goto endjob; =20 - if (!qemuDomainAgentAvailable(vm, true)) - goto endjob; + switch (source) { + default: + case VIR_DOMAIN_HOSTNAME_SRC_AGENT: + if (qemuDomainObjBeginAgentJob(driver, vm, QEMU_AGENT_JOB_QUERY) <= 0) + goto cleanup; =20 - agent =3D qemuDomainObjEnterAgent(vm); - ignore_value(qemuAgentGetHostname(agent, &hostname)); - qemuDomainObjExitAgent(vm, agent); + if (!qemuDomainAgentAvailable(vm, true)) + goto endjob; =20 - endjob: - qemuDomainObjEndAgentJob(vm); + agent =3D qemuDomainObjEnterAgent(vm); + ignore_value(qemuAgentGetHostname(agent, &hostname)); + qemuDomainObjExitAgent(vm, agent); + + endjob: + qemuDomainObjEndAgentJob(vm); + break; + 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; + } =20 cleanup: virDomainObjEndAPI(&vm); diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 23e42d17b1..8d09f605da 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1467,6 +1467,7 @@ struct remote_domain_get_cpu_stats_ret { =20 struct remote_domain_get_hostname_args { remote_nonnull_domain dom; + unsigned int source; unsigned int flags; }; =20 diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 9ad7a857e0..dd9d1ec6fa 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -3543,4 +3543,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_GUEST_INFO =3D 418, REMOTE_PROC_CONNECT_SET_IDENTITY =3D 419, REMOTE_PROC_DOMAIN_AGENT_SET_RESPONSE_TIMEOUT =3D 420, + REMOTE_PROC_DOMAIN_GET_HOSTNAME =3D 421, }; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 5883722d60..0cbda81c67 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2028,6 +2028,7 @@ testDomainReset(virDomainPtr dom, =20 static char * testDomainGetHostname(virDomainPtr domain, + unsigned int source G_GNUC_UNUSED, unsigned int flags) { char *ret =3D NULL; diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 6be9780836..141b141a10 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -11669,6 +11669,10 @@ 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, + .help =3D N_("address source: 'lease' or 'agent'")}, {.name =3D NULL} }; =20 @@ -11678,21 +11682,38 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd) char *hostname; virDomainPtr dom; bool ret =3D false; + const char *sourcestr =3D NULL; + int source =3D -1; /* Use default value. Drivers can have its own defa= ult. */ =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) { + if (STREQ(sourcestr, "lease")) { + source =3D VIR_DOMAIN_HOSTNAME_SRC_LEASE; + } else if (STREQ(sourcestr, "agent")) { + source =3D VIR_DOMAIN_HOSTNAME_SRC_AGENT; + } else { + vshError(ctl, _("Unknown data source '%s'"), sourcestr); + goto error; + } + } + + hostname =3D virDomainGetHostname(dom, source, 0); if (hostname =3D=3D NULL) { vshError(ctl, "%s", _("failed to get hostname")); goto error; } =20 vshPrint(ctl, "%s\n", hostname); + + VIR_FREE(hostname); ret =3D true; =20 error: - VIR_FREE(hostname); virshDomainFree(dom); return ret; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed Apr 24 12:21:04 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