diff options
author | Mark Fasheh <mark.fasheh@oracle.com> | 2007-07-20 15:56:16 -0400 |
---|---|---|
committer | Mark Fasheh <mark.fasheh@oracle.com> | 2007-08-09 20:25:49 -0400 |
commit | 5a25403175b8a945e93fc9c64ae9cf54f5730add (patch) | |
tree | b40693ea1e35ba8679c9b89ca91e92be3352748b /fs/ocfs2 | |
parent | ce76fd30ce98cdaeb38dca0dfbb3fa6d2801c5ce (diff) |
ocfs2: Fix max offset calculations
ocfs2_max_file_offset() was over-estimating the largest file size for
several cases. This wasn't really a problem before, but now that we support
sparse files, it needs to be more accurate.
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
Diffstat (limited to 'fs/ocfs2')
-rw-r--r-- | fs/ocfs2/super.c | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c index a100b488533e..c3c89e26567c 100644 --- a/fs/ocfs2/super.c +++ b/fs/ocfs2/super.c | |||
@@ -316,39 +316,51 @@ static void ocfs2_destroy_inode(struct inode *inode) | |||
316 | kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode)); | 316 | kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode)); |
317 | } | 317 | } |
318 | 318 | ||
319 | /* From xfs_super.c:xfs_max_file_offset | 319 | static unsigned long long ocfs2_max_file_offset(unsigned int bbits, |
320 | * Copyright (c) 2000-2004 Silicon Graphics, Inc. | 320 | unsigned int cbits) |
321 | */ | ||
322 | static unsigned long long ocfs2_max_file_offset(unsigned int blockshift) | ||
323 | { | 321 | { |
324 | unsigned int pagefactor = 1; | 322 | unsigned int bytes = 1 << cbits; |
325 | unsigned int bitshift = BITS_PER_LONG - 1; | 323 | unsigned int trim = bytes; |
326 | 324 | unsigned int bitshift = 32; | |
327 | /* Figure out maximum filesize, on Linux this can depend on | 325 | |
328 | * the filesystem blocksize (on 32 bit platforms). | 326 | /* |
329 | * __block_prepare_write does this in an [unsigned] long... | 327 | * i_size and all block offsets in ocfs2 are always 64 bits |
330 | * page->index << (PAGE_CACHE_SHIFT - bbits) | 328 | * wide. i_clusters is 32 bits, in cluster-sized units. So on |
331 | * So, for page sized blocks (4K on 32 bit platforms), | 329 | * 64 bit platforms, cluster size will be the limiting factor. |
332 | * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is | ||
333 | * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1) | ||
334 | * but for smaller blocksizes it is less (bbits = log2 bsize). | ||
335 | * Note1: get_block_t takes a long (implicit cast from above) | ||
336 | * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch | ||
337 | * can optionally convert the [unsigned] long from above into | ||
338 | * an [unsigned] long long. | ||
339 | */ | 330 | */ |
340 | 331 | ||
341 | #if BITS_PER_LONG == 32 | 332 | #if BITS_PER_LONG == 32 |
342 | # if defined(CONFIG_LBD) | 333 | # if defined(CONFIG_LBD) |
343 | BUILD_BUG_ON(sizeof(sector_t) != 8); | 334 | BUILD_BUG_ON(sizeof(sector_t) != 8); |
344 | pagefactor = PAGE_CACHE_SIZE; | 335 | /* |
345 | bitshift = BITS_PER_LONG; | 336 | * We might be limited by page cache size. |
337 | */ | ||
338 | if (bytes > PAGE_CACHE_SIZE) { | ||
339 | bytes = PAGE_CACHE_SIZE; | ||
340 | trim = 1; | ||
341 | /* | ||
342 | * Shift by 31 here so that we don't get larger than | ||
343 | * MAX_LFS_FILESIZE | ||
344 | */ | ||
345 | bitshift = 31; | ||
346 | } | ||
346 | # else | 347 | # else |
347 | pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift); | 348 | /* |
349 | * We are limited by the size of sector_t. Use block size, as | ||
350 | * that's what we expose to the VFS. | ||
351 | */ | ||
352 | bytes = 1 << bbits; | ||
353 | trim = 1; | ||
354 | bitshift = 31; | ||
348 | # endif | 355 | # endif |
349 | #endif | 356 | #endif |
350 | 357 | ||
351 | return (((unsigned long long)pagefactor) << bitshift) - 1; | 358 | /* |
359 | * Trim by a whole cluster when we can actually approach the | ||
360 | * on-disk limits. Otherwise we can overflow i_clusters when | ||
361 | * an extent start is at the max offset. | ||
362 | */ | ||
363 | return (((unsigned long long)bytes) << bitshift) - trim; | ||
352 | } | 364 | } |
353 | 365 | ||
354 | static int ocfs2_remount(struct super_block *sb, int *flags, char *data) | 366 | static int ocfs2_remount(struct super_block *sb, int *flags, char *data) |
@@ -1259,8 +1271,8 @@ static int ocfs2_initialize_super(struct super_block *sb, | |||
1259 | int sector_size) | 1271 | int sector_size) |
1260 | { | 1272 | { |
1261 | int status = 0; | 1273 | int status = 0; |
1262 | int i; | 1274 | int i, cbits, bbits; |
1263 | struct ocfs2_dinode *di = NULL; | 1275 | struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data; |
1264 | struct inode *inode = NULL; | 1276 | struct inode *inode = NULL; |
1265 | struct buffer_head *bitmap_bh = NULL; | 1277 | struct buffer_head *bitmap_bh = NULL; |
1266 | struct ocfs2_journal *journal; | 1278 | struct ocfs2_journal *journal; |
@@ -1281,7 +1293,9 @@ static int ocfs2_initialize_super(struct super_block *sb, | |||
1281 | sb->s_export_op = &ocfs2_export_ops; | 1293 | sb->s_export_op = &ocfs2_export_ops; |
1282 | sb->s_flags |= MS_NOATIME; | 1294 | sb->s_flags |= MS_NOATIME; |
1283 | /* this is needed to support O_LARGEFILE */ | 1295 | /* this is needed to support O_LARGEFILE */ |
1284 | sb->s_maxbytes = ocfs2_max_file_offset(sb->s_blocksize_bits); | 1296 | cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits); |
1297 | bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits); | ||
1298 | sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits); | ||
1285 | 1299 | ||
1286 | osb->sb = sb; | 1300 | osb->sb = sb; |
1287 | /* Save off for ocfs2_rw_direct */ | 1301 | /* Save off for ocfs2_rw_direct */ |
@@ -1341,8 +1355,6 @@ static int ocfs2_initialize_super(struct super_block *sb, | |||
1341 | goto bail; | 1355 | goto bail; |
1342 | } | 1356 | } |
1343 | 1357 | ||
1344 | di = (struct ocfs2_dinode *)bh->b_data; | ||
1345 | |||
1346 | osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots); | 1358 | osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots); |
1347 | if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) { | 1359 | if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) { |
1348 | mlog(ML_ERROR, "Invalid number of node slots (%u)\n", | 1360 | mlog(ML_ERROR, "Invalid number of node slots (%u)\n", |