mirror of
https://github.com/torvalds/linux
synced 2024-11-05 18:23:50 +00:00
ocfs2: Fix up i_blocks calculation to know about holes
Older file systems which didn't support holes did a dumb calculation of i_blocks based on i_size. This is no longer accurate, so fix things up to take actual allocation into account. Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
This commit is contained in:
parent
4f902c3772
commit
8110b073a9
9 changed files with 25 additions and 30 deletions
|
@ -1271,7 +1271,7 @@ ssize_t ocfs2_buffered_write_cluster(struct file *file, loff_t pos,
|
|||
i_size_write(inode, pos);
|
||||
mark_inode_dirty(inode);
|
||||
}
|
||||
inode->i_blocks = ocfs2_align_bytes_to_sectors((u64)(i_size_read(inode)));
|
||||
inode->i_blocks = ocfs2_inode_sector_count(inode);
|
||||
di->i_size = cpu_to_le64((u64)i_size_read(inode));
|
||||
inode->i_mtime = inode->i_ctime = CURRENT_TIME;
|
||||
di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
|
||||
|
|
|
@ -358,7 +358,7 @@ int ocfs2_do_extend_dir(struct super_block *sb,
|
|||
{
|
||||
int status;
|
||||
int extend;
|
||||
u64 p_blkno;
|
||||
u64 p_blkno, v_blkno;
|
||||
|
||||
spin_lock(&OCFS2_I(dir)->ip_lock);
|
||||
extend = (i_size_read(dir) == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters));
|
||||
|
@ -377,9 +377,8 @@ int ocfs2_do_extend_dir(struct super_block *sb,
|
|||
}
|
||||
}
|
||||
|
||||
status = ocfs2_extent_map_get_blocks(dir, (dir->i_blocks >>
|
||||
(sb->s_blocksize_bits - 9)),
|
||||
&p_blkno, NULL, NULL);
|
||||
v_blkno = ocfs2_blocks_for_bytes(sb, i_size_read(dir));
|
||||
status = ocfs2_extent_map_get_blocks(dir, v_blkno, &p_blkno, NULL, NULL);
|
||||
if (status < 0) {
|
||||
mlog_errno(status);
|
||||
goto bail;
|
||||
|
@ -488,7 +487,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
|
|||
|
||||
dir_i_size += dir->i_sb->s_blocksize;
|
||||
i_size_write(dir, dir_i_size);
|
||||
dir->i_blocks = ocfs2_align_bytes_to_sectors(dir_i_size);
|
||||
dir->i_blocks = ocfs2_inode_sector_count(dir);
|
||||
status = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh);
|
||||
if (status < 0) {
|
||||
mlog_errno(status);
|
||||
|
|
|
@ -1495,8 +1495,7 @@ static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
|
|||
if (S_ISLNK(inode->i_mode) && !oi->ip_clusters)
|
||||
inode->i_blocks = 0;
|
||||
else
|
||||
inode->i_blocks =
|
||||
ocfs2_align_bytes_to_sectors(i_size_read(inode));
|
||||
inode->i_blocks = ocfs2_inode_sector_count(inode);
|
||||
|
||||
inode->i_uid = be32_to_cpu(lvb->lvb_iuid);
|
||||
inode->i_gid = be32_to_cpu(lvb->lvb_igid);
|
||||
|
|
|
@ -216,7 +216,7 @@ int ocfs2_set_inode_size(handle_t *handle,
|
|||
|
||||
mlog_entry_void();
|
||||
i_size_write(inode, new_i_size);
|
||||
inode->i_blocks = ocfs2_align_bytes_to_sectors(new_i_size);
|
||||
inode->i_blocks = ocfs2_inode_sector_count(inode);
|
||||
inode->i_ctime = inode->i_mtime = CURRENT_TIME;
|
||||
|
||||
status = ocfs2_mark_inode_dirty(handle, inode, fe_bh);
|
||||
|
|
|
@ -221,6 +221,9 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
|
|||
goto bail;
|
||||
}
|
||||
|
||||
OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
|
||||
OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
|
||||
|
||||
inode->i_version = 1;
|
||||
inode->i_generation = le32_to_cpu(fe->i_generation);
|
||||
inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev));
|
||||
|
@ -232,8 +235,7 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
|
|||
if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
|
||||
inode->i_blocks = 0;
|
||||
else
|
||||
inode->i_blocks =
|
||||
ocfs2_align_bytes_to_sectors(le64_to_cpu(fe->i_size));
|
||||
inode->i_blocks = ocfs2_inode_sector_count(inode);
|
||||
inode->i_mapping->a_ops = &ocfs2_aops;
|
||||
inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime);
|
||||
inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec);
|
||||
|
@ -248,9 +250,6 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
|
|||
(unsigned long long)OCFS2_I(inode)->ip_blkno,
|
||||
(unsigned long long)fe->i_blkno);
|
||||
|
||||
OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
|
||||
OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
|
||||
|
||||
inode->i_nlink = le16_to_cpu(fe->i_links_count);
|
||||
|
||||
if (fe->i_flags & cpu_to_le32(OCFS2_SYSTEM_FL))
|
||||
|
@ -1243,7 +1242,7 @@ void ocfs2_refresh_inode(struct inode *inode,
|
|||
if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
|
||||
inode->i_blocks = 0;
|
||||
else
|
||||
inode->i_blocks = ocfs2_align_bytes_to_sectors(i_size_read(inode));
|
||||
inode->i_blocks = ocfs2_inode_sector_count(inode);
|
||||
inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime);
|
||||
inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec);
|
||||
inode->i_mtime.tv_sec = le64_to_cpu(fe->i_mtime);
|
||||
|
|
|
@ -138,4 +138,11 @@ int ocfs2_aio_write(struct file *file, struct kiocb *req, struct iocb *iocb);
|
|||
|
||||
void ocfs2_set_inode_flags(struct inode *inode);
|
||||
|
||||
static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
|
||||
{
|
||||
int c_to_s_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits - 9;
|
||||
|
||||
return (blkcnt_t)(OCFS2_I(inode)->ip_clusters << c_to_s_bits);
|
||||
}
|
||||
|
||||
#endif /* OCFS2_INODE_H */
|
||||
|
|
|
@ -650,25 +650,17 @@ static int ocfs2_force_read_journal(struct inode *inode)
|
|||
{
|
||||
int status = 0;
|
||||
int i;
|
||||
u64 v_blkno, p_blkno, p_blocks;
|
||||
u64 v_blkno, p_blkno, p_blocks, num_blocks;
|
||||
#define CONCURRENT_JOURNAL_FILL 32ULL
|
||||
struct buffer_head *bhs[CONCURRENT_JOURNAL_FILL];
|
||||
|
||||
mlog_entry_void();
|
||||
|
||||
BUG_ON(inode->i_blocks !=
|
||||
ocfs2_align_bytes_to_sectors(i_size_read(inode)));
|
||||
|
||||
memset(bhs, 0, sizeof(struct buffer_head *) * CONCURRENT_JOURNAL_FILL);
|
||||
|
||||
mlog(0, "Force reading %llu blocks\n",
|
||||
(unsigned long long)(inode->i_blocks >>
|
||||
(inode->i_sb->s_blocksize_bits - 9)));
|
||||
|
||||
num_blocks = ocfs2_blocks_for_bytes(inode->i_sb, inode->i_size);
|
||||
v_blkno = 0;
|
||||
while (v_blkno <
|
||||
(inode->i_blocks >> (inode->i_sb->s_blocksize_bits - 9))) {
|
||||
|
||||
while (v_blkno < num_blocks) {
|
||||
status = ocfs2_extent_map_get_blocks(inode, v_blkno,
|
||||
&p_blkno, &p_blocks, NULL);
|
||||
if (status < 0) {
|
||||
|
|
|
@ -285,7 +285,7 @@ static int ocfs2_fill_new_dir(struct ocfs2_super *osb,
|
|||
|
||||
i_size_write(inode, inode->i_sb->s_blocksize);
|
||||
inode->i_nlink = 2;
|
||||
inode->i_blocks = ocfs2_align_bytes_to_sectors(inode->i_sb->s_blocksize);
|
||||
inode->i_blocks = ocfs2_inode_sector_count(inode);
|
||||
status = ocfs2_mark_inode_dirty(handle, inode, fe_bh);
|
||||
if (status < 0) {
|
||||
mlog_errno(status);
|
||||
|
@ -1688,7 +1688,7 @@ static int ocfs2_symlink(struct inode *dir,
|
|||
goto bail;
|
||||
}
|
||||
i_size_write(inode, newsize);
|
||||
inode->i_blocks = ocfs2_align_bytes_to_sectors(newsize);
|
||||
inode->i_blocks = ocfs2_inode_sector_count(inode);
|
||||
} else {
|
||||
inode->i_op = &ocfs2_fast_symlink_inode_operations;
|
||||
memcpy((char *) fe->id2.i_symlink, symname, l);
|
||||
|
|
|
@ -381,8 +381,7 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
|
|||
le32_to_cpu(fe->i_clusters)));
|
||||
spin_unlock(&OCFS2_I(alloc_inode)->ip_lock);
|
||||
i_size_write(alloc_inode, le64_to_cpu(fe->i_size));
|
||||
alloc_inode->i_blocks =
|
||||
ocfs2_align_bytes_to_sectors(i_size_read(alloc_inode));
|
||||
alloc_inode->i_blocks = ocfs2_inode_sector_count(alloc_inode);
|
||||
|
||||
status = 0;
|
||||
bail:
|
||||
|
|
Loading…
Reference in a new issue