[dfs v2] support O_DIRECT and O_SYNC flags (#8155)
This commit is contained in:
parent
43f96b3f85
commit
1f05b6b401
|
@ -685,7 +685,7 @@ ssize_t dfs_file_read(struct dfs_file *file, void *buf, size_t len)
|
|||
if (dfs_is_mounted(file->vnode->mnt) == 0)
|
||||
{
|
||||
#ifdef RT_USING_PAGECACHE
|
||||
if (file->vnode->aspace)
|
||||
if (file->vnode->aspace && !(file->flags & O_DIRECT))
|
||||
{
|
||||
ret = dfs_aspace_read(file, buf, len, &pos);
|
||||
}
|
||||
|
@ -739,7 +739,7 @@ ssize_t dfs_file_write(struct dfs_file *file, const void *buf, size_t len)
|
|||
if (dfs_is_mounted(file->vnode->mnt) == 0)
|
||||
{
|
||||
#ifdef RT_USING_PAGECACHE
|
||||
if (file->vnode->aspace)
|
||||
if (file->vnode->aspace && !(file->flags & O_DIRECT))
|
||||
{
|
||||
ret = dfs_aspace_write(file, buf, len, &pos);
|
||||
}
|
||||
|
@ -748,6 +748,11 @@ ssize_t dfs_file_write(struct dfs_file *file, const void *buf, size_t len)
|
|||
{
|
||||
ret = file->fops->write(file, buf, len, &pos);
|
||||
}
|
||||
|
||||
if (file->flags & O_SYNC)
|
||||
{
|
||||
file->fops->flush(file);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -1153,7 +1153,25 @@ int dfs_aspace_write(struct dfs_file *file, const void *buf, size_t count, off_t
|
|||
aspace->vnode->size = *pos;
|
||||
}
|
||||
|
||||
dfs_page_dirty(page);
|
||||
if (file->flags & O_SYNC)
|
||||
{
|
||||
if (aspace->vnode->size < page->fpos + page->size)
|
||||
{
|
||||
page->len = aspace->vnode->size - page->fpos;
|
||||
}
|
||||
else
|
||||
{
|
||||
page->len = page->size;
|
||||
}
|
||||
|
||||
aspace->ops->write(page);
|
||||
page->is_dirty = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
dfs_page_dirty(page);
|
||||
}
|
||||
|
||||
dfs_page_release(page);
|
||||
dfs_aspace_unlock(aspace);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue