From nobody Sun Feb 8 14:52:10 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1607349329; cv=none; d=zohomail.com; s=zohoarc; b=kAzWNVWYrpWaDV1x0w7eom1NhuA5KLvXh0kgnSsaM65DFMKnywLA4kXRyCuye6Y0YtKcep/EkMMMuGMhFr9UaNyIk7j52pRg5IwF7tZYpldDxDDyvbbs72imVd/lbRAjDJvPXXkzp+rnoFM6SQOWihwREOGuMgLPMNoXtSbm2es= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607349329; 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=adCTGfKWw+cEAbI4cBNejmmL8rDzmd9xRTxmyBshCUk=; b=LVfNT0PxFDx3yS7s3zbTmnHIabPqhUc7km/bq9NJz2rw7U8xIjuzaIAw4Youoy2PjiLnzzmDSSI4QJsX92nAzOtKCGn+5/Sr0zRCCjSCvD00bYE5n4QhmKvVKxNrGeLKA1xrSKWewcjvSGbjMaelT44AgFPYQ/aSFWyAYc9NVPY= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1607349329981377.8767180773708; Mon, 7 Dec 2020 05:55:29 -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-563-6ENkXhw3OLW2k0bfMa4SwA-1; Mon, 07 Dec 2020 08:55:26 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A33181E7CD; Mon, 7 Dec 2020 13:55:19 +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 716C419C59; Mon, 7 Dec 2020 13:55:19 +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 D867E5002D; Mon, 7 Dec 2020 13:55:18 +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 0B7DtEJT013044 for ; Mon, 7 Dec 2020 08:55:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9A55264021; Mon, 7 Dec 2020 13:55:14 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9438A4405A for ; Mon, 7 Dec 2020 13:55:11 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) (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 86EE0811E76 for ; Mon, 7 Dec 2020 13:55:11 +0000 (UTC) Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-486-l_8lnWyCMGG-aq_PtGTuzQ-1; Mon, 07 Dec 2020 08:55:06 -0500 Received: by mail-qv1-f42.google.com with SMTP id l7so1134612qvt.4 for ; Mon, 07 Dec 2020 05:55:06 -0800 (PST) Received: from rekt.redhat.com ([2804:431:c7c7:c1a:69c1:2b22:e880:fc49]) by smtp.gmail.com with ESMTPSA id n95sm12233701qte.43.2020.12.07.05.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 05:55:05 -0800 (PST) X-MC-Unique: 6ENkXhw3OLW2k0bfMa4SwA-1 X-MC-Unique: l_8lnWyCMGG-aq_PtGTuzQ-1 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=adCTGfKWw+cEAbI4cBNejmmL8rDzmd9xRTxmyBshCUk=; b=EBH7F0kBImf4Ypy2iT77/bRzdSpSuvsLRWIFck0h+iWEHVkS18XaXIMgPHfTmx4yqc xK5G+O8OXQyxeTMST1sJasQ1Y9r84JyX/O2F1f9n8uZB1vCuuKeux6LDA8dnm3UpeJg2 7cYYMwDXDqUGuSeVJXBfq4XNc8mfW9eyQWk2O7Wvcvva72StX0TX6wfP2bdqqm3JKD2f NimkjLaS/ZnYfThH/WA6NqNsPKQSWNzmciNsEOAfMCftkYOcXeWn4MZlTEX+Nz+9JcHl 9Lq+y428gXAj3I0l1YpO9NdVhM8GQhc/8HvhlQr+a1qhRkHFX/famvdYYO7GBo9exSki 9MTA== X-Gm-Message-State: AOAM530gFsL4oF4vc6wDEuoKq65R0dmwSxBNzIDnWRxiXxwePjAkxBQ9 32enmd3Eba+edgaNrJAuzSbWTGlMpnU= X-Google-Smtp-Source: ABdhPJz5XvzemvO2eqxJfq4AbZDMvIYrH1o0kX1MrbO5DtKrvLM0m04NCWV+LdI5TewyBTyMVEKOew== X-Received: by 2002:a0c:a181:: with SMTP id e1mr21233026qva.53.1607349305762; Mon, 07 Dec 2020 05:55:05 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 9/9] domain_conf.c: move idmapEntry checks to validate callback Date: Mon, 7 Dec 2020 10:54:35 -0300 Message-Id: <20201207135435.884594-10-danielhb413@gmail.com> In-Reply-To: <20201207135435.884594-1-danielhb413@gmail.com> References: <20201207135435.884594-1-danielhb413@gmail.com> MIME-Version: 1.0 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 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Create a new function called virDomainDefIdMapValidate() and use it to move these checks out of virDomainIdmapDefParseXML() and virDomainDefParseXML(). Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 11711ba05d..471de235a1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7475,6 +7475,29 @@ virDomainDefTunablesValidate(const virDomainDef *def) } =20 =20 +static int +virDomainDefIdMapValidate(const virDomainDef *def) +{ + if ((def->idmap.uidmap && !def->idmap.gidmap) || + (!def->idmap.uidmap && def->idmap.gidmap)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("uid and gid should be mapped both")); + return -1; + } + + if ((def->idmap.uidmap && def->idmap.uidmap[0].start !=3D 0) || + (def->idmap.gidmap && def->idmap.gidmap[0].start !=3D 0)) { + /* Root user of container hasn't been mapped to any user of host, + * return error. */ + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("You must map the root user of container")); + return -1; + } + + return 0; +} + + static int virDomainDefValidateInternal(const virDomainDef *def, virDomainXMLOptionPtr xmlopt) @@ -7529,6 +7552,9 @@ virDomainDefValidateInternal(const virDomainDef *def, if (virDomainDefTunablesValidate(def) < 0) return -1; =20 + if (virDomainDefIdMapValidate(def) < 0) + return -1; + if (virDomainNumaDefValidate(def->numa) < 0) return -1; =20 @@ -19045,15 +19071,6 @@ virDomainIdmapDefParseXML(xmlXPathContextPtr ctxt, =20 qsort(idmap, num, sizeof(idmap[0]), virDomainIdMapEntrySort); =20 - if (idmap[0].start !=3D 0) { - /* Root user of container hasn't been mapped to any user of host, - * return error. */ - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("You must map the root user of container")); - VIR_FREE(idmap); - return NULL; - } - return idmap; } =20 @@ -22543,13 +22560,6 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); =20 - if ((def->idmap.uidmap && !def->idmap.gidmap) || - (!def->idmap.uidmap && def->idmap.gidmap)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("uid and gid should be mapped both")); - goto error; - } - if ((n =3D virXPathNodeSet("./sysinfo", ctxt, &nodes)) < 0) goto error; =20 --=20 2.26.2