X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=fs%2Fudf%2Fballoc.c;h=4cec9101568135fd6f18a0f50fcaf9ccd9689dc0;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=235418f35f65391d48aecb50ed70f4faeaaffc9e;hpb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;p=linux-2.6.git diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c index 235418f35..4cec91015 100644 --- a/fs/udf/balloc.c +++ b/fs/udf/balloc.c @@ -4,11 +4,6 @@ * PURPOSE * Block allocation handling routines for the OSTA-UDF(tm) filesystem. * - * CONTACTS - * E-mail regarding any portion of the Linux UDF file system should be - * directed to the development team mailing list (run by majordomo): - * linux_udf@hpesjro.fc.hp.com - * * COPYRIGHT * This file is distributed under the terms of the GNU General Public * License (GPL). Copies of the GPL can be obtained from: @@ -28,7 +23,7 @@ #include #include -#include +#include #include "udf_i.h" #include "udf_sb.h" @@ -46,7 +41,7 @@ #define uint(x) xuint(x) #define xuint(x) __le ## x -extern inline int find_next_one_bit (void * addr, int size, int offset) +static inline int find_next_one_bit (void * addr, int size, int offset) { uintBPL_t * p = ((uintBPL_t *) addr) + (offset / BITS_PER_LONG); int result = offset & ~(BITS_PER_LONG-1); @@ -148,6 +143,7 @@ static void udf_bitmap_free_blocks(struct super_block * sb, struct udf_bitmap *bitmap, kernel_lb_addr bloc, uint32_t offset, uint32_t count) { + struct udf_sb_info *sbi = UDF_SB(sb); struct buffer_head * bh = NULL; unsigned long block; unsigned long block_group; @@ -156,7 +152,7 @@ static void udf_bitmap_free_blocks(struct super_block * sb, int bitmap_nr; unsigned long overflow; - lock_super(sb); + mutex_lock(&sbi->s_alloc_mutex); if (bloc.logicalBlockNum < 0 || (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) { @@ -215,7 +211,7 @@ error_return: sb->s_dirt = 1; if (UDF_SB_LVIDBH(sb)) mark_buffer_dirty(UDF_SB_LVIDBH(sb)); - unlock_super(sb); + mutex_unlock(&sbi->s_alloc_mutex); return; } @@ -224,13 +220,13 @@ static int udf_bitmap_prealloc_blocks(struct super_block * sb, struct udf_bitmap *bitmap, uint16_t partition, uint32_t first_block, uint32_t block_count) { + struct udf_sb_info *sbi = UDF_SB(sb); int alloc_count = 0; int bit, block, block_group, group_start; int nr_groups, bitmap_nr; struct buffer_head *bh; - lock_super(sb); - + mutex_lock(&sbi->s_alloc_mutex); if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition)) goto out; @@ -279,7 +275,7 @@ out: mark_buffer_dirty(UDF_SB_LVIDBH(sb)); } sb->s_dirt = 1; - unlock_super(sb); + mutex_unlock(&sbi->s_alloc_mutex); return alloc_count; } @@ -287,6 +283,7 @@ static int udf_bitmap_new_block(struct super_block * sb, struct inode * inode, struct udf_bitmap *bitmap, uint16_t partition, uint32_t goal, int *err) { + struct udf_sb_info *sbi = UDF_SB(sb); int newbit, bit=0, block, block_group, group_start; int end_goal, nr_groups, bitmap_nr, i; struct buffer_head *bh = NULL; @@ -294,7 +291,7 @@ static int udf_bitmap_new_block(struct super_block * sb, int newblock = 0; *err = -ENOSPC; - lock_super(sb); + mutex_lock(&sbi->s_alloc_mutex); repeat: if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition)) @@ -367,7 +364,7 @@ repeat: } if (i >= (nr_groups*2)) { - unlock_super(sb); + mutex_unlock(&sbi->s_alloc_mutex); return newblock; } if (bit < sb->s_blocksize << 3) @@ -376,7 +373,7 @@ repeat: bit = udf_find_next_one_bit(bh->b_data, sb->s_blocksize << 3, group_start << 3); if (bit >= sb->s_blocksize << 3) { - unlock_super(sb); + mutex_unlock(&sbi->s_alloc_mutex); return 0; } @@ -390,7 +387,7 @@ got_block: */ if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) { - unlock_super(sb); + mutex_unlock(&sbi->s_alloc_mutex); *err = -EDQUOT; return 0; } @@ -413,13 +410,13 @@ got_block: mark_buffer_dirty(UDF_SB_LVIDBH(sb)); } sb->s_dirt = 1; - unlock_super(sb); + mutex_unlock(&sbi->s_alloc_mutex); *err = 0; return newblock; error_return: *err = -EIO; - unlock_super(sb); + mutex_unlock(&sbi->s_alloc_mutex); return 0; } @@ -428,14 +425,15 @@ static void udf_table_free_blocks(struct super_block * sb, struct inode * table, kernel_lb_addr bloc, uint32_t offset, uint32_t count) { + struct udf_sb_info *sbi = UDF_SB(sb); uint32_t start, end; - uint32_t nextoffset, oextoffset, elen; - kernel_lb_addr nbloc, obloc, eloc; - struct buffer_head *obh, *nbh; + uint32_t elen; + kernel_lb_addr eloc; + struct extent_position oepos, epos; int8_t etype; int i; - lock_super(sb); + mutex_lock(&sbi->s_alloc_mutex); if (bloc.logicalBlockNum < 0 || (bloc.logicalBlockNum + count) > UDF_SB_PARTLEN(sb, bloc.partitionReferenceNum)) { @@ -459,14 +457,13 @@ static void udf_table_free_blocks(struct super_block * sb, start = bloc.logicalBlockNum + offset; end = bloc.logicalBlockNum + offset + count - 1; - oextoffset = nextoffset = sizeof(struct unallocSpaceEntry); + epos.offset = oepos.offset = sizeof(struct unallocSpaceEntry); elen = 0; - obloc = nbloc = UDF_I_LOCATION(table); - - obh = nbh = NULL; + epos.block = oepos.block = UDF_I_LOCATION(table); + epos.bh = oepos.bh = NULL; while (count && (etype = - udf_next_aext(table, &nbloc, &nextoffset, &eloc, &elen, &nbh, 1)) != -1) + udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { if (((eloc.logicalBlockNum + (elen >> sb->s_blocksize_bits)) == start)) @@ -484,7 +481,7 @@ static void udf_table_free_blocks(struct super_block * sb, start += count; count = 0; } - udf_write_aext(table, obloc, &oextoffset, eloc, elen, obh, 1); + udf_write_aext(table, &oepos, eloc, elen, 1); } else if (eloc.logicalBlockNum == (end + 1)) { @@ -504,20 +501,20 @@ static void udf_table_free_blocks(struct super_block * sb, end -= count; count = 0; } - udf_write_aext(table, obloc, &oextoffset, eloc, elen, obh, 1); + udf_write_aext(table, &oepos, eloc, elen, 1); } - if (nbh != obh) + if (epos.bh != oepos.bh) { i = -1; - obloc = nbloc; - udf_release_data(obh); - atomic_inc(&nbh->b_count); - obh = nbh; - oextoffset = 0; + oepos.block = epos.block; + brelse(oepos.bh); + get_bh(epos.bh); + oepos.bh = epos.bh; + oepos.offset = 0; } else - oextoffset = nextoffset; + oepos.offset = epos.offset; } if (count) @@ -549,56 +546,53 @@ static void udf_table_free_blocks(struct super_block * sb, adsize = sizeof(long_ad); else { - udf_release_data(obh); - udf_release_data(nbh); + brelse(oepos.bh); + brelse(epos.bh); goto error_return; } - if (nextoffset + (2 * adsize) > sb->s_blocksize) + if (epos.offset + (2 * adsize) > sb->s_blocksize) { char *sptr, *dptr; int loffset; - udf_release_data(obh); - obh = nbh; - obloc = nbloc; - oextoffset = nextoffset; + brelse(oepos.bh); + oepos = epos; /* Steal a block from the extent being free'd */ - nbloc.logicalBlockNum = eloc.logicalBlockNum; + epos.block.logicalBlockNum = eloc.logicalBlockNum; eloc.logicalBlockNum ++; elen -= sb->s_blocksize; - if (!(nbh = udf_tread(sb, - udf_get_lb_pblock(sb, nbloc, 0)))) + if (!(epos.bh = udf_tread(sb, + udf_get_lb_pblock(sb, epos.block, 0)))) { - udf_release_data(obh); + brelse(oepos.bh); goto error_return; } - aed = (struct allocExtDesc *)(nbh->b_data); - aed->previousAllocExtLocation = cpu_to_le32(obloc.logicalBlockNum); - if (nextoffset + adsize > sb->s_blocksize) + aed = (struct allocExtDesc *)(epos.bh->b_data); + aed->previousAllocExtLocation = cpu_to_le32(oepos.block.logicalBlockNum); + if (epos.offset + adsize > sb->s_blocksize) { - loffset = nextoffset; + loffset = epos.offset; aed->lengthAllocDescs = cpu_to_le32(adsize); - if (obh) - sptr = UDF_I_DATA(inode) + nextoffset - udf_file_entry_alloc_offset(inode) + UDF_I_LENEATTR(inode) - adsize; - else - sptr = obh->b_data + nextoffset - adsize; - dptr = nbh->b_data + sizeof(struct allocExtDesc); + sptr = UDF_I_DATA(inode) + epos.offset - + udf_file_entry_alloc_offset(inode) + + UDF_I_LENEATTR(inode) - adsize; + dptr = epos.bh->b_data + sizeof(struct allocExtDesc); memcpy(dptr, sptr, adsize); - nextoffset = sizeof(struct allocExtDesc) + adsize; + epos.offset = sizeof(struct allocExtDesc) + adsize; } else { - loffset = nextoffset + adsize; + loffset = epos.offset + adsize; aed->lengthAllocDescs = cpu_to_le32(0); - sptr = (obh)->b_data + nextoffset; - nextoffset = sizeof(struct allocExtDesc); + sptr = oepos.bh->b_data + epos.offset; + epos.offset = sizeof(struct allocExtDesc); - if (obh) + if (oepos.bh) { - aed = (struct allocExtDesc *)(obh)->b_data; + aed = (struct allocExtDesc *)oepos.bh->b_data; aed->lengthAllocDescs = cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); } @@ -609,11 +603,11 @@ static void udf_table_free_blocks(struct super_block * sb, } } if (UDF_SB_UDFREV(sb) >= 0x0200) - udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1, - nbloc.logicalBlockNum, sizeof(tag)); + udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 3, 1, + epos.block.logicalBlockNum, sizeof(tag)); else - udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1, - nbloc.logicalBlockNum, sizeof(tag)); + udf_new_tag(epos.bh->b_data, TAG_IDENT_AED, 2, 1, + epos.block.logicalBlockNum, sizeof(tag)); switch (UDF_I_ALLOCTYPE(table)) { case ICBTAG_FLAG_AD_SHORT: @@ -622,7 +616,7 @@ static void udf_table_free_blocks(struct super_block * sb, sad->extLength = cpu_to_le32( EXT_NEXT_EXTENT_ALLOCDECS | sb->s_blocksize); - sad->extPosition = cpu_to_le32(nbloc.logicalBlockNum); + sad->extPosition = cpu_to_le32(epos.block.logicalBlockNum); break; } case ICBTAG_FLAG_AD_LONG: @@ -631,14 +625,14 @@ static void udf_table_free_blocks(struct super_block * sb, lad->extLength = cpu_to_le32( EXT_NEXT_EXTENT_ALLOCDECS | sb->s_blocksize); - lad->extLocation = cpu_to_lelb(nbloc); + lad->extLocation = cpu_to_lelb(epos.block); break; } } - if (obh) + if (oepos.bh) { - udf_update_tag(obh->b_data, loffset); - mark_buffer_dirty(obh); + udf_update_tag(oepos.bh->b_data, loffset); + mark_buffer_dirty(oepos.bh); } else mark_inode_dirty(table); @@ -646,30 +640,30 @@ static void udf_table_free_blocks(struct super_block * sb, if (elen) /* It's possible that stealing the block emptied the extent */ { - udf_write_aext(table, nbloc, &nextoffset, eloc, elen, nbh, 1); + udf_write_aext(table, &epos, eloc, elen, 1); - if (!nbh) + if (!epos.bh) { UDF_I_LENALLOC(table) += adsize; mark_inode_dirty(table); } else { - aed = (struct allocExtDesc *)nbh->b_data; + aed = (struct allocExtDesc *)epos.bh->b_data; aed->lengthAllocDescs = cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) + adsize); - udf_update_tag(nbh->b_data, nextoffset); - mark_buffer_dirty(nbh); + udf_update_tag(epos.bh->b_data, epos.offset); + mark_buffer_dirty(epos.bh); } } } - udf_release_data(nbh); - udf_release_data(obh); + brelse(epos.bh); + brelse(oepos.bh); error_return: sb->s_dirt = 1; - unlock_super(sb); + mutex_unlock(&sbi->s_alloc_mutex); return; } @@ -678,10 +672,11 @@ static int udf_table_prealloc_blocks(struct super_block * sb, struct inode *table, uint16_t partition, uint32_t first_block, uint32_t block_count) { + struct udf_sb_info *sbi = UDF_SB(sb); int alloc_count = 0; - uint32_t extoffset, elen, adsize; - kernel_lb_addr bloc, eloc; - struct buffer_head *bh; + uint32_t elen, adsize; + kernel_lb_addr eloc; + struct extent_position epos; int8_t etype = -1; if (first_block < 0 || first_block >= UDF_SB_PARTLEN(sb, partition)) @@ -694,16 +689,14 @@ static int udf_table_prealloc_blocks(struct super_block * sb, else return 0; - lock_super(sb); - - extoffset = sizeof(struct unallocSpaceEntry); - bloc = UDF_I_LOCATION(table); - - bh = NULL; + mutex_lock(&sbi->s_alloc_mutex); + epos.offset = sizeof(struct unallocSpaceEntry); + epos.block = UDF_I_LOCATION(table); + epos.bh = NULL; eloc.logicalBlockNum = 0xFFFFFFFF; while (first_block != eloc.logicalBlockNum && (etype = - udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1) + udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { udf_debug("eloc=%d, elen=%d, first_block=%d\n", eloc.logicalBlockNum, elen, first_block); @@ -712,7 +705,7 @@ static int udf_table_prealloc_blocks(struct super_block * sb, if (first_block == eloc.logicalBlockNum) { - extoffset -= adsize; + epos.offset -= adsize; alloc_count = (elen >> sb->s_blocksize_bits); if (inode && DQUOT_PREALLOC_BLOCK(inode, alloc_count > block_count ? block_count : alloc_count)) @@ -722,15 +715,15 @@ static int udf_table_prealloc_blocks(struct super_block * sb, alloc_count = block_count; eloc.logicalBlockNum += alloc_count; elen -= (alloc_count << sb->s_blocksize_bits); - udf_write_aext(table, bloc, &extoffset, eloc, (etype << 30) | elen, bh, 1); + udf_write_aext(table, &epos, eloc, (etype << 30) | elen, 1); } else - udf_delete_aext(table, bloc, extoffset, eloc, (etype << 30) | elen, bh); + udf_delete_aext(table, epos, eloc, (etype << 30) | elen); } else alloc_count = 0; - udf_release_data(bh); + brelse(epos.bh); if (alloc_count && UDF_SB_LVIDBH(sb)) { @@ -739,7 +732,7 @@ static int udf_table_prealloc_blocks(struct super_block * sb, mark_buffer_dirty(UDF_SB_LVIDBH(sb)); sb->s_dirt = 1; } - unlock_super(sb); + mutex_unlock(&sbi->s_alloc_mutex); return alloc_count; } @@ -747,11 +740,12 @@ static int udf_table_new_block(struct super_block * sb, struct inode * inode, struct inode *table, uint16_t partition, uint32_t goal, int *err) { + struct udf_sb_info *sbi = UDF_SB(sb); uint32_t spread = 0xFFFFFFFF, nspread = 0xFFFFFFFF; uint32_t newblock = 0, adsize; - uint32_t extoffset, goal_extoffset, elen, goal_elen = 0; - kernel_lb_addr bloc, goal_bloc, eloc, goal_eloc; - struct buffer_head *bh, *goal_bh; + uint32_t elen, goal_elen = 0; + kernel_lb_addr eloc, goal_eloc; + struct extent_position epos, goal_epos; int8_t etype; *err = -ENOSPC; @@ -763,8 +757,7 @@ static int udf_table_new_block(struct super_block * sb, else return newblock; - lock_super(sb); - + mutex_lock(&sbi->s_alloc_mutex); if (goal < 0 || goal >= UDF_SB_PARTLEN(sb, partition)) goal = 0; @@ -773,14 +766,12 @@ static int udf_table_new_block(struct super_block * sb, We store the buffer_head, bloc, and extoffset of the current closest match and use that when we are done. */ - - extoffset = sizeof(struct unallocSpaceEntry); - bloc = UDF_I_LOCATION(table); - - goal_bh = bh = NULL; + epos.offset = sizeof(struct unallocSpaceEntry); + epos.block = UDF_I_LOCATION(table); + epos.bh = goal_epos.bh = NULL; while (spread && (etype = - udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1) + udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1) { if (goal >= eloc.logicalBlockNum) { @@ -796,25 +787,25 @@ static int udf_table_new_block(struct super_block * sb, if (nspread < spread) { spread = nspread; - if (goal_bh != bh) + if (goal_epos.bh != epos.bh) { - udf_release_data(goal_bh); - goal_bh = bh; - atomic_inc(&goal_bh->b_count); + brelse(goal_epos.bh); + goal_epos.bh = epos.bh; + get_bh(goal_epos.bh); } - goal_bloc = bloc; - goal_extoffset = extoffset - adsize; + goal_epos.block = epos.block; + goal_epos.offset = epos.offset - adsize; goal_eloc = eloc; goal_elen = (etype << 30) | elen; } } - udf_release_data(bh); + brelse(epos.bh); if (spread == 0xFFFFFFFF) { - udf_release_data(goal_bh); - unlock_super(sb); + brelse(goal_epos.bh); + mutex_unlock(&sbi->s_alloc_mutex); return 0; } @@ -829,17 +820,17 @@ static int udf_table_new_block(struct super_block * sb, if (inode && DQUOT_ALLOC_BLOCK(inode, 1)) { - udf_release_data(goal_bh); - unlock_super(sb); + brelse(goal_epos.bh); + mutex_unlock(&sbi->s_alloc_mutex); *err = -EDQUOT; return 0; } if (goal_elen) - udf_write_aext(table, goal_bloc, &goal_extoffset, goal_eloc, goal_elen, goal_bh, 1); + udf_write_aext(table, &goal_epos, goal_eloc, goal_elen, 1); else - udf_delete_aext(table, goal_bloc, goal_extoffset, goal_eloc, goal_elen, goal_bh); - udf_release_data(goal_bh); + udf_delete_aext(table, goal_epos, goal_eloc, goal_elen); + brelse(goal_epos.bh); if (UDF_SB_LVIDBH(sb)) { @@ -849,7 +840,7 @@ static int udf_table_new_block(struct super_block * sb, } sb->s_dirt = 1; - unlock_super(sb); + mutex_unlock(&sbi->s_alloc_mutex); *err = 0; return newblock; } @@ -924,11 +915,14 @@ inline int udf_new_block(struct super_block * sb, struct inode * inode, uint16_t partition, uint32_t goal, int *err) { + int ret; + if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_BITMAP) { - return udf_bitmap_new_block(sb, inode, + ret = udf_bitmap_new_block(sb, inode, UDF_SB_PARTMAPS(sb)[partition].s_uspace.s_bitmap, partition, goal, err); + return ret; } else if (UDF_SB_PARTFLAGS(sb, partition) & UDF_PART_FLAG_UNALLOC_TABLE) {