ocfs2: Fix up i_blocks calculation to know about holes
authorMark Fasheh <mark.fasheh@oracle.com>
Thu, 22 Mar 2007 23:53:23 +0000 (16:53 -0700)
committerMark Fasheh <mark.fasheh@oracle.com>
Thu, 26 Apr 2007 22:07:40 +0000 (15:07 -0700)
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>
fs/ocfs2/aops.c
fs/ocfs2/dir.c
fs/ocfs2/dlmglue.c
fs/ocfs2/file.c
fs/ocfs2/inode.c
fs/ocfs2/inode.h
fs/ocfs2/journal.c
fs/ocfs2/namei.c
fs/ocfs2/suballoc.c

index ff71e0b430cdd53a8b8afdc0be99bed5c7288782..b74971e19d54cf58744b53e0a58aa6474b29954d 100644 (file)
@@ -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);
index 8d22e1e4a88d36a086f5e63bc710ccf4c32f154e..67e6866a2a4fb0782b13050ccbe2e6402698036f 100644 (file)
@@ -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);
index 8de6678a340aa9c0db87808c530148f543debe45..43267eea3538dbb5c0ca183f8828152712aacab2 100644 (file)
@@ -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);
index f516619a374481eb8a507b687a8cd6cbc5901dc9..e34474c0467877e556b92f0116a601e7edce3f96 100644 (file)
@@ -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);
index 310049bf7f6bc5a44f42aa7bb1d854670b915418..4bfc98c7013761a83a65c39a4fbb045077556e96 100644 (file)
@@ -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);
index a9ced009cb9c69a5d8826b399a5bd936654eff9d..aa84353d0d196d70983e40ace13063018ab5d7d6 100644 (file)
@@ -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 */
index 12d2340eee29ebf1761c2ed93df6ebe3bebd435c..5a8a90d1c787af7bf993f36516615e079221c61f 100644 (file)
@@ -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) {
index 9bdbe4ae92f8ef24a87b09d1438eac223bd90ce4..2bcf353fd7c5d4aa2a90ccfa7f2a868858702ff4 100644 (file)
@@ -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);
index 6dbb1176275973d7088bdc5d696e93227b1668bf..0da655ae5d6f807588a2b76a599b8c5135cacb74 100644 (file)
@@ -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: