Fixed a bug not handling fsync.

This commit is contained in:
Takeshi Nakatani 2015-03-10 16:18:03 +00:00
parent 761d2399f2
commit 26453c4874

View File

@ -185,6 +185,7 @@ static int s3fs_read(const char* path, char* buf, size_t size, off_t offset, str
static int s3fs_write(const char* path, const char* buf, size_t size, off_t offset, struct fuse_file_info* fi);
static int s3fs_statfs(const char* path, struct statvfs* stbuf);
static int s3fs_flush(const char* path, struct fuse_file_info* fi);
static int s3fs_fsync(const char* path, int datasync, struct fuse_file_info* fi);
static int s3fs_release(const char* path, struct fuse_file_info* fi);
static int s3fs_opendir(const char* path, struct fuse_file_info* fi);
static int s3fs_readdir(const char* path, void* buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info* fi);
@ -2052,6 +2053,38 @@ static int s3fs_flush(const char* path, struct fuse_file_info* fi)
return result;
}
// [NOTICE]
// Assumption is a valid fd.
//
static int s3fs_fsync(const char* path, int datasync, struct fuse_file_info* fi)
{
int result = 0;
FPRN("[path=%s][fd=%llu]", path, (unsigned long long)(fi->fh));
FdEntity* ent;
if(NULL != (ent = FdManager::get()->ExistOpen(path, static_cast<int>(fi->fh)))){
headers_t meta;
if(0 != (result = get_object_attribute(path, NULL, &meta))){
FdManager::get()->Close(ent);
return result;
}
// If datasync is not zero, only flush data without meta updating.
time_t ent_mtime;
if(ent->GetMtime(ent_mtime)){
if(0 == datasync && str(ent_mtime) != meta["x-amz-meta-mtime"]){
meta["x-amz-meta-mtime"] = str(ent_mtime);
}
}
result = ent->Flush(meta, false);
FdManager::get()->Close(ent);
}
S3FS_MALLOCTRIM(0);
return result;
}
static int s3fs_release(const char* path, struct fuse_file_info* fi)
{
FPRN("[path=%s][fd=%llu]", path, (unsigned long long)(fi->fh));
@ -4116,6 +4149,7 @@ int main(int argc, char* argv[])
s3fs_oper.write = s3fs_write;
s3fs_oper.statfs = s3fs_statfs;
s3fs_oper.flush = s3fs_flush;
s3fs_oper.fsync = s3fs_fsync;
s3fs_oper.release = s3fs_release;
s3fs_oper.opendir = s3fs_opendir;
s3fs_oper.readdir = s3fs_readdir;