From nobody Mon Sep 16 19:58:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 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=1694440378; cv=none; d=zohomail.com; s=zohoarc; b=luBm9hTPy6AbQaZ9R527Ipqjua3sVT4EKWE//Z2g8ZPOTqUdMiQalI8N0mrlScdASxQDPZ18AJcYmHrvBOsxL60k//jZVqG+TjDZK8hNmB4imClxDIFomXNC74JEE+++KCt7nukdNVDjgIREc8lxum35GlQQe0Z+m46tn0EVw2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694440378; h=Content-Type:Content-Transfer-Encoding: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=qNyMjYQlnBGIwMbY0flRh2D8ic0X9z0+FahLXFCncZg=; b=K1IiwCRWm3JDBjIQaC9a+sKpK8RKnq7FDgc3h4TDuhw2JtQlpAPNPcG7gON0omnTr/ESVVTvC7ZNTHehTUTkzPcjjgYg5Au56J+pxLOItuondyDleEmdhxA8vPWq+rh0OxOCJSJpTQxayozdBtjl93hwe3NEgasXz2F53B4Fxww= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1694440378970768.9693849261336; Mon, 11 Sep 2023 06:52:58 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-523-QgqIN9r6P_SmYrxqwMEv6A-1; Mon, 11 Sep 2023 09:52:47 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0559F80523C; Mon, 11 Sep 2023 13:52:34 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF7C82026D4B; Mon, 11 Sep 2023 13:52:33 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7282719465B8; Mon, 11 Sep 2023 13:52:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DB1911946A50 for ; Mon, 11 Sep 2023 13:52:30 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id CAD0E10EE859; Mon, 11 Sep 2023 13:52:30 +0000 (UTC) Received: from fedora.. (unknown [10.43.2.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 716CC10F1BE9 for ; Mon, 11 Sep 2023 13:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694440378; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=qNyMjYQlnBGIwMbY0flRh2D8ic0X9z0+FahLXFCncZg=; b=AdCoDztbX3M+IYz3xarXiW6WUuyNeUSNMCtxsOQ4VuN6ZHTxmXzRqQmJ8KV0kN/07d7/Hd Fs341rI26jH89FzUlOLFPwL/2ucTcn0RWJvLA06WoEe/p38xkbTbqvXVW/b4PqaKX/3zIq +SOmB8ycJUFewrGwWzA9+sCD6osXvuI= X-MC-Unique: QgqIN9r6P_SmYrxqwMEv6A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCHv1 4/8] conf: add idmap element to filesystem Date: Mon, 11 Sep 2023 15:51:24 +0200 Message-ID: <2682cd5d0fba149f3d66ef988b4b48641fd8cdf9.1694440288.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1694440407155100005 Let unprivileged virtiofs use user namespace. Signed-off-by: J=C3=A1n Tomko --- docs/formatdomain.rst | 7 +++ src/conf/domain_conf.c | 51 +++++++++++++++++++ src/conf/domain_conf.h | 1 + src/conf/schemas/domaincommon.rng | 3 ++ .../vhost-user-fs-fd-memory.xml | 4 ++ 5 files changed, 66 insertions(+) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index bc469e5f9f..0f10b3043f 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3501,6 +3501,10 @@ A directory on the host that can be accessed directl= y from the guest. + + + + @@ -3650,6 +3654,9 @@ A directory on the host that can be accessed directly= from the guest. Where the ``source`` can be accessed in the guest. For most drivers thi= s is an automatic mount point, but for QEMU/KVM this is merely an arbitrary = string tag that is exported to the guest as a hint for where to mount. +``idmap`` + For ``virtiofs``, an ``idmap`` element can be specified to map IDs in t= he user + namespace. See the `Container boot`_ section for the syntax of the elem= ent. ``readonly`` Enables exporting filesystem as a readonly mount for guest, by default read-write access is given (currently only works for QEMU/KVM driver). diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index dd67e7f21b..2379a9204f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2585,6 +2585,8 @@ void virDomainFSDefFree(virDomainFSDef *def) virObjectUnref(def->privateData); g_free(def->binary); g_free(def->sock); + g_free(def->idmap.uidmap); + g_free(def->idmap.gidmap); =20 g_free(def); } @@ -8767,6 +8769,8 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, xmlNodePtr binary_lock_node =3D virXPathNode("./binary/lock", ctxt= ); xmlNodePtr binary_cache_node =3D virXPathNode("./binary/cache", ct= xt); xmlNodePtr binary_sandbox_node =3D virXPathNode("./binary/sandbox"= , ctxt); + ssize_t n; + xmlNodePtr *nodes =3D NULL; =20 if (queue_size && virStrToLong_ull(queue_size, NULL, 10, &def->que= ue_size) < 0) { virReportError(VIR_ERR_XML_ERROR, @@ -8812,6 +8816,30 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, VIR_XML_PROP_NONZERO, &def->sandbox) < 0) goto error; + + if ((n =3D virXPathNodeSet("./idmap/uid", ctxt, &nodes)) < 0) + return NULL; + + if (n) { + def->idmap.uidmap =3D virDomainIdmapDefParseXML(ctxt, nodes, n= ); + if (!def->idmap.uidmap) + return NULL; + + def->idmap.nuidmap =3D n; + } + VIR_FREE(nodes); + + if ((n =3D virXPathNodeSet("./idmap/gid", ctxt, &nodes)) < 0) + return NULL; + + if (n) { + def->idmap.gidmap =3D virDomainIdmapDefParseXML(ctxt, nodes, = n); + if (!def->idmap.gidmap) + return NULL; + + def->idmap.ngidmap =3D n; + } + VIR_FREE(nodes); } =20 if (source =3D=3D NULL && def->type !=3D VIR_DOMAIN_FS_TYPE_RAM @@ -23164,6 +23192,29 @@ virDomainFSDefFormat(virBuffer *buf, virXMLFormatElement(buf, "driver", &driverAttrBuf, &driverBuf); virXMLFormatElement(buf, "binary", &binaryAttrBuf, &binaryBuf); =20 + if (def->idmap.uidmap) { + size_t i; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (i =3D 0; i < def->idmap.nuidmap; i++) { + virBufferAsprintf(buf, + "\n", + def->idmap.uidmap[i].start, + def->idmap.uidmap[i].target, + def->idmap.uidmap[i].count); + } + for (i =3D 0; i < def->idmap.ngidmap; i++) { + virBufferAsprintf(buf, + "\n", + def->idmap.gidmap[i].start, + def->idmap.gidmap[i].target, + def->idmap.gidmap[i].count); + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + switch (def->type) { case VIR_DOMAIN_FS_TYPE_MOUNT: case VIR_DOMAIN_FS_TYPE_BIND: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8937968e3b..b84719b01d 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -925,6 +925,7 @@ struct _virDomainFSDef { virTristateSwitch flock; virDomainFSSandboxMode sandbox; int thread_pool_size; + virDomainIdMapDef idmap; virDomainVirtioOptions *virtio; virObject *privateData; }; diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index 2f9ba31c0a..2ca0e92f00 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -3052,6 +3052,9 @@ + + + diff --git a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml b/tests/qem= uxml2argvdata/vhost-user-fs-fd-memory.xml index 81de8c0dd7..1d0bc26c46 100644 --- a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml +++ b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml @@ -34,6 +34,10 @@ + + + +
--=20 2.41.0