Skip to content

Commit

Permalink
Fix truncate for O_DIRECT
Browse files Browse the repository at this point in the history
In the buffered case page tail zeroing happens automatically.
In the O_DIRECT case it does not so we need to add it in our setattr
path just like EXT2. We want to zero the end of the block that contains
i_size during truncate, so we just call block_truncate_page in
set_inode_size.
  • Loading branch information
Bryant Duffy-Ly committed Mar 24, 2022
1 parent 5b53e0a commit eafb70c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions kmod/src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,8 @@ static int scoutfs_get_block_read(struct inode *inode, sector_t iblock,
return ret;
}

static int scoutfs_get_block_write(struct inode *inode, sector_t iblock,
struct buffer_head *bh, int create)
int scoutfs_get_block_write(struct inode *inode, sector_t iblock,
struct buffer_head *bh, int create)
{
struct scoutfs_inode_info *si = SCOUTFS_I(inode);
int ret;
Expand Down
2 changes: 2 additions & 0 deletions kmod/src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ int scoutfs_data_truncate_items(struct super_block *sb, struct inode *inode,
int scoutfs_data_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
u64 start, u64 len);
long scoutfs_fallocate(struct file *file, int mode, loff_t offset, loff_t len);
int scoutfs_get_block_write(struct inode *inode, sector_t iblock,
struct buffer_head *bh, int create);
int scoutfs_data_init_offline_extent(struct inode *inode, u64 size,
struct scoutfs_lock *lock);
int scoutfs_data_move_blocks(struct inode *from, u64 from_off,
Expand Down
11 changes: 10 additions & 1 deletion kmod/src/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/pagemap.h>
#include <linux/sched.h>
#include <linux/list_sort.h>
#include <linux/buffer_head.h>

#include "format.h"
#include "super.h"
Expand Down Expand Up @@ -354,15 +355,22 @@ static int set_inode_size(struct inode *inode, struct scoutfs_lock *lock,
{
struct scoutfs_inode_info *si = SCOUTFS_I(inode);
struct super_block *sb = inode->i_sb;
SCOUTFS_DECLARE_PER_TASK_ENTRY(pt_ent);
LIST_HEAD(ind_locks);
int ret;

if (!S_ISREG(inode->i_mode))
return 0;

scoutfs_per_task_add(&si->pt_data_lock, &pt_ent, lock);
ret = block_truncate_page(inode->i_mapping, new_size, scoutfs_get_block_write);
scoutfs_per_task_del(&si->pt_data_lock, &pt_ent);
if (ret)
goto out;

ret = scoutfs_inode_index_lock_hold(inode, &ind_locks, true, false);
if (ret)
return ret;
goto out;

if (new_size != i_size_read(inode))
scoutfs_inode_inc_data_version(inode);
Expand All @@ -378,6 +386,7 @@ static int set_inode_size(struct inode *inode, struct scoutfs_lock *lock,
scoutfs_release_trans(sb);
scoutfs_inode_index_unlock(sb, &ind_locks);

out:
return ret;
}

Expand Down

0 comments on commit eafb70c

Please sign in to comment.