Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap decrease btree height in a transaction #15

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions Linux-5.1/fs/winefs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,16 +564,8 @@ static void pmfs_decrease_btree_height(struct super_block *sb,
height--;
}
update_root_and_height:
/* pi->height and pi->root need to be atomically updated. use
* cmpxchg16 here. The following is dependent on a specific layout of
* inode fields */
*(u64 *)b = *(u64 *)pi;
/* pi->height is at offset 2 from pi */
b[2] = (u8)new_height;
/* TODO: the following function assumes cmpxchg16b instruction writes
* 16 bytes atomically. Confirm if it is really true. */
cmpxchg_double_local((u64 *)pi, &pi->root, *(u64 *)pi, pi->root,
*(u64 *)b, newroot);
pi->root = newroot;
pi->height = height;
}

static unsigned long pmfs_inode_count_iblocks_recursive(struct super_block *sb,
Expand Down Expand Up @@ -630,6 +622,7 @@ static void __pmfs_truncate_blocks(struct inode *inode, loff_t start,
unsigned int freed = 0;
unsigned int data_bits = blk_type_to_shift[pi->i_blk_type];
unsigned int meta_bits = META_BLK_SHIFT;
struct pmfs_transaction *trans;
bool mpty;

inode->i_mtime = inode->i_ctime = current_time(inode);
Expand Down Expand Up @@ -681,6 +674,11 @@ static void __pmfs_truncate_blocks(struct inode *inode, loff_t start,
inode->i_blocks -= (freed * (1 << (data_bits -
sb->s_blocksize_bits)));

PERSISTENT_BARRIER();
BUG_ON(pmfs_current_transaction());
trans = pmfs_new_transaction(sb, MAX_INODE_LENTRIES, pmfs_get_cpuid(sb));
pmfs_add_logentry(sb, trans, pi, sizeof(*pi), LE_DATA);

pmfs_memunlock_inode(sb, pi);
pi->i_blocks = cpu_to_le64(inode->i_blocks);
pi->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec);
Expand All @@ -690,7 +688,8 @@ static void __pmfs_truncate_blocks(struct inode *inode, loff_t start,
check_eof_blocks(sb, pi, inode->i_size);
pmfs_memlock_inode(sb, pi);
/* now flush the inode's first cacheline which was modified */
pmfs_flush_buffer(pi, 1, false);
pmfs_flush_buffer(pi, 1, true);
pmfs_commit_transaction(sb, trans);
return;
end_truncate_blocks:
/* we still need to update ctime and mtime */
Expand Down