take a look at fs/ext4/extents.c:

/*
 * Block allocation/map/preallocation routine for extents based files
 *
 */

int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
                        ext4_lblk_t iblock,
                        unsigned long max_blocks, struct buffer_head
*bh_result,
                        int create, int extend_disksize)

basically it shows how to allocate the block, and then reserve the blocks,
allocate it, and then intialize it etc.   remember:

a.  the blocks u want, may not necessary always be contiguous from previous
b.   anytime u may be interrupted, and then the next contiguous block
suddenly takenup by someone else....

and this is another related function (per-file preallocation, or per-group
preallocation, and highlighting the comments:

/*
 * search goal blocks in preallocated space
 */
static noinline_for_stack int
ext4_mb_use_preallocated(struct ext4_allocation_context *ac)
{


        /* first, try per-file preallocation */
        rcu_read_lock();
        list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) {

                /* all fields in this condition don't change,
                 * so we can skip locking for them */
                if (ac->ac_o_ex.fe_logical < pa->pa_lstart ||
                        ac->ac_o_ex.fe_logical >= pa->pa_lstart +
pa->pa_len)
                        continue;

                /* found preallocated blocks, use them */
                spin_lock(&pa->pa_lock);
                if (pa->pa_deleted == 0 && pa->pa_free) {
                        atomic_inc(&pa->pa_count);
                        ext4_mb_use_inode_pa(ac, pa);
                        spin_unlock(&pa->pa_lock);
                        ac->ac_criteria = 10;
                        rcu_read_unlock();
                        return 1;
                }
                spin_unlock(&pa->pa_lock);
        }
        rcu_read_unlock();

        /* can we use group allocation? */
<snip>
        /* inode may have no locality group for some reason */
        lg = ac->ac_lg;
<snip>
        /*
         * search for the prealloc space that is having
         * minimal distance from the goal block.
         */
<snip>


On Sat, Jan 10, 2009 at 4:41 PM, Sandeep K Sinha <[email protected]>wrote:

> Hi,
>
> I have an inode and I want to preallocate 100 data blocks for that
> inode, through a kernel module.
>
> Which function should I invoke inside the kernel to which i intend to
> pass (inode no., no. of blocks ), so that it will fill up the inode
> with the newly allocated blocks into the inode's block table (i_data
> in incore ext2 inode or i_block in ext2 disk inode).
>
> I have both the in-core and on-disk inode with me. So, I can use both.
>
> Remember I wish to do this inside the kernel and not from user space.
>
> Sometime back I read about fallocate, which also had similar
> intentions. Any one having any idea ?
>
> --
> Regards,
> Sandeep.
>
>
>
>
>
>
> "To learn is to change. Education is a process that changes the learner."
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to [email protected]
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>


-- 
Regards,
Peter Teoh

Reply via email to