Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fuser/fork rebase 01 #1273

Closed
wants to merge 12 commits into from
50 changes: 41 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,29 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Cache
id: rust-cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.rustup/toolchains/
target/
key: ${{ runner.os }}-cargo-compile-v1-${{ matrix.libfuse }}-${{ matrix.features }}-${{ hashFiles('**/Cargo.toml', '.github/workflows/*.yml') }}

- name: Install packages
run: |
sudo apt update
sudo apt install -y ${{ matrix.libfuse }} build-essential

- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: x86_64-unknown-linux-musl
- name: Install Rust
if: steps.rust-cache.outputs.cache-hit != 'true'
run: |
rustup target add x86_64-unknown-linux-musl

- name: Run tests
run: |
Expand All @@ -36,18 +51,35 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Cache
id: rust-cache
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
~/.rustup/toolchains/
target/
key: ${{ runner.os }}-cargo-ci-v1-${{ hashFiles('**/Cargo.toml', '.github/workflows/*.yml') }}

- name: Install packages
run: |
sudo apt update
sudo apt install -y libfuse-dev libfuse3-dev build-essential

- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt, clippy
- name: Install Rust
if: steps.rust-cache.outputs.cache-hit != 'true'
run: |
rustup toolchain install 1.81
rustup component add rustfmt
rustup component add clippy

- uses: taiki-e/install-action@v2
with:
tool: cargo[email protected]
- name: Install cargo-deny
if: steps.rust-cache.outputs.cache-hit != 'true'
run: cargo +1.81 install --force --version 0.16.2 cargo-deny --locked

- name: Run tests
run: INTERACTIVE="" make pre
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# FUSE for Rust - Changelog

## 0.15.1 - 2024-11-27
* Fix crtime related panic that could occur on MacOS. See PR #322 for details.

## 0.15.0 - 2024-10-25
* Add file handle argument to `getattr()`
* Change `poll()` to take a `PollHandle` instead of a `u64`
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ license = "MIT"
repository = "https://github.com/cberner/fuser"
documentation = "https://docs.rs/fuser"
homepage = "https://github.com/cberner/fuser"
version = "0.15.0"
version = "0.15.1"
edition = "2021"
readme = "README.md"
authors = ["Christopher Berner <[email protected]>"]
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
## Fork of fuser for Mountpoint

This is a fork of the excellent [`fuser`](https://github.com/cberner/fuser) Rust crate for FUSE bindings, with some Mountpoint-specific changes to improve performance of concurrent operations. We'll be working to upstream these changes soon.

### Fork Maintenance

This fork should be maintained in the `fuser/fork` branch of the [awslabs/mountpoint-s3 repository on GitHub](https://github.com/awslabs/mountpoint-s3/tree/main/vendor/fuser).

To pull in new changes from upstream, you should fetch and rebase the changes locally and then force push to the `fuser/fork` branch (- not ideal!).
Once the `fuser/fork` branch is as desired, create a new branch from Mountpoint's `main` branch.
Run the [`vendor-fuser.sh` script](https://github.com/awslabs/mountpoint-s3/blob/main/vendor-fuser.sh).
You should open a pull request with the new commit created by the script.
This pull request is where the changes are reviewed.

If you wish to add new divergent changes to this fork of Fuser,
open a pull request on the Mountpoint repository branching from the `fuser/fork` branch and use `fuser/fork` as the base branch when creating the pull request.

---

# FUSE (Filesystem in Userspace) for Rust

![CI](https://github.com/cberner/fuser/actions/workflows/ci.yml/badge.svg)
Expand Down
8 changes: 4 additions & 4 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ const HELLO_TXT_ATTR: FileAttr = FileAttr {
struct HelloFS;

impl Filesystem for HelloFS {
fn lookup(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) {
fn lookup(&self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) {
if parent == 1 && name.to_str() == Some("hello.txt") {
reply.entry(&TTL, &HELLO_TXT_ATTR, 0);
} else {
reply.error(ENOENT);
}
}

fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
fn getattr(&self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
match ino {
1 => reply.attr(&TTL, &HELLO_DIR_ATTR),
2 => reply.attr(&TTL, &HELLO_TXT_ATTR),
Expand All @@ -67,7 +67,7 @@ impl Filesystem for HelloFS {
}

fn read(
&mut self,
&self,
_req: &Request,
ino: u64,
_fh: u64,
Expand All @@ -85,7 +85,7 @@ impl Filesystem for HelloFS {
}

fn readdir(
&mut self,
&self,
_req: &Request,
ino: u64,
_fh: u64,
Expand Down
22 changes: 12 additions & 10 deletions examples/ioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ use fuser::{
use libc::{EINVAL, ENOENT};
use log::debug;
use std::ffi::OsStr;
use std::sync::Mutex;
use std::time::{Duration, UNIX_EPOCH};

const TTL: Duration = Duration::from_secs(1); // 1 second

struct FiocFS {
content: Vec<u8>,
content: Mutex<Vec<u8>>,
root_attr: FileAttr,
fioc_file_attr: FileAttr,
}
Expand Down Expand Up @@ -62,23 +63,23 @@ impl FiocFS {
};

Self {
content: vec![],
content: vec![].into(),
root_attr,
fioc_file_attr,
}
}
}

impl Filesystem for FiocFS {
fn lookup(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) {
fn lookup(&self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) {
if parent == 1 && name.to_str() == Some("fioc") {
reply.entry(&TTL, &self.fioc_file_attr, 0);
} else {
reply.error(ENOENT);
}
}

fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
fn getattr(&self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
match ino {
1 => reply.attr(&TTL, &self.root_attr),
2 => reply.attr(&TTL, &self.fioc_file_attr),
Expand All @@ -87,7 +88,7 @@ impl Filesystem for FiocFS {
}

fn read(
&mut self,
&self,
_req: &Request,
ino: u64,
_fh: u64,
Expand All @@ -98,14 +99,15 @@ impl Filesystem for FiocFS {
reply: ReplyData,
) {
if ino == 2 {
reply.data(&self.content[offset as usize..])
let content = self.content.lock().unwrap();
reply.data(&content[offset as usize..])
} else {
reply.error(ENOENT);
}
}

fn readdir(
&mut self,
&self,
_req: &Request,
ino: u64,
_fh: u64,
Expand Down Expand Up @@ -133,7 +135,7 @@ impl Filesystem for FiocFS {
}

fn ioctl(
&mut self,
&self,
_req: &Request<'_>,
ino: u64,
_fh: u64,
Expand All @@ -153,12 +155,12 @@ impl Filesystem for FiocFS {

match cmd.into() {
FIOC_GET_SIZE => {
let size_bytes = self.content.len().to_ne_bytes();
let size_bytes = self.content.lock().unwrap().len().to_ne_bytes();
reply.ioctl(0, &size_bytes);
}
FIOC_SET_SIZE => {
let new_size = usize::from_ne_bytes(in_data.try_into().unwrap());
self.content = vec![0_u8; new_size];
*self.content.lock().unwrap() = vec![0_u8; new_size];
reply.ioctl(0, &[]);
}
_ => {
Expand Down
8 changes: 4 additions & 4 deletions examples/notify_inval_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a> ClockFS<'a> {
}

impl<'a> Filesystem for ClockFS<'a> {
fn lookup(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) {
fn lookup(&self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) {
if parent != FUSE_ROOT_ID || name != AsRef::<OsStr>::as_ref(&self.get_filename()) {
reply.error(ENOENT);
return;
Expand All @@ -78,7 +78,7 @@ impl<'a> Filesystem for ClockFS<'a> {
reply.entry(&self.timeout, &ClockFS::stat(ClockFS::FILE_INO).unwrap(), 0);
}

fn forget(&mut self, _req: &Request, ino: u64, nlookup: u64) {
fn forget(&self, _req: &Request, ino: u64, nlookup: u64) {
if ino == ClockFS::FILE_INO {
let prev = self.lookup_cnt.fetch_sub(nlookup, SeqCst);
assert!(prev >= nlookup);
Expand All @@ -87,15 +87,15 @@ impl<'a> Filesystem for ClockFS<'a> {
}
}

fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
fn getattr(&self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
match ClockFS::stat(ino) {
Some(a) => reply.attr(&self.timeout, &a),
None => reply.error(ENOENT),
}
}

fn readdir(
&mut self,
&self,
_req: &Request,
ino: u64,
_fh: u64,
Expand Down
12 changes: 6 additions & 6 deletions examples/notify_inval_inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<'a> ClockFS<'a> {
}

impl<'a> Filesystem for ClockFS<'a> {
fn lookup(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) {
fn lookup(&self, _req: &Request, parent: u64, name: &OsStr, reply: ReplyEntry) {
if parent != FUSE_ROOT_ID || name != AsRef::<OsStr>::as_ref(&Self::FILE_NAME) {
reply.error(ENOENT);
return;
Expand All @@ -77,7 +77,7 @@ impl<'a> Filesystem for ClockFS<'a> {
reply.entry(&Duration::MAX, &self.stat(ClockFS::FILE_INO).unwrap(), 0);
}

fn forget(&mut self, _req: &Request, ino: u64, nlookup: u64) {
fn forget(&self, _req: &Request, ino: u64, nlookup: u64) {
if ino == ClockFS::FILE_INO {
let prev = self.lookup_cnt.fetch_sub(nlookup, SeqCst);
assert!(prev >= nlookup);
Expand All @@ -86,15 +86,15 @@ impl<'a> Filesystem for ClockFS<'a> {
}
}

fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
fn getattr(&self, _req: &Request, ino: u64, _fh: Option<u64>, reply: ReplyAttr) {
match self.stat(ino) {
Some(a) => reply.attr(&Duration::MAX, &a),
None => reply.error(ENOENT),
}
}

fn readdir(
&mut self,
&self,
_req: &Request,
ino: u64,
_fh: u64,
Expand All @@ -120,7 +120,7 @@ impl<'a> Filesystem for ClockFS<'a> {
}
}

fn open(&mut self, _req: &Request, ino: u64, flags: i32, reply: ReplyOpen) {
fn open(&self, _req: &Request, ino: u64, flags: i32, reply: ReplyOpen) {
if ino == FUSE_ROOT_ID {
reply.error(EISDIR);
} else if flags & libc::O_ACCMODE != libc::O_RDONLY {
Expand All @@ -134,7 +134,7 @@ impl<'a> Filesystem for ClockFS<'a> {
}

fn read(
&mut self,
&self,
_req: &Request,
ino: u64,
_fh: u64,
Expand Down
14 changes: 7 additions & 7 deletions examples/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl FSelFS {
}

impl fuser::Filesystem for FSelFS {
fn lookup(&mut self, _req: &Request, parent: u64, name: &OsStr, reply: fuser::ReplyEntry) {
fn lookup(&self, _req: &Request, parent: u64, name: &OsStr, reply: fuser::ReplyEntry) {
if parent != FUSE_ROOT_ID || name.len() != 1 {
reply.error(ENOENT);
return;
Expand All @@ -101,7 +101,7 @@ impl fuser::Filesystem for FSelFS {
reply.entry(&Duration::ZERO, &self.get_data().filestat(idx), 0);
}

fn getattr(&mut self, _req: &Request, ino: u64, _fh: Option<u64>, reply: fuser::ReplyAttr) {
fn getattr(&self, _req: &Request, ino: u64, _fh: Option<u64>, reply: fuser::ReplyAttr) {
if ino == FUSE_ROOT_ID {
let a = FileAttr {
ino: FUSE_ROOT_ID,
Expand Down Expand Up @@ -132,7 +132,7 @@ impl fuser::Filesystem for FSelFS {
}

fn readdir(
&mut self,
&self,
_req: &Request,
ino: u64,
_fh: u64,
Expand Down Expand Up @@ -169,7 +169,7 @@ impl fuser::Filesystem for FSelFS {
reply.ok();
}

fn open(&mut self, _req: &Request, ino: u64, flags: i32, reply: fuser::ReplyOpen) {
fn open(&self, _req: &Request, ino: u64, flags: i32, reply: fuser::ReplyOpen) {
let idx = FSelData::ino_to_idx(ino);
if idx >= NUMFILES {
reply.error(ENOENT);
Expand All @@ -196,7 +196,7 @@ impl fuser::Filesystem for FSelFS {
}

fn release(
&mut self,
&self,
_req: &Request,
_ino: u64,
fh: u64,
Expand All @@ -215,7 +215,7 @@ impl fuser::Filesystem for FSelFS {
}

fn read(
&mut self,
&self,
_req: &Request,
_ino: u64,
fh: u64,
Expand Down Expand Up @@ -247,7 +247,7 @@ impl fuser::Filesystem for FSelFS {
}

fn poll(
&mut self,
&self,
_req: &Request,
_ino: u64,
fh: u64,
Expand Down
Loading
Loading