linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* One question about ext4_fallocate
@ 2012-07-19 14:51 Wang Sheng-Hui
  2012-07-19 15:42 ` Andreas Dilger
  0 siblings, 1 reply; 3+ messages in thread
From: Wang Sheng-Hui @ 2012-07-19 14:51 UTC (permalink / raw)
  To: Allison Henderson, Lukas Czerner, Theodore Ts'o, linux-ext4

Dear all,

I have one question about ext4_fallocate:
	For its parameters, offset & len, it will preallocate
	one space with length >= len, right?

>From the code:
	map.m_lblk = offset >> blkbits;
	/*
	 * We can't just convert len to max_blocks because
	 * If blocksize = 4096 offset = 3072 and len = 2048
	 */
	max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits)
		- map.m_lblk;

We can see that the target space is enlarged to the (floor, ceiling) of 
(offset, offset+len). Right?

If I'm wrong, please correct me.


Regards,

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: One question about ext4_fallocate
  2012-07-19 14:51 One question about ext4_fallocate Wang Sheng-Hui
@ 2012-07-19 15:42 ` Andreas Dilger
  2012-07-20  6:39   ` Wang Sheng-Hui
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Dilger @ 2012-07-19 15:42 UTC (permalink / raw)
  To: Wang Sheng-Hui; +Cc: ext4 development


On 2012-07-19, at 7:51 AM, Wang Sheng-Hui wrote:
> I have one question about ext4_fallocate:
> 	For its parameters, offset & len, it will preallocate
> 	one space with length >= len, right?
> 
> From the code:
> 	map.m_lblk = offset >> blkbits;
> 	/*
> 	 * We can't just convert len to max_blocks because
> 	 * If blocksize = 4096 offset = 3072 and len = 2048
> 	 */
> 	max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits)
> 		- map.m_lblk;
> 
> We can see that the target space is enlarged to the (floor, ceiling) of 
> (offset, offset+len). Right?
> 
> If I'm wrong, please correct me.

A whole block has to be allocated for fallocate, but if KEEP_SIZE is not used, the i_size should be changed to match the actual requested size.

Cheers, Andreas






^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: One question about ext4_fallocate
  2012-07-19 15:42 ` Andreas Dilger
@ 2012-07-20  6:39   ` Wang Sheng-Hui
  0 siblings, 0 replies; 3+ messages in thread
From: Wang Sheng-Hui @ 2012-07-20  6:39 UTC (permalink / raw)
  To: Andreas Dilger; +Cc: ext4 development

On 2012年07月19日 23:42, Andreas Dilger wrote:
> 
> On 2012-07-19, at 7:51 AM, Wang Sheng-Hui wrote:
>> I have one question about ext4_fallocate:
>> 	For its parameters, offset & len, it will preallocate
>> 	one space with length >= len, right?
>>
>> From the code:
>> 	map.m_lblk = offset >> blkbits;
>> 	/*
>> 	 * We can't just convert len to max_blocks because
>> 	 * If blocksize = 4096 offset = 3072 and len = 2048
>> 	 */
>> 	max_blocks = (EXT4_BLOCK_ALIGN(len + offset, blkbits) >> blkbits)
>> 		- map.m_lblk;
>>
>> We can see that the target space is enlarged to the (floor, ceiling) of 
>> (offset, offset+len). Right?
>>
>> If I'm wrong, please correct me.
> 
> A whole block has to be allocated for fallocate, but if KEEP_SIZE is not used, the i_size should be changed to match the actual requested size.
> 

Got it.

From the code:
	/* Return error if mode is not supported */
	if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE))
		return -EOPNOTSUPP;

	if (mode & FALLOC_FL_PUNCH_HOLE)
		return ext4_punch_hole(file, offset, len);

ext4 only supports FALLOC_FL_KEEP_SIZE & FALLOC_FL_PUNCH_HOLE currently.
For FALLOC_FL_PUNCH_HOLE, it will turn to ext4_punch_hole, so the rest
path deals with only FALLOC_FL_KEEP_SIZE and thus it will use whole blocks.

Thanks, Andreas.
> Cheers, Andreas
> 
> 
> 
> 
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-20  6:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-19 14:51 One question about ext4_fallocate Wang Sheng-Hui
2012-07-19 15:42 ` Andreas Dilger
2012-07-20  6:39   ` Wang Sheng-Hui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).