@@ -472,8 +472,8 @@ void ext2_discard_reservation(struct inode *inode)
472472 * @block: start physical block to free
473473 * @count: number of blocks to free
474474 */
475- void ext2_free_blocks (struct inode * inode , unsigned long block ,
476- unsigned long count )
475+ void ext2_free_blocks (struct inode * inode , ext2_fsblk_t block ,
476+ unsigned long count )
477477{
478478 struct buffer_head * bitmap_bh = NULL ;
479479 struct buffer_head * bh2 ;
@@ -716,36 +716,34 @@ ext2_try_to_allocate(struct super_block *sb, int group,
716716}
717717
718718/**
719- * find_next_reservable_window():
720- * find a reservable space within the given range.
721- * It does not allocate the reservation window for now:
722- * alloc_new_reservation() will do the work later.
719+ * find_next_reservable_window - Find a reservable space within the given range.
720+ * @search_head: The list to search.
721+ * @my_rsv: The reservation we're currently using.
722+ * @sb: The super block.
723+ * @start_block: The first block we consider to start the real search from
724+ * @last_block: The maximum block number that our goal reservable space
725+ * could start from.
723726 *
724- * @search_head: the head of the searching list;
725- * This is not necessarily the list head of the whole filesystem
727+ * It does not allocate the reservation window: alloc_new_reservation()
728+ * will do the work later.
726729 *
727- * We have both head and start_block to assist the search
728- * for the reservable space. The list starts from head,
729- * but we will shift to the place where start_block is,
730- * then start from there, when looking for a reservable space.
730+ * We search the given range, rather than the whole reservation double
731+ * linked list, (start_block, last_block) to find a free region that is
732+ * of my size and has not been reserved.
731733 *
732- * @sb: the super block.
734+ * @search_head is not necessarily the list head of the whole filesystem.
735+ * We have both head and @start_block to assist the search for the
736+ * reservable space. The list starts from head, but we will shift to
737+ * the place where start_block is, then start from there, when looking
738+ * for a reservable space.
733739 *
734- * @start_block: the first block we consider to start the real search from
735- *
736- * @last_block:
737- * the maximum block number that our goal reservable space
738- * could start from. This is normally the last block in this
739- * group. The search will end when we found the start of next
740- * possible reservable space is out of this boundary.
741- * This could handle the cross boundary reservation window
742- * request.
743- *
744- * basically we search from the given range, rather than the whole
745- * reservation double linked list, (start_block, last_block)
746- * to find a free region that is of my size and has not
747- * been reserved.
740+ * @last_block is normally the last block in this group. The search will end
741+ * when we found the start of next possible reservable space is out
742+ * of this boundary. This could handle the cross boundary reservation
743+ * window request.
748744 *
745+ * Return: -1 if we could not find a range of sufficient size. If we could,
746+ * return 0 and fill in @my_rsv with the range information.
749747 */
750748static int find_next_reservable_window (
751749 struct ext2_reserve_window_node * search_head ,
@@ -833,41 +831,34 @@ static int find_next_reservable_window(
833831}
834832
835833/**
836- * alloc_new_reservation()--allocate a new reservation window
837- *
838- * To make a new reservation, we search part of the filesystem
839- * reservation list (the list that inside the group). We try to
840- * allocate a new reservation window near the allocation goal,
841- * or the beginning of the group, if there is no goal.
842- *
843- * We first find a reservable space after the goal, then from
844- * there, we check the bitmap for the first free block after
845- * it. If there is no free block until the end of group, then the
846- * whole group is full, we failed. Otherwise, check if the free
847- * block is inside the expected reservable space, if so, we
848- * succeed.
849- * If the first free block is outside the reservable space, then
850- * start from the first free block, we search for next available
851- * space, and go on.
834+ * alloc_new_reservation - Allocate a new reservation window.
835+ * @my_rsv: The reservation we're currently using.
836+ * @grp_goal: The goal block relative to the start of the group.
837+ * @sb: The super block.
838+ * @group: The group we are trying to allocate in.
839+ * @bitmap_bh: The block group block bitmap.
852840 *
853- * on succeed, a new reservation will be found and inserted into the list
854- * It contains at least one free block, and it does not overlap with other
855- * reservation windows.
841+ * To make a new reservation, we search part of the filesystem reservation
842+ * list (the list inside the group). We try to allocate a new
843+ * reservation window near @grp_goal, or the beginning of the
844+ * group, if @grp_goal is negative.
856845 *
857- * failed: we failed to find a reservation window in this group
846+ * We first find a reservable space after the goal, then from there,
847+ * we check the bitmap for the first free block after it. If there is
848+ * no free block until the end of group, then the whole group is full,
849+ * we failed. Otherwise, check if the free block is inside the expected
850+ * reservable space, if so, we succeed.
858851 *
859- * @my_rsv: the reservation
852+ * If the first free block is outside the reservable space, then start
853+ * from the first free block, we search for next available space, and
854+ * go on.
860855 *
861- * @grp_goal: The goal (group-relative). It is where the search for a
862- * free reservable space should start from.
863- * if we have a goal(goal >0 ), then start from there,
864- * no goal(goal = -1), we start from the first block
865- * of the group.
866- *
867- * @sb: the super block
868- * @group: the group we are trying to allocate in
869- * @bitmap_bh: the block group block bitmap
856+ * on succeed, a new reservation will be found and inserted into the
857+ * list. It contains at least one free block, and it does not overlap
858+ * with other reservation windows.
870859 *
860+ * Return: 0 on success, -1 if we failed to find a reservation window
861+ * in this group
871862 */
872863static int alloc_new_reservation (struct ext2_reserve_window_node * my_rsv ,
873864 ext2_grpblk_t grp_goal , struct super_block * sb ,
@@ -1131,8 +1122,13 @@ ext2_try_to_allocate_with_rsv(struct super_block *sb, unsigned int group,
11311122
11321123 if ((my_rsv -> rsv_start > group_last_block ) ||
11331124 (my_rsv -> rsv_end < group_first_block )) {
1125+ ext2_error (sb , __func__ ,
1126+ "Reservation out of group %u range goal %d fsb[%lu,%lu] rsv[%lu, %lu]" ,
1127+ group , grp_goal , group_first_block ,
1128+ group_last_block , my_rsv -> rsv_start ,
1129+ my_rsv -> rsv_end );
11341130 rsv_window_dump (& EXT2_SB (sb )-> s_rsv_window_root , 1 );
1135- BUG () ;
1131+ return -1 ;
11361132 }
11371133 ret = ext2_try_to_allocate (sb , group , bitmap_bh , grp_goal ,
11381134 & num , & my_rsv -> rsv_window );
@@ -1193,6 +1189,7 @@ int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
11931189 * @goal: given target block(filesystem wide)
11941190 * @count: target number of blocks to allocate
11951191 * @errp: error code
1192+ * @flags: allocate flags
11961193 *
11971194 * ext2_new_blocks uses a goal block to assist allocation. If the goal is
11981195 * free, or there is a free block within 32 blocks of the goal, that block
@@ -1202,7 +1199,7 @@ int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
12021199 * This function also updates quota and i_blocks field.
12031200 */
12041201ext2_fsblk_t ext2_new_blocks (struct inode * inode , ext2_fsblk_t goal ,
1205- unsigned long * count , int * errp )
1202+ unsigned long * count , int * errp , unsigned int flags )
12061203{
12071204 struct buffer_head * bitmap_bh = NULL ;
12081205 struct buffer_head * gdp_bh ;
@@ -1241,15 +1238,15 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
12411238 es = EXT2_SB (sb )-> s_es ;
12421239 ext2_debug ("goal=%lu.\n" , goal );
12431240 /*
1244- * Allocate a block from reservation only when
1245- * filesystem is mounted with reservation(default,-o reservation), and
1246- * it's a regular file, and
1247- * the desired window size is greater than 0 (One could use ioctl
1248- * command EXT2_IOC_SETRSVSZ to set the window size to 0 to turn off
1249- * reservation on that particular file)
1241+ * Allocate a block from reservation only when the filesystem is
1242+ * mounted with reservation(default,-o reservation), and it's a regular
1243+ * file, and the desired window size is greater than 0 (One could use
1244+ * ioctl command EXT2_IOC_SETRSVSZ to set the window size to 0 to turn
1245+ * off reservation on that particular file). Also do not use the
1246+ * reservation window if the caller asked us not to do it.
12501247 */
12511248 block_i = EXT2_I (inode )-> i_block_alloc_info ;
1252- if (block_i ) {
1249+ if (!( flags & EXT2_ALLOC_NORESERVE ) && block_i ) {
12531250 windowsz = block_i -> rsv_window_node .rsv_goal_size ;
12541251 if (windowsz > 0 )
12551252 my_rsv = & block_i -> rsv_window_node ;
@@ -1429,13 +1426,6 @@ ext2_fsblk_t ext2_new_blocks(struct inode *inode, ext2_fsblk_t goal,
14291426 return 0 ;
14301427}
14311428
1432- ext2_fsblk_t ext2_new_block (struct inode * inode , unsigned long goal , int * errp )
1433- {
1434- unsigned long count = 1 ;
1435-
1436- return ext2_new_blocks (inode , goal , & count , errp );
1437- }
1438-
14391429#ifdef EXT2FS_DEBUG
14401430
14411431unsigned long ext2_count_free (struct buffer_head * map , unsigned int numchars )
0 commit comments