Skip to contentSkip to conversation

UDF cleanup and fixes

PATCH In review Jan Kara 6 participants 27 messages Mar 6, 2007 – May 23, 2007 UDF filesystem

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

cover UDF cleanup and fixes

Hello,

the patches attached to six following emails implement some cleanup and
fixes in the UDF code. The main two fixes are:
1) UDF now works correctly for files larger than 1GB.
2) Deleting a directory updates number of links to the parent directory correctly.
See headers of following patches for details.

The patches sustained some torturing so I hope that I did not introduce more bugs than I've fixed ;). Andrew, could you please put the patches into -mm kernels for testing? Thanks.

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs
author
#1 lore raw

PATCH 1/6 UDF cleanup and fixes

Use sector_t and loff_t for file offsets in UDF filesystem. Otherwise
an overflow may occur for long files. Also make inode_bmap() return offset in the extent in number of blocks instead of number of bytes - for most callers this is more convenient.

fs/udf/dir.c +2 -2
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20/fs/udf/dir.c linux-2.6.20-1-udf_bmap_sector_t/fs/udf/dir.c
@@ -113,7 +113,8 @@ do_udf_readdir(struct inode * dir, struc
 	loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
 	struct buffer_head * bh = NULL, * tmp, * bha[16];
 	kernel_lb_addr bloc, eloc;
-	uint32_t extoffset, elen, offset;
+	uint32_t extoffset, elen;
+	sector_t offset;
 	int i, num;
 	unsigned int dt_type;
 
@@ -129,7 +130,6 @@ do_udf_readdir(struct inode * dir, struc
 	else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2),
 		&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
 	{
-		offset >>= dir->i_sb->s_blocksize_bits;
 		block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
 		if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
 		{
fs/udf/directory.c +1 -1
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20/fs/udf/directory.c linux-2.6.20-1-udf_bmap_sector_t/fs/udf/directory.c
@@ -77,7 +77,7 @@ udf_fileident_read(struct inode *dir, lo
 	struct fileIdentDesc *cfi,
 	kernel_lb_addr *bloc, uint32_t *extoffset, 
 	kernel_lb_addr *eloc, uint32_t *elen,
-	uint32_t *offset, struct buffer_head **bh)
+	sector_t *offset, struct buffer_head **bh)
 {
 	struct fileIdentDesc *fi;
 	int i, num, block;
fs/udf/inode.c +15 -13
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20/fs/udf/inode.c linux-2.6.20-1-udf_bmap_sector_t/fs/udf/inode.c
@@ -49,7 +49,7 @@ MODULE_LICENSE("GPL");
 static mode_t udf_convert_permissions(struct fileEntry *);
 static int udf_update_inode(struct inode *, int);
 static void udf_fill_inode(struct inode *, struct buffer_head *);
-static struct buffer_head *inode_getblk(struct inode *, long, int *,
+static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
 	long *, int *);
 static int8_t udf_insert_aext(struct inode *, kernel_lb_addr, int,
 	kernel_lb_addr, uint32_t, struct buffer_head *);
@@ -354,7 +354,7 @@ udf_getblk(struct inode *inode, long blo
 	return NULL;
 }
 
-static struct buffer_head * inode_getblk(struct inode * inode, long block,
+static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
 	int *err, long *phys, int *new)
 {
 	struct buffer_head *pbh = NULL, *cbh = NULL, *nbh = NULL, *result = NULL;
@@ -364,14 +364,15 @@ static struct buffer_head * inode_getblk
 	uint32_t elen = 0;
 	kernel_lb_addr eloc, pbloc, cbloc, nbloc;
 	int c = 1;
-	uint64_t lbcount = 0, b_off = 0;
-	uint32_t newblocknum, newblock, offset = 0;
+	loff_t lbcount = 0, b_off = 0;
+	uint32_t newblocknum, newblock;
+	sector_t offset = 0;
 	int8_t etype;
 	int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum;
 	char lastblock = 0;
 
 	pextoffset = cextoffset = nextoffset = udf_file_entry_alloc_offset(inode);
-	b_off = (uint64_t)block << inode->i_sb->s_blocksize_bits;
+	b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
 	pbloc = cbloc = nbloc = UDF_I_LOCATION(inode);
 
 	/* find the extent which contains the block we are looking for.
@@ -1948,10 +1949,10 @@ int8_t udf_delete_aext(struct inode *ino
 	return (elen >> 30);
 }
 
-int8_t inode_bmap(struct inode *inode, int block, kernel_lb_addr *bloc, uint32_t *extoffset,
-	kernel_lb_addr *eloc, uint32_t *elen, uint32_t *offset, struct buffer_head **bh)
+int8_t inode_bmap(struct inode *inode, sector_t block, kernel_lb_addr *bloc, uint32_t *extoffset,
+	kernel_lb_addr *eloc, uint32_t *elen, sector_t *offset, struct buffer_head **bh)
 {
-	uint64_t lbcount = 0, bcount = (uint64_t)block << inode->i_sb->s_blocksize_bits;
+	loff_t lbcount = 0, bcount = (loff_t)block << inode->i_sb->s_blocksize_bits;
 	int8_t etype;
 
 	if (block < 0)
@@ -1968,29 +1969,30 @@ int8_t inode_bmap(struct inode *inode, i
 	{
 		if ((etype = udf_next_aext(inode, bloc, extoffset, eloc, elen, bh, 1)) == -1)
 		{
-			*offset = bcount - lbcount;
+			*offset = (bcount - lbcount) >> inode->i_sb->s_blocksize_bits;
 			UDF_I_LENEXTENTS(inode) = lbcount;
 			return -1;
 		}
 		lbcount += *elen;
 	} while (lbcount <= bcount);
 
-	*offset = bcount + *elen - lbcount;
+	*offset = (bcount + *elen - lbcount) >> inode->i_sb->s_blocksize_bits;
 
 	return etype;
 }
 
-long udf_block_map(struct inode *inode, long block)
+long udf_block_map(struct inode *inode, sector_t block)
 {
 	kernel_lb_addr eloc, bloc;
-	uint32_t offset, extoffset, elen;
+	uint32_t extoffset, elen;
+	sector_t offset;
 	struct buffer_head *bh = NULL;
 	int ret;
 
 	lock_kernel();
 
 	if (inode_bmap(inode, block, &bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
-		ret = udf_get_lb_pblock(inode->i_sb, eloc, offset >> inode->i_sb->s_blocksize_bits);
+		ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
 	else
 		ret = 0;
 
fs/udf/namei.c +6 -6
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20/fs/udf/namei.c linux-2.6.20-1-udf_bmap_sector_t/fs/udf/namei.c
@@ -156,7 +156,8 @@ udf_find_entry(struct inode *dir, struct
 	uint16_t liu;
 	loff_t size;
 	kernel_lb_addr bloc, eloc;
-	uint32_t extoffset, elen, offset;
+	uint32_t extoffset, elen;
+	sector_t offset;
 	struct buffer_head *bh = NULL;
 
 	size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
@@ -168,7 +169,6 @@ udf_find_entry(struct inode *dir, struct
 	else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
 		&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
 	{
-		offset >>= dir->i_sb->s_blocksize_bits;
 		block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
 		if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
 		{
@@ -354,7 +354,8 @@ udf_add_entry(struct inode *dir, struct 
 	uint16_t liu;
 	int block;
 	kernel_lb_addr bloc, eloc;
-	uint32_t extoffset, elen, offset;
+	uint32_t extoffset, elen;
+	sector_t offset;
 	struct buffer_head *bh = NULL;
 
 	sb = dir->i_sb;
@@ -386,7 +387,6 @@ udf_add_entry(struct inode *dir, struct 
 	else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
 		&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
 	{
-		offset >>= dir->i_sb->s_blocksize_bits;
 		block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
 		if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
 		{
@@ -782,7 +782,8 @@ static int empty_dir(struct inode *dir)
 	loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
 	int block;
 	kernel_lb_addr bloc, eloc;
-	uint32_t extoffset, elen, offset;
+	uint32_t extoffset, elen;
+	sector_t offset;
 	struct buffer_head *bh = NULL;
 
 	f_pos = (udf_ext0_offset(dir) >> 2);
@@ -794,7 +795,6 @@ static int empty_dir(struct inode *dir)
 	else if (inode_bmap(dir, f_pos >> (dir->i_sb->s_blocksize_bits - 2),
 		&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
 	{
-		offset >>= dir->i_sb->s_blocksize_bits;
 		block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
 		if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
 		{
fs/udf/truncate.c +11 -10
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20/fs/udf/truncate.c linux-2.6.20-1-udf_bmap_sector_t/fs/udf/truncate.c
@@ -125,9 +125,10 @@ void udf_discard_prealloc(struct inode *
 void udf_truncate_extents(struct inode * inode)
 {
 	kernel_lb_addr bloc, eloc, neloc = { 0, 0 };
-	uint32_t extoffset, elen, offset, nelen = 0, lelen = 0, lenalloc;
+	uint32_t extoffset, elen, nelen = 0, lelen = 0, lenalloc;
 	int8_t etype;
-	int first_block = inode->i_size >> inode->i_sb->s_blocksize_bits;
+	sector_t first_block = inode->i_size >> inode->i_sb->s_blocksize_bits, offset;
+	loff_t byte_offset;
 	struct buffer_head *bh = NULL;
 	int adsize;
 
@@ -139,14 +140,14 @@ void udf_truncate_extents(struct inode *
 		adsize = 0;
 
 	etype = inode_bmap(inode, first_block, &bloc, &extoffset, &eloc, &elen, &offset, &bh);
-	offset += (inode->i_size & (inode->i_sb->s_blocksize - 1));
+	byte_offset = (offset << inode->i_sb->s_blocksize_bits) + (inode->i_size & (inode->i_sb->s_blocksize-1));
 	if (etype != -1)
 	{
 		extoffset -= adsize;
-		extent_trunc(inode, bloc, extoffset, eloc, etype, elen, bh, offset);
+		extent_trunc(inode, bloc, extoffset, eloc, etype, elen, bh, byte_offset);
 		extoffset += adsize;
 
-		if (offset)
+		if (byte_offset)
 			lenalloc = extoffset;
 		else
 			lenalloc = extoffset - adsize;
@@ -237,7 +238,7 @@ void udf_truncate_extents(struct inode *
 	}
 	else if (inode->i_size)
 	{
-		if (offset)
+		if (byte_offset)
 		{
 			/*
 			 *  OK, there is not extent covering inode->i_size and
@@ -248,7 +249,7 @@ void udf_truncate_extents(struct inode *
 			    (bh && extoffset == sizeof(struct allocExtDesc))) {
 				/* File has no extents at all! */
 				memset(&eloc, 0x00, sizeof(kernel_lb_addr));
-				elen = EXT_NOT_RECORDED_NOT_ALLOCATED | offset;
+				elen = EXT_NOT_RECORDED_NOT_ALLOCATED | byte_offset;
 				udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &bh, 1);
 			}
 			else {
@@ -257,7 +258,7 @@ void udf_truncate_extents(struct inode *
 				if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
 				{
 					extoffset -= adsize;
-					elen = EXT_NOT_RECORDED_NOT_ALLOCATED | (elen + offset);
+					elen = EXT_NOT_RECORDED_NOT_ALLOCATED | (elen + byte_offset);
 					udf_write_aext(inode, bloc, &extoffset, eloc, elen, bh, 0);
 				}
 				else if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
@@ -265,7 +266,7 @@ void udf_truncate_extents(struct inode *
 					kernel_lb_addr neloc = { 0, 0 };
 					extoffset -= adsize;
 					nelen = EXT_NOT_RECORDED_NOT_ALLOCATED |
-						((elen + offset + inode->i_sb->s_blocksize - 1) &
+						((elen + byte_offset + inode->i_sb->s_blocksize - 1) &
 						~(inode->i_sb->s_blocksize - 1));
 					udf_write_aext(inode, bloc, &extoffset, neloc, nelen, bh, 1);
 					udf_add_aext(inode, &bloc, &extoffset, eloc, (etype << 30) | elen, &bh, 1);
@@ -281,7 +282,7 @@ void udf_truncate_extents(struct inode *
 						udf_write_aext(inode, bloc, &extoffset, eloc, elen, bh, 1);
 					}
 					memset(&eloc, 0x00, sizeof(kernel_lb_addr));
-					elen = EXT_NOT_RECORDED_NOT_ALLOCATED | offset;
+					elen = EXT_NOT_RECORDED_NOT_ALLOCATED | byte_offset;
 					udf_add_aext(inode, &bloc, &extoffset, eloc, elen, &bh, 1);
 				}
 			}
fs/udf/udfdecl.h +3 -3
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20/fs/udf/udfdecl.h linux-2.6.20-1-udf_bmap_sector_t/fs/udf/udfdecl.h
@@ -98,8 +98,8 @@ extern void udf_read_inode(struct inode 
 extern void udf_delete_inode(struct inode *);
 extern void udf_clear_inode(struct inode *);
 extern int udf_write_inode(struct inode *, int);
-extern long udf_block_map(struct inode *, long);
-extern int8_t inode_bmap(struct inode *, int, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, uint32_t *, struct buffer_head **);
+extern long udf_block_map(struct inode *, sector_t);
+extern int8_t inode_bmap(struct inode *, sector_t, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, sector_t *, struct buffer_head **);
 extern int8_t udf_add_aext(struct inode *, kernel_lb_addr *, int *, kernel_lb_addr, uint32_t, struct buffer_head **, int);
 extern int8_t udf_write_aext(struct inode *, kernel_lb_addr, int *, kernel_lb_addr, uint32_t, struct buffer_head *, int);
 extern int8_t udf_delete_aext(struct inode *, kernel_lb_addr, int, kernel_lb_addr, uint32_t, struct buffer_head *);
@@ -151,7 +151,7 @@ extern int udf_new_block(struct super_bl
 extern int udf_fsync_file(struct file *, struct dentry *, int);
 
 /* directory.c */
-extern struct fileIdentDesc * udf_fileident_read(struct inode *, loff_t *, struct udf_fileident_bh *, struct fileIdentDesc *, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, uint32_t *, struct buffer_head **);
+extern struct fileIdentDesc * udf_fileident_read(struct inode *, loff_t *, struct udf_fileident_bh *, struct fileIdentDesc *, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, sector_t *, struct buffer_head **);
 extern struct fileIdentDesc * udf_get_fileident(void * buffer, int bufsize, int * offset);
 extern long_ad * udf_get_filelongad(uint8_t *, int, int *, int);
 extern short_ad * udf_get_fileshortad(uint8_t *, int, int *, int);
#2 lore raw
Quoted 4 lines · Jan Kara

Use sector_t and loff_t for file offsets in UDF filesystem. Otherwise
an overflow may occur for long files. Also make inode_bmap() return offset in the extent in number of blocks instead of number of bytes - for most callers this is more convenient.

Looks good, but can you make sure to add line breaks after 80 chars in all the lines you touch?

author
#3 lore raw

PATCH 2/6 UDF cleanup and fixes

In reply to Jan Kara

Introduce a structure extent_position to store a position of an extent and the corresponding buffer_head in one place.

fs/udf/balloc.c +83 -89
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-1-udf_bmap_sector_t/fs/udf/balloc.c linux-2.6.20-2-udf_extent_position_t/fs/udf/balloc.c
@@ -427,9 +427,9 @@ static void udf_table_free_blocks(struct
 {
 	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;
 
@@ -457,14 +457,13 @@ static void udf_table_free_blocks(struct
 	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))
@@ -482,7 +481,7 @@ static void udf_table_free_blocks(struct
 				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))
 		{
@@ -502,20 +501,20 @@ static void udf_table_free_blocks(struct
 				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;
+			udf_release_data(oepos.bh);
+			atomic_inc(&epos.bh->b_count);
+			oepos.bh = epos.bh;
+			oepos.offset = 0;
 		}
 		else
-			oextoffset = nextoffset;
+			oepos.offset = epos.offset;
 	}
 
 	if (count)
@@ -547,55 +546,53 @@ static void udf_table_free_blocks(struct
 			adsize = sizeof(long_ad);
 		else
 		{
-			udf_release_data(obh);
-			udf_release_data(nbh);
+			udf_release_data(oepos.bh);
+			udf_release_data(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;
+			udf_release_data(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);
+				udf_release_data(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);
-				sptr = UDF_I_DATA(inode) + nextoffset -
+				sptr = UDF_I_DATA(inode) + epos.offset -
 					udf_file_entry_alloc_offset(inode) +
 					UDF_I_LENEATTR(inode) - adsize;
-				dptr = nbh->b_data + sizeof(struct allocExtDesc);
+				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);
 				}
@@ -606,11 +603,11 @@ static void udf_table_free_blocks(struct
 				}
 			}
 			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:
@@ -619,7 +616,7 @@ static void udf_table_free_blocks(struct
 					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:
@@ -628,14 +625,14 @@ static void udf_table_free_blocks(struct
 					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);
@@ -643,26 +640,26 @@ static void udf_table_free_blocks(struct
 
 		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);
+	udf_release_data(epos.bh);
+	udf_release_data(oepos.bh);
 
 error_return:
 	sb->s_dirt = 1;
@@ -677,9 +674,9 @@ static int udf_table_prealloc_blocks(str
 {
 	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))
@@ -693,14 +690,13 @@ static int udf_table_prealloc_blocks(str
 		return 0;
 
 	mutex_lock(&sbi->s_alloc_mutex);
-	extoffset = sizeof(struct unallocSpaceEntry);
-	bloc = UDF_I_LOCATION(table);
-
-	bh = NULL;
+	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);
@@ -709,7 +705,7 @@ static int udf_table_prealloc_blocks(str
 
 	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))
@@ -719,15 +715,15 @@ static int udf_table_prealloc_blocks(str
 			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);
+	udf_release_data(epos.bh);
 
 	if (alloc_count && UDF_SB_LVIDBH(sb))
 	{
@@ -747,9 +743,9 @@ static int udf_table_new_block(struct su
 	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;
@@ -770,14 +766,12 @@ static int udf_table_new_block(struct su
 	   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)
 		{
@@ -793,24 +787,24 @@ static int udf_table_new_block(struct su
 		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);
+				udf_release_data(goal_epos.bh);
+				goal_epos.bh = epos.bh;
+				atomic_inc(&goal_epos.bh->b_count);
 			}
-			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);
+	udf_release_data(epos.bh);
 
 	if (spread == 0xFFFFFFFF)
 	{
-		udf_release_data(goal_bh);
+		udf_release_data(goal_epos.bh);
 		mutex_unlock(&sbi->s_alloc_mutex);
 		return 0;
 	}
@@ -826,17 +820,17 @@ static int udf_table_new_block(struct su
 
 	if (inode && DQUOT_ALLOC_BLOCK(inode, 1))
 	{
-		udf_release_data(goal_bh);
+		udf_release_data(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);
+	udf_release_data(goal_epos.bh);
 
 	if (UDF_SB_LVIDBH(sb))
 	{
fs/udf/dir.c +13 -12
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-1-udf_bmap_sector_t/fs/udf/dir.c linux-2.6.20-2-udf_extent_position_t/fs/udf/dir.c
@@ -111,12 +111,13 @@ do_udf_readdir(struct inode * dir, struc
 	uint16_t liu;
 	uint8_t lfi;
 	loff_t size = (udf_ext0_offset(dir) + dir->i_size) >> 2;
-	struct buffer_head * bh = NULL, * tmp, * bha[16];
-	kernel_lb_addr bloc, eloc;
-	uint32_t extoffset, elen;
+	struct buffer_head *tmp, *bha[16];
+	kernel_lb_addr eloc;
+	uint32_t elen;
 	sector_t offset;
 	int i, num;
 	unsigned int dt_type;
+	struct extent_position epos = { NULL, 0, {0, 0}};
 
 	if (nf_pos >= size)
 		return 0;
@@ -128,22 +129,22 @@ do_udf_readdir(struct inode * dir, struc
 	if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_IN_ICB)
 		fibh.sbh = fibh.ebh = NULL;
 	else if (inode_bmap(dir, nf_pos >> (dir->i_sb->s_blocksize_bits - 2),
-		&bloc, &extoffset, &eloc, &elen, &offset, &bh) == (EXT_RECORDED_ALLOCATED >> 30))
+		&epos, &eloc, &elen, &offset) == (EXT_RECORDED_ALLOCATED >> 30))
 	{
 		block = udf_get_lb_pblock(dir->i_sb, eloc, offset);
 		if ((++offset << dir->i_sb->s_blocksize_bits) < elen)
 		{
 			if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_SHORT)
-				extoffset -= sizeof(short_ad);
+				epos.offset -= sizeof(short_ad);
 			else if (UDF_I_ALLOCTYPE(dir) == ICBTAG_FLAG_AD_LONG)
-				extoffset -= sizeof(long_ad);
+				epos.offset -= sizeof(long_ad);
 		}
 		else
 			offset = 0;
 
 		if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block)))
 		{
-			udf_release_data(bh);
+			udf_release_data(epos.bh);
 			return -EIO;
 		}
 	
@@ -171,7 +172,7 @@ do_udf_readdir(struct inode * dir, struc
 	}
 	else
 	{
-		udf_release_data(bh);
+		udf_release_data(epos.bh);
 		return -ENOENT;
 	}
 
@@ -179,14 +180,14 @@ do_udf_readdir(struct inode * dir, struc
 	{
 		filp->f_pos = nf_pos + 1;
 
-		fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &bloc, &extoffset, &eloc, &elen, &offset, &bh);
+		fi = udf_fileident_read(dir, &nf_pos, &fibh, &cfi, &epos, &eloc, &elen, &offset);
 
 		if (!fi)
 		{
 			if (fibh.sbh != fibh.ebh)
 				udf_release_data(fibh.ebh);
 			udf_release_data(fibh.sbh);
-			udf_release_data(bh);
+			udf_release_data(epos.bh);
 			return 0;
 		}
 
@@ -246,7 +247,7 @@ do_udf_readdir(struct inode * dir, struc
 				if (fibh.sbh != fibh.ebh)
 					udf_release_data(fibh.ebh);
 				udf_release_data(fibh.sbh);
-				udf_release_data(bh);
+				udf_release_data(epos.bh);
 	 			return 0;
 			}
 		}
@@ -257,7 +258,7 @@ do_udf_readdir(struct inode * dir, struc
 	if (fibh.sbh != fibh.ebh)
 		udf_release_data(fibh.ebh);
 	udf_release_data(fibh.sbh);
-	udf_release_data(bh);
+	udf_release_data(epos.bh);
 
 	return 0;
 }
fs/udf/directory.c +8 -12
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-1-udf_bmap_sector_t/fs/udf/directory.c linux-2.6.20-2-udf_extent_position_t/fs/udf/directory.c
@@ -75,9 +75,9 @@ struct fileIdentDesc *
 udf_fileident_read(struct inode *dir, loff_t *nf_pos,
 	struct udf_fileident_bh *fibh,
 	struct fileIdentDesc *cfi,
-	kernel_lb_addr *bloc, uint32_t *extoffset, 
+	struct extent_position *epos,
 	kernel_lb_addr *eloc, uint32_t *elen,
-	sector_t *offset, struct buffer_head **bh)
+	sector_t *offset)
 {
 	struct fileIdentDesc *fi;
 	int i, num, block;
@@ -105,13 +105,11 @@ udf_fileident_read(struct inode *dir, lo
 
 	if (fibh->eoffset == dir->i_sb->s_blocksize)
 	{
-		int lextoffset = *extoffset;
+		int lextoffset = epos->offset;
 
-		if (udf_next_aext(dir, bloc, extoffset, eloc, elen, bh, 1) !=
+		if (udf_next_aext(dir, epos, eloc, elen, 1) !=
 			(EXT_RECORDED_ALLOCATED >> 30))
-		{
 			return NULL;
-		}
 
 		block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
 
@@ -120,7 +118,7 @@ udf_fileident_read(struct inode *dir, lo
 		if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
 			*offset = 0;
 		else
-			*extoffset = lextoffset;
+			epos->offset = lextoffset;
 
 		udf_release_data(fibh->sbh);
 		if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block)))
@@ -169,13 +167,11 @@ udf_fileident_read(struct inode *dir, lo
 	}
 	else if (fibh->eoffset > dir->i_sb->s_blocksize)
 	{
-		int lextoffset = *extoffset;
+		int lextoffset = epos->offset;
 
-		if (udf_next_aext(dir, bloc, extoffset, eloc, elen, bh, 1) !=
+		if (udf_next_aext(dir, epos, eloc, elen, 1) !=
 			(EXT_RECORDED_ALLOCATED >> 30))
-		{
 			return NULL;
-		}
 
 		block = udf_get_lb_pblock(dir->i_sb, *eloc, *offset);
 
@@ -184,7 +180,7 @@ udf_fileident_read(struct inode *dir, lo
 		if ((*offset << dir->i_sb->s_blocksize_bits) >= *elen)
 			*offset = 0;
 		else
-			*extoffset = lextoffset;
+			epos->offset = lextoffset;
 
 		fibh->soffset -= dir->i_sb->s_blocksize;
 		fibh->eoffset -= dir->i_sb->s_blocksize;
fs/udf/inode.c +169 -174

722 lines not on this page · raw message

fs/udf/namei.c +61 -61

350 lines not on this page · raw message

fs/udf/super.c +8 -9
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-1-udf_bmap_sector_t/fs/udf/super.c linux-2.6.20-2-udf_extent_position_t/fs/udf/super.c
@@ -1885,21 +1885,20 @@ static unsigned int
 udf_count_free_table(struct super_block *sb, struct inode * table)
 {
 	unsigned int accum = 0;
-	uint32_t extoffset, elen;
-	kernel_lb_addr bloc, eloc;
+	uint32_t elen;
+	kernel_lb_addr eloc;
 	int8_t etype;
-	struct buffer_head *bh = NULL;
+	struct extent_position epos;
 
 	lock_kernel();
 
-	bloc = UDF_I_LOCATION(table);
-	extoffset = sizeof(struct unallocSpaceEntry);
+	epos.block = UDF_I_LOCATION(table);
+	epos.offset = sizeof(struct unallocSpaceEntry);
+	epos.bh = NULL;
 
-	while ((etype = udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
-	{
+	while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
 		accum += (elen >> table->i_sb->s_blocksize_bits);
-	}
-	udf_release_data(bh);
+	udf_release_data(epos.bh);
 
 	unlock_kernel();
 
fs/udf/truncate.c +79 -82

319 lines not on this page · raw message

fs/udf/udfdecl.h +14 -7
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-1-udf_bmap_sector_t/fs/udf/udfdecl.h linux-2.6.20-2-udf_extent_position_t/fs/udf/udfdecl.h
@@ -77,6 +77,13 @@ struct ustr
 	uint8_t u_len;
 };
 
+struct extent_position {
+	struct buffer_head *bh;
+	uint32_t offset;
+	kernel_lb_addr block;
+};
+
+
 /* super.c */
 extern void udf_error(struct super_block *, const char *, const char *, ...);
 extern void udf_warning(struct super_block *, const char *, const char *, ...);
@@ -99,12 +106,12 @@ extern void udf_delete_inode(struct inod
 extern void udf_clear_inode(struct inode *);
 extern int udf_write_inode(struct inode *, int);
 extern long udf_block_map(struct inode *, sector_t);
-extern int8_t inode_bmap(struct inode *, sector_t, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, sector_t *, struct buffer_head **);
-extern int8_t udf_add_aext(struct inode *, kernel_lb_addr *, int *, kernel_lb_addr, uint32_t, struct buffer_head **, int);
-extern int8_t udf_write_aext(struct inode *, kernel_lb_addr, int *, kernel_lb_addr, uint32_t, struct buffer_head *, int);
-extern int8_t udf_delete_aext(struct inode *, kernel_lb_addr, int, kernel_lb_addr, uint32_t, struct buffer_head *);
-extern int8_t udf_next_aext(struct inode *, kernel_lb_addr *, int *, kernel_lb_addr *, uint32_t *, struct buffer_head **, int);
-extern int8_t udf_current_aext(struct inode *, kernel_lb_addr *, int *, kernel_lb_addr *, uint32_t *, struct buffer_head **, int);
+extern int8_t inode_bmap(struct inode *, sector_t, struct extent_position *, kernel_lb_addr *, uint32_t *, sector_t *);
+extern int8_t udf_add_aext(struct inode *, struct extent_position *, kernel_lb_addr, uint32_t, int);
+extern int8_t udf_write_aext(struct inode *, struct extent_position *, kernel_lb_addr, uint32_t, int);
+extern int8_t udf_delete_aext(struct inode *, struct extent_position, kernel_lb_addr, uint32_t);
+extern int8_t udf_next_aext(struct inode *, struct extent_position *, kernel_lb_addr *, uint32_t *, int);
+extern int8_t udf_current_aext(struct inode *, struct extent_position *, kernel_lb_addr *, uint32_t *, int);
 
 /* misc.c */
 extern struct buffer_head *udf_tgetblk(struct super_block *, int);
@@ -151,7 +158,7 @@ extern int udf_new_block(struct super_bl
 extern int udf_fsync_file(struct file *, struct dentry *, int);
 
 /* directory.c */
-extern struct fileIdentDesc * udf_fileident_read(struct inode *, loff_t *, struct udf_fileident_bh *, struct fileIdentDesc *, kernel_lb_addr *, uint32_t *, kernel_lb_addr *, uint32_t *, sector_t *, struct buffer_head **);
+extern struct fileIdentDesc * udf_fileident_read(struct inode *, loff_t *, struct udf_fileident_bh *, struct fileIdentDesc *, struct extent_position *, kernel_lb_addr *, uint32_t *, sector_t *);
 extern struct fileIdentDesc * udf_get_fileident(void * buffer, int bufsize, int * offset);
 extern long_ad * udf_get_filelongad(uint8_t *, int, int *, int);
 extern short_ad * udf_get_fileshortad(uint8_t *, int, int *, int);
#4 lore raw
Quoted 2 lines · Jan Kara

Introduce a structure extent_position to store a position of an extent and the corresponding buffer_head in one place.

Looks good.

author
#5 lore raw

PATCH 3/6 UDF cleanup and fixes

In reply to Jan Kara

Make UDF use get_bh() instead of directly accessing b_count and use brelse() instead of udf_release_data() which does just brelse()...

fs/udf/balloc.c +19 -16
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-2-udf_extent_position_t/fs/udf/balloc.c linux-2.6.20-3-udf_buffer_handling/fs/udf/balloc.c
@@ -508,8 +508,8 @@ static void udf_table_free_blocks(struct
 		{
 			i = -1;
 			oepos.block = epos.block;
-			udf_release_data(oepos.bh);
-			atomic_inc(&epos.bh->b_count);
+			brelse(oepos.bh);
+			get_bh(epos.bh);
 			oepos.bh = epos.bh;
 			oepos.offset = 0;
 		}
@@ -546,8 +546,8 @@ static void udf_table_free_blocks(struct
 			adsize = sizeof(long_ad);
 		else
 		{
-			udf_release_data(oepos.bh);
-			udf_release_data(epos.bh);
+			brelse(oepos.bh);
+			brelse(epos.bh);
 			goto error_return;
 		}
 
@@ -556,7 +556,7 @@ static void udf_table_free_blocks(struct
 			char *sptr, *dptr;
 			int loffset;
 	
-			udf_release_data(oepos.bh);
+			brelse(oepos.bh);
 			oepos = epos;
 
 			/* Steal a block from the extent being free'd */
@@ -567,7 +567,7 @@ static void udf_table_free_blocks(struct
 			if (!(epos.bh = udf_tread(sb,
 				udf_get_lb_pblock(sb, epos.block, 0))))
 			{
-				udf_release_data(oepos.bh);
+				brelse(oepos.bh);
 				goto error_return;
 			}
 			aed = (struct allocExtDesc *)(epos.bh->b_data);
@@ -658,8 +658,8 @@ static void udf_table_free_blocks(struct
 		}
 	}
 
-	udf_release_data(epos.bh);
-	udf_release_data(oepos.bh);
+	brelse(epos.bh);
+	brelse(oepos.bh);
 
 error_return:
 	sb->s_dirt = 1;
@@ -723,7 +723,7 @@ static int udf_table_prealloc_blocks(str
 	else
 		alloc_count = 0;
 
-	udf_release_data(epos.bh);
+	brelse(epos.bh);
 
 	if (alloc_count && UDF_SB_LVIDBH(sb))
 	{
@@ -789,9 +789,9 @@ static int udf_table_new_block(struct su
 			spread = nspread;
 			if (goal_epos.bh != epos.bh)
 			{
-				udf_release_data(goal_epos.bh);
+				brelse(goal_epos.bh);
 				goal_epos.bh = epos.bh;
-				atomic_inc(&goal_epos.bh->b_count);
+				get_bh(goal_epos.bh);
 			}
 			goal_epos.block = epos.block;
 			goal_epos.offset = epos.offset - adsize;
@@ -800,11 +800,11 @@ static int udf_table_new_block(struct su
 		}
 	}
 
-	udf_release_data(epos.bh);
+	brelse(epos.bh);
 
 	if (spread == 0xFFFFFFFF)
 	{
-		udf_release_data(goal_epos.bh);
+		brelse(goal_epos.bh);
 		mutex_unlock(&sbi->s_alloc_mutex);
 		return 0;
 	}
@@ -820,7 +820,7 @@ static int udf_table_new_block(struct su
 
 	if (inode && DQUOT_ALLOC_BLOCK(inode, 1))
 	{
-		udf_release_data(goal_epos.bh);
+		brelse(goal_epos.bh);
 		mutex_unlock(&sbi->s_alloc_mutex);
 		*err = -EDQUOT;
 		return 0;
@@ -830,7 +830,7 @@ static int udf_table_new_block(struct su
 		udf_write_aext(table, &goal_epos, goal_eloc, goal_elen, 1);
 	else
 		udf_delete_aext(table, goal_epos, goal_eloc, goal_elen);
-	udf_release_data(goal_epos.bh);
+	brelse(goal_epos.bh);
 
 	if (UDF_SB_LVIDBH(sb))
 	{
@@ -915,11 +915,14 @@ inline int udf_new_block(struct super_bl
 	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)
 	{
fs/udf/dir.c +11 -11
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-2-udf_extent_position_t/fs/udf/dir.c linux-2.6.20-3-udf_buffer_handling/fs/udf/dir.c
@@ -144,7 +144,7 @@ do_udf_readdir(struct inode * dir, struc
 
 		if (!(fibh.sbh = fibh.ebh = udf_tread(dir->i_sb, block)))
 		{
-			udf_release_data(epos.bh);
+			brelse(epos.bh);
 			return -EIO;
 		}
 	
@@ -172,7 +172,7 @@ do_udf_readdir(struct inode * dir, struc
 	}
 	else
 	{
-		udf_release_data(epos.bh);
+		brelse(epos.bh);
 		return -ENOENT;
 	}
 
@@ -185,9 +185,9 @@ do_udf_readdir(struct inode * dir, struc
 		if (!fi)
 		{
 			if (fibh.sbh != fibh.ebh)
-				udf_release_data(fibh.ebh);
-			udf_release_data(fibh.sbh);
-			udf_release_data(epos.bh);
+				brelse(fibh.ebh);
+			brelse(fibh.sbh);
+			brelse(epos.bh);
 			return 0;
 		}
 
@@ -245,9 +245,9 @@ do_udf_readdir(struct inode * dir, struc
 			if (filldir(dirent, fname, flen, filp->f_pos, iblock, dt_type) < 0)
 			{
 				if (fibh.sbh != fibh.ebh)
-					udf_release_data(fibh.ebh);
-				udf_release_data(fibh.sbh);
-				udf_release_data(epos.bh);
+					brelse(fibh.ebh);
+				brelse(fibh.sbh);
+				brelse(epos.bh);
 	 			return 0;
 			}
 		}
@@ -256,9 +256,9 @@ do_udf_readdir(struct inode * dir, struc
 	filp->f_pos = nf_pos + 1;
 
 	if (fibh.sbh != fibh.ebh)
-		udf_release_data(fibh.ebh);
-	udf_release_data(fibh.sbh);
-	udf_release_data(epos.bh);
+		brelse(fibh.ebh);
+	brelse(fibh.sbh);
+	brelse(epos.bh);
 
 	return 0;
 }
fs/udf/directory.c +5 -5
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-2-udf_extent_position_t/fs/udf/directory.c linux-2.6.20-3-udf_buffer_handling/fs/udf/directory.c
@@ -36,14 +36,14 @@ udf_filead_read(struct inode *dir, uint8
 
 	if (!ad)
 	{
-		udf_release_data(*bh);
+		brelse(*bh);
 		*error = 1;
 		return NULL;
 	}
 
 	if (*offset == dir->i_sb->s_blocksize)
 	{
-		udf_release_data(*bh);
+		brelse(*bh);
 		block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
 		if (!block)
 			return NULL;
@@ -57,7 +57,7 @@ udf_filead_read(struct inode *dir, uint8
 		remainder = dir->i_sb->s_blocksize - loffset;
 		memcpy((uint8_t *)ad, (*bh)->b_data + loffset, remainder);
 
-		udf_release_data(*bh);
+		brelse(*bh);
 		block = udf_get_lb_pblock(dir->i_sb, fe_loc, ++*pos);
 		if (!block)
 			return NULL;
@@ -120,7 +120,7 @@ udf_fileident_read(struct inode *dir, lo
 		else
 			epos->offset = lextoffset;
 
-		udf_release_data(fibh->sbh);
+		brelse(fibh->sbh);
 		if (!(fibh->sbh = fibh->ebh = udf_tread(dir->i_sb, block)))
 			return NULL;
 		fibh->soffset = fibh->eoffset = 0;
@@ -149,7 +149,7 @@ udf_fileident_read(struct inode *dir, lo
 	}
 	else if (fibh->sbh != fibh->ebh)
 	{
-		udf_release_data(fibh->sbh);
+		brelse(fibh->sbh);
 		fibh->sbh = fibh->ebh;
 	}
 
fs/udf/inode.c +37 -37

218 lines not on this page · raw message

fs/udf/misc.c +0 -6
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-2-udf_extent_position_t/fs/udf/misc.c linux-2.6.20-3-udf_buffer_handling/fs/udf/misc.c
@@ -274,12 +274,6 @@ udf_read_ptagged(struct super_block *sb,
 		loc.logicalBlockNum + offset, ident);
 }
 
-void udf_release_data(struct buffer_head *bh)
-{
-	if (bh)
-		brelse(bh);
-}
-
 void udf_update_tag(char *data, int length)
 {
 	tag *tptr = (tag *)data;
fs/udf/namei.c +68 -68

355 lines not on this page · raw message

fs/udf/partition.c +1 -1
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-2-udf_extent_position_t/fs/udf/partition.c linux-2.6.20-3-udf_buffer_handling/fs/udf/partition.c
@@ -81,7 +81,7 @@ uint32_t udf_get_pblock_virt15(struct su
 
 	loc = le32_to_cpu(((__le32 *)bh->b_data)[index]);
 
-	udf_release_data(bh);
+	brelse(bh);
 
 	if (UDF_I_LOCATION(UDF_SB_VAT(sb)).partitionReferenceNum == partition)
 	{
fs/udf/super.c +28 -28

218 lines not on this page · raw message

fs/udf/symlink.c +1 -1
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-2-udf_extent_position_t/fs/udf/symlink.c linux-2.6.20-3-udf_buffer_handling/fs/udf/symlink.c
@@ -95,7 +95,7 @@ static int udf_symlink_filler(struct fil
 	}
 
 	udf_pc_to_char(inode->i_sb, symlink, inode->i_size, p);
-	udf_release_data(bh);
+	brelse(bh);
 
 	unlock_kernel();
 	SetPageUptodate(page);
fs/udf/truncate.c +2 -2
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-2-udf_extent_position_t/fs/udf/truncate.c linux-2.6.20-3-udf_buffer_handling/fs/udf/truncate.c
@@ -119,7 +119,7 @@ void udf_discard_prealloc(struct inode *
 	}
 	UDF_I_LENEXTENTS(inode) = lbcount;
 
-	udf_release_data(epos.bh);
+	brelse(epos.bh);
 }
 
 void udf_truncate_extents(struct inode * inode)
@@ -287,5 +287,5 @@ void udf_truncate_extents(struct inode *
 	}
 	UDF_I_LENEXTENTS(inode) = inode->i_size;
 
-	udf_release_data(epos.bh);
+	brelse(epos.bh);
 }
fs/udf/udfdecl.h +1 -1
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-2-udf_extent_position_t/fs/udf/udfdecl.h linux-2.6.20-3-udf_buffer_handling/fs/udf/udfdecl.h
@@ -106,6 +106,7 @@ extern void udf_delete_inode(struct inod
 extern void udf_clear_inode(struct inode *);
 extern int udf_write_inode(struct inode *, int);
 extern long udf_block_map(struct inode *, sector_t);
+extern int udf_extend_file(struct inode *, struct extent_position *, kernel_long_ad *, sector_t);
 extern int8_t inode_bmap(struct inode *, sector_t, struct extent_position *, kernel_lb_addr *, uint32_t *, sector_t *);
 extern int8_t udf_add_aext(struct inode *, struct extent_position *, kernel_lb_addr, uint32_t, int);
 extern int8_t udf_write_aext(struct inode *, struct extent_position *, kernel_lb_addr, uint32_t, int);
@@ -120,7 +121,6 @@ extern struct genericFormat *udf_add_ext
 extern struct genericFormat *udf_get_extendedattr(struct inode *, uint32_t, uint8_t);
 extern struct buffer_head *udf_read_tagged(struct super_block *, uint32_t, uint32_t, uint16_t *);
 extern struct buffer_head *udf_read_ptagged(struct super_block *, kernel_lb_addr, uint32_t, uint16_t *);
-extern void udf_release_data(struct buffer_head *);
 extern void udf_update_tag(char *, int);
 extern void udf_new_tag(char *, uint16_t, uint16_t, uint16_t, uint32_t, int);
 
fs/udf/udf_sb.h +1 -1
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-2-udf_extent_position_t/fs/udf/udf_sb.h linux-2.6.20-3-udf_buffer_handling/fs/udf/udf_sb.h
@@ -93,7 +93,7 @@ static inline struct udf_sb_info *UDF_SB
 	for (i=0; i<nr_groups; i++)\
 	{\
 		if (UDF_SB_BITMAP(X,Y,Z,i))\
-			udf_release_data(UDF_SB_BITMAP(X,Y,Z,i));\
+			brelse(UDF_SB_BITMAP(X,Y,Z,i));\
 	}\
 	if (size <= PAGE_SIZE)\
 		kfree(UDF_SB_PARTMAPS(X)[Y].Z.s_bitmap);\
#6 lore raw
Quoted 2 lines · Jan Kara

Make UDF use get_bh() instead of directly accessing b_count and use brelse() instead of udf_release_data() which does just brelse()...

Looks good.

author
#7 lore raw

PATCH 4/6 UDF cleanup and fixes

In reply to Jan Kara

Add a few assertions into udf_discard_prealloc() to check that the file is sane (mostly helps debugging further patches ;).

fs/udf/truncate.c +3 -1
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-3-udf_buffer_handling/fs/udf/truncate.c linux-2.6.20-4-udf_discard_prealloc_cleanup/fs/udf/truncate.c
@@ -88,8 +88,9 @@ void udf_discard_prealloc(struct inode *
 	{
 		etype = netype;
 		lbcount += elen;
-		if (lbcount > inode->i_size && lbcount - inode->i_size < inode->i_sb->s_blocksize)
+		if (lbcount > inode->i_size && lbcount - elen < inode->i_size)
 		{
+			WARN_ON(lbcount - inode->i_size >= inode->i_sb->s_blocksize);
 			nelen = elen - (lbcount - inode->i_size);
 			epos.offset -= adsize;
 			extent_trunc(inode, &epos, eloc, etype, elen, nelen);
@@ -119,6 +120,7 @@ void udf_discard_prealloc(struct inode *
 	}
 	UDF_I_LENEXTENTS(inode) = lbcount;
 
+	WARN_ON(lbcount != inode->i_size);
 	brelse(epos.bh);
 }
 
#8 lore raw
Quoted 2 lines · Jan Kara

Add a few assertions into udf_discard_prealloc() to check that the file is sane (mostly helps debugging further patches ;).

Ok.

author
#9 lore raw

PATCH 5/6 UDF cleanup and fixes

In reply to Jan Kara

Make UDF work correctly for files larger than 1GB. As no extent can be longer than (1<<30)-blocksize bytes, we have to create several extents if a big hole is being created. As a side-effect, we now don't discard preallocated blocks when creating a hole.

fs/udf/inode.c +157 -35
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-4-udf_discard_prealloc_cleanup/fs/udf/inode.c linux-2.6.20-5-large_file_fix/fs/udf/inode.c
@@ -356,9 +356,106 @@ udf_getblk(struct inode *inode, long blo
 	return NULL;
 }
 
+/* Extend the file by 'blocks' blocks, return the number of extents added */
+int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
+	kernel_long_ad *last_ext, sector_t blocks)
+{
+	sector_t add;
+	int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
+	struct super_block *sb = inode->i_sb;
+	kernel_lb_addr prealloc_loc = {0, 0};
+	int prealloc_len = 0;
+
+	/* The previous extent is fake and we should not extend by anything
+	 * - there's nothing to do... */
+	if (!blocks && fake)
+		return 0;
+	/* Round the last extent up to a multiple of block size */
+	if (last_ext->extLength & (sb->s_blocksize - 1)) {
+		last_ext->extLength =
+			(last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
+			(((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
+				sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
+		UDF_I_LENEXTENTS(inode) =
+			(UDF_I_LENEXTENTS(inode) + sb->s_blocksize - 1) &
+				~(sb->s_blocksize - 1);
+	}
+	/* Last extent are just preallocated blocks? */
+	if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_ALLOCATED) {
+		/* Save the extent so that we can reattach it to the end */
+		prealloc_loc = last_ext->extLocation;
+		prealloc_len = last_ext->extLength;
+		/* Mark the extent as a hole */
+		last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
+			(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
+		last_ext->extLocation.logicalBlockNum = 0;
+       		last_ext->extLocation.partitionReferenceNum = 0;
+	}
+	/* Can we merge with the previous extent? */
+	if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) == EXT_NOT_RECORDED_NOT_ALLOCATED) {
+		add = ((1<<30) - sb->s_blocksize - (last_ext->extLength &
+			UDF_EXTENT_LENGTH_MASK)) >> sb->s_blocksize_bits;
+		if (add > blocks)
+			add = blocks;
+		blocks -= add;
+		last_ext->extLength += add << sb->s_blocksize_bits;
+	}
+
+	if (fake) {
+		udf_add_aext(inode, last_pos, last_ext->extLocation,
+			last_ext->extLength, 1);
+		count++;
+	}
+	else
+		udf_write_aext(inode, last_pos, last_ext->extLocation, last_ext->extLength, 1);
+	/* Managed to do everything necessary? */
+	if (!blocks)
+		goto out;
+
+	/* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
+	last_ext->extLocation.logicalBlockNum = 0;
+       	last_ext->extLocation.partitionReferenceNum = 0;
+	add = (1 << (30-sb->s_blocksize_bits)) - 1;
+	last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED | (add << sb->s_blocksize_bits);
+	/* Create enough extents to cover the whole hole */
+	while (blocks > add) {
+		blocks -= add;
+		if (udf_add_aext(inode, last_pos, last_ext->extLocation,
+			last_ext->extLength, 1) == -1)
+			return -1;
+		count++;
+	}
+	if (blocks) {
+		last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
+			(blocks << sb->s_blocksize_bits);
+		if (udf_add_aext(inode, last_pos, last_ext->extLocation,
+			last_ext->extLength, 1) == -1)
+			return -1;
+		count++;
+	}
+out:
+	/* Do we have some preallocated blocks saved? */
+	if (prealloc_len) {
+		if (udf_add_aext(inode, last_pos, prealloc_loc, prealloc_len, 1) == -1)
+			return -1;
+		last_ext->extLocation = prealloc_loc;
+		last_ext->extLength = prealloc_len;
+		count++;
+	}
+	/* last_pos should point to the last written extent... */
+	if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_SHORT)
+		last_pos->offset -= sizeof(short_ad);
+	else if (UDF_I_ALLOCTYPE(inode) == ICBTAG_FLAG_AD_LONG)
+		last_pos->offset -= sizeof(long_ad);
+	else
+		return -1;
+	return count;
+}
+
 static struct buffer_head * inode_getblk(struct inode * inode, sector_t block,
 	int *err, long *phys, int *new)
 {
+	static sector_t last_block;
 	struct buffer_head *result = NULL;
 	kernel_long_ad laarr[EXTENT_MERGE_SIZE];
 	struct extent_position prev_epos, cur_epos, next_epos;
@@ -371,7 +468,7 @@ static struct buffer_head * inode_getblk
 	sector_t offset = 0;
 	int8_t etype;
 	int goal = 0, pgoal = UDF_I_LOCATION(inode).logicalBlockNum;
-	char lastblock = 0;
+	int lastblock = 0;
 
 	prev_epos.offset = udf_file_entry_alloc_offset(inode);
 	prev_epos.block = UDF_I_LOCATION(inode);
@@ -423,6 +520,8 @@ static struct buffer_head * inode_getblk
 
 	b_off -= lbcount;
 	offset = b_off >> inode->i_sb->s_blocksize_bits;
+	/* Move into indirect extent if we are at a pointer to it */
+	udf_next_aext(inode, &prev_epos, &eloc, &elen, 0);
 
 	/* if the extent is allocated and recorded, return the block
        if the extent is not a multiple of the blocksize, round up */
@@ -444,43 +543,66 @@ static struct buffer_head * inode_getblk
 		return NULL;
 	}
 
+	last_block = block;
+	/* Are we beyond EOF? */
 	if (etype == -1)
 	{
-		endnum = startnum = ((count > 1) ? 1 : count);
-		if (laarr[c].extLength & (inode->i_sb->s_blocksize - 1))
-		{
-			laarr[c].extLength =
-				(laarr[c].extLength & UDF_EXTENT_FLAG_MASK) |
-				(((laarr[c].extLength & UDF_EXTENT_LENGTH_MASK) +
-					inode->i_sb->s_blocksize - 1) &
-				~(inode->i_sb->s_blocksize - 1));
-			UDF_I_LENEXTENTS(inode) =
-				(UDF_I_LENEXTENTS(inode) + inode->i_sb->s_blocksize - 1) &
-					~(inode->i_sb->s_blocksize - 1);
+		int ret;
+
+		if (count) {
+			if (c)
+				laarr[0] = laarr[1];
+			startnum = 1;
+		}
+		else {
+			/* Create a fake extent when there's not one */
+			memset(&laarr[0].extLocation, 0x00, sizeof(kernel_lb_addr));
+			laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
+			/* Will udf_extend_file() create real extent from a fake one? */
+			startnum = (offset > 0);
+		}
+		/* Create extents for the hole between EOF and offset */
+		ret = udf_extend_file(inode, &prev_epos, laarr, offset);
+		if (ret == -1) {
+			brelse(prev_epos.bh);
+			brelse(cur_epos.bh);
+			brelse(next_epos.bh);
+			/* We don't really know the error here so we just make
+			 * something up */
+			*err = -ENOSPC;
+			return NULL;
 		}
-		c = !c;
-		laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
-			((offset + 1) << inode->i_sb->s_blocksize_bits);
-		memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr));
-		count ++;
-		endnum ++;
+		c = 0;
+		offset = 0;
+		count += ret;
+		/* We are not covered by a preallocated extent? */
+		if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) != EXT_NOT_RECORDED_ALLOCATED) {
+			/* Is there any real extent? - otherwise we overwrite
+			 * the fake one... */
+			if (count)
+				c = !c;
+			laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
+				inode->i_sb->s_blocksize;
+			memset(&laarr[c].extLocation, 0x00, sizeof(kernel_lb_addr));
+			count ++;
+			endnum ++;
+		}
+		endnum = c+1;
 		lastblock = 1;
 	}
-	else
+	else {
 		endnum = startnum = ((count > 2) ? 2 : count);
 
-	/* if the current extent is in position 0, swap it with the previous */
-	if (!c && count != 1)
-	{
-		laarr[2] = laarr[0];
-		laarr[0] = laarr[1];
-		laarr[1] = laarr[2];
-		c = 1;
-	}
+		/* if the current extent is in position 0, swap it with the previous */
+		if (!c && count != 1)
+		{
+			laarr[2] = laarr[0];
+			laarr[0] = laarr[1];
+			laarr[1] = laarr[2];
+			c = 1;
+		}
 
-	/* if the current block is located in a extent, read the next extent */
-	if (etype != -1)
-	{
+		/* if the current block is located in an extent, read the next extent */
 		if ((etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0)) != -1)
 		{
 			laarr[c+1].extLength = (etype << 30) | elen;
@@ -489,11 +611,10 @@ static struct buffer_head * inode_getblk
 			startnum ++;
 			endnum ++;
 		}
-		else
+		else {
 			lastblock = 1;
+		}
 	}
-	brelse(cur_epos.bh);
-	brelse(next_epos.bh);
 
 	/* if the current extent is not recorded but allocated, get the
 		block in the extent corresponding to the requested block */
@@ -534,8 +655,8 @@ static struct buffer_head * inode_getblk
 	udf_merge_extents(inode, laarr, &endnum);
 
 	/* write back the new extents, inserting new extents if the new number
-       of extents is greater than the old number, and deleting extents if
-       the new number of extents is less than the old number */
+	of extents is greater than the old number, and deleting extents if
+	the new number of extents is less than the old number */
 	udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
 
 	brelse(prev_epos.bh);
@@ -991,6 +1112,7 @@ __udf_read_inode(struct inode *inode)
 		return;
 	}
 	udf_fill_inode(inode, bh);
+
 	brelse(bh);
 }
 
fs/udf/super.c +1 -1
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-4-udf_discard_prealloc_cleanup/fs/udf/super.c linux-2.6.20-5-large_file_fix/fs/udf/super.c
@@ -1663,7 +1663,7 @@ static int udf_fill_super(struct super_b
 		iput(inode);
 		goto error_out;
 	}
-	sb->s_maxbytes = 1<<30;
+	sb->s_maxbytes = MAX_LFS_FILESIZE;
 	return 0;
 
 error_out:
fs/udf/truncate.c +22 -46

128 lines not on this page · raw message

#10 lore raw
Quoted 4 lines · Jan Kara

Make UDF work correctly for files larger than 1GB. As no extent can be longer than (1<<30)-blocksize bytes, we have to create several extents if a big hole is being created. As a side-effect, we now don't discard preallocated blocks when creating a hole.

Ok.

author
#11 lore raw

PATCH 6/6 UDF cleanup and fixes

In reply to Jan Kara

We have to decrease link-count of the parent directory when removing a subdirectory.

fs/udf/namei.c +1 -1
diff -rupX /home/jack/.kerndiffexclude linux-2.6.20-5-large_file_fix/fs/udf/namei.c linux-2.6.20-6-rmdir_fix/fs/udf/namei.c
@@ -878,7 +878,7 @@ static int udf_rmdir(struct inode * dir,
 			inode->i_nlink);
 	clear_nlink(inode);
 	inode->i_size = 0;
-	inode_dec_link_count(inode);
+	inode_dec_link_count(dir);
 	inode->i_ctime = dir->i_ctime = dir->i_mtime = current_fs_time(dir->i_sb);
 	mark_inode_dirty(dir);
 
#12 lore raw
Quoted 2 lines · Jan Kara

We have to decrease link-count of the parent directory when removing a subdirectory.

Ok.

#13 lore raw
In reply to Jan Kara
Quoted 5 lines · Jan Kara

Hello,

the patches attached to six following emails implement some cleanup and
fixes in the UDF code. The main two fixes are:
1) UDF now works correctly for files larger than 1GB.

Hi,

I tried 2.6.20 with your patches and got the following behaviour:

$ ls -la dvd.udf 
-rw-r--r-- 1 root root 4699717632 Mar 29 15:36 dvd.udf
$ mount -o loop -t udf dvd.udf /media/udf/
$ df /media/udf/
Filesystem           1K-blocks      Used Available Use% Mounted on
/home/storage/dvd.udf
                       4588506 -8584746354 8589334860   -  /media/udf
                               ^^^^^^^^^^^^^^^^^^^^^^
$ ls -la /media/udf/
total 4587521
drwxr-xr-x 3 root root        144 Mar 29 15:36 .
drwxr-xr-x 9 root root       1024 Mar 20 12:02 ..
-rw-r--r-- 1 root root 4697620480 Mar 29 15:57 bk_usr.tar
drwxr-xr-x 2 root root         40 Mar 29 15:36 lost+found

Regards,
Tino

#14 lore raw
Quoted 11 lines · Tino Keitel
Quoted 5 lines · Jan Kara

Hello,

the patches attached to six following emails implement some cleanup and
fixes in the UDF code. The main two fixes are:
1) UDF now works correctly for files larger than 1GB.

Hi,

I tried 2.6.20 with your patches and got the following behaviour:

Quoted 15 lines
$ ls -la dvd.udf 
-rw-r--r-- 1 root root 4699717632 Mar 29 15:36 dvd.udf
$ mount -o loop -t udf dvd.udf /media/udf/
$ df /media/udf/
Filesystem           1K-blocks      Used Available Use% Mounted on
/home/storage/dvd.udf
                       4588506 -8584746354 8589334860   -  /media/udf
                               ^^^^^^^^^^^^^^^^^^^^^^
$ ls -la /media/udf/
total 4587521
drwxr-xr-x 3 root root        144 Mar 29 15:36 .
drwxr-xr-x 9 root root       1024 Mar 20 12:02 ..
-rw-r--r-- 1 root root 4697620480 Mar 29 15:57 bk_usr.tar
drwxr-xr-x 2 root root         40 Mar 29 15:36 lost+found

Is that on a 32-bit machine?

Seems to work okay on a 64-bit system here:

$ df /mnt/udf
Filesystem           1K-blocks      Used Available Use% Mounted on
/var/tmp/udf_fs        4798938       302   4798636   1% /mnt/udf
$ ll /var/tmp/udf_fs
-rw-r--r-- 1 root root 4915200000 Mar 30 13:49 /var/tmp/udf_fs

And after creating a large file in the filesystem:

$ ll /mnt/udf/udf_file
-rw-r--r-- 1 root root 4751360000 Mar 30 14:01 /mnt/udf/udf_file
$ df /mnt/udf
Filesystem           1K-blocks      Used Available Use% Mounted on
/var/tmp/udf_fs        4798938   4640304    158634  97% /mnt/udf
#15 lore raw
Quoted 21 lines · Chuck Ebbert
Quoted 20 lines · Tino Keitel
Quoted 5 lines · Jan Kara

Hello,

the patches attached to six following emails implement some cleanup and
fixes in the UDF code. The main two fixes are:
1) UDF now works correctly for files larger than 1GB.

Hi,

I tried 2.6.20 with your patches and got the following behaviour:

$ ls -la dvd.udf 
-rw-r--r-- 1 root root 4699717632 Mar 29 15:36 dvd.udf
$ mount -o loop -t udf dvd.udf /media/udf/
$ df /media/udf/
Filesystem           1K-blocks      Used Available Use% Mounted on
/home/storage/dvd.udf
                       4588506 -8584746354 8589334860   -  /media/udf
                               ^^^^^^^^^^^^^^^^^^^^^^
$ ls -la /media/udf/
Quoted 8 lines
Quoted 6 lines

total 4587521
drwxr-xr-x 3 root root 144 Mar 29 15:36 .
drwxr-xr-x 9 root root 1024 Mar 20 12:02 ..
-rw-r--r-- 1 root root 4697620480 Mar 29 15:57 bk_usr.tar
drwxr-xr-x 2 root root 40 Mar 29 15:36 lost+found

Is that on a 32-bit machine?

Yes, it's an Intel Core Duo.

Regards,
Tino

#16 lore raw
Quoted 29 lines · Tino Keitel
Quoted 11 lines · Chuck Ebbert
Quoted 10 lines · Tino Keitel
Quoted 5 lines · Jan Kara

Hello,

the patches attached to six following emails implement some cleanup and
fixes in the UDF code. The main two fixes are:
1) UDF now works correctly for files larger than 1GB.

Hi,

I tried 2.6.20 with your patches and got the following behaviour:

Quoted 16 lines
Quoted 6 lines
$ ls -la dvd.udf 
-rw-r--r-- 1 root root 4699717632 Mar 29 15:36 dvd.udf
$ mount -o loop -t udf dvd.udf /media/udf/
$ df /media/udf/
Filesystem           1K-blocks      Used Available Use% Mounted on
/home/storage/dvd.udf
Quoted 9 lines
                       4588506 -8584746354 8589334860   -  /media/udf
                               ^^^^^^^^^^^^^^^^^^^^^^
$ ls -la /media/udf/
total 4587521
drwxr-xr-x 3 root root        144 Mar 29 15:36 .
drwxr-xr-x 9 root root       1024 Mar 20 12:02 ..
-rw-r--r-- 1 root root 4697620480 Mar 29 15:57 bk_usr.tar
drwxr-xr-x 2 root root         40 Mar 29 15:36 lost+found

Is that on a 32-bit machine?

Quoted 1 line

Yes, it's an Intel Core Duo.

Well, it works for me on 32-bit as well, right up to 100% full. No problems at all...

#17 lore raw

On Mon, Apr 02, 2007 at 10:48:27 -0400, Chuck Ebbert wrote:

[...]

Quoted 2 lines

Well, it works for me on 32-bit as well, right up to 100% full. No problems at all...

Maybe it depends on the kernel. I patched 2.6.20 with the patches above and got the described behaviour.

Regards,
Tino

author
#18 lore raw
Quoted 9 lines · Tino Keitel

On Mon, Apr 02, 2007 at 10:48:27 -0400, Chuck Ebbert wrote:

[...]

Quoted 2 lines

Well, it works for me on 32-bit as well, right up to 100% full. No problems at all...

Maybe it depends on the kernel. I patched 2.6.20 with the patches above and got the described behaviour.

I've sent you an email with a few questions but probably it got lost in
the noise... Are you able to reproduce the problem? Have you reproduced the problem on a freshly created UDF image or was it some older image?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs
#19 lore raw
Quoted 5 lines · Jan Kara
Quoted 4 lines · Tino Keitel

On Mon, Apr 02, 2007 at 10:48:27 -0400, Chuck Ebbert wrote:

[...]

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Well, it works for me on 32-bit as well, right up to 100% full. No problems at all...

Maybe it depends on the kernel. I patched 2.6.20 with the patches above and got the described behaviour.

I've sent you an email with a few questions but probably it got lost in
the noise... Are you able to reproduce the problem? Have you reproduced the problem on a freshly created UDF image or was it some older image?

Hi,

I can't remember of any errors in the kernel or about not available space. It was an image file that I expermimented with, and I did multiple mkudffs runs on the file. Could it be that the behaviour was caused by stale data inside the image?

Regards,
Tino

author
#20 lore raw
Quoted 15 lines · Jan Kara
Quoted 5 lines · Tino Keitel
Quoted 4 lines · Chuck Ebbert

[...]

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Well, it works for me on 32-bit as well, right up to 100% full. No problems at all...

Maybe it depends on the kernel. I patched 2.6.20 with the patches above and got the described behaviour.

I've sent you an email with a few questions but probably it got lost in
the noise... Are you able to reproduce the problem? Have you reproduced the problem on a freshly created UDF image or was it some older image?

Quoted 6 lines

Hi,

I can't remember of any errors in the kernel or about not available space. It was an image file that I expermimented with, and I did multiple mkudffs runs on the file. Could it be that the behaviour was caused by stale data inside the image?

OK, thanks for info. Umm, I don't find it likely that some stale data
in the image would cause this but maybe something could confuse mkudffs (like it was expecting zeros somewhere where they were not). If you had some recipe how to reproduce the problem (it would be enough if you had something like: I have this file, I run mkudffs, mount it, see wrong free blocks count), I can have a look at it. Otherwise, it's hard to track it down...

Honza

author
#21 lore raw
In reply to Tino Keitel
Quoted 11 lines · Tino Keitel
Quoted 5 lines · Jan Kara

Hello,

the patches attached to six following emails implement some cleanup and
fixes in the UDF code. The main two fixes are:
1) UDF now works correctly for files larger than 1GB.

Hi,

I tried 2.6.20 with your patches and got the following behaviour:

Quoted 14 lines
$ ls -la dvd.udf 
-rw-r--r-- 1 root root 4699717632 Mar 29 15:36 dvd.udf
$ mount -o loop -t udf dvd.udf /media/udf/
$ df /media/udf/
Filesystem           1K-blocks      Used Available Use% Mounted on
/home/storage/dvd.udf
                       4588506 -8584746354 8589334860   -  /media/udf
                               ^^^^^^^^^^^^^^^^^^^^^^
$ ls -la /media/udf/
total 4587521
drwxr-xr-x 3 root root        144 Mar 29 15:36 .
drwxr-xr-x 9 root root       1024 Mar 20 12:02 ..
-rw-r--r-- 1 root root 4697620480 Mar 29 15:57 bk_usr.tar
drwxr-xr-x 2 root root         40 Mar 29 15:36 lost+found

Thanks for report. I'll have a look at it. I've tested my patches on a
64-bit machine and obviously some computation overflows on a 32-bit one...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs
author
#22 lore raw
In reply to Tino Keitel
Quoted 11 lines · Tino Keitel
Quoted 5 lines · Jan Kara

Hello,

the patches attached to six following emails implement some cleanup and
fixes in the UDF code. The main two fixes are:
1) UDF now works correctly for files larger than 1GB.

Hi,

I tried 2.6.20 with your patches and got the following behaviour:

Quoted 14 lines
$ ls -la dvd.udf 
-rw-r--r-- 1 root root 4699717632 Mar 29 15:36 dvd.udf
$ mount -o loop -t udf dvd.udf /media/udf/
$ df /media/udf/
Filesystem           1K-blocks      Used Available Use% Mounted on
/home/storage/dvd.udf
                       4588506 -8584746354 8589334860   -  /media/udf
                               ^^^^^^^^^^^^^^^^^^^^^^
$ ls -la /media/udf/
total 4587521
drwxr-xr-x 3 root root        144 Mar 29 15:36 .
drwxr-xr-x 9 root root       1024 Mar 20 12:02 ..
-rw-r--r-- 1 root root 4697620480 Mar 29 15:57 bk_usr.tar
drwxr-xr-x 2 root root         40 Mar 29 15:36 lost+found

Looking more into this it looks like a bug in accounting of free blocks
than some overflow. Was dvd.udf a freshly created image by mkudffs? Are there any errors in the log or did fs report anything like ENOSPC?

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs
#23 lore raw
In reply to Jan Kara
Quoted 9 lines · Jan Kara

Hello,

the patches attached to six following emails implement some cleanup and
fixes in the UDF code. The main two fixes are:
1) UDF now works correctly for files larger than 1GB.
2) Deleting a directory updates number of links to the parent directory correctly.
See headers of following patches for details.

Quoted 6 lines

The patches sustained some torturing so I hope that I did not introduce more bugs than I've fixed ;). Andrew, could you please put the patches into -mm kernels for testing? Thanks.

Honza

Jan -

I ran 2.6.21 + your udf patches from -mm through some udf tests which, oddly enough, can be found in the xfstests test suite in xfsprogs cvs from sgi.

It looks much better than before, but I was able to trip some of your asserts. They were generated while fsx was running. The good news, though, is that fsx passed. :) I haven't looked into it much further yet, but wanted to let you know.

Thanks,
-Eric

BUG: at /src/linux-2.6.21-rc5/fs/udf/truncate.c:123 udf_discard_prealloc()
 [<de969274>] udf_discard_prealloc+0x2d8/0x2ed [udf]
 [<de95eea5>] udf_release_file+0x15/0x1e [udf]
 [<c046f5f0>] __fput+0xa5/0x15b
 [<c046d0d2>] generic_file_open+0x0/0x45
 [<c046d3f3>] __dentry_open+0x115/0x17a
 [<c046d4d2>] nameidata_to_filp+0x24/0x33
 [<c046d513>] do_filp_open+0x32/0x39
 [<c046d278>] get_unused_fd+0x50/0xb6
 [<c046d55c>] do_sys_open+0x42/0xbe
 [<c046d611>] sys_open+0x1c/0x1e
 [<c0404db8>] syscall_call+0x7/0xb
 =======================
BUG: at /src/linux-2.6.21-rc5/fs/udf/truncate.c:123 udf_discard_prealloc()
 [<de969274>] udf_discard_prealloc+0x2d8/0x2ed [udf]
 [<de9632ae>] udf_clear_inode+0x1b/0x34 [udf]
 [<c047eb56>] clear_inode+0xb2/0x100
 [<c0459a95>] truncate_inode_pages+0x17/0x1a
 [<c047edfe>] dispose_list+0x33/0xb1
 [<c047f1f3>] invalidate_inodes+0xa8/0xbd
 [<c046fff2>] generic_shutdown_super+0x31/0xb7
 [<c0470095>] kill_block_super+0x1d/0x2d
 [<c047013d>] deactivate_super+0x52/0x65
 [<c0480de8>] sys_umount+0x1f2/0x21a
 [<c044e33f>] audit_syscall_entry+0x10d/0x137
 [<c0480e27>] sys_oldumount+0x17/0x1a
 [<c0404db8>] syscall_call+0x7/0xb
author
#24 lore raw
Quoted 19 lines · Eric Sandeen
Quoted 9 lines · Jan Kara

Hello,

the patches attached to six following emails implement some cleanup and
fixes in the UDF code. The main two fixes are:
1) UDF now works correctly for files larger than 1GB.
2) Deleting a directory updates number of links to the parent directory correctly.
See headers of following patches for details.

Quoted 6 lines

The patches sustained some torturing so I hope that I did not introduce more bugs than I've fixed ;). Andrew, could you please put the patches into -mm kernels for testing? Thanks.

Honza

Jan -

Quoted 8 lines

I ran 2.6.21 + your udf patches from -mm through some udf tests which, oddly enough, can be found in the xfstests test suite in xfsprogs cvs from sgi.

It looks much better than before, but I was able to trip some of your asserts. They were generated while fsx was running. The good news, though, is that fsx passed. :) I haven't looked into it much further yet, but wanted to let you know.

Thanks for the news. I'll try running fsx to see if I'll be able to
reproduce the problem (I think I was testing the patches with fsx but maybe it didn't run long enough).

Honza

Quoted 27 lines
BUG: at /src/linux-2.6.21-rc5/fs/udf/truncate.c:123 udf_discard_prealloc()
 [<de969274>] udf_discard_prealloc+0x2d8/0x2ed [udf]
 [<de95eea5>] udf_release_file+0x15/0x1e [udf]
 [<c046f5f0>] __fput+0xa5/0x15b
 [<c046d0d2>] generic_file_open+0x0/0x45
 [<c046d3f3>] __dentry_open+0x115/0x17a
 [<c046d4d2>] nameidata_to_filp+0x24/0x33
 [<c046d513>] do_filp_open+0x32/0x39
 [<c046d278>] get_unused_fd+0x50/0xb6
 [<c046d55c>] do_sys_open+0x42/0xbe
 [<c046d611>] sys_open+0x1c/0x1e
 [<c0404db8>] syscall_call+0x7/0xb
 =======================
BUG: at /src/linux-2.6.21-rc5/fs/udf/truncate.c:123 udf_discard_prealloc()
 [<de969274>] udf_discard_prealloc+0x2d8/0x2ed [udf]
 [<de9632ae>] udf_clear_inode+0x1b/0x34 [udf]
 [<c047eb56>] clear_inode+0xb2/0x100
 [<c0459a95>] truncate_inode_pages+0x17/0x1a
 [<c047edfe>] dispose_list+0x33/0xb1
 [<c047f1f3>] invalidate_inodes+0xa8/0xbd
 [<c046fff2>] generic_shutdown_super+0x31/0xb7
 [<c0470095>] kill_block_super+0x1d/0x2d
 [<c047013d>] deactivate_super+0x52/0x65
 [<c0480de8>] sys_umount+0x1f2/0x21a
 [<c044e33f>] audit_syscall_entry+0x10d/0x137
 [<c0480e27>] sys_oldumount+0x17/0x1a
 [<c0404db8>] syscall_call+0x7/0xb
Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs
#25 lore raw
In reply to Eric Sandeen
Quoted 10 lines · Eric Sandeen

Jan -

I ran 2.6.21 + your udf patches from -mm through some udf tests which, oddly enough, can be found in the xfstests test suite in xfsprogs cvs from sgi.

It looks much better than before, but I was able to trip some of your asserts. They were generated while fsx was running. The good news, though, is that fsx passed. :) I haven't looked into it much further yet, but wanted to let you know.

Here's a short hacky testcase that trips the assert around line 123 of udf/truncate.c I'm looking into it but you may immediately see what the problem is...?

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char ** argv)

{
        int fd;
        char buf[65536];

        fd = open("testfile", O_WRONLY|O_CREAT);
        lseek(fd, 16797, SEEK_SET);
        write(fd, buf, 22935);
        close(fd);

        fd = open("testfile", O_WRONLY);
        lseek(fd, 31281, SEEK_SET);
        write(fd, buf, 9592);
        close(fd);
}

-Eric

author
#26 lore raw
Quoted 8 lines · Eric Sandeen
Quoted 6 lines · Eric Sandeen

Jan -

I ran 2.6.21 + your udf patches from -mm through some udf tests which, oddly enough, can be found in the xfstests test suite in xfsprogs cvs from sgi.

Quoted 8 lines
Quoted 4 lines

It looks much better than before, but I was able to trip some of your asserts. They were generated while fsx was running. The good news, though, is that fsx passed. :) I haven't looked into it much further yet, but wanted to let you know.

Here's a short hacky testcase that trips the assert around line 123 of udf/truncate.c I'm looking into it but you may immediately see what the problem is...?

Yes, yesterday I've also managed to create a simple testcase - sorry for
not letting you know, I'd have saved you some time. I also know what the problem is:
1) discard_prealloc() shouldn't be called from udf_clear_inode() - at
that point inode won't be written any more and thus changes to it won't be reflected. Actually, this bug is hidden by the fact that UDF calls discard_prealloc() on each filp release but anyway.
2) the second problem is extent rounding - when we discard prealloc we
also truncate the extent to match i_size. That is fine but if the buffer remains in pagecache and is reused on second open, block_prepare_write() won't call udf_get_block() (as the buffer is already mapped) and thus the extent remains truncated even though we write after it's end. The easiest way out would be to simply leave the extent length rounded to block boundary but I have to check with the specification whether this is allowed...

Honza

Signature · 2 lines
Jan Kara <[email protected]>
SuSE CR Labs