aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Fasheh <mark.fasheh@oracle.com>2007-03-22 19:53:23 -0400
committerMark Fasheh <mark.fasheh@oracle.com>2007-04-26 18:07:40 -0400
commit8110b073a9135acf0a71bccfc20c0d1023f179c6 (patch)
treeb668738e25648f3fcfd7b1063ab8d4948cebc668
parent4f902c37727bbedbc0508a1477874c58ddcc9af8 (diff)
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>
-rw-r--r--fs/ocfs2/aops.c2
-rw-r--r--fs/ocfs2/dir.c9
-rw-r--r--fs/ocfs2/dlmglue.c3
-rw-r--r--fs/ocfs2/file.c2
-rw-r--r--fs/ocfs2/inode.c11
-rw-r--r--fs/ocfs2/inode.h7
-rw-r--r--fs/ocfs2/journal.c14
-rw-r--r--fs/ocfs2/namei.c4
-rw-r--r--fs/ocfs2/suballoc.c3
9 files changed, 25 insertions, 30 deletions
diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c
index ff71e0b430cd..b74971e19d54 100644
--- a/fs/ocfs2/aops.c
+++ b/fs/ocfs2/aops.c
@@ -1271,7 +1271,7 @@ ssize_t ocfs2_buffered_write_cluster(struct file *file, loff_t pos,
1271 i_size_write(inode, pos); 1271 i_size_write(inode, pos);
1272 mark_inode_dirty(inode); 1272 mark_inode_dirty(inode);
1273 } 1273 }
1274 inode->i_blocks = ocfs2_align_bytes_to_sectors((u64)(i_size_read(inode))); 1274 inode->i_blocks = ocfs2_inode_sector_count(inode);
1275 di->i_size = cpu_to_le64((u64)i_size_read(inode)); 1275 di->i_size = cpu_to_le64((u64)i_size_read(inode));
1276 inode->i_mtime = inode->i_ctime = CURRENT_TIME; 1276 inode->i_mtime = inode->i_ctime = CURRENT_TIME;
1277 di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec); 1277 di->i_mtime = di->i_ctime = cpu_to_le64(inode->i_mtime.tv_sec);
diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
index 8d22e1e4a88d..67e6866a2a4f 100644
--- a/fs/ocfs2/dir.c
+++ b/fs/ocfs2/dir.c
@@ -358,7 +358,7 @@ int ocfs2_do_extend_dir(struct super_block *sb,
358{ 358{
359 int status; 359 int status;
360 int extend; 360 int extend;
361 u64 p_blkno; 361 u64 p_blkno, v_blkno;
362 362
363 spin_lock(&OCFS2_I(dir)->ip_lock); 363 spin_lock(&OCFS2_I(dir)->ip_lock);
364 extend = (i_size_read(dir) == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)); 364 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,
377 } 377 }
378 } 378 }
379 379
380 status = ocfs2_extent_map_get_blocks(dir, (dir->i_blocks >> 380 v_blkno = ocfs2_blocks_for_bytes(sb, i_size_read(dir));
381 (sb->s_blocksize_bits - 9)), 381 status = ocfs2_extent_map_get_blocks(dir, v_blkno, &p_blkno, NULL, NULL);
382 &p_blkno, NULL, NULL);
383 if (status < 0) { 382 if (status < 0) {
384 mlog_errno(status); 383 mlog_errno(status);
385 goto bail; 384 goto bail;
@@ -488,7 +487,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
488 487
489 dir_i_size += dir->i_sb->s_blocksize; 488 dir_i_size += dir->i_sb->s_blocksize;
490 i_size_write(dir, dir_i_size); 489 i_size_write(dir, dir_i_size);
491 dir->i_blocks = ocfs2_align_bytes_to_sectors(dir_i_size); 490 dir->i_blocks = ocfs2_inode_sector_count(dir);
492 status = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh); 491 status = ocfs2_mark_inode_dirty(handle, dir, parent_fe_bh);
493 if (status < 0) { 492 if (status < 0) {
494 mlog_errno(status); 493 mlog_errno(status);
diff --git a/fs/ocfs2/dlmglue.c b/fs/ocfs2/dlmglue.c
index 8de6678a340a..43267eea3538 100644
--- a/fs/ocfs2/dlmglue.c
+++ b/fs/ocfs2/dlmglue.c
@@ -1495,8 +1495,7 @@ static void ocfs2_refresh_inode_from_lvb(struct inode *inode)
1495 if (S_ISLNK(inode->i_mode) && !oi->ip_clusters) 1495 if (S_ISLNK(inode->i_mode) && !oi->ip_clusters)
1496 inode->i_blocks = 0; 1496 inode->i_blocks = 0;
1497 else 1497 else
1498 inode->i_blocks = 1498 inode->i_blocks = ocfs2_inode_sector_count(inode);
1499 ocfs2_align_bytes_to_sectors(i_size_read(inode));
1500 1499
1501 inode->i_uid = be32_to_cpu(lvb->lvb_iuid); 1500 inode->i_uid = be32_to_cpu(lvb->lvb_iuid);
1502 inode->i_gid = be32_to_cpu(lvb->lvb_igid); 1501 inode->i_gid = be32_to_cpu(lvb->lvb_igid);
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index f516619a3744..e34474c04678 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -216,7 +216,7 @@ int ocfs2_set_inode_size(handle_t *handle,
216 216
217 mlog_entry_void(); 217 mlog_entry_void();
218 i_size_write(inode, new_i_size); 218 i_size_write(inode, new_i_size);
219 inode->i_blocks = ocfs2_align_bytes_to_sectors(new_i_size); 219 inode->i_blocks = ocfs2_inode_sector_count(inode);
220 inode->i_ctime = inode->i_mtime = CURRENT_TIME; 220 inode->i_ctime = inode->i_mtime = CURRENT_TIME;
221 221
222 status = ocfs2_mark_inode_dirty(handle, inode, fe_bh); 222 status = ocfs2_mark_inode_dirty(handle, inode, fe_bh);
diff --git a/fs/ocfs2/inode.c b/fs/ocfs2/inode.c
index 310049bf7f6b..4bfc98c70137 100644
--- a/fs/ocfs2/inode.c
+++ b/fs/ocfs2/inode.c
@@ -221,6 +221,9 @@ int ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe,
221 goto bail; 221 goto bail;
222 } 222 }
223 223
224 OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
225 OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
226
224 inode->i_version = 1; 227 inode->i_version = 1;
225 inode->i_generation = le32_to_cpu(fe->i_generation); 228 inode->i_generation = le32_to_cpu(fe->i_generation);
226 inode->i_rdev = huge_decode_dev(le64_to_cpu(fe->id1.dev1.i_rdev)); 229 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,
232 if (S_ISLNK(inode->i_mode) && !fe->i_clusters) 235 if (S_ISLNK(inode->i_mode) && !fe->i_clusters)
233 inode->i_blocks = 0; 236 inode->i_blocks = 0;
234 else 237 else
235 inode->i_blocks = 238 inode->i_blocks = ocfs2_inode_sector_count(inode);
236 ocfs2_align_bytes_to_sectors(le64_to_cpu(fe->i_size));
237 inode->i_mapping->a_ops = &ocfs2_aops; 239 inode->i_mapping->a_ops = &ocfs2_aops;
238 inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime); 240 inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime);
239 inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec); 241 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,
248 (unsigned long long)OCFS2_I(inode)->ip_blkno, 250 (unsigned long long)OCFS2_I(inode)->ip_blkno,
249 (unsigned long long)fe->i_blkno); 251 (unsigned long long)fe->i_blkno);
250 252
251 OCFS2_I(inode)->ip_clusters = le32_to_cpu(fe->i_clusters);
252 OCFS2_I(inode)->ip_attr = le32_to_cpu(fe->i_attr);
253
254 inode->i_nlink = le16_to_cpu(fe->i_links_count); 253 inode->i_nlink = le16_to_cpu(fe->i_links_count);
255 254
256 if (fe->i_flags & cpu_to_le32(OCFS2_SYSTEM_FL)) 255 if (fe->i_flags & cpu_to_le32(OCFS2_SYSTEM_FL))
@@ -1243,7 +1242,7 @@ void ocfs2_refresh_inode(struct inode *inode,
1243 if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0) 1242 if (S_ISLNK(inode->i_mode) && le32_to_cpu(fe->i_clusters) == 0)
1244 inode->i_blocks = 0; 1243 inode->i_blocks = 0;
1245 else 1244 else
1246 inode->i_blocks = ocfs2_align_bytes_to_sectors(i_size_read(inode)); 1245 inode->i_blocks = ocfs2_inode_sector_count(inode);
1247 inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime); 1246 inode->i_atime.tv_sec = le64_to_cpu(fe->i_atime);
1248 inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec); 1247 inode->i_atime.tv_nsec = le32_to_cpu(fe->i_atime_nsec);
1249 inode->i_mtime.tv_sec = le64_to_cpu(fe->i_mtime); 1248 inode->i_mtime.tv_sec = le64_to_cpu(fe->i_mtime);
diff --git a/fs/ocfs2/inode.h b/fs/ocfs2/inode.h
index a9ced009cb9c..aa84353d0d19 100644
--- a/fs/ocfs2/inode.h
+++ b/fs/ocfs2/inode.h
@@ -138,4 +138,11 @@ int ocfs2_aio_write(struct file *file, struct kiocb *req, struct iocb *iocb);
138 138
139void ocfs2_set_inode_flags(struct inode *inode); 139void ocfs2_set_inode_flags(struct inode *inode);
140 140
141static inline blkcnt_t ocfs2_inode_sector_count(struct inode *inode)
142{
143 int c_to_s_bits = OCFS2_SB(inode->i_sb)->s_clustersize_bits - 9;
144
145 return (blkcnt_t)(OCFS2_I(inode)->ip_clusters << c_to_s_bits);
146}
147
141#endif /* OCFS2_INODE_H */ 148#endif /* OCFS2_INODE_H */
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index 12d2340eee29..5a8a90d1c787 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -650,25 +650,17 @@ static int ocfs2_force_read_journal(struct inode *inode)
650{ 650{
651 int status = 0; 651 int status = 0;
652 int i; 652 int i;
653 u64 v_blkno, p_blkno, p_blocks; 653 u64 v_blkno, p_blkno, p_blocks, num_blocks;
654#define CONCURRENT_JOURNAL_FILL 32ULL 654#define CONCURRENT_JOURNAL_FILL 32ULL
655 struct buffer_head *bhs[CONCURRENT_JOURNAL_FILL]; 655 struct buffer_head *bhs[CONCURRENT_JOURNAL_FILL];
656 656
657 mlog_entry_void(); 657 mlog_entry_void();
658 658
659 BUG_ON(inode->i_blocks !=
660 ocfs2_align_bytes_to_sectors(i_size_read(inode)));
661
662 memset(bhs, 0, sizeof(struct buffer_head *) * CONCURRENT_JOURNAL_FILL); 659 memset(bhs, 0, sizeof(struct buffer_head *) * CONCURRENT_JOURNAL_FILL);
663 660
664 mlog(0, "Force reading %llu blocks\n", 661 num_blocks = ocfs2_blocks_for_bytes(inode->i_sb, inode->i_size);
665 (unsigned long long)(inode->i_blocks >>
666 (inode->i_sb->s_blocksize_bits - 9)));
667
668 v_blkno = 0; 662 v_blkno = 0;
669 while (v_blkno < 663 while (v_blkno < num_blocks) {
670 (inode->i_blocks >> (inode->i_sb->s_blocksize_bits - 9))) {
671
672 status = ocfs2_extent_map_get_blocks(inode, v_blkno, 664 status = ocfs2_extent_map_get_blocks(inode, v_blkno,
673 &p_blkno, &p_blocks, NULL); 665 &p_blkno, &p_blocks, NULL);
674 if (status < 0) { 666 if (status < 0) {
diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
index 9bdbe4ae92f8..2bcf353fd7c5 100644
--- a/fs/ocfs2/namei.c
+++ b/fs/ocfs2/namei.c
@@ -285,7 +285,7 @@ static int ocfs2_fill_new_dir(struct ocfs2_super *osb,
285 285
286 i_size_write(inode, inode->i_sb->s_blocksize); 286 i_size_write(inode, inode->i_sb->s_blocksize);
287 inode->i_nlink = 2; 287 inode->i_nlink = 2;
288 inode->i_blocks = ocfs2_align_bytes_to_sectors(inode->i_sb->s_blocksize); 288 inode->i_blocks = ocfs2_inode_sector_count(inode);
289 status = ocfs2_mark_inode_dirty(handle, inode, fe_bh); 289 status = ocfs2_mark_inode_dirty(handle, inode, fe_bh);
290 if (status < 0) { 290 if (status < 0) {
291 mlog_errno(status); 291 mlog_errno(status);
@@ -1688,7 +1688,7 @@ static int ocfs2_symlink(struct inode *dir,
1688 goto bail; 1688 goto bail;
1689 } 1689 }
1690 i_size_write(inode, newsize); 1690 i_size_write(inode, newsize);
1691 inode->i_blocks = ocfs2_align_bytes_to_sectors(newsize); 1691 inode->i_blocks = ocfs2_inode_sector_count(inode);
1692 } else { 1692 } else {
1693 inode->i_op = &ocfs2_fast_symlink_inode_operations; 1693 inode->i_op = &ocfs2_fast_symlink_inode_operations;
1694 memcpy((char *) fe->id2.i_symlink, symname, l); 1694 memcpy((char *) fe->id2.i_symlink, symname, l);
diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
index 6dbb11762759..0da655ae5d6f 100644
--- a/fs/ocfs2/suballoc.c
+++ b/fs/ocfs2/suballoc.c
@@ -381,8 +381,7 @@ static int ocfs2_block_group_alloc(struct ocfs2_super *osb,
381 le32_to_cpu(fe->i_clusters))); 381 le32_to_cpu(fe->i_clusters)));
382 spin_unlock(&OCFS2_I(alloc_inode)->ip_lock); 382 spin_unlock(&OCFS2_I(alloc_inode)->ip_lock);
383 i_size_write(alloc_inode, le64_to_cpu(fe->i_size)); 383 i_size_write(alloc_inode, le64_to_cpu(fe->i_size));
384 alloc_inode->i_blocks = 384 alloc_inode->i_blocks = ocfs2_inode_sector_count(alloc_inode);
385 ocfs2_align_bytes_to_sectors(i_size_read(alloc_inode));
386 385
387 status = 0; 386 status = 0;
388bail: 387bail: