Skip to content

Commit

Permalink
move timestamp update before data update in fast write path (fix utsa…
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwedeck committed Oct 11, 2023
1 parent b4017d0 commit b525eec
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Linux-5.1/fs/winefs/xip.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ static ssize_t pmfs_file_write_fast(struct super_block *sb, struct inode *inode,

offset = pos & (sb->s_blocksize - 1);

inode->i_ctime = inode->i_mtime = current_time(inode);
if(count + offset <= inode->i_size) {
u64 c_m_time;
/* make sure that the time is updated before any modified data may be committed */
c_m_time = (inode->i_ctime.tv_sec & 0xFFFFFFFF);
c_m_time = c_m_time | (c_m_time << 32);
pmfs_memunlock_inode(sb, pi);
pmfs_memcpy_atomic(&pi->i_ctime, &c_m_time, 8);
pmfs_memlock_inode(sb, pi);
pmfs_flush_buffer(pi, 1, true);
}

PMFS_START_TIMING(memcpy_w_t, memcpy_time);
pmfs_xip_mem_protect(sb, xmem + offset, count, 1);
copied = memcpy_to_nvmm((char *)xmem, offset, buf, count);
Expand All @@ -311,7 +323,6 @@ static ssize_t pmfs_file_write_fast(struct super_block *sb, struct inode *inode,
if (unlikely(copied != count && copied == 0))
ret = -EFAULT;
*ppos = pos;
inode->i_ctime = inode->i_mtime = current_time(inode);
if (pos > inode->i_size) {
/* make sure written data is persistent before updating
* time and size */
Expand All @@ -321,18 +332,8 @@ static ssize_t pmfs_file_write_fast(struct super_block *sb, struct inode *inode,
pmfs_memunlock_inode(sb, pi);
pmfs_update_time_and_size(inode, pi);
pmfs_memlock_inode(sb, pi);
} else {
u64 c_m_time;
/* update c_time and m_time atomically. We don't need to make the data
* persistent because the expectation is that the close() or an explicit
* fsync will do that. */
c_m_time = (inode->i_ctime.tv_sec & 0xFFFFFFFF);
c_m_time = c_m_time | (c_m_time << 32);
pmfs_memunlock_inode(sb, pi);
pmfs_memcpy_atomic(&pi->i_ctime, &c_m_time, 8);
pmfs_memlock_inode(sb, pi);
pmfs_flush_buffer(pi, 1, barrier);
}
pmfs_flush_buffer(pi, 1, barrier);
return ret;
}

Expand Down

0 comments on commit b525eec

Please sign in to comment.