From nobody Mon Feb 9 10:30:31 2026 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=1646643693; cv=none; d=zohomail.com; s=zohoarc; b=jbF3PQhqqXnHajVTr/FktFNNZti/wzO5qTJOXq8e9LlDsaoT6YjMXCYgFxpBVzM0ygh5/mUcnJqd318p0SppHz/b1fkcLHjX4GLVNThhBu0kO5l0qg6Zjce82rfIkTgYx6FpHUYNClUvp5ERijd8YvtggcJNN4LZQMdtxyCtXQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646643693; 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=7bNLPk5R3lmSfg6oFuLzTUKWEWuQKOWJ271Gn7su1ok=; b=QPyjgtkS1q/8Nx0Ez9ohV9VSiRGAJVM0Kp+sl1huFGNCfYLV+opSjIgCjRTYhDkjQvXvZBr5v5vn2d76nOqzVvo0FtOBvr/D1WAWaG17+NN8IUyIv9Uxybjc5HqYynbpHQHzLMc9v2nvCVxEDESWdhUfeqGirK16OH8OAZxy+6c= 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 1646643693694903.176545854953; Mon, 7 Mar 2022 01:01:33 -0800 (PST) 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-231-5lI8Kpt_OmKfqCziTbvvog-1; Mon, 07 Mar 2022 04:01:29 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AAF3983395B; Mon, 7 Mar 2022 09:01:24 +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 97218401E40; Mon, 7 Mar 2022 09:01:24 +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 421601931BDD; Mon, 7 Mar 2022 09:01:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8D3AB1931BF4 for ; Mon, 7 Mar 2022 09:01:23 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5007A1F473; Mon, 7 Mar 2022 09:01:23 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6FBD1F470 for ; Mon, 7 Mar 2022 09:01:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646643692; 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=7bNLPk5R3lmSfg6oFuLzTUKWEWuQKOWJ271Gn7su1ok=; b=QO2RD1bccar3T31SWtxHgJFljvqdsTgK581/eBlxUYzk+PJtx3HVQmpF9WZ6qsHSVXEsT3 Da7v1V2PiQNRoYStplafNmYZmkygpFA3x13XX6szeqtOt9qCa9El8iwbfaMJ+ntJjAYsIb WO7l6JDFuiaFfAUGZBzCe+h9xvv++Ho= X-MC-Unique: 5lI8Kpt_OmKfqCziTbvvog-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 16/17] lxc_fuse: Implement support for FUSE3 Date: Mon, 7 Mar 2022 10:01:06 +0100 Message-Id: <48c7cdbc723b6b816525a09e16a3f95c4b1b32e2.1646643526.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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 2.85 on 10.11.54.10 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 X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646643695872100009 Content-Type: text/plain; charset="utf-8" Plenty of projects switch from FUSE to FUSE3. This commit enables libvirt to compile with newer fuse-3.1 which allows users to have just one fuse package on their systems, allows us to set O_CLOEXEC on the fuse session FD. In general, FUSE3 offers more features, but apparently we don't need them right now. There is a rewrite guide at [1] but I've took most inspiration from sshfs [2]. 1: https://github.com/libfuse/libfuse/releases/tag/fuse-3.0.0 2: https://github.com/libfuse/sshfs Signed-off-by: Michal Privoznik --- src/lxc/lxc_fuse.c | 73 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index 181b05b605..802b2f5a1b 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -28,6 +28,9 @@ #if WITH_FUSE # define FUSE_USE_VERSION 26 # include +# if FUSE_USE_VERSION >=3D 31 +# include +# endif #endif =20 #include "lxc_fuse.h" @@ -48,15 +51,19 @@ struct virLXCFuse { virThread thread; char *mountpoint; struct fuse *fuse; +# if FUSE_USE_VERSION < 31 struct fuse_chan *ch; +# else + struct fuse_session *sess; +# endif virMutex lock; }; =20 static const char *fuse_meminfo_path =3D "/meminfo"; =20 static int -lxcProcGetattr(const char *path, - struct stat *stbuf) +lxcProcGetattrImpl(const char *path, + struct stat *stbuf) { g_autofree char *mempath =3D NULL; struct stat sb; @@ -90,6 +97,40 @@ lxcProcGetattr(const char *path, return 0; } =20 +# if FUSE_USE_VERSION >=3D 31 +static int +lxcProcGetattr(const char *path, + struct stat *stbuf, + struct fuse_file_info *fi G_GNUC_UNUSED) +{ + return lxcProcGetattrImpl(path, stbuf); +} +# else +static int lxcProcGetattr(const char *path, struct stat *stbuf) +{ + return lxcProcGetattrImpl(path, stbuf); +} +# endif + +# if FUSE_USE_VERSION >=3D 31 +static int +lxcProcReaddir(const char *path, + void *buf, + fuse_fill_dir_t filler, + off_t offset G_GNUC_UNUSED, + struct fuse_file_info *fi G_GNUC_UNUSED, + enum fuse_readdir_flags unused_flags G_GNUC_UNUSED) +{ + if (STRNEQ(path, "/")) + return -ENOENT; + + filler(buf, ".", NULL, 0, 0); + filler(buf, "..", NULL, 0, 0); + filler(buf, fuse_meminfo_path + 1, NULL, 0, 0); + + return 0; +} +# else static int lxcProcReaddir(const char *path, void *buf, @@ -106,6 +147,7 @@ lxcProcReaddir(const char *path, =20 return 0; } +# endif =20 static int lxcProcOpen(const char *path, @@ -292,7 +334,11 @@ lxcFuseDestroy(struct virLXCFuse *fuse) { VIR_LOCK_GUARD lock =3D virLockGuardLock(&fuse->lock); =20 +# if FUSE_USE_VERSION >=3D 31 + fuse_unmount(fuse->fuse); +# else fuse_unmount(fuse->mountpoint, fuse->ch); +# endif g_clear_pointer(&fuse->fuse, fuse_destroy); } =20 @@ -335,6 +381,23 @@ lxcSetupFuse(struct virLXCFuse **f, fuse_opt_add_arg(&args, "-ofsname=3Dlibvirt") =3D=3D -1) goto error; =20 +# if FUSE_USE_VERSION >=3D 31 + fuse->fuse =3D fuse_new(&args, &lxcProcOper, sizeof(lxcProcOper), fuse= ->def); + if (fuse->fuse =3D=3D NULL) + goto error; + + if (fuse_mount(fuse->fuse, fuse->mountpoint) < 0) + goto error; + + fuse->sess =3D fuse_get_session(fuse->fuse); + + if (virSetInherit(fuse_session_fd(fuse->sess), false) < 0) { + virReportSystemError(errno, "%s", + _("Cannot disable close-on-exec flag")); + goto error; + } + +# else fuse->ch =3D fuse_mount(fuse->mountpoint, &args); if (fuse->ch =3D=3D NULL) goto error; @@ -344,6 +407,7 @@ lxcSetupFuse(struct virLXCFuse **f, if (fuse->fuse =3D=3D NULL) { goto error; } +# endif =20 *f =3D g_steal_pointer(&fuse); ret =3D 0; @@ -352,8 +416,13 @@ lxcSetupFuse(struct virLXCFuse **f, return ret; =20 error: +# if FUSE_USE_VERSION < 31 if (fuse->ch) fuse_unmount(fuse->mountpoint, fuse->ch); +# else + fuse_unmount(fuse->fuse); + fuse_destroy(fuse->fuse); +# endif g_free(fuse->mountpoint); virMutexDestroy(&fuse->lock); goto cleanup; --=20 2.34.1