[dfs v2] support O_DIRECT and O_SYNC flags (#8155)

This commit is contained in:
XYZ 2023-10-20 13:24:56 +08:00 committed by GitHub
parent 43f96b3f85
commit 1f05b6b401
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -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
{

View File

@ -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);
}