Skip to contentSkip to conversation

xfsprogs: finer-grained sparse fixes

PATCH In review Eric Sandeen 4 participants 41 messages Oct 11, 2018 Kbuild

lore
Share & tools
lore
#0 lore raw

cover xfsprogs: finer-grained sparse fixes

hch asked for finer-grained patches for some of the sparse warning fixes, so here we go.

Thanks,
-Eric

#1 lore raw

PATCH 1/18 xfsprogs: enable sparse checking with "make C=[12]"

Enable "make C=1" or "make C=2" to do sparse checking. Blatantly ripped off from djwong's patch in e2fsprogs to do the same.

This is a bit simpler than redefining CC for the whole build, which requires extra commandline definitions and apparently is enough of a barrier that nobody's doing sparse checking.

Note, this requires unreleased sparse after v0.5, which enables the CHAR_BIT definition; otherwise it chokes.

---
 Makefile           | 14 ++++++++++++++
 include/buildrules |  2 ++
 2 files changed, 16 insertions(+)
Makefile +14 -0
index d031a60..7f3e774 100644
@@ -16,6 +16,20 @@ else
   Q = @
 endif
 
+CHECK=sparse
+CHECK_OPTS=-Wsparse-all -Wno-transparent-union -Wno-return-void -Wno-undef \
+	-Wno-non-pointer-null -D__linux__
+ifeq ("$(C)", "2")
+  CHECK_CMD=$(CHECK) $(CHECK_OPTS) -Wbitwise -D__CHECK_ENDIAN__
+else
+  ifeq ("$(C)", "1")
+    CHECK_CMD=$(CHECK) $(CHECK_OPTS)
+   else
+    CHECK_CMD=@true
+  endif
+endif
+export CHECK_CMD
+
 MAKEOPTS = --no-print-directory Q=$(Q)
 
 TOPDIR = .
include/buildrules +2 -0
index c57fdfc..23fc866 100644
@@ -54,10 +54,12 @@ $(LTLIBRARY) : $(SUBDIRS) $(LTOBJECTS)
 %.lo: %.c
 	@echo "    [CC]     $@"
 	$(Q)$(LTCOMPILE) -c $<
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
 else
 %.o: %.c
 	@echo "    [CC]     $@"
 	$(Q)$(CC) $(CFLAGS) -c $<
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
 
 endif
 
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH 2/18 xfs_db: convert single-bit bitfields to bools

In reply to Eric Sandeen

Sparse doesn't like signed single-bit bitfields, and they may as well just be booleans.

Fixes sparse warnings about this.

---
 db/check.c | 4 ++--
 db/io.h    | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
db/check.c +2 -2
index e0fd986..683e176 100644
@@ -41,8 +41,8 @@ typedef struct inodata {
 	struct inodata	*next;
 	nlink_t		link_set;
 	nlink_t		link_add;
-	char		isdir:1;
-	char		isreflink:1;
+	bool		isdir;
+	bool		isreflink;
 	char		security;
 	char		ilist;
 	xfs_ino_t	ino;
db/io.h +4 -4
index 8d5720b..7618be4 100644
@@ -26,10 +26,10 @@ typedef struct iocur {
 	const struct typ	*typ;	/* type of "data" */
 	bbmap_t			*bbmap;	/* map daddr if fragmented */
 	struct xfs_buf		*bp;	/* underlying buffer */
-	int			ino_crc_ok:1;
-	int			ino_buf:1;
-	int			dquot_buf:1;
-	int			need_crc:1;
+	bool			ino_crc_ok;
+	bool			ino_buf;
+	bool			dquot_buf;
+	bool			need_crc;
 } iocur_t;
 
 #define DB_RING_ADD 1                   /* add to ring on set_cur */
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 3/18 xfsprogs: minor endian annotation fixes

In reply to Eric Sandeen

No actual bugs, just quiet the sparse checker.

Fixes sparse warnings about this.

---
 copy/xfs_copy.c     | 2 +-
 db/crc.c            | 6 +++---
 db/write.c          | 4 ++--
 logprint/log_misc.c | 5 +++--
 repair/rmap.c       | 3 ++-
 5 files changed, 11 insertions(+), 9 deletions(-)
copy/xfs_copy.c +1 -1
index 64761b3..a6d6703 100644
@@ -505,7 +505,7 @@ sb_update_uuid(
 	 */
 	if (xfs_sb_version_hascrc(sb) && !xfs_sb_version_hasmetauuid(sb) &&
 	    !uuid_equal(&tcarg->uuid, &sb->sb_uuid)) {
-		__be32 feat;
+		uint32_t feat;
 
 		feat = be32_to_cpu(ag_hdr->xfs_sb->sb_features_incompat);
 		feat |= XFS_SB_FEAT_INCOMPAT_META_UUID;
db/crc.c +3 -3
index b6775bc..b6612a5 100644
@@ -130,7 +130,7 @@ crc_f(
 		flist_t		*sfl;
 		int		bit_length;
 		int		parentoffset;
-		int		crc;
+		uint32_t	crc;
 
 		sfl = fl;
 		parentoffset = 0;
@@ -144,8 +144,8 @@ crc_f(
 		bit_length *= fcount(sfl->fld, iocur_top->data, parentoffset);
 		crc = getbitval(iocur_top->data, sfl->offset, bit_length,
 				BVUNSIGNED);
-		/* Off by one.. */
-		crc = cpu_to_be32(crc + 1);
+		/* Off by one, ignore endianness - we're just corrupting it. */
+		crc++;
 		setbitval(iocur_top->data, sfl->offset, bit_length, &crc);
 
 		/* Temporarily remove write verifier to write a bad CRC */
db/write.c +2 -2
index a48576b..e25d6ea 100644
@@ -525,7 +525,7 @@ convert_arg(
 	char		*endp;
 	char		*rbuf;
 	char		*ostr;
-	__u64		*value;
+	__be64		*value;
 	__u64		val = 0;
 
 	if (bit_length <= 64)
@@ -535,7 +535,7 @@ convert_arg(
 
 	buf = xrealloc(buf, alloc_size);
 	memset(buf, 0, alloc_size);
-	value = (__u64 *)buf;
+	value = (__be64 *)buf;
 	rbuf = buf;
 
 	if (*arg == '\"') {
logprint/log_misc.c +3 -2
index e2889f0..e29366a 100644
@@ -467,6 +467,7 @@ xlog_print_dir2_sf(
 	xfs_dir2_sf_hdr_t *sfp,
 	int		size)
 {
+	__be64		pino;	/* parent inode nr */
 	xfs_ino_t	ino;
 	int		count;
 	int		i;
@@ -481,8 +482,8 @@ xlog_print_dir2_sf(
 
 	printf(_("SHORTFORM DIRECTORY size %d count %d\n"),
 	       size, sfp->count);
-	memmove(&ino, &(sfp->parent), sizeof(ino));
-	printf(_(".. ino 0x%llx\n"), (unsigned long long) be64_to_cpu(ino));
+	memmove(&pino, &(sfp->parent), sizeof(pino));
+	printf(_(".. ino 0x%llx\n"), (unsigned long long) be64_to_cpu(pino));
 
 	count = sfp->count;
 	sfep = xfs_dir2_sf_firstentry(sfp);
repair/rmap.c +2 -1
index 6de4a10..ebb5a3a 100644
@@ -482,7 +482,8 @@ rmap_store_ag_btree_rec(
 	 */
 	agfl_bno = XFS_BUF_TO_AGFL_BNO(mp, agflbp);
 	b = agfl_bno + ag_rmaps[agno].ar_flcount;
-	while (*b != NULLAGBLOCK && b - agfl_bno < libxfs_agfl_size(mp)) {
+	while (*b != cpu_to_be32(NULLAGBLOCK) &&
+	       b - agfl_bno < libxfs_agfl_size(mp)) {
 		error = rmap_add_ag_rec(mp, agno, be32_to_cpu(*b), 1,
 				XFS_RMAP_OWN_AG);
 		if (error)
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH 4/18 xfsprogs: avoid redefinition of NBBY

In reply to Eric Sandeen

Include sys/param.h for NBBY definition. Do this before our local guarded definition which is for platforms like android that don't have it, see commit:

c9a90185 xfsprogs: define NBBY if not defined by the system header files

Fixes sparse warnings about this redefinition.

---
 include/platform_defs.h.in | 2 ++
 1 file changed, 2 insertions(+)
include/platform_defs.h.in +2 -0
index c4f0e8b..d111ec6 100644
@@ -19,6 +19,7 @@
 #include <pthread.h>
 #include <ctype.h>
 #include <sys/types.h>
+#include <sys/param.h>
 #include <limits.h>
 #include <stdbool.h>
 #include <libgen.h>
@@ -65,6 +66,7 @@ typedef unsigned short umode_t;
 #define max(a,b)	(((a)>(b))?(a):(b))
 #endif
 
+/* If param.h doesn't provide it, i.e. for Android */
 #ifndef NBBY
 #define NBBY 8
 #endif
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH 5/18 xfsprogs: include headers for extern variables

In reply to Eric Sandeen

Include headers which export functions for their matching C files so that they don't appear to be static to the sparse checker.

Fixes sparse warnings about this.

---
 db/crc.c        | 1 +
 db/fuzz.c       | 1 +
 db/hash.c       | 1 +
 db/logformat.c  | 1 +
 db/symlink.c    | 2 +-
 db/text.c       | 1 +
 libfrog/crc32.c | 1 +
 7 files changed, 7 insertions(+), 1 deletion(-)
db/crc.c +1 -0
index b6612a5..95161c6 100644
@@ -17,6 +17,7 @@
 #include "output.h"
 #include "bit.h"
 #include "print.h"
+#include "crc.h"
 
 static int crc_f(int argc, char **argv);
 static void crc_help(void);
db/fuzz.c +1 -0
index 5d5d54f..65157bd 100644
@@ -21,6 +21,7 @@
 #include "print.h"
 #include "write.h"
 #include "malloc.h"
+#include "fuzz.h"
 
 static int	fuzz_f(int argc, char **argv);
 static void     fuzz_help(void);
db/hash.c +1 -0
index bda3316..68c53e7 100644
@@ -10,6 +10,7 @@
 #include "type.h"
 #include "io.h"
 #include "output.h"
+#include "hash.h"
 
 static int hash_f(int argc, char **argv);
 static void hash_help(void);
db/logformat.c +1 -0
index 42ce245..3374c29 100644
@@ -9,6 +9,7 @@
 #include "init.h"
 #include "output.h"
 #include "libxlog.h"
+#include "logformat.h"
 
 #define MAX_LSUNIT	256 * 1024	/* max log buf. size */
 
db/symlink.c +1 -1
index ebf6637..752cae4 100644
@@ -11,7 +11,7 @@
 #include "field.h"
 #include "bit.h"
 #include "init.h"
-
+#include "symlink.h"
 
 /*
  * XXX: no idea how to handle multiple contiguous block symlinks here.
db/text.c +1 -0
index 3a279d1..adf33a7 100644
@@ -17,6 +17,7 @@
 #include "io.h"
 #include "output.h"
 #include "init.h"
+#include "text.h"
 
 static void     print_rawtext(void *data, int len);
 
libfrog/crc32.c +1 -0
index 1d52f68..e3f3fd1 100644
@@ -33,6 +33,7 @@
 #include "xfs.h"
 #include "xfs_arch.h"
 #include "crc32defs.h"
+#include "crc32c.h"
 
 /* types specifc to this file */
 typedef __u8	u8;
Signature · 1 line
1.8.3.1
#14 lore raw

PATCH 6/18 libxfs: add several zone extern declarations to libxfs_priv.h

In reply to Eric Sandeen

Several zones have extern declarations in kernelspace headers we don't have in userspace.

Adding these to the libxfs_priv.h header silences sparse warnings about whether these should be static vars.

---
 libxfs/init.c        | 9 ---------
 libxfs/libxfs_priv.h | 7 +++++++
 2 files changed, 7 insertions(+), 9 deletions(-)
libxfs/init.c +0 -9
index 10dcbf3..80fbe6a 100644
@@ -363,15 +363,6 @@ done:
 static int
 manage_zones(int release)
 {
-	extern kmem_zone_t	*xfs_buf_zone;
-	extern kmem_zone_t	*xfs_ili_zone;
-	extern kmem_zone_t	*xfs_inode_zone;
-	extern kmem_zone_t	*xfs_ifork_zone;
-	extern kmem_zone_t	*xfs_buf_item_zone;
-	extern kmem_zone_t	*xfs_da_state_zone;
-	extern kmem_zone_t	*xfs_btree_cur_zone;
-	extern kmem_zone_t	*xfs_bmap_free_item_zone;
-	extern kmem_zone_t	*xfs_trans_zone;
 	extern void		xfs_dir_startup();
 
 	if (release) {	/* free zone allocation */
libxfs/libxfs_priv.h +7 -0
index 6df7864..b45d07e 100644
@@ -55,6 +55,13 @@
 #include "xfs_fs.h"
 #include "crc32c.h"
 
+/* Zones used in libxfs allocations that aren't in shared header files */
+extern kmem_zone_t *xfs_buf_item_zone;
+extern kmem_zone_t *xfs_ili_zone;
+extern kmem_zone_t *xfs_buf_zone;
+extern kmem_zone_t *xfs_inode_zone;
+extern kmem_zone_t *xfs_trans_zone;
+
 /* CRC stuff, buffer API dependent on it */
 #define crc32c(c,p,l)	crc32c_le((c),(unsigned char const *)(p),(l))
 
Signature · 1 line
1.8.3.1
#16 lore raw

PATCH 7/18 libxfs: silence static warnings about platform_* functions

In reply to Eric Sandeen

Add all platform_* prototypes to init.h and include it in linux.c to silence sparse warnings about static functions.

---
 libfrog/linux.c | 1 +
 libxfs/init.h   | 2 ++
 2 files changed, 3 insertions(+)
libfrog/linux.c +1 -0
index fc9f3ac..b6c2487 100644
@@ -11,6 +11,7 @@
 
 #include "libxfs_priv.h"
 #include "xfs_fs.h"
+#include "init.h"
 
 extern char *progname;
 static int max_block_alignment;
libxfs/init.h +2 -0
index e0b5091..2cda895 100644
@@ -19,5 +19,7 @@ extern char *platform_findblockpath (char *path);
 extern int platform_direct_blockdev (void);
 extern int platform_align_blockdev (void);
 extern unsigned long platform_physmem(void);	/* in kilobytes */
+extern void platform_findsizes(char *path, int fd, long long *sz, int *bsz);
+extern int platform_nproc(void);
 
 #endif	/* LIBXFS_INIT_H */
Signature · 1 line
1.8.3.1
#18 lore raw

PATCH 8/18 xfs_io: include io.h to silence static function warnings

In reply to Eric Sandeen

io.h exports functions from io/getrusage.c and io/log_writes.c, so include it from these files to silence warnings about potentially static functions (getrusage_init, log_writes_init) in sparse.

---
 io/getrusage.c  | 1 +
 io/log_writes.c | 1 +
 2 files changed, 2 insertions(+)
io/getrusage.c +1 -0
index ba704b7..6962913 100644
@@ -9,6 +9,7 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 #include "init.h"
+#include "io.h"
 
 static cmdinfo_t getrusage_cmd;
 
io/log_writes.c +1 -0
index 114f818..9c2285f 100644
@@ -8,6 +8,7 @@
 #include <libdevmapper.h>
 #include "command.h"
 #include "init.h"
+#include "io.h"
 
 static cmdinfo_t log_writes_cmd;
 
Signature · 1 line
1.8.3.1
#20 lore raw

PATCH 9/18 libxfs: silence sparse static function warnings in util.c

In reply to Eric Sandeen

libxfs.h exports functions defined in util.c, so include that file to silence sparse warnings about potential static functions.

---
 libxfs/util.c | 1 +
 1 file changed, 1 insertion(+)
libxfs/util.c +1 -0
index ffd2650..bd41404 100644
@@ -5,6 +5,7 @@
  */
 
 #include "libxfs_priv.h"
+#include "libxfs.h"
 #include "libxfs_io.h"
 #include "init.h"
 #include "xfs_fs.h"
Signature · 1 line
1.8.3.1
#22 lore raw

PATCH 10/18 avl64: export avl64_firstino / avl64_firstino from avl64.h

In reply to Eric Sandeen

These are flagged by the sparse checker as possibly static. They are actually not used at this point; avl64.c has a few unused functions and/or ones that could be made static, but for now just silence the warnings, and save deeper surgery for later.

---
 include/avl64.h | 6 ++++++
 1 file changed, 6 insertions(+)
include/avl64.h +6 -0
index 7a66883..4042f6c 100644
@@ -69,6 +69,12 @@ avl64_insert_immediate(
 	avl64node_t *afterp,
 	avl64node_t *newnode);
 
+avl64node_t *
+avl64_firstino(avl64node_t *root);
+
+avl64node_t *
+avl64_lastino(avl64node_t *root);
+
 void
 avl64_init_tree(
 	avl64tree_desc_t  *tree,
Signature · 1 line
1.8.3.1
#24 lore raw

PATCH 11/18 xfsprogs: misc static function warning fixes

In reply to Eric Sandeen

The last handful of static symbol warning cleanups for misc remaining issues.

---
 libxfs/init.h     | 1 +
 libxfs/rdwr.c     | 2 --
 repair/phase2.c   | 2 --
 repair/scan.h     | 2 ++
 scrub/xfs_scrub.h | 2 ++
 5 files changed, 5 insertions(+), 4 deletions(-)
libxfs/init.h +1 -0
index 2cda895..b23e493 100644
@@ -7,6 +7,7 @@
 #define LIBXFS_INIT_H
 
 struct stat;
+extern int     use_xfs_buf_lock;
 
 extern int platform_check_ismounted (char *path, char *block,
 					struct stat *sptr, int verbose);
libxfs/rdwr.c +0 -2
index e580aba..a00360e 100644
@@ -712,8 +712,6 @@ struct list_head	lock_buf_list = {&lock_buf_list, &lock_buf_list};
 int			lock_buf_count = 0;
 #endif
 
-extern int     use_xfs_buf_lock;
-
 static struct xfs_buf *
 __cache_lookup(struct xfs_bufkey *key, unsigned int flags)
 {
repair/phase2.c +0 -2
index b92ceb8..4bd6c63 100644
@@ -15,8 +15,6 @@
 #include "progress.h"
 #include "scan.h"
 
-void	set_mp(xfs_mount_t *mpp);
-
 /* workaround craziness in the xlog routines */
 int xlog_recover_do_trans(struct xlog *log, xlog_recover_t *t, int p)
 {
repair/scan.h +2 -0
index aa7c38d..bf1ee83 100644
@@ -8,6 +8,8 @@
 
 struct blkmap;
 
+void set_mp(xfs_mount_t *mpp);
+
 int scan_lbtree(
 	xfs_fsblock_t	root,
 	int		nlevels,
scrub/xfs_scrub.h +2 -0
index 8b80c79..a961d8f 100644
@@ -6,6 +6,8 @@
 #ifndef XFS_SCRUB_XFS_SCRUB_H_
 #define XFS_SCRUB_XFS_SCRUB_H_
 
+extern char *progname;
+
 #define _PATH_PROC_MOUNTS	"/proc/mounts"
 
 extern unsigned int		nr_threads;
Signature · 1 line
1.8.3.1
#26 lore raw

PATCH 12/18 xfsprogs: don't shadow global libxfs_init x variable

In reply to Eric Sandeen

We use the variable 'x' for the global libxfs_init structure, but several other functions think 'x' is a nice convenient local var too, and sparse complains. Rename these local variables (or in some cases re-use existing loop counter vars when x was used for this purpose).

---
 db/check.c          | 15 +++++++--------
 logprint/log_misc.c | 31 ++++++++++++++++---------------
 2 files changed, 23 insertions(+), 23 deletions(-)
db/check.c +7 -8
index 683e176..352aab3 100644
@@ -2050,7 +2050,7 @@ process_block_dir_v2(
 	int		nex;
 	xfs_ino_t	parent;
 	int		v;
-	int		x;
+	int		i;
 
 	nex = blkmap_getn(blkmap, 0, mp->m_dir_geo->fsbcount, &bmp);
 	v = id->ilist || verbose;
@@ -2067,9 +2067,9 @@ process_block_dir_v2(
 		make_bbmap(&bbmap, nex, bmp);
 	set_cur(&typtab[TYP_DIR2], XFS_FSB_TO_DADDR(mp, bmp->startblock),
 		mp->m_dir_geo->fsbcount * blkbb, DB_RING_IGN, nex > 1 ? &bbmap : NULL);
-	for (x = 0; !v && x < nex; x++) {
-		for (b = bmp[x].startblock;
-		     !v && b < bmp[x].startblock + bmp[x].blockcount;
+	for (i = 0; !v && i < nex; i++) {
+		for (b = bmp[i].startblock;
+		     !v && b < bmp[i].startblock + bmp[i].blockcount;
 		     b++)
 			v = CHECK_BLIST(b);
 	}
@@ -2998,7 +2998,6 @@ process_leaf_node_dir_v2(
 	int			t = 0;
 	int			v;
 	int			v2;
-	int			x;
 
 	v2 = verbose || id->ilist;
 	v = parent = 0;
@@ -3012,9 +3011,9 @@ process_leaf_node_dir_v2(
 	while ((dbno = blkmap_next_off(blkmap, dbno, &t)) != NULLFILEOFF) {
 		nex = blkmap_getn(blkmap, dbno, mp->m_dir_geo->fsbcount, &bmp);
 		ASSERT(nex > 0);
-		for (v = v2, x = 0; !v && x < nex; x++) {
-			for (b = bmp[x].startblock;
-			     !v && b < bmp[x].startblock + bmp[x].blockcount;
+		for (v = v2, i = 0; !v && i < nex; i++) {
+			for (b = bmp[i].startblock;
+			     !v && b < bmp[i].startblock + bmp[i].blockcount;
 			     b++)
 				v = CHECK_BLIST(b);
 		}
logprint/log_misc.c +16 -15
index e29366a..99d9920 100644
@@ -192,7 +192,6 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
     int64_t			 blkno;
     xfs_buf_log_format_t lbuf;
     int			 size, blen, map_size, struct_size;
-    __be64		 x, y;
     unsigned short	 flags;
 
     /*
@@ -247,20 +246,22 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
 		if (be32_to_cpu(head->oh_len) < 4*8) {
 			printf(_("Out of space\n"));
 		} else {
+			__be64		 a, b;
+
 			printf("\n");
 			/*
 			 * memmove because *ptr may not be 8-byte aligned
 			 */
-			memmove(&x, *ptr, sizeof(__be64));
-			memmove(&y, *ptr+8, sizeof(__be64));
-		       printf(_("icount: %llu  ifree: %llu  "),
-			       (unsigned long long) be64_to_cpu(x),
-			       (unsigned long long) be64_to_cpu(y));
-			memmove(&x, *ptr+16, sizeof(__be64));
-			memmove(&y, *ptr+24, sizeof(__be64));
-		       printf(_("fdblks: %llu  frext: %llu\n"),
-			       (unsigned long long) be64_to_cpu(x),
-			       (unsigned long long) be64_to_cpu(y));
+			memmove(&a, *ptr, sizeof(__be64));
+			memmove(&b, *ptr+8, sizeof(__be64));
+			printf(_("icount: %llu  ifree: %llu  "),
+			       (unsigned long long) be64_to_cpu(a),
+			       (unsigned long long) be64_to_cpu(b));
+			memmove(&a, *ptr+16, sizeof(__be64));
+			memmove(&b, *ptr+24, sizeof(__be64));
+			printf(_("fdblks: %llu  frext: %llu\n"),
+			       (unsigned long long) be64_to_cpu(a),
+			       (unsigned long long) be64_to_cpu(b));
 		}
 		super_block = 0;
 	} else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGI_MAGIC) {
@@ -1185,7 +1186,7 @@ xlog_print_extended_headers(
 	int 			num_hdrs;
 	int 			num_required;
 	char			xhbuf[XLOG_HEADER_SIZE];
-	xlog_rec_ext_header_t	*x;
+	xlog_rec_ext_header_t	*xhdr;
 
 	num_required = howmany(len, XLOG_HEADER_CYCLE_SIZE);
 	num_hdrs = be32_to_cpu(hdr->h_size) / XLOG_HEADER_CYCLE_SIZE;
@@ -1210,7 +1211,7 @@ xlog_print_extended_headers(
 	*ret_num_hdrs = num_hdrs;
 
 	/* don't include 1st header */
-	for (i = 1, x = *ret_xhdrs; i < num_hdrs; i++, (*blkno)++, x++) {
+	for (i = 1, xhdr = *ret_xhdrs; i < num_hdrs; i++, (*blkno)++, xhdr++) {
 	    /* read one extra header blk */
 	    if (read(fd, xhbuf, 512) == 0) {
 		printf(_("%s: physical end of log\n"), progname);
@@ -1240,9 +1241,9 @@ xlog_print_extended_headers(
 	     * will look asymmetric with the 1 hdr normal case
 	     * which does endian coversion on access.
 	     */
-	    x->xh_cycle = ((xlog_rec_ext_header_t*)xhbuf)->xh_cycle;
+	    xhdr->xh_cycle = ((xlog_rec_ext_header_t*)xhbuf)->xh_cycle;
 	    for (j = 0; j < XLOG_HEADER_CYCLE_SIZE / BBSIZE; j++) {
-		x->xh_cycle_data[j] =
+		xhdr->xh_cycle_data[j] =
 		    ((xlog_rec_ext_header_t*)xhbuf)->xh_cycle_data[j];
 	    }
 	}
Signature · 1 line
1.8.3.1
#28 lore raw

PATCH 13/18 xfs_io: rename global buffer variable

In reply to Eric Sandeen

"buffer" is a pretty poor name for a global variable, and leads to shadow variable warnings from sparse when other functions (reasonably) think it's a nice local variable name.

Rename it to io_buffer for less namespace pollution, and rename buffersize to io_buffersize to go with it.

---
 io/io.h     |  4 ++--
 io/mmap.c   |  6 +++---
 io/pread.c  | 56 ++++++++++++++++++++++++++++----------------------------
 io/pwrite.c | 28 ++++++++++++++--------------
 4 files changed, 47 insertions(+), 47 deletions(-)
io/io.h +2 -2
index 9278ad0..bc1e806 100644
@@ -79,8 +79,8 @@ extern void		printxattr(uint, int, int, const char *, int, int);
 extern unsigned int	recurse_all;
 extern unsigned int	recurse_dir;
 
-extern void		*buffer;
-extern size_t		buffersize;
+extern void		*io_buffer;
+extern size_t		io_buffersize;
 extern int		vectors;
 extern struct iovec	*iov;
 extern int		alloc_buffer(size_t, int, unsigned int);
io/mmap.c +3 -3
index 44749bb..f9383e5 100644
@@ -436,7 +436,7 @@ mread_f(
 
 	if (alloc_buffer(pagesize, 0, 0) < 0)
 		return 0;
-	bp = (char *)buffer;
+	bp = (char *)io_buffer;
 
 	dumplen = length % pagesize;
 	if (!dumplen)
@@ -451,7 +451,7 @@ mread_f(
 					dump_buffer(printoffset, dumplen);
 					printoffset += dumplen;
 				}
-				bp = (char *)buffer;
+				bp = (char *)io_buffer;
 				dumplen = pagesize;
 				cnt = 0;
 			} else {
@@ -466,7 +466,7 @@ mread_f(
 				if (dump)
 					dump_buffer(printoffset + tmp -
 						(dumplen - 1), dumplen);
-				bp = (char *)buffer;
+				bp = (char *)io_buffer;
 				dumplen = pagesize;
 				cnt = 0;
 			} else {
io/pread.c +28 -28

152 lines not on this page · raw message

io/pwrite.c +14 -14
index 34235ca..ccf14be 100644
@@ -62,7 +62,7 @@ do_pwritev(
 	ssize_t bytes = 0;
 
 	/* trim the iovec if necessary */
-	if (count < buffersize) {
+	if (count < io_buffersize) {
 		size_t	len = 0;
 		while (len + iov[vecs].iov_len < count) {
 			len += iov[vecs].iov_len;
@@ -102,7 +102,7 @@ do_pwrite(
 	int		pwritev2_flags)
 {
 	if (!vectors)
-		return pwrite(fd, buffer, min(count, buffer_size), offset);
+		return pwrite(fd, io_buffer, min(count, buffer_size), offset);
 
 	return do_pwritev(fd, offset, count, pwritev2_flags);
 }
@@ -120,22 +120,22 @@ write_random(
 	int		ops = 0;
 
 	srandom(seed);
-	if ((bytes = (offset % buffersize)))
+	if ((bytes = (offset % io_buffersize)))
 		offset -= bytes;
 	offset = max(0, offset);
-	if ((bytes = (count % buffersize)))
+	if ((bytes = (count % io_buffersize)))
 		count += bytes;
-	count = max(buffersize, count);
-	range = count - buffersize;
+	count = max(io_buffersize, count);
+	range = count - io_buffersize;
 
 	*total = 0;
 	while (count > 0) {
 		if (range)
-			off = ((offset + (random() % range)) / buffersize) *
-				buffersize;
+			off = ((offset + (random() % range)) / io_buffersize) *
+				io_buffersize;
 		else
 			off = offset;
-		bytes = do_pwrite(file->fd, off, buffersize, buffersize,
+		bytes = do_pwrite(file->fd, off, io_buffersize, io_buffersize,
 				pwritev2_flags);
 		if (bytes == 0)
 			break;
@@ -145,7 +145,7 @@ write_random(
 		}
 		ops++;
 		*total += bytes;
-		if (bytes < buffersize)
+		if (bytes < io_buffersize)
 			break;
 		count -= bytes;
 	}
@@ -172,10 +172,10 @@ write_backward(
 	*count = cnt;
 
 	/* Do initial unaligned write if needed */
-	if ((bytes_requested = (off % buffersize))) {
+	if ((bytes_requested = (off % io_buffersize))) {
 		bytes_requested = min(cnt, bytes_requested);
 		off -= bytes_requested;
-		bytes = do_pwrite(file->fd, off, bytes_requested, buffersize,
+		bytes = do_pwrite(file->fd, off, bytes_requested, io_buffersize,
 				pwritev2_flags);
 		if (bytes == 0)
 			return ops;
@@ -192,9 +192,9 @@ write_backward(
 
 	/* Iterate backward through the rest of the range */
 	while (cnt > end) {
-		bytes_requested = min(cnt, buffersize);
+		bytes_requested = min(cnt, io_buffersize);
 		off -= bytes_requested;
-		bytes = do_pwrite(file->fd, off, cnt, buffersize,
+		bytes = do_pwrite(file->fd, off, cnt, io_buffersize,
 				pwritev2_flags);
 		if (bytes == 0)
 			break;
Signature · 1 line
1.8.3.1
#30 lore raw

PATCH 14/18 xfs_logprint: fix shadow var in xlog_print_trans_buffer

In reply to Eric Sandeen

xlog_print_trans_buffer takes 'i' as an argument, but then uses it later as a local byte counter. Give the local var more useful, non-shadow name of "byte"

---
 logprint/log_misc.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
logprint/log_misc.c +6 -6
index 99d9920..c325f04 100644
@@ -395,15 +395,15 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
 		if (print_data) {
 			uint *dp  = (uint *)*ptr;
 			int  nums = be32_to_cpu(head->oh_len) >> 2;
-			int  i = 0;
+			int  byte = 0;
 
-			while (i < nums) {
-				if ((i % 8) == 0)
-					printf("%2x ", i);
+			while (byte < nums) {
+				if ((byte % 8) == 0)
+					printf("%2x ", byte);
 				printf("%8x ", *dp);
 				dp++;
-				i++;
-				if ((i % 8) == 0)
+				byte++;
+				if ((byte % 8) == 0)
 					printf("\n");
 			}
 			printf("\n");
Signature · 1 line
1.8.3.1
#32 lore raw

PATCH 15/18 xfs_repair: fix 'bno' shadow vars in scan.c

In reply to Eric Sandeen

scan.c has 3 functions which accept 'bno' as an argument, but then use a local variable of the same name for a different purpose in an inner scope, which causes sparse warnings.
Rename these inner-scope loop variables 'agbno' to fix this.

---
 repair/scan.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
repair/scan.c +11 -11
index 65a76e2..12ca314 100644
@@ -738,7 +738,7 @@ _("%s freespace btree block claimed (state %d), agno %d, bno %d, suspect %d\n"),
 	}
 
 	for (i = 0; i < numrecs; i++)  {
-		xfs_agblock_t		bno = be32_to_cpu(pp[i]);
+		xfs_agblock_t		agbno = be32_to_cpu(pp[i]);
 
 		/*
 		 * XXX - put sibling detection right here.
@@ -749,17 +749,17 @@ _("%s freespace btree block claimed (state %d), agno %d, bno %d, suspect %d\n"),
 		 * pointer mismatch, try and extract as much data
 		 * as possible.
 		 */
-		if (bno != 0 && verify_agbno(mp, agno, bno)) {
+		if (agbno != 0 && verify_agbno(mp, agno, agbno)) {
 			switch (magic) {
 			case XFS_ABTB_CRC_MAGIC:
 			case XFS_ABTB_MAGIC:
-				scan_sbtree(bno, level, agno, suspect,
+				scan_sbtree(agbno, level, agno, suspect,
 					    scan_allocbt, 0, magic, priv,
 					    &xfs_allocbt_buf_ops);
 				break;
 			case XFS_ABTC_CRC_MAGIC:
 			case XFS_ABTC_MAGIC:
-				scan_sbtree(bno, level, agno, suspect,
+				scan_sbtree(agbno, level, agno, suspect,
 					    scan_allocbt, 0, magic, priv,
 					    &xfs_allocbt_buf_ops);
 				break;
@@ -1177,7 +1177,7 @@ advance:
 	}
 
 	for (i = 0; i < numrecs; i++)  {
-		xfs_agblock_t		bno = be32_to_cpu(pp[i]);
+		xfs_agblock_t		agbno = be32_to_cpu(pp[i]);
 
 		/*
 		 * XXX - put sibling detection right here.
@@ -1199,12 +1199,12 @@ advance:
 			/* Look for impossible flags. */
 			do_warn(
 	_("invalid flags in high key %u of %s btree block %u/%u\n"),
-				i, name, agno, bno);
+				i, name, agno, agbno);
 			continue;
 		}
 
-		if (bno != 0 && verify_agbno(mp, agno, bno)) {
-			scan_sbtree(bno, level, agno, suspect, scan_rmapbt, 0,
+		if (agbno != 0 && verify_agbno(mp, agno, agbno)) {
+			scan_sbtree(agbno, level, agno, suspect, scan_rmapbt, 0,
 				    magic, priv, &xfs_rmapbt_buf_ops);
 		}
 	}
@@ -1419,10 +1419,10 @@ _("extent (%u/%u) len %u claimed, state is %d\n"),
 	}
 
 	for (i = 0; i < numrecs; i++)  {
-		xfs_agblock_t		bno = be32_to_cpu(pp[i]);
+		xfs_agblock_t		agbno = be32_to_cpu(pp[i]);
 
-		if (bno != 0 && verify_agbno(mp, agno, bno)) {
-			scan_sbtree(bno, level, agno, suspect, scan_refcbt, 0,
+		if (agbno != 0 && verify_agbno(mp, agno, agbno)) {
+			scan_sbtree(agbno, level, agno, suspect, scan_refcbt, 0,
 				    magic, priv, &xfs_refcountbt_buf_ops);
 		}
 	}
Signature · 1 line
1.8.3.1
#34 lore raw

PATCH 16/18 xfs_scrub: remove shadow var from run_scrub_phases()

In reply to Eric Sandeen

The local nr_threads shadows a global var of the same name. Use a local variable to avoid confusion (even though estimate_work() may simply fill in the value of the global...)

---
 scrub/xfs_scrub.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
scrub/xfs_scrub.c +5 -4
index 33b83a5..a789b6f 100644
@@ -422,7 +422,6 @@ run_scrub_phases(
 	bool			moveon = true;
 	unsigned int		debug_phase = 0;
 	unsigned int		phase;
-	unsigned int		nr_threads;
 	int			rshift;
 
 	if (debug_tweak_on("XFS_SCRUB_PHASE"))
@@ -454,12 +453,14 @@ run_scrub_phases(
 		if (!moveon)
 			break;
 		if (sp->estimate_work) {
-			moveon = sp->estimate_work(ctx, &max_work, &nr_threads,
-					&rshift);
+			unsigned int		work_threads;
+
+			moveon = sp->estimate_work(ctx, &max_work,
+					&work_threads, &rshift);
 			if (!moveon)
 				break;
 			moveon = progress_init_phase(ctx, progress_fp, phase,
-					max_work, rshift, nr_threads);
+					max_work, rshift, work_threads);
 		} else {
 			moveon = progress_init_phase(ctx, NULL, phase, 0, 0, 0);
 		}
Signature · 1 line
1.8.3.1
#36 lore raw

PATCH 17/18 xfs_metadump: remove shadow variable

In reply to Eric Sandeen

"length" is used in 2 nested inner scopes, which is fairly unclear and generates a sparse warning. Rename the inner scope variable for clarity.

---
 db/metadump.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
db/metadump.c +7 -6
index cc2ae9a..8b8e472 100644
@@ -1515,9 +1515,10 @@ process_dir_data_block(
 		dup = (xfs_dir2_data_unused_t *)ptr;
 
 		if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
-			int	length = be16_to_cpu(dup->length);
-			if (dir_offset + length > end_of_data ||
-			    !length || (length & (XFS_DIR2_DATA_ALIGN - 1))) {
+			int	free_length = be16_to_cpu(dup->length);
+			if (dir_offset + free_length > end_of_data ||
+			    !free_length ||
+			    (free_length & (XFS_DIR2_DATA_ALIGN - 1))) {
 				if (show_warnings)
 					print_warning(
 			"invalid length for dir free space in inode %llu",
@@ -1527,15 +1528,15 @@ process_dir_data_block(
 			if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) !=
 					dir_offset)
 				return;
-			dir_offset += length;
-			ptr += length;
+			dir_offset += free_length;
+			ptr += free_length;
 			/*
 			 * Zero the unused space up to the tag - the tag is
 			 * actually at a variable offset, so zeroing &dup->tag
 			 * is zeroing the free space in between
 			 */
 			if (zero_stale_data) {
-				int zlen = length -
+				int zlen = free_length -
 						sizeof(xfs_dir2_data_unused_t);
 
 				if (zlen > 0) {
Signature · 1 line
1.8.3.1
#39 lore raw

PATCH 18/18 libfrog: change project entity variable scope to local/static

In reply to Eric Sandeen

The project quota code used a global variable "p" for getprent() and getprpathent(), presumably to keep the interface analogous to getpwent() etc. However, other functions had their own local "p" which led to shadow variable warnings from sparse.

Rather than a global, make it a static variable within the project functions. Same behavior, same interface, less confusion, and retains an interface similar that of getpwent etc.

---
 libfrog/projects.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
libfrog/projects.c +6 -6
index d4dda3f..91bc78f 100644
@@ -15,12 +15,8 @@ char *projid_file;
 char *projects_file;
 
 static FILE *projects;
-static fs_project_t p;
-static char projects_buffer[512];
 
 static FILE *project_paths;
-static fs_project_path_t pp;
-static char project_paths_buffer[1024];
 
 void
 setprfiles(void)
@@ -64,8 +60,10 @@ endprpathent(void)
 fs_project_t *
 getprent(void)
 {
-	char	*idstart, *idend;
-	size_t	size = sizeof(projects_buffer) - 1;
+	static		fs_project_t p;
+	static char	projects_buffer[512];
+	char		*idstart, *idend;
+	size_t		size = sizeof(projects_buffer) - 1;
 
 	if (!projects)
 		return NULL;
@@ -125,6 +123,8 @@ getprprid(
 fs_project_path_t *
 getprpathent(void)
 {
+	static 		fs_project_path_t pp;
+	static char	project_paths_buffer[1024];
 	char		*nmstart, *nmend;
 	size_t		size = sizeof(project_paths_buffer) - 1;
 
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH 01/18] xfsprogs: enable sparse checking with "make C=[12]"

In reply to Eric Sandeen
Quoted 7 lines · Eric Sandeen

Enable "make C=1" or "make C=2" to do sparse checking. Blatantly ripped off from djwong's patch in e2fsprogs to do the same.

This is a bit simpler than redefining CC for the whole build, which requires extra commandline definitions and apparently is enough of a barrier that nobody's doing sparse checking.

Quoted 7 lines

Note, this requires unreleased sparse after v0.5, which enables the CHAR_BIT definition; otherwise it chokes.

---
 Makefile           | 14 ++++++++++++++
 include/buildrules |  2 ++

Please update doc/sparse.txt...

--D

Quoted 47 lines
 2 files changed, 16 insertions(+)
Makefile +14 -0
index d031a60..7f3e774 100644
@@ -16,6 +16,20 @@ else
   Q = @
 endif
 
+CHECK=sparse
+CHECK_OPTS=-Wsparse-all -Wno-transparent-union -Wno-return-void -Wno-undef \
+	-Wno-non-pointer-null -D__linux__
+ifeq ("$(C)", "2")
+  CHECK_CMD=$(CHECK) $(CHECK_OPTS) -Wbitwise -D__CHECK_ENDIAN__
+else
+  ifeq ("$(C)", "1")
+    CHECK_CMD=$(CHECK) $(CHECK_OPTS)
+   else
+    CHECK_CMD=@true
+  endif
+endif
+export CHECK_CMD
+
 MAKEOPTS = --no-print-directory Q=$(Q)
 
 TOPDIR = .
include/buildrules +2 -0
index c57fdfc..23fc866 100644
@@ -54,10 +54,12 @@ $(LTLIBRARY) : $(SUBDIRS) $(LTOBJECTS)
 %.lo: %.c
 	@echo "    [CC]     $@"
 	$(Q)$(LTCOMPILE) -c $<
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
 else
 %.o: %.c
 	@echo "    [CC]     $@"
 	$(Q)$(CC) $(CFLAGS) -c $<
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
 
 endif
 
Signature · 1 line
1.8.3.1
#37 lore raw

Re: [PATCH 17/18] xfs_metadump: remove shadow variable

In reply to Eric Sandeen
Quoted 13 lines · Eric Sandeen

"length" is used in 2 nested inner scopes, which is fairly unclear and generates a sparse warning. Rename the inner scope variable for clarity.

---
 db/metadump.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
db/metadump.c +0 -0
index cc2ae9a..8b8e472 100644

db/metadump.c process_dir_data_block( · line 1518

Quoted 7 lines
db/metadump.c +1 -3
@@ -1515,9 +1515,10 @@ process_dir_data_block(
 		dup = (xfs_dir2_data_unused_t *)ptr;
 
 		if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
-			int	length = be16_to_cpu(dup->length);
-			if (dir_offset + length > end_of_data ||
-			    !length || (length & (XFS_DIR2_DATA_ALIGN - 1))) {
+			int	free_length = be16_to_cpu(dup->length);

I know you're just changing names, but there ought to be a blank line betweeen the variable declaration and the first line of code.

Looks fine otherwise.

--D

Quoted 28 lines
db/metadump.c +6 -3
+			if (dir_offset + free_length > end_of_data ||
+			    !free_length ||
+			    (free_length & (XFS_DIR2_DATA_ALIGN - 1))) {
 				if (show_warnings)
 					print_warning(
 			"invalid length for dir free space in inode %llu",
@@ -1527,15 +1528,15 @@ process_dir_data_block(
 			if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) !=
 					dir_offset)
 				return;
-			dir_offset += length;
-			ptr += length;
+			dir_offset += free_length;
+			ptr += free_length;
 			/*
 			 * Zero the unused space up to the tag - the tag is
 			 * actually at a variable offset, so zeroing &dup->tag
 			 * is zeroing the free space in between
 			 */
 			if (zero_stale_data) {
-				int zlen = length -
+				int zlen = free_length -
 						sizeof(xfs_dir2_data_unused_t);
 
 				if (zlen > 0) {
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH v2 1/18 xfsprogs: enable sparse checking with "make C=[12]"

In reply to Eric Sandeen

Enable "make C=1" or "make C=2" to do sparse checking. Blatantly ripped off from djwong's patch in e2fsprogs to do the same.

This is a bit simpler than redefining CC for the whole build, which requires extra commandline definitions and apparently is enough of a barrier that nobody's doing sparse checking.

Note, this requires unreleased sparse after v0.5, which enables the CHAR_BIT definition; otherwise it chokes.

Add information about these helpers to doc/sparse.txt

---

Makefile +14 -0
index d031a60..7f3e774 100644
@@ -16,6 +16,20 @@ else
   Q = @
 endif
 
+CHECK=sparse
+CHECK_OPTS=-Wsparse-all -Wno-transparent-union -Wno-return-void -Wno-undef \
+	-Wno-non-pointer-null -D__linux__
+ifeq ("$(C)", "2")
+  CHECK_CMD=$(CHECK) $(CHECK_OPTS) -Wbitwise -D__CHECK_ENDIAN__
+else
+  ifeq ("$(C)", "1")
+    CHECK_CMD=$(CHECK) $(CHECK_OPTS)
+   else
+    CHECK_CMD=@true
+  endif
+endif
+export CHECK_CMD
+
 MAKEOPTS = --no-print-directory Q=$(Q)
 
 TOPDIR = .
doc/sparse.txt +14 -3
index 36a34a0..d426739 100644
@@ -5,9 +5,20 @@ to check the source code of the open source XFS commands and utilites
 First you need to install sparse, either from your distribution or from
 source as provided at http://www.kernel.org/pub/software/devel/sparse/.
 
-To simply build the xfsprogs source code while checking the source using
-sparse just set the compiler to cgcc, which is a wrapper that calls both
-sparse and gcc using:
+The xfsprogs Makefile has a convenient shortcut to running sparse, by setting
+the C ("check") variable on the make commandline.  To perform generic checks,
+
+	make C=1
+
+which checks with -Wsparse-all -Wno-transparent-union -Wno-return-void
+-Wno-undef -Wno-non-pointer-null, or to perform the bitwise checks, use
+
+	make C=2
+
+which checks with -Wbitwise -D__CHECK_ENDIAN__
+
+If you'd rather run sparse more manually, just set the compiler to cgcc,
+which is a wrapper that calls both sparse and gcc using:
 
 	CC=cgcc ./configure
 
include/buildrules +2 -0
index c57fdfc..23fc866 100644
@@ -54,10 +54,12 @@ $(LTLIBRARY) : $(SUBDIRS) $(LTOBJECTS)
 %.lo: %.c
 	@echo "    [CC]     $@"
 	$(Q)$(LTCOMPILE) -c $<
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
 else
 %.o: %.c
 	@echo "    [CC]     $@"
 	$(Q)$(CC) $(CFLAGS) -c $<
+	$(Q)$(CHECK_CMD) $(CFLAGS) $<
 
 endif
 
#4 lore raw

Re: [PATCH 01/18 V2] xfsprogs: enable sparse checking with "make C=[12]"

doc/sparse.txt to check the source code of the open source XFS commands and utilites · line 18

Quoted 12 lines
doc/sparse.txt +11 -1
-sparse and gcc using:
+The xfsprogs Makefile has a convenient shortcut to running sparse, by setting
+the C ("check") variable on the make commandline.  To perform generic checks,
+
+	make C=1
+
+which checks with -Wsparse-all -Wno-transparent-union -Wno-return-void
+-Wno-undef -Wno-non-pointer-null, or to perform the bitwise checks, use
+
+	make C=2
+
+which checks with -Wbitwise -D__CHECK_ENDIAN__

Out of all the sparce checks applicable to xfsprogs endianess is by far the most impotant one. I don't think it makes any sense to ever turn it off..

Reviewed-by on v1 2/18
#7 lore raw

Re: [PATCH 02/18] xfs_db: convert single-bit bitfields to bools

In reply to Eric Sandeen
Quoted 4 lines · Eric Sandeen

Sparse doesn't like signed single-bit bitfields, and they may as well just be booleans.

Fixes sparse warnings about this.

Looks good, although we could still do bool bitfields to save a tiny bit of space if we areally cared:

Reviewed-by on v1 4/18
#11 lore raw

Re: [PATCH 04/18] xfsprogs: avoid redefinition of NBBY

In reply to Eric Sandeen
Quoted 9 lines · Eric Sandeen

Include sys/param.h for NBBY definition. Do this before our local guarded definition which is for platforms like android that don't have it, see commit:

c9a90185 xfsprogs: define NBBY if not defined by the system header files

Fixes sparse warnings about this redefinition.

Looks good,

Reviewed-by on v1 6/18
#15 lore raw

Re: [PATCH 06/18] libxfs: add several zone extern declarations to libxfs_priv.h

In reply to Eric Sandeen
Quoted 7 lines · Eric Sandeen

Several zones have extern declarations in kernelspace headers we don't have in userspace.

Adding these to the libxfs_priv.h header silences sparse warnings about whether these should be static vars.

Looks good,

Reviewed-by on v1 8/18
#19 lore raw

Re: [PATCH 08/18] xfs_io: include io.h to silence static function warnings

In reply to Eric Sandeen
Quoted 5 lines · Eric Sandeen

io.h exports functions from io/getrusage.c and io/log_writes.c, so include it from these files to silence warnings about potentially static functions (getrusage_init, log_writes_init) in sparse.

Looks good,

Reviewed-by on v1 10/18
#23 lore raw

Re: [PATCH 10/18] avl64: export avl64_firstino / avl64_firstino from avl64.h

In reply to Eric Sandeen
Quoted 6 lines · Eric Sandeen

These are flagged by the sparse checker as possibly static. They are actually not used at this point; avl64.c has a few unused functions and/or ones that could be made static, but for now just silence the warnings, and save deeper surgery for later.

They've been unused for how long? I'd favor just removing them, but until that happens:

Reviewed-by on v1 12/18
#27 lore raw

Re: [PATCH 12/18] xfsprogs: don't shadow global libxfs_init x variable

In reply to Eric Sandeen
Quoted 6 lines · Eric Sandeen

We use the variable 'x' for the global libxfs_init structure, but several other functions think 'x' is a nice convenient local var too, and sparse complains. Rename these local variables (or in some cases re-use existing loop counter vars when x was used for this purpose).

Looks good,

Reviewed-by on v1 13/18
#29 lore raw

Re: [PATCH 13/18] xfs_io: rename global buffer variable

In reply to Eric Sandeen
Quoted 8 lines · Eric Sandeen

"buffer" is a pretty poor name for a global variable, and leads to shadow variable warnings from sparse when other functions (reasonably) think it's a nice local variable name.

Rename it to io_buffer for less namespace pollution, and rename buffersize to io_buffersize to go with it.

Looks good,

Reviewed-by on v1 15/18
#33 lore raw

Re: [PATCH 15/18] xfs_repair: fix 'bno' shadow vars in scan.c

In reply to Eric Sandeen
Quoted 6 lines · Eric Sandeen

scan.c has 3 functions which accept 'bno' as an argument, but then use a local variable of the same name for a different purpose in an inner scope, which causes sparse warnings.
Rename these inner-scope loop variables 'agbno' to fix this.

Looks good,

#5 lore raw

Re: [PATCH 01/18 V2] xfsprogs: enable sparse checking with "make C=[12]"

In reply to Christoph Hellwig
Quoted 8 lines · Christoph Hellwig
Quoted 8 lines
doc/sparse.txt +7 -1
-sparse and gcc using:
+The xfsprogs Makefile has a convenient shortcut to running sparse, by setting
+the C ("check") variable on the make commandline.  To perform generic checks,
+
+	make C=1
+
+which checks with -Wsparse-all -Wno-transparent-union -Wno-return-void
+-Wno-undef -Wno-non-pointer-null, or to perform the bitwise checks, use
Quoted 8 lines

doc/sparse.txt to check the source code of the open source XFS commands and utilites · line 18

Quoted 4 lines
doc/sparse.txt +4 -0
+
+	make C=2
+
+which checks with -Wbitwise -D__CHECK_ENDIAN__

Out of all the sparce checks applicable to xfsprogs endianess is by far the most impotant one. I don't think it makes any sense to ever turn it off..

Oh... whoops, I thought I was emulating kernel behavior (by following e2fsprogs behavior), but sadly no:

Quoted 4 lines

Do a kernel make with "make C=1" to run sparse on all the C files that get recompiled, or use "make C=2" to run sparse on the files whether they need to be recompiled or not. The latter is a fast way to check the whole tree if you have already built it.

Let me see if I can properly mimic that behavior, with endian checking baked in for both.

Thanks for bringing it up,
-Eric