From 0c893c02d45cc865684a9a8cf78499e5241eb00d Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Mon, 24 Jan 2022 20:21:48 +0000 Subject: [PATCH] Enabling opening files for writing --- olivefs/src/filesystem.rs | 26 ++++++++++++++------------ olivefs_common/src/messages.rs | 2 +- olivefsd/src/server/file_access.rs | 4 +++- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/olivefs/src/filesystem.rs b/olivefs/src/filesystem.rs index 1ec1ffe..17955dd 100644 --- a/olivefs/src/filesystem.rs +++ b/olivefs/src/filesystem.rs @@ -329,12 +329,10 @@ impl Filesystem for OliveFilesystem { }; if open_mode.write || open_mode.append { - debug!( - "[Not Implemented (because of writing)] open(ino: {:#x?}, flags: {:?})", + warn!( + "[DANGER: Writing is unstable!] open(ino: {:#x?}, flags: {:?})", ino, flags ); - reply.error(ENOSYS); - return; } self.spawn_with_error_handler( @@ -356,15 +354,19 @@ impl Filesystem for OliveFilesystem { // and caching up to that point. // We might wind up wanting to do our own buffering... - if let Some(config) = streaming_reader_opts { - requester - .start_streaming_reader(file_handle, config) - .await?; - debug!( - "open(ino: {:#x?}) = fh {:?} (streaming reader: yes)", - ino, file_handle - ); + if open_mode.read && !open_mode.write && !open_mode.append { + // Only enable streaming readers in read-only use + if let Some(config) = streaming_reader_opts { + requester + .start_streaming_reader(file_handle, config) + .await?; + debug!( + "open(ino: {:#x?}) = fh {:?} (streaming reader: yes)", + ino, file_handle + ); + } } + debug!( "open(ino: {:#x?}) = fh {:?} (streaming reader: no)", ino, file_handle diff --git a/olivefs_common/src/messages.rs b/olivefs_common/src/messages.rs index 231b844..963954b 100644 --- a/olivefs_common/src/messages.rs +++ b/olivefs_common/src/messages.rs @@ -28,7 +28,7 @@ impl HelloMessage { } } -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Serialize, Deserialize, Debug, Copy, Clone)] pub struct OpenMode { pub read: bool, pub write: bool, diff --git a/olivefsd/src/server/file_access.rs b/olivefsd/src/server/file_access.rs index 33fe9f6..b2e2915 100644 --- a/olivefsd/src/server/file_access.rs +++ b/olivefsd/src/server/file_access.rs @@ -14,6 +14,7 @@ use std::os::unix::fs::{MetadataExt, PermissionsExt}; use std::path::{Path, PathBuf}; use std::sync::Arc; use std::time::{Duration, Instant}; +use log::{error, warn}; use tokio::fs::{OpenOptions, ReadDir}; use tokio::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt}; use tokio::sync::RwLock; @@ -413,10 +414,11 @@ impl FileAccess { } if mode.write { open_options.write(true); - todo!(); + warn!("DANGER: file opened with write mode"); } if mode.append { open_options.append(true); + error!("UNSUPPORTED: file opened with append mode"); todo!(); } // TODO truncate?