From nobody Wed Feb 11 23:44:00 2026 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CEFB4F896 for ; Fri, 29 Mar 2024 01:54:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711677281; cv=none; b=itTJ0tEeQ7cYE1LIv7eOMojsXRcZ91mG/rgK1WvmY6w158QUi4zACWadK85hP/THFm8vbsi4rzyl2OKUPpF++Hlqt8XSA3VYfXielGwYjFavEBNS+sGhu3tIlxuTX6kGH8YLzqHN5nWfTbRXK5Y4aetXkU/LQPytRgwKjH2GU1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711677281; c=relaxed/simple; bh=VDSeOrmRZ4SYUgVp5dmLfIcaprrVde6t7qHG+s7E0hM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OzNqwlgxQZPavdlgh9bRTFr1m6kKvAKa6f6StvO22qgv6GklVb3SQ1Wj0aqDxOGCJuCSxWQY37UyHpB8DnOf6lXCAQVbMDUlH2LAX/0Nc9Xd2pR+dUDn2V6vArO9fTIoWF3zS1kSQY1Oo+ncpIF6qAsOLNwurQ6ZRgumrn7Z+eE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--drosen.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xjNF1C5Y; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--drosen.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xjNF1C5Y" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dcbfe1a42a4so2835665276.2 for ; Thu, 28 Mar 2024 18:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711677279; x=1712282079; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=MD93gZe61lT3bi7JodQUSrve0t6PielHvOmvulo6VTY=; b=xjNF1C5YPXePjkco0M80fBcxpb+MmIATViMfO03Q2/jEL8D8O3Ju61ojnbD8Jfr1pk /LquOyMrFOhHEg18gs6Al6S4a2ejuGaNnU5mQxKsMJzU6MVp4tJ67ILdanewwzlhhsoW EKh1hm4/ZTbt8cS8r0Od4xMG3Blkz5LmD+24ErHVbHVp/iqaP8JFSsjSxzAJ+4e9ABwB dAzeUcDsS3xvgQHr2lQuW7lYqDHnSJ6K0ViojESwwR+W1wSGsxlwjeh1V+HDz92oTHsG 1YIOHPmlXzZSiQL+P5XaG/XOxAVBUoRGUy7KI+SmW/k70Rcb6232G0ixdQiyNB2lY5aG 2VQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711677279; x=1712282079; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MD93gZe61lT3bi7JodQUSrve0t6PielHvOmvulo6VTY=; b=RfmQGxyqqcBcC7BI1Ygijz0IY3vhhaKHUKbZG327Y2HcbCStMoFpdkWuR+XlGkOmb+ AQ46yBt+MwoRHOte+fBTP3O/rOwsxEPT/BwUnbTK65SZr11mV7LExq/uLN2j2iDLpQuC kiwMLyU056/DGN+yhtaV+vqo59LK7o6lNWIlQ0dx45voq3rIpZa6OOTDJ1CanEKz08q/ 5PsOfE2Hkmjh7NWY4XbIT3V+5yavMs1V773Nmla3alyQ0U7vZw52bUIL59a6zRzzT0Ft +COs8C9ra0cSALl5f9MNTfcdCJBVF58VSWlsNZHYI8Ak+G0fmrsVq9dHcJGzuktlfZOC wwUw== X-Forwarded-Encrypted: i=1; AJvYcCVfNxGhfb3hwcRW1BuvWUxHspyccBxwm9U+jKLj16DJZjGd/xkan8kp041n8UrAR6f/RS3h1GeoRUMXKFvBFJgHHrXBYeRkLRxlCfMa X-Gm-Message-State: AOJu0YwjUXujJ8b3L/mSo2REhsOSfwctBZCfH4ea6TN/LJrmzEwHNJXV 6TaWicSC7fEvf4s8kA3fdAJCbVtp74EJ2tq7KPJoCz16D8nE+f4QIRNrhgT3ouQIWwsQtmhxmon G1g== X-Google-Smtp-Source: AGHT+IGhQUHEXr/GrzTbtSCdL1hqHgZVQAU0Jz8rAd+h7Sr956bHJaSbQ8HK4gIpji8SRFQsstttWqHj/A8= X-Received: from drosen.mtv.corp.google.com ([2620:15c:211:201:fcce:d6ab:804c:b94b]) (user=drosen job=sendgmr) by 2002:a05:6902:1884:b0:dc6:cafd:dce5 with SMTP id cj4-20020a056902188400b00dc6cafddce5mr296080ybb.12.1711677279199; Thu, 28 Mar 2024 18:54:39 -0700 (PDT) Date: Thu, 28 Mar 2024 18:53:33 -0700 In-Reply-To: <20240329015351.624249-1-drosen@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240329015351.624249-1-drosen@google.com> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240329015351.624249-19-drosen@google.com> Subject: [RFC PATCH v4 18/36] fuse-bpf: Add support for FUSE_COPY_FILE_RANGE From: Daniel Rosenberg To: Miklos Szeredi , bpf@vger.kernel.org, Alexei Starovoitov Cc: Amir Goldstein , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-unionfs@vger.kernel.org, Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Eduard Zingerman , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , Christian Brauner , kernel-team@android.com, Daniel Rosenberg , Paul Lawrence Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This adds backing support for FUSE_COPY_FILE_RANGE Signed-off-by: Daniel Rosenberg Signed-off-by: Paul Lawrence --- fs/fuse/backing.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++ fs/fuse/file.c | 4 +++ fs/fuse/fuse_i.h | 10 ++++++ 3 files changed, 101 insertions(+) diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c index e426268aa4e6..2363f392e915 100644 --- a/fs/fuse/backing.c +++ b/fs/fuse/backing.c @@ -11,6 +11,7 @@ #include #include #include +#include #include =20 /* @@ -778,6 +779,92 @@ int fuse_bpf_lseek(loff_t *out, struct inode *inode, s= truct file *file, loff_t o file, offset, whence); } =20 +struct fuse_copy_file_range_args { + struct fuse_copy_file_range_in in; + struct fuse_write_out out; +}; + +static int fuse_copy_file_range_initialize_in(struct bpf_fuse_args *fa, + struct fuse_copy_file_range_args *args, + struct file *file_in, loff_t pos_in, struct file *file_out, + loff_t pos_out, size_t len, unsigned int flags) +{ + struct fuse_file *fuse_file_in =3D file_in->private_data; + struct fuse_file *fuse_file_out =3D file_out->private_data; + + args->in =3D (struct fuse_copy_file_range_in) { + .fh_in =3D fuse_file_in->fh, + .off_in =3D pos_in, + .nodeid_out =3D fuse_file_out->nodeid, + .fh_out =3D fuse_file_out->fh, + .off_out =3D pos_out, + .len =3D len, + .flags =3D flags, + }; + + *fa =3D (struct bpf_fuse_args) { + .info =3D (struct bpf_fuse_meta_info) { + .nodeid =3D get_node_id(file_in->f_inode), + .opcode =3D FUSE_COPY_FILE_RANGE, + }, + .in_numargs =3D 1, + .in_args[0].size =3D sizeof(args->in), + .in_args[0].value =3D &args->in, + }; + + return 0; +} + +static int fuse_copy_file_range_initialize_out(struct bpf_fuse_args *fa, + struct fuse_copy_file_range_args *args, + struct file *file_in, loff_t pos_in, struct file *file_out, + loff_t pos_out, size_t len, unsigned int flags) +{ + fa->out_numargs =3D 1; + fa->out_args[0].size =3D sizeof(args->out); + fa->out_args[0].value =3D &args->out; + + return 0; +} + +static int fuse_copy_file_range_backing(struct bpf_fuse_args *fa, ssize_t = *out, struct file *file_in, + loff_t pos_in, struct file *file_out, loff_t pos_out, size_t len, + unsigned int flags) +{ + const struct fuse_copy_file_range_in *fci =3D fa->in_args[0].value; + struct fuse_file *fuse_file_in =3D file_in->private_data; + struct file *backing_file_in =3D fuse_file_in->backing_file; + struct fuse_file *fuse_file_out =3D file_out->private_data; + struct file *backing_file_out =3D fuse_file_out->backing_file; + + /* TODO: Handle changing of in/out files */ + if (backing_file_out) + *out =3D vfs_copy_file_range(backing_file_in, fci->off_in, backing_file_= out, + fci->off_out, fci->len, fci->flags); + else + *out =3D splice_copy_file_range(file_in, pos_in, file_out, pos_out, len); + return 0; +} + +static int fuse_copy_file_range_finalize(struct bpf_fuse_args *fa, ssize_t= *out, struct file *file_in, + loff_t pos_in, struct file *file_out, loff_t pos_out, size_t len, + unsigned int flags) +{ + return 0; +} + +int fuse_bpf_copy_file_range(ssize_t *out, struct inode *inode, struct fil= e *file_in, + loff_t pos_in, struct file *file_out, loff_t pos_out, size_t len, + unsigned int flags) +{ + return bpf_fuse_backing(inode, struct fuse_copy_file_range_args, out, + fuse_copy_file_range_initialize_in, + fuse_copy_file_range_initialize_out, + fuse_copy_file_range_backing, + fuse_copy_file_range_finalize, + file_in, pos_in, file_out, pos_out, len, flags); +} + static int fuse_fsync_initialize_in(struct bpf_fuse_args *fa, struct fuse_= fsync_in *in, struct file *file, loff_t start, loff_t end, int datasync) { diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 5983faf59c1f..46de67810f03 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -3168,6 +3168,10 @@ static ssize_t __fuse_copy_file_range(struct file *f= ile_in, loff_t pos_in, bool is_unstable =3D (!fc->writeback_cache) && ((pos_out + len) > inode_out->i_size); =20 + if (fuse_bpf_copy_file_range(&err, file_inode(file_in), file_in, pos_in, + file_out, pos_out, len, flags)) + return err; + if (fc->no_copy_file_range) return -EOPNOTSUPP; =20 diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 61a17071ab02..a95d543c79ae 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1454,6 +1454,9 @@ int fuse_bpf_release(int *out, struct inode *inode, s= truct fuse_file *ff); int fuse_bpf_releasedir(int *out, struct inode *inode, struct fuse_file *f= f); int fuse_bpf_flush(int *out, struct inode *inode, struct file *file, fl_ow= ner_t id); int fuse_bpf_lseek(loff_t *out, struct inode *inode, struct file *file, lo= ff_t offset, int whence); +int fuse_bpf_copy_file_range(ssize_t *out, struct inode *inode, struct fil= e *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t len, unsigned int flags); int fuse_bpf_fsync(int *out, struct inode *inode, struct file *file, loff_= t start, loff_t end, int datasync); int fuse_bpf_dir_fsync(int *out, struct inode *inode, struct file *file, l= off_t start, loff_t end, int datasync); int fuse_bpf_file_read_iter(ssize_t *out, struct inode *inode, struct kioc= b *iocb, struct iov_iter *to); @@ -1533,6 +1536,13 @@ static inline int fuse_bpf_lseek(loff_t *out, struct= inode *inode, struct file * return 0; } =20 +static inline int fuse_bpf_copy_file_range(ssize_t *out, struct inode *ino= de, struct file *file_in, loff_t pos_in, + struct file *file_out, loff_t pos_out, + size_t len, unsigned int flags) +{ + return 0; +} + static inline int fuse_bpf_fsync(int *out, struct inode *inode, struct fil= e *file, loff_t start, loff_t end, int datasync) { return 0; --=20 2.44.0.478.gd926399ef9-goog