Skip to content

Implement FuseFS — wrap around FileSystem that implements fuser::Filesystem trait to mount it. - #7

Open
Ycyken wants to merge 61 commits into
Piletskii-Oleg:mainfrom
Ycyken:fuse
Open

Implement FuseFS — wrap around FileSystem that implements fuser::Filesystem trait to mount it. #7
Ycyken wants to merge 61 commits into
Piletskii-Oleg:mainfrom
Ycyken:fuse

Conversation

@Ycyken

@Ycyken Ycyken commented Apr 5, 2025

Copy link
Copy Markdown
Contributor

Also added the ability to read the exact size from a file and at a specific offset.
Remove Hash copying in FileLayer::read_complete and FileLayer::read methods.

@Ycyken Ycyken changed the title Implement FuseFS - wrap around FileSystem that implements fuser::Filesystem trait. Implement FuseFS — wrap around FileSystem that implements fuser::Filesystem trait to mount it. Apr 5, 2025

@Piletskii-Oleg Piletskii-Oleg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

неплох

Comment thread src/system/database.rs Outdated

/// Retrieves a multitude of values, corresponding to the keys, in the correct order.
fn get_multi(&self, keys: &[K]) -> io::Result<Vec<V>> {
fn get_multi(&self, keys: Vec<&K>) -> io::Result<Vec<V>> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn get_multi(&self, keys: Vec<&K>) -> io::Result<Vec<V>> {
fn get_multi(&self, keys: &[&K]) -> io::Result<Vec<V>> {

так работает?

Comment thread src/system/file_layer.rs Outdated
}

pub fn offset(&self) -> &usize {
&self.offset

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usize предпочтительнее чем &usize (они занимают одинаково места в памяти)

Comment thread src/system/mod.rs
.storage
.retrieve(spans.iter().map(|span| span.hash()).collect())?;

let first_span = spans.first().unwrap();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в чем смысл этих двух действий внизу?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Т.к. мы читаем по оффсету, который может быть не ровно по оффсету FileSpan, а где-то посередине, то надо убрать лишнее в начале первого спана и лишнее в конце последнего спана. Добавил побольше комментариев

Comment thread src/system/storage.rs Outdated
/// Retrieves the data from the storage based on hashes of the data [`segments`][Segment],
/// or Error(NotFound) if some of the hashes were not present in the base.
pub fn retrieve(&self, request: &[Hash]) -> io::Result<Vec<Vec<u8>>> {
pub fn retrieve(&self, request: Vec<&Hash>) -> io::Result<Vec<Vec<u8>>> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub fn retrieve(&self, request: Vec<&Hash>) -> io::Result<Vec<Vec<u8>>> {
pub fn retrieve(&self, request: &[&Hash]) -> io::Result<Vec<Vec<u8>>> {

и снизу можно будет убрать .iter().collect() который не к месту

Comment thread src/system/file_layer.rs Outdated
}

pub fn offset(&self) -> usize {
self.offset.clone()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clone не нужен, usize маленький тип и имплементит Copy, потому он автоматически скопируется

Comment thread src/system/fuse_filesystem.rs Outdated
FileAttr, FileType, Filesystem, ReplyAttr, ReplyCreate, ReplyData, ReplyDirectory, ReplyEmpty,
ReplyEntry, ReplyOpen, ReplyWrite, Request, TimeOrNow,
};
use libc::{

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

убери эту строку импорта и вставь везде префикс libc где используются константы

@Ycyken
Ycyken requested a review from Piletskii-Oleg April 9, 2025 20:41
Comment thread examples/mount.rs Outdated

let session = fuser::spawn_mount2(fuse_fs, MOUNT_POINT, &vec![]).unwrap();

let file_path = format!("{}/{}", MOUNT_POINT, "file");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно MOUNT_POINT сделать Path и file_path инициализировать через MOUNT_POINT.join(...)

Comment thread src/system/file_layer.rs
Comment on lines +189 to +190
}
let last_span = spans.last().unwrap();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
let last_span = spans.last().unwrap();
}
let last_span = spans.last().unwrap();

Comment thread src/system/mod.rs Outdated
// Since we read by offset, which may be somewhere in the middle of the FileSpan offset,
// we need to remove the extra at the beginning of the first span
let first_span = spans.first().unwrap();
let last_span = spans.last().unwrap();

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

перекинь last_span чуть ниже, перед read_size_possible

Comment thread src/system/file_layer.rs
/// Starting point is based on the `FileHandle`'s offset.
///
/// If `size` + file handle offset is greater than file size, then returns FileSpans up to the end of the file.
pub fn read(&self, handle: &mut FileHandle, size: usize) -> Vec<&FileSpan<Hash>> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему он возвращает вектор FileSpan а не Hash?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Потому что если возвращать просто хэши, то будет непонятно, как обрезать данные в FileSystem::read(), т.к. информация об оффсетах потерялась. Можно попробовать возвращать вместе с хэшами какую-то информацию о начале и конце первого/последнего спана, но звучит не очень.

Comment thread src/system/mod.rs Outdated
pub fn read_from_file(&self, handle: &mut FileHandle) -> io::Result<Vec<u8>> {
let hashes = self.file_layer.read(handle);
Ok(self.storage.retrieve(&hashes)?.concat())
pub fn read_1mb_from_file(&self, handle: &mut FileHandle) -> io::Result<Vec<u8>> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше вернуть на read_from_file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ок

Comment thread tests/fuse_filesystem.rs

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по-хорошему бы накидать миллион тестов, проверяющих инварианты фьюза (не можем открыть файл к которому нет прав доступа, не можем создать папку, лукап работает верно, связка гетаттр/сетаттр и т.д.),

а чтобы в каждом из них не инициализировать это все в несколько строк, можно написать структурку FuseFixture, у которой будет какой-нибудь new или default, в нем будет собственно инициализация, монтирование и создание файла. к нему можно прикрутить методы типа "получить этот файл", а затем создавать через let fs = FuseFixture::new(); let file = fs.file()

тестов пока очень мало

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил тестов

Ycyken added 20 commits April 20, 2025 21:00
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
…f fh counter

Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Ycyken added 2 commits April 21, 2025 22:28
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Ycyken added 5 commits April 26, 2025 05:25
…orrect read()

Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
@Ycyken Ycyken closed this Apr 26, 2025
@Ycyken Ycyken reopened this Apr 26, 2025

@Piletskii-Oleg Piletskii-Oleg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

норм, замечания по мелочи

Ok(())
}

fn drop_cache(&mut self, file: Inode, handle: Fh) -> io::Result<()> {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

дока...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавил больше документации

Comment thread tests/fuse_filesystem.rs
Comment on lines +78 to +79
}
#[test]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

пробельчики

Suggested change
}
#[test]
}
#[test]

Comment thread tests/fuse_filesystem.rs Outdated
};
let read_denied = || {
let res = OpenOptions::new().read(true).open(&file_path);
assert!(res.is_err());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

какой именно err?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавил проверку на PermissionDenied

Comment thread tests/fuse_filesystem.rs Outdated

let dir_path = mount_point.join("directory");
let res = fs::create_dir(&dir_path);
assert!(res.is_err());

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

какой err?

Comment thread tests/fuse_filesystem.rs Outdated
}

#[test]
fn offset_change_not_affects_cache_drop() {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn offset_change_not_affects_cache_drop() {
fn offset_change_does_not_affect_cache_drop() {

Ycyken added 5 commits May 1, 2025 03:31
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
… behaviour

Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Ycyken added 3 commits May 2, 2025 08:41
…ry file's content change

Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
…possible inconsistency

Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
@Ycyken
Ycyken force-pushed the fuse branch 3 times, most recently from f1c61a4 to 77dbc11 Compare May 8, 2025 10:53
Ycyken added 4 commits May 8, 2025 15:46
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Ycyken and others added 4 commits May 8, 2025 16:11
…bench

Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Signed-off-by: Gleb Nasretdinov <gleb.nasretdinov@proton.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants