Allow regular files to be preallocated on-disk.
PATCH 4/13 Allow regular files to be preallocated on-disk.
Allow regular files to be preallocated on-disk up to the next multiple of the system PAGE_SIZE without complaining about extra blocks.
e2fsck/pass1.c +6 -1
@@ -1591,9 +1591,14 @@ static void check_blocks(e2fsck_t ctx, s bad_size =2 ; } }else { +e2_blkcnt_t blkpg =getpagesize () / fs->blocksize; + size =EXT2_I_SIZE (inode);if ((pb.last_block >=0 ) && - (size < (__u64 ) pb.last_block * fs->blocksize)) +/* allow allocated blocks to end of PAGE_SIZE */ + (size < (__u64 )pb.last_block * fs->blocksize) && + (pb.last_block / blkpg * blkpg != pb.last_block || + size < (__u64)(pb.last_block & ~(blkpg-1 )) *fs->blocksize)) bad_size =3 ;else if (size > ext2_max_sizes[fs->super->s_log_block_size]) bad_size =4 ;
Theodore Tso
AppliedQuoted 2 lines · Girish Shilamkar
Allow regular files to be preallocated on-disk up to the next multiple of the system
PAGE_SIZEwithout complaining about extra blocks.
Applied, with some fixups.
e2fsck/pass1.c static void check_blocks(e2fsck_t ctx, s · line 1594
Quoted 2 lines
e2fsck/pass1.c +1
-0}else { +e2_blkcnt_t blkpg =getpagesize () / fs->blocksize;
The getpagesize() call was marked LEGACY in SuSv2, and it was dropped in POSIX.1-2001. It's much better to use sysconf(_SC_PAGESIZE).
Also, the patch will cause e2fsck to core dump if it is asked to check a filesystem where fs->blocksize is > page_size. So in that case, we have to set blkpg to 1.
Finally, it's a bad idea to call getpagesize() for every single inode, since potentially getpagesize() or sysconf(_SC_PAGESIZE) could potentially require a system call. So this should be factored out and stashed away in the e2fsck context structure.
I'm also a little concerned this patch doesn't solve the problem where a filesystem that had been previously mounted on an IA64 machine gets connected to an x86 machine and then e2fsck is run. This patch doesn't make the problem any more worse, and to fix this for real would require stashing the largest blocksize ever used by the filesystem in the superblock, and I'm not entirely convinced it's worth it.
- Ted
Quoted 7 lines · Theodore Tso
I'm also a little concerned this patch doesn't solve the problem where a filesystem that had been previously mounted on an IA64 machine gets connected to an x86 machine and then e2fsck is run. This patch doesn't make the problem any more worse, and to fix this for real would require stashing the largest blocksize ever used by the filesystem in the superblock, and I'm not entirely convinced it's worth it.
At worst we get some warnings in that case and the extra blocks beyond EOF are removed.
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Quoted 11 lines · Andreas Dilger
Quoted 7 lines · Theodore Tso
I'm also a little concerned this patch doesn't solve the problem where a filesystem that had been previously mounted on an IA64 machine gets connected to an x86 machine and then e2fsck is run. This patch doesn't make the problem any more worse, and to fix this for real would require stashing the largest blocksize ever used by the filesystem in the superblock, and I'm not entirely convinced it's worth it.
At worst we get some warnings in that case and the extra blocks beyond EOF are removed.
Yep, that's why I said it's probably not worth it to worry about that case. It still bothers me a little, but that's the perfectionist in me struggling to get out. :-)
- Ted