Skip to contentSkip to conversation

xfs_io: fix extent array reallocation

PATCH In review Christoph Hellwig 2 participants 2 messages Mar 20, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs_io: fix extent array reallocation

From: Tomasz Majkowski <[email protected]>

The XFS_IOC_FSGETXATTRA ioctl only returns the number of allocated extents, so when we reallocate the extent array in the bmap command we have to account for the worst case where there is a whole between each two allocated extents. Also add some slack to that case to allow for a file growing while we are racing with it.

io/bmap.c +2 -2
Index: xfsprogs-dev/io/bmap.c
===================================================================
@@ -217,8 +217,8 @@
 			exitcode = 1;
 			return 0;
 		}
-		if (fsx.fsx_nextents >= map_size-1) {
-			map_size = 2*(fsx.fsx_nextents+1);
+		if (2 * fsx.fsx_nextents > map_size) {
+			map_size = 2 * fsx.fsx_nextents + 1;
 			map = realloc(map, map_size*sizeof(*map));
 			if (map == NULL) {
 				fprintf(stderr,

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Christoph Hellwig

From: Tomasz Majkowski <[email protected]>

The XFS_IOC_FSGETXATTRA ioctl only returns the number of allocated extents, so when we reallocate the extent array in the bmap command we have to account for the worst case where there is a whole between each two allocated extents. Also add some slack to that case to allow for a file growing while we are racing with it.

Quoted 19 lines

Index: xfsprogs-dev/io/bmap.c
===================================================================

io/bmap.c +2 -2
@@ -217,8 +217,8 @@
 			exitcode = 1;
 			return 0;
 		}
-		if (fsx.fsx_nextents >= map_size-1) {
-			map_size = 2*(fsx.fsx_nextents+1);
+		if (2 * fsx.fsx_nextents > map_size) {
+			map_size = 2 * fsx.fsx_nextents + 1;
 			map = realloc(map, map_size*sizeof(*map));
 			if (map == NULL) {
 				fprintf(stderr,
Quoted 4 lines

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs