From nobody Sat Feb 7 18:46:28 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=1607466097; cv=none; d=zohomail.com; s=zohoarc; b=B9LxKGArOShqcqtAAWui1nxahnNmZelnLzb3H7rtPgWFIYdvKnrFf+WD12ZiqLHo4iaYhEHTxWFXZXOCgZpDmHhNDbJEcC/W+WlbsMhXh9Dlc/QeNGtyWDqi9cjJKrK1M5ndTTqurzGMlWuyO6FKFa8dEHIcAhuDTIaB6M5sMs8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607466097; 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=ibn99CVnA74SXerb8ZXk0YhLcrSxRWwbVgD8CGwoopA=; b=O7bkDpvp6obi30heMKir+AoMQclBXWvewhQTWayX2RXWdVK9Xf6+gPqG3lmox6vOYUVuHnSA0LJES2mPV4VIpz2c8KZ5LiKYyY8eyRxVFJBS3FLWS9W40+TVMgrXJ1C4VobdBZRsnb6tEHdVwMChb4mzAmu18LqVjBrMNuAbMP0= 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 1607466097683266.48027802403624; Tue, 8 Dec 2020 14:21:37 -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-463-gfXMs-TxM96NXAbhJ9fA3Q-1; Tue, 08 Dec 2020 17:21:33 -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 E711B1005513; Tue, 8 Dec 2020 22:21:26 +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 C4F5A60C0F; Tue, 8 Dec 2020 22:21:26 +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 906141809CAD; Tue, 8 Dec 2020 22:21:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B8MLN2n017577 for ; Tue, 8 Dec 2020 17:21:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id B455A2166B2A; Tue, 8 Dec 2020 22:21:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast06.extmail.prod.ext.rdu2.redhat.com [10.11.55.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AF52A2166B29 for ; Tue, 8 Dec 2020 22:21:21 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.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 A015A1875042 for ; Tue, 8 Dec 2020 22:21:21 +0000 (UTC) Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-248-9_StCs-jM-2Z3qFtdMl_xA-1; Tue, 08 Dec 2020 17:21:18 -0500 Received: by mail-qt1-f173.google.com with SMTP id c14so3562851qtn.0; Tue, 08 Dec 2020 14:21:18 -0800 (PST) Received: from rekt.redhat.com ([2804:431:c7c7:c1a:69c1:2b22:e880:fc49]) by smtp.gmail.com with ESMTPSA id c14sm75057qtg.85.2020.12.08.14.21.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 14:21:17 -0800 (PST) X-MC-Unique: gfXMs-TxM96NXAbhJ9fA3Q-1 X-MC-Unique: 9_StCs-jM-2Z3qFtdMl_xA-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=ibn99CVnA74SXerb8ZXk0YhLcrSxRWwbVgD8CGwoopA=; b=HhqLbPkGp5w288QQE9XvS8ddHGtvS5qqHfCm+TtEYn959LEeBWtpLPoYNbLssFVXtG Tc/av1aOphanvOzutnaRWR8pqvQ4Rv1Sr0jLkBLi4/Bs4QXqAStGYg3NA6Ga4+C5nCvW XGdULkBhVN909i2D9V4X1QcoT+XooAOxvpqXwcGItTsU3L1vA+fEGsCIwWeSnXMyb6Mi Jwq4iFt5AqrJJYcE5RrJLpuHDqKCF+BNGr2g6RN1JP9WAqhzo7JfbBv6u63k4PnSeWl8 eZIdVvq3ybZe0Ky32CEX4YSyh4XvQm4xK83ZhB7oh0khr6T2qGXxTX5KIQbnnPqwTKNB lxKw== X-Gm-Message-State: AOAM530JIxystdF0QF7+adWHVmWkxEOHq8PgnhAyoGZU5Cvi6vGZJpjB WST9tFlodpbkxBpEONTkOhtvYxYXhnA= X-Google-Smtp-Source: ABdhPJyNH+2cWmdjNaG96uHG3R6ZFaoM4U681KREQLxEWiiE1k5eDk386vVFnkxH8t9aWDYfVQ/30A== X-Received: by 2002:ac8:7146:: with SMTP id h6mr268335qtp.112.1607466077626; Tue, 08 Dec 2020 14:21:17 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v3 14/14] domain_conf.c: move idmapEntry checks to domain_validate.c Date: Tue, 8 Dec 2020 19:20:30 -0300 Message-Id: <20201208222030.1302229-15-danielhb413@gmail.com> In-Reply-To: <20201208222030.1302229-1-danielhb413@gmail.com> References: <20201208222030.1302229-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.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Michal Privoznik , 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.79 on 10.5.11.12 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(). Reviewed-by: Michal Privoznik Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 19 +++---------------- src/conf/domain_validate.c | 23 +++++++++++++++++++++++ src/conf/domain_validate.h | 1 + 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7a7c9ec85c..44f136f530 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6947,6 +6947,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 @@ -18463,15 +18466,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 @@ -21961,13 +21955,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 diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 35deb9f017..0eed1ba982 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -612,3 +612,26 @@ virDomainControllerDefValidate(const virDomainControll= erDef *controller) =20 return 0; } + + +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; +} diff --git a/src/conf/domain_validate.h b/src/conf/domain_validate.h index e8004e358d..497a02b9b3 100644 --- a/src/conf/domain_validate.h +++ b/src/conf/domain_validate.h @@ -44,3 +44,4 @@ int virDomainSmartcardDefValidate(const virDomainSmartcar= dDef *smartcard, const virDomainDef *def); int virDomainDefTunablesValidate(const virDomainDef *def); int virDomainControllerDefValidate(const virDomainControllerDef *controlle= r); +int virDomainDefIdMapValidate(const virDomainDef *def); --=20 2.26.2