[Ocfs2-tools-devel] [patch 08/11] Modify fsck.ocfs2 to be fit for sparse files.

tao.ma tao.ma at oracle.com
Fri Aug 17 10:46:50 PDT 2007


Mark Fasheh wrote:
> On Thu, Aug 16, 2007 at 01:56:01AM +0800, tao.ma wrote:
>   
>> ===================================================================
>> --- test.ocfs2-tools.orig/fsck.ocfs2/pass1.c	2007-08-16 00:27:41.000000000 -0400
>> +++ test.ocfs2-tools/fsck.ocfs2/pass1.c	2007-08-16 00:36:28.000000000 -0400
>> @@ -739,7 +739,7 @@ static int clear_block(ocfs2_filesys *fs
>>  static errcode_t o2fsck_check_blocks(ocfs2_filesys *fs, o2fsck_state *ost,
>>  				     uint64_t blkno, struct ocfs2_dinode *di)
>>  {
>> -	uint64_t expected = 0;
>> +	uint64_t expected = 0, unexpected = 0;
>>  	errcode_t ret;
>>  	struct verifying_blocks vb = {
>>  		.vb_ost = ost,
>> @@ -804,21 +804,33 @@ static errcode_t o2fsck_check_blocks(ocf
>>  		goto out;	
>>  	}
>>  
>> -	if (vb.vb_num_blocks > 0)
>> -		expected = (vb.vb_last_block + 1) * fs->fs_blocksize;
>> -
>> -	/* i_size is checked for symlinks elsewhere */
>> -	if (!S_ISLNK(di->i_mode) && di->i_size > expected &&
>> -	    prompt(ost, PY, PR_INODE_SIZE, "Inode %"PRIu64" has a size of "
>> -		   "%"PRIu64" but has %"PRIu64" bytes of actual data. "
>> -		   "Correct the file size?",
>> -		    di->i_blkno, di->i_size, expected)) {
>> -		di->i_size = expected;
>> -		o2fsck_write_inode(ost, blkno, di);
>> +	/* For a sparse file, the file size can be greater than the real
>> +	 * last block offsets recorded in the extent list, but it shouldn't be
>> +	 * less than that cluster offset since we have already allocated some
>> +	 * blocks at that offset, so if the size is too small, fix it to the
>> +	 * end of the visible cluster end.
>> +	 *
>> +	 * It is also reasonable for a file which has no allocated blocks but
>> +	 * any number of byte sizes, so we don't need to check its size either.
>> +	 */
>> +	if (vb.vb_num_blocks > 0) {
>> +		expected = ocfs2_blocks_to_clusters(fs, vb.vb_last_block + 1);
>> +		expected *=  fs->fs_clustersize;
>> +		unexpected = expected - fs->fs_clustersize;
>>     
>
> This is another area where we want slightly different checks based on
> whether the fs supports sparse files or not. Notice that if fsck is on a
> non-sparse fs and i_size > 0 but clusters = 0, you won't throw an error...
>
> It might make sense to just fully seperate the two checks into sparse and
> !sparse cases, since the requirements are so different.
> 	--Mark
>   
Yeah, I forgot that we should take these 2 situation into consideration 
for one fsck since it should be ok with the old-formatted volume.
Thanks for your advice.
> --
> Mark Fasheh
> Senior Software Developer, Oracle
> mark.fasheh at oracle.com
>   




More information about the Ocfs2-tools-devel mailing list