-
Notifications
You must be signed in to change notification settings - Fork 157
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
Support open with O_RDWR flag #370
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,54 @@ enum FileHandleType<Client: ObjectClient, Runtime> { | |
}, | ||
} | ||
|
||
impl<Client: ObjectClient, Runtime> FileHandleType<Client, Runtime> { | ||
async fn new_write_handle( | ||
lookup: &LookedUp, | ||
ino: InodeNo, | ||
flags: i32, | ||
fs: &S3Filesystem<Client, Runtime>, | ||
) -> Result<FileHandleType<Client, Runtime>, libc::c_int> { | ||
// We can't support O_SYNC writes because they require the data to go to stable storage | ||
// at `write` time, but we only commit a PUT at `close` time. | ||
if flags & (libc::O_SYNC | libc::O_DSYNC) != 0 { | ||
error!("O_SYNC and O_DSYNC are unsupported"); | ||
return Err(libc::EINVAL); | ||
} | ||
|
||
let handle = match fs.superblock.write(&fs.client, ino, lookup.inode.parent()).await { | ||
Ok(handle) => handle, | ||
Err(e) => { | ||
error!("open failed: {e:?}"); | ||
return Err(e.into()); | ||
} | ||
}; | ||
let key = lookup.inode.full_key(); | ||
let handle = match fs.uploader.put(&fs.bucket, key).await { | ||
Err(e) => { | ||
error!(key, "put failed to start: {e:?}"); | ||
return Err(libc::EIO); | ||
} | ||
Ok(request) => FileHandleType::Write { | ||
request: UploadState::InProgress(request).into(), | ||
handle, | ||
}, | ||
}; | ||
Ok(handle) | ||
} | ||
|
||
async fn new_read_handle(lookup: &LookedUp) -> Result<FileHandleType<Client, Runtime>, libc::c_int> { | ||
lookup.inode.start_reading()?; | ||
let handle = FileHandleType::Read { | ||
request: Default::default(), | ||
etag: match &lookup.stat.etag { | ||
None => return Err(libc::EBADF), | ||
Some(etag) => ETag::from_str(etag).expect("E-Tag should be set"), | ||
}, | ||
}; | ||
Ok(handle) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
enum UploadState<Client: ObjectClient> { | ||
InProgress(UploadRequest<Client>), | ||
|
@@ -375,43 +423,18 @@ where | |
} | ||
|
||
let handle_type = if flags & libc::O_RDWR != 0 { | ||
error!("O_RDWR is unsupported"); | ||
return Err(libc::EINVAL); | ||
} else if flags & libc::O_WRONLY != 0 { | ||
// We can't support O_SYNC writes because they require the data to go to stable storage | ||
// at `write` time, but we only commit a PUT at `close` time. | ||
if flags & (libc::O_SYNC | libc::O_DSYNC) != 0 { | ||
error!("O_SYNC and O_DSYNC are unsupported"); | ||
return Err(libc::EINVAL); | ||
} | ||
|
||
let handle = match self.superblock.write(&self.client, ino, lookup.inode.parent()).await { | ||
Ok(handle) => handle, | ||
Err(e) => { | ||
error!("open failed: {e:?}"); | ||
return Err(e.into()); | ||
} | ||
}; | ||
let key = lookup.inode.full_key(); | ||
match self.uploader.put(&self.bucket, key).await { | ||
Err(e) => { | ||
error!(key, "put failed to start: {e:?}"); | ||
return Err(libc::EIO); | ||
} | ||
Ok(request) => FileHandleType::Write { | ||
request: UploadState::InProgress(request).into(), | ||
handle, | ||
}, | ||
let remote_file = lookup.inode.is_remote()?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably log here which option we're choosing for this |
||
if remote_file { | ||
trace!("fs:open choosing read handle for O_RDWR"); | ||
FileHandleType::new_read_handle(&lookup).await? | ||
} else { | ||
trace!("fs:open choosing write handle for O_RDWR"); | ||
FileHandleType::new_write_handle(&lookup, ino, flags, self).await? | ||
} | ||
} else if flags & libc::O_WRONLY != 0 { | ||
FileHandleType::new_write_handle(&lookup, ino, flags, self).await? | ||
} else { | ||
lookup.inode.start_reading()?; | ||
FileHandleType::Read { | ||
request: Default::default(), | ||
etag: match lookup.stat.etag { | ||
None => return Err(libc::EBADF), | ||
Some(etag) => ETag::from_str(&etag).expect("E-Tag should be set"), | ||
}, | ||
} | ||
FileHandleType::new_read_handle(&lookup).await? | ||
}; | ||
|
||
let full_key = lookup.inode.full_key().to_owned(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should mention that
O_RDWR
will work but you can't both read and write to the same fd