Merge pull request #918 from gaul/overwrite-file-range

Load tail range during overwrite
This commit is contained in:
Takeshi Nakatani 2019-01-23 19:12:23 +09:00 committed by GitHub
commit eb0b29708f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -1732,6 +1732,15 @@ ssize_t FdEntity::Write(const char* bytes, off_t start, size_t size)
pagelist.SetPageLoadedStatus(start, static_cast<size_t>(wsize), true);
}
// Load uninitialized area which starts from (start + size) to EOF after writing.
if(pagelist.Size() > static_cast<size_t>(start) + size){
result = Load(static_cast<size_t>(start + size), pagelist.Size());
if(0 != result){
S3FS_PRN_ERR("failed to load uninitialized area after writing(errno=%d)", result);
return static_cast<ssize_t>(result);
}
}
// check multipart uploading
if(0 < upload_id.length()){
mp_size += static_cast<size_t>(wsize);

View File

@ -487,6 +487,17 @@ function test_write_after_seek_ahead {
rm testfile
}
function test_overwrite_existing_file_range {
describe "Test overwrite range succeeds"
dd if=<(seq 1000) of=${TEST_TEXT_FILE}
dd if=/dev/zero of=${TEST_TEXT_FILE} seek=1 count=1 bs=1024 conv=notrunc
cmp ${TEST_TEXT_FILE} <(
seq 1000 | head -c 1024
dd if=/dev/zero count=1 bs=1024
seq 1000 | tail -c +2049
)
rm -f ${TEST_TEXT_FILE}
}
function add_all_tests {
add_tests test_append_file
@ -510,6 +521,7 @@ function add_all_tests {
add_tests test_update_time
add_tests test_rm_rf_dir
add_tests test_write_after_seek_ahead
add_tests test_overwrite_existing_file_range
}
init_suite