Skip to contentSkip to conversation

repair: fix incorrect use of thread local data in dir and attr code

PATCH In review Christoph Hellwig 2 participants 2 messages Feb 7, 2012 – Feb 8, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 repair: fix incorrect use of thread local data in dir and attr code

The attribute and dirv1 code use pthread thread local data incorrectly in a few places, which will make them fail in horrible ways when using the ag_stride options.

Replace the use of thread local data with simple local allocations given that there is no needed to micro-optimize these allocations as much as e.g. the extent map. The added benefit is that we have to allocate less memory, and can free it quickly.

repair/attr_repair.c +4 -8
Index: xfsprogs-dev/repair/attr_repair.c
===================================================================
@@ -363,12 +363,6 @@ rmtval_get(xfs_mount_t *mp, xfs_ino_t in
 	return (clearit);
 }
 
-/*
- * freespace map for directory and attribute leaf blocks (1 bit per byte)
- * 1 == used, 0 == free
- */
-size_t ts_attr_freemap_size = sizeof(da_freemap_t) * DA_BMAP_SIZE;
-
 /* The block is read in. The magic number and forward / backward
  * links are checked by the caller process_leaf_attr.
  * If any problems occur the routine returns with non-zero. In
@@ -503,7 +497,7 @@ process_leaf_attr_block(
 {
 	xfs_attr_leaf_entry_t *entry;
 	int  i, start, stop, clearit, usedbs, firstb, thissize;
-	da_freemap_t *attr_freemap = ts_attr_freemap();
+	da_freemap_t *attr_freemap;
 
 	clearit = usedbs = 0;
 	*repair = 0;
@@ -519,7 +513,7 @@ process_leaf_attr_block(
 		return (1);
 	}
 
-	init_da_freemap(attr_freemap);
+	attr_freemap = alloc_da_freemap(mp);
 	(void) set_da_freemap(mp, attr_freemap, 0, stop);
 
 	/* go thru each entry checking for problems */
@@ -636,6 +630,8 @@ process_leaf_attr_block(
 		* we can add it then.
 		*/
 	}
+
+	free(attr_freemap);
 	return (clearit);  /* and repair */
 }
 
repair/dir.c +23 -44

147 lines not on this page · raw message

repair/dir.h +3 -6
Index: xfsprogs-dev/repair/dir.h
===================================================================
@@ -21,9 +21,6 @@
 
 struct blkmap;
 
-/* 1 bit per byte, max XFS blocksize == 64K bits / NBBY */
-#define DA_BMAP_SIZE		8192
-
 typedef unsigned char	da_freemap_t;
 
 /*
@@ -81,9 +78,9 @@ get_first_dblock_fsbno(
 	xfs_ino_t	ino,
 	xfs_dinode_t	*dino);
 
-void
-init_da_freemap(
-	da_freemap_t *dir_freemap);
+da_freemap_t *
+alloc_da_freemap(
+	xfs_mount_t	*mp);
 
 int
 namecheck(
repair/globals.h +0 -4
Index: xfsprogs-dev/repair/globals.h
===================================================================
@@ -185,10 +185,6 @@ EXTERN xfs_extlen_t	sb_inoalignmt;
 EXTERN __uint32_t	sb_unit;
 EXTERN __uint32_t	sb_width;
 
-extern size_t 		ts_dirbuf_size;
-extern size_t 		ts_dir_freemap_size;
-extern size_t 		ts_attr_freemap_size;
-
 EXTERN pthread_mutex_t	*ag_locks;
 
 EXTERN int 		report_interval;
repair/init.c +0 -52

74 lines not on this page · raw message

repair/protos.h +0 -4
Index: xfsprogs-dev/repair/protos.h
===================================================================
@@ -41,9 +41,5 @@ char	*alloc_ag_buf(int size);
 void	print_inode_list(xfs_agnumber_t i);
 char *	err_string(int err_code);
 
-extern void *ts_attr_freemap(void);
-extern void *ts_dir_freemap(void);
-extern void *ts_dirbuf(void);
-extern void ts_init(void);
 extern void thread_init(void);
 

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

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

The attribute and dirv1 code use pthread thread local data incorrectly in a few places, which will make them fail in horrible ways when using the ag_stride options.

Quoted 8 lines

Replace the use of thread local data with simple local allocations given that there is no needed to micro-optimize these allocations as much as e.g. the extent map. The added benefit is that we have to allocate less memory, and can free it quickly.

Looks pretty sane to me. Especially as the comments suggest it never even worked correctly in the first place.

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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