bugfix: read/write fd dropped unexpectedly.#184
Merged
WeiZhang555 merged 1 commit intocloud-hypervisor:masterfrom Feb 5, 2024
Merged
bugfix: read/write fd dropped unexpectedly.#184WeiZhang555 merged 1 commit intocloud-hypervisor:masterfrom
WeiZhang555 merged 1 commit intocloud-hypervisor:masterfrom
Conversation
read/write function invokes ``` self.check_fd_flags(data, f.as_raw_fd(), flags)?; ``` which takes ownership of `data` and it's inner `File`, after the function call returns, File will be dropped and cannot be read/write later anymore, causing a failed read/write. This bug is triggered when `no_open` config option is set, in this case, `self.get_data` opens a new file and it's dropped immediately after `check_fd_flags`. The bug can be solved by create a new clone of data by `data.clone()`, the original data(and inner File) can be kept in whole lifetime of read/write function. Signed-off-by: Wei Zhang <weizhang555.zw@gmail.com>
7925c96 to
9ca710d
Compare
eryugey
approved these changes
Jan 25, 2024
bergwolf
reviewed
Jan 31, 2024
| assert!(!fs.cfg.writeback); | ||
| } | ||
|
|
||
| impl ZeroCopyReader for File { |
Contributor
There was a problem hiding this comment.
Why are these needed? The commit message does not seem to explain it.
Collaborator
Author
There was a problem hiding this comment.
This resides in mod tests, at https://github.com/cloud-hypervisor/fuse-backend-rs/pull/184/files/9ca710da29796b759d6d782e8dd2d9209d5bf838#diff-7f83e7da9ae6f4daf23fadb16185e191349a8f96620bd58d29483e3b28ec1a1cR1593
I need a &mut dyn ZeroCopyReader, in fuse-backend-rs, I didn't find a convenient implementation of ZeroCopyReader and ZeroCopyWriter, so I have to implement one in mod tests for test usage.
bergwolf
approved these changes
Feb 5, 2024
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
read/write function invokes
which takes ownership of
dataand it's innerFile, after the function call returns, File will be dropped and cannot be read/write later anymore, causing a failed read/write.This bug is triggered when
no_openconfig option is set, in this case,self.get_dataopens a new file and it's dropped immediately aftercheck_fd_flags.The bug can be solved by create a new clone of data by
data.clone(), the original data(and inner File) can be kept in whole lifetime of read/write function.