From nobody Sun Feb 8 18:08:51 2026 Received: from smtp01-ext2.udag.de (smtp01-ext2.udag.de [62.146.106.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0F54364E95; Fri, 9 Jan 2026 18:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.146.106.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767983238; cv=none; b=XqDtPp5bl5fz1z4awgS7lz1CM9v9me1z9yhpgwdWPxpulDoM5cMcLPjY0nW/qUGexgZCrcPezIlum2V2exE0pbTs/nQ4pDOLaec/JoL1k7k3b8LNWO0w+c9+sVIKx1cix/Q1s5LrZTMP89gO9WciMuYxWBaf/Q9k9Ema5/prAso= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767983238; c=relaxed/simple; bh=FfNfHuhka45Oh1oAKK9SM76gPbOP7HrYhJ9pgVkxaLk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fPDAOWGB45tH3shiCah0Ptrh6IU2ERNlTL2Y+jVwxPQuBlqVs3yXMtBvUxSieZZLqJuzBl0PqDmuO5zJ83LUMmjYU03UFWNpHbyoOuzTB1qgL54VK5uArY02S2ObhHzcUtXRw2ucSo/sxNYIq68GlxgjwriozJ8h1nrPxMFxmds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=birthelmer.com; spf=pass smtp.mailfrom=birthelmer.com; dkim=pass (2048-bit key) header.d=birthelmer.com header.i=@birthelmer.com header.b=nGU/0uVZ; arc=none smtp.client-ip=62.146.106.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=birthelmer.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=birthelmer.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=birthelmer.com header.i=@birthelmer.com header.b="nGU/0uVZ" Received: from [127.0.1.1] (049-102-000-128.ip-addr.inexio.net [128.0.102.49]) by smtp01-ext2.udag.de (Postfix) with ESMTPA id 5474EE01F7; Fri, 9 Jan 2026 19:27:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=birthelmer.com; s=uddkim-202310; t=1767983228; h=from:from: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; bh=gSiK28kg0Qx+lI39xvPxztDwFHl+hlxd3X0is3FrMoQ=; b=nGU/0uVZ8WwmXl60vQ0JWZVribYcQJUxm5d7VufN8jQ9UB+idnpHCq5H+0RtlHE5Yf9xYG vrNzfdTnHjifni5g+bSst6nigs7PYdVH2iw+yOaY361H8CMp7DKHvgPbsOJAtSGfPmlnfw 9BIn6CdMzeTfEKOiNmPjfO6WOr+RPoHfTxxhtVMenPXpodC3JYqaO3p4yfkvQ3EbtgKrLx cAWxI2Ga20u54/EICJNnd1WlceR1hXlCrcw3jaKZQQhElLT44ehwDk9RqHQhhJcqcsW/Kq +7VKSrb7SQkR8flHA8SHut7Jpek7+QAlvNXHJNuvncehtuZwLnTO/t5mHeCTng== Authentication-Results: smtp01-ext2.udag.de; auth=pass smtp.auth=birthelmercom-0001 smtp.mailfrom=horst@birthelmer.com From: Horst Birthelmer Date: Fri, 09 Jan 2026 19:26:59 +0100 Subject: [PATCH v4 1/3] fuse: add compound command to combine multiple requests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260109-fuse-compounds-upstream-v4-1-0d3b82a4666f@ddn.com> References: <20260109-fuse-compounds-upstream-v4-0-0d3b82a4666f@ddn.com> In-Reply-To: <20260109-fuse-compounds-upstream-v4-0-0d3b82a4666f@ddn.com> To: Miklos Szeredi , Bernd Schubert , Joanne Koong Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Horst Birthelmer X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767983227; l=11366; i=hbirthelmer@ddn.com; s=20251006; h=from:subject:message-id; bh=AQhJiHqXWZQ/xoM10wtTeI1woX0yVXrn5+y/+dfoVWQ=; b=8mMES687V2jmWoB/P239dt/TThSzXFctwWUlpqG6Ppdb3ooQr7bl1FZi8UfkLxLNMVuwFNLrZ 9kow/Aj7ombC361etRVblL/pJzwsKIJJ7FGzDZF2eLycuLyS1UT8QBV X-Developer-Key: i=hbirthelmer@ddn.com; a=ed25519; pk=v3BVDFoy16EzgHZ23ObqW+kbpURtjrwxgKu8YNDKjGg= From: Horst Birthelmer For a FUSE_COMPOUND we add a header that contains information about how many commands there are in the compound and about the size of the expected result. This will make the interpretation in libfuse easier, since we can preallocate the whole result. Then we append the requests that belong to this compound. The API for the compound command has: fuse_compound_alloc() fuse_compound_add() fuse_compound_send() fuse_compound_free() Signed-off-by: Horst Birthelmer --- fs/fuse/Makefile | 2 +- fs/fuse/compound.c | 270 ++++++++++++++++++++++++++++++++++++++++++= ++++ fs/fuse/fuse_i.h | 12 +++ include/uapi/linux/fuse.h | 37 +++++++ 4 files changed, 320 insertions(+), 1 deletion(-) diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile index 22ad9538dfc4..4c09038ef995 100644 --- a/fs/fuse/Makefile +++ b/fs/fuse/Makefile @@ -11,7 +11,7 @@ obj-$(CONFIG_CUSE) +=3D cuse.o obj-$(CONFIG_VIRTIO_FS) +=3D virtiofs.o =20 fuse-y :=3D trace.o # put trace.o first so we see ftrace errors sooner -fuse-y +=3D dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o i= octl.o +fuse-y +=3D dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o i= octl.o compound.o fuse-y +=3D iomode.o fuse-$(CONFIG_FUSE_DAX) +=3D dax.o fuse-$(CONFIG_FUSE_PASSTHROUGH) +=3D passthrough.o backing.o diff --git a/fs/fuse/compound.c b/fs/fuse/compound.c new file mode 100644 index 000000000000..0f1e4c073d8b --- /dev/null +++ b/fs/fuse/compound.c @@ -0,0 +1,270 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * FUSE: Filesystem in Userspace + * Copyright (C) 2025 + * + * This file implements compound operations for FUSE, allowing multiple + * operations to be batched into a single request to reduce round trips + * between kernel and userspace. + */ + +#include "fuse_i.h" + +/* + * Compound request builder and state tracker and args pointer storage + */ +struct fuse_compound_req { + struct fuse_mount *fm; + struct fuse_compound_in compound_header; + struct fuse_compound_out result_header; + + /* Per-operation error codes */ + int op_errors[FUSE_MAX_COMPOUND_OPS]; + /* Original fuse_args for response parsing */ + struct fuse_args *op_args[FUSE_MAX_COMPOUND_OPS]; +}; + +struct fuse_compound_req *fuse_compound_alloc(struct fuse_mount *fm, u32 f= lags) +{ + struct fuse_compound_req *compound; + + compound =3D kzalloc(sizeof(*compound), GFP_KERNEL); + if (!compound) + return ERR_PTR(-ENOMEM); + + compound->fm =3D fm; + compound->compound_header.flags =3D flags; + + return compound; +} + +void fuse_compound_free(struct fuse_compound_req *compound) +{ + if (!compound) + return; + + kfree(compound); +} + +int fuse_compound_add(struct fuse_compound_req *compound, + struct fuse_args *args) +{ + if (!compound || + compound->compound_header.count >=3D FUSE_MAX_COMPOUND_OPS) + return -EINVAL; + + if (args->in_pages) + return -EINVAL; + + compound->op_args[compound->compound_header.count] =3D args; + compound->compound_header.count++; + return 0; +} + +static void *fuse_copy_response_data(struct fuse_args *args, + char *response_data) +{ + size_t copied =3D 0; + int i; + + for (i =3D 0; i < args->out_numargs; i++) { + struct fuse_arg current_arg =3D args->out_args[i]; + size_t arg_size; + + /* + * Last argument with out_pages: copy to pages + * External payload (in the last out arg) is not supported + * at the moment + */ + if (i =3D=3D args->out_numargs - 1 && args->out_pages) + return response_data; + + arg_size =3D current_arg.size; + + if (current_arg.value && arg_size > 0) { + memcpy(current_arg.value, + (char *)response_data + copied, arg_size); + copied +=3D arg_size; + } + } + + return (char *)response_data + copied; +} + +int fuse_compound_get_error(struct fuse_compound_req *compound, int op_idx) +{ + return compound->op_errors[op_idx]; +} + +static void *fuse_compound_parse_one_op(struct fuse_compound_req *compound, + int op_index, void *op_out_data, + void *response_end) +{ + struct fuse_out_header *op_hdr =3D op_out_data; + struct fuse_args *args =3D compound->op_args[op_index]; + + if (op_hdr->len < sizeof(struct fuse_out_header)) + return NULL; + + /* Check if the entire operation response fits in the buffer */ + if ((char *)op_out_data + op_hdr->len > (char *)response_end) + return NULL; + + if (op_hdr->error !=3D 0) + compound->op_errors[op_index] =3D op_hdr->error; + + if (args && op_hdr->len > sizeof(struct fuse_out_header)) + return fuse_copy_response_data(args, op_out_data + + sizeof(struct fuse_out_header)); + + /* No response data, just advance past the header */ + return (char *)op_out_data + op_hdr->len; +} + +static int fuse_compound_parse_resp(struct fuse_compound_req *compound, + u32 count, void *response, + size_t response_size) +{ + void *op_out_data =3D response; + void *response_end =3D (char *)response + response_size; + int i; + + if (!response || response_size < sizeof(struct fuse_out_header)) + return -EIO; + + for (i =3D 0; i < count && i < compound->result_header.count; i++) { + op_out_data =3D fuse_compound_parse_one_op(compound, i, + op_out_data, + response_end); + if (!op_out_data) + return -EIO; + } + + return 0; +} + +ssize_t fuse_compound_send(struct fuse_compound_req *compound) +{ + struct fuse_args args =3D { + .opcode =3D FUSE_COMPOUND, + .nodeid =3D 0, + .in_numargs =3D 2, + .out_numargs =3D 2, + .out_argvar =3D true, + }; + size_t resp_buffer_size; + size_t actual_response_size; + size_t buffer_pos; + size_t total_expected_out_size; + void *buffer =3D NULL; + void *resp_payload; + ssize_t ret; + int i; + + if (!compound) { + pr_info_ratelimited("FUSE: compound request is NULL in %s\n", + __func__); + return -EINVAL; + } + + if (compound->compound_header.count =3D=3D 0) { + pr_info_ratelimited("FUSE: compound request contains no operations\n"); + return -EINVAL; + } + + buffer_pos =3D 0; + total_expected_out_size =3D 0; + + for (i =3D 0; i < compound->compound_header.count; i++) { + struct fuse_args *op_args =3D compound->op_args[i]; + size_t needed_size =3D sizeof(struct fuse_in_header); + int j; + + for (j =3D 0; j < op_args->in_numargs; j++) + needed_size +=3D op_args->in_args[j].size; + + buffer_pos +=3D needed_size; + + for (j =3D 0; j < op_args->out_numargs; j++) + total_expected_out_size +=3D op_args->out_args[j].size; + } + + buffer =3D kvmalloc(buffer_pos, GFP_KERNEL); + if (!buffer) + return -ENOMEM; + + buffer_pos =3D 0; + for (i =3D 0; i < compound->compound_header.count; i++) { + struct fuse_args *op_args =3D compound->op_args[i]; + struct fuse_in_header *hdr; + size_t needed_size =3D sizeof(struct fuse_in_header); + int j; + + for (j =3D 0; j < op_args->in_numargs; j++) + needed_size +=3D op_args->in_args[j].size; + + hdr =3D (struct fuse_in_header *)(buffer + buffer_pos); + memset(hdr, 0, sizeof(*hdr)); + hdr->len =3D needed_size; + hdr->opcode =3D op_args->opcode; + hdr->nodeid =3D op_args->nodeid; + hdr->uid =3D from_kuid(compound->fm->fc->user_ns, + current_fsuid()); + hdr->gid =3D from_kgid(compound->fm->fc->user_ns, + current_fsgid()); + hdr->pid =3D pid_nr_ns(task_pid(current), + compound->fm->fc->pid_ns); + buffer_pos +=3D sizeof(*hdr); + + for (j =3D 0; j < op_args->in_numargs; j++) { + memcpy(buffer + buffer_pos, op_args->in_args[j].value, + op_args->in_args[j].size); + buffer_pos +=3D op_args->in_args[j].size; + } + } + + resp_buffer_size =3D total_expected_out_size + + (compound->compound_header.count * + sizeof(struct fuse_out_header)); + + resp_payload =3D kvmalloc(resp_buffer_size, GFP_KERNEL | __GFP_ZERO); + if (!resp_payload) { + ret =3D -ENOMEM; + goto out_free_buffer; + } + + compound->compound_header.result_size =3D total_expected_out_size; + + args.in_args[0].size =3D sizeof(compound->compound_header); + args.in_args[0].value =3D &compound->compound_header; + args.in_args[1].size =3D buffer_pos; + args.in_args[1].value =3D buffer; + + args.out_args[0].size =3D sizeof(compound->result_header); + args.out_args[0].value =3D &compound->result_header; + args.out_args[1].size =3D resp_buffer_size; + args.out_args[1].value =3D resp_payload; + + ret =3D fuse_simple_request(compound->fm, &args); + if (ret < 0) + goto out; + + actual_response_size =3D args.out_args[1].size; + + if (actual_response_size < sizeof(struct fuse_compound_out)) { + pr_info_ratelimited("FUSE: compound response too small (%zu bytes, minim= um %zu bytes)\n", + actual_response_size, + sizeof(struct fuse_compound_out)); + ret =3D -EINVAL; + goto out; + } + + ret =3D fuse_compound_parse_resp(compound, compound->result_header.count, + (char *)resp_payload, + actual_response_size); +out: + kvfree(resp_payload); +out_free_buffer: + kvfree(buffer); + return ret; +} diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 7f16049387d1..6dddbe2b027b 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1273,6 +1273,18 @@ static inline ssize_t fuse_simple_idmap_request(stru= ct mnt_idmap *idmap, int fuse_simple_background(struct fuse_mount *fm, struct fuse_args *args, gfp_t gfp_flags); =20 +/** + * Compound request API + */ +struct fuse_compound_req; +ssize_t fuse_compound_send(struct fuse_compound_req *compound); + +struct fuse_compound_req *fuse_compound_alloc(struct fuse_mount *fm, u32 f= lags); +int fuse_compound_add(struct fuse_compound_req *compound, + struct fuse_args *args); +int fuse_compound_get_error(struct fuse_compound_req *compound, int op_idx= ); +void fuse_compound_free(struct fuse_compound_req *compound); + /** * Assign a unique id to a fuse request */ diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index c13e1f9a2f12..4464f28c3242 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -664,6 +664,13 @@ enum fuse_opcode { FUSE_STATX =3D 52, FUSE_COPY_FILE_RANGE_64 =3D 53, =20 + /* A compound request is handled like a single request, + * but contains multiple requests as input. + * This can be used to signal to the fuse server that + * the requests can be combined atomically. + */ + FUSE_COMPOUND =3D 54, + /* CUSE specific operations */ CUSE_INIT =3D 4096, =20 @@ -1245,6 +1252,36 @@ struct fuse_supp_groups { uint32_t groups[]; }; =20 +#define FUSE_MAX_COMPOUND_OPS 16 /* Maximum operations per compou= nd */ + +/* + * Compound request header + * + * This header is followed by the fuse requests + */ +struct fuse_compound_in { + uint32_t count; /* Number of operations */ + uint32_t flags; /* Compound flags */ + + /* Total size of all results. + * This is needed for preallocating the whole result for all + * commands in this compound. + */ + uint32_t result_size; + uint64_t reserved; +}; + +/* + * Compound response header + * + * This header is followed by complete fuse responses + */ +struct fuse_compound_out { + uint32_t count; /* Number of results */ + uint32_t flags; /* Result flags */ + uint64_t reserved; +}; + /** * Size of the ring buffer header */ --=20 2.51.0 From nobody Sun Feb 8 18:08:51 2026 Received: from smtp01-ext2.udag.de (smtp01-ext2.udag.de [62.146.106.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73ED0368295; Fri, 9 Jan 2026 18:27:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.146.106.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767983240; cv=none; b=UBha72+Jcv2YPQHIh5bibT0pc3C8i41YZoOXPhIwgkZxYphZxpyZZI1l9uIKF57ZNsxek7azrQ6Pb8Wki6Gf2kWoEnwete2M+XcZu9Ou73ACiKmtYUHZezNiO2ugdWDEB87FEVekD4AAFmxtLJQRJJGCirs9VIqUDntp/11KuKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767983240; c=relaxed/simple; bh=9XfoZlR7RMZjQ1UPbGfMYcB3+CdY04U6bx6NDkzoIk8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mVzglZLRO9kEmvA2ZRmKsrrYA+HttZprd0/g1Hg8lEFSv2HFFLgvKrl3vQwpPOSWCRoFKiKruQ6FfbRRcug4YNZryw4net2KGAfaz/2FvHAHALjIzHrN4EUHXpA/tjk15n5gL/vCpaHb6xjQL/mbB3eSjW4vTT3HM1upmkEWHyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=birthelmer.com; spf=pass smtp.mailfrom=birthelmer.com; dkim=pass (2048-bit key) header.d=birthelmer.com header.i=@birthelmer.com header.b=eRX5T5zK; arc=none smtp.client-ip=62.146.106.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=birthelmer.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=birthelmer.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=birthelmer.com header.i=@birthelmer.com header.b="eRX5T5zK" Received: from [127.0.1.1] (049-102-000-128.ip-addr.inexio.net [128.0.102.49]) by smtp01-ext2.udag.de (Postfix) with ESMTPA id 049AEE0214; Fri, 9 Jan 2026 19:27:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=birthelmer.com; s=uddkim-202310; t=1767983229; h=from:from: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; bh=Cy8LGj4OUZMCQj7CBFMdH306bwkDHHxsxHmesfmRs/w=; b=eRX5T5zKfywyQWtEOr1+M6KTOm8YGCJtVhhyuoaEyp0FJORr8m4qIaHiE5yum58NT9gIsR pc7RJRBDemkzm4xlZhBmoF92zObMO3C6gmqYCSQSWDYc4iXP+UGCfiI72j86QQuHb4+V/X DGaeGwDVbj9KKniNqC8OunK1V9/aZniIiEfLYB/w70f7PwpxUvNvHH6rNaHTUuM7UG4KaG vl7T2zBOlio6aZcKdhpgbrhdxQfcqE83nVrpFkAf/2SdE8q725GCPCZoSCdLCV5fr1fNxm 4QhnIZh/TrRR+PkzYQPtd3zAeJMqLOSuV9r5tJYuJ59oF48tZDk/GllUcjRe9g== Authentication-Results: smtp01-ext2.udag.de; auth=pass smtp.auth=birthelmercom-0001 smtp.mailfrom=horst@birthelmer.com From: Horst Birthelmer Date: Fri, 09 Jan 2026 19:27:00 +0100 Subject: [PATCH v4 2/3] fuse: create helper functions for filling in fuse args for open and getattr Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260109-fuse-compounds-upstream-v4-2-0d3b82a4666f@ddn.com> References: <20260109-fuse-compounds-upstream-v4-0-0d3b82a4666f@ddn.com> In-Reply-To: <20260109-fuse-compounds-upstream-v4-0-0d3b82a4666f@ddn.com> To: Miklos Szeredi , Bernd Schubert , Joanne Koong Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Horst Birthelmer X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767983227; l=3897; i=hbirthelmer@ddn.com; s=20251006; h=from:subject:message-id; bh=HDrL8KiO1FuGwP0s1BR0III0doQji3syVR6q/bqPCRc=; b=QZ07sEbv6UkeR39qY+ehjLw6iOxlFQI0+X4RDH319Sovewf4NNsY9FfEZbwobzwcBJ8Ojk5/p 8OOH8Mn0OotDZt+R4R9rUerxKejsjMZeMPUbfpKZuLuU4wQMmnMBI2I X-Developer-Key: i=hbirthelmer@ddn.com; a=ed25519; pk=v3BVDFoy16EzgHZ23ObqW+kbpURtjrwxgKu8YNDKjGg= From: Horst Birthelmer create fuse_getattr_args_fill() and fuse_open_args_fill() to fill in the parameters for the open and getattr calls. This is in preparation for implementing open+getattr and does not represent any functional change. Signed-off-by: Horst Birthelmer --- fs/fuse/dir.c | 9 +-------- fs/fuse/file.c | 42 ++++++++++++++++++++++++++++++++++-------- fs/fuse/fuse_i.h | 8 ++++++++ 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 4b6b3d2758ff..ca8b69282c60 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1493,14 +1493,7 @@ static int fuse_do_getattr(struct mnt_idmap *idmap, = struct inode *inode, inarg.getattr_flags |=3D FUSE_GETATTR_FH; inarg.fh =3D ff->fh; } - args.opcode =3D FUSE_GETATTR; - args.nodeid =3D get_node_id(inode); - args.in_numargs =3D 1; - args.in_args[0].size =3D sizeof(inarg); - args.in_args[0].value =3D &inarg; - args.out_numargs =3D 1; - args.out_args[0].size =3D sizeof(outarg); - args.out_args[0].value =3D &outarg; + fuse_getattr_args_fill(&args, get_node_id(inode), &inarg, &outarg); err =3D fuse_simple_request(fm, &args); if (!err) { if (fuse_invalid_attr(&outarg.attr) || diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 01bc894e9c2b..53744559455d 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -23,6 +23,39 @@ #include #include =20 +/* + * Helper function to initialize fuse_args for OPEN/OPENDIR operations + */ +void fuse_open_args_fill(struct fuse_args *args, u64 nodeid, int opcode, + struct fuse_open_in *inarg, struct fuse_open_out *outarg) +{ + args->opcode =3D opcode; + args->nodeid =3D nodeid; + args->in_numargs =3D 1; + args->in_args[0].size =3D sizeof(*inarg); + args->in_args[0].value =3D inarg; + args->out_numargs =3D 1; + args->out_args[0].size =3D sizeof(*outarg); + args->out_args[0].value =3D outarg; +} + +/* + * Helper function to initialize fuse_args for GETATTR operations + */ +void fuse_getattr_args_fill(struct fuse_args *args, u64 nodeid, + struct fuse_getattr_in *inarg, + struct fuse_attr_out *outarg) +{ + args->opcode =3D FUSE_GETATTR; + args->nodeid =3D nodeid; + args->in_numargs =3D 1; + args->in_args[0].size =3D sizeof(*inarg); + args->in_args[0].value =3D inarg; + args->out_numargs =3D 1; + args->out_args[0].size =3D sizeof(*outarg); + args->out_args[0].value =3D outarg; +} + static int fuse_send_open(struct fuse_mount *fm, u64 nodeid, unsigned int open_flags, int opcode, struct fuse_open_out *outargp) @@ -40,14 +73,7 @@ static int fuse_send_open(struct fuse_mount *fm, u64 nod= eid, inarg.open_flags |=3D FUSE_OPEN_KILL_SUIDGID; } =20 - args.opcode =3D opcode; - args.nodeid =3D nodeid; - args.in_numargs =3D 1; - args.in_args[0].size =3D sizeof(inarg); - args.in_args[0].value =3D &inarg; - args.out_numargs =3D 1; - args.out_args[0].size =3D sizeof(*outargp); - args.out_args[0].value =3D outargp; + fuse_open_args_fill(&args, nodeid, opcode, &inarg, outargp); =20 return fuse_simple_request(fm, &args); } diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 6dddbe2b027b..98ea41f76623 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1179,6 +1179,14 @@ struct fuse_io_args { void fuse_read_args_fill(struct fuse_io_args *ia, struct file *file, loff_= t pos, size_t count, int opcode); =20 +/* + * Helper functions to initialize fuse_args for common operations + */ +void fuse_open_args_fill(struct fuse_args *args, u64 nodeid, int opcode, + struct fuse_open_in *inarg, struct fuse_open_out *outarg); +void fuse_getattr_args_fill(struct fuse_args *args, u64 nodeid, + struct fuse_getattr_in *inarg, + struct fuse_attr_out *outarg); =20 struct fuse_file *fuse_file_alloc(struct fuse_mount *fm, bool release); void fuse_file_free(struct fuse_file *ff); --=20 2.51.0 From nobody Sun Feb 8 18:08:51 2026 Received: from smtp01-ext2.udag.de (smtp01-ext2.udag.de [62.146.106.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 73E20368293; Fri, 9 Jan 2026 18:27:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.146.106.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767983241; cv=none; b=KcQNSPNaPBayztSL0BFls4uGuSUg4aHxfz6mT6OIM7rPSj7sIpVc09103BLlBhAtnw9QcbAWpivPCwALPLaPmYI2vsBnO8YVklC4RatNRRe2p54Erj7dwu1eZUJr0D/uVetGjMVKM9U3fW06iWzw3qNnLV/zpwCxKpE6JUliDFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767983241; c=relaxed/simple; bh=BdfhQjAzF93Ljq+YaEpMJp4FRx79yzMRea+PO4tcf7Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C93tXW0c7iXOFLpuHzL06b/lXEpY6KTi2PVpSmuuPByieE3JBSaVeEBt7snqvtnlvqyEpF8edaSH7Q3eSFX2kfvj97VhAq50giuxfftecsZkvmsydzYQZ7Jpfax81CeaRr/hCTpx7ME5K8pzxbRtzmplmTw9lxVInLj9Fp/Gyps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=birthelmer.com; spf=pass smtp.mailfrom=birthelmer.com; dkim=pass (2048-bit key) header.d=birthelmer.com header.i=@birthelmer.com header.b=qUvQ5Ld1; arc=none smtp.client-ip=62.146.106.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=birthelmer.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=birthelmer.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=birthelmer.com header.i=@birthelmer.com header.b="qUvQ5Ld1" Received: from [127.0.1.1] (049-102-000-128.ip-addr.inexio.net [128.0.102.49]) by smtp01-ext2.udag.de (Postfix) with ESMTPA id 8721EE0215; Fri, 9 Jan 2026 19:27:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=birthelmer.com; s=uddkim-202310; t=1767983229; h=from:from: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; bh=001lqfZyaF5rz5UgMb2uv/QEnMbybV2OKoAuJetIMJA=; b=qUvQ5Ld11XCzfACxlC3NNZU7UsbOLhjARuAiIb63JbWUB12b321CThEWPAyt/2SWhuM+lq XlNStosh2nLhb2INCj+lt3jG+kTPfJulBkbPUOuJy/W8xVoqqFtMpxJfsXfzCpGsaDnU+g 8k4yG7uydesyzc8i8vOOttNHBXDLPIrf6Y5TooxSy+GUEeqKGeTH35rwjMFYl3WKkkPJlV E2nOkrx0NziLjI1LqwwK7hvOE+J+0IUSR9oNqILG8+K5GKsBsE+hYkS8qYy+k1lp2krHTK p19phQ5o1XUddhjXW5nfoptAFBoZc3iJf9KJCijEKB0lqe1BBf54DkN2VqRwsw== Authentication-Results: smtp01-ext2.udag.de; auth=pass smtp.auth=birthelmercom-0001 smtp.mailfrom=horst@birthelmer.com From: Horst Birthelmer Date: Fri, 09 Jan 2026 19:27:01 +0100 Subject: [PATCH v4 3/3] fuse: add an implementation of open+getattr Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260109-fuse-compounds-upstream-v4-3-0d3b82a4666f@ddn.com> References: <20260109-fuse-compounds-upstream-v4-0-0d3b82a4666f@ddn.com> In-Reply-To: <20260109-fuse-compounds-upstream-v4-0-0d3b82a4666f@ddn.com> To: Miklos Szeredi , Bernd Schubert , Joanne Koong Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Horst Birthelmer X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767983227; l=6485; i=hbirthelmer@ddn.com; s=20251006; h=from:subject:message-id; bh=dDxgmzy2WLXTQBLLyekP0mUPMBrqJXIWFWxigRtE+ZY=; b=3/Ti6uOLRUQ3OJRf35e6ujLlGHHTVrxTtAMIm/tFaIIFW+mzN5H2ImX0MlsI3Jf4tpPxi/Ere Q5fOUFJbdHQDAvN8VU37jo5etoD8MeSW3YTEHRMylCLesPJaqj/yE6m X-Developer-Key: i=hbirthelmer@ddn.com; a=ed25519; pk=v3BVDFoy16EzgHZ23ObqW+kbpURtjrwxgKu8YNDKjGg= From: Horst Birthelmer The discussion about compound commands in fuse was started over an argument to add a new operation that will open a file and return its attributes in the same operation. Here is a demonstration of that use case with compound commands. Signed-off-by: Horst Birthelmer --- fs/fuse/file.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++----= ---- fs/fuse/fuse_i.h | 7 +++- fs/fuse/inode.c | 6 +++ fs/fuse/ioctl.c | 2 +- 4 files changed, 107 insertions(+), 18 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 53744559455d..c0375b32967d 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -152,8 +152,66 @@ static void fuse_file_put(struct fuse_file *ff, bool s= ync) } } =20 +static int fuse_compound_open_getattr(struct fuse_mount *fm, u64 nodeid, + int flags, int opcode, + struct fuse_file *ff, + struct fuse_attr_out *outattrp, + struct fuse_open_out *outopenp) +{ + struct fuse_compound_req *compound; + struct fuse_args open_args =3D {}; + struct fuse_args getattr_args =3D {}; + struct fuse_open_in open_in =3D {}; + struct fuse_getattr_in getattr_in =3D {}; + int err; + + compound =3D fuse_compound_alloc(fm, 0); + if (IS_ERR(compound)) + return PTR_ERR(compound); + + open_in.flags =3D flags & ~(O_CREAT | O_EXCL | O_NOCTTY); + if (!fm->fc->atomic_o_trunc) + open_in.flags &=3D ~O_TRUNC; + + if (fm->fc->handle_killpriv_v2 && + (open_in.flags & O_TRUNC) && !capable(CAP_FSETID)) + open_in.open_flags |=3D FUSE_OPEN_KILL_SUIDGID; + + fuse_open_args_fill(&open_args, nodeid, opcode, &open_in, outopenp); + + err =3D fuse_compound_add(compound, &open_args); + if (err) + goto out; + + fuse_getattr_args_fill(&getattr_args, nodeid, &getattr_in, outattrp); + + err =3D fuse_compound_add(compound, &getattr_args); + if (err) + goto out; + + err =3D fuse_compound_send(compound); + if (err) + goto out; + + err =3D fuse_compound_get_error(compound, 0); + if (err) + goto out; + + err =3D fuse_compound_get_error(compound, 1); + if (err) + goto out; + + ff->fh =3D outopenp->fh; + ff->open_flags =3D outopenp->open_flags; + +out: + fuse_compound_free(compound); + return err; +} + struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid, - unsigned int open_flags, bool isdir) + struct inode *inode, + unsigned int open_flags, bool isdir) { struct fuse_conn *fc =3D fm->fc; struct fuse_file *ff; @@ -179,23 +237,44 @@ struct fuse_file *fuse_file_open(struct fuse_mount *f= m, u64 nodeid, if (open) { /* Store outarg for fuse_finish_open() */ struct fuse_open_out *outargp =3D &ff->args->open_outarg; - int err; + int err =3D -ENOSYS; + + if (inode && fc->compound_open_getattr) { + struct fuse_attr_out attr_outarg; + + err =3D fuse_compound_open_getattr(fm, nodeid, open_flags, + opcode, ff, + &attr_outarg, outargp); + if (!err) + fuse_change_attributes(inode, &attr_outarg.attr, + NULL, + ATTR_TIMEOUT(&attr_outarg), + fuse_get_attr_version(fc)); + } + if (err =3D=3D -ENOSYS) { + err =3D fuse_send_open(fm, nodeid, open_flags, opcode, + outargp); + if (!err) { + ff->fh =3D outargp->fh; + ff->open_flags =3D outargp->open_flags; + } + } =20 - err =3D fuse_send_open(fm, nodeid, open_flags, opcode, outargp); - if (!err) { - ff->fh =3D outargp->fh; - ff->open_flags =3D outargp->open_flags; - } else if (err !=3D -ENOSYS) { - fuse_file_free(ff); - return ERR_PTR(err); - } else { - if (isdir) { + if (err) { + if (err !=3D -ENOSYS) { + /* err is not ENOSYS */ + fuse_file_free(ff); + return ERR_PTR(err); + } else { /* No release needed */ kfree(ff->args); ff->args =3D NULL; - fc->no_opendir =3D 1; - } else { - fc->no_open =3D 1; + + /* we don't have open */ + if (isdir) + fc->no_opendir =3D 1; + else + fc->no_open =3D 1; } } } @@ -211,11 +290,10 @@ struct fuse_file *fuse_file_open(struct fuse_mount *f= m, u64 nodeid, int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file, bool isdir) { - struct fuse_file *ff =3D fuse_file_open(fm, nodeid, file->f_flags, isdir); + struct fuse_file *ff =3D fuse_file_open(fm, nodeid, file_inode(file), fil= e->f_flags, isdir); =20 if (!IS_ERR(ff)) file->private_data =3D ff; - return PTR_ERR_OR_ZERO(ff); } EXPORT_SYMBOL_GPL(fuse_do_open); diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 98ea41f76623..e7828405e262 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -924,6 +924,9 @@ struct fuse_conn { /* Use io_uring for communication */ unsigned int io_uring; =20 + /* Does the filesystem support compound operations? */ + unsigned int compound_open_getattr:1; + /** Maximum stack depth for passthrough backing files */ int max_stack_depth; =20 @@ -1563,7 +1566,9 @@ void fuse_file_io_release(struct fuse_file *ff, struc= t inode *inode); =20 /* file.c */ struct fuse_file *fuse_file_open(struct fuse_mount *fm, u64 nodeid, - unsigned int open_flags, bool isdir); + struct inode *inode, + unsigned int open_flags, + bool isdir); void fuse_file_release(struct inode *inode, struct fuse_file *ff, unsigned int open_flags, fl_owner_t id, bool isdir); =20 diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index 819e50d66622..a5fd721be96d 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -991,6 +991,12 @@ void fuse_conn_init(struct fuse_conn *fc, struct fuse_= mount *fm, fc->blocked =3D 0; fc->initialized =3D 0; fc->connected =3D 1; + + /* pretend fuse server supports compound operations + * until it tells us otherwise. + */ + fc->compound_open_getattr =3D 1; + atomic64_set(&fc->attr_version, 1); atomic64_set(&fc->evict_ctr, 1); get_random_bytes(&fc->scramble_key, sizeof(fc->scramble_key)); diff --git a/fs/fuse/ioctl.c b/fs/fuse/ioctl.c index fdc175e93f74..07a02e47b2c3 100644 --- a/fs/fuse/ioctl.c +++ b/fs/fuse/ioctl.c @@ -494,7 +494,7 @@ static struct fuse_file *fuse_priv_ioctl_prepare(struct= inode *inode) if (!S_ISREG(inode->i_mode) && !isdir) return ERR_PTR(-ENOTTY); =20 - return fuse_file_open(fm, get_node_id(inode), O_RDONLY, isdir); + return fuse_file_open(fm, get_node_id(inode), NULL, O_RDONLY, isdir); } =20 static void fuse_priv_ioctl_cleanup(struct inode *inode, struct fuse_file = *ff) --=20 2.51.0